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 {
expect(orgService.root().id()).toEqual(1);
});
+ it('should sort tree by shortname', () => {
+ initTestData();
+ orgService.sortTree('shortname');
+ expect(orgService.root().children()[0].shortname()).toEqual('A');
+ });
+
});
return this.org.get(this.selected.id);
}
+ sortedOrgs: IdlObject[] = [];
+
constructor(
private auth: AuthService,
private store: StoreService,
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
),
map(term => {
- let orgs = this.org.list().filter(org =>
+ let orgs = this.sortedOrgs.filter(org =>
this.hidden.filter(id => org.id() === id).length === 0
);
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);