From: Galen Charlton Date: Mon, 2 Aug 2021 23:06:44 +0000 (-0400) Subject: LP#1938835: make the Angular staff portal/home page dynamic X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c0a44748f260138472f0f0ffbfbb14468a8fc91b;p=Evergreen.git LP#1938835: make the Angular staff portal/home page dynamic Details and test plan will be in the commit with the release notes. Sponsored-by: Pioneer Library System Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/eg2/src/app/staff/splash.component.html b/Open-ILS/src/eg2/src/app/staff/splash.component.html index 450a3e5916..6f95510a2f 100644 --- a/Open-ILS/src/eg2/src/app/staff/splash.component.html +++ b/Open-ILS/src/eg2/src/app/staff/splash.component.html @@ -30,114 +30,58 @@
-
+
-
-

Circulation and Patrons

+
+

{{header.label()}}

-
-
- -
-
-
-

Item Search and Cataloging

-
-
-
-
-
- - - - - + + -
- - -
-
-
-
- -
-
-
-

Administration

-
-
-
- - - +
+
+ + + + +
+
+ +
+

{{entry.label()}}

+
+
+ +
+
+
+
+
+
diff --git a/Open-ILS/src/eg2/src/app/staff/splash.component.ts b/Open-ILS/src/eg2/src/app/staff/splash.component.ts index 6756b6519c..ccf95222f9 100644 --- a/Open-ILS/src/eg2/src/app/staff/splash.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/splash.component.ts @@ -1,4 +1,7 @@ -import {Component, OnInit, Renderer2} from '@angular/core'; +import {Component, OnInit, AfterViewInit, Directive, ElementRef, Renderer2} from '@angular/core'; +import {OrgService} from '@eg/core/org.service'; +import {AuthService} from '@eg/core/auth.service'; +import {PcrudService} from '@eg/core/pcrud.service'; import {Router} from '@angular/router'; @Component({ @@ -8,16 +11,82 @@ import {Router} from '@angular/router'; export class StaffSplashComponent implements OnInit { catSearchQuery: string; + portalEntries: any[][] = []; + portalHeaders: any[] = []; constructor( private renderer: Renderer2, + private pcrud: PcrudService, + private auth: AuthService, + private org: OrgService, private router: Router ) {} ngOnInit() { + const tmpPortalEntries: any[][] = []; + const wsAncestors = this.org.ancestors(this.auth.user().ws_ou(), true); + this.pcrud.search('cusppe', {owner: wsAncestors}).subscribe( + item => { + const page_col = item.page_col(); + if (tmpPortalEntries[page_col] === undefined) { + tmpPortalEntries[page_col] = []; + } + if (tmpPortalEntries[page_col][item.col_pos()] === undefined) { + tmpPortalEntries[page_col][item.col_pos()] = []; + } + // we push here, then flatten the results when we filter + // by owner later because (page_col, col_pos) is not + // guaranteed to be unique + tmpPortalEntries[page_col][item.col_pos()].push(item); + }, + err => {}, + () => { + // find the first set of entries belonging to the + // workstation OU or one of its ancestors + let filteredPortalEntries: any[][] = []; + let foundMatch = false; + for (const ou of wsAncestors) { + tmpPortalEntries.forEach((col) => { + if (col !== undefined) { + const filtered = col.reduce((prev, curr) => prev.concat(curr), []) + .filter(x => x !== undefined) + .filter(x => ou === x.owner()); + if (filtered.length) { + foundMatch = true; + filteredPortalEntries.push(filtered); + } + } + }); + if (foundMatch) { + break; + } else { + filteredPortalEntries = []; + } + } - // Focus catalog search form - this.renderer.selectRootElement('#catalog-search-input').focus(); + // munge the results so that we don't need to + // care if there are gaps in the page_col or col_pos + // sequences + filteredPortalEntries.forEach((col) => { + if (col !== undefined) { + const filtered = col.filter(x => x !== undefined); + this.portalEntries.push(filtered); + filtered.forEach((entry) => { + if (entry.entry_type() === 'header') { + this.portalHeaders[this.portalEntries.length - 1] = entry; + } + }); + } + }); + // supply an empty header entry in case a column was + // defined without a header + this.portalEntries.forEach((col, i) => { + if (this.portalHeaders.length <= i) { + this.portalHeaders[i] = undefined; + } + }); + } + ); } searchCatalog(): void { @@ -30,4 +99,13 @@ export class StaffSplashComponent implements OnInit { } } +@Directive({ + selector: '[egAutofocus]' +}) +export class AutofocusDirective implements AfterViewInit { + constructor(private host: ElementRef) {} + ngAfterViewInit() { + this.host.nativeElement.focus(); + } +} diff --git a/Open-ILS/src/eg2/src/app/staff/staff.module.ts b/Open-ILS/src/eg2/src/app/staff/staff.module.ts index dd22f93e17..34bf589ef7 100644 --- a/Open-ILS/src/eg2/src/app/staff/staff.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/staff.module.ts @@ -5,7 +5,7 @@ import {StaffComponent} from './staff.component'; import {StaffRoutingModule} from './routing.module'; import {StaffNavComponent} from './nav.component'; import {StaffLoginComponent} from './login.component'; -import {StaffSplashComponent} from './splash.component'; +import {StaffSplashComponent, AutofocusDirective} from './splash.component'; import {AboutComponent} from './about.component'; @NgModule({ @@ -13,6 +13,7 @@ import {AboutComponent} from './about.component'; StaffComponent, StaffNavComponent, StaffSplashComponent, + AutofocusDirective, StaffLoginComponent, AboutComponent ],