Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 7ffcc28

Browse files
BoykoAlexilayaperumalg
authored andcommitted
Support syntax validation only for tasks without app name/properties verification
Different validation status string for syntactically correct and valid defs
1 parent 0d6eaf6 commit 7ffcc28

File tree

5 files changed

+480
-344
lines changed

5 files changed

+480
-344
lines changed

ui/app/scripts/task/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ define([
2929
'ngAnimate',
3030
'pagination',
3131
'angularHighlightjs',
32+
'ngCookies',
3233
'./controllers',
3334
'./services',
3435
'../directives',
@@ -53,6 +54,7 @@ define([
5354
'angularUtils.directives.dirPagination',
5455
'cgBusy',
5556
'hljs',
56-
'angular-growl'
57+
'angular-growl',
58+
'ngCookies'
5759
]);
5860
});

ui/app/scripts/task/controllers/bulk-define-tasks.js

Lines changed: 95 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ define(function (require) {
2525

2626
var PROGRESS_BAR_WAIT_TIME = 500;
2727

28+
var VERIFY_APPS_OFF_COOKIE_KEY = 'taskDefs.bulkDefine.verifyAppsOff';
29+
2830
var angular = require('angular');
2931

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) {
3234

3335
var editor;
3436

@@ -61,6 +63,49 @@ define(function (require) {
6163
}
6264
}
6365

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+
64109
/**
65110
* Bulk Define Tasks.
66111
*/
@@ -81,7 +126,7 @@ define(function (require) {
81126
});
82127
requests.push(request);
83128
});
84-
129+
85130
utils.$q.all(requests).then(function() {
86131
utils.growl.success('Task Definitions created successfully');
87132
}, function() {
@@ -152,13 +197,11 @@ define(function (require) {
152197
utils.growl.info('Failed to be created task(s) definition(s) are shown in the editor!');
153198
// Show only failed defs DSL
154199
if (failedDefs.length !== $scope.definitions.length) {
155-
var text = '';
156-
failedDefs.sort(function(d1, d2) {
200+
$scope.dsl = failedDefs.sort(function(d1, d2) {
157201
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');
162205
}
163206
});
164207

@@ -216,47 +259,6 @@ define(function (require) {
216259
}
217260
};
218261

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-
260262
$scope.nextError = function() {
261263
navigateToNextMarker(editor, $scope.errors);
262264
};
@@ -265,15 +267,58 @@ define(function (require) {
265267
navigateToNextMarker(editor, $scope.warnings);
266268
};
267269

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+
268279
$scope.$watch('errors', function(errors) {
280+
if (updateRulerErrors) {
281+
// Update overview ruler error/warning markers
282+
updateRulerErrors.update(errors);
283+
}
269284
$scope.bulkDefineTasksForm.$setValidity('validDsl', !errors || errors.length === 0);
270285
});
271286

287+
$scope.$watch('warnings', function(warnings) {
288+
if (updateRulerWarnings) {
289+
// Update overview ruler error/warning markers
290+
updateRulerWarnings.update(warnings);
291+
}
292+
});
293+
272294
$scope.$watch('definitions', function(definitions) {
273295
$scope.bulkDefineTasksForm.$setValidity('taskDefsPresent', angular.isArray(definitions) && definitions.length > 0);
274296
$scope.bulkDefineTasksForm.$setValidity('processedDsl', angular.isArray(definitions));
275297
});
276298

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);
277322
$scope.numberOfTasks = 0;
278323
$scope.errors = [];
279324
$scope.warnings = [];

ui/app/scripts/task/services/task-dsl-validator.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ define(function() {
2727

2828
var DEBUG = false;
2929

30-
function createValidator(dslText) {
30+
function createValidator(dslText, options) {
3131
var cancelled = false;
3232
var appInfos = {}; // Cached results for one run of the validator
3333

@@ -62,6 +62,25 @@ define(function() {
6262
return deferred.promise;
6363
}
6464

65+
// Build a nicely structured command definition
66+
function constructDefinitionText(parsedInfo) {
67+
var def = parsedInfo.name;
68+
if (parsedInfo.options) {
69+
Object.keys(parsedInfo.options).forEach(function (name) {
70+
def += ' --' + name + '=' + parsedInfo.options[name];
71+
});
72+
}
73+
return def;
74+
}
75+
76+
function constructDefinitionObject(parsedInfo) {
77+
return {
78+
name: parsedInfo.group,
79+
definition: constructDefinitionText(parsedInfo),
80+
line: parsedInfo.range.start.line
81+
};
82+
}
83+
6584
/**
6685
* Check if the parsed definition supports the specified options. If not then
6786
* append error messages to the messageAccumulator. Returns a promise that will be resolved
@@ -103,18 +122,7 @@ define(function() {
103122
});
104123
// TODO create errors for options you *must* specify but haven't
105124
if (!hasErrors && parsedInfo.group) {
106-
// Build a nicely structured command definition
107-
var def = appName;
108-
if (parsedInfo.options) {
109-
Object.keys(parsedInfo.options).forEach(function (name) {
110-
def += ' --' + name + '=' + parsedInfo.options[name];
111-
});
112-
}
113-
definitionsAccumulator.push({
114-
name: parsedInfo.group,
115-
definition: def,
116-
line: parsedInfo.range.start.line
117-
});
125+
definitionsAccumulator.push(constructDefinitionObject(parsedInfo));
118126
}
119127
}
120128
deferred.resolve(parsedInfo);
@@ -174,9 +182,14 @@ define(function() {
174182
knownTaskDefinitionNames.push(taskDefinitionName);
175183
}
176184
}
177-
verificationPromiseChain =
178-
verificationPromiseChain.then(
179-
createVerifyAppInvoker(line.success[0],messages,definitions));
185+
var parsedInfo = line.success[0];
186+
if (options.semantics) {
187+
verificationPromiseChain =
188+
verificationPromiseChain.then(
189+
createVerifyAppInvoker(parsedInfo, messages, definitions));
190+
} else if (parsedInfo.group) {
191+
definitions.push(constructDefinitionObject(parsedInfo));
192+
}
180193
}
181194
}
182195
}
@@ -202,7 +215,7 @@ define(function() {
202215
return {
203216
cancel: cancel,
204217
validate: validate
205-
};
218+
};
206219
}
207220

208221
return {

ui/app/scripts/task/views/bulk-define-tasks.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h1>Bulk Define Tasks</h1>
77
<form class="form-horizontal col-md-12" style="padding: 0px;" name="bulkDefineTasksForm" role="form" ng-submit="bulkDefineTasks()" novalidate>
88
<div class="row help-block">
99
<div class="text-left pull-left">
10-
<span ng-hide="bulkDefineTasksForm.$error.processedDsl">{{definitions.length === 0 ? 'No valid task definitions detected' : definitions.length + ' valid task definition'+(definitions.length>1?'s':'')+' detected'}}</span>
10+
<span ng-hide="bulkDefineTasksForm.$error.processedDsl">{{getValidationStatus()}}</span>
1111
<span ng-show="bulkDefineTasksForm.$error.processedDsl">
1212
<span class="glyphicon glyphicon-refresh icon-rotate-animation"></span>
1313
<i>Validating task definitions</i>
@@ -39,6 +39,11 @@ <h1>Bulk Define Tasks</h1>
3939
<input type="file" on-read-file="displayFileContents(contents)" style="display:none;"/>
4040
Import File
4141
</label>
42+
<label class="btn btn-default" tooltip-placement="top"
43+
tooltip="Switch On/Off DSL editor live verification of app names and options">
44+
<input type="checkbox" ng-model="verifyApps"/>
45+
Verify Apps
46+
</label>
4247
</div>
4348
<div class="col-md-12 text-center" style="padding: 9px 12px;">
4449
<span style="padding-right: 15px;">

0 commit comments

Comments
 (0)