@@ -25,10 +25,12 @@ define(function (require) {
25
25
26
26
var PROGRESS_BAR_WAIT_TIME = 500 ;
27
27
28
+ var VERIFY_APPS_OFF_COOKIE_KEY = 'taskDefs.bulkDefine.verifyAppsOff' ;
29
+
28
30
var angular = require ( 'angular' ) ;
29
31
30
- return [ '$scope' , 'DataflowUtils' , '$modal' , '$state' , 'TaskAppService' , 'TaskDslValidatorService' ,
31
- function ( $scope , utils , $modal , $state , taskAppService , validatorService ) {
32
+ return [ '$scope' , 'DataflowUtils' , '$modal' , '$state' , 'TaskAppService' , 'TaskDslValidatorService' , '$cookieStore' ,
33
+ function ( $scope , utils , $modal , $state , taskAppService , validatorService , $cookieStore ) {
32
34
33
35
var editor ;
34
36
@@ -61,6 +63,49 @@ define(function (require) {
61
63
}
62
64
}
63
65
66
+ function createLinterOption ( ) {
67
+ return {
68
+ async : true ,
69
+ getAnnotations : function ( dslText , callback , options , doc ) { // jshint ignore:line
70
+ // markers.push({from: range.start, to: range.end, message: 'Some error message!', severity: 'error'});
71
+ // callback(doc, markers);
72
+
73
+ // Init editor
74
+ if ( ! editor ) {
75
+ editor = doc ;
76
+ editor . on ( 'change' , function ( ) {
77
+ $scope . definitions = undefined ;
78
+ $scope . bulkDefineTasksForm . $setValidity ( 'notEmpty' , dslText && dslText . length ) ;
79
+ } ) ;
80
+ updateRulerWarnings = editor . annotateScrollbar ( 'CodeMirror-vertical-ruler-warning' ) ;
81
+ updateRulerErrors = editor . annotateScrollbar ( 'CodeMirror-vertical-ruler-error' ) ;
82
+ }
83
+
84
+ // Switch validator
85
+ if ( activeValidator ) {
86
+ activeValidator . cancel ( ) ;
87
+ }
88
+ activeValidator = validatorService . createValidator ( dslText , { semantics : $scope . verifyApps } ) ;
89
+
90
+ // Perform validation
91
+ activeValidator . validate ( ) . then ( function ( validationResults ) {
92
+ // Update CodeMirror gutter error/warning markers
93
+ callback ( doc , validationResults . errors . concat ( validationResults . warnings ) ) ;
94
+
95
+ validationResults . errors . sort ( function ( a , b ) {
96
+ return a . from . line - b . from . line ;
97
+ } ) ;
98
+ validationResults . warnings . sort ( function ( a , b ) {
99
+ return a . from . line - b . from . line ;
100
+ } ) ;
101
+ $scope . errors = validationResults . errors ;
102
+ $scope . warnings = validationResults . warnings ;
103
+ $scope . definitions = validationResults . definitions ;
104
+ } ) ;
105
+ }
106
+ } ;
107
+ }
108
+
64
109
/**
65
110
* Bulk Define Tasks.
66
111
*/
@@ -81,7 +126,7 @@ define(function (require) {
81
126
} ) ;
82
127
requests . push ( request ) ;
83
128
} ) ;
84
-
129
+
85
130
utils . $q . all ( requests ) . then ( function ( ) {
86
131
utils . growl . success ( 'Task Definitions created successfully' ) ;
87
132
} , function ( ) {
@@ -152,13 +197,11 @@ define(function (require) {
152
197
utils . growl . info ( 'Failed to be created task(s) definition(s) are shown in the editor!' ) ;
153
198
// Show only failed defs DSL
154
199
if ( failedDefs . length !== $scope . definitions . length ) {
155
- var text = '' ;
156
- failedDefs . sort ( function ( d1 , d2 ) {
200
+ $scope . dsl = failedDefs . sort ( function ( d1 , d2 ) {
157
201
return d1 . line - d2 . line ;
158
- } ) . forEach ( function ( def ) {
159
- text += editor . getLine ( def . line ) + '\n' ;
160
- } ) ;
161
- $scope . dsl = text ;
202
+ } ) . map ( function ( def ) {
203
+ return editor . getLine ( def . line ) ;
204
+ } ) . join ( '\n' ) ;
162
205
}
163
206
} ) ;
164
207
@@ -216,47 +259,6 @@ define(function (require) {
216
259
}
217
260
} ;
218
261
219
- $scope . lint = {
220
- async : true ,
221
- getAnnotations : function ( dslText , callback , options , doc ) { // jshint ignore:line
222
- // markers.push({from: range.start, to: range.end, message: 'Some error message!', severity: 'error'});
223
- // callback(doc, markers);
224
-
225
- if ( ! editor ) {
226
- editor = doc ;
227
- editor . on ( 'change' , function ( ) {
228
- $scope . definitions = undefined ;
229
- } ) ;
230
- updateRulerWarnings = editor . annotateScrollbar ( 'CodeMirror-vertical-ruler-warning' ) ;
231
- updateRulerErrors = editor . annotateScrollbar ( 'CodeMirror-vertical-ruler-error' ) ;
232
- }
233
-
234
- $scope . definitions = undefined ;
235
-
236
- if ( activeValidator ) {
237
- activeValidator . cancel ( ) ;
238
- }
239
- activeValidator = validatorService . createValidator ( dslText ) ;
240
- activeValidator . validate ( ) . then ( function ( validationResults ) {
241
- // Update CodeMirror gutter error/warning markers
242
- callback ( doc , validationResults . errors . concat ( validationResults . warnings ) ) ;
243
- // Update overview ruler error/warning markers
244
- updateRulerWarnings . update ( validationResults . warnings ) ;
245
- updateRulerErrors . update ( validationResults . errors ) ;
246
-
247
- validationResults . errors . sort ( function ( a , b ) {
248
- return a . from . line - b . from . line ;
249
- } ) ;
250
- validationResults . warnings . sort ( function ( a , b ) {
251
- return a . from . line - b . from . line ;
252
- } ) ;
253
- $scope . errors = validationResults . errors ;
254
- $scope . warnings = validationResults . warnings ;
255
- $scope . definitions = validationResults . definitions ;
256
- } ) ;
257
- }
258
- } ;
259
-
260
262
$scope . nextError = function ( ) {
261
263
navigateToNextMarker ( editor , $scope . errors ) ;
262
264
} ;
@@ -265,15 +267,58 @@ define(function (require) {
265
267
navigateToNextMarker ( editor , $scope . warnings ) ;
266
268
} ;
267
269
270
+ $scope . getValidationStatus = function ( ) {
271
+ var validStr = $scope . verifyApps ? 'valid' : 'syntactically correct' ;
272
+ if ( $scope . definitions && $scope . definitions . length ) {
273
+ return $scope . definitions . length + ' ' + validStr + ' task definition' + ( $scope . definitions . length > 1 ? 's' : '' ) + ' detected' ;
274
+ } else {
275
+ return 'No ' + validStr + ' task definitions detected' ;
276
+ }
277
+ } ;
278
+
268
279
$scope . $watch ( 'errors' , function ( errors ) {
280
+ if ( updateRulerErrors ) {
281
+ // Update overview ruler error/warning markers
282
+ updateRulerErrors . update ( errors ) ;
283
+ }
269
284
$scope . bulkDefineTasksForm . $setValidity ( 'validDsl' , ! errors || errors . length === 0 ) ;
270
285
} ) ;
271
286
287
+ $scope . $watch ( 'warnings' , function ( warnings ) {
288
+ if ( updateRulerWarnings ) {
289
+ // Update overview ruler error/warning markers
290
+ updateRulerWarnings . update ( warnings ) ;
291
+ }
292
+ } ) ;
293
+
272
294
$scope . $watch ( 'definitions' , function ( definitions ) {
273
295
$scope . bulkDefineTasksForm . $setValidity ( 'taskDefsPresent' , angular . isArray ( definitions ) && definitions . length > 0 ) ;
274
296
$scope . bulkDefineTasksForm . $setValidity ( 'processedDsl' , angular . isArray ( definitions ) ) ;
275
297
} ) ;
276
298
299
+ $scope . $watch ( 'verifyApps' , function ( ) {
300
+ if ( activeValidator ) {
301
+ activeValidator . cancel ( ) ;
302
+ }
303
+ $scope . numberOfTasks = 0 ;
304
+ $scope . errors = [ ] ;
305
+ $scope . warnings = [ ] ;
306
+ $scope . definitions = undefined ;
307
+ $scope . lint = createLinterOption ( ) ;
308
+ } ) ;
309
+
310
+ $scope . $on ( '$destroy' , function ( ) {
311
+ if ( activeValidator ) {
312
+ activeValidator . cancel ( ) ;
313
+ }
314
+ if ( $scope . verifyApps ) {
315
+ $cookieStore . remove ( VERIFY_APPS_OFF_COOKIE_KEY ) ;
316
+ } else {
317
+ $cookieStore . put ( VERIFY_APPS_OFF_COOKIE_KEY , true ) ;
318
+ }
319
+ } ) ;
320
+
321
+ $scope . verifyApps = ! $cookieStore . get ( VERIFY_APPS_OFF_COOKIE_KEY ) ;
277
322
$scope . numberOfTasks = 0 ;
278
323
$scope . errors = [ ] ;
279
324
$scope . warnings = [ ] ;
0 commit comments