зеркало из https://github.com/mozilla/smarthome.git
Ser services default values
Signed-off-by: Aoun Bukhari <bukhari@itemis.de>
This commit is contained in:
Родитель
946a2ce571
Коммит
a92dabe19f
|
@ -182,6 +182,9 @@ angular.module('PaperUI.controllers.configuration', []).controller('Configuratio
|
|||
}, function(configDescription) {
|
||||
if (configDescription) {
|
||||
$scope.parameters = configService.getRenderingModel(configDescription.parameters, configDescription.parameterGroups);
|
||||
if (!jQuery.isEmptyObject($scope.configuration)) {
|
||||
$scope.configuration = configService.setConfigDefaults($scope.configuration, $scope.parameters);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -197,6 +200,9 @@ angular.module('PaperUI.controllers.configuration', []).controller('Configuratio
|
|||
if (config) {
|
||||
$scope.configuration = config;
|
||||
$scope.configArray = configService.getConfigAsArray(config);
|
||||
if ($scope.parameters && $scope.parameters.length > 0) {
|
||||
$scope.configuration = configService.setConfigDefaults($scope.configuration, $scope.parameters);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -221,6 +227,7 @@ angular.module('PaperUI.controllers.configuration', []).controller('Configuratio
|
|||
if ($scope.expertMode) {
|
||||
$scope.configuration = configService.getConfigAsObject($scope.configArray);
|
||||
}
|
||||
$scope.configuration = configService.setConfigDefaults($scope.configuration, $scope.parameters);
|
||||
serviceConfigService.updateConfig({
|
||||
id : (serviceId ? serviceId : $scope.serviceId)
|
||||
}, $scope.configuration, function() {
|
||||
|
|
|
@ -181,6 +181,28 @@ angular.module('PaperUI.services', [ 'PaperUI.constants' ]).config(function($htt
|
|||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
setConfigDefaults : function(configuration, groups) {
|
||||
for (var i = 0; i < groups.length; i++) {
|
||||
$.each(groups[i].parameters, function(i, parameter) {
|
||||
if (parameter.defaultValue !== 'null') {
|
||||
if (configuration[parameter.name] == null || configuration[parameter.name] == "") {
|
||||
if (parameter.type === 'TEXT') {
|
||||
configuration[parameter.name] = parameter.defaultValue
|
||||
} else if (parameter.type === 'BOOLEAN') {
|
||||
configuration[parameter.name] = new Boolean(parameter.defaultValue);
|
||||
} else if (parameter.type === 'INTEGER' || parameter.type === 'DECIMAL') {
|
||||
configuration[parameter.name] = parseInt(parameter.defaultValue);
|
||||
} else {
|
||||
configuration[parameter.name] = parameter.defaultValue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
configuration[parameter.name] = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
};
|
||||
});
|
|
@ -7,18 +7,18 @@
|
|||
<div class="parameter col-sm-6 col-xs-12" ng-switch="parameter.element">
|
||||
<div ng-switch-when="input">
|
||||
<div ng-if="parameter.type=='INTEGER'">
|
||||
<md-input-container> <label>{{parameter.label}}</label> <input ng-init="focus=false" name="{{parameter.name}}" type="number" min="{{parameter.min}}" max="{{parameter.max}}" ng-model="configuration[parameter.name]" ng-required="parameter.required" type="{{parameter.inputType}}" ng-focus="focus=true" ng-blur="focus=false">
|
||||
<div ng-messages="form.configForm.{{parameter.name}}.$error" ng-show="focus">
|
||||
<div ng-message="min">Minimum allowed number is {{parameter.min}}</div>
|
||||
<div ng-message="max">Maximum allowed number is {{parameter.max}}</div>
|
||||
<div ng-message="required">Field is required</div>
|
||||
</div>
|
||||
<span ng-messages="" ng-show="!focus">
|
||||
<p class="hint">
|
||||
<small>{{parameter.description}}</small>
|
||||
</p>
|
||||
</span> </md-input-container>
|
||||
</div>
|
||||
<md-input-container> <label>{{parameter.label}}</label> <input ng-init="focus=false" name="{{parameter.name}}" type="number" min="{{parameter.min}}" max="{{parameter.max}}" ng-model="configuration[parameter.name]" ng-required="parameter.required" type="{{parameter.inputType}}" ng-focus="focus=true" ng-blur="focus=false">
|
||||
<div ng-messages="form.configForm.{{parameter.name}}.$error" ng-show="focus">
|
||||
<div ng-message="min">Minimum allowed number is {{parameter.min}}</div>
|
||||
<div ng-message="max">Maximum allowed number is {{parameter.max}}</div>
|
||||
<div ng-message="required">Field is required</div>
|
||||
</div>
|
||||
<span ng-messages="" ng-show="!focus">
|
||||
<p class="hint">
|
||||
<small>{{parameter.description}}</small>
|
||||
</p>
|
||||
</span> </md-input-container>
|
||||
</div>
|
||||
<div ng-if="parameter.type=='TEXT'">
|
||||
<md-input-container> <label>{{parameter.label}}</label> <input ng-init="focus=false" name="{{parameter.name}}" ng-minlength="parameter.min" ng-maxlength="parameter.max" ng-model="configuration[parameter.name]" ng-required="parameter.required" type="{{parameter.inputType}}" ng-focus="focus=true" ng-blur="focus=false">
|
||||
<div ng-messages="form.configForm.{{parameter.name}}.$error" ng-show="focus">
|
||||
|
|
Загрузка…
Ссылка в новой задаче