Dashboard: Add URL filter

This commit is contained in:
Igor Scheller 2020-11-24 01:18:05 +01:00 committed by msquare
parent 2745b04dc2
commit 8284921ac5
7 changed files with 60 additions and 11 deletions

View File

@ -11,9 +11,30 @@ use Engelsystem\ShiftsFilter;
function public_dashboard_controller()
{
$filter = null;
if (request()->get('filtered') && auth()->user()) {
if (request()->get('filtered')) {
$requestRooms = check_request_int_array('rooms');
$requestAngelTypes = check_request_int_array('types');
if (!$requestRooms && !$requestAngelTypes) {
$sessionFilter = collect(session()->get('shifts-filter', []));
$requestRooms = $sessionFilter->get('rooms', []);
$requestAngelTypes = $sessionFilter->get('types', []);
}
$angelTypes = collect(unrestricted_angeltypes());
$rooms = $requestRooms ?: Rooms()->pluck('id')->toArray();
$angelTypes = $requestAngelTypes ?: $angelTypes->pluck('id')->toArray();
$filterValues = [
'userShiftsAdmin' => false,
'filled' => [],
'rooms' => $rooms,
'types' => $angelTypes,
'startTime' => null,
'endTime' => null,
];
$filter = new ShiftsFilter();
$filter->sessionImport(session()->get('shifts-filter'));
$filter->sessionImport($filterValues);
}
$stats = [

View File

@ -167,11 +167,19 @@ function load_types()
]
);
if (empty($types)) {
return DB::select('SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0');
return unrestricted_angeltypes();
}
return $types;
}
/**
* @return array[]
*/
function unrestricted_angeltypes()
{
return DB::select('SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0');
}
/**
* @return string
*/

View File

@ -39,15 +39,24 @@ function tabs($tabs, $selected = 0)
$tab_content = [];
foreach ($tabs as $header => $content) {
$class = '';
$id = $header;
$href = '#' . $id;
if (count($tab_header) == $selected) {
$class = 'active';
}
if (is_array($content)) {
$href = $content['href'];
$content = null;
$id = null;
}
$tab_header[] = '<li role="presentation" class="' . $class . '">
<a href="#' . $header . '" aria-controls="' . $header . '" role="tab" data-toggle="tab">'
<a href="'. $href . '"'
. ($id ? ' aria-controls="' . $id . '" role="tab" data-toggle="tab"' : '')
. '>'
. $header . '</a></li>';
$tab_content[] = '<div role="tabpanel" class="tab-pane ' . $class . '" id="' . $header . '">'
$tab_content[] = $content ? '<div role="tabpanel" class="tab-pane ' . $class . '" id="' . $id . '">'
. $content
. '</div>';
. '</div>' : '';
}
return div('', [
'<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>',

View File

@ -358,7 +358,7 @@ function AngelType_view(
$angeltype,
$shiftsFilterRenderer,
$shiftCalendarRenderer
)
),
], $tab)
], true);
}
@ -374,7 +374,7 @@ function AngelType_view_shifts($angeltype, $shiftsFilterRenderer, $shiftCalendar
$shifts = $shiftsFilterRenderer->render(page_link_to('angeltypes', [
'action' => 'view',
'angeltype_id' => $angeltype['id']
]));
]), ['type' => $angeltype['id']]);
$shifts .= $shiftCalendarRenderer->render();
return div('first', $shifts);

View File

@ -32,6 +32,7 @@ function public_dashboard_view($stats, $free_shifts)
}
$isFiltered = request()->get('filtered');
$filter = collect(session()->get('shifts-filter'))->only(['rooms', 'types'])->toArray();
return page([
div('public-dashboard', [
div('first', [
@ -58,7 +59,7 @@ function public_dashboard_view($stats, $free_shifts)
glyph('fullscreen') . __('Fullscreen')
),
auth()->user() ? button(
public_dashboard_link($isFiltered ? [] : ['filtered' => 1]),
public_dashboard_link($isFiltered ? [] : ['filtered' => 1] + $filter),
glyph('filter') . ($isFiltered ? __('All') : __('Filtered'))
) : ''
])], 'fullscreen-button'),

View File

@ -41,7 +41,7 @@ function Room_view(Room $room, ShiftsFilterRenderer $shiftsFilterRenderer, Shift
$shiftsFilterRenderer->render(page_link_to('rooms', [
'action' => 'view',
'room_id' => $room->id
])),
]), ['rooms' => [$room->id]]),
$shiftCalendarRenderer->render()
]);

View File

@ -40,9 +40,11 @@ class ShiftsFilterRenderer
* Renders the filter.
*
* @param string $page_link Link pointing to the actual page.
* @param array $dashboardFilter
*
* @return string Generated HTML
*/
public function render($page_link)
public function render($page_link, $dashboardFilter = [])
{
$toolbar = [];
if ($this->daySelectionEnabled && !empty($this->days)) {
@ -53,6 +55,14 @@ class ShiftsFilterRenderer
$day_dropdown_items[] = toolbar_item_link($link, '', $day);
}
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
if ($dashboardFilter) {
$toolbar[] = sprintf(
'<li role="presentation"><a href="%s">%s</a></li>',
url('/public-dashboard', ['filtered' => true] + $dashboardFilter),
glyph('dashboard') . __('Dashboard')
);
}
}
return div('form-group', [
toolbar_pills($toolbar)