Skip to content

Commit c630f75

Browse files
author
Pavlo
committed
Fix issues with sorting
Sort employees on the employees page by last name Fix sorting by name in reporting Department sorting respects locale
1 parent 853d1f9 commit c630f75

File tree

7 files changed

+12
-7
lines changed

7 files changed

+12
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,4 @@ By default the value is `en` (English). One can override it with other locales s
146146

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

149+

lib/model/Report.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const leaveIntoObject = (leave) => {
8989
id: leave.id,
9090
employeeId: leave.userId,
9191
employeeFullName: (leave.user ? leave.user.full_name() : 'N/A'),
92+
employeeLastName: (leave.user ? leave.user.lastname : 'N/A'),
9293
departmentId: (leave.user ? leave.user.departmentId : null),
9394
departmentName: (leave.user && leave.user.department ? leave.user.department.name : 'N/A'),
9495
typeId: leave.leaveTypeId,

lib/route/departments.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
"use strict";
33

4+
const { sorter } = require('../util');
5+
46
const express = require('express'),
57
router = express.Router(),
68
validator = require('validator'),
@@ -94,13 +96,12 @@ router.get('/departments/', function(req, res){
9496
company_for_template = company;
9597
return company.getDepartments({
9698
scope : ['with_simple_users', 'with_boss'],
97-
order : [[ model.Department.default_order_field() ]],
9899
});
99100
})
100101
.then(function(departments){
101102
res.render('departments_overview', {
102103
title : 'Departments settings',
103-
departments : departments,
104+
departments : departments.sort((a, b) => sorter(a.name, b.name)),
104105
allowance_options : generate_all_department_allowances(),
105106
company : company_for_template,
106107
});

lib/route/reports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const renderLeavesReportAsCsv = async ({res, company, startDate, endDate, leaves
205205

206206
const defaultSortAttributeForLeaveReport = 'employeeFullName';
207207
const sortersForLeavesReport = {
208-
employeeFullName: (a,b) => sorter(a.employeeFullName, b.employeeFullName),
208+
employeeFullName: (a,b) => sorter(a.employeeLastName, b.employeeLastName),
209209
departmentName: (a,b) => sorter(a.departmentName, b.departmentName),
210210
type: (a,b) => sorter(a.type, b.type),
211211
startDate: (a,b) => moment.utc(a.startDate).toDate().valueOf() - moment.utc(b.startDate).toDate().valueOf(),

lib/route/users/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ router.get('/add/', function(req, res){
2828
.then(function(company){
2929
res.render('user_add', {
3030
company : company,
31+
departments: company.departments.sort((a, b) => sorter(a.name, b.name)),
3132
});
3233
});
3334
});
@@ -239,6 +240,7 @@ router.get('/edit/:user_id/', function(req, res){
239240
company : company,
240241
employee : employee,
241242
show_main_tab : true,
243+
departments: company.departments.sort((a, b) => sorter(a.name, b.name)),
242244
});
243245
});
244246
})
@@ -805,7 +807,7 @@ router.get('/', function(req, res) {
805807
})
806808
// stick departments to company as well
807809
.then(function(departments){
808-
company.departments = departments;
810+
company.departments = departments.sort((a,b) => sorter(a.name, b.name));
809811
return Promise.resolve(company);
810812
})
811813
})
@@ -906,7 +908,7 @@ function promise_user_list_data_for_rendering(args) {
906908
}));
907909

908910
const sortedUsersInfoForRendering = usersInfoForRendering
909-
.sort((a, b) => sorter(a.user_full_name, b.user_full_name));
911+
.sort((a, b) => sorter(a.user_lastname, b.user_lastname));
910912

911913
return Promise.resolve([company, sortedUsersInfoForRendering]);
912914
}

views/partials/user_details/general.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<div class="form-group">
2525
<label for="select_inp" class="control-label">Department</label>
2626
<select class="form-control" id="select_inp" name="department" aria-describedby="department_help">
27-
{{#each company.departments}}
27+
{{#each departments}}
2828
<option value="{{this.id}}" {{#if_equal ../employee.DepartmentId this.id}} selected="selected"{{/if_equal}}>{{this.name}} (approver {{this.boss.name}} {{this.boss.lastname}})</option>
2929
{{/each}}
3030
</select>

views/user_add.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<label for="select_inp" class="col-md-3 control-label">Department</label>
5757
<div class="col-md-3">
5858
<select class="form-control" id="select_inp" name="department" aria-describedby="department_help">
59-
{{#each company.departments}}
59+
{{#each departments}}
6060
<option value="{{this.id}}" data-vpp="{{@index}}">{{this.name}}</option>
6161
{{/each}}
6262
</select>

0 commit comments

Comments
 (0)