diff --git a/lib/route/calendar.js b/lib/route/calendar.js index 202d7ba4b..0a8796caf 100644 --- a/lib/route/calendar.js +++ b/lib/route/calendar.js @@ -137,7 +137,7 @@ router.get('/teamview/', async (req, res) => { ? moment.utc(req.query['date']) : user.company.get_today(); - const grouped_mode = !! req.query['grouped_mode']; + const grouped_mode = getGroupedModeParameter(req); const team_view = new TeamView({ user, base_date }); @@ -195,6 +195,25 @@ router.get('/teamview/', async (req, res) => { }; }); +const getGroupedModeParameter = (req) => { + /** + * grouped_mode parameter is saved in the current session so user's + * transition between different pages does not reset the value + */ + let groupedMode = !! req.query['grouped_mode']; + + if (req.query['save_grouped_mode']) { + req.session.teamViewGroupedMode = groupedMode + } + + // for cases when no grouped_mode parameter was supplied: used onf from session + if (req.query['grouped_mode'] === undefined) { + groupedMode = req.session.teamViewGroupedMode + } + + return groupedMode +}; + const groupUsersOnTeamViewByDepartments = (usersAndLeaves) => { const departmentsDict = usersAndLeaves.reduce( (acc, item) => ({ ...acc, [item.user.department.id]: { departmentName: item.user.department.name, users_and_leaves: [] } }), diff --git a/views/partials/team_view_url_parameters.hbs b/views/partials/team_view_url_parameters.hbs index c56af0800..0c533a8ff 100644 --- a/views/partials/team_view_url_parameters.hbs +++ b/views/partials/team_view_url_parameters.hbs @@ -1 +1,4 @@ -{{#if current_department }}department={{current_department.id}}{{/if}}{{#if base_date }}&date={{ as_date_formatted base_date 'YYYY-MM' }}{{/if}}{{#if grouped_mode}}&grouped_mode={{grouped_mode}}{{/if}} +{{#if current_department }}{{#unless grouped_mode}}department={{current_department.id}}&{{/unless}}{{/if~}} +{{~#if base_date }}date={{ as_date_formatted base_date 'YYYY-MM' }}&{{/if~}} +{{~#if grouped_mode }}grouped_mode={{grouped_mode}}&{{/if~}} +{{~#if save_grouped_mode}}save_grouped_mode=1&{{/if~}} diff --git a/views/team_view.hbs b/views/team_view.hbs index 86deede58..9bfc3bae4 100644 --- a/views/team_view.hbs +++ b/views/team_view.hbs @@ -7,8 +7,8 @@
{{logged_user.name}} {{logged_user.lastname}}'s team
- All - By Department + All + By department