1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {IdlService, IdlObject} from '@eg/core/idl.service';
3 import {PcrudService} from '@eg/core/pcrud.service';
4 import {Pager} from '@eg/share/util/pager';
5 import {OrgService} from '@eg/core/org.service';
6 import {PermService} from '@eg/core/perm.service';
7 import {GridDataSource} from '@eg/share/grid/grid';
8 import {GridComponent} from '@eg/share/grid/grid.component';
9 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
10 import {ConjoinedItemsDialogComponent
11 } from '@eg/staff/share/holdings/conjoined-items-dialog.component';
13 /** Conjoined items per record grid */
16 selector: 'eg-catalog-record-conjoined',
17 templateUrl: 'conjoined.component.html'
19 export class ConjoinedComponent implements OnInit {
21 @Input() recordId: number;
24 gridDataSource: GridDataSource;
25 idsToUnlink: number[];
27 @ViewChild('conjoinedGrid') private grid: GridComponent;
29 @ViewChild('conjoinedDialog')
30 private conjoinedDialog: ConjoinedItemsDialogComponent;
32 @ViewChild('confirmUnlink')
33 private confirmUnlink: ConfirmDialogComponent;
36 private idl: IdlService,
37 private org: OrgService,
38 private pcrud: PcrudService,
39 private perm: PermService
41 this.gridDataSource = new GridDataSource();
42 this.idsToUnlink = [];
47 this.perm.hasWorkPermHere(['UPDATE_COPY'])
48 .then(perms => this.hasPerm = perms.UPDATE_COPY);
50 this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
51 const orderBy: any = {};
53 if (sort.length) { // Sort provided by grid.
54 orderBy.bmp = sort[0].name + ' ' + sort[0].dir;
65 return this.pcrud.search('bpbcm',
66 {peer_record: this.recordId}, searchOps, {fleshSelectors: true});
70 async unlink(rows: any) {
72 this.idsToUnlink = rows.map(r => r.target_copy().id());
73 if (this.idsToUnlink.length === 0) { return; }
75 this.confirmUnlink.open({size: 'sm'}).subscribe(confirmed => {
77 if (!confirmed) { return; }
80 this.pcrud.search('bpbcm',
81 {target_copy: this.idsToUnlink, peer_record: this.recordId})
83 map => maps.push(map),
86 this.pcrud.remove(maps).subscribe(
87 ok => console.debug('deleted map ', ok),
88 err => console.error(err),
90 this.idsToUnlink = [];
99 openConjoinedDialog() {
100 this.conjoinedDialog.open({size: 'sm'}).subscribe(