1 import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
2 import {Router} from '@angular/router';
3 import {HttpClient} from '@angular/common/http';
4 import {StoreService} from '@eg/core/store.service';
5 import {CatalogService} from '@eg/share/catalog/catalog.service';
6 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
7 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
8 import {StaffCatalogService} from '../catalog.service';
9 import {StringService} from '@eg/share/string/string.service';
10 import {ToastService} from '@eg/share/toast/toast.service';
11 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
13 export const AC_CLEAR_CACHE_PATH = '/opac/extras/ac/clearcache/all/r/';
16 selector: 'eg-catalog-record-actions',
17 templateUrl: 'actions.component.html'
19 export class RecordActionsComponent implements OnInit {
21 @Output() addHoldingsRequested: EventEmitter<void>
22 = new EventEmitter<void>();
26 searchContext: CatalogSearchContext;
30 key: 'eg.cat.marked_conjoined_record',
34 key: 'eg.cat.marked_overlay_record',
38 key: 'eg.circ.hold.title_transfer_target',
42 key: 'eg.cat.transfer_target_record',
44 clear: [ // Clear these values on mark.
45 'eg.cat.transfer_target_lib',
46 'eg.cat.transfer_target_vol'
51 get patronViewUrl(): string {
52 if (!this.staffCat.patronViewUrl) {
53 return `/eg/opac/record/${encodeURIComponent(this.recId)}`;
55 return encodeURI(this.staffCat.patronViewUrl.replace(
56 /\{eg_record_id\}/g, ''+this.recId
60 @Input() set recordId(recId: number) {
63 // Fire any record specific actions here
67 @Input() isHoldable: boolean;
70 private router: Router,
71 private store: StoreService,
72 private strings: StringService,
73 private toast: ToastService,
74 private cat: CatalogService,
75 private catUrl: CatalogUrlService,
76 private staffCat: StaffCatalogService,
77 private holdings: HoldingsService,
78 private http: HttpClient
84 Object.keys(this.targets).forEach(name => {
85 const target = this.targets[name];
86 target.current = this.store.getLocalItem(target.key);
91 const target = this.targets[name];
92 target.current = this.recId;
93 this.store.setLocalItem(target.key, this.recId);
96 // Some marks require clearing other marks.
97 target.clear.forEach(key => this.store.removeLocalItem(key));
100 this.strings.interpolate('catalog.record.toast.' + name)
101 .then(txt => this.toast.success(txt));
105 Object.keys(this.targets).forEach(name => {
106 const target = this.targets[name];
107 target.current = null;
108 this.store.removeLocalItem(target.key);
110 this.strings.interpolate('catalog.record.toast.cleared')
111 .then(txt => this.toast.success(txt));
115 this.addHoldingsRequested.emit();
118 clearAddedContentCache() {
119 const url = AC_CLEAR_CACHE_PATH + this.recId;
120 this.http.get(url, {responseType: 'text'}).subscribe(
123 this.strings.interpolate('catalog.record.toast.clearAddedContentCache')
124 .then(txt => this.toast.success(txt));
127 this.strings.interpolate('catalog.record.toast.clearAddedContentCacheFailed')
128 .then(txt => this.toast.danger(txt));