From 7b742d599a0ee25647aafc8a1157d37f6e5793ca Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Tue, 3 Aug 2021 16:57:16 +0200 Subject: [PATCH] Feat: improve month selector --- package.json | 1 + src/components/monthSelector.vue | 53 ++++++++++++++++++++++++++++---- src/store/travail/index.js | 21 ++++++++++++- src/style.css | 17 +++++----- src/views/home.vue | 7 +++-- yarn.lock | 5 +++ 6 files changed, 87 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index f90712e..7b1fb57 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "main": "background.js", "dependencies": { "core-js": "^3.6.5", + "date-fns": "^2.23.0", "vue": "^3.0.0", "vue-router": "^4.0.8", "vuex": "^4.0.2" diff --git a/src/components/monthSelector.vue b/src/components/monthSelector.vue index 20c472e..ccd3feb 100644 --- a/src/components/monthSelector.vue +++ b/src/components/monthSelector.vue @@ -1,13 +1,17 @@ @@ -19,13 +23,14 @@ import { addMonths, format, parseISO } from 'date-fns' const today = new Date(); - export default { name: 'MonthSelector', components: { }, data () { - return {} + return { + selected: "", + } }, computed: { ...mapGetters('travail', { @@ -43,6 +48,7 @@ export default { start: format(start, 'yyyy-MM'), end: format(today, 'yyyy-MM'), } + this.selected = "month" this.setRange(range) }, setRange1year: function () { @@ -51,6 +57,7 @@ export default { start: format(start, 'yyyy-MM'), end: format(today, 'yyyy-MM'), } + this.selected = "year" this.setRange(range) }, setRangeAll: function () { @@ -61,6 +68,7 @@ export default { start: format(start, 'yyyy-MM'), end: format(end, 'yyyy-MM'), } + this.selected = "all" this.setRange(range) }, }, @@ -69,6 +77,39 @@ export default { diff --git a/src/store/travail/index.js b/src/store/travail/index.js index 2b9d413..aef9565 100644 --- a/src/store/travail/index.js +++ b/src/store/travail/index.js @@ -60,14 +60,23 @@ const travail = { remumeration: 2800, // rémunération décidée }, }, + range: { + start: "2021-01", + end: "2021-08", + }, } }, getters: { Count (state) {return state.months.length}, TheEmptyMonth (state) {return {...state.empty}}, + Range (state) {return state.range}, MonthsDate (state) { + // Get months inside the range + return Object.keys(state.months).filter(date => (date >= state.range.start)&&(date <= state.range.end) ).sort().reverse() + }, + MonthsAllDate (state) { + // Get all the months return Object.keys(state.months).sort().reverse() - //return state.months.sort((a, b) => new Date(b.date) - new Date(a.date)) }, getMonth: (state) => (date) => { return state.months[date] @@ -80,9 +89,14 @@ const travail = { createMonth (state, {date, month}) { state.months[date] = month }, + setRange (state, range) { + state.range = range + }, + }, actions: { updateMonth (context, {date, month}) { + // update month's datas if (date in context.state.months) { context.commit('updateMonth', {date, month}) } else { @@ -90,6 +104,7 @@ const travail = { } }, createMonth (context, {date, month}) { + // Create a new month if (!(date in context.state.months)) { console.log(date) context.commit('createMonth', {date, month}) @@ -98,6 +113,10 @@ const travail = { console.log("This month already exists") } }, + setRange (context, range) { + context.commit("setRange", range) + }, + }, } diff --git a/src/style.css b/src/style.css index 18295a6..67bb90f 100644 --- a/src/style.css +++ b/src/style.css @@ -6,14 +6,15 @@ } button { - border: none; - color: white; - padding: 15px 32px; - text-align: center; - display: inline-block; - width: 100%; - font-size: 16px; - border-radius: 5px; + border: none; + color: white; + padding: 15px 32px; + text-align: center; + display: inline-block; + width: 100%; + font-size: 16px; + border-radius: 5px; + color: black; } .validate { background-color: green; diff --git a/src/views/home.vue b/src/views/home.vue index 0b78f8f..29d620a 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -1,7 +1,8 @@