Browse Source

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
Timur Sufiev 3 years ago
parent
commit
d82d48453f

+ 11
- 6
extensions/mistral/static/mistral/js/mistral.init.js View File

@@ -4,10 +4,15 @@
4 4
 (function() {
5 5
   'use strict';
6 6
 
7
-  angular.module('mistral', ['merlin'])
8
-    .run(['merlin.templates', function(templates) {
9
-      templates.prefetch('/static/mistral/templates/fields/',
10
-        ['varlist', 'yaqllist']);
11
-    }])
7
+  angular
8
+    .module('mistral', ['merlin'])
9
+    .run(initModule);
12 10
 
13
-})();
11
+  initModule.$inject = ['merlin.templates'];
12
+
13
+  function initModule(templates) {
14
+    templates.prefetch('/static/mistral/templates/fields/',
15
+      ['varlist', 'yaqllist']);
16
+  }
17
+
18
+})();

+ 73
- 68
extensions/mistral/static/mistral/js/mistral.workbook.controllers.js View File

@@ -4,82 +4,87 @@
4 4
 (function() {
5 5
   'use strict';
6 6
 
7
-  angular.module('mistral')
7
+  angular
8
+    .module('mistral')
8 9
     .value('baseActionID', 'action')
9 10
     .value('baseWorkflowID', 'workflow')
10
-    .controller('workbookCtrl',
11
-    ['$scope', 'mistral.workbook.models', '$http',
12
-      'baseActionID', 'baseWorkflowID',
13
-      function($scope, models, $http, baseActionId, baseWorkflowId) {
14
-        $scope.init = function(id, yaml, commitUrl, discardUrl) {
15
-          $scope.workbookID = id;
16
-          $scope.commitUrl = commitUrl;
17
-          $scope.discardUrl = discardUrl;
18
-          if ( id !== undefined ) {
19
-            $scope.workbook = models.Workbook.create(jsyaml.safeLoad(yaml));
20
-          } else {
21
-            $scope.workbook = models.Workbook.create({name: 'My Workbook'});
22
-          }
23
-          $scope.root = models.Root.create();
24
-          $scope.root.set('workbook', $scope.workbook);
11
+    .controller('WorkbookController', WorkbookController);
25 12
 
26
-          $scope.root.set('standardActions', {
27
-            'nova.create_server': ['image', 'flavor', 'network_id'],
28
-            'neutron.create_network': ['name', 'create_subnet'],
29
-            'glance.create_image': ['image_url']
30
-          });
31
-        };
13
+  WorkbookController.$inject = ['mistral.workbook.models', '$http',
14
+    '$window', 'baseActionID', 'baseWorkflowID'];
32 15
 
33
-        function getNextIDSuffix(container, regexp) {
34
-          var max = Math.max.apply(Math, container.getIDs().map(function(id) {
35
-            var match = regexp.exec(id);
36
-            return match && +match[2];
37
-          }));
38
-          return max > 0 ? max + 1 : 1;
39
-        }
16
+  function WorkbookController(models, $http, $window,
17
+                              baseActionId, baseWorkflowId) {
18
+    var vm = this;
19
+    vm.init = function(id, yaml, commitUrl, discardUrl) {
20
+      vm.workbookID = id;
21
+      vm.commitUrl = commitUrl;
22
+      vm.discardUrl = discardUrl;
23
+      if (angular.isDefined(id)) {
24
+        vm.workbook = models.Workbook.create(jsyaml.safeLoad(yaml));
25
+      } else {
26
+        vm.workbook = models.Workbook.create({name: 'My Workbook'});
27
+      }
28
+      vm.root = models.Root.create();
29
+      vm.root.set('workbook', vm.workbook);
40 30
 
41
-        function getWorkbookNextIDSuffix(base) {
42
-          var containerName = base + 's',
43
-            regexp = /(workflow|action)([0-9]+)/,
44
-            container = $scope.workbook.get(containerName);
45
-          if ( !container ) {
46
-            throw 'Base should be either "action" or "workflow"!';
47
-          }
48
-          return getNextIDSuffix(container, regexp);
49
-        }
31
+      vm.root.set('standardActions', {
32
+        'nova.create_server': ['image', 'flavor', 'network_id'],
33
+        'neutron.create_network': ['name', 'create_subnet'],
34
+        'glance.create_image': ['image_url']
35
+      });
36
+    };
50 37
 
51
-        $scope.addAction = function() {
52
-          var nextSuffix = getWorkbookNextIDSuffix(baseActionId),
53
-            newID = baseActionId + nextSuffix;
54
-          $scope.workbook.get('actions').push(
55
-            {name: 'Action ' + nextSuffix}, {id: newID});
56
-        };
38
+    function getNextIDSuffix(container, regexp) {
39
+      var max = Math.max.apply(Math, container.getIDs().map(function(id) {
40
+        var match = regexp.exec(id);
41
+        return match && +match[2];
42
+      }));
43
+      return max > 0 ? max + 1 : 1;
44
+    }
57 45
 
58
-        $scope.addWorkflow = function() {
59
-          var nextSuffix = getWorkbookNextIDSuffix(baseWorkflowId),
60
-            newID = baseWorkflowId + nextSuffix;
61
-          $scope.workbook.get('workflows').push(
62
-            {name: 'Workflow ' + nextSuffix}, {id: newID});
63
-        };
46
+    function getWorkbookNextIDSuffix(base) {
47
+      var containerName = base + 's';
48
+      var regexp = /(workflow|action)([0-9]+)/;
49
+      var container = vm.workbook.get(containerName);
50
+      if ( !container ) {
51
+        throw new Error('Base should be either "action" or "workflow"!');
52
+      }
53
+      return getNextIDSuffix(container, regexp);
54
+    }
64 55
 
65
-        $scope.commitWorkbook = function() {
66
-          var data = {
67
-            name: $scope.workbook.get('name').get(),
68
-            yaml: $scope.workbook.toYAML()
69
-            };
56
+    vm.addAction = function() {
57
+      var nextSuffix = getWorkbookNextIDSuffix(baseActionId);
58
+      var newID = baseActionId + nextSuffix;
59
+      vm.workbook.get('actions').push(
60
+        {name: 'Action ' + nextSuffix}, {id: newID});
61
+    };
70 62
 
71
-          $http({
72
-            url: $scope.commitUrl,
73
-            method: 'POST',
74
-            data: data
75
-          }).success(function(data, status, headers, config) {
76
-            document.location = $scope.discardUrl;
77
-          });
78
-        };
63
+    vm.addWorkflow = function() {
64
+      var nextSuffix = getWorkbookNextIDSuffix(baseWorkflowId);
65
+      var newID = baseWorkflowId + nextSuffix;
66
+      vm.workbook.get('workflows').push(
67
+        {name: 'Workflow ' + nextSuffix}, {id: newID});
68
+    };
79 69
 
80
-        $scope.discardWorkbook = function() {
81
-          document.location = $scope.discardUrl;
82
-        };
70
+    vm.commitWorkbook = function() {
71
+      var data = {
72
+        name: vm.workbook.get('name').get(),
73
+        yaml: vm.workbook.toYAML()
74
+      };
83 75
 
84
-      }])
85
-})();
76
+      $http({
77
+        url: vm.commitUrl,
78
+        method: 'POST',
79
+        data: data
80
+      }).success(function() {
81
+        $window.location.href = vm.discardUrl;
82
+      });
83
+    };
84
+
85
+    vm.discardWorkbook = function() {
86
+      $window.location.href = vm.discardUrl;
87
+    };
88
+
89
+  }
90
+})();

+ 551
- 548
extensions/mistral/static/mistral/js/mistral.workbook.models.js
File diff suppressed because it is too large
View File


+ 18
- 16
extensions/mistral/templates/mistral/create.html View File

@@ -38,34 +38,36 @@
38 38
 
39 39
 {% block main %}
40 40
 <h3>Create Workbook</h3>
41
-  <div id="create-workbook" class="fluid-container" ng-cloak ng-controller="workbookCtrl"
42
-       ng-init="init({{ id|default:'undefined' }}, '{{ yaml }}', '{{ commit_url }}', '{{ discard_url }}')">
41
+  <div id="create-workbook" class="fluid-container" ng-cloak ng-controller="WorkbookController as wb"
42
+       ng-init="wb.init({{ id|default:'undefined' }}, '{{ yaml }}', '{{ commit_url }}', '{{ discard_url }}')">
43 43
     <div class="well">
44 44
       <div class="two-panels">
45 45
         <div class="left-panel">
46 46
           <div class="pull-left">
47
-            <h4><strong>{$ workbook.get('name') $}</strong></h4>
47
+            <h4><strong>{$ wb.workbook.get('name') $}</strong></h4>
48 48
           </div>
49 49
           <div class="pull-right">
50 50
             <div class="table-actions clearfix">
51
-              <button ng-click="addAction()" class="btn btn-default btn-sm"><span class="fa fa-plus">Add Action</span></button>
52
-              <button ng-click="addWorkflow()" class="btn btn-default btn-sm"><span class="fa fa-plus">Add Workflow</span></button>
51
+              <button ng-click="wb.addAction()" class="btn btn-default btn-sm">
52
+                <span class="fa fa-plus">Add Action</span></button>
53
+              <button ng-click="wb.addWorkflow()" class="btn btn-default btn-sm">
54
+                <span class="fa fa-plus">Add Workflow</span></button>
53 55
             </div>
54 56
           </div>
55 57
         </div>
56 58
         <div class="right-panel">
57 59
           <div class="btn-group btn-toggle pull-right">
58
-            <button ng-click="isGraphMode = true" class="btn btn-sm"
59
-                ng-class="isGraphMode ? 'active btn-primary' : 'btn-default'">Graph</button>
60
-            <button ng-click="isGraphMode = false" class="btn btn-sm"
61
-                ng-class="!isGraphMode ? 'active btn-primary' : 'btn-default'">YAML</button>
60
+            <button ng-click="wb.isGraphMode = true" class="btn btn-sm"
61
+                ng-class="wb.isGraphMode ? 'active btn-primary' : 'btn-default'">Graph</button>
62
+            <button ng-click="wb.isGraphMode = false" class="btn btn-sm"
63
+                ng-class="!wb.isGraphMode ? 'active btn-primary' : 'btn-default'">YAML</button>
62 64
           </div>
63 65
         </div>
64 66
       </div>
65 67
       <!-- Data panel start -->
66 68
       <div class="two-panels">
67 69
         <div class="left-panel">
68
-          <panel ng-repeat="panel in workbook | extractPanels track by panel.id"
70
+          <panel ng-repeat="panel in wb.workbook | extractPanels track by panel.id"
69 71
                  content="panel">
70 72
             <div ng-repeat="row in panel | extractRows track by row.id">
71 73
               <div ng-class="{'two-columns': row.index !== undefined }">
@@ -81,10 +83,10 @@
81 83
         <!-- YAML Panel -->
82 84
         <div class="right-panel">
83 85
           <div class="panel panel-default">
84
-            <div class="panel-body" ng-show="!isGraphMode">
85
-              <pre>{$ workbook.toYAML() $}</pre>
86
+            <div class="panel-body" ng-show="!wb.isGraphMode">
87
+              <pre>{$ wb.workbook.toYAML() $}</pre>
86 88
             </div>
87
-            <div class="panel-body" ng-show="isGraphMode">
89
+            <div class="panel-body" ng-show="wb.isGraphMode">
88 90
               Here will be a fancy Graph View as soon as we implement it!
89 91
             </div>
90 92
           </div>
@@ -94,9 +96,9 @@
94 96
       <div class="two-panels">
95 97
         <div class="full-width">
96 98
           <div class="pull-right">
97
-            <button ng-click="discardWorkbook()" class="btn btn-default cancel">Cancel</button>
98
-            <button ng-click="commitWorkbook()" class="btn btn-primary">
99
-              {$ workbookID ? 'Modify' : 'Create' $}
99
+            <button ng-click="wb.discardWorkbook()" class="btn btn-default cancel">Cancel</button>
100
+            <button ng-click="wb.commitWorkbook()" class="btn btn-primary">
101
+              {$ wb.workbookID ? 'Modify' : 'Create' $}
100 102
               </button>
101 103
           </div>
102 104
         </div>

+ 15
- 17
extensions/mistral/test/js/workbook.controller.spec.js View File

@@ -27,24 +27,22 @@ describe('together workbook model and controller', function() {
27 27
 
28 28
 
29 29
   describe('define top-level actions available to user:', function () {
30
-    var $scope;
30
+    var wbCtrl;
31 31
 
32 32
     beforeEach(inject(function (_$controller_) {
33
-      var $controller = _$controller_;
34
-      $scope = {};
35
-      $controller('workbookCtrl', {$scope: $scope});
36
-      $scope.workbook = workbook;
33
+      wbCtrl = _$controller_('WorkbookController', {});
34
+      wbCtrl.workbook = workbook;
37 35
     }));
38 36
 
39 37
     describe("'Add Action' action", function () {
40 38
       it('adds a new Action', function () {
41
-        $scope.addAction();
39
+        wbCtrl.addAction();
42 40
 
43 41
         expect(workbook.get('actions').get(0)).toBeDefined();
44 42
       });
45 43
 
46 44
       it('creates action with predefined name', function () {
47
-        $scope.addAction();
45
+        wbCtrl.addAction();
48 46
 
49 47
         expect(workbook.get('actions').get(0).getID()).toBeGreaterThan('');
50 48
       });
@@ -56,7 +54,7 @@ describe('together workbook model and controller', function() {
56 54
         }));
57 55
 
58 56
         it("corresponding JSON has the right key for the Action", function () {
59
-          $scope.addAction();
57
+          wbCtrl.addAction();
60 58
 
61 59
           expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeDefined();
62 60
         });
@@ -64,7 +62,7 @@ describe('together workbook model and controller', function() {
64 62
         it("once the Action ID is changed, it's reflected in JSON", function () {
65 63
           var newID = 'action10';
66 64
 
67
-          $scope.addAction();
65
+          wbCtrl.addAction();
68 66
           workbook.get('actions').getByID(actionID).setID(newID);
69 67
 
70 68
           expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeUndefined();
@@ -74,8 +72,8 @@ describe('together workbook model and controller', function() {
74 72
       });
75 73
 
76 74
       it('creates actions with different names on 2 successive calls', function () {
77
-        $scope.addAction();
78
-        $scope.addAction();
75
+        wbCtrl.addAction();
76
+        wbCtrl.addAction();
79 77
 
80 78
         expect(workbook.get('actions').get(0).getID()).not.toEqual(
81 79
           workbook.get('actions').get(1).getID())
@@ -84,7 +82,7 @@ describe('together workbook model and controller', function() {
84 82
 
85 83
     describe("'Add Workflow' action", function () {
86 84
       it('adds a new Workflow', function () {
87
-        $scope.addWorkflow();
85
+        wbCtrl.addWorkflow();
88 86
 
89 87
         expect(workbook.get('workflows').get(0)).toBeDefined();
90 88
       });
@@ -96,7 +94,7 @@ describe('together workbook model and controller', function() {
96 94
         }));
97 95
 
98 96
         it("corresponding JSON has the right key for the Workflow", function () {
99
-          $scope.addWorkflow();
97
+          wbCtrl.addWorkflow();
100 98
 
101 99
           expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeDefined();
102 100
         });
@@ -104,7 +102,7 @@ describe('together workbook model and controller', function() {
104 102
         it("once the workflow ID is changed, it's reflected in JSON", function () {
105 103
           var newID = 'workflow10';
106 104
 
107
-          $scope.addWorkflow();
105
+          wbCtrl.addWorkflow();
108 106
           workbook.get('workflows').getByID(workflowID).setID(newID);
109 107
 
110 108
           expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeUndefined();
@@ -114,14 +112,14 @@ describe('together workbook model and controller', function() {
114 112
       });
115 113
 
116 114
       it('creates workflow with predefined name', function () {
117
-        $scope.addWorkflow();
115
+        wbCtrl.addWorkflow();
118 116
 
119 117
         expect(workbook.get('workflows').get(0).getID()).toBeGreaterThan('');
120 118
       });
121 119
 
122 120
       it('creates workflows with different names on 2 successive calls', function () {
123
-        $scope.addWorkflow();
124
-        $scope.addWorkflow();
121
+        wbCtrl.addWorkflow();
122
+        wbCtrl.addWorkflow();
125 123
 
126 124
         expect(workbook.get('workflows').get(0).getID()).not.toEqual(
127 125
           workbook.get('workflows').get(1).getID())

+ 1
- 1
package.json View File

@@ -43,6 +43,6 @@
43 43
     "postinstall": "bower install",
44 44
     "test-unit": "grunt test:unit",
45 45
     "test": "karma start ./karma-unit.conf.js",
46
-    "lint": "eslint --no-color ./merlin/static"
46
+    "lint": "eslint --no-color ./merlin/static ./extensions/mistral/static"
47 47
   }
48 48
 }

Loading…
Cancel
Save