Skip to content

Commit 23bb52e

Browse files
authored
Merge pull request #105 from pengz1/Fix-canvas-waitOns-issues
Fix canvas wait ons issues
2 parents d1f9d85 + cb9b56a commit 23bb52e

8 files changed

+50
-50
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To Be Added.
2121
## Dependencies
2222
What you need to run this app:
2323
* `node` and `npm` (`brew install node`)
24-
* Ensure you're running the latest versions Node `v6.x.x`+ (or `v7.x.x`) and NPM `3.x.x`+
24+
* Ensure you're running the latest versions Node `v8.x.x` and NPM `5.x.x`+
2525

2626
> If you have `nvm` installed, which is highly recommended (`brew install nvm`) you can do a `nvm install --lts && nvm use` in `$` to run with the latest Node LTS. You can also have this `zsh` done for you [automatically](https://github.com/creationix/nvm#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
2727

src/app/canvas-graph/canvas-graph.component.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ export class CanvasGraphComponent implements OnInit {
137137
}
138138
}
139139

140-
afterInputDisconnect(taskToBeChanged) {
141-
this.changeTaskWaitOn(taskToBeChanged);
140+
afterInputDisconnect(taskToBeChanged, preTask, preTaskResult) {
141+
this.changeTaskWaitOn(taskToBeChanged, preTask, preTaskResult);
142142
}
143143

144144
afterClick(e, node) {
@@ -189,14 +189,14 @@ export class CanvasGraphComponent implements OnInit {
189189
if (!preTask && !waitOnText) {
190190
_.forEach(this.workflow && this.workflow.tasks, (task) => {
191191
if (_.isEqual(task, taskToBeChanged)) {
192-
delete task['waitOn'];
192+
delete task['waitOn'][preTask];
193193
}
194194
});
195195
} else {
196196
//this.workflow may be undefined.
197197
_.forEach(this.workflow && this.workflow.tasks, (task) => {
198198
if (_.isEqual(task, taskToBeChanged)) {
199-
task['waitOn'] = _.set({}, preTask.label, waitOnText);
199+
task['waitOn'] = _.assign(task["waitOn"] || {}, {[preTask.label]: waitOnText});
200200
}
201201
});
202202
}
@@ -325,7 +325,11 @@ export class CanvasGraphComponent implements OnInit {
325325
let options = [];
326326
if (!self.editable) return options;
327327
if (node.removable !== false)
328-
options.push(null, {content: 'Remove', callback: self.removeNode.bind(self)});
328+
options.push(
329+
null,
330+
{content: 'Remove', callback: self.removeNode.bind(self)},
331+
{content: 'AddInput', callback: self.addInput.bind(self)}
332+
);
329333
if (node.graph && node.graph.onGetNodeMenuOptions)
330334
node.graph.onGetNodeMenuOptions(options, node);
331335
return options;
@@ -337,6 +341,11 @@ export class CanvasGraphComponent implements OnInit {
337341
global.LGraphCanvas.onMenuNodeRemove(value, options, e, menu, node);
338342
}
339343

344+
addInput(value, options, e, menu, node){
345+
node.addInput("waitOn", global.LiteGraph.EVENT);
346+
// this.afterWorkflowUpdate();
347+
}
348+
340349
drawNodes() {
341350
if (!this.workflow) return;
342351

src/app/header/header.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<header class="header-6">
22
<div class="branding">
33
<a class="nav-link">
4-
<img src="../../assets/logo-icon.png" alt="">
4+
<img src="../../assets/rackhd-icon.png" alt="">
55
<span class="title" style="padding-left: 10px">RackHD</span>
66
</a>
77
</div>

src/app/header/header.component.scss

-12
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,3 @@ header {
44
width: 100vw;
55
z-index: 9999;
66
}
7-
.app-header {
8-
.logo-placeholder {
9-
color: white;
10-
font-size: x-large;
11-
}
12-
.branding {
13-
img {
14-
height: 60px;
15-
width: 60px;
16-
}
17-
}
18-
}

src/app/workflow-center/workflow-editor/workflow-editor.component.html

+10-20
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
</button>
2323
<div class="editor-dropdown">
2424
<dropdown-group [data]="workflowStore" [columns]="columns" [placeholders]="placeholders" [fields]="fields"
25-
needSearchIcon=true
26-
(selected)="onSelected($event)" (cleared)="onRefresh()">
27-
</dropdown-group>
25+
needSearchIcon=true
26+
(selected)="onSelected($event)" (cleared)="onRefresh()">
27+
</dropdown-group>
2828
</div>
2929
</div>
3030
<div #jsoneditor id="jsoneditor"></div>
@@ -33,31 +33,21 @@
3333

3434
<clr-modal [(clrModalOpen)]="isShowModal" [clrModalSize]="'xl'">
3535

36-
<div class="modal-title" *ngIf="saveConfirmed && (selectWorkflow.injectableName == '')">
37-
<h3 style="color:red">No workflow selected.</h3>
38-
</div>
36+
<h3 class="modal-title" [ngClass]="{'red-title': !isWorkflowValid}">{{saveGraphInfo.status}}</h3>
3937

40-
<div class="modal-body" *ngIf="saveConfirmed && !(selectWorkflow.injectableName == '')">
41-
<p>Are you sure to save {{this.editor.get().injectableName}} ?</p>
38+
<div class="modal-body">
39+
<p>{{saveGraphInfo.notes}}</p>
4240
</div>
4341

44-
<div class="modal-footer" *ngIf="saveConfirmed && !(selectWorkflow.injectableName == '')">
45-
<button class="btn btn-outline" type="button" (click)="saveConfirmed = false; isShowModal = false;">No</button>
46-
<button class="btn btn-primary" type="button" (click)="saveConfirmed = false; saveWorkflow()">Yes</button>
42+
<div class="modal-footer" *ngIf="isWorkflowValid && isShowModal && saveGraphInfo.type === 0">
43+
<button class="btn btn-outline" type="button" (click)="isShowModal = false;">No</button>
44+
<button class="btn btn-primary" type="button" (click)="saveWorkflow()">Yes</button>
4745
</div>
4846

49-
<h3 class="modal-title" *ngIf="isShowModal && (!saveConfirmed)">{{saveGraphInfo.status}}</h3>
50-
51-
<div class="modal-body" *ngIf="isShowModal && (!saveConfirmed)">
52-
<p>{{saveGraphInfo.notes}}</p>
53-
</div>
54-
<div class="modal-footer" *ngIf="isShowModal && (!saveConfirmed) && saveGraphInfo.type === 1">
47+
<div class="modal-footer" *ngIf="isShowModal && saveGraphInfo.type === 1">
5548
<button class="btn btn-outline" type="button" (click)="isShowModal = false">No</button>
5649
<button class="btn btn-primary" type="button" (click)="jumpRunWorkflow()">Yes</button>
5750
</div>
58-
<div class="modal-footer" *ngIf="isShowModal && (!saveConfirmed) && saveGraphInfo.type === 2">
59-
<button class="btn btn-primary" type="button" (click)="isShowModal = false">Confirm</button>
60-
</div>
6151
</clr-modal>
6252

6353
<clr-modal [(clrModalOpen)]="isWaitOnMismatch" [clrModalSize]="'lg'">

src/app/workflow-center/workflow-editor/workflow-editor.component.scss

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
float: right;
44
}
55
.workflow-json-operation {
6-
padding-bottom: 45px;
76
display: inline-flex;
7+
padding-bottom: 60px;
88
width: 100%;
99

1010
p {
@@ -34,3 +34,7 @@
3434
}
3535
}
3636
}
37+
38+
.red-title {
39+
color: #ff0000; //Red
40+
}

src/app/workflow-center/workflow-editor/workflow-editor.component.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { GraphService } from '../../services/rackhd/graph.service';
55
import { JSONEditor } from '../../utils/json-editor';
66

77
const global = (window as any);
8-
const SAVE_INFO_INIT = {status: "Saving", notes: 'Waiting...', type: 0};
98

109
@Component({
1110
selector: 'app-workflow-editor',
@@ -17,8 +16,8 @@ export class WorkflowEditorComponent implements OnInit {
1716
selectWorkflow: any;
1817
editor: any;
1918
isShowModal: boolean;
20-
saveConfirmed: boolean;
21-
saveGraphInfo = SAVE_INFO_INIT;
19+
saveGraphInfo: any = {};
20+
isWorkflowValid: boolean;
2221

2322
workflowStore: any[] = [];
2423

@@ -35,7 +34,6 @@ export class WorkflowEditorComponent implements OnInit {
3534
clearInput() {
3635
this.onWorkflowChanged(this.graphService.getInitGraph());
3736
this.pushDataToCanvas();
38-
this.saveGraphInfo = SAVE_INFO_INIT;
3937
}
4038

4139
putWorkflowIntoCanvas(injectableName: string) {
@@ -64,12 +62,8 @@ export class WorkflowEditorComponent implements OnInit {
6462

6563
ngOnInit() {
6664
this.isShowModal = false;
67-
this.saveConfirmed = false;
6865
this.selectWorkflow = this.graphService.getInitGraph();
6966
let container = document.getElementById('jsoneditor');
70-
let canvas = document.getElementById('mycanvas');
71-
canvas.setAttribute('height', "1000px");
72-
canvas.setAttribute('width', "800px");
7367
let options = {mode: 'code'};
7468
this.editor = new JSONEditor(container, options);
7569
this.updateEditor(this.selectWorkflow);
@@ -124,7 +118,22 @@ export class WorkflowEditorComponent implements OnInit {
124118
}
125119

126120
saveConfirm() {
127-
this.saveConfirmed = true;
121+
this.isWorkflowValid = this.selectWorkflow && this.selectWorkflow.injectableName
122+
&& this.selectWorkflow.friendlyName && _.startsWith(this.selectWorkflow.injectableName, "Graph.")
123+
&& this.selectWorkflow.tasks && (this.selectWorkflow.tasks.length > 0);
124+
if (this.isWorkflowValid) {
125+
this.saveGraphInfo = {
126+
status: "Are you sure to save " + this.selectWorkflow.injectableName,
127+
notes: '',
128+
type: 0
129+
}
130+
} else {
131+
this.saveGraphInfo = {
132+
status: "Invalid workflow payload!",
133+
notes: "Please make sure 'injectableName', 'friendlyName' and 'tasks' are not empty! Make sure 'injectableName' starts with 'Graph.'",
134+
type: 0
135+
};
136+
}
128137
this.isShowModal = true;
129138
}
130139

@@ -135,7 +144,7 @@ export class WorkflowEditorComponent implements OnInit {
135144
res => {
136145
this.saveGraphInfo = {
137146
status: "Saved Successfully!",
138-
notes: 'The workflow ' + this.selectWorkflow.injectableName + ' has been saved successfully. Do you want to run it now?',
147+
notes: 'Workflow ' + this.selectWorkflow.injectableName + ' has been saved successfully. Do you want to run it now?',
139148
type: 1
140149
};
141150
},
File renamed without changes.

0 commit comments

Comments
 (0)