Skip to content

Commit

Permalink
Merge pull request #490 from timeoff-management/tom-xxx-cleanup-for-g…
Browse files Browse the repository at this point in the history
…rouping-team-view

Team view page improvements
  • Loading branch information
vpp authored Aug 24, 2021
2 parents 75f19b1 + 5d583d9 commit 351e238
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
21 changes: 20 additions & 1 deletion lib/route/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -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: [] } }),
Expand Down
5 changes: 4 additions & 1 deletion views/partials/team_view_url_parameters.hbs
Original file line number Diff line number Diff line change
@@ -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~}}
4 changes: 2 additions & 2 deletions views/team_view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<div class="col-md-6 lead">{{logged_user.name}} {{logged_user.lastname}}'s team <a href="/calendar/feeds/" data-toggle="tooltip" data-placement="right" title="Export Team View to external calendars"><span class="fa fa-rss"></span></a></div>
<div class="col-md-3 col-md-offset-3">
<div class="btn-group btn-group-sm pull-right" role="group">
<a href="/calendar/teamview/?{{> team_view_url_parameters grouped_mode = 0 }}" class="btn btn-default" {{#unless grouped_mode}}disabled=disabled{{/unless}}>All</a>
<a href="/calendar/teamview/?{{> team_view_url_parameters grouped_mode = 1 }}" class="btn btn-default" {{#if grouped_mode}}disabled=disabled{{/if}}>By Department</a>
<a href="/calendar/teamview/?{{> team_view_url_parameters grouped_mode = 0 save_grouped_mode = 1 }}" class="btn btn-default" {{#unless grouped_mode}}disabled=disabled{{/unless}}>All</a>
<a href="/calendar/teamview/?{{> team_view_url_parameters grouped_mode = 1 save_grouped_mode = 1 }}" class="btn btn-default" {{#if grouped_mode}}disabled=disabled{{/if}}>By department</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 351e238

Please sign in to comment.