From b674615264836dfb3bc4991343f24d4505bfb9f5 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 27 May 2021 19:32:27 -0700 Subject: [PATCH] LP1922120: Add to carousel action in angular catalog To test: 1) Create several manual carousels, and make sure they are set to active. 2) Open a bib record in the Angular staff catalog. 3) Under Other Actions, choose the "Add to Carousel" action 4) Choose your preferred carousel. 5) Click Add to carousel. 6) Go back to carousel administration (or look at the carousel itself), and confirm that the record has been added to the carousel in question. Signed-off-by: Jane Sandberg Signed-off-by: Terran McCanna Signed-off-by: Galen Charlton --- .../src/app/staff/catalog/catalog.module.ts | 2 + .../catalog/record/actions.component.html | 24 ++++-- .../add-to-carousel-dialog.component.html | 31 +++++++ .../add-to-carousel-dialog.component.ts | 86 +++++++++++++++++++ 4 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.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 9b7d57acdc..cff15a18af 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 @@ -21,6 +21,7 @@ import {RecordActionsComponent} from './record/actions.component'; import {BasketActionsComponent} from './basket-actions.component'; import {HoldComponent} from './hold/hold.component'; import {PartsComponent} from './record/parts.component'; +import {AddToCarouselDialogComponent} from './record/add-to-carousel-dialog.component'; import {PartMergeDialogComponent} from './record/part-merge-dialog.component'; import {BrowseComponent} from './browse.component'; import {BrowseResultsComponent} from './browse/results.component'; @@ -47,6 +48,7 @@ import {PreferencesComponent} from './prefs.component'; BasketActionsComponent, HoldComponent, PartsComponent, + AddToCarouselDialogComponent, PartMergeDialogComponent, BrowseComponent, BrowseResultsComponent, diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html index 9a64f73fad..2b5bc7f973 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html @@ -1,18 +1,21 @@ - - - - - + + +
@@ -42,19 +45,19 @@
@@ -77,7 +80,10 @@ - + Add To Carousel + + View/Place Orders diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.html new file mode 100644 index 0000000000..9199bd96ad --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.html @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.ts new file mode 100644 index 0000000000..6941bef0e0 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/add-to-carousel-dialog.component.ts @@ -0,0 +1,86 @@ +import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {FormControl} from '@angular/forms'; +import {takeLast} from 'rxjs/operators'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {AuthService} from '@eg/core/auth.service'; +import {NetService} from '@eg/core/net.service'; +import {EventService} from '@eg/core/event.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; +import {StringComponent} from '@eg/share/string/string.component'; + +@Component({ + selector: 'eg-add-to-carousel-dialog', + templateUrl: './add-to-carousel-dialog.component.html' +}) + + +export class AddToCarouselDialogComponent extends DialogComponent implements OnInit { + + // IDs of records to add to the carousel + @Input() recordIds: number[]; + + + @ViewChild('successMsg', { static: true }) private successMsg: StringComponent; + @ViewChild('errorMsg', { static: true }) private errorMsg: StringComponent; + + selectedCarousel = new FormControl(''); + + private carousels = []; + + public addToCarousel: () => void; + private reset: () => void; + + constructor( + private modal: NgbModal, + private auth: AuthService, + private evt: EventService, + private net: NetService, + private toast: ToastService + ) { + super(modal); + } + + ngOnInit() { + this.onOpen$.subscribe(ok => { + this.reset(); + this.net.request( + 'open-ils.actor', + 'open-ils.actor.carousel.retrieve_manual_by_staff', + this.auth.token() + ).subscribe(carousels => this.carousels = carousels); + }); + + this.reset = () => { + this.carousels = []; + }; + + this.addToCarousel = () => { + this.net.request( + 'open-ils.actor', + 'open-ils.actor.container.item.create.batch', + this.auth.token(), + 'biblio_record_entry', + this.selectedCarousel.value['id'], + this.recordIds + ).pipe(takeLast(1)) + .subscribe( + result => { + const evt = this.evt.parse(result); + if (evt) { + this.errorMsg.current().then(m => this.toast.danger(m)); + } else { + this.successMsg.current().then(m => this.toast.success(m)); + this.close(true); + } + } + ); + }; + } + + formatCarouselEntries(): ComboboxEntry[] { + return this.carousels.map(carousel => ({id: carousel['bucket'], label: carousel['name']})); + } + +} -- 2.43.2