-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
688 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<template> | ||
<ModalVue :title="title" ref="modalComponent"> | ||
<template #body | ||
><form @submit.prevent="createEtf" :id="'createEtfForm' + idSuffix"> | ||
<div class="container-fluid"> | ||
<DivError :server-errors="serverErrors" /> | ||
<div class="row"> | ||
<div class="col-xs-12"> | ||
<InputStandard | ||
v-model="met.name" | ||
:validation-schema="schema.name" | ||
:id="'name' + idSuffix" | ||
:field-label="$t('General.name')" | ||
/> | ||
</div> | ||
</div> | ||
<div class="row pt-2"> | ||
<div class="col-xs-12"> | ||
<InputStandard | ||
v-model="met.isin" | ||
:validation-schema="schema.isin" | ||
:id="'isin' + idSuffix" | ||
:field-label="$t('ETF.isin')" | ||
/> | ||
</div> | ||
</div> | ||
<div class="row pt-2"> | ||
<div class="col-xs-12"> | ||
<InputStandard | ||
v-model="met.wkn" | ||
:validation-schema="schema.wkn" | ||
:id="'wkn' + idSuffix" | ||
:field-label="$t('ETF.wkn')" | ||
/> | ||
</div> | ||
</div> | ||
<div class="row pt-2"> | ||
<div class="col-xs-12"> | ||
<InputStandard | ||
v-model="met.ticker" | ||
:validation-schema="schema.ticker" | ||
:id="'ticker' + idSuffix" | ||
:field-label="$t('ETF.ticker')" | ||
/> | ||
</div> | ||
</div> | ||
<div class="row pt-2"> | ||
<div class="col-xs-12"> | ||
<InputStandard | ||
v-model="met.chartUrl" | ||
:validation-schema="schema.chartUrl" | ||
:id="'chartUrl' + idSuffix" | ||
:field-label="$t('ETF.chartUrl')" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</template> | ||
<template #footer> | ||
<button type="button" class="btn btn-secondary" @click="resetForm"> | ||
{{ $t("General.reset") }} | ||
</button> | ||
<ButtonSubmit | ||
:button-label="$t('General.save')" | ||
:form-id="'createEtfForm' + idSuffix" | ||
/> | ||
</template> | ||
</ModalVue> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { useForm } from "vee-validate"; | ||
import { computed, ref } from "vue"; | ||
import { useI18n } from "vue-i18n"; | ||
import { string, ZodType } from "zod"; | ||
import ButtonSubmit from "../ButtonSubmit.vue"; | ||
import DivError from "../DivError.vue"; | ||
import InputStandard from "../InputStandard.vue"; | ||
import ModalVue from "../Modal.vue"; | ||
import { handleBackendError } from "@/tools/views/HandleBackendError"; | ||
import { globErr } from "@/tools/views/ZodUtil"; | ||
import type { Etf } from "@/model/etf/Etf"; | ||
import CrudEtfControllerHandler from "@/handler/CrudEtfControllerHandler"; | ||
const { t } = useI18n(); | ||
defineProps({ | ||
idSuffix: { | ||
type: String, | ||
default: "", | ||
}, | ||
}); | ||
const serverErrors = ref(new Array<string>()); | ||
const schema: Partial<{ [key in keyof Etf]: ZodType }> = { | ||
isin: string(globErr(t("ETF.validation.isin"))) | ||
.min(1) | ||
.max(30, t("ETF.validation.length.isin")), | ||
name: string(globErr(t("ETF.validation.name"))) | ||
.min(1) | ||
.max(30, t("ETF.validation.length.name")), | ||
wkn: string(globErr(t("ETF.validation.wkn"))) | ||
.min(1) | ||
.max(30, t("ETF.validation.length.wkn")), | ||
ticker: string(globErr(t("ETF.validation.ticker"))) | ||
.min(1) | ||
.max(30, t("ETF.validation.length.ticker")), | ||
chartUrl: string().max(100, t("ETF.validation.length.chartUrl")).optional(), | ||
}; | ||
const met = ref({} as Etf); | ||
const origMcp = ref({} as Etf | undefined); | ||
const modalComponent = ref(); | ||
const emit = defineEmits(["etfCreated", "etfUpdated"]); | ||
const { handleSubmit, values, setFieldTouched } = useForm(); | ||
const title = computed(() => { | ||
return origMcp.value === undefined | ||
? t("ETF.title.create") | ||
: t("ETF.title.update"); | ||
}); | ||
const resetForm = () => { | ||
if (origMcp.value) { | ||
Object.assign(met.value, origMcp.value); | ||
} else { | ||
met.value = {} as Etf; | ||
} | ||
serverErrors.value = new Array<string>(); | ||
Object.keys(values).forEach((field) => setFieldTouched(field, false)); | ||
}; | ||
const _show = async (_met?: Etf) => { | ||
origMcp.value = _met ?? undefined; | ||
resetForm(); | ||
modalComponent.value._show(); | ||
}; | ||
const createEtf = handleSubmit(() => { | ||
serverErrors.value = new Array<string>(); | ||
if (met.value.id > 0) { | ||
//update | ||
CrudEtfControllerHandler.updateEtf(met.value) | ||
.then(() => { | ||
modalComponent.value._hide(); | ||
emit("etfUpdated", met.value); | ||
}) | ||
.catch((backendError) => { | ||
handleBackendError(backendError, serverErrors); | ||
}); | ||
} else { | ||
//create | ||
CrudEtfControllerHandler.createEtf(met.value) | ||
.then((etf) => { | ||
met.value = etf; | ||
modalComponent.value._hide(); | ||
emit("etfCreated", met.value); | ||
}) | ||
.catch((backendError) => { | ||
handleBackendError(backendError, serverErrors); | ||
}); | ||
} | ||
}); | ||
defineExpose({ _show }); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<template> | ||
<ModalVue :title="$t('ETF.title.delete')" ref="modalComponent"> | ||
<template #body> | ||
<DivError :server-errors="serverErrors" /> | ||
<div class="row d-flex justify-content-center mt-3"> | ||
<div class="col-11"> | ||
<table class="table table-bordered table-hover"> | ||
<colgroup> | ||
<col span="1" style="background-color: #f2f2f2" width="35%" /> | ||
</colgroup> | ||
<tbody> | ||
<tr> | ||
<th>{{ $t("General.name") }}</th> | ||
<td>{{ etf.name }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t("ETF.isin") }}</th> | ||
<td>{{ etf.isin }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t("ETF.wkn") }}</th> | ||
<td>{{ etf.wkn }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t("ETF.ticker") }}</th> | ||
<td>{{ etf.ticker }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t("ETF.chartUrl") }}</th> | ||
<td>{{ etf.chartUrl }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</template> | ||
<template #footer> | ||
<button type="button" class="btn btn-danger" @click="deleteEtf"> | ||
{{ $t("General.delete") }} | ||
</button> | ||
</template> | ||
</ModalVue> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref } from "vue"; | ||
import DivError from "../DivError.vue"; | ||
import ModalVue from "../Modal.vue"; | ||
import { handleBackendError } from "@/tools/views/HandleBackendError"; | ||
import type { Etf } from "@/model/etf/Etf"; | ||
import CrudEtfControllerHandler from "@/handler/CrudEtfControllerHandler"; | ||
const serverErrors = ref(new Array<string>()); | ||
const etf = ref({} as Etf); | ||
const modalComponent = ref(); | ||
const emit = defineEmits(["etfDeleted"]); | ||
const _show = (_etf: Etf) => { | ||
etf.value = _etf; | ||
serverErrors.value = new Array<string>(); | ||
modalComponent.value._show(); | ||
}; | ||
const deleteEtf = () => { | ||
serverErrors.value = new Array<string>(); | ||
CrudEtfControllerHandler.deleteEtf(etf.value.id) | ||
.then(() => { | ||
modalComponent.value._hide(); | ||
emit("etfDeleted", etf.value); | ||
}) | ||
.catch((backendError) => { | ||
handleBackendError(backendError, serverErrors); | ||
}); | ||
}; | ||
defineExpose({ _show }); | ||
</script> |
Oops, something went wrong.