Skip to content

Commit

Permalink
Prevent to delete locked nodes and drawings
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed May 18, 2024
1 parent 3c48ef6 commit a27a7ff
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -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(() => {});
});
}
}
}

0 comments on commit a27a7ff

Please sign in to comment.