Commit 8d962cb57a641164b9ad4cb1b0c94c9e92bf04fa
1 parent
2cf25e78
UI: Remove null properties from objects generated by json schema.
Showing
2 changed files
with
27 additions
and
3 deletions
@@ -136,6 +136,7 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t | @@ -136,6 +136,7 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t | ||
136 | 136 | ||
137 | var service = { | 137 | var service = { |
138 | getDefaultDatasource: getDefaultDatasource, | 138 | getDefaultDatasource: getDefaultDatasource, |
139 | + generateObjectFromJsonSchema: generateObjectFromJsonSchema, | ||
139 | getDefaultDatasourceJson: getDefaultDatasourceJson, | 140 | getDefaultDatasourceJson: getDefaultDatasourceJson, |
140 | getDefaultAlarmDataKeys: getDefaultAlarmDataKeys, | 141 | getDefaultAlarmDataKeys: getDefaultAlarmDataKeys, |
141 | getMaterialColor: getMaterialColor, | 142 | getMaterialColor: getMaterialColor, |
@@ -277,11 +278,34 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t | @@ -277,11 +278,34 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t | ||
277 | function getDefaultDatasource(dataKeySchema) { | 278 | function getDefaultDatasource(dataKeySchema) { |
278 | var datasource = angular.copy(defaultDatasource); | 279 | var datasource = angular.copy(defaultDatasource); |
279 | if (angular.isDefined(dataKeySchema)) { | 280 | if (angular.isDefined(dataKeySchema)) { |
280 | - datasource.dataKeys[0].settings = jsonSchemaDefaults(dataKeySchema); | 281 | + datasource.dataKeys[0].settings = generateObjectFromJsonSchema(dataKeySchema); |
281 | } | 282 | } |
282 | return datasource; | 283 | return datasource; |
283 | } | 284 | } |
284 | 285 | ||
286 | + function generateObjectFromJsonSchema(schema) { | ||
287 | + var obj = jsonSchemaDefaults(schema); | ||
288 | + deleteNullProperties(obj); | ||
289 | + return obj; | ||
290 | + } | ||
291 | + | ||
292 | + function deleteNullProperties(obj) { | ||
293 | + if (angular.isUndefined(obj) || obj == null) { | ||
294 | + return; | ||
295 | + } | ||
296 | + for (var propName in obj) { | ||
297 | + if (obj[propName] === null || angular.isUndefined(obj[propName])) { | ||
298 | + delete obj[propName]; | ||
299 | + } else if (angular.isObject(obj[propName])) { | ||
300 | + deleteNullProperties(obj[propName]); | ||
301 | + } else if (angular.isArray(obj[propName])) { | ||
302 | + for (var i=0;i<obj[propName].length;i++) { | ||
303 | + deleteNullProperties(obj[propName][i]); | ||
304 | + } | ||
305 | + } | ||
306 | + } | ||
307 | + } | ||
308 | + | ||
285 | function getDefaultDatasourceJson(dataKeySchema) { | 309 | function getDefaultDatasourceJson(dataKeySchema) { |
286 | return angular.toJson(getDefaultDatasource(dataKeySchema)); | 310 | return angular.toJson(getDefaultDatasource(dataKeySchema)); |
287 | } | 311 | } |
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -import jsonSchemaDefaults from 'json-schema-defaults'; | 16 | + |
17 | import thingsboardTypes from '../../common/types.constant'; | 17 | import thingsboardTypes from '../../common/types.constant'; |
18 | import thingsboardUtils from '../../common/utils.service'; | 18 | import thingsboardUtils from '../../common/utils.service'; |
19 | import thingsboardEntityAliasSelect from '../entity-alias-select.directive'; | 19 | import thingsboardEntityAliasSelect from '../entity-alias-select.directive'; |
@@ -421,7 +421,7 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout | @@ -421,7 +421,7 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout | ||
421 | } | 421 | } |
422 | 422 | ||
423 | if (angular.isDefined(scope.datakeySettingsSchema.schema)) { | 423 | if (angular.isDefined(scope.datakeySettingsSchema.schema)) { |
424 | - result.settings = jsonSchemaDefaults(scope.datakeySettingsSchema.schema); | 424 | + result.settings = utils.generateObjectFromJsonSchema(scope.datakeySettingsSchema.schema); |
425 | } | 425 | } |
426 | 426 | ||
427 | return result; | 427 | return result; |