From 9387c5e5b65034665b41468926db7bdd0a73c502 Mon Sep 17 00:00:00 2001 From: Pavlo Date: Wed, 25 Aug 2021 09:16:56 +0100 Subject: [PATCH] Save Team View's department ID in session So transition between pages does not reset selected value. --- lib/route/calendar.js | 27 +++++++++++++++++---- views/partials/team_view_url_parameters.hbs | 1 + views/team_view.hbs | 8 +++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/route/calendar.js b/lib/route/calendar.js index 0a8796caf..3b0845548 100644 --- a/lib/route/calendar.js +++ b/lib/route/calendar.js @@ -138,13 +138,9 @@ router.get('/teamview/', async (req, res) => { : user.company.get_today(); const grouped_mode = getGroupedModeParameter(req); - + const currentDepartmentId = getDepartmentIdForTeamView(req); const team_view = new TeamView({ user, base_date }); - const currentDepartmentId = validator.isNumeric(req.query['department']) - ? req.query['department'] - : null; - try { const [team_view_details, company] = await Promise.all([ team_view.promise_team_view_details({ @@ -214,6 +210,27 @@ const getGroupedModeParameter = (req) => { return groupedMode }; +const getDepartmentIdForTeamView = (req) => { + /** + * department parameter is saved in the current session so user's + * transition between different pages does not reset the value + */ + let departmentId = validator.isNumeric(req.query['department']) + ? req.query['department'] + : null; + + if (req.query['save_current_department']) { + req.session.teamViewDepartmentId = departmentId + } + + // for cases when no grouped_mode parameter was supplied: used onf from session + if (req.query['department'] === undefined) { + departmentId = req.session.teamViewDepartmentId + } + + return departmentId +} + 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 0c533a8ff..9b2119c5e 100644 --- a/views/partials/team_view_url_parameters.hbs +++ b/views/partials/team_view_url_parameters.hbs @@ -2,3 +2,4 @@ {{~#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~}} +{{~#if save_current_department}}save_current_department=1&{{/if~}} diff --git a/views/team_view.hbs b/views/team_view.hbs index 9bfc3bae4..6128d011e 100644 --- a/views/team_view.hbs +++ b/views/team_view.hbs @@ -7,8 +7,8 @@
{{logged_user.name}} {{logged_user.lastname}}'s team
@@ -105,10 +105,10 @@