LP#626157 Ang2 experiments
authorBill Erickson <berickxx@gmail.com>
Mon, 11 Dec 2017 15:35:59 +0000 (10:35 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Dec 2017 17:39:51 +0000 (12:39 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/webby-src/src/app/core/idl.ts
Open-ILS/webby-src/src/app/share/catalog/search-context.ts
Open-ILS/webby-src/src/app/share/org-select.component.html [new file with mode: 0644]
Open-ILS/webby-src/src/app/share/org-select.component.ts [new file with mode: 0644]
Open-ILS/webby-src/src/app/staff/nav.component.html
Open-ILS/webby-src/src/app/staff/share/org-select.component.html [deleted file]
Open-ILS/webby-src/src/app/staff/share/org-select.component.ts [deleted file]
Open-ILS/webby-src/src/app/staff/splash.component.html
Open-ILS/webby-src/src/app/staff/staff.module.ts

index e503ba7..8f46933 100644 (file)
@@ -36,15 +36,20 @@ export class EgIdlService {
     }
 
     parseIdl(): void {
-        let this_ = this;
-        this_.classes = _preload_fieldmapper_IDL;
+
+        try {
+            this.classes = _preload_fieldmapper_IDL;
+        } catch (E) {
+            console.error('IDL (IDL2js) not found.  Is the system running?');
+            return;
+        }
 
         /**
          * Creates the class constructor and getter/setter
          * methods for each IDL class.
          */
         let mkclass = (cls, fields) => {
-            this_.classes[cls].classname = cls;
+            this.classes[cls].classname = cls;
 
             // This dance lets us encode each IDL object with the
             // EgIdlObject interface.  Useful for adding type restrictions
@@ -67,16 +72,16 @@ export class EgIdlService {
                 return x;
             });
 
-            this_.constructors[cls] = generator();
+            this.constructors[cls] = generator();
 
             // global class constructors required for JSON_v1.js
             // TODO: polluting the window namespace w/ every IDL class 
             // is less than ideal.
-            window[cls] = this_.constructors[cls]; 
+            window[cls] = this.constructors[cls]; 
         }
 
-        for (var cls in this_.classes) 
-            mkclass(cls, this_.classes[cls].fields);
+        for (var cls in this.classes) 
+            mkclass(cls, this.classes[cls].fields);
     };
 }
 
index 5503580..4b1914e 100644 (file)
@@ -70,7 +70,10 @@ export class CatalogSearchContext {
         let ids = [];
         for (
             let idx = this.pager.offset;
-            idx < this.pager.offset + this.pager.limit;
+            idx < Math.min( 
+                this.pager.offset + this.pager.limit, 
+                this.pager.resultCount
+            );
             idx++
         ) {ids.push(this.resultIds[idx])}
         return ids;
diff --git a/Open-ILS/webby-src/src/app/share/org-select.component.html b/Open-ILS/webby-src/src/app/share/org-select.component.html
new file mode 100644 (file)
index 0000000..d7b9101
--- /dev/null
@@ -0,0 +1,15 @@
+
+<!-- todo disabled -->
+<ng-template #displayTemplate let-r="result">
+{{r.label}}
+</ng-template>
+
+<input type="text" 
+  class="form-control" 
+  [placeholder]="placeholder"
+  [(ngModel)]="selected" 
+  [ngbTypeahead]="filter"
+  [resultTemplate]="displayTemplate"
+  [inputFormatter]="formatter"
+  (selectItem)="orgChanged($event)"
+/>
diff --git a/Open-ILS/webby-src/src/app/share/org-select.component.ts b/Open-ILS/webby-src/src/app/share/org-select.component.ts
new file mode 100644 (file)
index 0000000..7738215
--- /dev/null
@@ -0,0 +1,102 @@
+import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
+import {Observable} from 'rxjs/Observable';
+import {map, debounceTime} from 'rxjs/operators';
+import {EgAuthService} from '@eg/core/auth';
+import {EgStoreService} from '@eg/core/store';
+import {EgOrgService} from '@eg/core/org';
+import {EgIdlObject} from '@eg/core/idl';
+import {NgbTypeaheadSelectItemEvent} from '@ng-bootstrap/ng-bootstrap';
+
+// Use a unicode char for spacing instead of ASCII=32 so the browser 
+// won't collapse the nested display entries down to a single space.
+const PAD_SPACE: string = ' '; // U+2007 
+
+interface OrgDisplay {
+  id: number;
+  label: string;
+  disabled: boolean;
+}
+
+@Component({
+  selector: 'eg-org-select',
+  templateUrl: './org-select.component.html'
+})
+export class EgOrgSelectComponent implements OnInit {
+
+    selected: OrgDisplay;
+    startOrg: EgIdlObject;
+    hidden: number[] = [];
+    disabled: number[] = [];
+
+    // Read-only properties optionally provided by the calling component.
+    @Input() placeholder: string;
+    @Input() stickySetting: string;
+    @Input() displayField: string = 'shortname';
+
+    @Input() set initialOrg(org: EgIdlObject) {
+        if (org) this.startOrg = org;
+    }
+
+    @Input() set hideOrgs(ids: number[]) {
+        if (ids) this.hidden = ids;
+    }
+
+    @Input() set disableOrgs(ids: number[]) {
+        if (ids) this.disabled = ids;
+    }
+
+    /** Emitted when the org unit value is changed via the selector.
+      * Does not fire on initialOrg.
+      */
+    @Output() onChange = new EventEmitter<EgIdlObject>();
+
+    constructor(
+      private auth: EgAuthService,
+      private store: EgStoreService,
+      private org: EgOrgService 
+    ) {}
+    
+    ngOnInit() {
+        if (this.startOrg) {
+            this.selected = this.formatForDisplay(this.startOrg);
+        }
+    }
+
+    formatForDisplay(org: EgIdlObject): OrgDisplay {
+        return {
+            id : org.id(),
+            label : PAD_SPACE.repeat(org.ou_type().depth()) 
+              + org[this.displayField](),
+            disabled : false
+        };
+    }
+
+    orgChanged(selEvent: NgbTypeaheadSelectItemEvent) {
+        this.onChange.emit(this.org.get(selEvent.item.id));
+    }
+
+    // Formats the selected value
+    formatter = (result: OrgDisplay) => result.label.trim();
+
+    filter = (text$: Observable<string>): Observable<OrgDisplay[]> => {
+        return text$
+            .debounceTime(100)
+            .distinctUntilChanged()
+            .map(term => {
+
+                return this.org.list().filter(org => {
+
+                    // Find orgs matching the search term
+                    return org[this.displayField]()
+                      .toLowerCase().indexOf(term.toLowerCase()) > -1
+
+                }).filter(org => { // Exclude hidden orgs
+                    return this.hidden.filter(
+                        id => {return org.id() == id}).length == 0;
+
+                }).map(org => {return this.formatForDisplay(org)})
+            });
+    }
+}
+
+
index 4206cd4..7b1a052 100644 (file)
         </a>
         <div class="dropdown-menu" ngbDropdownMenu>
           <a class="dropdown-item"
-              routerLink="/staff/circ/patron/bcsearch">
+              routerLink="/staff/splash">
             <span class="material-icons">trending_up</span>
             <span i18n>Check Out</span>
           </a>
-          <a class="dropdown-item" routerLink="/staff">
+          <a class="dropdown-item" routerLink="/staff/splash">
             <span class="material-icons">trending_down</span>
             <span i18n>Check In</span>
           </a>
         </div>
       </div>
     </div>
+    <div class="navbar-nav">
+      <div ngbDropdown class="nav-item dropdown">
+        <a ngbDropdownToggle i18n class="nav-link dropdown-toggle">
+         Cataloging
+        </a>
+        <div class="dropdown-menu" ngbDropdownMenu>
+          <a class="dropdown-item"
+              routerLink="/staff/catalog/search">
+            <span class="material-icons">search</span>
+            <span i18n>Search the Catalog</span>
+          </a>
+        </div>
+      </div>
+    </div>
+
     <div class="navbar-nav mr-auto"></div>
     <div class="navbar-nav">
       <div ngbDropdown class="nav-item dropdown" placement="bottom-right">
diff --git a/Open-ILS/webby-src/src/app/staff/share/org-select.component.html b/Open-ILS/webby-src/src/app/staff/share/org-select.component.html
deleted file mode 100644 (file)
index d7b9101..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-
-<!-- todo disabled -->
-<ng-template #displayTemplate let-r="result">
-{{r.label}}
-</ng-template>
-
-<input type="text" 
-  class="form-control" 
-  [placeholder]="placeholder"
-  [(ngModel)]="selected" 
-  [ngbTypeahead]="filter"
-  [resultTemplate]="displayTemplate"
-  [inputFormatter]="formatter"
-  (selectItem)="orgChanged($event)"
-/>
diff --git a/Open-ILS/webby-src/src/app/staff/share/org-select.component.ts b/Open-ILS/webby-src/src/app/staff/share/org-select.component.ts
deleted file mode 100644 (file)
index 7738215..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
-import {Observable} from 'rxjs/Observable';
-import {map, debounceTime} from 'rxjs/operators';
-import {EgAuthService} from '@eg/core/auth';
-import {EgStoreService} from '@eg/core/store';
-import {EgOrgService} from '@eg/core/org';
-import {EgIdlObject} from '@eg/core/idl';
-import {NgbTypeaheadSelectItemEvent} from '@ng-bootstrap/ng-bootstrap';
-
-// Use a unicode char for spacing instead of ASCII=32 so the browser 
-// won't collapse the nested display entries down to a single space.
-const PAD_SPACE: string = ' '; // U+2007 
-
-interface OrgDisplay {
-  id: number;
-  label: string;
-  disabled: boolean;
-}
-
-@Component({
-  selector: 'eg-org-select',
-  templateUrl: './org-select.component.html'
-})
-export class EgOrgSelectComponent implements OnInit {
-
-    selected: OrgDisplay;
-    startOrg: EgIdlObject;
-    hidden: number[] = [];
-    disabled: number[] = [];
-
-    // Read-only properties optionally provided by the calling component.
-    @Input() placeholder: string;
-    @Input() stickySetting: string;
-    @Input() displayField: string = 'shortname';
-
-    @Input() set initialOrg(org: EgIdlObject) {
-        if (org) this.startOrg = org;
-    }
-
-    @Input() set hideOrgs(ids: number[]) {
-        if (ids) this.hidden = ids;
-    }
-
-    @Input() set disableOrgs(ids: number[]) {
-        if (ids) this.disabled = ids;
-    }
-
-    /** Emitted when the org unit value is changed via the selector.
-      * Does not fire on initialOrg.
-      */
-    @Output() onChange = new EventEmitter<EgIdlObject>();
-
-    constructor(
-      private auth: EgAuthService,
-      private store: EgStoreService,
-      private org: EgOrgService 
-    ) {}
-    
-    ngOnInit() {
-        if (this.startOrg) {
-            this.selected = this.formatForDisplay(this.startOrg);
-        }
-    }
-
-    formatForDisplay(org: EgIdlObject): OrgDisplay {
-        return {
-            id : org.id(),
-            label : PAD_SPACE.repeat(org.ou_type().depth()) 
-              + org[this.displayField](),
-            disabled : false
-        };
-    }
-
-    orgChanged(selEvent: NgbTypeaheadSelectItemEvent) {
-        this.onChange.emit(this.org.get(selEvent.item.id));
-    }
-
-    // Formats the selected value
-    formatter = (result: OrgDisplay) => result.label.trim();
-
-    filter = (text$: Observable<string>): Observable<OrgDisplay[]> => {
-        return text$
-            .debounceTime(100)
-            .distinctUntilChanged()
-            .map(term => {
-
-                return this.org.list().filter(org => {
-
-                    // Find orgs matching the search term
-                    return org[this.displayField]()
-                      .toLowerCase().indexOf(term.toLowerCase()) > -1
-
-                }).filter(org => { // Exclude hidden orgs
-                    return this.hidden.filter(
-                        id => {return org.id() == id}).length == 0;
-
-                }).map(org => {return this.formatForDisplay(org)})
-            });
-    }
-}
-
-
index 0259031..a278fd1 100644 (file)
@@ -1,10 +1,7 @@
 <b>Staff Splash Page</b>
 
 <br/>
-Some links to test...
 
 <a routerLink="/staff/admin/workstation/workstations">Workstation Admin</a>
 <br/>
-<br/>
-<a routerLink="/staff/catalog/search">Catalog Test</a>
 
index 692e6f6..526d8c2 100644 (file)
@@ -9,7 +9,7 @@ import {EgStaffRoutingModule} from './routing.module';
 import {EgStaffNavComponent} from './nav.component';
 import {EgStaffLoginComponent} from './login.component';
 import {EgStaffSplashComponent} from './splash.component';
-import {EgOrgSelectComponent} from './share/org-select.component';
+import {EgOrgSelectComponent} from '@eg/share/org-select.component';
 
 @NgModule({
   declarations: [