mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
Update frontend
This commit is contained in:
@@ -39,15 +39,17 @@
|
||||
<div class="col">
|
||||
<div class="btn-group btn-group-sm d-flex">
|
||||
<button
|
||||
class="btn btn-secondary btn-sm"
|
||||
class="btn btn-secondary btn-sm" :title="$t('firefly.custom_period')"
|
||||
@click="togglePopover({ placement: 'auto-start', positionFixed:true })"
|
||||
><i class="fas fa-calendar-alt"></i></button>
|
||||
<button
|
||||
class="btn btn-secondary"
|
||||
:title="$t('firefly.reset_to_current')"
|
||||
><i class="fas fa-history"></i></button>
|
||||
|
||||
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
|
||||
:title="$t('firefly.select_period')"
|
||||
aria-expanded="false">
|
||||
<i class="fas fa-list"></i>
|
||||
</button>
|
||||
@@ -79,11 +81,7 @@
|
||||
export default {
|
||||
name: "Calendar",
|
||||
created() {
|
||||
// this.locale = localStorage.locale ?? 'en-US';
|
||||
// this.$store.commit('increment');
|
||||
// console.log(this.$store.state.count);
|
||||
// get dates for current period (history button):
|
||||
// get dates for optional periods (dropdown) + descriptions.
|
||||
this.locale = localStorage.locale ?? 'en-US';
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@@ -60,10 +60,28 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {createNamespacedHelpers} from "vuex";
|
||||
|
||||
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('dashboard/index')
|
||||
|
||||
export default {
|
||||
name: "Dashboard",
|
||||
created() {},
|
||||
computed: {},
|
||||
methods: {}
|
||||
created() {
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapGetters([
|
||||
'viewRange',
|
||||
'start',
|
||||
'end'
|
||||
])
|
||||
},
|
||||
methods: {},
|
||||
watch: {
|
||||
start: function (value) {
|
||||
console.log('Value of start is now ' + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
7
frontend/src/components/store/index.js
vendored
7
frontend/src/components/store/index.js
vendored
@@ -21,6 +21,7 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex, {createLogger} from 'vuex'
|
||||
import transactions_create from './modules/transactions/create';
|
||||
import dashboard_index from './modules/dashboard/index';
|
||||
|
||||
Vue.use(Vuex)
|
||||
const debug = process.env.NODE_ENV !== 'production'
|
||||
@@ -33,6 +34,12 @@ export default new Vuex.Store(
|
||||
modules: {
|
||||
create: transactions_create
|
||||
}
|
||||
},
|
||||
dashboard: {
|
||||
namespaced: true,
|
||||
modules: {
|
||||
index: dashboard_index
|
||||
}
|
||||
}
|
||||
},
|
||||
strict: debug,
|
||||
|
186
frontend/src/components/store/modules/dashboard/index.js
vendored
Normal file
186
frontend/src/components/store/modules/dashboard/index.js
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* index.js
|
||||
* Copyright (c) 2020 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/>.
|
||||
*/
|
||||
|
||||
// initial state
|
||||
const state = () => (
|
||||
{
|
||||
start: null,
|
||||
end: null,
|
||||
viewRange: 'default'
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
// getters
|
||||
const getters = {
|
||||
start: state => {
|
||||
return state.start;
|
||||
},
|
||||
end: state => {
|
||||
return state.end;
|
||||
},
|
||||
viewRange: state => {
|
||||
return state.viewRange;
|
||||
}
|
||||
}
|
||||
|
||||
// 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:
|
||||
context.dispatch('setDatesFromViewRange');
|
||||
}
|
||||
).catch(error => {
|
||||
console.log(error);
|
||||
context.commit('setViewRange', '1M');
|
||||
// call another action:
|
||||
context.dispatch('setDatesFromViewRange');
|
||||
});
|
||||
}
|
||||
},
|
||||
setDatesFromViewRange(context) {
|
||||
console.log('Must set dates from viewRange "' + context.state.viewRange + '"');
|
||||
// check local storage first?
|
||||
if (localStorage.viewRangeStart) {
|
||||
console.log('view range set from local storage.');
|
||||
context.commit('setStart', localStorage.viewRangeStart);
|
||||
}
|
||||
if (localStorage.viewRangeEnd) {
|
||||
console.log('view range set from local storage.');
|
||||
context.commit('setEnd', localStorage.viewRangeEnd);
|
||||
}
|
||||
if (null !== context.getters.end && null !== context.getters.start) {
|
||||
return;
|
||||
}
|
||||
console.log('view range must be calculated.');
|
||||
let start;
|
||||
let end;
|
||||
let viewRange = context.getters.viewRange;
|
||||
viewRange = '1Y';
|
||||
switch (viewRange) {
|
||||
case '1D':
|
||||
// one day:
|
||||
start = new Date;
|
||||
end = new Date(start.getTime());
|
||||
start.setHours(0, 0, 0, 0);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
break;
|
||||
case '1W':
|
||||
// this week:
|
||||
start = new Date;
|
||||
end = new Date(start.getTime());
|
||||
// start of week
|
||||
let diff = start.getDate() - start.getDay() + (start.getDay() === 0 ? -6 : 1);
|
||||
start.setDate(diff);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
|
||||
// end of week
|
||||
let lastday = end.getDate() - (end.getDay() - 1) + 6;
|
||||
end.setDate(lastday);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
break;
|
||||
case '1M':
|
||||
// this month:
|
||||
start = new Date;
|
||||
start = new Date(start.getFullYear(), start.getMonth(), 1);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
end = new Date(start.getFullYear(), start.getMonth() + 1, 0);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
break;
|
||||
case '3M':
|
||||
// this quarter
|
||||
start = new Date;
|
||||
end = new Date;
|
||||
let quarter = Math.floor((start.getMonth() + 3) / 3)-1;
|
||||
// start and end months? I'm sure this could be better:
|
||||
let startMonths = [0,3,6,9];
|
||||
let endMonths = [2,5,8,11];
|
||||
// set start to the correct month, day one:
|
||||
start = new Date(start.getFullYear(), startMonths[quarter], 1);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
|
||||
// set end to the correct month, day one
|
||||
end = new Date(end.getFullYear(), endMonths[quarter], 1);
|
||||
// then to the last day of the month:
|
||||
end = new Date(end.getFullYear(), end.getMonth() + 1, 0);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
break;
|
||||
case '6M':
|
||||
// this half-year
|
||||
start = new Date;
|
||||
end = new Date;
|
||||
let half = start.getMonth()<= 5 ? 0 : 1;
|
||||
|
||||
let startHalf = [0,6];
|
||||
let endHalf = [5,11];
|
||||
// set start to the correct month, day one:
|
||||
start = new Date(start.getFullYear(), startHalf[half], 1);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
|
||||
// set end to the correct month, day one
|
||||
end = new Date(end.getFullYear(), endHalf[half], 1);
|
||||
// then to the last day of the month:
|
||||
end = new Date(end.getFullYear(), end.getMonth() + 1, 0);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
break;
|
||||
case '1Y':
|
||||
// this year
|
||||
start = new Date;
|
||||
end = new Date;
|
||||
start = new Date(start.getFullYear(), 0, 1);
|
||||
|
||||
end = new Date(end.getFullYear(), 11, 31);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
break;
|
||||
}
|
||||
console.log('Range is ' + viewRange);
|
||||
console.log('Start is ' + start);
|
||||
console.log('End is ' + end);
|
||||
context.commit('setStart', start);
|
||||
context.commit('setEnd', end);
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setStart(state, value) {
|
||||
state.start = value;
|
||||
},
|
||||
setEnd(state, value) {
|
||||
state.end = value;
|
||||
},
|
||||
setViewRange(state, range) {
|
||||
state.viewRange = range;
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
@@ -380,8 +380,8 @@ export default {
|
||||
groupTitleErrors: [],
|
||||
|
||||
// group ID + title once submitted:
|
||||
groupId: 0,
|
||||
groupTitle: '',
|
||||
returnedGroupId: 0,
|
||||
returnedGroupTitle: '',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -468,7 +468,7 @@ export default {
|
||||
// console.log('finalizeSubmit (' + this.submittedTransaction + ', ' + this.submittedAttachments + ', ' + this.submittedLinks + ')');
|
||||
if (this.submittedTransaction && this.submittedAttachments && this.submittedLinks) {
|
||||
if (false === this.createAnother && false === this.inError) {
|
||||
window.location.href = (window.previousURL ?? '/') + '?transaction_group_id=' + this.groupId + '&message=created';
|
||||
window.location.href = (window.previousURL ?? '/') + '?transaction_group_id=' + this.returnedGroupId + '&message=created';
|
||||
return;
|
||||
}
|
||||
// enable flags:
|
||||
@@ -480,7 +480,7 @@ export default {
|
||||
|
||||
// show message:
|
||||
this.errorMessage = '';
|
||||
this.successMessage = this.$t('firefly.transaction_stored_link', {ID: this.groupId, title: this.groupTitle});
|
||||
this.successMessage = this.$t('firefly.transaction_stored_link', {ID: this.returnedGroupId, title: this.returnedGroupTitle});
|
||||
|
||||
// reset attachments (always do this)
|
||||
for (let i in this.transactions) {
|
||||
@@ -528,8 +528,8 @@ export default {
|
||||
this.submitAttachments(data, response);
|
||||
|
||||
// meanwhile, store the ID and the title in some easy to access variables.
|
||||
this.groupId = parseInt(response.data.data.id);
|
||||
this.groupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;
|
||||
this.returnedGroupId = parseInt(response.data.data.id);
|
||||
this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;
|
||||
// console.log('Group title is now "' + this.groupTitle + '"');
|
||||
})
|
||||
.catch(error => {
|
||||
|
2
frontend/src/pages/dashboard.js
vendored
2
frontend/src/pages/dashboard.js
vendored
@@ -78,9 +78,9 @@ new Vue({
|
||||
beforeCreate() {
|
||||
this.$store.commit('initialiseStore');
|
||||
this.$store.dispatch('updateCurrencyPreference');
|
||||
this.$store.dispatch('dashboard/index/initialiseStore');
|
||||
},
|
||||
});
|
||||
|
||||
new Vue({
|
||||
i18n,
|
||||
store,
|
||||
|
Reference in New Issue
Block a user