Browse Source

Add support of AutoScalingGroup

Change-Id: Ib0fc88eddb9bb5b02b158d199b729bf4f42f3a11
Task: #19672
Story: #2002031
Xinni Ge 10 months ago
parent
commit
6a260ecd5d
10 changed files with 438 additions and 0 deletions
  1. 1
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js
  2. 1
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/template-generator.module.js
  3. 4
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-blue.svg
  4. 3
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-gray.svg
  5. 4
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-green.svg
  6. 4
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-red.svg
  7. 144
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html
  8. 145
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.js
  9. 128
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.spec.js
  10. 4
    0
      heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.svg

+ 1
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js View File

@@ -67,6 +67,7 @@
67 67
                                 func = hotgenUtils.extract_list;
68 68
                                 break;
69 69
                             case 'resource_def':
70
+                            case 'resource':
70 71
                                 func = hotgenUtils.extract_resource_def;
71 72
                                 break;
72 73
                             default:

+ 1
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/template-generator.module.js View File

@@ -24,6 +24,7 @@
24 24
         .constant('horizon.dashboard.project.heat_dashboard.template_generator.validationRules', {
25 25
             'name': /^[A-Za-z0-9_.-]+$/,
26 26
             'path': /^\/[a-z0-9/-]+$/,
27
+            'integer': /^\d*$/,
27 28
             'keypair': /^([A-Za-z0-9_.-]{1,255})=([A-Za-z0-9_.-]{1,255})$/,
28 29
             'ip_address': /^([0-9.]{1,15})|([A-Fa-f0-9:]{1,39})$/,
29 30
             'domain': /^[A-Za-z0-9_.-]+$/,

+ 4
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-blue.svg View File

@@ -0,0 +1,4 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="55" height="55" viewBox="0 0 55 55">
2
+<rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="none" stroke="none" class="" style=""/><g class="currentLayer" style=""><title>Layer 1</title><path d="M42.1771287043557,41.60010476176677 v-20.074996256989024 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h20.07495656319317 q0.2398662089352129,0 0.41515305392632923,-0.17528719158216585 t0.17528684499111694,-0.4151538747998659 zm2.3617595956697843,-20.074996256989024 v20.074996256989024 q0,1.2177846994129382 -0.8672086015349999,2.084995015661544 t-2.084990893052231,0.8672103162486069 h-20.07495656319317 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 zm-7.085278787009353,-7.085292796584362 v2.952205331910151 h-2.3617595956697843 v-2.952205331910151 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h2.9521994945872314 v2.3617642655281212 h-2.9521994945872314 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 z" id="svg_1" class="" stroke="#3f51b5" stroke-opacity="1" fill="#3f51b5" fill-opacity="1"/></g><g><title>Layer 2</title><g id="svg_3">
3
+<circle class="frame" r="25" style="fill:none;fill-opacity=0.0;stroke-width:3;stroke:#3f51b5" cy="27.75" cx="27.5" id="svg_2"/>
4
+</g></g></svg>

+ 3
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-gray.svg View File

@@ -0,0 +1,3 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" width="55" height="55" style=""><rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="none" stroke="none" class="" style=""/><g class="currentLayer" style=""><title>Layer 1</title><path d="M42.1771287043557,41.60010476176677 v-20.074996256989024 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h20.07495656319317 q0.2398662089352129,0 0.41515305392632923,-0.17528719158216585 t0.17528684499111694,-0.4151538747998659 zm2.3617595956697843,-20.074996256989024 v20.074996256989024 q0,1.2177846994129382 -0.8672086015349999,2.084995015661544 t-2.084990893052231,0.8672103162486069 h-20.07495656319317 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 zm-7.085278787009353,-7.085292796584362 v2.952205331910151 h-2.3617595956697843 v-2.952205331910151 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h2.9521994945872314 v2.3617642655281212 h-2.9521994945872314 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 z" id="svg_1" class="" stroke="#808080" stroke-opacity="1" fill="#808080" fill-opacity="1"/></g><g><title>Layer 2</title><g id="svg_3">
2
+<circle class="frame" r="25" style="fill:none;fill-opacity=0.0;stroke-width:3;stroke:#808080" cy="27.75" cx="27.5" id="svg_2"/>
3
+</g></g></svg>

+ 4
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-green.svg View File

@@ -0,0 +1,4 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="55" height="55" viewBox="0 0 55 55">
2
+<rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="none" stroke="none" class="" style=""/><g class="currentLayer" style=""><title>Layer 1</title><path d="M42.1771287043557,41.60010476176677 v-20.074996256989024 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h20.07495656319317 q0.2398662089352129,0 0.41515305392632923,-0.17528719158216585 t0.17528684499111694,-0.4151538747998659 zm2.3617595956697843,-20.074996256989024 v20.074996256989024 q0,1.2177846994129382 -0.8672086015349999,2.084995015661544 t-2.084990893052231,0.8672103162486069 h-20.07495656319317 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 zm-7.085278787009353,-7.085292796584362 v2.952205331910151 h-2.3617595956697843 v-2.952205331910151 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h2.9521994945872314 v2.3617642655281212 h-2.9521994945872314 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 z" id="svg_1" class="" stroke="green" stroke-opacity="1" fill="green" fill-opacity="1"/></g><g><title>Layer 2</title><g id="svg_3">
3
+<circle class="frame" r="25" style="fill:none;fill-opacity=0.0;stroke-width:3;stroke:green" cy="27.75" cx="27.5" id="svg_2"/>
4
+</g></g></svg>

+ 4
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-red.svg View File

@@ -0,0 +1,4 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="55" height="55" viewBox="0 0 55 55">
2
+<rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="none" stroke="none" class="" style=""/><g class="currentLayer" style=""><title>Layer 1</title><path d="M42.1771287043557,41.60010476176677 v-20.074996256989024 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h20.07495656319317 q0.2398662089352129,0 0.41515305392632923,-0.17528719158216585 t0.17528684499111694,-0.4151538747998659 zm2.3617595956697843,-20.074996256989024 v20.074996256989024 q0,1.2177846994129382 -0.8672086015349999,2.084995015661544 t-2.084990893052231,0.8672103162486069 h-20.07495656319317 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 zm-7.085278787009353,-7.085292796584362 v2.952205331910151 h-2.3617595956697843 v-2.952205331910151 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h2.9521994945872314 v2.3617642655281212 h-2.9521994945872314 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 z" id="svg_1" class="" stroke="#C82128" stroke-opacity="1" fill="#C82128" fill-opacity="1"/></g><g><title>Layer 2</title><g id="svg_3">
3
+<circle class="frame" r="25" style="fill:none;fill-opacity=0.0;stroke-width:3;stroke:#C82128" cy="27.75" cx="27.5" id="svg_2"/>
4
+</g></g></svg>

+ 144
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html View File

@@ -0,0 +1,144 @@
1
+<md-tabs md-dynamic-height md-stretch-tabs="always" md-border-bottom>
2
+    <md-tab label="Properties" >
3
+        <md-content layout-padding>
4
+
5
+            <md-input-container class="md-block" flex-gt-xs>
6
+                <label>Max Size</label>
7
+                <input ng-model="$ctrl.autoscalinggroup.max_size" name="max_size" type="number" min="0" ng-pattern="validate_integer" required/>
8
+                <div ng-messages="$ctrl.formReference.max_size.$error" role="alert" multiple>
9
+                    <div ng-message="number">You did not enter a valid integer.</div>
10
+                    <div ng-message="min">You did not enter a non-negative number.</div>
11
+                    <div ng-message="required">You must supply a maximum size.</div>
12
+                    <div ng-message="pattern">You must supply an integer.</div>
13
+                </div>
14
+            </md-input-container>
15
+
16
+            <md-input-container class="md-block" flex-gt-xs>
17
+                <label>Min Size</label>
18
+                <input ng-model="$ctrl.autoscalinggroup.min_size" name="min_size" type="number" min="0" ng-pattern="validate_integer" required/>
19
+                <div ng-messages="$ctrl.formReference.min_size.$error" role="alert" multiple>
20
+                    <div ng-message="number">You did not enter a valid integer.</div>
21
+                    <div ng-message="min">You did not enter a non-negative number.</div>
22
+                    <div ng-message="required">You must supply a minimum size.</div>
23
+                    <div ng-message="pattern">You must supply an integer.</div>
24
+                </div>
25
+            </md-input-container>
26
+            <md-input-container class="md-block" flex-gt-xs>
27
+            <label>Select Resource Type by: </label>
28
+                <md-select ng-model="is_upload" aria-label="" required name="is_upload">
29
+                    <md-option value="false">existing items</md-option>
30
+                    <md-option value="true">uploading a template file</md-option>
31
+                </md-select>
32
+                <div ng-messages="$ctrl.formReference.is_upload.$error" role="alert" multiple>
33
+                    <div ng-message="required" class="my-message">You did not specify Resource Type.</div>
34
+                </div>
35
+            </md-input-container>
36
+
37
+            <div ng-if="is_upload == 'false'">
38
+                <label>Resource Type</label>
39
+                <md-input-container class="md-block" flex-gt-xs>
40
+                    <md-select ng-model="controller.autoscalinggroup.resource.type" aria-label="Resource Type">
41
+                        <md-option ng-repeat="resource_type in resource_types" ng-value="resource_type">{$ resource_type $}</md-option>
42
+                    </md-select>
43
+                </md-input-container>
44
+
45
+            </div>
46
+
47
+            <div ng-if="is_upload == 'true'">
48
+                <div layout-gt-sm="row" style="padding:0">
49
+                    <md-input-container class="md-block" flex-gt-xs>
50
+                        <label>Resource Type</label>
51
+                        <input ng-model="controller.autoscalinggroup.resource.type" name="filename" type="text" readonly/>
52
+                    </md-input-container>
53
+                    <md-input-container class="md-block">
54
+                        <md-button class="md-raised md-accent md-button md-ink-ripple" ng-click="clickUpload()" style="font-size:11px; top:-15px;">
55
+                            <span class="ng-scope">choose a file</span>
56
+                        </md-button>
57
+                    </md-input-container>
58
+                </div>
59
+
60
+                <md-input-container class="md-block" flex-gt-xs>
61
+                <label>Resource Type Content</label>
62
+                    <textarea ng-model="filecontent" readonly rows="10" maxlength="65536" name="filecontent"></textarea>
63
+                </md-input-container>
64
+
65
+                <input ng-show="false" multiple="" ng-model="file" id="resourcetype-file" name="file" type="file" onchange="angular.element(this).scope().file_upload(this)" accept=".yaml"/>
66
+            </div>
67
+
68
+            <label>Resource Properties</label>
69
+            <md-button ng-click="$ctrl.add_property()" aria-label="Add" class="md-icon-button">
70
+                <i class="fa fa-fw fa-plus"></i>
71
+            </md-button>
72
+            <div ng-repeat="record in $ctrl.autoscalinggroup.resource.properties" ng-class-odd="'odd'" ng-class-even="'even'">
73
+                <div layout-gt-xs="row" >
74
+                    <md-input-container class="md-block" flex-gt-xs>
75
+                        <label>Property</label>
76
+                        <input ng-model="record.key" type="text">
77
+                    </md-input-container>
78
+                    <md-input-container class="md-block" flex-gt-xs>
79
+                        <label>Value</label>
80
+                        <input ng-model="record.value" type="text">
81
+                    </md-input-container>
82
+                    <md-button ng-click="$ctrl.delete_property($index)" aria-label="Delete" class="md-icon-button"><i class="fa fa-fw fa-times"></i></md-button>
83
+                </div>
84
+            </div>
85
+
86
+            <md-input-container class="md-block" flex-gt-xs>
87
+                <label>Cooldown</label>
88
+                <input ng-model="$ctrl.autoscalinggroup.cooldown" name="cooldown" type="number" ng-pattern="validate_integer" min="0"/>
89
+                <div ng-messages="$ctrl.formReference.cooldown.$error" role="alert" multiple>
90
+                    <div ng-message="number">You did not enter a valid integer.</div>
91
+                    <div ng-message="min">You did not enter a non-negative number.</div>
92
+                    <div ng-message="pattern">You must supply an integer.</div>
93
+                </div>
94
+            </md-input-container>
95
+
96
+            <md-input-container class="md-block" flex-gt-xs>
97
+                <label>Desired Capacity</label>
98
+                <input ng-model="$ctrl.autoscalinggroup.desired_capacity" name="desired_capacity" type="number" ng-pattern="validate_integer" min="0"/>
99
+                <div ng-messages="$ctrl.formReference.desired_capacity.$error" role="alert" multiple>
100
+                    <div ng-message="number">You did not enter a valid integer.</div>
101
+                    <div ng-message="min">You did not enter a non-negative number.</div>
102
+                    <div ng-message="pattern">You must supply an integer.</div>
103
+                </div>
104
+            </md-input-container>
105
+
106
+            <label>Rolling Updates</label>
107
+            <md-input-container class="md-block" flex-gt-xs>
108
+                <label>Min In Service</label>
109
+                <input ng-model="$ctrl.autoscalinggroup.rolling_updates.min_in_service" name="min_in_service" type="number" ng-pattern="validate_integer" min="0"/>
110
+                <div ng-messages="$ctrl.formReference.min_in_service.$error" role="alert" multiple>
111
+                    <div ng-message="number">You did not enter a valid integer.</div>
112
+                    <div ng-message="min">You did not enter a non-negative number.</div>
113
+                    <div ng-message="pattern">You must supply an integer.</div>
114
+                </div>
115
+            </md-input-container>
116
+            <md-input-container class="md-block" flex-gt-xs>
117
+                <label>Pause Time</label>
118
+                <input ng-model="$ctrl.autoscalinggroup.rolling_updates.pause_time" name="pause_time" type="number" min="0"/>
119
+                <div ng-messages="$ctrl.formReference.pause_time.$error" role="alert" multiple>
120
+                    <div ng-message="number">You did not enter a valid number.</div>
121
+                    <div ng-message="min">You did not enter a non-negative number.</div>
122
+                </div>
123
+            </md-input-container>
124
+
125
+            <md-input-container class="md-block" flex-gt-xs>
126
+                <label>Max Batch Size</label>
127
+                <input ng-model="$ctrl.autoscalinggroup.rolling_updates.max_batch_size" name="max_batch_size" type="number" ng-pattern="validate_integer" min="1"/>
128
+                <div ng-messages="$ctrl.formReference.max_batch_size.$error" role="alert" multiple>
129
+                    <div ng-message="number">You did not enter a valid integer.</div>
130
+                    <div ng-message="min">You did not enter a positive number.</div>
131
+                    <div ng-message="pattern">You must supply an integer.</div>
132
+                </div>
133
+            </md-input-container>
134
+
135
+        </md-content>
136
+    </md-tab>
137
+
138
+    <md-tab label="Depends on">
139
+        <md-content layout-padding>
140
+            <depends-on dependson='dependson'></depends-on>
141
+        </md-content>
142
+    </md-tab>
143
+
144
+</md-tabs>

+ 145
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.js View File

@@ -0,0 +1,145 @@
1
+(function() {
2
+    'use strict';
3
+
4
+    /* OS::Heat::AutoScalingGroup
5
+     *
6
+     */
7
+
8
+    angular.module('horizon.dashboard.project.heat_dashboard.template_generator')
9
+      .value('osHeatAutoScalingGroupSettings',
10
+        {
11
+            resource_key: "OS__Heat__AutoScalingGroup",
12
+            admin: false,
13
+            icon: {
14
+                class: 'fa-hdd-o',
15
+                name: 'OS::Heat::AutoScalingGroup',
16
+                code: '\uf0a0',
17
+                color: '#0bb238'
18
+            },
19
+            label: 'name',
20
+            modal_component: '<os-heat-autoscalinggroup autoscalinggroup="resource" dependson="dependson" connectedoptions="connectedoptions" form-reference="resourceForm"></os-heat-autoscalinggroup>',
21
+            edge_settings: null,
22
+            necessary_properties: ['max_size', 'min_size', 'resource']
23
+        }
24
+    )
25
+
26
+    // Register the resource to globals
27
+    angular.module('horizon.dashboard.project.heat_dashboard.template_generator')
28
+      .run(['osHeatAutoScalingGroupSettings','hotgenGlobals', function(osHeatAutoScalingGroupSettings, hotgenGlobals){
29
+        hotgenGlobals.update_resource_icons(
30
+            osHeatAutoScalingGroupSettings.resource_key ,
31
+            osHeatAutoScalingGroupSettings.icon);
32
+
33
+        hotgenGlobals.update_resource_components(
34
+            osHeatAutoScalingGroupSettings.resource_key,
35
+            osHeatAutoScalingGroupSettings.modal_component);
36
+
37
+        hotgenGlobals.update_node_labels(
38
+            osHeatAutoScalingGroupSettings.resource_key,
39
+            osHeatAutoScalingGroupSettings.label);
40
+    }]);
41
+
42
+
43
+    // Define  <os-heat-autoscalinggroup> controller
44
+    function osHeatAutoScalingGroupController($scope, hotgenGlobals, hotgenNotify, validationRules) {
45
+        this.$onInit = function(){
46
+            $scope.dependson = this.dependson;
47
+            if (typeof this.autoscalinggroup.resource === 'undefined'){
48
+                this.autoscalinggroup.resource = {'type': '', 'properties': [{}]};
49
+            }
50
+            if (typeof this.autoscalinggroup.rolling_updates === 'undefined'){
51
+                this.autoscalinggroup.rolling_updates = {};
52
+            }
53
+            if (this.autoscalinggroup.resource.type){
54
+                $scope.filecontent = hotgenGlobals.get_reference_file(this.autoscalinggroup.resource.type);
55
+            }
56
+        };
57
+
58
+        $scope.validate_integer = validationRules['integer'];
59
+        $scope.controller = this;
60
+        $scope.resource_types = [];
61
+        var resource_types = hotgenGlobals.get_resource_types();
62
+        resource_types.forEach(function(element){
63
+            $scope.resource_types.push(element.replace(/_/g, ':'));
64
+        });
65
+        $scope.options = hotgenGlobals.get_resource_options();
66
+        $scope.update_upload = function(){
67
+            if ($scope.controller.autoscalinggroup && $scope.controller.autoscalinggroup.resource && $scope.controller.autoscalinggroup.resource.type.indexOf('.yaml') != -1){
68
+                return 'true';
69
+            }
70
+            return 'false';
71
+        }
72
+
73
+        $scope.is_upload = $scope.update_upload();
74
+
75
+        $scope.$watch('is_upload', function(newValue, oldValue){
76
+            if (oldValue === newValue){
77
+                return;
78
+            }
79
+            if (newValue === true || newValue === 'true'){
80
+                $scope.controller.autoscalinggroup.resource.properties = [{}];
81
+                if (!($scope.filecontent && $scope.filecontent.length >= 0)){
82
+                    $scope.controller.autoscalinggroup.resource.type = '';
83
+                }
84
+            } else{
85
+            //  ;
86
+            }
87
+        });
88
+
89
+        $scope.file_upload = function(element){
90
+            var file = element.files[0];
91
+            if (!file){
92
+                return;
93
+            }
94
+            var textType = /\.yaml$/;
95
+            if (file.name.match(textType)) {
96
+                var reader = new FileReader();
97
+                $scope.controller.autoscalinggroup.resource.type = file.name;
98
+                reader.onload = function(e) {
99
+                    hotgenNotify.show_success('Read file content.');
100
+                    hotgenGlobals.set_reference_file(file.name, reader.result)
101
+                    $scope.filecontent = reader.result;
102
+                }
103
+                reader.readAsText(file);
104
+           } else {
105
+               hotgenNotify.show_error('File type is not supported.');
106
+           }
107
+        }
108
+        $scope.clickUpload = function(){
109
+            setTimeout(function () {
110
+              angular.element('#resourcetype-file').trigger('click');
111
+            }, 0);
112
+        };
113
+        this.delete_property = function(index){
114
+            this.autoscalinggroup.resource.properties.splice(index, 1);
115
+
116
+        }
117
+        this.add_property = function(){
118
+            this.autoscalinggroup.resource.properties.push({});
119
+        }
120
+    }
121
+
122
+    function osHeatAutoScalingGroupPath (basePath){
123
+        return  basePath + 'js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html';
124
+    }
125
+
126
+    osHeatAutoScalingGroupController.$inject = ['$scope', 'hotgenGlobals', 'hotgenNotify',
127
+        'horizon.dashboard.project.heat_dashboard.template_generator.validationRules',
128
+    ];
129
+
130
+    osHeatAutoScalingGroupPath.$inject = ['horizon.dashboard.project.heat_dashboard.template_generator.basePath'];
131
+
132
+    angular.module('horizon.dashboard.project.heat_dashboard.template_generator')
133
+      .component('osHeatAutoscalinggroup', {
134
+        templateUrl: osHeatAutoScalingGroupPath,
135
+        controller: osHeatAutoScalingGroupController,
136
+        bindings: {
137
+          'autoscalinggroup': '=',
138
+          'dependson': '=',
139
+          'connectedoptions': '<',
140
+          'formReference': '<',
141
+        }
142
+    });
143
+
144
+
145
+})();

+ 128
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.spec.js View File

@@ -0,0 +1,128 @@
1
+(function() {
2
+    'use strict';
3
+
4
+    describe('component os-heat-auto-scaling-group', function(){
5
+
6
+        beforeEach(module('horizon.dashboard.project.heat_dashboard.template_generator'));
7
+
8
+        beforeEach(module('appTemplates'));
9
+
10
+        var $scope, $isolateScope, $compile;
11
+        var hotgenNotify;
12
+        var element;
13
+
14
+        beforeEach(inject(function($injector) {
15
+            $scope = $injector.get('$rootScope').$new();
16
+            $compile = $injector.get('$compile');
17
+            hotgenNotify = $injector.get('hotgenNotify');
18
+            spyOn(hotgenNotify, 'show_success');
19
+            spyOn(hotgenNotify, 'show_error');
20
+
21
+            $scope.resource = {};
22
+            $scope.dependson = [];
23
+            $scope.connectedoptions = [];
24
+            $scope.resourceForm = {};
25
+
26
+            // element will enable you to test your directive's element on the DOM
27
+            element = $compile(angular.element('<os-heat-autoscalinggroup autoscalinggroup="resource"'+
28
+                    ' dependson="dependson" connectedoptions="connectedoptions"'+
29
+                    ' form-reference="resourceForm"></os-heat-autoscalinggroup>'))($scope);
30
+
31
+            // Digest needs to be called to set any values on the directive's scope
32
+            $scope.$digest();
33
+
34
+            $isolateScope = element.isolateScope();
35
+        }));
36
+
37
+        it('find tab title Properties',  function() {
38
+            expect(element.find('span').html()).toContain("Properties");
39
+            expect($isolateScope.is_upload).toEqual('false');
40
+        });
41
+
42
+        it('find tab title with resource set',  function() {
43
+            $scope.resource = {resource: {type: 'filepath.yaml'}};
44
+
45
+            // element will enable you to test your directive's element on the DOM
46
+            element = $compile(angular.element('<os-heat-autoscalinggroup autoscalinggroup="resource"'+
47
+                    ' dependson="dependson" connectedoptions="connectedoptions"'+
48
+                    ' form-reference="resourceForm"></os-heat-autoscalinggroup'))($scope);
49
+
50
+            // Digest needs to be called to set any values on the directive's scope
51
+            $scope.$digest();
52
+
53
+            $isolateScope = element.isolateScope();
54
+
55
+            expect($isolateScope.is_upload ).toEqual('true');
56
+        });
57
+
58
+        it('$scope.is_upload should be successfully watched',  function() {
59
+            $isolateScope.is_upload = 'true';
60
+            $isolateScope.$digest();
61
+
62
+            $isolateScope.is_upload = 'false';
63
+            $isolateScope.$digest();
64
+            $isolateScope.filecontent = 'some thing here';
65
+
66
+            $isolateScope.is_upload = 'true';
67
+            $isolateScope.$digest();
68
+
69
+            expect($isolateScope.controller.autoscalinggroup.resource.type ).toEqual('');
70
+        });
71
+
72
+        it('file should be successfully uploaded',  function() {
73
+            var blob = new Blob([''], {type: '', });
74
+            blob['name'] = 'filename.yaml'
75
+            var upload_element = {files: [blob], }
76
+            spyOn(window, 'FileReader').and.returnValue({
77
+              readAsText: function(file) {
78
+                this.onload({});
79
+              },
80
+              result: 'file contents.'
81
+            });
82
+            $isolateScope.file_upload(upload_element);
83
+
84
+            expect($isolateScope.filecontent).toEqual('file contents.');
85
+            expect(hotgenNotify.show_success).toHaveBeenCalled();
86
+        });
87
+
88
+        it('file should be not uploaded return undefined',  function() {
89
+            var upload_element = {files: []}
90
+            var returnValue = $isolateScope.file_upload(upload_element);
91
+
92
+            expect(returnValue).toEqual(undefined);
93
+
94
+        });
95
+
96
+        it('file should be not uploaded show error',  function() {
97
+            var upload_element = {files: [{name: 'file.txt'}]}
98
+            var returnValue = $isolateScope.file_upload(upload_element);
99
+
100
+            expect(hotgenNotify.show_error).toHaveBeenCalled();
101
+
102
+        });
103
+
104
+        it('property should be successfully added',  function() {
105
+            var $ctrl = $isolateScope.$ctrl;
106
+            $ctrl.add_property();
107
+
108
+            expect($ctrl.autoscalinggroup.resource.properties.length).toEqual(2);
109
+        });
110
+
111
+        it('property should be successfully deleted',  function() {
112
+            var $ctrl = $isolateScope.$ctrl;
113
+            $ctrl.delete_property();
114
+
115
+            expect($ctrl.autoscalinggroup.resource.properties.length).toEqual(0);
116
+        });
117
+
118
+        it('click upload',  function() {
119
+            spyOn(window, 'setTimeout').and.callFake(function(){});
120
+
121
+            $isolateScope.clickUpload();
122
+
123
+            expect(setTimeout).toHaveBeenCalled();
124
+        });
125
+
126
+    });
127
+
128
+})();

+ 4
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.svg View File

@@ -0,0 +1,4 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="55" height="55" viewBox="0 0 55 55">
2
+<rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="none" stroke="none" class="" style=""/><g class="currentLayer" style=""><title>Layer 1</title><path d="M42.1771287043557,41.60010476176677 v-20.074996256989024 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h20.07495656319317 q0.2398662089352129,0 0.41515305392632923,-0.17528719158216585 t0.17528684499111694,-0.4151538747998659 zm2.3617595956697843,-20.074996256989024 v20.074996256989024 q0,1.2177846994129382 -0.8672086015349999,2.084995015661544 t-2.084990893052231,0.8672103162486069 h-20.07495656319317 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 zm-7.085278787009353,-7.085292796584362 v2.952205331910151 h-2.3617595956697843 v-2.952205331910151 q0,-0.2398666832176999 -0.17528684499111694,-0.4151538747998659 t-0.41515305392632923,-0.17528719158216585 h-20.07495656319317 q-0.2398662089352129,0 -0.41515305392632923,0.17528719158216585 t-0.17528684499111694,0.4151538747998659 v20.074996256989024 q0,0.2398666832176999 0.17528684499111694,0.4151538747998659 t0.41515305392632923,0.17528719158216585 h2.9521994945872314 v2.3617642655281212 h-2.9521994945872314 q-1.2177822915172334,0 -2.084990893052231,-0.8672103162486069 t-0.8672086015349999,-2.084995015661544 v-20.074996256989024 q0,-1.2177846994129382 0.8672086015349999,-2.084995015661544 t2.084990893052231,-0.8672103162486069 h20.07495656319317 q1.2177822915172334,0 2.084990893052231,0.8672103162486069 t0.8672086015349999,2.084995015661544 z" id="svg_1" class="" stroke="#000000" stroke-opacity="1" fill="#000000" fill-opacity="1"/></g><g><title>Layer 2</title><g id="svg_3">
3
+<circle class="frame" r="25" style="fill:none;fill-opacity=0.0;stroke-width:3;stroke:black" cy="27.75" cx="27.5" id="svg_2"/>
4
+</g></g></svg>

Loading…
Cancel
Save