mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 10:58:21 +00:00
fix Update to use NicerForm
This commit is contained in:
parent
568d8cac5c
commit
4d928ca00e
1 changed files with 19 additions and 14 deletions
|
@ -7,37 +7,35 @@ const p = getPlugins();
|
||||||
const props = $defineProps<{subsystem: string, entity: string, id: string | number}>();
|
const props = $defineProps<{subsystem: string, entity: string, id: string | number}>();
|
||||||
const { subsystem, entity, id } = $(props);
|
const { subsystem, entity, id } = $(props);
|
||||||
|
|
||||||
let initialValues = $ref({} as {});
|
let vm = $ref({});
|
||||||
let loading = $ref(true);
|
let loading = $ref(true);
|
||||||
|
|
||||||
async function load(){
|
async function load(){
|
||||||
loading = true;
|
loading = true;
|
||||||
let res: any;
|
let res: any;
|
||||||
if (editTypes[subsystem][entity].idType == 'Number') {
|
if (editTypes[subsystem][entity].idType == 'Number') {
|
||||||
res = await apiCall(`${subsystem}.${entity}.get`, {id: id as number - 0});
|
res = await apiCall(`${subsystem}.${entity}.get`, {index: id as number - 0});
|
||||||
} else {
|
} else {
|
||||||
res = await apiCall(`${subsystem}.${entity}.get`, {id: id});
|
res = await apiCall(`${subsystem}.${entity}.get`, {name: id});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.Error === null) {
|
if (res.Error === null) {
|
||||||
console.debug('update data', res.Data);
|
console.debug('update data', res.Data);
|
||||||
initialValues = res.Data;
|
vm = res.Data;
|
||||||
} else {
|
} else {
|
||||||
console.debug('error', res);
|
console.debug('error', res);
|
||||||
}
|
}
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function update(value: any) {
|
async function update() {
|
||||||
console.debug('value', value);
|
console.debug('value', vm);
|
||||||
let res: any;
|
let res: any;
|
||||||
|
|
||||||
if (editTypes[subsystem][entity].idType == 'Number') {
|
if (editTypes[subsystem][entity].idType == 'Number') {
|
||||||
res = await apiCall(`${subsystem}.${entity}.update`, {id: id as number - 0, thing: value});
|
res = await apiCall(`${subsystem}.${entity}.update`, {index: id as number - 0, thing: vm});
|
||||||
} else {
|
} else {
|
||||||
// TODO dont have name in value at all, see create (index.vue)
|
res = await apiCall(`${subsystem}.${entity}.update`, {name: id, thing: vm});
|
||||||
delete value.name;
|
|
||||||
res = await apiCall(`${subsystem}.${entity}.update`, {id: id, thing: value});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.Error === null) {
|
if (res.Error === null) {
|
||||||
|
@ -56,15 +54,22 @@ onMounted(async() => {
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div v-if="editTypes[subsystem][entity]">
|
<p v-if="loading">Loading...</p>
|
||||||
|
<div v-else-if="editTypes[subsystem][entity]">
|
||||||
<PageHeader :title="'Update ' + editTypes[subsystem][entity].name">
|
<PageHeader :title="'Update ' + editTypes[subsystem][entity].name">
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<NiceForm v-if="!loading" class="scroll cl-secondary" :submit="update" :discard="() => $router.go(-1)" :sections="editTypes[subsystem][entity].sections" :initial-values="initialValues"/>
|
<NicerForm class="scroll cl-secondary" :fields="editTypes[subsystem][entity].fields" v-model="vm"/>
|
||||||
<p v-else>Loading...</p>
|
<div class="actions">
|
||||||
|
<div class="flex-grow"/>
|
||||||
|
<button @click="update">Submit</button>
|
||||||
|
<div class="space"/>
|
||||||
|
<button @click="$router.go(-1)">Discard</button>
|
||||||
|
<div class="flex-grow"/>
|
||||||
|
</div>
|
||||||
|
<p>{{ vm }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<PageHeader title="Error"/>
|
<PageHeader title="Error"/>
|
||||||
No editType for this Entity
|
No editType for this Entity
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue