editor layout, array insertion

This commit is contained in:
Timo Hocker 2020-08-05 12:30:19 +02:00
parent 015a89fe2b
commit b09e851580
2 changed files with 93 additions and 54 deletions

View File

@ -38,7 +38,7 @@ const user = {
app.use (api); app.use (api);
app.use (history_fallback ()); app.use (history_fallback ());
app.use (http_proxy ('localhost:8080')); app.use (http_proxy ('localhost:8081'));
app.listen (3000, () => { app.listen (3000, () => {
console.log ('listening on 3000'); console.log ('listening on 3000');

View File

@ -1,9 +1,14 @@
<template> <template>
<div class="config-editor">
<p
clasS="label"
v-text="template.name"
/>
<!-- editor -->
<div <div
v-if="template.type === 'object'" v-if="template.type === 'object'"
class="editor" class="editor"
> >
<p v-text="template.name" />
<ConfigEditor <ConfigEditor
v-for="(prop,key) of template.properties" v-for="(prop,key) of template.properties"
:key="key" :key="key"
@ -21,7 +26,10 @@
:config="child" :config="child"
:template="template.child" :template="template.child"
/> />
<button type="button"> <button
type="button"
@click="config.push(create_default(template.child))"
>
add add
</button> </button>
</div> </div>
@ -29,7 +37,6 @@
v-else-if="template.type === 'string'" v-else-if="template.type === 'string'"
class="editor" class="editor"
> >
<label v-text="template.name || ''" />
<input <input
v-model="config" v-model="config"
type="text" type="text"
@ -39,7 +46,6 @@
v-else-if="template.type === 'number'" v-else-if="template.type === 'number'"
class="editor" class="editor"
> >
<label v-text="template.name || ''" />
<input <input
v-model="config" v-model="config"
type="number" type="number"
@ -49,7 +55,6 @@
v-else-if="template.type === 'boolean'" v-else-if="template.type === 'boolean'"
class="editor" class="editor"
> >
<label v-text="template.name || ''" />
<input <input
v-model="config" v-model="config"
type="checkbox" type="checkbox"
@ -58,6 +63,7 @@
<pre v-else> <pre v-else>
invalid config invalid config
</pre> </pre>
</div>
</template> </template>
<script> <script>
@ -70,13 +76,46 @@ export default {
type: Object, type: Object,
required: true required: true
} }
},
methods: {
create_default (template) {
if (typeof template.default !== 'undefined')
return template.default;
if (template.type === 'string')
return '';
if (template.type === 'number')
return 0;
if (template.type === 'boolean')
return false;
if (template.type === 'array')
return [];
if (template.type === 'object') {
const res = {};
for (const prop of template.properties)
res[prop.name] = this.create_default (prop);
return res;
}
return null;
}
} }
}; };
</script> </script>
<style scoped> <style scoped>
.config-editor {
display: grid;
grid-template-areas: 'label editor';
grid-template-columns: auto 1fr;
}
.editor { .editor {
border: 1px solid black; border: 1px solid black;
margin-left: 10px; margin-left: 10px;
grid-column: editor;
}
.label {
display: inline-block;
grid-column: label;
} }
</style> </style>