this.copyNotesDialog.inPlaceCreateMode = true;
this.copyNotesDialog.copyIds = this.context.copyList().map(c => c.id());
- this.copyNotesDialog.open({size: 'lg'}).subscribe(newNotes => {
- if (!newNotes || newNotes.length === 0) { return; }
+ this.copyNotesDialog.open({size: 'lg'}).subscribe(changes => {
+ if ((!changes.newNotes || changes.newNotes.length === 0) &&
+ (!changes.delNotes || changes.delNotes.length === 0)
+ ) {
+ return;
+ }
- console.log(newNotes);
- newNotes.forEach(note => {
+ changes.newNotes.forEach(note => {
this.context.copyList().forEach(copy => {
const n = this.idl.clone(note);
n.owning_copy(copy.id());
copy.ischanged(true);
});
});
+ if (this.context.copyList().length === 1) {
+ const copy = this.context.copyList()[0];
+ changes.delNotes.forEach(note => {
+ const existing = copy.notes().filter(n => n.id() === note.id())[0];
+ if (existing) {
+ existing.isdeleted(true);
+ copy.ischanged(true);
+ }
+ });
+ }
});
}
* Dialog for managing copy notes.
*/
+export interface CopyNotesChanges {
+ newNotes: IdlObject[];
+ delNotes: IdlObject[];
+}
+
@Component({
selector: 'eg-copy-notes-dialog',
templateUrl: 'copy-notes-dialog.component.html'
/**
*/
- open(args: NgbModalOptions): Observable<IdlObject[]> {
+ open(args: NgbModalOptions): Observable<CopyNotesChanges> {
this.copy = null;
this.copies = [];
this.newNotes = [];
+ this.delNotes = [];
if (this.copyIds.length === 0 && !this.inPlaceCreateMode) {
return throwError('copy ID required');
applyChanges() {
if (this.inPlaceCreateMode) {
- this.close(this.newNotes);
+ this.close({ newNotes: this.newNotes, delNotes: this.delNotes });
return;
}