From: Bill Erickson Date: Mon, 11 Dec 2017 15:35:59 +0000 (-0500) Subject: LP#626157 Ang2 experiments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8d4fbc832101ea35466895e95bb784a25e2473d4;p=working%2FEvergreen.git LP#626157 Ang2 experiments Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/webby-src/src/app/core/idl.ts b/Open-ILS/webby-src/src/app/core/idl.ts index e503ba74a4..8f46933954 100644 --- a/Open-ILS/webby-src/src/app/core/idl.ts +++ b/Open-ILS/webby-src/src/app/core/idl.ts @@ -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); }; } diff --git a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts index 5503580e81..4b1914e851 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts @@ -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 index 0000000000..d7b9101c89 --- /dev/null +++ b/Open-ILS/webby-src/src/app/share/org-select.component.html @@ -0,0 +1,15 @@ + + + +{{r.label}} + + + 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 index 0000000000..7738215b4b --- /dev/null +++ b/Open-ILS/webby-src/src/app/share/org-select.component.ts @@ -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(); + + 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): Observable => { + 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)}) + }); + } +} + + diff --git a/Open-ILS/webby-src/src/app/staff/nav.component.html b/Open-ILS/webby-src/src/app/staff/nav.component.html index 4206cd448f..7b1a05298f 100644 --- a/Open-ILS/webby-src/src/app/staff/nav.component.html +++ b/Open-ILS/webby-src/src/app/staff/nav.component.html @@ -14,11 +14,11 @@ + +