Feat: improve month selector
This commit is contained in:
parent
7f9cecf06d
commit
7b742d599a
@ -14,6 +14,7 @@
|
|||||||
"main": "background.js",
|
"main": "background.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
|
"date-fns": "^2.23.0",
|
||||||
"vue": "^3.0.0",
|
"vue": "^3.0.0",
|
||||||
"vue-router": "^4.0.8",
|
"vue-router": "^4.0.8",
|
||||||
"vuex": "^4.0.2"
|
"vuex": "^4.0.2"
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
Période
|
<h2>Période</h2>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
<input type="month" v-model="range.start">
|
<input type="month" v-model="range.start">
|
||||||
<input type="month" v-model="range.end">
|
<input type="month" v-model="range.end">
|
||||||
</li>
|
</li>
|
||||||
<li @click="setRange6months">6 mois</li>
|
<li>
|
||||||
<li @click="setRange1year">1 an</li>
|
<button @click="setRange6months" :active='selected=="month"'>6 mois</button>
|
||||||
<li @click="setRangeAll">Tout</li>
|
<button @click="setRange1year" :active='selected=="year"'>1 an</button>
|
||||||
|
<button @click="setRangeAll" :active='selected=="all"'>Tout</button>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
@ -19,13 +23,14 @@ import { addMonths, format, parseISO } from 'date-fns'
|
|||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MonthSelector',
|
name: 'MonthSelector',
|
||||||
components: {
|
components: {
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {}
|
return {
|
||||||
|
selected: "",
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters('travail', {
|
...mapGetters('travail', {
|
||||||
@ -43,6 +48,7 @@ export default {
|
|||||||
start: format(start, 'yyyy-MM'),
|
start: format(start, 'yyyy-MM'),
|
||||||
end: format(today, 'yyyy-MM'),
|
end: format(today, 'yyyy-MM'),
|
||||||
}
|
}
|
||||||
|
this.selected = "month"
|
||||||
this.setRange(range)
|
this.setRange(range)
|
||||||
},
|
},
|
||||||
setRange1year: function () {
|
setRange1year: function () {
|
||||||
@ -51,6 +57,7 @@ export default {
|
|||||||
start: format(start, 'yyyy-MM'),
|
start: format(start, 'yyyy-MM'),
|
||||||
end: format(today, 'yyyy-MM'),
|
end: format(today, 'yyyy-MM'),
|
||||||
}
|
}
|
||||||
|
this.selected = "year"
|
||||||
this.setRange(range)
|
this.setRange(range)
|
||||||
},
|
},
|
||||||
setRangeAll: function () {
|
setRangeAll: function () {
|
||||||
@ -61,6 +68,7 @@ export default {
|
|||||||
start: format(start, 'yyyy-MM'),
|
start: format(start, 'yyyy-MM'),
|
||||||
end: format(end, 'yyyy-MM'),
|
end: format(end, 'yyyy-MM'),
|
||||||
}
|
}
|
||||||
|
this.selected = "all"
|
||||||
this.setRange(range)
|
this.setRange(range)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -69,6 +77,39 @@ export default {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
ul {
|
ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column wrap;
|
||||||
|
}
|
||||||
|
ul > * {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
list-style-type: none;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row;
|
||||||
|
justify-content: space-around;
|
||||||
|
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
padding: 15px 32px;
|
||||||
|
text-align: center;
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
flex-basis: 33%;
|
||||||
|
height: 3rem;
|
||||||
|
background-color: white;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
@ -60,14 +60,23 @@ const travail = {
|
|||||||
remumeration: 2800, // rémunération décidée
|
remumeration: 2800, // rémunération décidée
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
range: {
|
||||||
|
start: "2021-01",
|
||||||
|
end: "2021-08",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
Count (state) {return state.months.length},
|
Count (state) {return state.months.length},
|
||||||
TheEmptyMonth (state) {return {...state.empty}},
|
TheEmptyMonth (state) {return {...state.empty}},
|
||||||
|
Range (state) {return state.range},
|
||||||
MonthsDate (state) {
|
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 Object.keys(state.months).sort().reverse()
|
||||||
//return state.months.sort((a, b) => new Date(b.date) - new Date(a.date))
|
|
||||||
},
|
},
|
||||||
getMonth: (state) => (date) => {
|
getMonth: (state) => (date) => {
|
||||||
return state.months[date]
|
return state.months[date]
|
||||||
@ -80,9 +89,14 @@ const travail = {
|
|||||||
createMonth (state, {date, month}) {
|
createMonth (state, {date, month}) {
|
||||||
state.months[date] = month
|
state.months[date] = month
|
||||||
},
|
},
|
||||||
|
setRange (state, range) {
|
||||||
|
state.range = range
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
updateMonth (context, {date, month}) {
|
updateMonth (context, {date, month}) {
|
||||||
|
// update month's datas
|
||||||
if (date in context.state.months) {
|
if (date in context.state.months) {
|
||||||
context.commit('updateMonth', {date, month})
|
context.commit('updateMonth', {date, month})
|
||||||
} else {
|
} else {
|
||||||
@ -90,6 +104,7 @@ const travail = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
createMonth (context, {date, month}) {
|
createMonth (context, {date, month}) {
|
||||||
|
// Create a new month
|
||||||
if (!(date in context.state.months)) {
|
if (!(date in context.state.months)) {
|
||||||
console.log(date)
|
console.log(date)
|
||||||
context.commit('createMonth', {date, month})
|
context.commit('createMonth', {date, month})
|
||||||
@ -98,6 +113,10 @@ const travail = {
|
|||||||
console.log("This month already exists")
|
console.log("This month already exists")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setRange (context, range) {
|
||||||
|
context.commit("setRange", range)
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,14 +6,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
border: none;
|
border: none;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 15px 32px;
|
padding: 15px 32px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
color: black;
|
||||||
}
|
}
|
||||||
.validate {
|
.validate {
|
||||||
background-color: green;
|
background-color: green;
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<h1>Home</h1>
|
<h1>Home</h1>
|
||||||
<section id="selector">
|
<section id="selector">
|
||||||
|
<month-selector>
|
||||||
|
</month-selector>
|
||||||
</section>
|
</section>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<section id="months">
|
<section id="months">
|
||||||
@ -21,18 +22,20 @@
|
|||||||
import { mapGetters, mapActions } from 'vuex'
|
import { mapGetters, mapActions } from 'vuex'
|
||||||
import MonthsList from '../components/MonthsUl.vue'
|
import MonthsList from '../components/MonthsUl.vue'
|
||||||
import CreateMonth from '../components/CreateMonth.vue'
|
import CreateMonth from '../components/CreateMonth.vue'
|
||||||
|
import MonthSelector from '../components/monthSelector.vue'
|
||||||
export default {
|
export default {
|
||||||
name: 'home',
|
name: 'home',
|
||||||
components: {
|
components: {
|
||||||
MonthsList: MonthsList,
|
MonthsList: MonthsList,
|
||||||
CreateMonth: CreateMonth,
|
CreateMonth: CreateMonth,
|
||||||
|
MonthSelector: MonthSelector,
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
state: "datas/count",
|
count: "datas/count",
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -3450,6 +3450,11 @@ dashdash@^1.12.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
assert-plus "^1.0.0"
|
assert-plus "^1.0.0"
|
||||||
|
|
||||||
|
date-fns@^2.23.0:
|
||||||
|
version "2.23.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.23.0.tgz#4e886c941659af0cf7b30fafdd1eaa37e88788a9"
|
||||||
|
integrity sha512-5ycpauovVyAk0kXNZz6ZoB9AYMZB4DObse7P3BPWmyEjXNORTI8EJ6X0uaSAq4sCHzM1uajzrkr6HnsLQpxGXA==
|
||||||
|
|
||||||
debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
|
debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
|
||||||
version "2.6.9"
|
version "2.6.9"
|
||||||
resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz"
|
resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz"
|
||||||
|
Loading…
Reference in New Issue
Block a user