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 = {
|
var service = {
|
||||||
getDefaultDatasource: getDefaultDatasource,
|
getDefaultDatasource: getDefaultDatasource,
|
||||||
|
generateObjectFromJsonSchema: generateObjectFromJsonSchema,
|
||||||
getDefaultDatasourceJson: getDefaultDatasourceJson,
|
getDefaultDatasourceJson: getDefaultDatasourceJson,
|
||||||
getDefaultAlarmDataKeys: getDefaultAlarmDataKeys,
|
getDefaultAlarmDataKeys: getDefaultAlarmDataKeys,
|
||||||
getMaterialColor: getMaterialColor,
|
getMaterialColor: getMaterialColor,
|
||||||
@ -277,11 +278,34 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t
|
|||||||
function getDefaultDatasource(dataKeySchema) {
|
function getDefaultDatasource(dataKeySchema) {
|
||||||
var datasource = angular.copy(defaultDatasource);
|
var datasource = angular.copy(defaultDatasource);
|
||||||
if (angular.isDefined(dataKeySchema)) {
|
if (angular.isDefined(dataKeySchema)) {
|
||||||
datasource.dataKeys[0].settings = jsonSchemaDefaults(dataKeySchema);
|
datasource.dataKeys[0].settings = generateObjectFromJsonSchema(dataKeySchema);
|
||||||
}
|
}
|
||||||
return datasource;
|
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) {
|
function getDefaultDatasourceJson(dataKeySchema) {
|
||||||
return angular.toJson(getDefaultDatasource(dataKeySchema));
|
return angular.toJson(getDefaultDatasource(dataKeySchema));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import jsonSchemaDefaults from 'json-schema-defaults';
|
|
||||||
import thingsboardTypes from '../../common/types.constant';
|
import thingsboardTypes from '../../common/types.constant';
|
||||||
import thingsboardUtils from '../../common/utils.service';
|
import thingsboardUtils from '../../common/utils.service';
|
||||||
import thingsboardEntityAliasSelect from '../entity-alias-select.directive';
|
import thingsboardEntityAliasSelect from '../entity-alias-select.directive';
|
||||||
@ -421,7 +421,7 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (angular.isDefined(scope.datakeySettingsSchema.schema)) {
|
if (angular.isDefined(scope.datakeySettingsSchema.schema)) {
|
||||||
result.settings = jsonSchemaDefaults(scope.datakeySettingsSchema.schema);
|
result.settings = utils.generateObjectFromJsonSchema(scope.datakeySettingsSchema.schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user