From d7d2d351138e131e451a6372973e37c1bd21a88c Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 25 Jun 2020 15:40:08 -0400 Subject: [PATCH 1/1] LP1885179 Staff catalog add results to basket Adds a new staff catalog option to add all search results to the basket. prior to this, results could only be added one page at a time to the basket. Note there is currently a 1k limit on the number of items added from a search result set. This could be modified. Signed-off-by: Bill Erickson Signed-off-by: Mike Risher Signed-off-by: Galen Charlton --- .../src/app/share/catalog/catalog.service.ts | 5 ++- .../catalog/basket-actions.component.html | 19 ++++++---- .../staff/catalog/basket-actions.component.ts | 37 +++++++++++++++++-- .../src/app/staff/catalog/catalog.service.ts | 4 +- 4 files changed, 52 insertions(+), 13 deletions(-) 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 af996c2383..36c3ead829 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 @@ -99,11 +99,14 @@ export class CatalogService { return this.basket.getRecordIds().then(ids => { + const pageIds = + ids.slice(ctx.pager.offset, ctx.pager.limit + ctx.pager.offset); + // Map our list of IDs into a search results object // the search context can understand. const result = { count: ids.length, - ids: ids.map(id => [id]) + ids: pageIds.map(id => [id]) }; this.applyResultData(ctx, result); 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 index 752557c503..7014944d49 100644 --- 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 @@ -1,6 +1,8 @@ + +
@@ -15,22 +17,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 index b5f35722bb..50f86113bd 100644 --- 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 @@ -1,11 +1,17 @@ -import {Component, OnInit, ViewChild} from '@angular/core'; +import {Component, Input, OnInit, ViewChild} from '@angular/core'; import {BasketService} from '@eg/share/catalog/basket.service'; import {Router} from '@angular/router'; import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {PrintService} from '@eg/share/print/print.service'; +import {CatalogService} from '@eg/share/catalog/catalog.service'; +import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context'; +import {StaffCatalogService} from './catalog.service'; import {BucketDialogComponent } from '@eg/staff/share/buckets/bucket-dialog.component'; +import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; + +const MAX_FROM_SEARCH_RESULTS = 1000; @Component({ selector: 'eg-catalog-basket-actions', @@ -18,12 +24,17 @@ export class BasketActionsComponent implements OnInit { @ViewChild('addBasketToBucketDialog', { static: true }) addToBucketDialog: BucketDialogComponent; + @ViewChild('addAllProgress', {static: true}) + addAllProgress: ProgressDialogComponent; + constructor( private router: Router, private net: NetService, private auth: AuthService, private printer: PrintService, - private basket: BasketService + private basket: BasketService, + private cat: CatalogService, + private staffCat: StaffCatalogService ) { this.basketAction = ''; } @@ -35,13 +46,33 @@ export class BasketActionsComponent implements OnInit { return this.basket.recordCount(); } + isMetarecordSearch(): boolean { + return this.staffCat.searchContext && + this.staffCat.searchContext.termSearch.isMetarecordSearch(); + } + // TODO: confirmation dialogs? applyAction(action: string) { this.basketAction = action; - console.debug('Performing basket action', this.basketAction); switch (this.basketAction) { + + case 'add_all': + // Add all search results to basket. + + this.addAllProgress.open(); + + const ctx = this.staffCat.cloneContext(this.staffCat.searchContext); + ctx.pager.offset = 0; + ctx.pager.limit = MAX_FROM_SEARCH_RESULTS; + + this.cat.search(ctx) + .then(_ => this.basket.addRecordIds(ctx.currentResultIds())) + .then(_ => this.addAllProgress.close()); + + break; + case 'view': // This does not propagate search params -- unclear if needed. this.router.navigate(['/staff/catalog/search'], diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts index 63c5c4ed99..5ed26d48db 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts @@ -89,7 +89,9 @@ export class StaffCatalogService { cloneContext(context: CatalogSearchContext): CatalogSearchContext { const params: any = this.catUrl.toUrlParams(context); - return this.catUrl.fromUrlHash(params); + const ctx = this.catUrl.fromUrlHash(params); + ctx.isStaff = true; // not carried in the URL + return ctx; } applySearchDefaults(): void { -- 2.43.2