1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {EventService} from '@eg/core/event.service';
4 import {ToastService} from '@eg/share/toast/toast.service';
5 import {AuthService} from '@eg/core/auth.service';
6 import {DialogComponent} from '@eg/share/dialog/dialog.component';
7 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
8 import {StringComponent} from '@eg/share/string/string.component';
11 * Dialog for merging authority records.
15 selector: 'eg-authority-merge-dialog',
16 templateUrl: 'merge-dialog.component.html'
19 export class AuthorityMergeDialogComponent
20 extends DialogComponent implements OnInit {
22 // Rows passed from the authority browse grid.
23 @Input() authData: any[] = [];
27 @ViewChild('successMsg', {static: true})
28 private successMsg: StringComponent;
30 @ViewChild('errorMsg', {static: true})
31 private errorMsg: StringComponent;
34 private modal: NgbModal, // required for passing to parent
35 private toast: ToastService,
36 private net: NetService,
37 private evt: EventService,
38 private auth: AuthService) {
39 super(modal); // required for subclassing
43 this.onOpen$.subscribe(_ => {
44 if (this.authData.length > 0) {
45 this.leadRecord = this.authData[0].authority.id();
52 const list = this.authData
53 .map(data => data.authority.id())
54 .filter(id => id !== this.leadRecord);
56 this.net.request('open-ils.cat',
57 'open-ils.cat.authority.records.merge',
58 this.auth.token(), this.leadRecord, list)
60 const evt = this.evt.parse(resp);
63 this.errorMsg.current().then(str => this.toast.warning(str));
66 this.successMsg.current().then(str => this.toast.success(str));