This commit is contained in:
Jan Bader 2022-02-10 16:07:29 +00:00
parent c693625e34
commit 21dcd7837b
8 changed files with 46 additions and 38 deletions

View File

@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
import { mapState } from "pinia"; import { mapState } from "pinia";
import { defineComponent } from "vue"; import { defineComponent } from "vue";
import { LOGOUT } from "./store/mutation-types";
import { useBudgetsStore } from "./stores/budget"; import { useBudgetsStore } from "./stores/budget";
import { useAccountStore } from "./stores/budget-account"; import { useAccountStore } from "./stores/budget-account";
import { useSessionStore } from "./stores/session"; import { useSessionStore } from "./stores/session";
@ -38,7 +37,6 @@ export default defineComponent({
sessionStore.User = restoredState.Session.User; sessionStore.User = restoredState.Session.User;
sessionStore.Token = restoredState.Session.Token; sessionStore.Token = restoredState.Session.Token;
for (const budget of restoredState.Budgets || []) { for (const budget of restoredState.Budgets || []) {
console.log("UIAE", sessionStore.Budgets, budget)
sessionStore.Budgets.set(budget[0], budget[1]); sessionStore.Budgets.set(budget[0], budget[1]);
} }

View File

@ -1,5 +1,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from "vue" import { defineComponent, PropType } from "vue"
import { useAPI } from "../stores/api";
import { useBudgetsStore } from "../stores/budget";
export interface Suggestion { export interface Suggestion {
ID : string ID : string
@ -40,9 +42,10 @@ export default defineComponent({
return; return;
} }
fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID + "/autocomplete/" + this.type + "?s=" + text, { const api = useAPI();
headers: this.$store.getters.AuthHeaders const budgetStore = useBudgetsStore();
}) .then(x=>x.json()) api.GET("/budget/" + budgetStore.CurrentBudgetID + "/autocomplete/" + this.type + "?s=" + text)
.then(x=>x.json())
.then(x => { .then(x => {
let suggestions = x || []; let suggestions = x || [];
if(suggestions.length > 10){ if(suggestions.length > 10){

View File

@ -1,10 +1,15 @@
<script lang="ts"> <script lang="ts">
import { mapState } from "pinia";
import { defineComponent } from "vue"; import { defineComponent } from "vue";
import { useBudgetsStore } from "../stores/budget";
import Currency from "./Currency.vue"; import Currency from "./Currency.vue";
export default defineComponent({ export default defineComponent({
props: [ "transaction", "index" ], props: [ "transaction", "index" ],
components: { Currency } components: { Currency },
computed: {
...mapState(useBudgetsStore, ["CurrentBudgetID"])
}
}) })
</script> </script>
@ -18,7 +23,7 @@ export default defineComponent({
{{ transaction.CategoryGroup ? transaction.CategoryGroup + " : " + transaction.Category : "" }} {{ transaction.CategoryGroup ? transaction.CategoryGroup + " : " + transaction.Category : "" }}
</td> </td>
<td> <td>
<a :href="'/budget/' + $store.getters.CurrentBudgetID + '/transaction/' + transaction.ID"> <a :href="'/budget/' + CurrentBudgetID + '/transaction/' + transaction.ID">
{{ transaction.Memo }} {{ transaction.Memo }}
</a> </a>
</td> </td>

View File

@ -4,6 +4,7 @@ import { defineComponent } from "vue"
import Autocomplete, { Suggestion } from '../components/Autocomplete.vue' import Autocomplete, { Suggestion } from '../components/Autocomplete.vue'
import Currency from "../components/Currency.vue"; import Currency from "../components/Currency.vue";
import TransactionRow from "../components/TransactionRow.vue"; import TransactionRow from "../components/TransactionRow.vue";
import { useAPI } from "../stores/api";
import { useAccountStore } from "../stores/budget-account"; import { useAccountStore } from "../stores/budget-account";
import { useSessionStore } from "../stores/session"; import { useSessionStore } from "../stores/session";
@ -25,9 +26,8 @@ export default defineComponent({
methods: { methods: {
saveTransaction(e : MouseEvent) { saveTransaction(e : MouseEvent) {
e.preventDefault(); e.preventDefault();
fetch("/api/v1/transaction/new", { const api = useAPI();
method: "POST", api.POST("/transaction/new", JSON.stringify({
body: JSON.stringify({
budget_id: this.budgetid, budget_id: this.budgetid,
account_id: this.accountid, account_id: this.accountid,
date: this.$data.TransactionDate, date: this.$data.TransactionDate,
@ -36,9 +36,7 @@ export default defineComponent({
memo: this.$data.Memo, memo: this.$data.Memo,
amount: this.$data.Amount, amount: this.$data.Amount,
state: "Uncleared" state: "Uncleared"
}), }))
headers: useSessionStore().AuthHeaders,
})
.then(x => x.json()); .then(x => x.json());
}, },
} }

View File

@ -12,7 +12,7 @@ interface Date {
export default defineComponent({ export default defineComponent({
mounted() { mounted() {
document.title = "Budgeteer - Budget for " + this.month + " " + this.year; document.title = "Budgeteer - Budget for " + this.selected.Month + "/" + this.selected.Year;
return useAccountStore().FetchMonthBudget(this.budgetid, this.year, this.month); return useAccountStore().FetchMonthBudget(this.budgetid, this.year, this.month);
}, },
watch: { watch: {
@ -27,7 +27,9 @@ export default defineComponent({
computed: { computed: {
...mapState(useBudgetsStore, ["CurrentBudgetID"]), ...mapState(useBudgetsStore, ["CurrentBudgetID"]),
Categories() : IterableIterator<Category> | undefined { Categories() : IterableIterator<Category> | undefined {
return useAccountStore().Categories(this.year, this.month); const accountStore = useAccountStore();
console.log(accountStore.CategoriesForMonth(this.year, this.month));
return accountStore.CategoriesForMonth(this.year, this.month);
}, },
previous(): Date { previous(): Date {
return { return {

View File

@ -36,7 +36,7 @@ export default defineComponent({
return; return;
const api = useAPI(); const api = useAPI();
api.DELETE("/api/v1/budget/" + currentBudgetID); api.DELETE("/budget/" + currentBudgetID);
const budgetStore = useSessionStore(); const budgetStore = useSessionStore();
budgetStore.Budgets.delete(currentBudgetID); budgetStore.Budgets.delete(currentBudgetID);
@ -45,7 +45,7 @@ export default defineComponent({
clearBudget() { clearBudget() {
const currentBudgetID = useBudgetsStore().CurrentBudgetID; const currentBudgetID = useBudgetsStore().CurrentBudgetID;
const api = useAPI(); const api = useAPI();
api.POST("/api/v1/budget/" + currentBudgetID + "/settings/clear", null) api.POST("/budget/" + currentBudgetID + "/settings/clear", null)
}, },
cleanNegative() { cleanNegative() {
// <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a> // <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a>

View File

@ -1,5 +1,4 @@
import { defineStore } from "pinia" import { defineStore } from "pinia"
import { FETCH_ACCOUNT } from "../store/action-types";
import { useAPI } from "./api"; import { useAPI } from "./api";
import { useSessionStore } from "./session"; import { useSessionStore } from "./session";
@ -42,7 +41,8 @@ export const useAccountStore = defineStore("budget/account", {
AccountsList(state) { AccountsList(state) {
return state.Accounts.values(); return state.Accounts.values();
}, },
Categories: (state) => (year : number, month : number) => { CategoriesForMonth: (state) => (year : number, month : number) => {
console.log("MTH", state.Months)
const yearMap = state.Months.get(year); const yearMap = state.Months.get(year);
return yearMap?.get(month)?.values(); return yearMap?.get(month)?.values();
}, },
@ -64,7 +64,7 @@ export const useAccountStore = defineStore("budget/account", {
OffBudgetAccountsBalance(state) : Number { OffBudgetAccountsBalance(state) : Number {
return this.OffBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0); return this.OffBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0);
}, },
Transactions(state) { TransactionsList(state) {
return (state.Transactions || []); return (state.Transactions || []);
} }
}, },
@ -82,11 +82,11 @@ export const useAccountStore = defineStore("budget/account", {
}, },
async FetchAccount(accountid : string) { async FetchAccount(accountid : string) {
const api = useAPI(); const api = useAPI();
const result = await api.GET("/api/v1/account/" + accountid + "/transactions"); const result = await api.GET("/account/" + accountid + "/transactions");
const response = await result.json(); const response = await result.json();
this.Transactions = response.Transactions; this.Transactions = response.Transactions;
}, },
async FetchMonthBudget(budgetid : string, month : number, year : number) { async FetchMonthBudget(budgetid : string, year : number, month : number) {
const api = useAPI(); const api = useAPI();
const result = await api.GET("/budget/" + budgetid + "/" + year + "/" + month); const result = await api.GET("/budget/" + budgetid + "/" + year + "/" + month);
const response = await result.json(); const response = await result.json();

View File

@ -1,4 +1,5 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { useAPI } from './api';
interface State { interface State {
Token: string | null Token: string | null
@ -33,17 +34,18 @@ export const useSessionStore = defineStore('session', {
this.Token = x.Token; this.Token = x.Token;
this.Budgets = x.Budgets; this.Budgets = x.Budgets;
}, },
login(login: any) { async login(login: any) {
return fetch("/api/v1/user/login", { method: "POST", body: JSON.stringify(login) }) const api = useAPI();
.then(x => x.json()) const response = await api.POST("/user/login", JSON.stringify(login));
.then(x => this.loginSuccess(x)); const result = await response.json();
return this.loginSuccess(result);
}, },
register(login : any) { async register(login : any) {
return fetch("/api/v1/user/register", { method: "POST", body: JSON.stringify(login) }) const api = useAPI();
.then(x => x.json()) const response = await api.POST("/user/register", JSON.stringify(login));
.then(x => this.loginSuccess(x)) const result = await response.json();
return this.loginSuccess(result);
}, },
// easily reset state using `$reset`
logout() { logout() {
this.$reset() this.$reset()
} }