Rebuild frontend.

This commit is contained in:
James Cole
2021-04-17 20:53:42 +02:00
parent 0a4e3edf43
commit 1a311664e8
70 changed files with 639 additions and 126 deletions

View File

@@ -46,7 +46,8 @@
class="btn btn-secondary"
@click="resetDate"
><i class="fas fa-history"></i></button>
<button id="dropdownMenuButton" :title="$t('firefly.select_period')" aria-expanded="false" aria-haspopup="true" class="btn btn-secondary dropdown-toggle"
<button id="dropdownMenuButton" :title="$t('firefly.select_period')" aria-expanded="false" aria-haspopup="true"
class="btn btn-secondary dropdown-toggle"
data-toggle="dropdown"
type="button">
<i class="fas fa-list"></i>
@@ -78,8 +79,19 @@
import {createNamespacedHelpers} from "vuex";
import Vue from "vue";
import DatePicker from "v-calendar/lib/components/date-picker.umd";
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('dashboard/index')
import subDays from 'date-fns/subDays'
import addDays from 'date-fns/addDays'
import startOfDay from 'date-fns/startOfDay'
import endOfDay from 'date-fns/endOfDay'
import startOfWeek from 'date-fns/startOfWeek'
import endOfWeek from 'date-fns/endOfWeek'
import format from 'date-fns/format'
import startOfQuarter from 'date-fns/startOfQuarter';
import endOfQuarter from 'date-fns/endOfQuarter';
import subQuarters from 'date-fns/subQuarters';
import addQuarters from 'date-fns/addQuarters';
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('dashboard/index')
Vue.component('date-picker', DatePicker)
@@ -130,16 +142,89 @@ export default {
this.generatePeriods()
return false;
},
generatePeriods: function () {
this.periods = [];
// create periods.
let today;
let end;
generateDaily: function () {
let today = new Date(this.range.start);
// yesterday
this.periods.push(
{
start: startOfDay(subDays(today, 1)).toDateString(),
end: endOfDay(subDays(today, 1)).toDateString(),
title: new Intl.DateTimeFormat(this.locale, {year: 'numeric', month: 'long', day: 'numeric'}).format(subDays(today, 1))
}
);
today = new Date(this.range.start);
// today
this.periods.push(
{
start: startOfDay(today).toDateString(),
end: endOfDay(today).toDateString(),
title: new Intl.DateTimeFormat(this.locale, {year: 'numeric', month: 'long', day: 'numeric'}).format(today)
}
);
// tomorrow:
this.periods.push(
{
start: startOfDay(addDays(today, 1)).toDateString(),
end: endOfDay(addDays(today, 1)).toDateString(),
title: new Intl.DateTimeFormat(this.locale, {year: 'numeric', month: 'long', day: 'numeric'}).format(addDays(today, 1))
}
);
// The Day After Tomorrow dun-dun-dun!
this.periods.push(
{
start: startOfDay(addDays(today, 2)).toDateString(),
end: endOfDay(addDays(today, 2)).toDateString(),
title: new Intl.DateTimeFormat(this.locale, {year: 'numeric', month: 'long', day: 'numeric'}).format(addDays(today, 2))
}
);
},
generateWeekly: function () {
let today = new Date(this.range.start);
let start = startOfDay(startOfWeek(subDays(today, 7), {weekStartsOn: 1}));
let end = endOfDay(endOfWeek(subDays(today, 7), {weekStartsOn: 1}));
let dateFormat = this.$t('config.week_in_year_fns');
let title = format(start, dateFormat);
// last week
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// this week
start = startOfDay(startOfWeek(today, {weekStartsOn: 1}));
end = endOfDay(endOfWeek(today, {weekStartsOn: 1}));
title = format(start, dateFormat);
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// next week
start = startOfDay(startOfWeek(addDays(today, 7), {weekStartsOn: 1}));
end = endOfDay(endOfWeek(addDays(today, 7), {weekStartsOn: 1}));
title = format(start, dateFormat);
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
},
generateMonthly: function () {
let today = new Date(this.range.start);
// previous month
firstDayOfMonth = new Date(today.getFullYear(), today.getMonth()-1, 1);
firstDayOfMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1);
lastDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 0);
this.periods.push(
{
@@ -151,7 +236,7 @@ export default {
// this month
firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0);
lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
this.periods.push(
{
start: firstDayOfMonth.toDateString(),
@@ -161,8 +246,8 @@ export default {
);
// next month
let firstDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 1);
let lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+2, 0);
let firstDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 1);
let lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 2, 0);
this.periods.push(
{
start: firstDayOfMonth.toDateString(),
@@ -171,9 +256,271 @@ export default {
}
);
},
generateQuarterly: function () {
let today = new Date(this.range.start);
// last quarter
let start = startOfDay(startOfQuarter(subQuarters(today, 1)));
let end = endOfDay(endOfQuarter(subQuarters(today, 1)));
let dateFormat = this.$t('config.quarter_fns');
let title = format(start, dateFormat);
// last week
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// this quarter
start = startOfDay(startOfQuarter(today));
end = endOfDay(endOfQuarter(today));
title = format(start, dateFormat);
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// next quarter
start = startOfDay(startOfQuarter(addQuarters(today, 1)));
end = endOfDay(endOfQuarter(addQuarters(today, 1)));
title = format(start, dateFormat);
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
},
generateHalfYearly: function () {
let today = new Date(this.range.start);
let start;
let end;
let title = 'todo';
let half = 1;
// its currently first half of year:
if (today.getMonth() <= 5) {
// previous year, last half:
start = today;
start.setFullYear(start.getFullYear() - 1);
start.setMonth(6);
start.setDate(1);
start = startOfDay(start);
end = start;
end.setMonth(11);
end.setDate(31);
end = endOfDay(end);
half = 2;
title = format(start, this.$t('config.half_year_fns', {half: half}));
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// this year, first half:
start = today;
start.setMonth(0);
start.setDate(1);
start = startOfDay(start);
end = today;
end.setMonth(5);
end.setDate(30);
end = endOfDay(start);
half = 1;
title = format(start, this.$t('config.half_year_fns', {half: half}));
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// this year, second half:
start = today;
start.setMonth(6);
start.setDate(1);
start = startOfDay(start);
end = start;
end.setMonth(11);
end.setDate(31);
end = endOfDay(end);
half = 2;
title = format(start, this.$t('config.half_year_fns', {half: half}));
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
return;
}
// this year, first half:
start = today;
start.setMonth(0);
start.setDate(1);
start = startOfDay(start);
end = start;
end.setMonth(5);
end.setDate(30);
end = endOfDay(end);
half = 1;
title = format(start, this.$t('config.half_year_fns', {half: half}));
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// this year, second half:
start = today;
start.setMonth(6);
start.setDate(1);
start = startOfDay(start);
end = today;
end.setMonth(11);
end.setDate(31);
end = endOfDay(start);
half = 2;
title = format(start, this.$t('config.half_year_fns', {half: half}));
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
// next year, first half:
start = today;
start.setMonth(0);
start.setDate(1);
start = startOfDay(start);
end = start;
end.setMonth(5);
end.setDate(30);
end = endOfDay(end);
half = 1;
title = format(start, this.$t('config.half_year_fns', {half: half}));
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: title
}
);
},
generateYearly: function () {
let today = new Date(this.range.start);
let start;
let end;
let title;
// last year
start = new Date(today);
start.setFullYear(start.getFullYear() - 1);
start.setMonth(0);
start.setDate(1);
start = startOfDay(start);
end = new Date(today);
end.setFullYear(end.getFullYear() - 1);
end.setMonth(11);
end.setDate(31);
end = endOfDay(end);
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: start.getFullYear()
}
);
// 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);
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: start.getFullYear()
}
);
// next year
start = new Date(today);
start.setFullYear(start.getFullYear() + 1);
start.setMonth(0);
start.setDate(1);
start = startOfDay(start);
end = new Date(today);
end.setFullYear(end.getFullYear() + 1);
end.setMonth(11);
end.setDate(31);
end = endOfDay(end);
this.periods.push(
{
start: start.toDateString(),
end: end.toDateString(),
title: start.getFullYear()
}
);
},
generatePeriods: function () {
this.periods = [];
//console.log('The view range is "' + this.viewRange + '".');
switch (this.viewRange) {
case '1D':
this.generateDaily();
break;
case '1W':
this.generateWeekly();
break;
case '1M':
this.generateMonthly();
break;
case '3M':
this.generateQuarterly();
break;
case '6M':
this.generateHalfYearly();
break;
case '1Y':
this.generateYearly();
break;
}
// last 7 days
today = new Date;
end = new Date;
let today = new Date;
let end = new Date;
end.setDate(end.getDate() - 7);
this.periods.push(
{

View File

@@ -24,7 +24,6 @@ const state = () => (
viewRange: 'default',
start: null,
end: null,
// default range:
defaultStart: null,
defaultEnd: null,
}
@@ -53,24 +52,32 @@ const getters = {
// actions
const actions = {
initialiseStore(context) {
if ('default' === context.state.viewRange) {
axios.get('./api/v1/preferences/viewRange')
.then(response => {
let viewRange = response.data.data.attributes.data;
context.commit('setViewRange', viewRange);
// call another action:
// console.log('initialiseStore');
// restore from local storage:
context.dispatch('restoreViewRange');
axios.get('./api/v1/preferences/viewRange')
.then(response => {
let viewRange = response.data.data.attributes.data;
let oldViewRange = context.getters.viewRange;
context.commit('setViewRange', viewRange);
if (viewRange !== oldViewRange) {
// console.log('View range changed from "' + oldViewRange + '" to "' + viewRange + '"');
context.dispatch('setDatesFromViewRange');
}
).catch(error => {
// console.log(error);
context.commit('setViewRange', '1M');
// call another action:
context.dispatch('setDatesFromViewRange');
});
}
if(viewRange === oldViewRange) {
// console.log('Restore view range dates');
context.dispatch('restoreViewRangeDates');
}
}
).catch(() => {
context.commit('setViewRange', '1M');
context.dispatch('setDatesFromViewRange');
});
},
setDatesFromViewRange(context) {
// console.log('Must set dates from viewRange "' + context.state.viewRange + '"');
restoreViewRangeDates: function(context) {
// check local storage first?
if (localStorage.viewRangeStart) {
// console.log('view range start set from local storage.');
@@ -91,10 +98,16 @@ const actions = {
// console.log(localStorage.viewRangeDefaultEnd);
context.commit('setDefaultEnd', new Date(localStorage.viewRangeDefaultEnd));
}
if (null !== context.getters.end && null !== context.getters.start) {
return;
},
restoreViewRange: function (context) {
// console.log('restoreViewRange');
let viewRange = localStorage.getItem('viewRange');
if (null !== viewRange) {
// console.log('restored restoreViewRange ' + viewRange );
context.commit('setViewRange', viewRange);
}
},
setDatesFromViewRange(context) {
let start;
let end;
let viewRange = context.getters.viewRange;
@@ -206,6 +219,7 @@ const mutations = {
},
setViewRange(state, range) {
state.viewRange = range;
window.localStorage.setItem('viewRange', range);
}
}

View File

@@ -141,7 +141,10 @@
"next_expected_match": "\u0421\u043b\u0435\u0434\u0432\u0430\u0449o \u043e\u0447\u0430\u043a\u0432\u0430\u043do \u0441\u044a\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435"
},
"config": {
"html_language": "bg"
"html_language": "bg",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "\u0421\u0443\u043c\u0430 \u0432\u044a\u0432 \u0432\u0430\u043b\u0443\u0442\u0430",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Dal\u0161\u00ed o\u010dek\u00e1van\u00e1 shoda"
},
"config": {
"html_language": "cs"
"html_language": "cs",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "\u010c\u00e1stka v ciz\u00ed m\u011bn\u011b",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "N\u00e4chste erwartete \u00dcbereinstimmung"
},
"config": {
"html_language": "de"
"html_language": "de",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Ausl\u00e4ndischer Betrag",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "\u0395\u03c0\u03cc\u03bc\u03b5\u03bd\u03b7 \u03b1\u03bd\u03b1\u03bc\u03b5\u03bd\u03cc\u03bc\u03b5\u03bd\u03b7 \u03b1\u03bd\u03c4\u03b9\u03c3\u03c4\u03bf\u03af\u03c7\u03b9\u03c3\u03b7"
},
"config": {
"html_language": "el"
"html_language": "el",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "\u03a0\u03bf\u03c3\u03cc \u03c3\u03b5 \u03be\u03ad\u03bd\u03bf \u03bd\u03cc\u03bc\u03b9\u03c3\u03bc\u03b1",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Next expected match"
},
"config": {
"html_language": "en-gb"
"html_language": "en-gb",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Foreign amount",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Next expected match"
},
"config": {
"html_language": "en"
"html_language": "en",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Foreign amount",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Pr\u00f3xima coincidencia esperada"
},
"config": {
"html_language": "es"
"html_language": "es",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Cantidad extranjera",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Seuraava lasku odotettavissa"
},
"config": {
"html_language": "fi"
"html_language": "fi",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Ulkomaan summa",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Prochaine association attendue"
},
"config": {
"html_language": "fr"
"html_language": "fr",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Montant en devise \u00e9trang\u00e8re",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "K\u00f6vetkez\u0151 v\u00e1rhat\u00f3 egyez\u00e9s"
},
"config": {
"html_language": "hu"
"html_language": "hu",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "K\u00fclf\u00f6ldi \u00f6sszeg",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Prossimo abbinamento previsto"
},
"config": {
"html_language": "it"
"html_language": "it",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Importo estero",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Neste forventede treff"
},
"config": {
"html_language": "nb"
"html_language": "nb",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Utenlandske bel\u00f8p",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Volgende verwachte match"
},
"config": {
"html_language": "nl"
"html_language": "nl",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Bedrag in vreemde valuta",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Nast\u0119pne oczekiwane dopasowanie"
},
"config": {
"html_language": "pl"
"html_language": "pl",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Kwota zagraniczna",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Pr\u00f3ximo correspondente esperado"
},
"config": {
"html_language": "pt-br"
"html_language": "pt-br",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Montante em moeda estrangeira",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Proxima correspondencia esperada"
},
"config": {
"html_language": "pt"
"html_language": "pt",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Montante estrangeiro",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Urm\u0103toarea potrivire a\u0219teptat\u0103"
},
"config": {
"html_language": "ro"
"html_language": "ro",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Sum\u0103 str\u0103in\u0103",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442"
},
"config": {
"html_language": "ru"
"html_language": "ru",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "\u0421\u0443\u043c\u043c\u0430 \u0432 \u0438\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u0435",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "\u010eal\u0161ia o\u010dak\u00e1van\u00e1 zhoda"
},
"config": {
"html_language": "sk"
"html_language": "sk",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Suma v cudzej mene",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "N\u00e4sta f\u00f6rv\u00e4ntade tr\u00e4ff"
},
"config": {
"html_language": "sv"
"html_language": "sv",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Utl\u00e4ndskt belopp",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "Tr\u1eadn \u0111\u1ea5u d\u1ef1 ki\u1ebfn ti\u1ebfp theo"
},
"config": {
"html_language": "vi"
"html_language": "vi",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "Ngo\u1ea1i t\u1ec7",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "\u9884\u671f\u4e0b\u6b21\u652f\u4ed8"
},
"config": {
"html_language": "zh-cn"
"html_language": "zh-cn",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "\u5916\u5e01\u91d1\u989d",

View File

@@ -141,7 +141,10 @@
"next_expected_match": "\u4e0b\u4e00\u500b\u9810\u671f\u7684\u914d\u5c0d"
},
"config": {
"html_language": "zh-tw"
"html_language": "zh-tw",
"week_in_year_fns": "'Week' I, yyyy",
"quarter_fns": "'Q'Q, yyyy",
"half_year_fns": "'H{half}', yyyy"
},
"form": {
"foreign_amount": "\u5916\u5e63\u91d1\u984d",