Skip to content

Firefly III: a personal finances manager

First commit of sort client side

Sander Dorigo51d0c7863344
diff --git a/resources/assets/v3/js/api/model/account/get.js b/resources/assets/v3/js/api/model/account/get.js
index b86397d6d4..778f1e1314 100644
--- a/resources/assets/v3/js/api/model/account/get.js
+++ b/resources/assets/v3/js/api/model/account/get.js
@@ -26,4 +26,7 @@ export default class Get {
get(id) {
return api.get(`/api/v1/accounts/${id}`);
}
+ list(params) {
+ return api.get("/api/v1/accounts", { params: params });
+ }
}
diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.js
index d4d3cd6c84..acdfb54db6 100644
--- a/resources/assets/v3/js/pages/accounts/index.js
+++ b/resources/assets/v3/js/pages/accounts/index.js
@@ -21,10 +21,10 @@
import "../../boot/bootstrap.js";
import sidebar from "../shared/sidebar.js";
import dates from "../shared/dates.js";
-import { addDrag } from "../shared/drag-and-droppable-rows.js";
import Alpine from "alpinejs";
import { getVariable } from "../../store/get-variable.js";
import Put from "../../api/model/account/put.js";
+import Get from "../../api/model/account/get.js";
window.enableDates = false;
@@ -32,15 +32,49 @@ let index = function () {
return {
listPageSize: 50,
objectType: 'invalid',
+ sortColumn: 'order',
+ sortDirection: 'asc',
init() {
const page = window.location.href.split("/");
this.objectType = page[page.length - 1].substring(0, 15);
+ const params = new Proxy(new URLSearchParams(window.location.search), {
+ get: (searchParams, prop) => searchParams.get(prop),
+ });
+ this.sortColumn = params.column ?? 'order';
+ this.sortDirection = params.direction ?? 'asc';
+ console.log('Sort "'+this.sortColumn+'" in direction "'+this.sortDirection+'"');
+
+ // grab the account list.
+
+ let sort = 'asc' === this.sortDirection ? this.sortColumn : '-' + this.sortColumn;
+
+ (new Get).list({sort: sort}).then((response) => {
+ console.log(response.data);
+ });
+
+ // get accounts by initial sort.
+ document.querySelectorAll('table.sortable th').forEach((el) => {
+ console.log('El', el);
+ el.addEventListener('click', (event) => {
+ let newColumn = event.currentTarget.dataset.column;
+ if(newColumn === this.sortColumn) {
+ this.sortDirection = 'asc' === this.sortDirection ? 'desc' : 'asc';
+ }
+ if(newColumn !== this.sortColumn) {
+ this.sortColumn = newColumn;
+ }
+ console.log('Will now sort on column', newColumn, 'direction', this.sortDirection);
+ if (history.pushState) {
+ let newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?column=' + this.sortColumn + '&direction=' + this.sortDirection;
+ window.history.pushState({path:newurl},'',newurl);
+ }
+ });
+ });
getVariable("listPageSize").then((listPageSize) => {
- console.log(listPageSize);
this.listPageSize = listPageSize;
- addDrag();
+ //addDrag();
document.addEventListener("firefly-iii-drag-complete", (e) => {
for (let i = 0; i < e.detail.length; i++) {
if (Object.hasOwn(e.detail, i)) {
@@ -55,7 +89,7 @@ let index = function () {
}
}
}
- console.log(e.detail);
+ // console.log(e.detail);
});
});
},
diff --git a/resources/assets/v3/sass/app.scss b/resources/assets/v3/sass/app.scss
index 3fc5c3db9c..006eaad93f 100644
--- a/resources/assets/v3/sass/app.scss
+++ b/resources/assets/v3/sass/app.scss
@@ -51,6 +51,15 @@ $primary: #1e6581; // original
);
@import "shepherd.js/dist/css/shepherd.css";
+// for sortable tables
+table.sortable thead th.sortable {cursor:pointer;}
+table.sortable th.sortable.sortable_sorted.sortable_sorted_asc:after {
+ content: " \25B4"
+}
+table.sortable th.sortable.sortable_sorted.sortable_sorted_desc:after {
+ content: " \25BE"
+}
+
// for light mode, different money colors are used.
html[data-bs-theme="light"] .money-negative {
color: #993b1e !important;
diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.php
index 95527050a9..047803aefe 100644
--- a/resources/views/accounts/index.blade.php
+++ b/resources/views/accounts/index.blade.php
@@ -15,8 +15,8 @@
<table class="table table-valign-middle table-sm table-hover sortable">
<thead>
<tr>
- <th class="w-5">&nbsp;</th>
- <th class="w-20">{{ trans('list.name') }}</th>
+ <th data-column="order" :class="{'w-5' : true,'sortable': true, 'sortable_sorted': 'order' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">&nbsp;</th>
+ <th data-column="name" :class="{'w-20' : true,'sortable': true, 'sortable_sorted': 'name' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">{{ trans('list.name') }}</th>
<template x-if="'asset' === objectType">
<th {{-- hide on LG and smaller. --}} class="d-lg-table-cell d-none">{{ trans('list.role') }}</th>
</template>