Prevent to delete locked nodes and drawings

This commit is contained in:
grossmj 2024-05-18 23:11:35 +07:00
parent 3c48ef67dc
commit a27a7ff4ee
No known key found for this signature in database
GPG Key ID: 0A2D76AC45EA25CD

View File

@ -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(() => {});
});
}
}
}