|
|
|
@ -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)); |
|
|
|
} |
|
|
|
|