From 1109d6189de529de3c1e0fee553eac5f258616be Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 13 Nov 2018 11:09:11 -0500 Subject: [PATCH] record checkboxes continued Signed-off-by: Bill Erickson --- .../eg2/src/app/share/catalog/basket.service.ts | 23 ++++++- .../eg2/src/app/share/catalog/catalog.service.ts | 11 ++- .../app/staff/catalog/result/record.component.html | 2 +- .../app/staff/catalog/result/record.component.ts | 21 ++++-- .../staff/catalog/result/results.component.html | 3 +- .../app/staff/catalog/result/results.component.ts | 78 ++++++++++++++++++---- 6 files changed, 113 insertions(+), 25 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/catalog/basket.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/basket.service.ts index 46efcc4671..7db2749e50 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/basket.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/basket.service.ts @@ -1,4 +1,4 @@ -import {Injectable} from '@angular/core'; +import {Injectable, EventEmitter} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {StoreService} from '@eg/core/store.service'; import {NetService} from '@eg/core/net.service'; @@ -19,12 +19,18 @@ export class BasketService { idList: number[]; + // Fired every time our list of ID's are updated. + onChange: EventEmitter; + constructor( private net: NetService, private pcrud: PcrudService, private store: StoreService, private anonCache: AnonCacheService - ) { this.idList = []; } + ) { + this.idList = []; + this.onChange = new EventEmitter(); + } hasRecordId(id: number): boolean { return this.idList.indexOf(Number(id)) > -1; @@ -62,20 +68,31 @@ export class BasketService { return this.anonCache.setItem(cacheKey, BASKET_CACHE_ATTR, this.idList) .then(cacheKey => { this.store.setLoginSessionItem(BASKET_CACHE_KEY_COOKIE, cacheKey); + this.onChange.emit(this.idList); return this.idList; }); } addRecordIds(ids: number[]): Promise { ids = ids.filter(id => !this.hasRecordId(id)); // avoid dupes + + if (ids.length === 0) { + return Promise.resolve(this.idList); + } return this.setRecordIds( this.idList.concat(ids.map(id => Number(id)))); } removeRecordIds(ids: number[]): Promise { + + if (this.idList.length === 0) { + return Promise.resolve(this.idList); + } + const wantedIds = this.idList.filter( id => ids.indexOf(Number(id)) < 0); - return this.setRecordIds(wantedIds); + + return this.setRecordIds(wantedIds); // OK if empty } } diff --git a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts index 95967cb606..2dc07c521f 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts @@ -1,4 +1,4 @@ -import {Injectable} from '@angular/core'; +import {Injectable, EventEmitter} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {mergeMap} from 'rxjs/operators/mergeMap'; import {map} from 'rxjs/operators/map'; @@ -37,6 +37,9 @@ export class CatalogService { lastFacetData: any; lastFacetKey: string; + // Allow anyone to watch for completed searches. + onSearchComplete: EventEmitter; + constructor( private idl: IdlService, private net: NetService, @@ -44,7 +47,10 @@ export class CatalogService { private unapi: UnapiService, private pcrud: PcrudService, private bibService: BibRecordService - ) {} + ) { + this.onSearchComplete = new EventEmitter(); + + } search(ctx: CatalogSearchContext): Promise { ctx.searchState = CatalogSearchState.SEARCHING; @@ -67,6 +73,7 @@ export class CatalogService { ).subscribe(result => { this.applyResultData(ctx, result); ctx.searchState = CatalogSearchState.COMPLETE; + this.onSearchComplete.emit(ctx); resolve(); }); }); diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.html index 6bf3ec9eb8..54b79c195b 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.html @@ -17,7 +17,7 @@ {{index + 1 + searchContext.pager.offset}}. -