Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
TEIIDTOOLS-486
Browse files Browse the repository at this point in the history
 * deleting compositions linked to deleted source nodes
  • Loading branch information
blafond committed Sep 6, 2018
1 parent fb77c1a commit 6dabe58
Showing 1 changed file with 39 additions and 10 deletions.
Expand Up @@ -428,30 +428,59 @@ export class ViewEditorComponent implements DoCheck, OnDestroy, OnInit {
// 3) fire view state changed event for each
// ------------------

let tempCmd: Command = null;

selectionArgs.forEach( ( nextArg ) => {

// need to parse the command to find the source path
const commandPart = this.getCommandId(nextArg);
// the payload for src will be the source/connection path
// the payload for the composition will be the json representing the composition properties
const argPart = this.getPayload(nextArg);

if (commandPart.startsWith(AddSourcesCommand.id)) {
tempCmd = CommandFactory.createRemoveSourcesCommand(argPart, commandPart);
// Look for any composition with src paths links and remove if exist
const comps: Composition[] = this.editorService.getEditorView().getCompositions();
comps.forEach( (nextComp) => {
const leftPath = nextComp.getLeftSourcePath();
if (leftPath && leftPath != null && argPart === leftPath) {
let addCompCmd = CommandFactory.createRemoveCompositionCommand(nextComp.toString(), AddCompositionCommand.id);
if (addCompCmd && addCompCmd != null) {
this.notifyRemoved(addCompCmd);
}
} else {
const rightPath = nextComp.getRightSourcePath();
if (rightPath && rightPath != null && argPart === rightPath) {
let addCompCmd = CommandFactory.createRemoveCompositionCommand(nextComp.toString(), AddCompositionCommand.id);
if (addCompCmd && addCompCmd != null) {
this.notifyRemoved(addCompCmd);
}
}
}
});

// Remove Source Command
let addSrcsCmd = CommandFactory.createRemoveSourcesCommand(argPart, commandPart);
this.notifyRemoved(addSrcsCmd);

} else if (commandPart.startsWith(AddCompositionCommand.id)) {
tempCmd = CommandFactory.createRemoveCompositionCommand(argPart, commandPart);
}
if (tempCmd !== null ) {
const cmd = tempCmd as Command;
this.editorService.fireViewStateHasChanged(ViewEditorPart.EDITOR, cmd);
} else {
this.logger.error("Failed to create RemoveSourcesCommand");
// Remove composition
let addCompCmd = CommandFactory.createRemoveCompositionCommand(argPart, commandPart);
this.notifyRemoved(addCompCmd);
}

this.editorService.select(null);
});
});
}

private notifyRemoved(command: Command): void {
if (command !== null ) {
const cmd = command as Command;
this.editorService.fireViewStateHasChanged(ViewEditorPart.EDITOR, cmd);
} else {
this.logger.error("Failed to create Remove Command");
}
}

private doSampleData(selection: string[]): void {
if (!selection || selection.length === 0) {
alert("Nothing selected for sample data");
Expand Down

0 comments on commit 6dabe58

Please sign in to comment.