From: Bill Erickson Date: Fri, 2 Aug 2019 17:18:09 +0000 (-0400) Subject: LP1818927 Angular admin splash page sorting X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0e9694e454ea47de7310e05b858a4362ac3f3314;p=working%2FEvergreen.git LP1818927 Angular admin splash page sorting Adds support for a sortKey value that may be applied to a link table link. When present, the sortKey is used to group link links together and indicates where in the overall page the group should be sorted. Links within each group are subsequently sorted by label. Non grouped links are sorted solely by label. Adds a default set of sortKey values to Angular server admin splash page. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html index 99cb4781b7..965f790685 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html @@ -3,45 +3,45 @@
- + - - - - - - - - - - - - - @@ -53,29 +53,29 @@ routerLink="/staff/admin/server/config/hold_matrix_weights"> - - - - - - - - - - - - diff --git a/Open-ILS/src/eg2/src/app/staff/share/link-table/link-table.component.ts b/Open-ILS/src/eg2/src/app/staff/share/link-table/link-table.component.ts index 9b06c92732..2652956dc8 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/link-table/link-table.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/link-table/link-table.component.ts @@ -4,6 +4,7 @@ interface LinkTableLink { label: string; url?: string; routerLink?: string; + sortKey?: string; } @Component({ @@ -25,6 +26,8 @@ export class LinkTableComponent implements AfterViewInit { } ngAfterViewInit() { + this.sortLinks(); + // table-ize the links const rowCount = Math.ceil(this.links.length / this.columnCount); this.colWidth = Math.floor(12 / this.columnCount); // Bootstrap 12-grid @@ -47,6 +50,33 @@ export class LinkTableComponent implements AfterViewInit { } }); } + + // Links with sortKeys are first sorted and grouped by sortKey. + // Links within each group are then sorted by label. Ungrouped + // links are sorted by label only. + sortLinks() { + this.links = this.links.sort((a: LinkTableLink, b: LinkTableLink) => { + let aVal: string = a.label; + let bVal: string = b.label; + + if (a.sortKey) { + if (b.sortKey) { + if (b.sortKey === a.sortKey) { + // Sort within groups on label + } else { + aVal = a.sortKey; + bVal = b.sortKey; + } + } else { + aVal = a.sortKey; + } + } else if (b.sortKey) { + bVal = b.sortKey; + } + + return aVal.toLowerCase() < bVal.toLowerCase() ? -1 : 1; + }); + } } @Component({ @@ -58,6 +88,7 @@ export class LinkTableLinkComponent implements OnInit { @Input() label: string; @Input() url: string; @Input() routerLink: string; + @Input() sortKey: string; constructor(@Host() private linkTable: LinkTableComponent) {} @@ -65,7 +96,8 @@ export class LinkTableLinkComponent implements OnInit { this.linkTable.links.push({ label : this.label, url: this.url, - routerLink: this.routerLink + routerLink: this.routerLink, + sortKey: this.sortKey }); } }