1 import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
2 import {DialogComponent} from '@eg/share/dialog/dialog.component';
3 import {IdlService, IdlObject} from '@eg/core/idl.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
8 selector: 'eg-catalog-part-merge-dialog',
9 templateUrl: './part-merge-dialog.component.html'
13 * Ask the user which part is the lead part then merge others parts in.
15 export class PartMergeDialogComponent extends DialogComponent {
17 // What parts are we merging
19 copyPartMaps: IdlObject[];
23 private idl: IdlService,
24 private pcrud: PcrudService,
25 private modal: NgbModal) {
30 console.log('Merging parts into lead part ', this.leadPart);
32 if (!this.leadPart) { return; }
34 this.leadPart = Number(this.leadPart);
36 // 1. Migrate copy maps to the lead part.
37 const partIds = this.parts
38 .filter(p => Number(p.id()) !== this.leadPart)
39 .map(p => Number(p.id()));
42 this.pcrud.search('acpm', {part: partIds})
45 map.part(this.leadPart);
51 // 2. Delete the now-empty subordinate parts. Note the
52 // delete must come after the part map changes are committed.
53 if (maps.length > 0) {
54 this.pcrud.autoApply(maps)
55 .toPromise().then(() => this.deleteParts());
64 const parts = this.parts.filter(p => Number(p.id()) !== this.leadPart);
65 parts.forEach(p => p.isdeleted(true));
66 this.pcrud.autoApply(parts).toPromise().then(res => this.close(res));