@@ -5,7 +5,6 @@ import { GraphService } from '../../services/rackhd/graph.service';
5
5
import { JSONEditor } from '../../utils/json-editor' ;
6
6
7
7
const global = ( window as any ) ;
8
- const SAVE_INFO_INIT = { status : "Saving" , notes : 'Waiting...' , type : 0 } ;
9
8
10
9
@Component ( {
11
10
selector : 'app-workflow-editor' ,
@@ -17,8 +16,8 @@ export class WorkflowEditorComponent implements OnInit {
17
16
selectWorkflow : any ;
18
17
editor : any ;
19
18
isShowModal : boolean ;
20
- saveConfirmed : boolean ;
21
- saveGraphInfo = SAVE_INFO_INIT ;
19
+ saveGraphInfo : any = { } ;
20
+ isWorkflowValid : boolean ;
22
21
23
22
workflowStore : any [ ] = [ ] ;
24
23
@@ -35,7 +34,6 @@ export class WorkflowEditorComponent implements OnInit {
35
34
clearInput ( ) {
36
35
this . onWorkflowChanged ( this . graphService . getInitGraph ( ) ) ;
37
36
this . pushDataToCanvas ( ) ;
38
- this . saveGraphInfo = SAVE_INFO_INIT ;
39
37
}
40
38
41
39
putWorkflowIntoCanvas ( injectableName : string ) {
@@ -64,12 +62,8 @@ export class WorkflowEditorComponent implements OnInit {
64
62
65
63
ngOnInit ( ) {
66
64
this . isShowModal = false ;
67
- this . saveConfirmed = false ;
68
65
this . selectWorkflow = this . graphService . getInitGraph ( ) ;
69
66
let container = document . getElementById ( 'jsoneditor' ) ;
70
- let canvas = document . getElementById ( 'mycanvas' ) ;
71
- canvas . setAttribute ( 'height' , "1000px" ) ;
72
- canvas . setAttribute ( 'width' , "800px" ) ;
73
67
let options = { mode : 'code' } ;
74
68
this . editor = new JSONEditor ( container , options ) ;
75
69
this . updateEditor ( this . selectWorkflow ) ;
@@ -124,7 +118,22 @@ export class WorkflowEditorComponent implements OnInit {
124
118
}
125
119
126
120
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
+ }
128
137
this . isShowModal = true ;
129
138
}
130
139
@@ -135,7 +144,7 @@ export class WorkflowEditorComponent implements OnInit {
135
144
res => {
136
145
this . saveGraphInfo = {
137
146
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?' ,
139
148
type : 1
140
149
} ;
141
150
} ,
0 commit comments