UI: Remove null properties from objects generated by json schema.
This commit is contained in:
parent
2cf25e78ca
commit
8d962cb57a
@ -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));
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user