Skip to content

Commit

Permalink
Merge pull request #484 from timeoff-management/tom-xxx-fix-sorting-i…
Browse files Browse the repository at this point in the history
…ssues

Fix issues with sorting
  • Loading branch information
vpp authored Jul 28, 2021
2 parents 853d1f9 + c630f75 commit bd98cd1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,4 @@ By default the value is `en` (English). One can override it with other locales s

Please report any issues or feedback to <a href="https://twitter.com/FreeTimeOffApp">twitter</a> or Email: pavlo at timeoff.management


1 change: 1 addition & 0 deletions lib/model/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const leaveIntoObject = (leave) => {
id: leave.id,
employeeId: leave.userId,
employeeFullName: (leave.user ? leave.user.full_name() : 'N/A'),
employeeLastName: (leave.user ? leave.user.lastname : 'N/A'),
departmentId: (leave.user ? leave.user.departmentId : null),
departmentName: (leave.user && leave.user.department ? leave.user.department.name : 'N/A'),
typeId: leave.leaveTypeId,
Expand Down
5 changes: 3 additions & 2 deletions lib/route/departments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

"use strict";

const { sorter } = require('../util');

const express = require('express'),
router = express.Router(),
validator = require('validator'),
Expand Down Expand Up @@ -94,13 +96,12 @@ router.get('/departments/', function(req, res){
company_for_template = company;
return company.getDepartments({
scope : ['with_simple_users', 'with_boss'],
order : [[ model.Department.default_order_field() ]],
});
})
.then(function(departments){
res.render('departments_overview', {
title : 'Departments settings',
departments : departments,
departments : departments.sort((a, b) => sorter(a.name, b.name)),
allowance_options : generate_all_department_allowances(),
company : company_for_template,
});
Expand Down
2 changes: 1 addition & 1 deletion lib/route/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const renderLeavesReportAsCsv = async ({res, company, startDate, endDate, leaves

const defaultSortAttributeForLeaveReport = 'employeeFullName';
const sortersForLeavesReport = {
employeeFullName: (a,b) => sorter(a.employeeFullName, b.employeeFullName),
employeeFullName: (a,b) => sorter(a.employeeLastName, b.employeeLastName),
departmentName: (a,b) => sorter(a.departmentName, b.departmentName),
type: (a,b) => sorter(a.type, b.type),
startDate: (a,b) => moment.utc(a.startDate).toDate().valueOf() - moment.utc(b.startDate).toDate().valueOf(),
Expand Down
6 changes: 4 additions & 2 deletions lib/route/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ router.get('/add/', function(req, res){
.then(function(company){
res.render('user_add', {
company : company,
departments: company.departments.sort((a, b) => sorter(a.name, b.name)),
});
});
});
Expand Down Expand Up @@ -239,6 +240,7 @@ router.get('/edit/:user_id/', function(req, res){
company : company,
employee : employee,
show_main_tab : true,
departments: company.departments.sort((a, b) => sorter(a.name, b.name)),
});
});
})
Expand Down Expand Up @@ -805,7 +807,7 @@ router.get('/', function(req, res) {
})
// stick departments to company as well
.then(function(departments){
company.departments = departments;
company.departments = departments.sort((a,b) => sorter(a.name, b.name));
return Promise.resolve(company);
})
})
Expand Down Expand Up @@ -906,7 +908,7 @@ function promise_user_list_data_for_rendering(args) {
}));

const sortedUsersInfoForRendering = usersInfoForRendering
.sort((a, b) => sorter(a.user_full_name, b.user_full_name));
.sort((a, b) => sorter(a.user_lastname, b.user_lastname));

return Promise.resolve([company, sortedUsersInfoForRendering]);
}
Expand Down
2 changes: 1 addition & 1 deletion views/partials/user_details/general.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="form-group">
<label for="select_inp" class="control-label">Department</label>
<select class="form-control" id="select_inp" name="department" aria-describedby="department_help">
{{#each company.departments}}
{{#each departments}}
<option value="{{this.id}}" {{#if_equal ../employee.DepartmentId this.id}} selected="selected"{{/if_equal}}>{{this.name}} (approver {{this.boss.name}} {{this.boss.lastname}})</option>
{{/each}}
</select>
Expand Down
2 changes: 1 addition & 1 deletion views/user_add.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<label for="select_inp" class="col-md-3 control-label">Department</label>
<div class="col-md-3">
<select class="form-control" id="select_inp" name="department" aria-describedby="department_help">
{{#each company.departments}}
{{#each departments}}
<option value="{{this.id}}" data-vpp="{{@index}}">{{this.name}}</option>
{{/each}}
</select>
Expand Down

0 comments on commit bd98cd1

Please sign in to comment.