Skip to content

Commit

Permalink
#111 Improve personnel search by removing accents
Browse files Browse the repository at this point in the history
  • Loading branch information
robo-w committed Oct 3, 2021
1 parent b4d32e8 commit 76f906d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions main/resources/ReleaseNotes/2.7.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
* FMD-211 Fix display of units on hierarchy-edit page
* Caused by breaking change of upgrade to knockout.js 3.4.2 to 3.5.1
* Fixed by using named templates instead of html directly inside of 'knockout sortable'
* \#111 ANSIfy personnel names
* Remove any accents in names and search terms on searching for crew members
1 change: 1 addition & 0 deletions main/view/src/main/webapp/static/js/edit/models/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ define(function() {
this.id = data.id;
this.fullname = data.lastname + " " + data.firstname;
this.personnelId = data.personnelId;
this.normalizedFullname = this.fullname.normalizeAccents();
};

return Person;
Expand Down
8 changes: 4 additions & 4 deletions main/view/src/main/webapp/static/js/edit/viewmodels/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ define(["jquery", "knockout", "../models/editableunit", "../models/person", "dat
if (!filterVal) {
return [];
}
return $.map(filterVal.split(" "), function(item) {
return new RegExp(RegExp.escape(item), "i");
return $.map(filterVal.split(" "), function(singleSearchTerm) {
return new RegExp(RegExp.escape(singleSearchTerm.normalizeAccents()), "i");
});
}, this);

Expand All @@ -70,10 +70,10 @@ define(["jquery", "knockout", "../models/editableunit", "../models/person", "dat
this.filtered = this.persons.extend({
list: {
filter: {
regex: function(item) {
regex: function(personToTest) {
var regex = self.regex(), i;
for (i = 0; i < regex.length; i++) {
if (!regex[i].test(item.pid) && !regex[i].test(item.fullname)) {
if (!regex[i].test(personToTest.personnelId) && !regex[i].test(personToTest.normalizedFullname)) {
return false;
}
}
Expand Down
5 changes: 5 additions & 0 deletions main/view/src/main/webapp/static/js/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ define(["jquery", "knockout", "utils/conf"], function ($, ko, conf) {
return '&' + String.escapeChars[m] + ';';
});
};

String.prototype.normalizeAccents = function () {
// From https://stackoverflow.com/questions/5700636/using-javascript-to-perform-text-matches-with-without-accented-characters
return this.normalize('NFD').replace(/[\u0300-\u036f]/g, "");
};
});

0 comments on commit 76f906d

Please sign in to comment.