Skip to content

Firefly III: a personal finances manager

Better search

James Cole199b94b55d47
diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.js
index da2c14bf6d..7342f2c395 100644
--- a/resources/assets/v3/js/pages/accounts/index.js
+++ b/resources/assets/v3/js/pages/accounts/index.js
@@ -72,39 +72,6 @@ let index = function () {
storeFilterAndSort: storeFilterAndSort,
sortableTable: null,
- // objectToQueryString(obj, prefix) {
- // if (null === obj) {
- // return "";
- // }
- // return Object.keys(obj)
- // .map((objKey) => {
- // if (Object.hasOwn(obj, objKey)) {
- // const key = prefix ? `${prefix}[${objKey}]` : objKey;
- // const value = obj[objKey];
- //
- // return typeof value === "object"
- // ? this.objectToQueryString(value, key)
- // : `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
- // }
- //
- // return null;
- // })
- // .join("&");
- // },
-
- // updateFilterValue(field, newValue) {
- // console.log("Update", field, newValue);
- // this.filter[field] = newValue;
- // if ("" !== newValue) {
- // this.isFiltering = true;
- // }
- // if ("" === newValue) {
- // this.isFiltering = false;
- // }
- // this.updateHistory();
- // this.downloadAccounts();
- // },
-
init() {
// prepare some variables:
@@ -117,14 +84,16 @@ let index = function () {
this.defaultSortColumn = "expense" === this.objectType || "revenue" === this.objectType ? "name" : this.defaultSortColumn;
this.active = "inactive-accounts" !== address[address.length - 2];
+ // grab state from localStorage.
let fromStore = window.store.get(this.storageKey);
if (fromStore) {
this.defaultSortColumn = fromStore.column;
this.defaultSortDirection = fromStore.direction;
this.filter = fromStore.filter;
- console.log('Restore from store:', fromStore);
+ //console.log('Restore from store:', fromStore);
}
+ // grab state from URL params.
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
@@ -132,11 +101,7 @@ let index = function () {
this.defaultSortColumn = params.column ?? this.defaultSortColumn;
this.defaultSortDirection = params.direction ?? this.defaultSortDirection;
- console.log('Restore from params:', {
- page: this.page,
- column: this.defaultSortColumn,
- direction: this.defaultSortDirection
- });
+ // console.log('Restore from params:', {page: this.page, column: this.defaultSortColumn, direction: this.defaultSortDirection});
this.sortableTable = new sortableTable('main');
@@ -147,8 +112,6 @@ let index = function () {
this.sortableTable.init(this);
- //updateHistory(this.page, this.defaultSortColumn, this.defaultSortDirection, this.filter);
-
// watch for changes in the sortable table instructions.
document.addEventListener('sortable-table-sort-change', (event) => {
console.log('sortable-table-sort-change', event.detail);
@@ -159,16 +122,8 @@ let index = function () {
this.downloadAccounts();
});
this.downloadAccounts();
- console.log(this.isFiltering);
-
- // grab the account list.
- // document.addEventListener('alpine:initialized', (function () {
- // console.log('Init!');
- //
- // }).bind(this));
// respond to drag and drop.
-
getVariable("listPageSize").then((listPageSize) => {
this.listPageSize = listPageSize;
addDrag();
@@ -301,13 +256,9 @@ let index = function () {
pc_current_debt_float: current.attributes.pc_debt_amount_float,
liability_type: i18next.t("firefly.account_type_" + current.attributes.liability_type),
- liability_direction: i18next.t(
- "firefly.liability_direction_" + current.attributes.liability_direction + "_short",
- ),
+ liability_direction: i18next.t("firefly.liability_direction_" + current.attributes.liability_direction + "_short",),
liability_interest: current.attributes.interest,
- liability_interest_period: i18next
- .t("firefly.interest_calc_" + current.attributes.interest_period)
- .toLowerCase(),
+ liability_interest_period: i18next.t("firefly.interest_calc_" + current.attributes.interest_period).toLowerCase(),
};
this.accounts.push(account);
}
diff --git a/resources/assets/v3/js/pages/shared/sortable-tables.js b/resources/assets/v3/js/pages/shared/sortable-tables.js
index 9a5c1442c9..32d651c52d 100644
--- a/resources/assets/v3/js/pages/shared/sortable-tables.js
+++ b/resources/assets/v3/js/pages/shared/sortable-tables.js
@@ -24,6 +24,7 @@ export class sortableTable {
sortDirection = 'asc';
storageKey = '';
disableRefresh = false;
+ parent = null;
constructor(tableId) {
this.tableId = tableId;
@@ -31,6 +32,7 @@ export class sortableTable {
}
init(parent) {
+ this.parent = parent;
queueMicrotask(() => {
this.updateHeaderClasses();
this.addClickEvents();
@@ -44,17 +46,17 @@ export class sortableTable {
});
// add a watch for sortColumn, sortDirection and page
- parent.$watch('sortColumn', (newValue, oldValue) => {
- console.log('sortColumn changed from "' + oldValue + '" to "' + newValue + '"');
+ // parent.$watch('sortColumn', (newValue, oldValue) => {
+ // console.log('sortColumn changed from "' + oldValue + '" to "' + newValue + '"');
// this.updateHeaderClasses();
- });
- parent.$watch('sortDirection', (newValue, oldValue) => {
- console.log('sortDirection changed from "' + oldValue + '" to "' + newValue + '"');
- });
- parent.$watch('page', (newValue, oldValue) => {
- console.log('page changed from "' + oldValue + '" to "' + newValue + '"');
- });
+ // });
+ // parent.$watch('sortDirection', (newValue, oldValue) => {
+ // console.log('sortDirection changed from "' + oldValue + '" to "' + newValue + '"');
+ // });
+ // parent.$watch('page', (newValue, oldValue) => {
+ // console.log('page changed from "' + oldValue + '" to "' + newValue + '"');
+ // });
// loop all filtered columns and watch those values.
document.querySelectorAll('table[data-sort-identifier="' + this.tableId + '"] thead th[data-filter-column]').forEach((th) => {
let column = th.getAttribute('data-filter-column');
@@ -71,15 +73,21 @@ export class sortableTable {
// parent.filter[column] = newValue;
console.log('filter for column "' + column + '" changed from "' + oldValue + '" to "' + newValue + '"');
this.fireSortChangeEvent();
+ if('' !== newValue) {
+ showSearchBox(th);
+ }
});
- if (null !== valueToUse) {
- console.log('DISABLE refresh');
+ if (null !== valueToUse && '' !== valueToUse) {
+ // console.log('DISABLE refresh');
this.disableRefresh = true;
parent.isFiltering = true;
- console.log('Setting initial filter value for column "' + column + '" to "' + valueToUse + '"');
+ // console.log('Setting initial filter value for column "' + column + '" to "' + valueToUse + '"');
parent.filter[column] = valueToUse;
-
+ // make sure the button is visible.
+ setTimeout(() => {
+ showSearchBox(th);
+ },50);
}
});
}
@@ -123,14 +131,14 @@ export class sortableTable {
clickCloseButton(event) {
let th = event.currentTarget.parentNode.parentNode.parentNode;
let column = th.dataset.filterColumn;
- console.log('close again', column);
+ console.log('close search box for ', column);
th.querySelector('.search-filter').classList.add('d-none');
th.querySelector('.title').classList.remove('d-none');
th.querySelector('span.search-spacer').classList.remove("d-none");
th.querySelector('.search-button').classList.remove('d-none');
// console.log(th.querySelector('.form-control').value);
th.querySelector('.form-control').value = '';
-
+ this.parent.filter[column] = '';
this.fireSortChangeEvent();
}
@@ -153,7 +161,7 @@ export class sortableTable {
});
}
createSearchBox(th) {
- console.log('createSearchBox', th);
+ //console.log('createSearchBox', th);
let column = th.dataset.filterColumn;
// create filter inset.
let inset = document.createElement('span');
@@ -228,6 +236,7 @@ function showSearchBox(th) {
let column = th.dataset.filterColumn;
// hide search buttons etc.
+ console.log('search button?',th.querySelector('.search-button'));
th.querySelector('.search-button').classList.add("d-none");
th.querySelector('span.title').classList.add("d-none");
th.querySelector('span.search-spacer').classList.add("d-none");