Skip to content

Commit

Permalink
closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliL committed May 3, 2024
1 parent b888402 commit 5f030dc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 95 deletions.
8 changes: 0 additions & 8 deletions src/handler/EtfControllerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ class EtfControllerHandler extends AbstractControllerHandler {
const response = await this.api.listEtfFlowsById(etfId);
return this.handleListEtfFlowsResponse(response);
}
async listEtfFlows(): Promise<EtfDepot> {
const response = await this.api.listEtfFlows();
return this.handleListEtfFlowsResponse(response);
}

async handleListEtfFlowsResponse(
response: AxiosResponse<ListEtfFlowsResponse, any>,
Expand All @@ -61,7 +57,6 @@ class EtfControllerHandler extends AbstractControllerHandler {
const etfListViewData = {} as EtfDepot;
etfListViewData.calcEtfAskPrice = listEtfFlowsResponse.calcEtfAskPrice;
etfListViewData.calcEtfBidPrice = listEtfFlowsResponse.calcEtfBidPrice;
etfListViewData.defaultEtfId = listEtfFlowsResponse.defaultEtfId;
etfListViewData.calcEtfSalePieces = listEtfFlowsResponse.calcEtfSalePieces;
etfListViewData.calcEtfTransactionCosts =
listEtfFlowsResponse.calcEtfTransactionCosts;
Expand All @@ -74,9 +69,6 @@ class EtfControllerHandler extends AbstractControllerHandler {
listEtfFlowsResponse.etfEffectiveFlowTransports?.map((flow) => {
return mapEtfEffectiveFlowTransportToModel(flow);
});
etfListViewData.etfs = listEtfFlowsResponse.etfTransports?.map((etf) => {
return mapEtfTransportToModel(etf);
});

return etfListViewData;
}
Expand Down
3 changes: 0 additions & 3 deletions src/model/etf/EtfDepot.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { Etf } from "./Etf";
import type { EtfFlow } from "./EtfFlow";

export type EtfDepot = {
etfs?: Array<Etf>;
etfFlows?: Array<EtfFlow>;
etfEffectiveFlows?: Array<EtfFlow>;
defaultEtfId?: number;
calcEtfSalePieces?: number;
calcEtfBidPrice?: number;
calcEtfAskPrice?: number;
Expand Down
152 changes: 71 additions & 81 deletions src/views/etf/ListEtfDepot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
</div>
</div>
<div class="row justify-content-md-center mb-12">
<div class="col-xxl-4 col-md-7 col-xs-12" v-if="dataLoaded">
<div class="col-xxl-4 col-md-7 col-xs-12" v-if="etfsLoaded">
<div
class="row no-gutters flex-lg-nowrap d-flex justify-content align-items-center"
>
<div class="col-xxl-8 col-md-8 col-xs-12 justify-content-end mb-2">
<SelectStandard
v-model="defaultEtfId"
v-model="selectedEtf"
:validation-schema="schema.etfId"
id="etf"
:field-label="$t('General.selectEtf')"
Expand Down Expand Up @@ -391,6 +391,7 @@ import type { SelectBoxValue } from "@/model/SelectBoxValue";
import EtfControllerHandler from "@/handler/EtfControllerHandler";
import DivError from "@/components/DivError.vue";
import type { EtfDepot } from "@/model/etf/EtfDepot";
import CrudEtfControllerHandler from "@/handler/CrudEtfControllerHandler";
const { t } = useI18n();
Expand All @@ -403,6 +404,7 @@ const schema = {
bidPrice: amountSchema(t("ETFFlow.validation.bidPrice")),
transactionCosts: amountSchema(t("ETFFlow.validation.transactionCosts")),
};
const etfsLoaded = ref(false);
const dataLoaded = ref(false);
const etfFlows = ref({} as Array<ListDepotRowData>);
const etfEffectiveFlows = ref({} as Array<ListDepotRowData>);
Expand All @@ -411,7 +413,7 @@ const etfsSelectValues = ref({} as Array<SelectBoxValue>);
const calcEtfAskPrice = ref(0);
const calcEtfBidPrice = ref(0);
const defaultEtfId = ref(0);
const selectedEtf = ref(0);
const calcEtfSalePieces = ref(0);
const calcEtfTransactionCosts = ref(0);
const calcResults = ref({} as EtfSalesCalculation);
Expand All @@ -422,12 +424,11 @@ const effectiveTab = ref();
const allTab = ref();
const deleteModal = ref();
const createModal = ref();
const loadedEtf = ref(-1);
const { handleSubmit, values, setFieldTouched } = useForm();
onMounted(() => {
loadData();
loadEtfs();
});
const etfEffectiveFlowAmountSum = computed(() => {
Expand Down Expand Up @@ -468,37 +469,39 @@ const etfFlowPriceAvg = computed(() => {
return etfFlowAmountPriceSum.value / etfFlowAmountSum.value;
});
const initView = () => {
const loadEtfs = () => {
serverErrors.value = new Array<string>();
dataLoaded.value = false;
etfFlows.value = new Array<ListDepotRowData>();
etfEffectiveFlows.value = new Array<ListDepotRowData>();
etfs.value = new Array<Etf>();
etfsLoaded.value = false;
etfsSelectValues.value = new Array<SelectBoxValue>();
};
const loadData = () => {
initView();
CrudEtfControllerHandler.fetchAllEtf()
.then((response) => {
etfs.value = response;
for (let etf of response) {
etfsSelectValues.value.push({ id: etf.id, value: etf.name });
if (etf.isFavorite) selectedEtf.value = etf.id;
}
etfsLoaded.value = true;
EtfControllerHandler.listEtfFlows()
.then((etfDepot) => {
handleServerResponse(etfDepot);
if (selectedEtf.value !== 0) {
loadData(selectedEtf.value);
}
})
.catch((backendError) => {
handleBackendError(backendError, serverErrors);
});
Object.keys(values).forEach((field) => setFieldTouched(field, false));
};
const loadDataWithId = (etfId: number) => {
loadedEtf.value = etfId;
const loadData = (etfId: number) => {
serverErrors.value = new Array<string>();
dataLoaded.value = false;
calcResults.value = {} as EtfSalesCalculation;
initView();
etfFlows.value = new Array<ListDepotRowData>();
etfEffectiveFlows.value = new Array<ListDepotRowData>();
EtfControllerHandler.listEtfFlowsById(etfId)
.then((etfDepot) => {
handleServerResponse(etfDepot);
handleServerResponse(etfDepot, etfId);
})
.catch((backendError) => {
handleBackendError(backendError, serverErrors);
Expand All @@ -507,58 +510,45 @@ const loadDataWithId = (etfId: number) => {
Object.keys(values).forEach((field) => setFieldTouched(field, false));
};
const handleServerResponse = (etfDepot: EtfDepot) => {
if (etfDepot.etfs) {
for (let etf of etfDepot.etfs) {
etfsSelectValues.value.push({ id: etf.id, value: etf.name });
}
if (etfDepot.defaultEtfId != defaultEtfId.value) {
defaultEtfId.value = etfDepot.defaultEtfId ? etfDepot.defaultEtfId : 0;
loadedEtf.value = defaultEtfId.value;
}
etfs.value = etfDepot.etfs;
calcEtfAskPrice.value = etfDepot.calcEtfAskPrice
? etfDepot.calcEtfAskPrice
: 0;
calcEtfBidPrice.value = etfDepot.calcEtfBidPrice
? etfDepot.calcEtfBidPrice
: 0;
calcEtfSalePieces.value = etfDepot.calcEtfSalePieces
? etfDepot.calcEtfSalePieces
: 0;
calcEtfTransactionCosts.value = etfDepot.calcEtfTransactionCosts
? etfDepot.calcEtfTransactionCosts
: 0;
const etfMap = new Map<number, Etf>();
for (let etf of etfDepot.etfs) {
etfMap.set(etf.id, etf);
const handleServerResponse = (etfDepot: EtfDepot, etfId: number) => {
calcEtfAskPrice.value = etfDepot.calcEtfAskPrice
? etfDepot.calcEtfAskPrice
: 0;
calcEtfBidPrice.value = etfDepot.calcEtfBidPrice
? etfDepot.calcEtfBidPrice
: 0;
calcEtfSalePieces.value = etfDepot.calcEtfSalePieces
? etfDepot.calcEtfSalePieces
: 0;
calcEtfTransactionCosts.value = etfDepot.calcEtfTransactionCosts
? etfDepot.calcEtfTransactionCosts
: 0;
let etf = {} as Etf;
for (let _etf of etfs.value) {
if (_etf.id == etfId) {
etf = _etf;
break;
}
if (etfDepot.etfFlows) {
for (let etfFlow of etfDepot.etfFlows) {
const etf = etfMap.get(etfFlow.etfId);
if (etf)
etfFlows.value.push({
...etfFlow,
name: etf.name,
chartUrl: etf.chartUrl,
});
}
}
if (etfDepot.etfFlows) {
for (let etfFlow of etfDepot.etfFlows) {
etfFlows.value.push({
...etfFlow,
name: etf.name,
chartUrl: etf.chartUrl,
});
}
if (etfDepot.etfEffectiveFlows) {
for (let etfFlow of etfDepot.etfEffectiveFlows) {
const etf = etfMap.get(etfFlow.etfId);
if (etf)
etfEffectiveFlows.value.push({
...etfFlow,
name: etf.name,
chartUrl: etf.chartUrl,
});
}
}
if (etfDepot.etfEffectiveFlows) {
for (let etfFlow of etfDepot.etfEffectiveFlows) {
etfEffectiveFlows.value.push({
...etfFlow,
name: etf.name,
chartUrl: etf.chartUrl,
});
}
dataLoaded.value = true;
}
dataLoaded.value = true;
};
const showEffective = () => {
Expand Down Expand Up @@ -603,7 +593,7 @@ const calculateEtfSale = handleSubmit(() => {
serverErrors.value = new Array<string>();
EtfControllerHandler.calcEtfSale(
defaultEtfId.value,
selectedEtf.value,
calcEtfSalePieces.value,
calcEtfBidPrice.value,
calcEtfAskPrice.value,
Expand All @@ -620,30 +610,30 @@ const calculateEtfSale = handleSubmit(() => {
const deleteEtfFlow = (etfFlow: EtfFlow, etfName: string) => {
(deleteModal.value as typeof DeleteEtfFlowModalVue)._show(etfFlow, etfName);
};
const etfFlowDeleted = () => {
const etfFlowDeleted = (etfFlow: EtfFlow) => {
// reload because effective/all logic happens on server
loadData();
loadData(etfFlow.etfId);
};
const createEtfFlow = () => {
createModal.value._show(etfs.value, null, loadedEtf.value);
createModal.value._show(etfs.value, null, selectedEtf.value);
};
const etfFlowCreated = () => {
const etfFlowCreated = (etfFlow: EtfFlow) => {
// reload because effective/all logic happens on server
loadData();
loadData(etfFlow.etfId);
};
const editEtfFlow = (etfFlow: EtfFlow) => {
createModal.value._show(etfs.value, etfFlow);
};
const etfFlowUpdated = () => {
const etfFlowUpdated = (etfFlow: EtfFlow) => {
// reload because effective/all logic happens on server
loadData();
loadData(etfFlow.etfId);
};
watch(defaultEtfId, (newVal, oldVal) => {
if (newVal != loadedEtf.value) {
loadDataWithId(newVal);
watch(selectedEtf, (newVal, oldVal) => {
if (newVal != selectedEtf.value) {
loadData(newVal);
}
});
</script>
8 changes: 5 additions & 3 deletions src/views/etf/ListPreliminaryLumpSums.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ onMounted(() => {
const etfId: number | undefined = props.etfId ? +props.etfId : undefined;
const year: number | undefined = props.year ? +props.year : undefined;
loadEtfs();
if (selectedEtf.value !== 0) {
loadYear(selectedEtf.value, year);
}
});
const loadEtfs = () => {
Expand All @@ -157,11 +154,16 @@ const loadEtfs = () => {
if (etf.isFavorite) selectedEtf.value = etf.id;
}
etfsLoaded.value = true;
if (selectedEtf.value !== 0) {
loadYear(selectedEtf.value, undefined);
}
})
.catch((backendError) => {
handleBackendError(backendError, serverErrors);
});
};
const loadYear = (etfId: number, year?: number) => {
serverErrors.value = new Array<string>();
Expand Down

0 comments on commit 5f030dc

Please sign in to comment.