Browse Source

Remove 'type' attribute from <typed-field>

... because it's excessive and can be calculated from 'value' attribute.

Change-Id: Id56024027ee455518619f1ee846d0b0735d5210d
changes/53/209253/3
Timur Sufiev 4 years ago
parent
commit
d6e2842979

+ 2
- 2
extensions/mistral/templates/mistral/create.html View File

@@ -51,14 +51,14 @@
51 51
               <div ng-repeat="(label, field) in row track by field.uid()">
52 52
                 <div ng-if="field.isAtomic()" class="col-xs-6">
53 53
                   <labeled label="label" for="{$ field.uid() $}">
54
-                    <typed-field value="field" type="{$ field.getType() $}"></typed-field>
54
+                    <typed-field value="field"></typed-field>
55 55
                   </labeled>
56 56
                 </div>
57 57
                 <div ng-if="!field.isAtomic()" class="col-xs-12">
58 58
                   <collapsible-group content="field" title="label"
59 59
                                      additive="{$ field.isAdditive() $}" on-add="field.add()">
60 60
                     <div ng-class="field.isPlainStructure() ? 'col-xs-6' : 'col-xs-12'">
61
-                      <typed-field value="field" type="{$ field.getType() $}"></typed-field>
61
+                      <typed-field value="field"></typed-field>
62 62
                     </div>
63 63
                   </collapsible-group>
64 64
                 </div>

+ 3
- 3
merlin/static/merlin/js/merlin.directives.js View File

@@ -221,11 +221,11 @@
221 221
     return {
222 222
       restrict: 'E',
223 223
       scope: {
224
-        value: '=',
225
-        type: '@'
224
+        value: '='
226 225
       },
227 226
       link: function(scope, element) {
228
-        templates.templateReady(scope.type).then(function(template) {
227
+        var type = scope.value.getType();
228
+        templates.templateReady(type).then(function(template) {
229 229
           element.append($compile(template)(scope));
230 230
         });
231 231
       }

+ 3
- 4
merlin/static/merlin/templates/fields/dictionary.html View File

@@ -3,7 +3,7 @@
3 3
     <div ng-repeat="(key, field) in value | extractFields track by field.uid()">
4 4
       <labeled ng-if="field.isAtomic()" label="field.keyValue" for="{$ field.uid() $}">
5 5
         <div class="input-group">
6
-          <typed-field id="{$ field.uid() $}" value="field" type="{$ field.getType() $}"></typed-field>
6
+          <typed-field id="{$ field.uid() $}" value="field"></typed-field>
7 7
         <span class="input-group-btn">
8 8
           <button class="btn btn-default" ng-click="value.removeItem(field.keyValue())">
9 9
             <i class="fa fa-minus-circle"></i>
@@ -15,10 +15,9 @@
15 15
         <collapsible-group ng-if="!field.inline" class="col-xs-12" title="field.keyValue"
16 16
                            on-remove="value.removeItem(field.keyValue())"
17 17
                            additive="{$ field.isAdditive() $}" on-add="field.add()">
18
-          <typed-field value="field" type="{$ field.getType() $}"></typed-field>
18
+          <typed-field value="field"></typed-field>
19 19
         </collapsible-group>
20
-        <typed-field ng-if="field.inline"
21
-                     value="field" type="{$ field.getType() $}"></typed-field>
20
+        <typed-field ng-if="field.inline" value="field"></typed-field>
22 21
       </div>
23 22
     </div>
24 23
   </div>

+ 3
- 3
merlin/static/merlin/templates/fields/frozendict.html View File

@@ -3,19 +3,19 @@
3 3
     <div ng-repeat="(key, field) in row track by field.uid()">
4 4
       <div ng-if="field.isAtomic()" class="col-xs-6">
5 5
         <labeled label="key" for="{$ field.uid() $}">
6
-          <typed-field value="field" type="{$ field.getType() $}"></typed-field>
6
+          <typed-field value="field"></typed-field>
7 7
         </labeled>
8 8
       </div>
9 9
       <div ng-if="!field.isAtomic()">
10 10
         <collapsible-group ng-if="!field.inline" class="col-xs-12" title="key"
11 11
                            additive="{$ field.isAdditive() $}" on-add="field.add()">
12 12
           <div ng-class="field.isPlainStructure() ? 'col-xs-6' : 'col-xs-12'">
13
-            <typed-field value="field" type="{$ field.getType() $}"></typed-field>
13
+            <typed-field value="field"></typed-field>
14 14
           </div>
15 15
         </collapsible-group>
16 16
         <labeled ng-if="field.inline" class="col-xs-6"
17 17
                  label="key" for="{$ field.uid() $}">
18
-          <typed-field value="field" type="{$ field.getType() $}"></typed-field>
18
+          <typed-field value="field"></typed-field>
19 19
         </labeled>
20 20
       </div>
21 21
     </div>

+ 2
- 2
merlin/static/merlin/templates/fields/list.html View File

@@ -3,7 +3,7 @@
3 3
     <div ng-repeat="(index, field) in value | extractFields track by field.uid()">
4 4
       <div ng-if="field.isAtomic()" class="form-group">
5 5
         <div class="input-group">
6
-          <typed-field value="field" type="{$ field.getType() $}"></typed-field>
6
+          <typed-field value="field"></typed-field>
7 7
         <span class="input-group-btn">
8 8
           <button class="btn btn-default" ng-click="value.remove($index)">
9 9
             <i class="fa fa-minus-circle"></i>
@@ -12,7 +12,7 @@
12 12
         </div>
13 13
       </div>
14 14
       <div ng-if="!field.isAtomic()">
15
-        <typed-field value="field" type="{$ field.getType() $}"></typed-field>
15
+        <typed-field value="field"></typed-field>
16 16
       </div>
17 17
     </div>
18 18
   </div>

+ 7
- 7
merlin/test/js/merlin.directives.spec.js View File

@@ -232,12 +232,12 @@ describe('merlin directives', function() {
232 232
         '<div><typed-field ' + contents + '></typed-field></div>')($scope);
233 233
     }
234 234
 
235
-    it('type of resulting field is determined by `type` attribute', function() {
235
+    it('type of resulting field is determined by `value.getType` method', function() {
236 236
       var element1, element2;
237
-      $scope.value1 = {type: 'text'};
238
-      $scope.value2 = {type: 'number'};
239
-      element1 = makeFieldElem('value="value1" type="{$ value1.type $}"');
240
-      element2 = makeFieldElem('value="value2" type="{$ value2.type $}"');
237
+      $scope.value1 = {getType: function() { return 'text'; }};
238
+      $scope.value2 = {getType: function() { return 'number'; }};
239
+      element1 = makeFieldElem('value="value1"');
240
+      element2 = makeFieldElem('value="value2"');
241 241
       $httpBackend.flush();
242 242
       $scope.$digest();
243 243
 
@@ -247,8 +247,8 @@ describe('merlin directives', function() {
247 247
 
248 248
     it('field is not rendered until the corresponding template has been served', function() {
249 249
       var element;
250
-      $scope.value = {type: 'text'};
251
-      element = makeFieldElem('value="value" type="{$ value.type $}"');
250
+      $scope.value = {getType: function() {return 'text'; }};
251
+      element = makeFieldElem('value="value"');
252 252
       expect(element.html()).not.toContain('<textarea');
253 253
 
254 254
       $httpBackend.flush();

Loading…
Cancel
Save