staff portal: implement looking for the relevant set of portal entries
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 3 Aug 2021 17:58:50 +0000 (13:58 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 1 Sep 2021 18:42:30 +0000 (14:42 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/splash.component.ts

index 82e395b..987a3e3 100644 (file)
@@ -1,4 +1,6 @@
 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';
 
@@ -15,12 +17,15 @@ export class StaffSplashComponent implements OnInit {
     constructor(
         private renderer: Renderer2,
         private pcrud: PcrudService,
+        private auth: AuthService,
+        private org: OrgService,
         private router: Router
     ) {}
 
     ngOnInit() {
         const tmpPortalEntries: any[][] = [];
-        this.pcrud.search('cusppe', {owner: 1}).subscribe(
+        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) {
@@ -30,10 +35,32 @@ export class StaffSplashComponent implements OnInit {
             },
             err => {},
             () => {
+                // find the first set of entries belonging to the
+                // workstation OU or one of its ancestors
+                var filteredPortalEntries: any[][] = [];
+                var foundMatch = false;
+                for (let ou of wsAncestors) {
+                    tmpPortalEntries.forEach((col) => {
+                        if (col !== undefined) {
+                            const filtered = col.filter(x => x !== undefined)
+                                                .filter(x => ou === x.owner());
+                            if (filtered.length) {
+                                foundMatch = true;
+                                filteredPortalEntries.push(filtered);
+                            }
+                        }
+                    });
+                    if (foundMatch) {
+                        break;
+                    } else {
+                        filteredPortalEntries = [];
+                    }
+                }
+
                 // munge the results so that we don't need to
                 // care if there are gaps in the page_col or col_pos
                 // sequences
-                tmpPortalEntries.forEach((col) => {
+                filteredPortalEntries.forEach((col) => {
                     if (col !== undefined) {
                         const filtered = col.filter(x => x !== undefined);
                         this.portalEntries.push(filtered);