this.copyTagsDialog.inPlaceCreateMode = true;
this.copyTagsDialog.copyIds = this.context.copyList().map(c => c.id());
- this.copyTagsDialog.open({size: 'lg'}).subscribe(newTags => {
- if (!newTags || newTags.length === 0) { return; }
+ this.copyTagsDialog.open({size: 'lg'}).subscribe(changes => {
+ if ((!changes.newTags || changes.newTags.length === 0) &&
+ (!changes.deletedMaps || changes.deletedMaps.length === 0)) {
+ return;
+ }
- newTags.forEach(tag => {
+ changes.newTags.forEach(tag => {
this.context.copyList().forEach(copy => {
if (copy.tags().filter(
- m => m.tag().id() === tag.id()).length > 0) {
+ m => m.tag() === tag.id()).length > 0) {
return; // map already exists
}
copy.ischanged(true);
});
});
+
+ if (this.context.copyList().length === 1) {
+ const copy = this.context.copyList()[0];
+ changes.deletedMaps.forEach(tag => {
+ const existing = copy.tags().filter(t => t.id() === tag.id())[0];
+ if (existing) {
+ existing.isdeleted(true);
+ copy.ischanged(true);
+ }
+ });
+ }
});
}
* Dialog for managing copy tags.
*/
+export interface CopyTagChanges {
+ newTags: IdlObject[];
+ deletedMaps: IdlObject[];
+}
+
@Component({
selector: 'eg-copy-tags-dialog',
templateUrl: 'copy-tags-dialog.component.html'
/**
*/
- open(args: NgbModalOptions): Observable<IdlObject[]> {
+ open(args: NgbModalOptions): Observable<CopyTagChanges> {
this.copy = null;
this.copies = [];
this.newTags = [];
// In manage mode, we can only manage a single copy.
// But in create mode, we can add tags to multiple copies.
-
- if (this.copyIds.length === 1 && !this.inPlaceCreateMode) {
+ // We can only manage copies that already exist in the database.
+ if (this.copyIds.length === 1 && this.copyIds[0] > 0) {
this.mode = 'manage';
} else {
this.mode = 'create';
applyChanges() {
if (this.inPlaceCreateMode) {
- this.close(this.newTags);
+ this.close({ newTags: this.newTags, deletedMaps: this.deletedMaps });
return;
}
promise.then(_ => {
this.successMsg.current().then(msg => this.toast.success(msg));
- this.close(this.newTags.length > 0);
+ this.close({ newTags: this.newTags, deletedMaps: this.deletedMaps });
});
}
}