From 2c2dddc071eb4491efcb24832d11860600306565 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 22 Jul 2023 07:51:02 +0200 Subject: [PATCH] It works! --- resources/assets/v4/bootstrap.js | 2 +- resources/assets/v4/dashboard.js | 38 +++++++++++ resources/assets/v4/pages/dashboard.js | 63 +++++++++++++++++++ resources/views/index.blade.php | 2 +- .../views/partials/dashboard/boxes.blade.php | 18 +++++- 5 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 resources/assets/v4/dashboard.js create mode 100644 resources/assets/v4/pages/dashboard.js diff --git a/resources/assets/v4/bootstrap.js b/resources/assets/v4/bootstrap.js index f7c8bb9a3c..0c0b6f4597 100644 --- a/resources/assets/v4/bootstrap.js +++ b/resources/assets/v4/bootstrap.js @@ -5,7 +5,7 @@ */ import axios from 'axios'; -import Alpine from 'alpinejs'; +//import Alpine from 'alpinejs'; import BasicStore from './store/Basic'; window.axios = axios; diff --git a/resources/assets/v4/dashboard.js b/resources/assets/v4/dashboard.js new file mode 100644 index 0000000000..70076396dd --- /dev/null +++ b/resources/assets/v4/dashboard.js @@ -0,0 +1,38 @@ +/* + * dashboard.js + * Copyright (c) 2023 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 . + */ + +import './bootstrap.js'; +import Alpine from "alpinejs"; + +// move to bootstrap later on? +window.Alpine = Alpine + +import dashboard from './pages/dashboard.js'; + +const comps = {dashboard}; + +//import * as comps from '/dist/demo/index.js'; +Object.keys(comps).forEach(comp => { + //let data = new comps[comp](); + console.log('Loaded component ' + comp); + let data = comps[comp](); + Alpine.data(comp, () => data); +}); +Alpine.start(); diff --git a/resources/assets/v4/pages/dashboard.js b/resources/assets/v4/pages/dashboard.js new file mode 100644 index 0000000000..692814cd3a --- /dev/null +++ b/resources/assets/v4/pages/dashboard.js @@ -0,0 +1,63 @@ +/* + * dashboard.js + * Copyright (c) 2023 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 . + */ + + +import Summary from "../api/summary/index.js"; +import {format} from "date-fns"; + +export default () => ({ + balanceBox: {amounts: [], subtitles: []}, + constructor() { + console.log('DashboardClass constructor'); + // + + }, + + // Getter + init() { + // get boxes info. + let getter = new Summary(); + let start = window.BasicStore.get('start'); + let end = window.BasicStore.get('end'); + + // check on NULL values: + if (start !== null && end !== null) { + start = new Date(start); + end = new Date(end); + } + + getter.get(format(start, 'yyyy-MM-dd'), format(end, 'yyyy-MM-dd'), null).then((response) => { + console.log('DashboardClass done!'); + console.log(response.data); + for (const i in response.data) { + if (response.data.hasOwnProperty(i)) { + const current = response.data[i]; + if (i.startsWith('balance-in-')) { + console.log('Balance in: ', current); + this.balanceBox.amounts.push(current.value_parsed); + this.balanceBox.subtitles.push(current.sub_title); + } + } + } + }); + + + }, +}); diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index 34643e79f9..c5ded193c2 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -1,6 +1,6 @@ @extends('layout.v4.default') @section('vite') - @vite(['resources/assets/v4/sass/app.scss', 'resources/assets/v4/app.js', 'resources/assets/v4/index.js']) + @vite(['resources/assets/v4/sass/app.scss', 'resources/assets/v4/dashboard.js']) @endsection @section('content') diff --git a/resources/views/partials/dashboard/boxes.blade.php b/resources/views/partials/dashboard/boxes.blade.php index c987b5ff29..99579ea13a 100644 --- a/resources/views/partials/dashboard/boxes.blade.php +++ b/resources/views/partials/dashboard/boxes.blade.php @@ -2,9 +2,16 @@
-
+
-

TODO amount

+

+ +

{{ __('firefly.in_out_period') }} @@ -15,7 +22,12 @@ - TODO amount + amount +