Allow account grouping

This commit is contained in:
James Cole
2024-04-28 14:40:22 +02:00
parent 7992b810fd
commit b951d4130c
5 changed files with 121 additions and 40 deletions

View File

@@ -157,7 +157,11 @@ let index = function () {
// hide modal
window.bootstrap.Modal.getInstance(document.getElementById('filterModal')).hide();
this.loadAccounts();
},
saveGroupedAccounts() {
setVariable(this.getPreferenceKey('grouped'), this.pageOptions.groupedAccounts);
this.page = 1;
this.loadAccounts();
},
removeFilter(field) {
this.filters[field] = null;
@@ -236,7 +240,6 @@ let index = function () {
})
// some opts
this.pageOptions.isLoading = true;
this.notifications.wait.show = true;
@@ -249,6 +252,7 @@ let index = function () {
{name: this.getPreferenceKey('sc'), default: ''},
{name: this.getPreferenceKey('sd'), default: ''},
{name: this.getPreferenceKey('filters'), default: this.filters},
{name: this.getPreferenceKey('grouped'), default: true},
]).then((res) => {
// process columns:
for (let k in res[0]) {
@@ -270,6 +274,9 @@ let index = function () {
}
}
// group accounts
this.pageOptions.groupedAccounts = res[4];
this.loadAccounts();
});
},
@@ -360,10 +367,8 @@ let index = function () {
delete params.start;
delete params.end;
}
// check if cache is present:
this.accounts = [];
let groupedAccounts = {};
// one page only.o
(new Get()).index(params).then(response => {
this.totalPages = response.meta.pagination.total_pages;
@@ -392,12 +397,38 @@ let index = function () {
interest_period: current.attributes.interest_period,
current_debt: current.attributes.current_debt,
};
this.accounts.push(account);
// get group info:
let groupId = current.attributes.object_group_id;
if(!this.pageOptions.groupedAccounts) {
groupId = '0';
}
if (!groupedAccounts.hasOwnProperty(groupId)) {
groupedAccounts[groupId] = {
group: {
id: '0' === groupId || null === groupId ? null : parseInt(groupId),
title: current.attributes.object_group_title, // are ignored if group id is null.
order: current.attributes.object_group_order,
},
accounts: [],
}
}
groupedAccounts[groupId].accounts.push(account);
//this.accounts.push(account);
}
}
// order grouped accounts by order.
let sortable = [];
for (let set in groupedAccounts) {
sortable.push(groupedAccounts[set]);
}
sortable.sort(function(a, b) {
return a.group.order - b.group.order;
});
this.accounts = sortable;
this.notifications.wait.show = false;
this.pageOptions.isLoading = false;
// add click trigger thing.
});
},
}

View File

@@ -37,16 +37,20 @@
</div>
<div class="row mb-3">
<div class="col">
<div x-html="pageNavigation()">
<div x-html="pageNavigation">
</div>
</div>
<template x-for="(set, rootIndex) in accounts" :key="rootIndex">
<div class="row mb-3">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="card mb-3">
<div class="card-header">
<div class="row">
<div class="col">
<h3 class="card-title">{{ __('firefly.undefined_accounts') }}</h3>
<h3 class="card-title">
<span x-show="null === set.group.id">{{ __('firefly.undefined_accounts') }}</span>
<span x-show="null !== set.group.id" x-text="set.group.title"></span>
</h3>
</div>
<div class="col text-end">
</div>
@@ -173,7 +177,7 @@
</tr>
</thead>
<tbody>
<template x-for="(account, index) in accounts" :key="index">
<template x-for="(account, index) in set.accounts" :key="index">
<tr>
<td x-show="tableColumns.drag_and_drop.visible && tableColumns.drag_and_drop.enabled">
<em class="fa-solid fa-bars"></em>
@@ -312,9 +316,10 @@
</div>
</div>
</template>
<div class="row mb-3">
<div class="col">
<div x-html="pageNavigation()">
<div x-html="pageNavigation">
</div>
</div>
@@ -353,19 +358,17 @@
</select>
</div>
</div>
<!--
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Group accounts</label>
<div class="col-sm-8">
<div class="form-check form-switch">
<label>
<input class="form-check-input" type="checkbox"
<input class="form-check-input" type="checkbox" @change="saveGroupedAccounts"
x-model="pageOptions.groupedAccounts"><span>Group accounts</span>
</label>
</div>
</div>
</div>
-->
<!--
<div class="row mb-3">
<label for="inputEmail3" class="col-sm-4 col-form-label">Show info boxes</label>
@@ -408,14 +411,14 @@
<div class="modal-body">
<div class="mb-3">
<label for="filterInput" class="form-label">Search in column: <span x-text="lastClickedFilter"></span></label>
<input @keyup.enter="applyFilter()" type="text" class="form-control" id="filterInput" placeholder="" x-model="lastFilterInput">
<input @keyup.enter="applyFilter" type="text" class="form-control" id="filterInput" placeholder="" x-model="lastFilterInput">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><em
class="fa-solid fa-right-from-bracket"></em> Cancel
</button>
<button @click="applyFilter()" type="button" class="btn btn-primary" data-bs-dismiss="modal"><em
<button @click="applyFilter" type="button" class="btn btn-primary" data-bs-dismiss="modal"><em
class="fa-solid fa-magnifying-glass"></em> Search
</button>