Skip to content

Commit

Permalink
Merge pull request #491 from timeoff-management/tom-xxx-store-team-vi…
Browse files Browse the repository at this point in the history
…ew-department-id-in-session

Save Team View's department ID in session
  • Loading branch information
vpp authored Aug 25, 2021
2 parents 351e238 + 9387c5e commit 319091d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
27 changes: 22 additions & 5 deletions lib/route/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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: [] } }),
Expand Down
1 change: 1 addition & 0 deletions views/partials/team_view_url_parameters.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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~}}
8 changes: 4 additions & 4 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 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>
<a href="/calendar/teamview/?{{> team_view_url_parameters grouped_mode = 0 save_grouped_mode = 1 save_current_department = 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 save_current_department = 1 }}" class="btn btn-default" {{#if grouped_mode}}disabled=disabled{{/if}}>By department</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -105,10 +105,10 @@
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="?{{> team_view_url_parameters current_department = null }}">All</a></li>
<li><a href="?{{> team_view_url_parameters current_department = null save_current_department = 1 }}">All</a></li>
<li role="separator" class="divider"></li>
{{#each related_departments}}
<li><a href="?{{> team_view_url_parameters base_date = ../base_date current_department = this }}">{{this.name}}</a></li>
<li><a href="?{{> team_view_url_parameters base_date = ../base_date current_department = this save_current_department = 1 }}">{{this.name}}</a></li>
{{/each}}
</ul>
</div>
Expand Down

0 comments on commit 319091d

Please sign in to comment.