From 7475532a3a43fafe56e18d92eb2e37b60687c121 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 13 Nov 2018 12:54:53 -0500 Subject: [PATCH] basket actions Signed-off-by: Bill Erickson --- .../eg2/src/app/share/catalog/basket.service.ts | 4 ++ .../staff/catalog/basket-actions.component.html | 23 +++++++++++ .../app/staff/catalog/basket-actions.component.ts | 48 ++++++++++++++++++++++ .../eg2/src/app/staff/catalog/catalog.module.ts | 4 +- .../staff/catalog/result/results.component.html | 2 +- .../app/staff/catalog/result/results.component.ts | 12 +++--- .../app/staff/catalog/search-form.component.html | 12 +----- 7 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.ts 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 7db2749e50..99c8c24ca0 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 @@ -94,6 +94,10 @@ export class BasketService { return this.setRecordIds(wantedIds); // OK if empty } + + removeAllRecordIds(): Promise { + return this.setRecordIds([]); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html new file mode 100644 index 0000000000..be1f5bb386 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html @@ -0,0 +1,23 @@ + +
+ +
+ +
+
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.ts new file mode 100644 index 0000000000..d79d30915f --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.ts @@ -0,0 +1,48 @@ +import {Component, OnInit} from '@angular/core'; +import {BasketService} from '@eg/share/catalog/basket.service'; +import {Subscription} from 'rxjs/Subscription'; +import {Router} from '@angular/router'; + +@Component({ + selector: 'eg-catalog-basket-actions', + templateUrl: 'basket-actions.component.html' +}) +export class BasketActionsComponent implements OnInit { + + basketAction: string; + + constructor( + private router: Router, + private basket: BasketService + ) { + this.basketAction = ''; + } + + ngOnInit() { + } + + basketCount(): number { + return this.basket.recordCount(); + } + + applyAction() { + console.debug('Performing basket action', this.basketAction); + + switch(this.basketAction) { + case 'view': + this.router.navigate(['/staff/catalog/basket']); + break; + + case 'clear': + this.basket.removeAllRecordIds(); + break; + } + + // Resetting basketAction inside its onchange handler + // prevents the new value from propagating to Angular + // Reset after the current thread. + setTimeout(() => this.basketAction = ''); // reset + } +} + + 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 20e17a091c..e490da2b80 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 @@ -14,6 +14,7 @@ import {StaffCatalogService} from './catalog.service'; import {RecordPaginationComponent} from './record/pagination.component'; import {RecordActionsComponent} from './record/actions.component'; import {HoldingsService} from '@eg/staff/share/holdings.service'; +import {BasketActionsComponent} from './basket-actions.component'; @NgModule({ declarations: [ @@ -26,7 +27,8 @@ import {HoldingsService} from '@eg/staff/share/holdings.service'; ResultFacetsComponent, ResultPaginationComponent, RecordPaginationComponent, - RecordActionsComponent + RecordActionsComponent, + BasketActionsComponent ], imports: [ StaffCommonModule, diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.html index 1f2ba300de..d37981b450 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.html @@ -35,7 +35,7 @@ Select {{searchContext.pager.rowNumber(0)}} - - {{searchContext.pager.rowNumber(searchContext.pager.limit - 1)}} + {{searchContext.pager.rowNumber(searchContext.currentResultIds().length - 1)}} diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts index c4efdb2e36..f402ea4ff3 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts @@ -28,6 +28,7 @@ export class ResultsComponent implements OnInit, OnDestroy { searchSub: Subscription; routeSub: Subscription; + basketSub: Subscription; constructor( private route: ActivatedRoute, @@ -64,11 +65,16 @@ export class ResultsComponent implements OnInit, OnDestroy { // After each completed search, update the record selector. this.searchSub = this.cat.onSearchComplete.subscribe( ctx => this.applyRecordSelection()); + + // Watch for basket changes applied by other components. + this.basketSub = this.basket.onChange.subscribe( + () => this.applyRecordSelection()); } ngOnDestroy() { this.routeSub.unsubscribe(); this.searchSub.unsubscribe(); + this.basketSub.unsubscribe(); } // Apply the select-all checkbox when all visible records @@ -108,13 +114,9 @@ export class ResultsComponent implements OnInit, OnDestroy { switch (pageCount) { case 1: return this.searchContext.result.records[0]; - case 2: - return this.searchContext.result.records[0] - && this.searchContext.result.records[1]; default: return this.searchContext.result.records[0] - && this.searchContext.result.records[1] - && this.searchContext.result.records[2]; + && this.searchContext.result.records[1]; } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html index b604c7154d..0d777156ea 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html @@ -149,17 +149,7 @@ TODO focus search input
- +
-- 2.11.0