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() {
|
||||
'use strict';
|
||||
|
||||
angular.module('mistral', ['merlin'])
|
||||
.run(['merlin.templates', function(templates) {
|
||||
templates.prefetch('/static/mistral/templates/fields/',
|
||||
['varlist', 'yaqllist']);
|
||||
}])
|
||||
angular
|
||||
.module('mistral', ['merlin'])
|
||||
.run(initModule);
|
||||
|
||||
})();
|
||||
initModule.$inject = ['merlin.templates'];
|
||||
|
||||
function initModule(templates) {
|
||||
templates.prefetch('/static/mistral/templates/fields/',
|
||||
['varlist', 'yaqllist']);
|
||||
}
|
||||
|
||||
})();
|
||||
|
@ -4,82 +4,87 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular.module('mistral')
|
||||
angular
|
||||
.module('mistral')
|
||||
.value('baseActionID', 'action')
|
||||
.value('baseWorkflowID', 'workflow')
|
||||
.controller('workbookCtrl',
|
||||
['$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);
|
||||
.controller('WorkbookController', WorkbookController);
|
||||
|
||||
$scope.root.set('standardActions', {
|
||||
'nova.create_server': ['image', 'flavor', 'network_id'],
|
||||
'neutron.create_network': ['name', 'create_subnet'],
|
||||
'glance.create_image': ['image_url']
|
||||
});
|
||||
};
|
||||
WorkbookController.$inject = ['mistral.workbook.models', '$http',
|
||||
'$window', 'baseActionID', 'baseWorkflowID'];
|
||||
|
||||
function getNextIDSuffix(container, regexp) {
|
||||
var max = Math.max.apply(Math, container.getIDs().map(function(id) {
|
||||
var match = regexp.exec(id);
|
||||
return match && +match[2];
|
||||
}));
|
||||
return max > 0 ? max + 1 : 1;
|
||||
}
|
||||
function WorkbookController(models, $http, $window,
|
||||
baseActionId, baseWorkflowId) {
|
||||
var vm = this;
|
||||
vm.init = function(id, yaml, commitUrl, discardUrl) {
|
||||
vm.workbookID = id;
|
||||
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) {
|
||||
var containerName = base + 's',
|
||||
regexp = /(workflow|action)([0-9]+)/,
|
||||
container = $scope.workbook.get(containerName);
|
||||
if ( !container ) {
|
||||
throw 'Base should be either "action" or "workflow"!';
|
||||
}
|
||||
return getNextIDSuffix(container, regexp);
|
||||
}
|
||||
vm.root.set('standardActions', {
|
||||
'nova.create_server': ['image', 'flavor', 'network_id'],
|
||||
'neutron.create_network': ['name', 'create_subnet'],
|
||||
'glance.create_image': ['image_url']
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addAction = function() {
|
||||
var nextSuffix = getWorkbookNextIDSuffix(baseActionId),
|
||||
newID = baseActionId + nextSuffix;
|
||||
$scope.workbook.get('actions').push(
|
||||
{name: 'Action ' + nextSuffix}, {id: newID});
|
||||
};
|
||||
function getNextIDSuffix(container, regexp) {
|
||||
var max = Math.max.apply(Math, container.getIDs().map(function(id) {
|
||||
var match = regexp.exec(id);
|
||||
return match && +match[2];
|
||||
}));
|
||||
return max > 0 ? max + 1 : 1;
|
||||
}
|
||||
|
||||
$scope.addWorkflow = function() {
|
||||
var nextSuffix = getWorkbookNextIDSuffix(baseWorkflowId),
|
||||
newID = baseWorkflowId + nextSuffix;
|
||||
$scope.workbook.get('workflows').push(
|
||||
{name: 'Workflow ' + nextSuffix}, {id: newID});
|
||||
};
|
||||
function getWorkbookNextIDSuffix(base) {
|
||||
var containerName = base + 's';
|
||||
var regexp = /(workflow|action)([0-9]+)/;
|
||||
var container = vm.workbook.get(containerName);
|
||||
if ( !container ) {
|
||||
throw new Error('Base should be either "action" or "workflow"!');
|
||||
}
|
||||
return getNextIDSuffix(container, regexp);
|
||||
}
|
||||
|
||||
$scope.commitWorkbook = function() {
|
||||
var data = {
|
||||
name: $scope.workbook.get('name').get(),
|
||||
yaml: $scope.workbook.toYAML()
|
||||
};
|
||||
vm.addAction = function() {
|
||||
var nextSuffix = getWorkbookNextIDSuffix(baseActionId);
|
||||
var newID = baseActionId + nextSuffix;
|
||||
vm.workbook.get('actions').push(
|
||||
{name: 'Action ' + nextSuffix}, {id: newID});
|
||||
};
|
||||
|
||||
$http({
|
||||
url: $scope.commitUrl,
|
||||
method: 'POST',
|
||||
data: data
|
||||
}).success(function(data, status, headers, config) {
|
||||
document.location = $scope.discardUrl;
|
||||
});
|
||||
};
|
||||
vm.addWorkflow = function() {
|
||||
var nextSuffix = getWorkbookNextIDSuffix(baseWorkflowId);
|
||||
var newID = baseWorkflowId + nextSuffix;
|
||||
vm.workbook.get('workflows').push(
|
||||
{name: 'Workflow ' + nextSuffix}, {id: newID});
|
||||
};
|
||||
|
||||
$scope.discardWorkbook = function() {
|
||||
document.location = $scope.discardUrl;
|
||||
};
|
||||
vm.commitWorkbook = function() {
|
||||
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 %}
|
||||
<h3>Create Workbook</h3>
|
||||
<div id="create-workbook" class="fluid-container" ng-cloak ng-controller="workbookCtrl"
|
||||
ng-init="init({{ id|default:'undefined' }}, '{{ yaml }}', '{{ commit_url }}', '{{ discard_url }}')">
|
||||
<div id="create-workbook" class="fluid-container" ng-cloak ng-controller="WorkbookController as wb"
|
||||
ng-init="wb.init({{ id|default:'undefined' }}, '{{ yaml }}', '{{ commit_url }}', '{{ discard_url }}')">
|
||||
<div class="well">
|
||||
<div class="two-panels">
|
||||
<div class="left-panel">
|
||||
<div class="pull-left">
|
||||
<h4><strong>{$ workbook.get('name') $}</strong></h4>
|
||||
<h4><strong>{$ wb.workbook.get('name') $}</strong></h4>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<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="addWorkflow()" class="btn btn-default btn-sm"><span class="fa fa-plus">Add Workflow</span></button>
|
||||
<button ng-click="wb.addAction()" class="btn btn-default btn-sm">
|
||||
<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 class="right-panel">
|
||||
<div class="btn-group btn-toggle pull-right">
|
||||
<button ng-click="isGraphMode = true" class="btn btn-sm"
|
||||
ng-class="isGraphMode ? 'active btn-primary' : 'btn-default'">Graph</button>
|
||||
<button ng-click="isGraphMode = false" class="btn btn-sm"
|
||||
ng-class="!isGraphMode ? 'active btn-primary' : 'btn-default'">YAML</button>
|
||||
<button ng-click="wb.isGraphMode = true" class="btn btn-sm"
|
||||
ng-class="wb.isGraphMode ? 'active btn-primary' : 'btn-default'">Graph</button>
|
||||
<button ng-click="wb.isGraphMode = false" class="btn btn-sm"
|
||||
ng-class="!wb.isGraphMode ? 'active btn-primary' : 'btn-default'">YAML</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Data panel start -->
|
||||
<div class="two-panels">
|
||||
<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">
|
||||
<div ng-repeat="row in panel | extractRows track by row.id">
|
||||
<div ng-class="{'two-columns': row.index !== undefined }">
|
||||
@ -81,10 +83,10 @@
|
||||
<!-- YAML Panel -->
|
||||
<div class="right-panel">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body" ng-show="!isGraphMode">
|
||||
<pre>{$ workbook.toYAML() $}</pre>
|
||||
<div class="panel-body" ng-show="!wb.isGraphMode">
|
||||
<pre>{$ wb.workbook.toYAML() $}</pre>
|
||||
</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!
|
||||
</div>
|
||||
</div>
|
||||
@ -94,9 +96,9 @@
|
||||
<div class="two-panels">
|
||||
<div class="full-width">
|
||||
<div class="pull-right">
|
||||
<button ng-click="discardWorkbook()" class="btn btn-default cancel">Cancel</button>
|
||||
<button ng-click="commitWorkbook()" class="btn btn-primary">
|
||||
{$ workbookID ? 'Modify' : 'Create' $}
|
||||
<button ng-click="wb.discardWorkbook()" class="btn btn-default cancel">Cancel</button>
|
||||
<button ng-click="wb.commitWorkbook()" class="btn btn-primary">
|
||||
{$ wb.workbookID ? 'Modify' : 'Create' $}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,24 +27,22 @@ describe('together workbook model and controller', function() {
|
||||
|
||||
|
||||
describe('define top-level actions available to user:', function () {
|
||||
var $scope;
|
||||
var wbCtrl;
|
||||
|
||||
beforeEach(inject(function (_$controller_) {
|
||||
var $controller = _$controller_;
|
||||
$scope = {};
|
||||
$controller('workbookCtrl', {$scope: $scope});
|
||||
$scope.workbook = workbook;
|
||||
wbCtrl = _$controller_('WorkbookController', {});
|
||||
wbCtrl.workbook = workbook;
|
||||
}));
|
||||
|
||||
describe("'Add Action' action", function () {
|
||||
it('adds a new Action', function () {
|
||||
$scope.addAction();
|
||||
wbCtrl.addAction();
|
||||
|
||||
expect(workbook.get('actions').get(0)).toBeDefined();
|
||||
});
|
||||
|
||||
it('creates action with predefined name', function () {
|
||||
$scope.addAction();
|
||||
wbCtrl.addAction();
|
||||
|
||||
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 () {
|
||||
$scope.addAction();
|
||||
wbCtrl.addAction();
|
||||
|
||||
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 () {
|
||||
var newID = 'action10';
|
||||
|
||||
$scope.addAction();
|
||||
wbCtrl.addAction();
|
||||
workbook.get('actions').getByID(actionID).setID(newID);
|
||||
|
||||
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 () {
|
||||
$scope.addAction();
|
||||
$scope.addAction();
|
||||
wbCtrl.addAction();
|
||||
wbCtrl.addAction();
|
||||
|
||||
expect(workbook.get('actions').get(0).getID()).not.toEqual(
|
||||
workbook.get('actions').get(1).getID())
|
||||
@ -84,7 +82,7 @@ describe('together workbook model and controller', function() {
|
||||
|
||||
describe("'Add Workflow' action", function () {
|
||||
it('adds a new Workflow', function () {
|
||||
$scope.addWorkflow();
|
||||
wbCtrl.addWorkflow();
|
||||
|
||||
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 () {
|
||||
$scope.addWorkflow();
|
||||
wbCtrl.addWorkflow();
|
||||
|
||||
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 () {
|
||||
var newID = 'workflow10';
|
||||
|
||||
$scope.addWorkflow();
|
||||
wbCtrl.addWorkflow();
|
||||
workbook.get('workflows').getByID(workflowID).setID(newID);
|
||||
|
||||
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 () {
|
||||
$scope.addWorkflow();
|
||||
wbCtrl.addWorkflow();
|
||||
|
||||
expect(workbook.get('workflows').get(0).getID()).toBeGreaterThan('');
|
||||
});
|
||||
|
||||
it('creates workflows with different names on 2 successive calls', function () {
|
||||
$scope.addWorkflow();
|
||||
$scope.addWorkflow();
|
||||
wbCtrl.addWorkflow();
|
||||
wbCtrl.addWorkflow();
|
||||
|
||||
expect(workbook.get('workflows').get(0).getID()).not.toEqual(
|
||||
workbook.get('workflows').get(1).getID())
|
||||
|
@ -43,6 +43,6 @@
|
||||
"postinstall": "bower install",
|
||||
"test-unit": "grunt test:unit",
|
||||
"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