From cdc0b8dd2c77fd9a0a8dc28a4ec678939524774e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 21 Apr 2024 17:09:15 +0200 Subject: [PATCH] Add index options --- .../assets/v2/src/pages/accounts/index.js | 108 ++++++++++++++++-- resources/assets/v2/src/store/get-variable.js | 11 +- resources/assets/v2/vite.config.js | 3 + resources/views/v2/accounts/index.blade.php | 80 ++++++++----- 4 files changed, 158 insertions(+), 44 deletions(-) diff --git a/resources/assets/v2/src/pages/accounts/index.js b/resources/assets/v2/src/pages/accounts/index.js index 1ca9bbaf99..a2f0c2c7e6 100644 --- a/resources/assets/v2/src/pages/accounts/index.js +++ b/resources/assets/v2/src/pages/accounts/index.js @@ -32,6 +32,8 @@ import Put from "../../api/v2/model/account/put.js"; import AccountRenderer from "../../support/renderers/AccountRenderer.js"; import {showInternalsButton} from "../../support/page-settings/show-internals-button.js"; import {showWizardButton} from "../../support/page-settings/show-wizard-button.js"; +import {getVariable} from "../../store/get-variable.js"; +import {setVariable} from "../../store/set-variable.js"; // set type from URL @@ -50,7 +52,6 @@ sortingColumn = params.column ?? ''; sortDirection = params.direction ?? ''; - showInternalsButton(); showWizardButton(); @@ -66,10 +67,64 @@ let index = function () { show: false, text: '', } - }, totalPages: 1, page: 1, // available columns: + }, + totalPages: 1, + page: 1, + + // available columns: + // visible is hard coded, enabled is user-configurable. tableColumns: { + drag_and_drop: { + visible: true, + enabled: true, + }, + active: { + visible: true, + enabled: true, + }, name: { - enabled: true + visible: true, + enabled: true, + }, + type: { + visible: true, + enabled: true, + }, + liability_type: { + visible: type === 'liabilities', + enabled: true, + }, + liability_direction: { + visible: type === 'liabilities', + enabled: true, + }, + liability_interest: { + visible: type === 'liabilities', + enabled: true, + }, + number: { + visible: true, + enabled: true, + }, + current_balance: { + visible: type !== 'liabilities', + enabled: true, + }, + amount_due: { + visible: type === 'liabilities', + enabled: true, + }, + last_activity: { + visible: true, + enabled: true, + }, + balance_difference: { + visible: true, + enabled: true, + }, + menu: { + visible: true, + enabled: true, }, }, editors: {}, @@ -99,11 +154,34 @@ let index = function () { format(date) { return format(date, i18next.t('config.date_time_fns')); }, + saveColumnSettings() { + let newSettings = {}; + for (let key in this.tableColumns) { + if (this.tableColumns.hasOwnProperty(key)) { + newSettings[key] = this.tableColumns[key].enabled; + } + } + console.log('New settings', newSettings); + setVariable('accts_columns_' + type, newSettings); + }, init() { this.notifications.wait.show = true; this.notifications.wait.text = i18next.t('firefly.wait_loading_data') - this.loadAccounts(); + + const key = 'accts_columns_' + type; + const defaultValue = {"drag_and_drop": false}; + + getVariable(key, defaultValue).then((response) => { + for (let k in response) { + if (response.hasOwnProperty(k) && this.tableColumns.hasOwnProperty(k)) { + this.tableColumns[k].enabled = response[k] ?? true; + } + } + }).then(() => { + this.loadAccounts(); + }); + }, renderObjectValue(field, account) { let renderer = new AccountRenderer(); @@ -148,18 +226,32 @@ let index = function () { }, loadAccounts() { + // sort instructions + const sorting = [{column: this.sortingColumn, direction: this.sortDirection}]; + // get start and end from the store: const start = new Date(window.store.get('start')); const end = new Date(window.store.get('end')); + let params = { + sorting: sorting, + type: type, + page: this.page, + start: start, + end: end + }; + + if(!this.tableColumns.balance_difference.enabled){ + delete params.start; + delete params.end; + } + this.notifications.wait.show = true; this.notifications.wait.text = i18next.t('firefly.wait_loading_data') this.accounts = []; - // sort instructions - // &sorting[0][column]=description&sorting[0][direction]=asc - const sorting = [{column: this.sortingColumn, direction: this.sortDirection}]; + // one page only.o - (new Get()).index({sorting: sorting, type: type, page: this.page, start: start, end: end}).then(response => { + (new Get()).index(params).then(response => { for (let i = 0; i < response.data.data.length; i++) { if (response.data.data.hasOwnProperty(i)) { let current = response.data.data[i]; diff --git a/resources/assets/v2/src/store/get-variable.js b/resources/assets/v2/src/store/get-variable.js index 56d506de46..f65e474b7e 100644 --- a/resources/assets/v2/src/store/get-variable.js +++ b/resources/assets/v2/src/store/get-variable.js @@ -22,31 +22,27 @@ import Get from "../api/v1/preferences/index.js"; import Post from "../api/v1/preferences/post.js"; export function getVariable(name, defaultValue = null) { - const validCache = window.store.get('cacheValid'); // currently unused, window.X can be used by the blade template // to make things available quicker than if the store has to grab it through the API. // then again, it's not that slow. if (validCache && window.hasOwnProperty(name)) { - // console.log('Get from window'); return Promise.resolve(window[name]); } // load from store2, if it's present. const fromStore = window.store.get(name); if (validCache && typeof fromStore !== 'undefined') { - // console.log('Get "' + name + '" from store'); return Promise.resolve(fromStore); } let getter = (new Get); + return getter.getByName(name).then((response) => { - // console.log('Get "' + name + '" from API'); return Promise.resolve(parseResponse(name, response)); - }).catch(() => { + }).catch((error) => { // preference does not exist (yet). // POST it and then return it anyway. let poster = (new Post); - poster.post(name, defaultValue).then((response) => { - + return poster.post(name, defaultValue).then((response) => { return Promise.resolve(parseResponse(name, response)); }); }); @@ -55,7 +51,6 @@ export function getVariable(name, defaultValue = null) { export function parseResponse(name, response) { let value = response.data.data.attributes.data; window.store.set(name, value); - // console.log('Store "' + name + '" in localStorage'); return value; } diff --git a/resources/assets/v2/vite.config.js b/resources/assets/v2/vite.config.js index 822231a7fc..2b56201a0e 100644 --- a/resources/assets/v2/vite.config.js +++ b/resources/assets/v2/vite.config.js @@ -73,6 +73,9 @@ export default defineConfig({ server: { usePolling: true, + watch: { + usePolling: true, + }, host: '10.0.0.15', // hmr: { // protocol: 'wss', diff --git a/resources/views/v2/accounts/index.blade.php b/resources/views/v2/accounts/index.blade.php index 346825f90e..a71036b8d8 100644 --- a/resources/views/v2/accounts/index.blade.php +++ b/resources/views/v2/accounts/index.blade.php @@ -56,58 +56,56 @@ - - + - - - + + + + - - + - + - - - + + + - - + - + @@ -196,6 +213,13 @@
  +   Active? + Name Type + TypeLiability typeLiability directionLiability interest Account number + Current balance + + Current balance + + + Last activity + Balance difference  
+ @@ -135,7 +133,7 @@ + @@ -143,7 +141,10 @@ " + + + + TODO + + + +