mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 12:15:55 +00:00
Rename some things from v4 to v2
This commit is contained in:
35
resources/assets/v2/api/preferences/index.js
Normal file
35
resources/assets/v2/api/preferences/index.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 Preferences {
|
||||
getByName(name) {
|
||||
return api.get('/api/v1/preferences/' + name);
|
||||
}
|
||||
|
||||
getByNameNow(name) {
|
||||
return api.get('/api/v1/preferences/' + name);
|
||||
}
|
||||
|
||||
postByName(name, value) {
|
||||
return api.post('/api/v1/preferences', {name: name, data: value});
|
||||
}
|
||||
}
|
||||
28
resources/assets/v2/api/summary/index.js
Normal file
28
resources/assets/v2/api/summary/index.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* index.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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
import {api} from "../../boot/axios.js";
|
||||
|
||||
export default class Summary {
|
||||
get(start, end, code) {
|
||||
return api.get('/api/v1/summary/basic', {params: {start: start, end: end, code: code}});
|
||||
}
|
||||
}
|
||||
187
resources/assets/v2/app.js
Normal file
187
resources/assets/v2/app.js
Normal file
@@ -0,0 +1,187 @@
|
||||
// import './bootstrap';
|
||||
// import {
|
||||
// addMonths,
|
||||
// endOfDay,
|
||||
// endOfMonth,
|
||||
// endOfQuarter,
|
||||
// endOfWeek,
|
||||
// startOfDay,
|
||||
// startOfMonth,
|
||||
// startOfQuarter,
|
||||
// startOfWeek,
|
||||
// startOfYear,
|
||||
// subDays,
|
||||
// subMonths
|
||||
// } from "date-fns";
|
||||
// import format from './util/format'
|
||||
//
|
||||
// export default () => ({
|
||||
// range: {
|
||||
// start: null, end: null
|
||||
// },
|
||||
// defaultRange: {
|
||||
// start: null, end: null
|
||||
// },
|
||||
//
|
||||
// init() {
|
||||
// console.log('MainApp init');
|
||||
// // get values from store and use them accordingly.
|
||||
// // this.viewRange = window.BasicStore.get('viewRange');
|
||||
// // this.locale = window.BasicStore.get('locale');
|
||||
// // this.language = window.BasicStore.get('language');
|
||||
// // this.locale = 'equal' === this.locale ? this.language : this.locale;
|
||||
// // window.__localeId__ = this.language;
|
||||
// //
|
||||
// // // the range is always null but later on we will store it in BasicStore.
|
||||
// // if (null === this.range.start && null === this.range.end) {
|
||||
// // console.log('start + end = null, calling setDatesFromViewRange()');
|
||||
// // this.range = this.setDatesFromViewRange(new Date);
|
||||
// // }
|
||||
// // console.log('MainApp: set defaultRange');
|
||||
// // this.defaultRange = this.setDatesFromViewRange(new Date);
|
||||
// // // default range is always the current period (initialized ahead)
|
||||
// },
|
||||
//
|
||||
//
|
||||
// buildDateRange() {
|
||||
// console.log('MainApp: buildDateRange');
|
||||
// // generate ranges
|
||||
// let nextRange = this.getNextRange();
|
||||
// let prevRange = this.getPrevRange();
|
||||
// let last7 = this.lastDays(7);
|
||||
// let last30 = this.lastDays(30);
|
||||
// let mtd = this.mtd();
|
||||
// let ytd = this.ytd();
|
||||
//
|
||||
// // set the title:
|
||||
// let element = document.getElementsByClassName('daterange-holder')[0];
|
||||
// element.textContent = format(this.range.start) + ' - ' + format(this.range.end);
|
||||
// element.setAttribute('data-start', format(this.range.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(this.range.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // set the current one
|
||||
// element = document.getElementsByClassName('daterange-current')[0];
|
||||
// element.textContent = format(this.defaultRange.start) + ' - ' + format(this.defaultRange.end);
|
||||
// element.setAttribute('data-start', format(this.defaultRange.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(this.defaultRange.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // generate next range
|
||||
// element = document.getElementsByClassName('daterange-next')[0];
|
||||
// element.textContent = format(nextRange.start) + ' - ' + format(nextRange.end);
|
||||
// element.setAttribute('data-start', format(nextRange.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(nextRange.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // previous range.
|
||||
// element = document.getElementsByClassName('daterange-prev')[0];
|
||||
// element.textContent = format(prevRange.start) + ' - ' + format(prevRange.end);
|
||||
// element.setAttribute('data-start', format(prevRange.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(prevRange.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // last 7
|
||||
// element = document.getElementsByClassName('daterange-7d')[0];
|
||||
// element.setAttribute('data-start', format(last7.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(last7.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // last 30
|
||||
// element = document.getElementsByClassName('daterange-90d')[0];
|
||||
// element.setAttribute('data-start', format(last30.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(last30.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // MTD
|
||||
// element = document.getElementsByClassName('daterange-mtd')[0];
|
||||
// element.setAttribute('data-start', format(mtd.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(mtd.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // YTD
|
||||
// element = document.getElementsByClassName('daterange-ytd')[0];
|
||||
// element.setAttribute('data-start', format(ytd.start, 'yyyy-MM-dd'));
|
||||
// element.setAttribute('data-end', format(ytd.end, 'yyyy-MM-dd'));
|
||||
//
|
||||
// // custom range.
|
||||
// console.log('MainApp: buildDateRange end');
|
||||
// },
|
||||
//
|
||||
// getNextRange() {
|
||||
// let start = startOfMonth(this.range.start);
|
||||
// let nextMonth = addMonths(start, 1);
|
||||
// let end = endOfMonth(nextMonth);
|
||||
// return {start: nextMonth, end: end};
|
||||
// },
|
||||
//
|
||||
// getPrevRange() {
|
||||
// let start = startOfMonth(this.range.start);
|
||||
// let prevMonth = subMonths(start, 1);
|
||||
// let end = endOfMonth(prevMonth);
|
||||
// return {start: prevMonth, end: end};
|
||||
// },
|
||||
//
|
||||
// ytd() {
|
||||
// let end = new Date;
|
||||
// let start = startOfYear(this.range.start);
|
||||
// return {start: start, end: end};
|
||||
// },
|
||||
//
|
||||
// mtd() {
|
||||
//
|
||||
// let end = new Date;
|
||||
// let start = startOfMonth(this.range.start);
|
||||
// return {start: start, end: end};
|
||||
// },
|
||||
//
|
||||
// lastDays(days) {
|
||||
// let end = new Date;
|
||||
// let start = subDays(end, days);
|
||||
// return {start: start, end: end};
|
||||
// },
|
||||
//
|
||||
// changeDateRange(e) {
|
||||
// console.log('MainApp: changeDateRange');
|
||||
// let target = e.currentTarget;
|
||||
// //alert('OK 3');
|
||||
// let start = new Date(target.getAttribute('data-start'));
|
||||
// let end = new Date(target.getAttribute('data-end'));
|
||||
// console.log('MainApp: Change date range', start, end);
|
||||
// e.preventDefault();
|
||||
// // TODO send start + end to the store and trigger this again?
|
||||
// window.app.setStart(start);
|
||||
// window.app.setEnd(end);
|
||||
// window.app.buildDateRange();
|
||||
// console.log('MainApp: end changeDateRange');
|
||||
// return false;
|
||||
// },
|
||||
//
|
||||
// setStart(date) {
|
||||
// console.log('MainApp: setStart');
|
||||
// this.range.start = date;
|
||||
// window.BasicStore.store('start', date);
|
||||
// },
|
||||
//
|
||||
// setEnd(date) {
|
||||
// console.log('MainApp: setEnd');
|
||||
// this.range.end = date;
|
||||
// window.BasicStore.store('end', date);
|
||||
// },
|
||||
// });
|
||||
//
|
||||
// // let app = new MainApp();
|
||||
// //
|
||||
// // // Listen for the basic store, we need it to continue with the
|
||||
// // document.addEventListener("BasicStoreReady", (e) => {
|
||||
// // console.log('MainApp: app.js from event handler');
|
||||
// // app.init();
|
||||
// // app.buildDateRange();
|
||||
// // const event = new Event("AppReady");
|
||||
// // document.dispatchEvent(event);
|
||||
// // }, false,);
|
||||
// //
|
||||
// // if (window.BasicStore.isReady()) {
|
||||
// // console.log('MainApp: app.js from store ready');
|
||||
// // app.init();
|
||||
// // app.buildDateRange();
|
||||
// // const event = new Event("AppReady");
|
||||
// // document.dispatchEvent(event);
|
||||
// // }
|
||||
// //
|
||||
// // window.app = app;
|
||||
// //
|
||||
// // export default app;
|
||||
40
resources/assets/v2/boot/axios.js
Normal file
40
resources/assets/v2/boot/axios.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* axios.js
|
||||
* Copyright (c) 2022 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 axios from 'axios'
|
||||
|
||||
// Be careful when using SSR for cross-request state pollution
|
||||
// due to creating a Singleton instance here;
|
||||
// If any client changes this (global) instance, it might be a
|
||||
// good idea to move this instance creation inside of the
|
||||
// "export default () => {}" function below (which runs individually
|
||||
// for each client)
|
||||
|
||||
|
||||
// for use inside Vue files (Options API) through this.$axios and this.$api
|
||||
|
||||
|
||||
const url = '/';
|
||||
const api = axios.create({baseURL: url, withCredentials: true});
|
||||
|
||||
axios.defaults.withCredentials = true;
|
||||
axios.defaults.baseURL = url;
|
||||
|
||||
export {api}
|
||||
50
resources/assets/v2/bootstrap.js
vendored
Normal file
50
resources/assets/v2/bootstrap.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* We'll load the axios HTTP library which allows us to easily issue requests
|
||||
* to our Laravel back-end. This library automatically handles sending the
|
||||
* CSRF token as a header based on the value of the "XSRF" token cookie.
|
||||
*/
|
||||
|
||||
// import things
|
||||
import axios from 'axios';
|
||||
import store from "store";
|
||||
import observePlugin from 'store/plugins/observe';
|
||||
import Alpine from "alpinejs";
|
||||
|
||||
// add plugin to store and put in window
|
||||
store.addPlugin(observePlugin);
|
||||
window.store = store;
|
||||
|
||||
// import even more
|
||||
import {getVariable} from "./store/get-variable.js";
|
||||
import {getViewRange} from "./support/get-viewrange.js";
|
||||
|
||||
// wait for 3 promises, because we need those later on.
|
||||
window.bootstrapped = false;
|
||||
Promise.all([
|
||||
getVariable('viewRange'),
|
||||
getVariable('darkMode'),
|
||||
getVariable('locale'),
|
||||
getVariable('language'),
|
||||
]).then((values) => {
|
||||
if (!store.get('start') || !store.get('end')) {
|
||||
// calculate new start and end, and store them.
|
||||
const range = getViewRange(values[0], new Date);
|
||||
store.set('start', range.start);
|
||||
store.set('end', range.end);
|
||||
}
|
||||
|
||||
const event = new Event('firefly-iii-bootstrapped');
|
||||
document.dispatchEvent(event);
|
||||
window.bootstrapped = true;
|
||||
});
|
||||
|
||||
window.axios = axios;
|
||||
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
||||
|
||||
// include popper js
|
||||
import '@popperjs/core';
|
||||
|
||||
// include bootstrap CSS
|
||||
import * as bootstrap from 'bootstrap'
|
||||
|
||||
window.Alpine = Alpine
|
||||
42
resources/assets/v2/dashboard.js
Normal file
42
resources/assets/v2/dashboard.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import './bootstrap.js';
|
||||
import dates from './pages/shared/dates.js';
|
||||
import boxes from './pages/dashboard/boxes.js';
|
||||
|
||||
const comps = {dates, boxes};
|
||||
|
||||
function loadPage(comps) {
|
||||
Object.keys(comps).forEach(comp => {
|
||||
let data = comps[comp]();
|
||||
Alpine.data(comp, () => data);
|
||||
});
|
||||
Alpine.start();
|
||||
}
|
||||
|
||||
// wait for load until bootstrapped event is received.
|
||||
document.addEventListener('firefly-iii-bootstrapped', () => {
|
||||
loadPage(comps);
|
||||
});
|
||||
// or is bootstrapped before event is triggered.
|
||||
if (window.bootstrapped) {
|
||||
loadPage(comps);
|
||||
}
|
||||
80
resources/assets/v2/index.js
Normal file
80
resources/assets/v2/index.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import Summary from "./api/summary/index.js";
|
||||
import {format} from 'date-fns'
|
||||
import Alpine from "alpinejs";
|
||||
|
||||
//let amounts = [];
|
||||
|
||||
class IndexApp {
|
||||
|
||||
balanceBox = {foo: 'bar'};
|
||||
|
||||
constructor() {
|
||||
console.log('IndexApp constructor');
|
||||
}
|
||||
|
||||
init() {
|
||||
console.log('IndexApp init');
|
||||
this.loadBoxes();
|
||||
}
|
||||
|
||||
loadBoxes() {
|
||||
console.log('IndexApp loadBoxes');
|
||||
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('IndexApp done!');
|
||||
console.log(response.data);
|
||||
document.querySelector('#balanceAmount').innerText = 'ok dan';
|
||||
//window.$refs.balanceAmount.text = 'bar!';
|
||||
for (const i in response.data) {
|
||||
if (response.data.hasOwnProperty(i)) {
|
||||
const current = response.data[i];
|
||||
if (i.startsWith('balance-in-')) {
|
||||
//amounts.push(current);
|
||||
console.log('Balance in: ', current);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let index = new IndexApp();
|
||||
|
||||
document.addEventListener("AppReady", (e) => {
|
||||
index.init();
|
||||
}, false,);
|
||||
|
||||
if (window.BasicStore.isReady()) {
|
||||
index.init();
|
||||
}
|
||||
document.addEventListener('alpine:init', () => {
|
||||
Alpine.data('balanceBox', () => ({
|
||||
foo: 'barX'
|
||||
}))
|
||||
})
|
||||
|
||||
export function amounts() {
|
||||
return {
|
||||
amounts: ['bar', 'boo', 'baz'],
|
||||
add() {
|
||||
this.amounts.push('foo');
|
||||
},
|
||||
get() {
|
||||
return this.amounts[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.Alpine = Alpine
|
||||
Alpine.start()
|
||||
97
resources/assets/v2/pages/dashboard/boxes.js
Normal file
97
resources/assets/v2/pages/dashboard/boxes.js
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import Summary from "../../api/summary/index.js";
|
||||
import {format} from "date-fns";
|
||||
import {getVariable} from "../../store/get-variable.js";
|
||||
|
||||
|
||||
export default () => ({
|
||||
balanceBox: {amounts: [], subtitles: []},
|
||||
billBox: {paid: [], unpaid: []},
|
||||
leftBox: {left: [], perDay: []},
|
||||
netBox: {net: []},
|
||||
loadBoxes() {
|
||||
console.log('loadboxes');
|
||||
|
||||
// get stuff
|
||||
let getter = new Summary();
|
||||
let start = new Date(window.store.get('start'));
|
||||
let end = new Date(window.store.get('end'));
|
||||
|
||||
getter.get(format(start, 'yyyy-MM-dd'), format(end, 'yyyy-MM-dd'), null).then((response) => {
|
||||
// reset boxes:
|
||||
this.balanceBox = {amounts: [], subtitles: []};
|
||||
this.billBox = {paid: [], unpaid: []};
|
||||
this.leftBox = {left: [], perDay: []};
|
||||
this.netBox = {net: []};
|
||||
|
||||
// process new content:
|
||||
for (const i in response.data) {
|
||||
if (response.data.hasOwnProperty(i)) {
|
||||
const current = response.data[i];
|
||||
if (i.startsWith('balance-in-')) {
|
||||
this.balanceBox.amounts.push(current.value_parsed);
|
||||
this.balanceBox.subtitles.push(current.sub_title);
|
||||
continue;
|
||||
}
|
||||
if (i.startsWith('bills-unpaid-in-')) {
|
||||
this.billBox.unpaid.push(current.value_parsed);
|
||||
continue;
|
||||
}
|
||||
if (i.startsWith('bills-paid-in-')) {
|
||||
this.billBox.paid.push(current.value_parsed);
|
||||
continue;
|
||||
}
|
||||
if (i.startsWith('spent-in-')) {
|
||||
this.leftBox.left.push(current.value_parsed);
|
||||
continue;
|
||||
}
|
||||
if (i.startsWith('left-to-spend-in-')) { // per day
|
||||
this.leftBox.perDay.push(current.sub_title);
|
||||
continue;
|
||||
}
|
||||
if (i.startsWith('net-worth-in-')) {
|
||||
this.netBox.net.push(current.value_parsed);
|
||||
|
||||
}
|
||||
//console.log('Next up: ', current);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
// Getter
|
||||
init() {
|
||||
console.log('Now in boxes');
|
||||
Promise.all([
|
||||
getVariable('viewRange'),
|
||||
]).then((values) => {
|
||||
this.loadBoxes();
|
||||
});
|
||||
window.store.observe('start', (newValue, oldValue) => {
|
||||
// this.loadBoxes();
|
||||
});
|
||||
window.store.observe('end', (newValue, oldValue) => {
|
||||
this.loadBoxes();
|
||||
});
|
||||
},
|
||||
});
|
||||
177
resources/assets/v2/pages/shared/dates.js
Normal file
177
resources/assets/v2/pages/shared/dates.js
Normal file
@@ -0,0 +1,177 @@
|
||||
import {
|
||||
addMonths,
|
||||
endOfDay,
|
||||
endOfMonth,
|
||||
endOfQuarter,
|
||||
endOfWeek,
|
||||
startOfDay,
|
||||
startOfMonth,
|
||||
startOfQuarter,
|
||||
startOfWeek,
|
||||
startOfYear,
|
||||
subDays,
|
||||
subMonths
|
||||
} from "date-fns";
|
||||
import format from '../../util/format'
|
||||
|
||||
export default () => ({
|
||||
range: {
|
||||
start: null, end: null
|
||||
},
|
||||
defaultRange: {
|
||||
start: null, end: null
|
||||
},
|
||||
language: 'en-US',
|
||||
|
||||
init() {
|
||||
console.log('Dates init');
|
||||
|
||||
this.range = {
|
||||
start: new Date(window.store.get('start')),
|
||||
end: new Date(window.store.get('end'))
|
||||
};
|
||||
this.defaultRange = {
|
||||
start: new Date(window.store.get('start')),
|
||||
end: new Date(window.store.get('end'))
|
||||
};
|
||||
this.language = window.store.get('language');
|
||||
this.locale = window.store.get('locale');
|
||||
this.locale = 'equal' === this.locale ? this.language : this.locale;
|
||||
window.__localeId__ = this.language;
|
||||
this.buildDateRange();
|
||||
|
||||
window.store.observe('start', (newValue) => {
|
||||
this.range.start = new Date(newValue);
|
||||
});
|
||||
window.store.observe('end', (newValue) => {
|
||||
this.range.end = new Date(newValue);
|
||||
this.buildDateRange();
|
||||
});
|
||||
|
||||
//this.range = this.setDatesFromViewRange(this.range.start);
|
||||
// get values from store and use them accordingly.
|
||||
// this.viewRange = window.BasicStore.get('viewRange');
|
||||
// this.locale = window.BasicStore.get('locale');
|
||||
// this.language = window.BasicStore.get('language');
|
||||
// this.locale = 'equal' === this.locale ? this.language : this.locale;
|
||||
// window.__localeId__ = this.language;
|
||||
//
|
||||
// // the range is always null but later on we will store it in BasicStore.
|
||||
// if (null === this.range.start && null === this.range.end) {
|
||||
// console.log('start + end = null, calling setDatesFromViewRange()');
|
||||
// this.range = this.setDatesFromViewRange(new Date);
|
||||
// }
|
||||
// console.log('MainApp: set defaultRange');
|
||||
// this.defaultRange = this.setDatesFromViewRange(new Date);
|
||||
// // default range is always the current period (initialized ahead)
|
||||
},
|
||||
|
||||
|
||||
buildDateRange() {
|
||||
console.log('Dates buildDateRange');
|
||||
|
||||
// generate ranges
|
||||
let nextRange = this.getNextRange();
|
||||
let prevRange = this.getPrevRange();
|
||||
let last7 = this.lastDays(7);
|
||||
let last30 = this.lastDays(30);
|
||||
let mtd = this.mtd();
|
||||
let ytd = this.ytd();
|
||||
|
||||
// set the title:
|
||||
let element = document.getElementsByClassName('daterange-holder')[0];
|
||||
element.textContent = format(this.range.start) + ' - ' + format(this.range.end);
|
||||
element.setAttribute('data-start', format(this.range.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(this.range.end, 'yyyy-MM-dd'));
|
||||
|
||||
// set the current one
|
||||
element = document.getElementsByClassName('daterange-current')[0];
|
||||
element.textContent = format(this.defaultRange.start) + ' - ' + format(this.defaultRange.end);
|
||||
element.setAttribute('data-start', format(this.defaultRange.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(this.defaultRange.end, 'yyyy-MM-dd'));
|
||||
|
||||
// generate next range
|
||||
element = document.getElementsByClassName('daterange-next')[0];
|
||||
element.textContent = format(nextRange.start) + ' - ' + format(nextRange.end);
|
||||
element.setAttribute('data-start', format(nextRange.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(nextRange.end, 'yyyy-MM-dd'));
|
||||
|
||||
// previous range.
|
||||
element = document.getElementsByClassName('daterange-prev')[0];
|
||||
element.textContent = format(prevRange.start) + ' - ' + format(prevRange.end);
|
||||
element.setAttribute('data-start', format(prevRange.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(prevRange.end, 'yyyy-MM-dd'));
|
||||
|
||||
// last 7
|
||||
element = document.getElementsByClassName('daterange-7d')[0];
|
||||
element.setAttribute('data-start', format(last7.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(last7.end, 'yyyy-MM-dd'));
|
||||
|
||||
// last 30
|
||||
element = document.getElementsByClassName('daterange-90d')[0];
|
||||
element.setAttribute('data-start', format(last30.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(last30.end, 'yyyy-MM-dd'));
|
||||
|
||||
// MTD
|
||||
element = document.getElementsByClassName('daterange-mtd')[0];
|
||||
element.setAttribute('data-start', format(mtd.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(mtd.end, 'yyyy-MM-dd'));
|
||||
|
||||
// YTD
|
||||
element = document.getElementsByClassName('daterange-ytd')[0];
|
||||
element.setAttribute('data-start', format(ytd.start, 'yyyy-MM-dd'));
|
||||
element.setAttribute('data-end', format(ytd.end, 'yyyy-MM-dd'));
|
||||
|
||||
// custom range.
|
||||
console.log('MainApp: buildDateRange end');
|
||||
},
|
||||
|
||||
getNextRange() {
|
||||
let start = startOfMonth(this.range.start);
|
||||
let nextMonth = addMonths(start, 1);
|
||||
let end = endOfMonth(nextMonth);
|
||||
return {start: nextMonth, end: end};
|
||||
},
|
||||
|
||||
getPrevRange() {
|
||||
let start = startOfMonth(this.range.start);
|
||||
let prevMonth = subMonths(start, 1);
|
||||
let end = endOfMonth(prevMonth);
|
||||
return {start: prevMonth, end: end};
|
||||
},
|
||||
|
||||
ytd() {
|
||||
let end = new Date;
|
||||
let start = startOfYear(this.range.start);
|
||||
return {start: start, end: end};
|
||||
},
|
||||
|
||||
mtd() {
|
||||
|
||||
let end = new Date;
|
||||
let start = startOfMonth(this.range.start);
|
||||
return {start: start, end: end};
|
||||
},
|
||||
|
||||
lastDays(days) {
|
||||
let end = new Date;
|
||||
let start = subDays(end, days);
|
||||
return {start: start, end: end};
|
||||
},
|
||||
|
||||
changeDateRange(e) {
|
||||
e.preventDefault();
|
||||
console.log('MainApp: changeDateRange');
|
||||
let target = e.currentTarget;
|
||||
|
||||
let start = new Date(target.getAttribute('data-start'));
|
||||
let end = new Date(target.getAttribute('data-end'));
|
||||
console.log('MainApp: Change date range', start, end);
|
||||
|
||||
window.store.set('start', start);
|
||||
window.store.set('end', end);
|
||||
//this.buildDateRange();
|
||||
return false;
|
||||
},
|
||||
|
||||
});
|
||||
34
resources/assets/v2/sass/app.scss
Normal file
34
resources/assets/v2/sass/app.scss
Normal file
@@ -0,0 +1,34 @@
|
||||
/*!
|
||||
* app.scss
|
||||
* Copyright (c) 2019 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/>.
|
||||
*/
|
||||
|
||||
/* TODO REMOVE ME */
|
||||
// Variables
|
||||
//@import "variables";
|
||||
|
||||
// Bootstrap
|
||||
//@import "~bootstrap-sass/assets/stylesheets/bootstrap";
|
||||
|
||||
// Font awesome
|
||||
//@import "~font-awesome/css/font-awesome";
|
||||
$fa-font-path: "@fortawesome/fontawesome-free/webfonts";
|
||||
@import "@fortawesome/fontawesome-free/scss/fontawesome.scss";
|
||||
@import "@fortawesome/fontawesome-free/scss/solid.scss";
|
||||
@import "@fortawesome/fontawesome-free/scss/brands.scss";
|
||||
@import "@fortawesome/fontawesome-free/scss/regular.scss";
|
||||
102
resources/assets/v2/store/Basic.js
Normal file
102
resources/assets/v2/store/Basic.js
Normal file
@@ -0,0 +1,102 @@
|
||||
// basic store for preferred date range and some other vars.
|
||||
// used in layout.
|
||||
import Get from '../api/preferences/index.js';
|
||||
import store from 'store';
|
||||
|
||||
|
||||
/**
|
||||
* A basic store for Firefly III persistent UI data and preferences.
|
||||
*/
|
||||
const Basic = () => {
|
||||
|
||||
// currently availabel variables:
|
||||
const viewRange = '1M';
|
||||
const darkMode = 'browser';
|
||||
const language = 'en-US';
|
||||
const locale = 'en-US';
|
||||
|
||||
// start and end are used by most pages to allow the user to browse back and forth.
|
||||
const start = null;
|
||||
const end = null;
|
||||
|
||||
// others, to be used in the future.
|
||||
const listPageSize = 10;
|
||||
const currencyCode = 'AAA';
|
||||
const currencyId = '0';
|
||||
const ready = false;
|
||||
//
|
||||
// a very basic way to signal the store now contains all variables.
|
||||
const count = 0;
|
||||
const readyCount = 4;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const init = () => {
|
||||
console.log('Basic store init')
|
||||
this.loadVariable('viewRange')
|
||||
this.loadVariable('darkMode')
|
||||
this.loadVariable('language')
|
||||
this.loadVariable('locale')
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a variable, fresh or from storage.
|
||||
* @param name
|
||||
*/
|
||||
const loadVariable = (name) => {
|
||||
|
||||
// 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 (window.hasOwnProperty(name)) {
|
||||
this[name] = window[name];
|
||||
this.triggerReady();
|
||||
return;
|
||||
}
|
||||
// load from store
|
||||
if (store.get(name)) {
|
||||
this[name] = store.get(name);
|
||||
this.triggerReady();
|
||||
return;
|
||||
}
|
||||
// grab
|
||||
let getter = (new Get);
|
||||
getter.getByName(name).then((response) => this.parseResponse(name, response));
|
||||
}
|
||||
//
|
||||
const parseResponse = (name, response) => {
|
||||
let value = response.data.data.attributes.data;
|
||||
this[name] = value;
|
||||
// TODO store.
|
||||
store.set(name, value);
|
||||
this.triggerReady();
|
||||
}
|
||||
//
|
||||
// set(name, value) {
|
||||
// this[name] = value;
|
||||
// store.set(name, value);
|
||||
// }
|
||||
//
|
||||
// get(name) {
|
||||
// return store.get(name, this[name]);
|
||||
// }
|
||||
//
|
||||
const isReady = () => {
|
||||
return this.count === this.readyCount;
|
||||
}
|
||||
|
||||
const triggerReady = () => {
|
||||
this.count++;
|
||||
if (this.count === this.readyCount) {
|
||||
console.log('Basic store is ready!')
|
||||
// trigger event:
|
||||
const event = new Event("BasicStoreReady");
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
return {
|
||||
init
|
||||
};
|
||||
}
|
||||
export const basic = Basic();
|
||||
51
resources/assets/v2/store/get-variable.js
Normal file
51
resources/assets/v2/store/get-variable.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* get-variable.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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import Get from "../api/preferences/index.js";
|
||||
|
||||
export function getVariable(name) {
|
||||
|
||||
// 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 (window.hasOwnProperty(name)) {
|
||||
console.log('Get from window');
|
||||
return Promise.resolve(window[name]);
|
||||
}
|
||||
// load from store2, if it's present.
|
||||
if (window.store.get(name)) {
|
||||
console.log('Get from store');
|
||||
return Promise.resolve(window.store.get(name));
|
||||
}
|
||||
let getter = (new Get);
|
||||
return getter.getByName(name).then((response) => {
|
||||
console.log('Get from API');
|
||||
return Promise.resolve(parseResponse(name, response));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function parseResponse(name, response) {
|
||||
let value = response.data.data.attributes.data;
|
||||
window.store.set(name, value);
|
||||
console.log('Store from API');
|
||||
return value;
|
||||
}
|
||||
|
||||
107
resources/assets/v2/support/get-viewrange.js
Normal file
107
resources/assets/v2/support/get-viewrange.js
Normal file
@@ -0,0 +1,107 @@
|
||||
import {
|
||||
endOfDay, endOfMonth, endOfQuarter,
|
||||
endOfWeek,
|
||||
startOfDay,
|
||||
startOfMonth,
|
||||
startOfQuarter,
|
||||
startOfWeek,
|
||||
startOfYear,
|
||||
subDays
|
||||
} from "date-fns";
|
||||
|
||||
function getViewRange(viewRange, today) {
|
||||
let start;
|
||||
let end;
|
||||
|
||||
console.log('getViewRange: ' + viewRange);
|
||||
|
||||
switch (viewRange) {
|
||||
case 'last365':
|
||||
start = startOfDay(subDays(today, 365));
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case 'last90':
|
||||
start = startOfDay(subDays(today, 90));
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case 'last30':
|
||||
start = startOfDay(subDays(today, 30));
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case 'last7':
|
||||
start = startOfDay(subDays(today, 7));
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case 'YTD':
|
||||
start = startOfYear(today);
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case 'QTD':
|
||||
start = startOfQuarter(today);
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case 'MTD':
|
||||
start = startOfMonth(today);
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case '1D':
|
||||
// today:
|
||||
start = startOfDay(today);
|
||||
end = endOfDay(today);
|
||||
break;
|
||||
case '1W':
|
||||
// this week:
|
||||
start = startOfDay(startOfWeek(today, {weekStartsOn: 1}));
|
||||
end = endOfDay(endOfWeek(today, {weekStartsOn: 1}));
|
||||
break;
|
||||
case '1M':
|
||||
// this month:
|
||||
start = startOfDay(startOfMonth(today));
|
||||
end = endOfDay(endOfMonth(today));
|
||||
break;
|
||||
case '3M':
|
||||
// this quarter
|
||||
start = startOfDay(startOfQuarter(today));
|
||||
end = endOfDay(endOfQuarter(today));
|
||||
break;
|
||||
case '6M':
|
||||
// this half-year
|
||||
if (today.getMonth() <= 5) {
|
||||
start = new Date(today);
|
||||
start.setMonth(0);
|
||||
start.setDate(1);
|
||||
start = startOfDay(start);
|
||||
end = new Date(today);
|
||||
end.setMonth(5);
|
||||
end.setDate(30);
|
||||
end = endOfDay(start);
|
||||
}
|
||||
if (today.getMonth() > 5) {
|
||||
start = new Date(today);
|
||||
start.setMonth(6);
|
||||
start.setDate(1);
|
||||
start = startOfDay(start);
|
||||
end = new Date(today);
|
||||
end.setMonth(11);
|
||||
end.setDate(31);
|
||||
end = endOfDay(start);
|
||||
}
|
||||
break;
|
||||
case '1Y':
|
||||
// this year
|
||||
start = new Date(today);
|
||||
start.setMonth(0);
|
||||
start.setDate(1);
|
||||
start = startOfDay(start);
|
||||
|
||||
end = new Date(today);
|
||||
end.setMonth(11);
|
||||
end.setDate(31);
|
||||
end = endOfDay(end);
|
||||
break;
|
||||
}
|
||||
console.log('MainApp: setDatesFromViewRange done!');
|
||||
return {start: start, end: end};
|
||||
}
|
||||
|
||||
export {getViewRange};
|
||||
99
resources/assets/v2/util/format.js
Normal file
99
resources/assets/v2/util/format.js
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* format.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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {format} from 'date-fns'
|
||||
import {
|
||||
bg,
|
||||
cs,
|
||||
da,
|
||||
de,
|
||||
el,
|
||||
enGB,
|
||||
enUS,
|
||||
es,
|
||||
ca,
|
||||
fi,
|
||||
fr,
|
||||
hu,
|
||||
id,
|
||||
it,
|
||||
ja,
|
||||
ko,
|
||||
nb,
|
||||
nn,
|
||||
nl,
|
||||
pl,
|
||||
ptBR,
|
||||
pt,
|
||||
ro,
|
||||
ru,
|
||||
sk,
|
||||
sl,
|
||||
sv,
|
||||
tr,
|
||||
uk,
|
||||
vi,
|
||||
zhTW,
|
||||
zhCN
|
||||
} from 'date-fns/locale'
|
||||
|
||||
const locales = {
|
||||
bg,
|
||||
cs,
|
||||
da,
|
||||
de,
|
||||
el,
|
||||
enGB,
|
||||
enUS,
|
||||
es,
|
||||
ca,
|
||||
fi,
|
||||
fr,
|
||||
hu,
|
||||
id,
|
||||
it,
|
||||
ja,
|
||||
ko,
|
||||
nb,
|
||||
nn,
|
||||
nl,
|
||||
pl,
|
||||
ptBR,
|
||||
pt,
|
||||
ro,
|
||||
ru,
|
||||
sk,
|
||||
sl,
|
||||
sv,
|
||||
tr,
|
||||
uk,
|
||||
vi,
|
||||
zhTW,
|
||||
zhCN
|
||||
}
|
||||
|
||||
// by providing a default string of 'PP' or any of its variants for `formatStr`
|
||||
// it will format dates in whichever way is appropriate to the locale
|
||||
export default function (date, formatStr = 'PP') {
|
||||
let locale = window.__localeId__.replace('_', '');
|
||||
return format(date, formatStr, {
|
||||
locale: locales[locale] ?? locales[locale.slice(0, 2)] ?? locales['enUS'] // or global.__localeId__
|
||||
})
|
||||
}
|
||||
24
resources/assets/v2/util/index.js
Normal file
24
resources/assets/v2/util/index.js
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
const domContentLoadedCallbacks = [];
|
||||
// from admin LTE
|
||||
const onDOMContentLoaded = (callback) => {
|
||||
if (document.readyState === 'loading') {
|
||||
// add listener on the first call when the document is in loading state
|
||||
if (!domContentLoadedCallbacks.length) {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
for (const callback of domContentLoadedCallbacks) {
|
||||
callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
domContentLoadedCallbacks.push(callback)
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
onDOMContentLoaded,
|
||||
}
|
||||
Reference in New Issue
Block a user