Skip to content

Commit

Permalink
closes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliL committed Apr 30, 2024
1 parent 7370c49 commit 8cc3895
Show file tree
Hide file tree
Showing 15 changed files with 688 additions and 75 deletions.
24 changes: 12 additions & 12 deletions src/components/etf/CreateEtfFlowModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
v-model="etfFlow.etfId"
:validation-schema="schema.etfId"
id="etf"
:field-label="$t('ETF.etf')"
:field-label="$t('General.etf')"
:select-box-values="etfs"
/>
</div>
Expand All @@ -21,7 +21,7 @@
v-model="bookingdate"
:validation-schema="schema.timestamp"
id="bookingdate"
:field-label="$t('ETF.bookingdate')"
:field-label="$t('ETFFlow.bookingdate')"
/>
</div>
</div>
Expand All @@ -31,7 +31,7 @@
v-model="bookingtime"
:validation-schema="schema.nanoseconds"
id="bookingtime"
:field-label="$t('ETF.bookingtime')"
:field-label="$t('ETFFlow.bookingtime')"
/>
</div>
</div>
Expand All @@ -43,7 +43,7 @@
id="amount"
field-type="number"
step="0.001"
:field-label="$t('ETF.amount')"
:field-label="$t('ETFFlow.amount')"
/>
</div>
</div>
Expand All @@ -56,7 +56,7 @@
id="price"
step="0.01"
field-type="number"
:field-label="$t('ETF.price')"
:field-label="$t('ETFFlow.price')"
>
<template #icon
><span class="input-group-text"
Expand Down Expand Up @@ -107,13 +107,13 @@ const { t } = useI18n();
const serverErrors = ref(new Array<string>());
const amountErrMsg = globErr(t("ETF.validation.amount"));
const priceErrMsg = globErr(t("ETF.validation.price"));
const amountErrMsg = globErr(t("ETFFlow.validation.amount"));
const priceErrMsg = globErr(t("ETFFlow.validation.price"));
const schema: Partial<{ [key in keyof EtfFlow]: ZodType }> = {
etfId: number(globErr(t("ETF.validation.etfId"))).gt(0),
timestamp: date(globErr(t("ETF.validation.timestamp"))),
nanoseconds: string(globErr(t("ETF.validation.nanoseconds"))).regex(
etfId: number(globErr(t("ETFFlow.validation.etfId"))).gt(0),
timestamp: date(globErr(t("ETFFlow.validation.timestamp"))),
nanoseconds: string(globErr(t("ETFFlow.validation.nanoseconds"))).regex(
new RegExp("^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]:[0-9]{3}$"),
),
amount: union(
Expand All @@ -138,8 +138,8 @@ const { handleSubmit, values, setFieldTouched } = useForm();
const title = computed(() => {
return etfFlow.value === undefined
? t("ETF.title.create")
: t("ETF.title.update");
? t("ETFFlow.title.create")
: t("ETFFlow.title.update");
});
const resetForm = () => {
Expand Down
172 changes: 172 additions & 0 deletions src/components/etf/CreateEtfModal.vue
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>
10 changes: 5 additions & 5 deletions src/components/etf/DeleteEtfFlowModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<ModalVue :title="$t('ETF.title.delete')" ref="modalComponent">
<ModalVue :title="$t('ETFFlow.title.delete')" ref="modalComponent">
<template #body>
<DivError :server-errors="serverErrors" />
<div class="row d-flex justify-content-center mt-3">
Expand All @@ -10,19 +10,19 @@
</colgroup>
<tbody>
<tr>
<th>{{ $t("ETF.etf") }}</th>
<th>{{ $t("General.etf") }}</th>
<td>{{ etfName }}</td>
</tr>
<tr>
<th>{{ $t("ETF.bookingdate") }}</th>
<th>{{ $t("ETFFlow.bookingdate") }}</th>
<td>{{ timestampString }}</td>
</tr>
<tr>
<th>{{ $t("ETF.amount") }}</th>
<th>{{ $t("ETFFlow.amount") }}</th>
<td :class="amountClass">{{ amountString }}</td>
</tr>
<tr>
<th>{{ $t("ETF.price") }}</th>
<th>{{ $t("ETFFlow.price") }}</th>
<td><SpanAmount :amount="etfFlow.price" /></td>
</tr>
</tbody>
Expand Down
83 changes: 83 additions & 0 deletions src/components/etf/DeleteEtfModal.vue
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>
Loading

0 comments on commit 8cc3895

Please sign in to comment.