Dashboard: Add URL filter

main
Igor Scheller 4 years ago committed by msquare
parent 2745b04dc2
commit 8284921ac5

@ -11,9 +11,30 @@ use Engelsystem\ShiftsFilter;
function public_dashboard_controller() function public_dashboard_controller()
{ {
$filter = null; $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 = new ShiftsFilter();
$filter->sessionImport(session()->get('shifts-filter')); $filter->sessionImport($filterValues);
} }
$stats = [ $stats = [

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

@ -39,15 +39,24 @@ function tabs($tabs, $selected = 0)
$tab_content = []; $tab_content = [];
foreach ($tabs as $header => $content) { foreach ($tabs as $header => $content) {
$class = ''; $class = '';
$id = $header;
$href = '#' . $id;
if (count($tab_header) == $selected) { if (count($tab_header) == $selected) {
$class = 'active'; $class = 'active';
} }
if (is_array($content)) {
$href = $content['href'];
$content = null;
$id = null;
}
$tab_header[] = '<li role="presentation" class="' . $class . '"> $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>'; . $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 . $content
. '</div>'; . '</div>' : '';
} }
return div('', [ return div('', [
'<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>', '<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>',

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

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

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

@ -40,9 +40,11 @@ class ShiftsFilterRenderer
* Renders the filter. * Renders the filter.
* *
* @param string $page_link Link pointing to the actual page. * @param string $page_link Link pointing to the actual page.
* @param array $dashboardFilter
*
* @return string Generated HTML * @return string Generated HTML
*/ */
public function render($page_link) public function render($page_link, $dashboardFilter = [])
{ {
$toolbar = []; $toolbar = [];
if ($this->daySelectionEnabled && !empty($this->days)) { if ($this->daySelectionEnabled && !empty($this->days)) {
@ -53,6 +55,14 @@ class ShiftsFilterRenderer
$day_dropdown_items[] = toolbar_item_link($link, '', $day); $day_dropdown_items[] = toolbar_item_link($link, '', $day);
} }
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active'); $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', [ return div('form-group', [
toolbar_pills($toolbar) toolbar_pills($toolbar)

Loading…
Cancel
Save