Implement download from UI

This commit is contained in:
2022-02-25 20:06:10 +00:00
parent 5b5b8215c3
commit 212c81ab81
3 changed files with 44 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import { useBudgetsStore } from "../stores/budget";
import { useSessionStore } from "../stores/session";
import Card from "../components/Card.vue";
import Button from "../components/Button.vue";
import { saveAs } from 'file-saver';
const transactionsFile = ref<File | undefined>(undefined);
const assignmentsFile = ref<File | undefined>(undefined);
@ -15,6 +16,10 @@ onMounted(() => {
useSessionStore().setTitle("Settings");
});
const budgetStore = useBudgetsStore();
const CurrentBudgetID = computed(() => budgetStore.CurrentBudgetID);
const CurrentBudgetName = computed(() => budgetStore.CurrentBudgetName);
function gotAssignments(e: Event) {
const input = (<HTMLInputElement>e.target);
if (input.files != null)
@ -26,19 +31,17 @@ function gotTransactions(e: Event) {
transactionsFile.value = input.files[0];
};
function deleteBudget() {
const currentBudgetID = useBudgetsStore().CurrentBudgetID;
if (currentBudgetID == null)
if (CurrentBudgetID.value == null)
return;
DELETE("/budget/" + currentBudgetID);
DELETE("/budget/" + CurrentBudgetID.value);
const budgetStore = useSessionStore();
budgetStore.Budgets.delete(currentBudgetID);
budgetStore.Budgets.delete(CurrentBudgetID.value);
useRouter().push("/")
};
function clearBudget() {
const currentBudgetID = useBudgetsStore().CurrentBudgetID;
POST("/budget/" + currentBudgetID + "/settings/clear", null)
POST("/budget/" + CurrentBudgetID.value + "/settings/clear", null)
};
function cleanNegative() {
// <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a>
@ -53,6 +56,22 @@ function ynabImport() {
const budgetStore = useBudgetsStore();
budgetStore.ImportYNAB(formData);
};
function ynabExport() {
const timeStamp = new Date().toISOString();
POST("/budget/"+CurrentBudgetID.value+"/export/ynab/assignments", "")
.then(x => x.text())
.then(x => {
var blob = new Blob([x], {type: "text/plain;charset=utf-8"});
saveAs(blob, timeStamp + " " + CurrentBudgetName.value + " - Budget.tsv");
})
POST("/budget/"+CurrentBudgetID.value+"/export/ynab/transactions", "")
.then(x => x.text())
.then(x => {
var blob = new Blob([x], {type: "text/plain;charset=utf-8"});
saveAs(blob, timeStamp + " " + CurrentBudgetName.value + " - Transactions.tsv");
})
}
</script>
<template>
@ -94,6 +113,13 @@ function ynabImport() {
<Button class="bg-blue-500" :disabled="filesIncomplete" @click="ynabImport">Importieren</Button>
</div>
</Card>
<Card class="flex-col p-3">
<h2 class="text-lg font-bold">Export as YNAB TSV</h2>
<div class="flex flex-row">
<Button class="bg-blue-500" @click="ynabExport">Export</Button>
</div>
</Card>
</div>
</div>
</template>