Implement filtering on frontend
This commit is contained in:
parent
dc15ae307b
commit
f437491823
@ -1,7 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -38,17 +38,33 @@ const filters = ref({
|
|||||||
PayeeID: null,
|
PayeeID: null,
|
||||||
Category: null,
|
Category: null,
|
||||||
CategoryID: null,
|
CategoryID: null,
|
||||||
FromDate: null,
|
FromDate: new Date(1900, 0, 2, 0, 0, 0),
|
||||||
ToDate: null,
|
ToDate: new Date(2999,11,32,0,0,0),
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(() => filters.value.AccountID + filters.value.PayeeID + filters.value.CategoryID, function() {
|
watch(() => filters.value.AccountID
|
||||||
|
+ filters.value.PayeeID
|
||||||
|
+ filters.value.CategoryID
|
||||||
|
+ filters.value.FromDate?.toISOString()
|
||||||
|
+ filters.value.ToDate?.toISOString(), function() {
|
||||||
|
console.log(filters.value.FromDate)
|
||||||
if(!hasFilters.value)
|
if(!hasFilters.value)
|
||||||
return;
|
return;
|
||||||
transactions.GetFilteredTransactions(filters.value.AccountID, filters.value.CategoryID, filters.value.PayeeID);
|
transactions.GetFilteredTransactions(
|
||||||
|
filters.value.AccountID,
|
||||||
|
filters.value.CategoryID,
|
||||||
|
filters.value.PayeeID,
|
||||||
|
filters.value.FromDate?.toISOString(),
|
||||||
|
filters.value.ToDate?.toISOString(),
|
||||||
|
);
|
||||||
})
|
})
|
||||||
|
|
||||||
const hasFilters = computed(() => filters.value.AccountID != null || filters.value.PayeeID != null || filters.value.CategoryID);
|
const hasFilters = computed(() =>
|
||||||
|
filters.value.AccountID != null
|
||||||
|
|| filters.value.PayeeID != null
|
||||||
|
|| filters.value.CategoryID != null
|
||||||
|
|| (filters.value.FromDate != null && filters.value.FromDate.getYear() > 1900)
|
||||||
|
|| (filters.value.ToDate != null && filters.value.ToDate.getYear() < 2999))
|
||||||
const transactionsList = computed(() => {
|
const transactionsList = computed(() => {
|
||||||
if (hasFilters.value){
|
if (hasFilters.value){
|
||||||
return transactions.FilteredTransactionsList;
|
return transactions.FilteredTransactionsList;
|
||||||
|
@ -90,12 +90,14 @@ export const useTransactionsStore = defineStore("budget/transactions", {
|
|||||||
this.AddTransactions(transactions);
|
this.AddTransactions(transactions);
|
||||||
this.ProblematicTransactions = [...transactions?.map((x : Transaction) => x.ID)];
|
this.ProblematicTransactions = [...transactions?.map((x : Transaction) => x.ID)];
|
||||||
},
|
},
|
||||||
async GetFilteredTransactions(accountID : string | null, categoryID : string | null, payeeID : string | null) {
|
async GetFilteredTransactions(accountID : string | null, categoryID : string | null, payeeID : string | null, fromDate : string, toDate : string) {
|
||||||
const budgetStore = useBudgetsStore();
|
const budgetStore = useBudgetsStore();
|
||||||
const payload = JSON.stringify({
|
const payload = JSON.stringify({
|
||||||
category_id: categoryID,
|
category_id: categoryID,
|
||||||
payee_id: payeeID,
|
payee_id: payeeID,
|
||||||
account_id: accountID,
|
account_id: accountID,
|
||||||
|
from_date: fromDate,
|
||||||
|
to_date: toDate,
|
||||||
});
|
});
|
||||||
const result = await POST("/budget/" + budgetStore.CurrentBudgetID + "/filtered-transactions", payload);
|
const result = await POST("/budget/" + budgetStore.CurrentBudgetID + "/filtered-transactions", payload);
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user