From 5ae37c297ba99a16ffe3784051c73faac8725d16 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 19 Feb 2019 11:04:15 -0500 Subject: [PATCH] LP1806087 Catalog holds display WIP Signed-off-by: Bill Erickson --- .../eg2/src/app/staff/catalog/catalog.module.ts | 6 +- .../app/staff/catalog/record/record.component.html | 4 +- .../app/staff/catalog/record/record.component.ts | 7 ++ .../src/app/staff/catalog/search-form.component.ts | 5 +- .../holds-grid/holds-grid.component.html} | 0 .../holds-grid/holds-grid.component.ts} | 94 +++++++++++++++++----- .../staff/share/holds-grid/holds-grid.module.ts | 19 +++++ 7 files changed, 110 insertions(+), 25 deletions(-) rename Open-ILS/src/eg2/src/app/staff/{catalog/record/holds.component.html => share/holds-grid/holds-grid.component.html} (100%) rename Open-ILS/src/eg2/src/app/staff/{catalog/record/holds.component.ts => share/holds-grid/holds-grid.component.ts} (53%) create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.module.ts diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts index cc30f6cc1d..d159437822 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts @@ -2,6 +2,7 @@ import {NgModule} from '@angular/core'; import {StaffCommonModule} from '@eg/staff/common.module'; import {CatalogCommonModule} from '@eg/share/catalog/catalog-common.module'; import {CatalogRoutingModule} from './routing.module'; +import {HoldsGridModule} from '@eg/staff/share/holds-grid/holds-grid.module'; import {CatalogComponent} from './catalog.component'; import {SearchFormComponent} from './search-form.component'; import {ResultsComponent} from './result/results.component'; @@ -21,7 +22,6 @@ import {PartsComponent} from './record/parts.component'; import {PartMergeDialogComponent} from './record/part-merge-dialog.component'; import {BrowseComponent} from './browse.component'; import {BrowseResultsComponent} from './browse/results.component'; -import {HoldsComponent} from './record/holds.component'; @NgModule({ declarations: [ @@ -41,12 +41,12 @@ import {HoldsComponent} from './record/holds.component'; PartMergeDialogComponent, BrowseComponent, BrowseResultsComponent, - HoldsComponent ], imports: [ StaffCommonModule, CatalogCommonModule, - CatalogRoutingModule + CatalogRoutingModule, + HoldsGridModule ], providers: [ StaffCatalogService, diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html index 5f3bf73a8a..68689443d7 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html @@ -42,7 +42,9 @@ - + diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts index 6c935ffdcf..a0ee5c1a7e 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts @@ -127,6 +127,13 @@ export class RecordComponent implements OnInit { this.bib.fleshBibUsers([summary.record]); }); } + + currentSearchOrg(): IdlObject { + if (this.staffCat && this.staffCat.searchContext) { + return this.staffCat.searchContext.searchOrg; + } + return null; + } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts index ed35231d05..785e69e682 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts @@ -100,9 +100,10 @@ export class SearchFormComponent implements OnInit, AfterViewInit { try { // TODO: sometime the selector is not available in the DOM // until even later (even with setTimeouts). Need to fix this. - // Note the error is thrown selectRootElement(). + // Note the error is thrown from selectRootElement(), not the + // call to .focus() on a null reference. this.renderer.selectRootElement(selector).focus(); - } catch(E) {} + } catch (E) {} } /** diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/holds.component.html b/Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.component.html similarity index 100% rename from Open-ILS/src/eg2/src/app/staff/catalog/record/holds.component.html rename to Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.component.html diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/holds.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.component.ts similarity index 53% rename from Open-ILS/src/eg2/src/app/staff/catalog/record/holds.component.ts rename to Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.component.ts index 5c281b6380..1b840e8e7d 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/holds.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.component.ts @@ -5,49 +5,90 @@ import {IdlObject} from '@eg/core/idl.service'; import {NetService} from '@eg/core/net.service'; import {OrgService} from '@eg/core/org.service'; import {AuthService} from '@eg/core/auth.service'; -import {StaffCatalogService} from '../catalog.service'; import {Pager} from '@eg/share/util/pager'; import {GridDataSource} from '@eg/share/grid/grid'; import {GridComponent} from '@eg/share/grid/grid.component'; import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; @Component({ - selector: 'eg-catalog-holds', - templateUrl: 'holds.component.html' + selector: 'eg-holds-grid', + templateUrl: 'holds-grid.component.html' }) -export class HoldsComponent implements OnInit { +export class HoldsGridComponent implements OnInit { + + // If either are set/true, the pickup lib selector will display + @Input() initialPickupLib: number | IdlObject; + + // How to sort when no sort parameters have been applied + // via grid controls. This uses the eg-grid sort format: + // [{name: fname, dir: 'asc'}, {name: fname2, dir: 'desc'}] + @Input() defaultSort: any[]; - recId: number; initDone = false; - gridDataSource: GridDataSource; pickupLib: IdlObject; holdsCount: number; + gridDataSource: GridDataSource; @ViewChild('holdsGrid') private holdsGrid: GridComponent; - @ViewChild('progressDialog') private progressDialog: ProgressDialogComponent; + @ViewChild('progressDialog') + private progressDialog: ProgressDialogComponent; + // Bib record ID. + _recordId: number; @Input() set recordId(id: number) { - this.recId = id; - // Only force new data collection when recordId() - // is invoked after ngInit() has already run. + this._recordId = id; + if (this.initDone) { // reload on update + this.holdsGrid.reload(); + } + } + + _userId: number; + @Input() set userId(id: number) { + this._userId = id; if (this.initDone) { this.holdsGrid.reload(); } } + // Include holds canceled on or after the provided date. + // If no value is passed, canceled holds are not displayed. + _showCanceledSince: Date; + @Input() set showCanceledSince(show: Date) { + this._showCanceledSince = show; + if (this.initDone) { // reload on update + this.holdsGrid.reload(); + } + } + + // Include holds fulfilled on or after hte provided date. + // If no value is passed, fulfilled holds are not displayed. + _showFulfilledSince: Date; + @Input() set showFulfilledSince(show: Date) { + this._showFulfilledSince = show; + if (this.initDone) { // reload on update + this.holdsGrid.reload(); + } + } + constructor( private net: NetService, private org: OrgService, private auth: AuthService, - private staffCat: StaffCatalogService, ) { this.gridDataSource = new GridDataSource(); } ngOnInit() { this.initDone = true; - this.pickupLib = this.staffCat.searchContext.searchOrg; + this.pickupLib = this.org.get(this.initialPickupLib); this.gridDataSource.getRows = (pager: Pager, sort: any[]) => { + + if (this.defaultSort && sort.length === 0) { + // Only use initial sort if sorting has not been modified + // by the grid's own sort controls. + sort = this.defaultSort; + } + // sorting not currently supported return this.fetchHolds(pager, sort); }; @@ -59,18 +100,33 @@ export class HoldsComponent implements OnInit { } fetchHolds(pager: Pager, sort: any[]): Observable { - if (!this.recId) { return of([]); } - const orgs = this.org.descendants(this.pickupLib, true); + // We need at least one filter. + if (!this._recordId && !this.pickupLib && !this._userId) { + return of([]); + } - const restrictions = { + const restrictions: any = { is_staff_request: true, - fulfillment_time: null, - cancel_time: null, - record_id: this.recId, - pickup_lib: orgs + fulfillment_time: this._showFulfilledSince ? + this._showFulfilledSince.toISOString() : null, + cancel_time: this._showCanceledSince ? + this._showCanceledSince.toISOString() : null, }; + if (this.pickupLib) { + restrictions.pickup_lib = + this.org.descendants(this.pickupLib, true); + } + + if (this._recordId) { + restrictions.record_id = this._recordId; + } + + if (this._userId) { + restrictions.usr_id = this._userId; + } + const orderBy: any = []; sort.forEach(obj => { const subObj: any = {}; diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.module.ts b/Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.module.ts new file mode 100644 index 0000000000..13647291f2 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/holds-grid/holds-grid.module.ts @@ -0,0 +1,19 @@ +import {NgModule} from '@angular/core'; +import {StaffCommonModule} from '@eg/staff/common.module'; +import {HoldsGridComponent} from './holds-grid.component'; + +@NgModule({ + declarations: [ + HoldsGridComponent + ], + imports: [ + StaffCommonModule + ], + exports: [ + HoldsGridComponent + ], + providers: [ + ] +}) + +export class HoldsGridModule {} -- 2.11.0