Fix Edit form for Number Type ID's

This commit is contained in:
Samuel Lorch 2023-05-13 22:51:07 +02:00
parent 4ab4ab37d5
commit 64a449e9b4
2 changed files with 18 additions and 5 deletions

View file

@ -87,6 +87,7 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
name: "Firewall",
"forwardrules": {
name: "ForwardRule",
idType: "Number",
validationSchema: toFormValidator(
zod.object({
name: zod.string(),
@ -111,6 +112,7 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
},
"destinationnatrules": {
name: "DestinationNATRule",
idType: "Number",
validationSchema: toFormValidator(
zod.object({
name: zod.string(),
@ -141,6 +143,7 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
},
"sourcenatrules": {
name: "SourceNATRule",
idType: "Number",
validationSchema: toFormValidator(
zod.object({
name: zod.string(),
@ -208,6 +211,7 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
},
"staticroutes": {
name: "StaticRoute",
idType: "Number",
validationSchema: toFormValidator(
zod.object({
name: zod.string(),
@ -275,6 +279,7 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
name: "Service",
"dhcpv4servers": {
name: "DHCPv4Server",
idType: "Number",
validationSchema: toFormValidator(
zod.object({
}),
@ -299,6 +304,7 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
},
"ntpservers": {
name: "NTPServer",
idType: "Number",
validationSchema: toFormValidator(
zod.object({
}),
@ -314,6 +320,7 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
},
"dnsservers": {
name: "DNSServer",
idType: "Number",
validationSchema: toFormValidator(
zod.object({
}),

View file

@ -4,22 +4,28 @@ import { apiCall } from "../../../../api";
import getPlugins from '../../../../plugins';
const p = getPlugins();
const props = $defineProps<{subsystem: string, entity: string, id: string}>();
const props = $defineProps<{subsystem: string, entity: string, id: string | number}>();
const { subsystem, entity, id } = $(props);
let initialValues = $ref({} as {});
let loading = $ref(true);
async function load(){
loading = true
let res = await apiCall(editTypes[subsystem].name +".Get"+ editTypes[subsystem][entity].name, {id: id});
loading = true;
let res: any;
if (editTypes[subsystem][entity].idType == "Number") {
res = await apiCall(editTypes[subsystem].name +".Get"+ editTypes[subsystem][entity].name, {id: id as number - 0});
} else {
res = await apiCall(editTypes[subsystem].name +".Get"+ editTypes[subsystem][entity].name, {id: id});
}
if (res.Error === null) {
console.debug("update data", res.Data);
initialValues = res.Data;
} else {
console.debug("error", res);
}
loading = false
loading = false;
}
async function update(value: any) {
@ -44,7 +50,7 @@ onMounted(async() => {
<div v-if="editTypes[subsystem][entity]">
<PageHeader :title="'Update ' + editTypes[subsystem][entity].name">
</PageHeader>
<NiceForm v-if="!loading" class="scroll cl-secondary" :submit="update" :discard="() => $router.go(-1)" :sections="editTypes[subsystem][entity].sections" :initialValues="initialValues"/>
<NiceForm v-if="!loading" class="scroll cl-secondary" :submit="update" :discard="() => $router.go(-1)" :sections="editTypes[subsystem][entity].sections" :initial-values="initialValues"/>
<p v-else>Loading...</p>
</div>
<div v-else>