Add Mistral js files to linter and fix linting errors
As a consequence, change how the workbookCtrl controller is used (and unit-tests for it). Change-Id: I21514ac01baa81c5a760abd9e7d0f909d89617d6
This commit is contained in:
parent
ac6336b5e2
commit
d82d48453f
@ -4,10 +4,15 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('mistral', ['merlin'])
|
angular
|
||||||
.run(['merlin.templates', function(templates) {
|
.module('mistral', ['merlin'])
|
||||||
templates.prefetch('/static/mistral/templates/fields/',
|
.run(initModule);
|
||||||
['varlist', 'yaqllist']);
|
|
||||||
}])
|
|
||||||
|
|
||||||
})();
|
initModule.$inject = ['merlin.templates'];
|
||||||
|
|
||||||
|
function initModule(templates) {
|
||||||
|
templates.prefetch('/static/mistral/templates/fields/',
|
||||||
|
['varlist', 'yaqllist']);
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
|
@ -4,82 +4,87 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('mistral')
|
angular
|
||||||
|
.module('mistral')
|
||||||
.value('baseActionID', 'action')
|
.value('baseActionID', 'action')
|
||||||
.value('baseWorkflowID', 'workflow')
|
.value('baseWorkflowID', 'workflow')
|
||||||
.controller('workbookCtrl',
|
.controller('WorkbookController', WorkbookController);
|
||||||
['$scope', 'mistral.workbook.models', '$http',
|
|
||||||
'baseActionID', 'baseWorkflowID',
|
|
||||||
function($scope, models, $http, baseActionId, baseWorkflowId) {
|
|
||||||
$scope.init = function(id, yaml, commitUrl, discardUrl) {
|
|
||||||
$scope.workbookID = id;
|
|
||||||
$scope.commitUrl = commitUrl;
|
|
||||||
$scope.discardUrl = discardUrl;
|
|
||||||
if ( id !== undefined ) {
|
|
||||||
$scope.workbook = models.Workbook.create(jsyaml.safeLoad(yaml));
|
|
||||||
} else {
|
|
||||||
$scope.workbook = models.Workbook.create({name: 'My Workbook'});
|
|
||||||
}
|
|
||||||
$scope.root = models.Root.create();
|
|
||||||
$scope.root.set('workbook', $scope.workbook);
|
|
||||||
|
|
||||||
$scope.root.set('standardActions', {
|
WorkbookController.$inject = ['mistral.workbook.models', '$http',
|
||||||
'nova.create_server': ['image', 'flavor', 'network_id'],
|
'$window', 'baseActionID', 'baseWorkflowID'];
|
||||||
'neutron.create_network': ['name', 'create_subnet'],
|
|
||||||
'glance.create_image': ['image_url']
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function getNextIDSuffix(container, regexp) {
|
function WorkbookController(models, $http, $window,
|
||||||
var max = Math.max.apply(Math, container.getIDs().map(function(id) {
|
baseActionId, baseWorkflowId) {
|
||||||
var match = regexp.exec(id);
|
var vm = this;
|
||||||
return match && +match[2];
|
vm.init = function(id, yaml, commitUrl, discardUrl) {
|
||||||
}));
|
vm.workbookID = id;
|
||||||
return max > 0 ? max + 1 : 1;
|
vm.commitUrl = commitUrl;
|
||||||
}
|
vm.discardUrl = discardUrl;
|
||||||
|
if (angular.isDefined(id)) {
|
||||||
|
vm.workbook = models.Workbook.create(jsyaml.safeLoad(yaml));
|
||||||
|
} else {
|
||||||
|
vm.workbook = models.Workbook.create({name: 'My Workbook'});
|
||||||
|
}
|
||||||
|
vm.root = models.Root.create();
|
||||||
|
vm.root.set('workbook', vm.workbook);
|
||||||
|
|
||||||
function getWorkbookNextIDSuffix(base) {
|
vm.root.set('standardActions', {
|
||||||
var containerName = base + 's',
|
'nova.create_server': ['image', 'flavor', 'network_id'],
|
||||||
regexp = /(workflow|action)([0-9]+)/,
|
'neutron.create_network': ['name', 'create_subnet'],
|
||||||
container = $scope.workbook.get(containerName);
|
'glance.create_image': ['image_url']
|
||||||
if ( !container ) {
|
});
|
||||||
throw 'Base should be either "action" or "workflow"!';
|
};
|
||||||
}
|
|
||||||
return getNextIDSuffix(container, regexp);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.addAction = function() {
|
function getNextIDSuffix(container, regexp) {
|
||||||
var nextSuffix = getWorkbookNextIDSuffix(baseActionId),
|
var max = Math.max.apply(Math, container.getIDs().map(function(id) {
|
||||||
newID = baseActionId + nextSuffix;
|
var match = regexp.exec(id);
|
||||||
$scope.workbook.get('actions').push(
|
return match && +match[2];
|
||||||
{name: 'Action ' + nextSuffix}, {id: newID});
|
}));
|
||||||
};
|
return max > 0 ? max + 1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
$scope.addWorkflow = function() {
|
function getWorkbookNextIDSuffix(base) {
|
||||||
var nextSuffix = getWorkbookNextIDSuffix(baseWorkflowId),
|
var containerName = base + 's';
|
||||||
newID = baseWorkflowId + nextSuffix;
|
var regexp = /(workflow|action)([0-9]+)/;
|
||||||
$scope.workbook.get('workflows').push(
|
var container = vm.workbook.get(containerName);
|
||||||
{name: 'Workflow ' + nextSuffix}, {id: newID});
|
if ( !container ) {
|
||||||
};
|
throw new Error('Base should be either "action" or "workflow"!');
|
||||||
|
}
|
||||||
|
return getNextIDSuffix(container, regexp);
|
||||||
|
}
|
||||||
|
|
||||||
$scope.commitWorkbook = function() {
|
vm.addAction = function() {
|
||||||
var data = {
|
var nextSuffix = getWorkbookNextIDSuffix(baseActionId);
|
||||||
name: $scope.workbook.get('name').get(),
|
var newID = baseActionId + nextSuffix;
|
||||||
yaml: $scope.workbook.toYAML()
|
vm.workbook.get('actions').push(
|
||||||
};
|
{name: 'Action ' + nextSuffix}, {id: newID});
|
||||||
|
};
|
||||||
|
|
||||||
$http({
|
vm.addWorkflow = function() {
|
||||||
url: $scope.commitUrl,
|
var nextSuffix = getWorkbookNextIDSuffix(baseWorkflowId);
|
||||||
method: 'POST',
|
var newID = baseWorkflowId + nextSuffix;
|
||||||
data: data
|
vm.workbook.get('workflows').push(
|
||||||
}).success(function(data, status, headers, config) {
|
{name: 'Workflow ' + nextSuffix}, {id: newID});
|
||||||
document.location = $scope.discardUrl;
|
};
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.discardWorkbook = function() {
|
vm.commitWorkbook = function() {
|
||||||
document.location = $scope.discardUrl;
|
var data = {
|
||||||
};
|
name: vm.workbook.get('name').get(),
|
||||||
|
yaml: vm.workbook.toYAML()
|
||||||
|
};
|
||||||
|
|
||||||
}])
|
$http({
|
||||||
})();
|
url: vm.commitUrl,
|
||||||
|
method: 'POST',
|
||||||
|
data: data
|
||||||
|
}).success(function() {
|
||||||
|
$window.location.href = vm.discardUrl;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
vm.discardWorkbook = function() {
|
||||||
|
$window.location.href = vm.discardUrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -38,34 +38,36 @@
|
|||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<h3>Create Workbook</h3>
|
<h3>Create Workbook</h3>
|
||||||
<div id="create-workbook" class="fluid-container" ng-cloak ng-controller="workbookCtrl"
|
<div id="create-workbook" class="fluid-container" ng-cloak ng-controller="WorkbookController as wb"
|
||||||
ng-init="init({{ id|default:'undefined' }}, '{{ yaml }}', '{{ commit_url }}', '{{ discard_url }}')">
|
ng-init="wb.init({{ id|default:'undefined' }}, '{{ yaml }}', '{{ commit_url }}', '{{ discard_url }}')">
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<div class="two-panels">
|
<div class="two-panels">
|
||||||
<div class="left-panel">
|
<div class="left-panel">
|
||||||
<div class="pull-left">
|
<div class="pull-left">
|
||||||
<h4><strong>{$ workbook.get('name') $}</strong></h4>
|
<h4><strong>{$ wb.workbook.get('name') $}</strong></h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<div class="table-actions clearfix">
|
<div class="table-actions clearfix">
|
||||||
<button ng-click="addAction()" class="btn btn-default btn-sm"><span class="fa fa-plus">Add Action</span></button>
|
<button ng-click="wb.addAction()" class="btn btn-default btn-sm">
|
||||||
<button ng-click="addWorkflow()" class="btn btn-default btn-sm"><span class="fa fa-plus">Add Workflow</span></button>
|
<span class="fa fa-plus">Add Action</span></button>
|
||||||
|
<button ng-click="wb.addWorkflow()" class="btn btn-default btn-sm">
|
||||||
|
<span class="fa fa-plus">Add Workflow</span></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="right-panel">
|
<div class="right-panel">
|
||||||
<div class="btn-group btn-toggle pull-right">
|
<div class="btn-group btn-toggle pull-right">
|
||||||
<button ng-click="isGraphMode = true" class="btn btn-sm"
|
<button ng-click="wb.isGraphMode = true" class="btn btn-sm"
|
||||||
ng-class="isGraphMode ? 'active btn-primary' : 'btn-default'">Graph</button>
|
ng-class="wb.isGraphMode ? 'active btn-primary' : 'btn-default'">Graph</button>
|
||||||
<button ng-click="isGraphMode = false" class="btn btn-sm"
|
<button ng-click="wb.isGraphMode = false" class="btn btn-sm"
|
||||||
ng-class="!isGraphMode ? 'active btn-primary' : 'btn-default'">YAML</button>
|
ng-class="!wb.isGraphMode ? 'active btn-primary' : 'btn-default'">YAML</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Data panel start -->
|
<!-- Data panel start -->
|
||||||
<div class="two-panels">
|
<div class="two-panels">
|
||||||
<div class="left-panel">
|
<div class="left-panel">
|
||||||
<panel ng-repeat="panel in workbook | extractPanels track by panel.id"
|
<panel ng-repeat="panel in wb.workbook | extractPanels track by panel.id"
|
||||||
content="panel">
|
content="panel">
|
||||||
<div ng-repeat="row in panel | extractRows track by row.id">
|
<div ng-repeat="row in panel | extractRows track by row.id">
|
||||||
<div ng-class="{'two-columns': row.index !== undefined }">
|
<div ng-class="{'two-columns': row.index !== undefined }">
|
||||||
@ -81,10 +83,10 @@
|
|||||||
<!-- YAML Panel -->
|
<!-- YAML Panel -->
|
||||||
<div class="right-panel">
|
<div class="right-panel">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-body" ng-show="!isGraphMode">
|
<div class="panel-body" ng-show="!wb.isGraphMode">
|
||||||
<pre>{$ workbook.toYAML() $}</pre>
|
<pre>{$ wb.workbook.toYAML() $}</pre>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body" ng-show="isGraphMode">
|
<div class="panel-body" ng-show="wb.isGraphMode">
|
||||||
Here will be a fancy Graph View as soon as we implement it!
|
Here will be a fancy Graph View as soon as we implement it!
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -94,9 +96,9 @@
|
|||||||
<div class="two-panels">
|
<div class="two-panels">
|
||||||
<div class="full-width">
|
<div class="full-width">
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<button ng-click="discardWorkbook()" class="btn btn-default cancel">Cancel</button>
|
<button ng-click="wb.discardWorkbook()" class="btn btn-default cancel">Cancel</button>
|
||||||
<button ng-click="commitWorkbook()" class="btn btn-primary">
|
<button ng-click="wb.commitWorkbook()" class="btn btn-primary">
|
||||||
{$ workbookID ? 'Modify' : 'Create' $}
|
{$ wb.workbookID ? 'Modify' : 'Create' $}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,24 +27,22 @@ describe('together workbook model and controller', function() {
|
|||||||
|
|
||||||
|
|
||||||
describe('define top-level actions available to user:', function () {
|
describe('define top-level actions available to user:', function () {
|
||||||
var $scope;
|
var wbCtrl;
|
||||||
|
|
||||||
beforeEach(inject(function (_$controller_) {
|
beforeEach(inject(function (_$controller_) {
|
||||||
var $controller = _$controller_;
|
wbCtrl = _$controller_('WorkbookController', {});
|
||||||
$scope = {};
|
wbCtrl.workbook = workbook;
|
||||||
$controller('workbookCtrl', {$scope: $scope});
|
|
||||||
$scope.workbook = workbook;
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("'Add Action' action", function () {
|
describe("'Add Action' action", function () {
|
||||||
it('adds a new Action', function () {
|
it('adds a new Action', function () {
|
||||||
$scope.addAction();
|
wbCtrl.addAction();
|
||||||
|
|
||||||
expect(workbook.get('actions').get(0)).toBeDefined();
|
expect(workbook.get('actions').get(0)).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates action with predefined name', function () {
|
it('creates action with predefined name', function () {
|
||||||
$scope.addAction();
|
wbCtrl.addAction();
|
||||||
|
|
||||||
expect(workbook.get('actions').get(0).getID()).toBeGreaterThan('');
|
expect(workbook.get('actions').get(0).getID()).toBeGreaterThan('');
|
||||||
});
|
});
|
||||||
@ -56,7 +54,7 @@ describe('together workbook model and controller', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it("corresponding JSON has the right key for the Action", function () {
|
it("corresponding JSON has the right key for the Action", function () {
|
||||||
$scope.addAction();
|
wbCtrl.addAction();
|
||||||
|
|
||||||
expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeDefined();
|
expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeDefined();
|
||||||
});
|
});
|
||||||
@ -64,7 +62,7 @@ describe('together workbook model and controller', function() {
|
|||||||
it("once the Action ID is changed, it's reflected in JSON", function () {
|
it("once the Action ID is changed, it's reflected in JSON", function () {
|
||||||
var newID = 'action10';
|
var newID = 'action10';
|
||||||
|
|
||||||
$scope.addAction();
|
wbCtrl.addAction();
|
||||||
workbook.get('actions').getByID(actionID).setID(newID);
|
workbook.get('actions').getByID(actionID).setID(newID);
|
||||||
|
|
||||||
expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeUndefined();
|
expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeUndefined();
|
||||||
@ -74,8 +72,8 @@ describe('together workbook model and controller', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('creates actions with different names on 2 successive calls', function () {
|
it('creates actions with different names on 2 successive calls', function () {
|
||||||
$scope.addAction();
|
wbCtrl.addAction();
|
||||||
$scope.addAction();
|
wbCtrl.addAction();
|
||||||
|
|
||||||
expect(workbook.get('actions').get(0).getID()).not.toEqual(
|
expect(workbook.get('actions').get(0).getID()).not.toEqual(
|
||||||
workbook.get('actions').get(1).getID())
|
workbook.get('actions').get(1).getID())
|
||||||
@ -84,7 +82,7 @@ describe('together workbook model and controller', function() {
|
|||||||
|
|
||||||
describe("'Add Workflow' action", function () {
|
describe("'Add Workflow' action", function () {
|
||||||
it('adds a new Workflow', function () {
|
it('adds a new Workflow', function () {
|
||||||
$scope.addWorkflow();
|
wbCtrl.addWorkflow();
|
||||||
|
|
||||||
expect(workbook.get('workflows').get(0)).toBeDefined();
|
expect(workbook.get('workflows').get(0)).toBeDefined();
|
||||||
});
|
});
|
||||||
@ -96,7 +94,7 @@ describe('together workbook model and controller', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it("corresponding JSON has the right key for the Workflow", function () {
|
it("corresponding JSON has the right key for the Workflow", function () {
|
||||||
$scope.addWorkflow();
|
wbCtrl.addWorkflow();
|
||||||
|
|
||||||
expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeDefined();
|
expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeDefined();
|
||||||
});
|
});
|
||||||
@ -104,7 +102,7 @@ describe('together workbook model and controller', function() {
|
|||||||
it("once the workflow ID is changed, it's reflected in JSON", function () {
|
it("once the workflow ID is changed, it's reflected in JSON", function () {
|
||||||
var newID = 'workflow10';
|
var newID = 'workflow10';
|
||||||
|
|
||||||
$scope.addWorkflow();
|
wbCtrl.addWorkflow();
|
||||||
workbook.get('workflows').getByID(workflowID).setID(newID);
|
workbook.get('workflows').getByID(workflowID).setID(newID);
|
||||||
|
|
||||||
expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeUndefined();
|
expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeUndefined();
|
||||||
@ -114,14 +112,14 @@ describe('together workbook model and controller', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('creates workflow with predefined name', function () {
|
it('creates workflow with predefined name', function () {
|
||||||
$scope.addWorkflow();
|
wbCtrl.addWorkflow();
|
||||||
|
|
||||||
expect(workbook.get('workflows').get(0).getID()).toBeGreaterThan('');
|
expect(workbook.get('workflows').get(0).getID()).toBeGreaterThan('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates workflows with different names on 2 successive calls', function () {
|
it('creates workflows with different names on 2 successive calls', function () {
|
||||||
$scope.addWorkflow();
|
wbCtrl.addWorkflow();
|
||||||
$scope.addWorkflow();
|
wbCtrl.addWorkflow();
|
||||||
|
|
||||||
expect(workbook.get('workflows').get(0).getID()).not.toEqual(
|
expect(workbook.get('workflows').get(0).getID()).not.toEqual(
|
||||||
workbook.get('workflows').get(1).getID())
|
workbook.get('workflows').get(1).getID())
|
||||||
|
@ -43,6 +43,6 @@
|
|||||||
"postinstall": "bower install",
|
"postinstall": "bower install",
|
||||||
"test-unit": "grunt test:unit",
|
"test-unit": "grunt test:unit",
|
||||||
"test": "karma start ./karma-unit.conf.js",
|
"test": "karma start ./karma-unit.conf.js",
|
||||||
"lint": "eslint --no-color ./merlin/static"
|
"lint": "eslint --no-color ./merlin/static ./extensions/mistral/static"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user