Created
March 10, 2021 17:02
-
-
Save Fanna1119/a8c851eb3c098f20113fa16a3b47ebd9 to your computer and use it in GitHub Desktop.
vuex3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
import Vuex from 'vuex'; | |
import createPersistedState from "vuex-persistedstate"; | |
Vue.use(Vuex); | |
export const store = new Vuex.Store({ | |
plugins: [createPersistedState()], | |
state: { | |
scrums: [], | |
activescrum: '', | |
timer: { | |
isopen: false, | |
estimate_complete_time: null, | |
activetimerId: null, | |
currenttodoname: '', | |
belongsto: '' | |
} | |
}, | |
getters: { | |
scrumHasData: (state) => state.scrums.length > 0, | |
scrumNames: (state) => state.scrums.map(o => { | |
return { name: o.name, id: o.id } | |
}), | |
currentScrumData: (state) => state.scrums.find(x => x.id === state.activescrum), | |
isdueDate: (state, getters) => { | |
return Date.parse(new Date().toISOString().substr(0, 10)) >= Date.parse(getters.currentScrumData.duedate) | |
}, | |
timeToComplete(state, getter) { | |
function toseconds(hhmm) { | |
var a = hhmm.split(':'); | |
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60; | |
return seconds | |
} | |
const arrSum = arr => arr.reduce((a, b) => a + b, 0) | |
const tod = getter.currentScrumData.scrum.todo.map(x => toseconds(x.estcomplete)); | |
const prog = getter.currentScrumData.scrum.inprogress.map(x => toseconds(x.estcomplete)); | |
return new Date(arrSum([...tod, ...prog]) * 1000).toISOString().substr(11, 8) | |
}, | |
todoById: (state, getters) => (payload) => { | |
return getters.currentScrumData.scrum[payload.list].find(todo => todo.id === payload.id) | |
}, | |
}, | |
mutations: { | |
updateScrum(state, payload) { | |
state.scrums.push(payload); | |
}, | |
selectedScrum(state, payload) { | |
state.activescrum = payload; | |
}, | |
pushTodo(state, payload) { | |
state.scrums.find(x => x.id === state.activescrum).scrum.todo.push(payload); | |
// change to action | |
}, | |
deleteTodo(state, payload) { | |
// takes payload.list and payload.id | |
const index = state.scrums.find(x => x.id === state.activescrum).scrum[payload.list].findIndex(x => x.id === payload.id); | |
state.scrums.find(x => x.id === state.activescrum).scrum[payload.list].splice(index, 1); | |
}, | |
pushToDone(state, payload) { | |
state.scrums.find(x => x.id === state.activescrum).scrum.done.push(payload); | |
// change to action | |
}, | |
scrumDragChange(state, payload) { | |
state.scrums.find(x => x.id === state.activescrum).scrum[payload.list] = payload.neworder | |
}, | |
triggerTimer(state) { | |
state.timer.isopen = !state.timer.isopen; | |
}, | |
setTimerVals(state, payload) { | |
state.timer.estimate_complete_time = payload.est; | |
state.timer.activetimerId = payload.id; | |
state.timer.currenttodoname = payload.name; | |
state.timer.belongsto = payload.list; | |
}, | |
saveEditor(state, payload) { | |
state.scrums.find(x => x.id === state.activescrum).scrum.backlog = payload | |
} | |
}, | |
actions: { | |
openTimer({ commit }, payload) { | |
commit('triggerTimer'); | |
commit('setTimerVals', payload) | |
}, | |
closeTimer({ commit, state, getters }, payload) { | |
// set timer vals to null | |
// and push time took to complete to current todo | |
// then push timer to | |
const currentTodo = getters.todoById({ id: payload.currenttodo, list: state.timer.belongsto }); | |
currentTodo['belongsto'] = "done"; | |
currentTodo['finaltime'] = payload.finaltime; | |
commit('pushToDone', currentTodo) | |
commit('triggerTimer'); | |
commit('deleteTodo', { id: payload.currenttodo, list: state.timer.belongsto }) | |
commit('setTimerVals', { | |
est: null, | |
id: null, | |
name: null, | |
list: null | |
}) | |
}, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment