Expand dashboard view

This commit is contained in:
James Cole 2024-03-24 16:22:27 +01:00
parent 0b6877a20e
commit 87be478dd8
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
8 changed files with 136 additions and 24 deletions

View File

@ -34,6 +34,10 @@ class EitherConfigKey
{
public static array $static
= [
// currency conversion
'cer.enabled',
// firefly iii settings
'firefly.version',
'firefly.api_version',
'firefly.default_location',

View File

@ -0,0 +1,27 @@
/*
* basic.js
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "../../../boot/axios";
export default class Get {
getByName(name) {
return api.get('/api/v1/configuration/' + name);
}
}

View File

@ -27,6 +27,7 @@ import {Chart} from 'chart.js';
import {getDefaultChartSettings} from "../../support/default-chart-settings.js";
import {getColors} from "../../support/get-colors.js";
import {getCacheKey} from "../../support/get-cache-key.js";
import {getConfiguration} from "../../store/get-configuration.js";
// this is very ugly, but I have no better ideas at the moment to save the currency info
// for each series.
@ -40,6 +41,7 @@ export default () => ({
loadingAccounts: false,
accountList: [],
autoConversion: false,
autoConversionAvailable: false,
chartOptions: null,
switchAutoConversion() {
this.autoConversion = !this.autoConversion;
@ -215,8 +217,16 @@ export default () => ({
for (let iii = 0; iii < current.attributes.transactions.length; iii++) {
let currentTransaction = current.attributes.transactions[iii];
//console.log(currentTransaction);
const nativeAmountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.native_amount) * -1 : parseFloat(currentTransaction.native_amount);
const amountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.amount) * -1 : parseFloat(currentTransaction.amount);
let nativeAmountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.native_amount) * -1 : parseFloat(currentTransaction.native_amount);
let amountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.amount) * -1 : parseFloat(currentTransaction.amount);
// if transfer and source is this account, multiply again
if('transfer' === currentTransaction.type && parseInt(currentTransaction.source_id) === accountId) { //
console.log('transfer', parseInt(currentTransaction.source_id), accountId);
nativeAmountRaw = nativeAmountRaw * -1;
amountRaw = amountRaw * -1;
}
group.transactions.push({
description: currentTransaction.description,
id: current.id,
@ -259,9 +269,12 @@ export default () => ({
init() {
// console.log('accounts init');
Promise.all([getVariable('viewRange', '1M'), getVariable('autoConversion', false), getVariable('language', 'en_US')]).then((values) => {
Promise.all([getVariable('viewRange', '1M'), getVariable('autoConversion', false), getVariable('language', 'en_US'),
getConfiguration('cer.enabled', false)
]).then((values) => {
//console.log('accounts after promises');
this.autoConversion = values[1];
this.autoConversion = values[1] && values[3];
this.autoConversionAvailable = values[3];
afterPromises = true;
// main dashboard chart:

View File

@ -0,0 +1,45 @@
/*
* get-configuration.js
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import Get from "../api/v1/configuration/get.js";
import {parseResponse} from "./get-variable.js";
export function getConfiguration(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') {
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(() => {
return defaultValue;
});
}

View File

@ -52,7 +52,7 @@ export function getVariable(name, defaultValue = null) {
});
}
function parseResponse(name, response) {
export function parseResponse(name, response) {
let value = response.data.data.attributes.data;
window.store.set(name, value);
// console.log('Store "' + name + '" in localStorage');

View File

@ -9,22 +9,24 @@
<div class="card-body p-0" style="position: relative;height:400px;">
<canvas id="account-chart"></canvas>
</div>
<div class="card-footer text-end">
<template x-if="autoConversion">
<button type="button" @click="switchAutoConversion"
class="btn btn-outline-info btm-sm">
<template x-if="autoConversionAvailable">
<div class="card-footer text-end">
<template x-if="autoConversion">
<button type="button" @click="switchAutoConversion"
class="btn btn-outline-info btm-sm">
<span
class="fa-solid fa-comments-dollar"></span> {{ __('firefly.disable_auto_convert') }}
</button>
</template>
<template x-if="!autoConversion">
<button type="button" @click="switchAutoConversion"
class="btn btn-outline-info btm-sm">
</button>
</template>
<template x-if="!autoConversion">
<button type="button" @click="switchAutoConversion"
class="btn btn-outline-info btm-sm">
<span
class="fa-solid fa-comments-dollar"></span> {{ __('firefly.enable_auto_convert') }}
</button>
</template>
</div>
</button>
</template>
</div>
</template>
</div>
</div>

View File

@ -63,7 +63,7 @@
<template x-if="!loading && billBox.unpaid.length > 0">
<p><a href="{{ route('bills.index') }}">{{ __('firefly.bills_to_pay') }}</a></p>
</template>
<template x-if="0 === billBox.unpaid.length">
<template x-if="0 === billBox.unpaid.length && !loading">
<p>No subscriptions are waiting to be paid</p>
</template>
</div>

View File

@ -23,14 +23,35 @@
<template x-if="!autoConversion">
<span>
<template x-if="{{ $amount }}_raw < 0">
<span class="text-danger">
<span x-text="{{ $amount }}"></span>
</span>
<span>
<template x-if="'transfer' === {{ $type }}">
<span class="text-primary">
<span x-text="{{ $native }}"></span>
</span>
</template>
<template x-if="'transfer' !== {{ $type }}">
<span class="text-danger">
<span x-text="{{ $native }}"></span>
</span>
</template>
</span>
</template>
<template x-if="{{ $amount }}_raw >= 0">
<span class="text-success">
<span x-text="{{ $amount }}"></span>
</span>
<span>
<template x-if="'transfer' === {{ $type }}">
<span class="text-primary">
<span x-text="{{ $native }}"></span>
</span>
</template>
<template x-if="'transfer' !== {{ $type }}">
<span class="text-success">
<span x-text="{{ $native }}"></span>
</span>
</template>
</span>
</template>
</span>
</template>