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 (history_fallback ());
app.use (http_proxy ('localhost:8080'));
app.use (http_proxy ('localhost:8081'));
app.listen (3000, () => {
console.log ('listening on 3000');

View File

@ -1,63 +1,69 @@
<template>
<div
v-if="template.type === 'object'"
class="editor"
>
<p v-text="template.name" />
<ConfigEditor
v-for="(prop,key) of template.properties"
:key="key"
:template="prop"
:config="config[prop.name]"
<div class="config-editor">
<p
clasS="label"
v-text="template.name"
/>
</div>
<div
v-else-if="template.type === 'array'"
class="editor"
>
<ConfigEditor
v-for="(child,key) of config"
:key="key"
:config="child"
:template="template.child"
/>
<button type="button">
add
</button>
</div>
<div
v-else-if="template.type === 'string'"
class="editor"
>
<label v-text="template.name || ''" />
<input
v-model="config"
type="text"
<!-- editor -->
<div
v-if="template.type === 'object'"
class="editor"
>
</div>
<div
v-else-if="template.type === 'number'"
class="editor"
>
<label v-text="template.name || ''" />
<input
v-model="config"
type="number"
<ConfigEditor
v-for="(prop,key) of template.properties"
:key="key"
:template="prop"
:config="config[prop.name]"
/>
</div>
<div
v-else-if="template.type === 'array'"
class="editor"
>
</div>
<div
v-else-if="template.type === 'boolean'"
class="editor"
>
<label v-text="template.name || ''" />
<input
v-model="config"
type="checkbox"
<ConfigEditor
v-for="(child,key) of config"
:key="key"
:config="child"
:template="template.child"
/>
<button
type="button"
@click="config.push(create_default(template.child))"
>
add
</button>
</div>
<div
v-else-if="template.type === 'string'"
class="editor"
>
</div>
<pre v-else>
<input
v-model="config"
type="text"
>
</div>
<div
v-else-if="template.type === 'number'"
class="editor"
>
<input
v-model="config"
type="number"
>
</div>
<div
v-else-if="template.type === 'boolean'"
class="editor"
>
<input
v-model="config"
type="checkbox"
>
</div>
<pre v-else>
invalid config
</pre>
</div>
</template>
<script>
@ -70,13 +76,46 @@ export default {
type: Object,
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>
<style scoped>
.config-editor {
display: grid;
grid-template-areas: 'label editor';
grid-template-columns: auto 1fr;
}
.editor {
border: 1px solid black;
margin-left: 10px;
grid-column: editor;
}
.label {
display: inline-block;
grid-column: label;
}
</style>