30 Commits
0.3.0 ... 0.3.1

Author SHA1 Message Date
0aa877d7d4 Merge pull request 'Use vue's Composition API' (#10) from vue-composition into master
All checks were successful
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #10
2022-02-14 23:44:00 +01:00
87a70ee5fa Revert
All checks were successful
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
continuous-integration/drone/pr Build is passing
ci/woodpecker/pr/woodpecker Pipeline was successful
2022-02-14 22:39:14 +00:00
0a030eaee1 Convert other pages to composition API 2022-02-14 22:24:42 +00:00
d11c0036b5 Do not use a store for API 2022-02-14 08:12:41 +00:00
ca93e9cd55 Migrate Account.vue to composition API
All checks were successful
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
2022-02-14 08:06:16 +00:00
a061ffd350 Merge pull request 'Implement minor fixes' (#9) from minor-fixes into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
continuous-integration/drone/push Build is passing
Reviewed-on: #9
2022-02-14 08:48:07 +01:00
5633c029ac Update Earthfile and production docker-compose.yml
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2022-02-13 13:20:18 +00:00
a97d050ead Specify Map serializer for budgets
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2022-02-13 13:16:50 +00:00
958929fd16 Update docker-compose to use new tag 2022-02-13 13:16:50 +00:00
a61d80ee1f Implement SPA handling in Backend 2022-02-13 13:16:50 +00:00
41c5095b8b Merge pull request 'Use woodpecker for CI' (#8) from woodpecker into master
All checks were successful
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #8
2022-02-13 14:16:38 +01:00
c074dfe865 Fix Taskfile
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2022-02-12 00:00:33 +00:00
fa8a2854f2 Add node packages to image
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2022-02-12 00:00:19 +00:00
15bb73de30 Add secrects
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2022-02-11 23:54:26 +00:00
e506510fde Remove user and add go deps from builder image 2022-02-11 23:49:43 +00:00
11ac8758da Disable docker from taskfile
Some checks failed
continuous-integration/drone/pr Build is passing
ci/woodpecker/push/woodpecker Pipeline failed
continuous-integration/drone/push Build is passing
ci/woodpecker/pr/woodpecker Pipeline was successful
2022-02-11 23:43:55 +00:00
3db5e1e72c Reenable docker push
Some checks failed
continuous-integration/drone/push Build is failing
ci/woodpecker/push/woodpecker Pipeline failed
continuous-integration/drone/pr Build is failing
ci/woodpecker/pr/woodpecker Pipeline failed
2022-02-11 23:42:03 +00:00
4e2a783b2e Extract variable 2022-02-11 23:40:46 +00:00
bb83563bc6 Use docker build-target
Some checks failed
continuous-integration/drone/push Build is failing
ci/woodpecker/push/woodpecker Pipeline failed
2022-02-11 23:35:15 +00:00
0a21c59eff Fetch deps before build
Some checks failed
continuous-integration/drone/push Build is failing
ci/woodpecker/push/woodpecker Pipeline failed
2022-02-11 23:33:47 +00:00
3308b58524 Fix sources in Taskfile
Some checks failed
continuous-integration/drone/push Build is failing
ci/woodpecker/push/woodpecker Pipeline failed
2022-02-11 23:30:53 +00:00
941b642f39 Build docker within task
Some checks failed
continuous-integration/drone/push Build is failing
ci/woodpecker/push/woodpecker Pipeline failed
2022-02-11 23:16:57 +00:00
6a77c71df4 Always pull dev image
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
continuous-integration/drone/push Build is failing
2022-02-11 22:59:38 +00:00
bf20914c1c Use default build name
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
continuous-integration/drone/push Build is failing
2022-02-11 22:58:31 +00:00
7874ef69a2 Fix Taskfile
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
continuous-integration/drone/push Build is failing
2022-02-11 22:57:26 +00:00
2e719b590e Add admin page 2022-02-11 22:52:00 +00:00
95d8e4fccc Rewrite event filter
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
continuous-integration/drone/push Build is failing
2022-02-11 22:49:06 +00:00
7cf106eb85 Rename 2022-02-11 22:41:35 +00:00
148fc18cd8 Fix schema 2022-02-11 22:41:07 +00:00
47095ae6ec Add .woodpecker.yaml 2022-02-11 22:39:19 +00:00
24 changed files with 406 additions and 374 deletions

View File

@ -8,3 +8,4 @@ config.example.json
.vscode/ .vscode/
budgeteer budgeteer
budgeteer.exe budgeteer.exe
**/node_modules/

View File

@ -6,8 +6,9 @@ name: budgeteer
steps: steps:
- name: Taskfile.dev - name: Taskfile.dev
image: hub.javil.eu/budgeteer:dev image: hub.javil.eu/budgeteer:dev
pull: true
commands: commands:
- task build - task
- name: docker - name: docker
image: plugins/docker image: plugins/docker

23
.woodpecker.yml Normal file
View File

@ -0,0 +1,23 @@
pipeline:
build:
name: Taskfile.dev
image: hub.javil.eu/budgeteer:dev
pull: true
commands:
- task
docker:
image: plugins/docker
secrets: [ docker_username, docker_password ]
settings:
registry: hub.javil.eu
repo: hub.javil.eu/budgeteer
context: build
dockerfile: build/Dockerfile
tags:
- latest
when:
event: [push, tag, deployment]
image_pull_secrets:
- hub.javil.eu

View File

@ -12,7 +12,7 @@ docker:
WORKDIR /app WORKDIR /app
COPY +build/budgeteer . COPY +build/budgeteer .
ENTRYPOINT ["/app/budgeteer"] ENTRYPOINT ["/app/budgeteer"]
SAVE IMAGE budgeteer:latest SAVE IMAGE hub.javil.eu/budgeteer:latest
run: run:
LOCALLY LOCALLY

View File

@ -1,9 +1,12 @@
version: '3' version: '3'
vars:
IMAGE_NAME: hub.javil.eu/budgeteer
tasks: tasks:
default: default:
cmds: cmds:
- task: build - task: build-prod
sqlc: sqlc:
desc: sqlc code generation desc: sqlc code generation
@ -59,12 +62,13 @@ tasks:
frontend: frontend:
desc: Build vue frontend desc: Build vue frontend
dir: web
sources: sources:
- web/src/**/* - web/src/**/*
generates: generates:
- web/dist/**/* - web/dist/**/*
cmds: cmds:
- cd web - yarn
- yarn build - yarn build
docker: docker:
@ -72,8 +76,18 @@ tasks:
deps: [build-prod] deps: [build-prod]
sources: sources:
- ./build/budgeteer{{exeExt}} - ./build/budgeteer{{exeExt}}
- ./build/Dockerfile
cmds: cmds:
- docker build -t budgeteer:latest -t hub.javil.eu/budgeteer:latest ./build - docker build -t {{.IMAGE_NAME}}:latest ./build
- docker push {{.IMAGE_NAME}}:latest
dev-docker:
desc: Build budgeeter:dev
sources:
- ./docker/Dockerfile
cmds:
- docker build -t {{.IMAGE_NAME}}:dev . -f docker/Dockerfile
- docker push {{.IMAGE_NAME}}:dev
run: run:
desc: Start budgeteer desc: Start budgeteer

View File

@ -2,9 +2,7 @@ version: '3.7'
services: services:
app: app:
image: budgeteer:dev image: hub.javil.eu/budgeteer:dev
build:
context: ./docker/
container_name: budgeteer container_name: budgeteer
stdin_open: true # docker run -i stdin_open: true # docker run -i
tty: true # docker run -t tty: true # docker run -t

View File

@ -2,7 +2,7 @@ version: '3.7'
services: services:
app: app:
image: budgeteer:latest image: hub.javil.eu/budgeteer:latest
container_name: budgeteer container_name: budgeteer
ports: ports:
- 1323:1323 - 1323:1323

View File

@ -1,13 +1,16 @@
FROM alpine as godeps
RUN apk add go
RUN go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
RUN go install github.com/go-task/task/v3/cmd/task@latest
FROM alpine FROM alpine
RUN apk add go RUN apk add go
RUN apk add nodejs yarn bash curl git git-perl tmux RUN apk add nodejs yarn bash curl git git-perl tmux
RUN bash -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin ADD docker/build.sh /
ADD build.sh / COPY --from=godeps /root/go/bin/task /root/go/bin/sqlc /usr/local/bin/
RUN addgroup -S dev && adduser -S dev -G dev
USER dev
RUN go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
RUN go install github.com/go-task/task/v3/cmd/task@latest
RUN yarn global add @vue/cli RUN yarn global add @vue/cli
ENV PATH="/home/dev/go/bin:/home/dev/.yarn/bin/:${PATH}" ENV PATH="/root/.yarn/bin/:${PATH}"
WORKDIR /src WORKDIR /src
ADD web/package.json /src/web/
RUN yarn
CMD /build.sh CMD /build.sh

View File

@ -1,8 +1,11 @@
package http package http
import ( import (
"errors"
"io"
"io/fs" "io/fs"
"net/http" "net/http"
"path"
"strings" "strings"
"git.javil.eu/jacob1123/budgeteer" "git.javil.eu/jacob1123/budgeteer"
@ -18,6 +21,7 @@ type Handler struct {
Service *postgres.Database Service *postgres.Database
TokenVerifier budgeteer.TokenVerifier TokenVerifier budgeteer.TokenVerifier
CredentialsVerifier *bcrypt.Verifier CredentialsVerifier *bcrypt.Verifier
StaticFS http.FileSystem
} }
const ( const (
@ -37,14 +41,10 @@ func (h *Handler) LoadRoutes(router *gin.Engine) {
if err != nil { if err != nil {
panic("couldn't open static files") panic("couldn't open static files")
} }
staticFS := http.FS(static) h.StaticFS = http.FS(static)
router.Use(enableCachingForStaticFiles()) router.Use(enableCachingForStaticFiles())
router.NoRoute( router.NoRoute(h.ServeStatic)
func(c *gin.Context) {
c.FileFromFS(c.Request.URL.Path, staticFS)
},
)
withLogin := router.Group("") withLogin := router.Group("")
withLogin.Use(h.verifyLoginWithRedirect) withLogin.Use(h.verifyLoginWithRedirect)
@ -81,6 +81,35 @@ func (h *Handler) LoadRoutes(router *gin.Engine) {
transaction.POST("/new", h.newTransaction) transaction.POST("/new", h.newTransaction)
transaction.POST("/:transactionid", h.newTransaction) transaction.POST("/:transactionid", h.newTransaction)
} }
func (h *Handler) ServeStatic(c *gin.Context) {
h.ServeStaticFile(c, c.Request.URL.Path)
}
func (h *Handler) ServeStaticFile(c *gin.Context, fullPath string) {
file, err := h.StaticFS.Open(fullPath)
if errors.Is(err, fs.ErrNotExist) {
h.ServeStaticFile(c, path.Join("/", "/index.html"))
return
}
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
stat, err := file.Stat()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
if stat.IsDir() {
h.ServeStaticFile(c, path.Join(fullPath, "index.html"))
return
}
http.ServeContent(c.Writer, c.Request, stat.Name(), stat.ModTime(), file.(io.ReadSeeker))
}
func enableCachingForStaticFiles() gin.HandlerFunc { func enableCachingForStaticFiles() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {

26
web/src/api.ts Normal file
View File

@ -0,0 +1,26 @@
import { useSessionStore } from "./stores/session";
export const BASE_URL = "/api/v1"
export function GET(path: string) {
const sessionStore = useSessionStore();
return fetch(BASE_URL + path, {
headers: sessionStore.AuthHeaders,
})
};
export function POST(path: string, body: FormData | string | null) {
const sessionStore = useSessionStore();
return fetch(BASE_URL + path, {
method: "POST",
headers: sessionStore.AuthHeaders,
body: body,
})
}
export function DELETE(path: string) {
const sessionStore = useSessionStore();
return fetch(BASE_URL + path, {
method: "DELETE",
headers: sessionStore.AuthHeaders,
})
}

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from "vue" import { defineComponent, PropType } from "vue"
import { useAPI } from "../stores/api"; import { GET } from "../api";
import { useBudgetsStore } from "../stores/budget"; import { useBudgetsStore } from "../stores/budget";
export interface Suggestion { export interface Suggestion {
@ -42,9 +42,8 @@ export default defineComponent({
return; return;
} }
const api = useAPI();
const budgetStore = useBudgetsStore(); const budgetStore = useBudgetsStore();
api.GET("/budget/" + budgetStore.CurrentBudgetID + "/autocomplete/" + this.type + "?s=" + text) GET("/budget/" + budgetStore.CurrentBudgetID + "/autocomplete/" + this.type + "?s=" + text)
.then(x=>x.json()) .then(x=>x.json())
.then(x => { .then(x => {
let suggestions = x || []; let suggestions = x || [];

View File

@ -1,89 +1,89 @@
<script lang="ts"> <script lang="ts" setup>
import { mapState } from "pinia"; import { computed, ref } from "vue"
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 { POST } from "../api";
import { useAccountStore } from "../stores/budget-account"; import { useAccountStore } from "../stores/budget-account";
import { useSessionStore } from "../stores/session";
export default defineComponent({ const props = defineProps<{
data() { budgetid: string
return { accountid: string
TransactionDate: new Date().toISOString().substring(0, 10), }>()
Payee: undefined as Suggestion | undefined,
Category: undefined as Suggestion | undefined, const TransactionDate = ref(new Date().toISOString().substring(0, 10));
Memo: "", const Payee = ref<Suggestion | undefined>(undefined);
Amount: 0 const Category = ref<Suggestion | undefined>(undefined);
} const Memo = ref("");
}, const Amount = ref(0);
components: { Autocomplete, Currency, TransactionRow },
props: ["budgetid", "accountid"], function saveTransaction(e: MouseEvent) {
computed: { e.preventDefault();
...mapState(useAccountStore, ["CurrentAccount", "TransactionsList"]), POST("/transaction/new", JSON.stringify({
}, budget_id: props.budgetid,
methods: { account_id: props.accountid,
saveTransaction(e : MouseEvent) { date: TransactionDate.value,
e.preventDefault(); payee: Payee.value,
const api = useAPI(); category: Category.value,
api.POST("/transaction/new", JSON.stringify({ memo: Memo.value,
budget_id: this.budgetid, amount: Amount,
account_id: this.accountid, state: "Uncleared"
date: this.$data.TransactionDate, }))
payee: this.$data.Payee, .then(x => x.json());
category: this.$data.Category, }
memo: this.$data.Memo,
amount: this.$data.Amount, const accountStore = useAccountStore();
state: "Uncleared" const CurrentAccount = accountStore.CurrentAccount;
})) const TransactionsList = accountStore.TransactionsList;
.then(x => x.json());
},
}
})
</script> </script>
<template> <template>
<h1>{{ CurrentAccount?.Name }}</h1> <h1>{{ CurrentAccount?.Name }}</h1>
<p> <p>
Current Balance: Current Balance:
<Currency :value="CurrentAccount?.Balance" /> <Currency :value="CurrentAccount?.Balance" />
</p> </p>
<table> <table>
<tr class="font-bold"> <tr class="font-bold">
<td style="width: 90px;">Date</td> <td style="width: 90px;">Date</td>
<td style="max-width: 150px;">Payee</td> <td style="max-width: 150px;">Payee</td>
<td style="max-width: 200px;">Category</td> <td style="max-width: 200px;">Category</td>
<td>Memo</td> <td>Memo</td>
<td class="text-right">Amount</td> <td class="text-right">Amount</td>
<td style="width: 20px;"></td> <td style="width: 20px;"></td>
<td style="width: 20px;"></td> <td style="width: 20px;"></td>
</tr> </tr>
<tr> <tr>
<td style="width: 90px;" class="text-sm"> <td style="width: 90px;" class="text-sm">
<input class="border-b-2 border-black" type="date" v-model="TransactionDate" /> <input class="border-b-2 border-black" type="date" v-model="TransactionDate" />
</td> </td>
<td style="max-width: 150px;"> <td style="max-width: 150px;">
<Autocomplete v-model="Payee" type="payees" /> <Autocomplete v-model="Payee" type="payees" />
</td> </td>
<td style="max-width: 200px;"> <td style="max-width: 200px;">
<Autocomplete v-model="Category" type="categories" /> <Autocomplete v-model="Category" type="categories" />
</td> </td>
<td> <td>
<input class="block w-full border-b-2 border-black" type="text" v-model="Memo" /> <input class="block w-full border-b-2 border-black" type="text" v-model="Memo" />
</td> </td>
<td style="width: 80px;" class="text-right"> <td style="width: 80px;" class="text-right">
<input class="text-right block w-full border-b-2 border-black" type="currency" v-model="Amount" /> <input
</td> class="text-right block w-full border-b-2 border-black"
<td style="width: 20px;"> type="currency"
<input type="submit" @click="saveTransaction" value="Save" /> v-model="Amount"
</td> />
<td style="width: 20px;"></td> </td>
</tr> <td style="width: 20px;">
<TransactionRow v-for="(transaction, index) in TransactionsList" <input type="submit" @click="saveTransaction" value="Save" />
:transaction="transaction" </td>
:index="index" /> <td style="width: 20px;"></td>
</table> </tr>
<TransactionRow
v-for="(transaction, index) in TransactionsList"
:transaction="transaction"
:index="index"
/>
</table>
</template> </template>
<style> <style>

15
web/src/pages/Admin.vue Normal file
View File

@ -0,0 +1,15 @@
<script lang="ts" setup>
import { onMounted } from 'vue';
onMounted(() => {
document.title = "Budgeteer - Admin";
})
</script>
<template>
<h1>Danger Zone</h1>
<div class="budget-item">
<button>Clear database</button>
<p>This removes all data and starts from scratch. Not undoable!</p>
</div>
</template>

View File

@ -1,20 +1,25 @@
<script lang="ts"> <script lang="ts" setup>
import { mapState } from "pinia"
import { defineComponent } from "vue"
import Currency from "../components/Currency.vue" import Currency from "../components/Currency.vue"
import { useBudgetsStore } from "../stores/budget" import { useBudgetsStore } from "../stores/budget"
import { useAccountStore } from "../stores/budget-account" import { useAccountStore } from "../stores/budget-account"
import { useSettingsStore } from "../stores/settings" import { useSettingsStore } from "../stores/settings"
export default defineComponent({ const props = defineProps<{
props: ["budgetid", "accountid"], budgetid: string,
components: { Currency }, accountid: string,
computed: { }>();
...mapState(useSettingsStore, ["ExpandMenu"]),
...mapState(useBudgetsStore, ["CurrentBudgetName", "CurrentBudgetID"]), const ExpandMenu = useSettingsStore().Menu.Expand;
...mapState(useAccountStore, ["OnBudgetAccounts", "OnBudgetAccountsBalance", "OffBudgetAccounts", "OffBudgetAccountsBalance"])
} const budgetStore = useBudgetsStore();
}) const CurrentBudgetName = budgetStore.CurrentBudgetName;
const CurrentBudgetID = budgetStore.CurrentBudgetID;
const accountStore = useAccountStore();
const OnBudgetAccounts = accountStore.OnBudgetAccounts;
const OffBudgetAccounts = accountStore.OffBudgetAccounts;
const OnBudgetAccountsBalance = accountStore.OnBudgetAccountsBalance;
const OffBudgetAccountsBalance = accountStore.OffBudgetAccountsBalance;
</script> </script>
<template> <template>

View File

@ -1,68 +1,48 @@
<script lang="ts"> <script lang="ts" setup>
import { mapState } from "pinia"; import { computed, defineProps, onMounted, PropType, watch, watchEffect } from "vue";
import { defineComponent, PropType } from "vue";
import Currency from "../components/Currency.vue"; import Currency from "../components/Currency.vue";
import { useBudgetsStore } from "../stores/budget"; import { useBudgetsStore } from "../stores/budget";
import { Category, useAccountStore } from "../stores/budget-account"; import { useAccountStore } from "../stores/budget-account";
interface Date { interface Date {
Year: number, Year: number,
Month: number, Month: number,
} }
export default defineComponent({ const props = defineProps<{
props: { budgetid: string,
budgetid: {} as PropType<string>, year: string,
year: {} as PropType<number>, month: string,
month: {} as PropType<number>, }>()
},
computed: { const budgetsStore = useBudgetsStore();
...mapState(useBudgetsStore, ["CurrentBudgetID"]), const CurrentBudgetID = computed(() => budgetsStore.CurrentBudgetID);
Categories() : Category[] {
const accountStore = useAccountStore(); const categoriesForMonth = useAccountStore().CategoriesForMonth;
return [...accountStore.CategoriesForMonth(this.selected.Year, this.selected.Month)]; const Categories = computed(() => {
}, return [...categoriesForMonth(selected.value.Year, selected.value.Month)];
previous() : Date { });
return { const previous = computed(() => ({
Year: new Date(this.selected.Year, this.selected.Month - 1, 1).getFullYear(), Year: new Date(selected.value.Year, selected.value.Month - 1, 1).getFullYear(),
Month: new Date(this.selected.Year, this.selected.Month - 1, 1).getMonth(), Month: new Date(selected.value.Year, selected.value.Month - 1, 1).getMonth(),
}; }));
}, const current = computed(() => ({
current() : Date { Year: new Date().getFullYear(),
return { Month: new Date().getMonth(),
Year: new Date().getFullYear(), }));
Month: new Date().getMonth(), const selected = computed(() => ({
}; Year: Number(props.year) ?? current.value.Year,
}, Month: Number(props.month ?? current.value.Month)
selected() : Date { }));
return { const next = computed(() => ({
Year: this.year ?? this.current.Year, Year: new Date(selected.value.Year, Number(props.month) + 1, 1).getFullYear(),
Month: Number(this.month ?? this.current.Month) + 1 Month: new Date(selected.value.Year, Number(props.month) + 1, 1).getMonth(),
} }));
},
next() : Date { watchEffect(() => {
return { if (props.year != undefined && props.month != undefined)
Year: new Date(this.selected.Year, Number(this.month) + 1, 1).getFullYear(), return useAccountStore().FetchMonthBudget(props.budgetid ?? "", Number(props.year), Number(props.month));
Month: new Date(this.selected.Year, Number(this.month) + 1, 1).getMonth(), });
};
}
},
mounted() : Promise<void> {
document.title = "Budgeteer - Budget for " + this.selected.Month + "/" + this.selected.Year;
return useAccountStore().FetchMonthBudget(this.budgetid ?? "", this.selected.Year, this.selected.Month);
},
watch: {
year() {
if (this.year != undefined && this.month != undefined)
return useAccountStore().FetchMonthBudget(this.budgetid ?? "", this.year, this.month);
},
month() {
if (this.year != undefined && this.month != undefined)
return useAccountStore().FetchMonthBudget(this.budgetid ?? "", this.year, this.month);
},
},
components: { Currency }
})
/*{{define "title"}} /*{{define "title"}}
{{printf "Budget for %s %d" .Date.Month .Date.Year}} {{printf "Budget for %s %d" .Date.Month .Date.Year}}
@ -70,7 +50,7 @@ export default defineComponent({
</script> </script>
<template> <template>
<h1>Budget for {{ selected.Month }}/{{ selected.Year }}</h1> <h1>Budget for {{ selected.Month + 1 }}/{{ selected.Year }}</h1>
<div> <div>
<router-link <router-link
:to="'/budget/' + CurrentBudgetID + '/budgeting/' + previous.Year + '/' + previous.Month" :to="'/budget/' + CurrentBudgetID + '/budgeting/' + previous.Year + '/' + previous.Month"

View File

@ -1,17 +1,13 @@
<script lang="ts"> <script lang="ts" setup>
import NewBudget from '../dialogs/NewBudget.vue'; import NewBudget from '../dialogs/NewBudget.vue';
import Card from '../components/Card.vue'; import Card from '../components/Card.vue';
import { defineComponent } from 'vue';
import { mapState } from 'pinia';
import { useSessionStore } from '../stores/session'; import { useSessionStore } from '../stores/session';
export default defineComponent({ const props = defineProps<{
props: ["budgetid"], budgetid: string,
components: { NewBudget, Card }, }>();
computed: {
...mapState(useSessionStore, ["BudgetsList"]), const BudgetsList = useSessionStore().BudgetsList;
}
})
</script> </script>
<template> <template>

View File

@ -1,9 +1,4 @@
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue';
export default defineComponent({
})
</script> </script>
<template> <template>

View File

@ -1,46 +1,48 @@
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from "vue"; import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { useSessionStore } from "../stores/session"; import { useSessionStore } from "../stores/session";
export default defineComponent({ const error = ref("");
data() { const login = ref({ user: "", password: "" });
return {
error: "",
login: {
user: "",
password: ""
},
showPassword: false
}
},
mounted() {
document.title = "Budgeteer - Login";
},
methods: {
formSubmit(e : MouseEvent) {
e.preventDefault();
useSessionStore().login(this.$data.login)
.then(x => {
this.$data.error = "";
this.$router.replace("/dashboard");
})
.catch(x => this.$data.error = "The entered credentials are invalid!");
// TODO display invalidCredentials onMounted(() => {
// TODO redirect to dashboard on success document.title = "Budgeteer - Login";
} });
}
}) function formSubmit(e: MouseEvent) {
e.preventDefault();
useSessionStore().login(login)
.then(x => {
error.value = "";
useRouter().replace("/dashboard");
})
.catch(x => error.value = "The entered credentials are invalid!");
// TODO display invalidCredentials
// TODO redirect to dashboard on success
}
</script> </script>
<template> <template>
<div> <div>
<input type="text" v-model="login.user" placeholder="Username" class="border-2 border-black rounded-lg block px-2 my-2 w-48" /> <input
<input type="password" v-model="login.password" placeholder="Password" class="border-2 border-black rounded-lg block px-2 my-2 w-48" /> type="text"
</div> v-model="login.user"
<div>{{ error }}</div> placeholder="Username"
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Login</button> class="border-2 border-black rounded-lg block px-2 my-2 w-48"
<p> />
New user? <router-link to="/register">Register</router-link> instead! <input
</p> type="password"
v-model="login.password"
placeholder="Password"
class="border-2 border-black rounded-lg block px-2 my-2 w-48"
/>
</div>
<div>{{ error }}</div>
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Login</button>
<p>
New user?
<router-link to="/register">Register</router-link>instead!
</p>
</template> </template>

View File

@ -1,31 +1,20 @@
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { ref } from 'vue';
import { useSessionStore } from '../stores/session'; import { useSessionStore } from '../stores/session';
export default defineComponent({ const error = ref("");
data() { const login = ref({ email: "", password: "", name: "" });
return { const showPassword = ref(false);
showPassword: false,
error: "",
login: {
email: "",
password: "",
name: "",
}
}
},
methods: {
formSubmit (e : FormDataEvent) {
e.preventDefault();
useSessionStore().register(this.$data.login)
.then(() => this.$data.error = "")
.catch(() => this.$data.error = "Something went wrong!");
// TODO display invalidCredentials function formSubmit(e: FormDataEvent) {
// TODO redirect to dashboard on success e.preventDefault();
} useSessionStore().register(login)
} .then(() => error.value = "")
}) .catch(() => error.value = "Something went wrong!");
// TODO display invalidCredentials
// TODO redirect to dashboard on success
}
</script> </script>
<template> <template>
@ -38,30 +27,35 @@ export default defineComponent({
<v-text-field v-model="login.name" type="text" label="Name" /> <v-text-field v-model="login.name" type="text" label="Name" />
</v-col> </v-col>
<v-col cols="6"> <v-col cols="6">
<v-text-field v-model="login.password" label="Password" <v-text-field
v-model="login.password"
label="Password"
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'" :append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
:type="showPassword ? 'text' : 'password'" :type="showPassword ? 'text' : 'password'"
@click:append="showPassword = showPassword" @click:append="showPassword = showPassword"
:error-message="error" :error-message="error"
error-count="2" error-count="2"
error /> error
/>
</v-col> </v-col>
<v-col cols="6"> <v-col cols="6">
<v-text-field v-model="login.password" label="Repeat password" <v-text-field
v-model="login.password"
label="Repeat password"
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'" :append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
:type="showPassword ? 'text' : 'password'" :type="showPassword ? 'text' : 'password'"
@click:append="showPassword = showPassword" @click:append="showPassword = showPassword"
:error-message="error" :error-message="error"
error-count="2" error-count="2"
error /> error
/>
</v-col> </v-col>
</v-row> </v-row>
<div class="form-group"> <div class="form-group">{{ error }}</div>
{{ error }}
</div>
<v-btn type="submit" @click="formSubmit">Register</v-btn> <v-btn type="submit" @click="formSubmit">Register</v-btn>
<p> <p>
Existing user? <router-link to="/login">Login</router-link> instead! Existing user?
</p> <router-link to="/login">Login</router-link>instead!
</p>
</v-container> </v-container>
</template> </template>

View File

@ -1,67 +1,56 @@
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from "vue" import { computed, defineComponent, onMounted, ref } from "vue"
import { useAPI } from "../stores/api"; import { useRouter } from "vue-router";
import { DELETE, POST } from "../api";
import { useBudgetsStore } from "../stores/budget"; import { useBudgetsStore } from "../stores/budget";
import { useSessionStore } from "../stores/session"; import { useSessionStore } from "../stores/session";
export default defineComponent({ const transactionsFile = ref<File | undefined>(undefined);
data() { const assignmentsFile = ref<File | undefined>(undefined);
return {
transactionsFile: undefined as File | undefined,
assignmentsFile: undefined as File | undefined
}
},
computed: {
filesIncomplete() : boolean {
return this.$data.transactionsFile == undefined || this.$data.assignmentsFile == undefined;
}
},
mounted() {
document.title = "Budgeteer - Settings";
},
methods: {
gotAssignments(e : Event) {
const input = (<HTMLInputElement>e.target);
if(input.files != null)
this.$data.assignmentsFile = input.files[0];
},
gotTransactions(e : Event) {
const input = (<HTMLInputElement>e.target);
if(input.files != null)
this.$data.transactionsFile = input.files[0];
},
deleteBudget() {
const currentBudgetID = useBudgetsStore().CurrentBudgetID;
if (currentBudgetID == null)
return;
const api = useAPI(); const filesIncomplete = computed(() => transactionsFile.value == undefined || assignmentsFile.value == undefined);
api.DELETE("/budget/" + currentBudgetID); onMounted(() => {
document.title = "Budgeteer - Settings";
});
const budgetStore = useSessionStore(); function gotAssignments(e: Event) {
budgetStore.Budgets.delete(currentBudgetID); const input = (<HTMLInputElement>e.target);
this.$router.push("/") if (input.files != null)
}, assignmentsFile.value = input.files[0];
clearBudget() { }
const currentBudgetID = useBudgetsStore().CurrentBudgetID; function gotTransactions(e: Event) {
const api = useAPI(); const input = (<HTMLInputElement>e.target);
api.POST("/budget/" + currentBudgetID + "/settings/clear", null) if (input.files != null)
}, transactionsFile.value = input.files[0];
cleanNegative() { };
// <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a> function deleteBudget() {
}, const currentBudgetID = useBudgetsStore().CurrentBudgetID;
ynabImport() { if (currentBudgetID == null)
if (this.$data.transactionsFile == undefined || this.$data.assignmentsFile == undefined) return;
return
let formData = new FormData(); DELETE("/budget/" + currentBudgetID);
formData.append("transactions", this.$data.transactionsFile);
formData.append("assignments", this.$data.assignmentsFile); const budgetStore = useSessionStore();
const budgetStore = useBudgetsStore(); budgetStore.Budgets.delete(currentBudgetID);
budgetStore.ImportYNAB(formData); useRouter().push("/")
} };
} function clearBudget() {
}) const currentBudgetID = useBudgetsStore().CurrentBudgetID;
POST("/budget/" + currentBudgetID + "/settings/clear", null)
};
function cleanNegative() {
// <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a>
};
function ynabImport() {
if (transactionsFile.value == undefined || assignmentsFile.value == undefined)
return
let formData = new FormData();
formData.append("transactions", transactionsFile.value);
formData.append("assignments", assignmentsFile.value);
const budgetStore = useBudgetsStore();
budgetStore.ImportYNAB(formData);
};
</script> </script>
<template> <template>
@ -126,10 +115,7 @@ export default defineComponent({
</label> </label>
<v-card-actions class="justify-center"> <v-card-actions class="justify-center">
<v-btn <v-btn :disabled="filesIncomplete" @click="ynabImport">Importieren</v-btn>
:disabled="filesIncomplete"
@click="ynabImport"
>Importieren</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-col> </v-col>

View File

@ -1,28 +0,0 @@
import { defineStore } from "pinia";
import { useSessionStore } from "./session";
export const useAPI = defineStore("api", {
actions: {
GET(path : string) {
const sessionStore = useSessionStore();
return fetch("/api/v1" + path, {
headers: sessionStore.AuthHeaders,
})
},
POST(path : string, body : FormData | string | null) {
const sessionStore = useSessionStore();
return fetch("/api/v1" + path, {
method: "POST",
headers: sessionStore.AuthHeaders,
body: body,
})
},
DELETE(path : string) {
const sessionStore = useSessionStore();
return fetch("/api/v1" + path, {
method: "DELETE",
headers: sessionStore.AuthHeaders,
})
},
}
});

View File

@ -1,5 +1,5 @@
import { defineStore } from "pinia" import { defineStore } from "pinia"
import { useAPI } from "./api"; import { GET } from "../api";
import { useSessionStore } from "./session"; import { useSessionStore } from "./session";
interface State { interface State {
@ -81,14 +81,12 @@ export const useAccountStore = defineStore("budget/account", {
await this.FetchAccount(accountid); await this.FetchAccount(accountid);
}, },
async FetchAccount(accountid : string) { async FetchAccount(accountid : string) {
const api = useAPI(); const result = await GET("/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, year : number, month : number) { async FetchMonthBudget(budgetid : string, year : number, month : number) {
const api = useAPI(); const result = await GET("/budget/" + budgetid + "/" + year + "/" + month);
const result = await api.GET("/budget/" + budgetid + "/" + year + "/" + month);
const response = await result.json(); const response = await result.json();
this.addCategoriesForMonth(year, month, response.Categories); this.addCategoriesForMonth(year, month, response.Categories);
}, },

View File

@ -1,5 +1,5 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { useAPI } from "./api"; import { GET, POST } from "../api";
import { useAccountStore } from "./budget-account"; import { useAccountStore } from "./budget-account";
import { Budget, useSessionStore } from "./session"; import { Budget, useSessionStore } from "./session";
@ -25,15 +25,13 @@ export const useBudgetsStore = defineStore('budget', {
}, },
actions: { actions: {
ImportYNAB(formData: FormData) { ImportYNAB(formData: FormData) {
const api = useAPI(); return POST(
return api.POST(
"/budget/" + this.CurrentBudgetID + "/import/ynab", "/budget/" + this.CurrentBudgetID + "/import/ynab",
formData, formData,
); );
}, },
async NewBudget(budgetName: string): Promise<void> { async NewBudget(budgetName: string): Promise<void> {
const api = useAPI(); const result = await POST(
const result = await api.POST(
"/budget/new", "/budget/new",
JSON.stringify({ name: budgetName }) JSON.stringify({ name: budgetName })
); );
@ -51,8 +49,7 @@ export const useBudgetsStore = defineStore('budget', {
await this.FetchBudget(budgetid); await this.FetchBudget(budgetid);
}, },
async FetchBudget(budgetid: string) { async FetchBudget(budgetid: string) {
const api = useAPI(); const result = await GET("/budget/" + budgetid);
const result = await api.GET("/budget/" + budgetid);
const response = await result.json(); const response = await result.json();
for (const account of response.Accounts || []) { for (const account of response.Accounts || []) {
useAccountStore().Accounts.set(account.ID, account); useAccountStore().Accounts.set(account.ID, account);

View File

@ -1,6 +1,6 @@
import { StorageSerializers, useStorage } from '@vueuse/core'; import { StorageSerializers, useStorage } from '@vueuse/core';
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { useAPI } from './api'; import { POST } from '../api';
interface State { interface State {
Session: Session | null Session: Session | null
@ -21,7 +21,7 @@ export interface Budget {
export const useSessionStore = defineStore('session', { export const useSessionStore = defineStore('session', {
state: () => ({ state: () => ({
Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }), Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }),
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>()), Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
}), }),
getters: { getters: {
BudgetsList: (state) => [ ...state.Budgets.values() ], BudgetsList: (state) => [ ...state.Budgets.values() ],
@ -40,14 +40,12 @@ export const useSessionStore = defineStore('session', {
this.Budgets = x.Budgets; this.Budgets = x.Budgets;
}, },
async login(login: any) { async login(login: any) {
const api = useAPI(); const response = await POST("/user/login", JSON.stringify(login));
const response = await api.POST("/user/login", JSON.stringify(login));
const result = await response.json(); const result = await response.json();
return this.loginSuccess(result); return this.loginSuccess(result);
}, },
async register(login : any) { async register(login : any) {
const api = useAPI(); const response = await POST("/user/register", JSON.stringify(login));
const response = await api.POST("/user/register", JSON.stringify(login));
const result = await response.json(); const result = await response.json();
return this.loginSuccess(result); return this.loginSuccess(result);
}, },