thingsboard-aplcache
Changes
ui/src/app/common/utils.service.js 26(+25 -1)
Details
ui/src/app/common/utils.service.js 26(+25 -1)
diff --git a/ui/src/app/common/utils.service.js b/ui/src/app/common/utils.service.js
index b8a98a8..9d99781 100644
--- a/ui/src/app/common/utils.service.js
+++ b/ui/src/app/common/utils.service.js
@@ -136,6 +136,7 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t
var service = {
getDefaultDatasource: getDefaultDatasource,
+ generateObjectFromJsonSchema: generateObjectFromJsonSchema,
getDefaultDatasourceJson: getDefaultDatasourceJson,
getDefaultAlarmDataKeys: getDefaultAlarmDataKeys,
getMaterialColor: getMaterialColor,
@@ -277,11 +278,34 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t
function getDefaultDatasource(dataKeySchema) {
var datasource = angular.copy(defaultDatasource);
if (angular.isDefined(dataKeySchema)) {
- datasource.dataKeys[0].settings = jsonSchemaDefaults(dataKeySchema);
+ datasource.dataKeys[0].settings = generateObjectFromJsonSchema(dataKeySchema);
}
return datasource;
}
+ function generateObjectFromJsonSchema(schema) {
+ var obj = jsonSchemaDefaults(schema);
+ deleteNullProperties(obj);
+ return obj;
+ }
+
+ function deleteNullProperties(obj) {
+ if (angular.isUndefined(obj) || obj == null) {
+ return;
+ }
+ for (var propName in obj) {
+ if (obj[propName] === null || angular.isUndefined(obj[propName])) {
+ delete obj[propName];
+ } else if (angular.isObject(obj[propName])) {
+ deleteNullProperties(obj[propName]);
+ } else if (angular.isArray(obj[propName])) {
+ for (var i=0;i<obj[propName].length;i++) {
+ deleteNullProperties(obj[propName][i]);
+ }
+ }
+ }
+ }
+
function getDefaultDatasourceJson(dataKeySchema) {
return angular.toJson(getDefaultDatasource(dataKeySchema));
}
diff --git a/ui/src/app/components/widget/widget-config.directive.js b/ui/src/app/components/widget/widget-config.directive.js
index 4e19bfd..3b66757 100644
--- a/ui/src/app/components/widget/widget-config.directive.js
+++ b/ui/src/app/components/widget/widget-config.directive.js
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import jsonSchemaDefaults from 'json-schema-defaults';
+
import thingsboardTypes from '../../common/types.constant';
import thingsboardUtils from '../../common/utils.service';
import thingsboardEntityAliasSelect from '../entity-alias-select.directive';
@@ -421,7 +421,7 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout
}
if (angular.isDefined(scope.datakeySettingsSchema.schema)) {
- result.settings = jsonSchemaDefaults(scope.datakeySettingsSchema.schema);
+ result.settings = utils.generateObjectFromJsonSchema(scope.datakeySettingsSchema.schema);
}
return result;