Cleaner plugin conf saving
This commit is contained in:
@@ -25,7 +25,7 @@ function loadDefaults (schema, configuration) {
|
||||
return
|
||||
}
|
||||
forEach(schema.properties, (item, key) => {
|
||||
if (!(key in configuration)) {
|
||||
if (item.type === 'boolean' && !(key in configuration)) { // String default values are used as placeholders in view
|
||||
configuration[key] = item && item.default
|
||||
}
|
||||
})
|
||||
@@ -35,8 +35,26 @@ function cleanUpConfiguration (schema, configuration) {
|
||||
if (!schema || !configuration) {
|
||||
return
|
||||
}
|
||||
|
||||
function sanitizeItem (item) {
|
||||
if (typeof item === 'string') {
|
||||
item = trim(item)
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
function keepItem (item) {
|
||||
if (item === undefined || item === null || item === '' || (Array.isArray(item) && item.length === 0) || item.__use === false) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
forEach(configuration, (item, key) => {
|
||||
if (item && item.__use === false || !schema.properties || !(key in schema.properties)) {
|
||||
item = sanitizeItem(item)
|
||||
configuration[key] = item
|
||||
if (!keepItem(item) || !schema.properties || !(key in schema.properties)) {
|
||||
delete configuration[key]
|
||||
} else if (schema.properties && schema.properties[key] && schema.properties[key].type === 'object') {
|
||||
cleanUpConfiguration(schema.properties[key], item)
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
| {{key}}
|
||||
span.text-warning(ng-if = 'ctrl.isRequired(key, plugin.configurationSchema)') *
|
||||
.col-md-5
|
||||
input.form-control(ng-if = 'prop.type === "string" && !ctrl.isPassword(key)', type = 'text', ng-model = 'plugin.configuration[key]', ng-required = 'ctrl.isRequired(key, plugin.configurationSchema)')
|
||||
input.form-control(ng-if = 'prop.type === "string" && !ctrl.isPassword(key)', type = 'text', ng-model = 'plugin.configuration[key]', ng-required = 'ctrl.isRequired(key, plugin.configurationSchema)', placeholder = '{{ plugin.configurationSchema.properties[key].default }}')
|
||||
input.form-control(ng-if = 'prop.type === "string" && ctrl.isPassword(key)', type = 'password', ng-model = 'plugin.configuration[key]', ng-required = 'ctrl.isRequired(key, plugin.configurationSchema)')
|
||||
multi-string-input(ng-if = 'prop.type === "array" && prop.items.type === "string"', model = 'plugin.configuration[key]')
|
||||
.checkbox(ng-if = 'prop.type === "boolean"'): label: input(type = 'checkbox', ng-model = 'plugin.configuration[key]')
|
||||
|
||||
Reference in New Issue
Block a user