Skip to content

Commit

Permalink
#127 fixed replacement of parameter object on adding new field
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Nov 1, 2019
1 parent 9e04546 commit 6b30752
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 194 deletions.
3 changes: 1 addition & 2 deletions samples/configs/parameterized.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
{
"name": "Simple Int",
"param": "--simple_int",
"type": "int",
"max": ""
"type": "int"
},
{
"name": "Simple Boolean",
Expand Down
2 changes: 1 addition & 1 deletion web-src/js/admin/scripts-config/ParamListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import ParameterConfigForm from './ParameterConfigForm';
export default {
name: 'ParamHeader',
name: 'ParamListItem',
components: {ParameterConfigForm},
props: {
Expand Down
27 changes: 15 additions & 12 deletions web-src/js/admin/scripts-config/ParameterConfigForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<script>
import Vue from 'vue';
import {forEachKeyValue, isEmptyArray, isEmptyString} from '../../common';
import {forEachKeyValue, isEmptyString} from '../../common';
import Checkbox from '../../components/checkbox';
import Combobox from '../../components/combobox';
import TextArea from '../../components/TextArea';
Expand All @@ -91,6 +91,13 @@
typeField
} from './parameter-fields';
function updateValue(value, configField, newValue) {
if (!value.hasOwnProperty(configField)) {
Object.assign(value, {[configField]: newValue});
}
Vue.set(value, configField, newValue);
}
export default {
name: 'ParameterConfigForm',
components: {ChipsList, TextArea, Checkbox, Combobox, Textfield},
Expand Down Expand Up @@ -121,7 +128,7 @@
};
forEachKeyValue(simpleFields, (vmField, configField) => {
this.$watch(vmField, (newValue) => Vue.set(this.value, configField, newValue));
this.$watch(vmField, (newValue) => updateValue(this.value, configField, newValue));
});
for (const child of this.$children) {
Expand Down Expand Up @@ -247,11 +254,7 @@
}
},
fileExtensions(fileExtensions) {
if (isEmptyArray(fileExtensions)) {
Vue.delete(this.value, 'file_extensions');
} else {
Vue.set(this.value, 'file_extensions', fileExtensions);
}
updateValue(this.value, 'file_extensions', fileExtensions);
},
allowedValuesFromScript() {
this.updateAllowedValues();
Expand All @@ -264,15 +267,15 @@
},
defaultValue() {
if (this.selectedType === 'multiselect') {
Vue.set(this.value, 'default', this.defaultValue.split(',').filter(s => !isEmptyString(s)));
updateValue(this.value, 'default', this.defaultValue.split(',').filter(s => !isEmptyString(s)));
} else if (this.isRecursiveFile()) {
let path = this.defaultValue.split('/').filter(s => !isEmptyString(s));
if (this.defaultValue.startsWith('/')) {
path = ['/', ...path];
}
Vue.set(this.value, 'default', path);
updateValue(this.value, 'default', path);
} else {
Vue.set(this.value, 'default', this.defaultValue);
updateValue(this.value, 'default', this.defaultValue);
}
}
},
Expand All @@ -294,9 +297,9 @@
methods: {
updateAllowedValues() {
if (this.allowedValuesFromScript) {
Vue.set(this.value, 'values', {script: this.allowedValuesScript});
updateValue(this.value, 'values', {script: this.allowedValuesScript});
} else {
Vue.set(this.value, 'values', this.allowedValues);
updateValue(this.value, 'values', this.allowedValues);
}
},
isRecursiveFile() {
Expand Down
9 changes: 6 additions & 3 deletions web-src/js/admin/scripts-config/ScriptParamList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@
}, 40);
},
parameters(parameters) {
for (const parameter of parameters) {
this.setParameterKey(parameter);
parameters :{
immediate: true,
handler(parameters) {
for (const parameter of parameters) {
this.setParameterKey(parameter);
}
}
}
}
Expand Down
31 changes: 28 additions & 3 deletions web-src/js/admin/scripts-config/script-config-module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import axios from 'axios';
import {contains, forEachKeyValue, isEmptyValue} from '../../common';

const allowedEmptyValuesInParam = ['name'];

function removeEmptyValues(config) {
for (const parameter of config.parameters) {
let emptyValueKeys = [];
forEachKeyValue(parameter, (key, value) => {
if (contains(allowedEmptyValuesInParam, key)) {
return;
}

if (isEmptyValue(value)) {
emptyValueKeys.push(key);
}
});

emptyValueKeys.forEach(key => delete parameter[key]);
}
}

export default {
state: {
Expand All @@ -21,11 +41,16 @@ export default {
});
},

save({state}) {
save({dispatch, state}) {
const config = $.extend({}, state.scriptConfig);

removeEmptyValues(config);

return axios.put('admin/scripts', {
config: state.scriptConfig,
config,
filename: state.scriptFilename
});
})
.then(dispatch('init', config.name));
}
},
mutations: {
Expand Down
4 changes: 3 additions & 1 deletion web-src/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function isEmptyArray(value) {
return isNull(value) || value.length === 0;
}

function isEmptyValue(value) {
export function isEmptyValue(value) {
if (isNull(value)) {
return true;
}
Expand All @@ -46,6 +46,8 @@ function isEmptyValue(value) {
if (typeof value === 'object') {
return isEmptyObject(value);
}

return false;
}

export function isEmptyObject(obj) {
Expand Down
Loading

0 comments on commit 6b30752

Please sign in to comment.