1 import {Component, OnInit, AfterViewInit, Directive, ElementRef, Renderer2} from '@angular/core';
2 import {OrgService} from '@eg/core/org.service';
3 import {AuthService} from '@eg/core/auth.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {Router} from '@angular/router';
8 templateUrl: 'splash.component.html'
11 export class StaffSplashComponent implements OnInit {
13 catSearchQuery: string;
14 portalEntries: any[][] = [];
15 portalHeaders: any[] = [];
18 private renderer: Renderer2,
19 private pcrud: PcrudService,
20 private auth: AuthService,
21 private org: OrgService,
22 private router: Router
26 const tmpPortalEntries: any[][] = [];
27 const wsAncestors = this.org.ancestors(this.auth.user().ws_ou(), true);
28 this.pcrud.search('cusppe', {owner: wsAncestors}).subscribe(
30 const page_col = item.page_col();
31 if (tmpPortalEntries[page_col] === undefined) {
32 tmpPortalEntries[page_col] = [];
34 if (tmpPortalEntries[page_col][item.col_pos()] === undefined) {
35 tmpPortalEntries[page_col][item.col_pos()] = [];
37 // we push here, then flatten the results when we filter
38 // by owner later because (page_col, col_pos) is not
39 // guaranteed to be unique
40 tmpPortalEntries[page_col][item.col_pos()].push(item);
44 // find the first set of entries belonging to the
45 // workstation OU or one of its ancestors
46 let filteredPortalEntries: any[][] = [];
47 let foundMatch = false;
48 for (const ou of wsAncestors) {
49 tmpPortalEntries.forEach((col) => {
50 if (col !== undefined) {
51 const filtered = col.reduce((prev, curr) => prev.concat(curr), [])
52 .filter(x => x !== undefined)
53 .filter(x => ou === x.owner());
54 if (filtered.length) {
56 filteredPortalEntries.push(filtered);
63 filteredPortalEntries = [];
67 // munge the results so that we don't need to
68 // care if there are gaps in the page_col or col_pos
70 filteredPortalEntries.forEach((col) => {
71 if (col !== undefined) {
72 const filtered = col.filter(x => x !== undefined);
73 this.portalEntries.push(filtered);
74 filtered.forEach((entry) => {
75 if (entry.entry_type() === 'header') {
76 this.portalHeaders[this.portalEntries.length - 1] = entry;
81 // supply an empty header entry in case a column was
82 // defined without a header
83 this.portalEntries.forEach((col, i) => {
84 if (this.portalHeaders.length <= i) {
85 this.portalHeaders[i] = undefined;
92 searchCatalog(): void {
93 if (!this.catSearchQuery) { return; }
96 ['/staff/catalog/search'],
97 {queryParams: {query : this.catSearchQuery}}
103 selector: '[egAutofocus]'
105 export class AutofocusDirective implements AfterViewInit {
106 constructor(private host: ElementRef) {}
109 this.host.nativeElement.focus();