From a27a7ff4eedddb5640b165312c4b3affa2994bf9 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 18 May 2024 23:11:35 +0700 Subject: [PATCH] Prevent to delete locked nodes and drawings --- .../delete-action/delete-action.component.ts | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.ts b/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.ts index dfd55a59..0171234c 100644 --- a/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.ts +++ b/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.ts @@ -11,6 +11,7 @@ import { Controller } from '../../../../../models/controller'; import { DrawingService } from '../../../../../services/drawing.service'; import { LinkService } from '../../../../../services/link.service'; import { NodeService } from '../../../../../services/node.service'; +import { ToasterService } from '../../../../../services/toaster.service'; @Component({ selector: 'app-delete-action', @@ -23,6 +24,7 @@ export class DeleteActionComponent implements OnInit { @Input() links: Link[]; constructor( + private toasterService: ToasterService, private nodesDataSource: NodesDataSource, private drawingsDataSource: DrawingsDataSource, private linksDataSource: LinksDataSource, @@ -46,22 +48,34 @@ export class DeleteActionComponent implements OnInit { } delete() { - this.nodes.forEach((node) => { - this.nodesDataSource.remove(node); - this.nodeService.delete(this.controller, node).subscribe((node: Node) => {}); + this.nodes.forEach((node) => { + if (!node.locked) { + this.nodesDataSource.remove(node); + this.nodeService.delete(this.controller, node).subscribe((node: Node) => {}); + } + else { + this.toasterService.error('Cannot delete locked node: ' + node.name); + return; + } }); this.drawings.forEach((drawing) => { - this.drawingsDataSource.remove(drawing); - - this.drawingService.delete(this.controller, drawing).subscribe((drawing: Drawing) => {}); + if (!drawing.locked) { + this.drawingsDataSource.remove(drawing); + this.drawingService.delete(this.controller, drawing).subscribe((drawing: Drawing) => {}); + } + else { + this.toasterService.error('Cannot delete locked drawing'); + return; + } }); - this.links.forEach((link) => { - this.linksDataSource.remove(link); - - this.linkService.deleteLink(this.controller, link).subscribe(() => {}); - }); + if (this.nodes.length == 0 && this.drawings.length == 0) { + this.links.forEach((link) => { + this.linksDataSource.remove(link); + this.linkService.deleteLink(this.controller, link).subscribe(() => {}); + }); + } } }