Commit 3f76ab12fb5dc32f61b2d7ada911dbed9fbe9924

Authored by Mirco Pizzichini
1 parent fc6e219b

Add further datakey settings: tooltip, text color, min-max range, margins, mandatory

@@ -56,6 +56,7 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type @@ -56,6 +56,7 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type
56 vm.datasources = null; 56 vm.datasources = null;
57 57
58 vm.cellStyle = cellStyle; 58 vm.cellStyle = cellStyle;
  59 + vm.textColor = textColor;
59 vm.discardAll = discardAll; 60 vm.discardAll = discardAll;
60 vm.inputChanged = inputChanged; 61 vm.inputChanged = inputChanged;
61 vm.postData = postData; 62 vm.postData = postData;
@@ -82,7 +83,7 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type @@ -82,7 +83,7 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type
82 return {}; 83 return {};
83 } 84 }
84 85
85 - function cellStyle(key) { 86 + function cellStyle(key, rowIndex, firstKey, lastKey) {
86 var style = {}; 87 var style = {};
87 if (key) { 88 if (key) {
88 var styleInfo = vm.stylesInfo[key.label]; 89 var styleInfo = vm.stylesInfo[key.label];
@@ -97,6 +98,33 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type @@ -97,6 +98,33 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type
97 style = defaultStyle(); 98 style = defaultStyle();
98 } 99 }
99 } 100 }
  101 + if (vm.settings.rowMargin) {
  102 + if (angular.isUndefined(style.marginTop) && rowIndex != 0) {
  103 + style.marginTop = (vm.settings.rowMargin / 2) + 'px';
  104 + }
  105 + if (angular.isUndefined(style.marginBottom)) {
  106 + style.marginBottom = (vm.settings.rowMargin / 2) + 'px';
  107 + }
  108 + }
  109 + if (vm.settings.columnMargin) {
  110 + if (angular.isUndefined(style.marginLeft) && !firstKey) {
  111 + style.marginLeft = (vm.settings.columnMargin / 2) + 'px';
  112 + }
  113 + if (angular.isUndefined(style.marginRight) && !lastKey) {
  114 + style.marginRight = (vm.settings.columnMargin / 2) + 'px';
  115 + }
  116 + }
  117 + return style;
  118 + }
  119 +
  120 + function textColor(key) {
  121 + var style = {};
  122 + if (key) {
  123 + var styleInfo = vm.stylesInfo[key.label];
  124 + if (styleInfo.color) {
  125 + style = { color: styleInfo.color };
  126 + }
  127 + }
100 return style; 128 return style;
101 } 129 }
102 130
@@ -232,7 +260,8 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type @@ -232,7 +260,8 @@ function MultipleInputWidgetController($q, $scope, attributeService, toast, type
232 260
233 vm.stylesInfo[dataKey.label] = { 261 vm.stylesInfo[dataKey.label] = {
234 useCellStyleFunction: useCellStyleFunction, 262 useCellStyleFunction: useCellStyleFunction,
235 - cellStyleFunction: cellStyleFunction 263 + cellStyleFunction: cellStyleFunction,
  264 + color: keySettings.color
236 }; 265 };
237 266
238 row.data.push(dataKey); 267 row.data.push(dataKey);
@@ -46,10 +46,3 @@ md-toast { @@ -46,10 +46,3 @@ md-toast {
46 font-size: 14px !important; 46 font-size: 14px !important;
47 } 47 }
48 } 48 }
49 -  
50 -.footer {  
51 - position: absolute;  
52 - bottom: 0;  
53 - left: 0;  
54 - width: 100%;  
55 -}  
@@ -15,22 +15,34 @@ @@ -15,22 +15,34 @@
15 limitations under the License. 15 limitations under the License.
16 16
17 --> 17 -->
18 -<form class="tb-multiple-input" name="multipleInputForm" ng-submit="vm.postData($event)"> 18 +<form class="tb-multiple-input" name="multipleInputForm" ng-submit="vm.postData($event)" novalidate>
19 <div style="padding: 0 8px; margin: auto 0;"> 19 <div style="padding: 0 8px; margin: auto 0;">
20 - <div ng-show="vm.entityDetected" layout="row" flex ng-repeat="row in vm.rows track by $index">  
21 - <div layout="column" flex ng-repeat="key in row.data track by $index">  
22 - <md-input-container class="md-icon-float" ng-style="vm.cellStyle(key)">  
23 - <label>{{key.label}}</label>  
24 - <md-icon class="material-icons" ng-if="key.settings.icon"> 20 + <div ng-show="vm.entityDetected" layout="row" flex ng-repeat="row in vm.rows" ng-init="rowIndex=$index">
  21 + <div layout="column" flex ng-repeat="key in row.data track by $index" ng-init="keyIndex=$index">
  22 + <md-tooltip class="tb-tooltip-multiline" ng-if="key.settings.tooltipMessage && key.settings.tooltipMessage.length" md-direction="left">
  23 + <span ng-bind-html="key.settings.tooltipMessage"></span>
  24 + </md-tooltip>
  25 + <md-input-container class="md-block" ng-style="vm.cellStyle(key, rowIndex, $first, $last)">
  26 + <label ng-style="vm.textColor(key)">{{key.label}}</label>
  27 + <md-icon ng-style="vm.textColor(key)" class="material-icons" ng-if="key.settings.icon">
25 {{key.settings.icon}} 28 {{key.settings.icon}}
26 </md-icon> 29 </md-icon>
27 - <input name="key.name" 30 + <input name="value{{rowIndex}}{{keyIndex}}"
  31 + ng-style="vm.textColor(key)"
28 ng-disabled="key.settings.readOnly" 32 ng-disabled="key.settings.readOnly"
29 ng-model="key.currentValue" 33 ng-model="key.currentValue"
  34 + min="{{key.settings.min}}"
  35 + max="{{key.settings.max}}"
  36 + ng-required="key.settings.required"
30 type="{{key.settings.inputType}}" 37 type="{{key.settings.inputType}}"
31 step="{{key.settings.step}}" 38 step="{{key.settings.step}}"
32 md-select-on-focus 39 md-select-on-focus
33 ng-change="vm.inputChanged()"> 40 ng-change="vm.inputChanged()">
  41 + <div ng-messages="multipleInputForm['value' + rowIndex + keyIndex].$error">
  42 + <div ng-message="min">Value must be greater than {{key.settings.min}}</div>
  43 + <div ng-message="max">Value must be lower than {{key.settings.max}}</div>
  44 + <div ng-message="required">This field is required</div>
  45 + </div>
34 </md-input-container> 46 </md-input-container>
35 </div> 47 </div>
36 </div> 48 </div>
@@ -44,12 +56,12 @@ @@ -44,12 +56,12 @@
44 Timeseries parameter cannot be used in this widget 56 Timeseries parameter cannot be used in this widget
45 </div> 57 </div>
46 </div> 58 </div>
47 - <div class="footer md-padding" layout="row" layout-align="end center" ng-show="vm.entityDetected && vm.dataKeyDetected"> 59 + <div class="md-padding" layout="row" layout-align="end center" ng-show="vm.entityDetected && vm.dataKeyDetected">
48 <md-button class="md-primary" ng-click="vm.discardAll()" style="max-height: 50px;margin-right:20px;" ng-disabled="!vm.hasAnyChange"> 60 <md-button class="md-primary" ng-click="vm.discardAll()" style="max-height: 50px;margin-right:20px;" ng-disabled="!vm.hasAnyChange">
49 - {{ 'action.discard-changes' | translate }} 61 + {{ 'action.undo' | translate }}
50 </md-button> 62 </md-button>
51 <md-button class="md-raised md-primary" type="submit" value="Submit" style="max-height: 50px;margin-right:20px;" 63 <md-button class="md-raised md-primary" type="submit" value="Submit" style="max-height: 50px;margin-right:20px;"
52 - ng-disabled="!vm.hasAnyChange" ng-click="vm.isFocused = false"> 64 + ng-disabled="!vm.hasAnyChange || multipleInputForm.$invalid" ng-click="vm.isFocused = false">
53 {{ 'action.save' | translate }} 65 {{ 'action.save' | translate }}
54 </md-button> 66 </md-button>
55 </div> 67 </div>