Implmeent expand/collapse of category-groups
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Jan Bader 2022-02-25 20:06:26 +00:00
parent 212c81ab81
commit 55dffbbe89
2 changed files with 19 additions and 4 deletions

View File

@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, defineProps, onMounted, watchEffect } from "vue"; import { computed, defineProps, onMounted, ref, watchEffect } 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";
@ -52,6 +52,18 @@ watchEffect(() => {
onMounted(() => { onMounted(() => {
useSessionStore().setTitle("Budget for " + selected.value.Month + "/" + selected.value.Year); useSessionStore().setTitle("Budget for " + selected.value.Month + "/" + selected.value.Year);
}) })
const expandedGroups = ref<Map<string, boolean>>(new Map<string, boolean>())
function toggleGroup(group : {Name : string, Expand: boolean}) {
console.log(expandedGroups.value);
expandedGroups.value.set(group.Name, !(expandedGroups.value.get(group.Name) ?? group.Expand))
}
function getGroupState(group : {Name : string, Expand: boolean}) : boolean {
return expandedGroups.value.get(group.Name) ?? group.Expand;
}
</script> </script>
<template> <template>
@ -78,8 +90,8 @@ onMounted(() => {
<th>Available</th> <th>Available</th>
</tr> </tr>
<tbody v-for="group in GroupsForMonth"> <tbody v-for="group in GroupsForMonth">
<p class="text-lg font-bold">{{ group }}</p> <a class="text-lg font-bold" @click="toggleGroup(group)">{{ (getGroupState(group) ? "" : "+") + " " + group.Name }}</a>
<tr v-for="category in GetCategories(group)"> <tr v-for="category in GetCategories(group.Name)" v-if="getGroupState(group)">
<td>{{ category.Name }}</td> <td>{{ category.Name }}</td>
<td></td> <td></td>
<td></td> <td></td>

View File

@ -67,7 +67,10 @@ export const useAccountStore = defineStore("budget/account", {
let prev = undefined; let prev = undefined;
for (const category of categories) { for (const category of categories) {
if(category.Group != prev) if(category.Group != prev)
categoryGroups.push(category.Group); categoryGroups.push({
Name: category.Group,
Expand: category.Group != "Hidden Categories",
});
prev = category.Group; prev = category.Group;
} }
return categoryGroups; return categoryGroups;