From: Bill Erickson Date: Thu, 26 Dec 2019 18:18:26 +0000 (-0500) Subject: LP1857350 Org selector sorts by display value X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4ab843f4988f147ef1f5e8fcd8643d3ad8998c4d;p=working%2FEvergreen.git LP1857350 Org selector sorts by display value When displaying the org unit selector, sort each set of children by the display label (defaults to shortname). Fixes issues with the org server sortTree function and adds a unit test to test the repaired sort function. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/core/org.service.ts b/Open-ILS/src/eg2/src/app/core/org.service.ts index c666957d2c..f99b210556 100644 --- a/Open-ILS/src/eg2/src/app/core/org.service.ts +++ b/Open-ILS/src/eg2/src/app/core/org.service.ts @@ -150,11 +150,11 @@ export class OrgService { if (!sortField) { sortField = 'shortname'; } if (!node) { node = this.orgTree; } node.children( - node.children.sort((a, b) => { + node.children().sort((a, b) => { return a[sortField]() < b[sortField]() ? -1 : 1; }) ); - node.children.forEach(n => this.sortTree(n)); + node.children().forEach(n => this.sortTree(sortField, n)); } absorbTree(node?: IdlObject): void { diff --git a/Open-ILS/src/eg2/src/app/core/org.spec.ts b/Open-ILS/src/eg2/src/app/core/org.spec.ts index 78c2f26657..e764ec74f4 100644 --- a/Open-ILS/src/eg2/src/app/core/org.spec.ts +++ b/Open-ILS/src/eg2/src/app/core/org.spec.ts @@ -61,6 +61,12 @@ describe('OrgService', () => { expect(orgService.root().id()).toEqual(1); }); + it('should sort tree by shortname', () => { + initTestData(); + orgService.sortTree('shortname'); + expect(orgService.root().children()[0].shortname()).toEqual('A'); + }); + }); diff --git a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts index f455c36bf3..334902ec21 100644 --- a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts @@ -100,6 +100,8 @@ export class OrgSelectComponent implements OnInit { // Does not fire on initialOrg @Output() onChange = new EventEmitter(); + sortedOrgs: IdlObject[] = []; + constructor( private auth: AuthService, private store: StoreService, @@ -109,6 +111,14 @@ export class OrgSelectComponent implements OnInit { ngOnInit() { + // Sort the tree and reabsorb to propagate the sorted nodes to the + // org.list() used by this component. + this.org.sortTree(this.displayField); + this.org.absorbTree(); + // Maintain our own copy of the org list in case the org service + // is sorted in a different manner by other parts of the code. + this.sortedOrgs = this.org.list(); + // Apply a default org unit if desired and possible. if (!this.startOrg && this.applyDefault && this.auth.user()) { // note: ws_ou defaults to home_ou on the server @@ -186,7 +196,7 @@ export class OrgSelectComponent implements OnInit { ), map(term => { - let orgs = this.org.list().filter(org => + let orgs = this.sortedOrgs.filter(org => this.hidden.filter(id => org.id() === id).length === 0 ); diff --git a/Open-ILS/src/eg2/src/test_data/eg_mock.js b/Open-ILS/src/eg2/src/test_data/eg_mock.js index 3db357974f..d0588f5c06 100644 --- a/Open-ILS/src/eg2/src/test_data/eg_mock.js +++ b/Open-ILS/src/eg2/src/test_data/eg_mock.js @@ -30,11 +30,13 @@ window._eg_mock_data = { org2.id(2); org2.parent_ou(1); org2.ou_type(type2); + org2.shortname('B'); // to test sorting var org3 = idlService.create('aou'); org3.id(3); org3.parent_ou(1); org3.ou_type(type2); + org3.shortname('A'); // to test sorting var org4 = idlService.create('aou'); org4.id(4);