2018-11-30 17:36:30 +00:00
|
|
|
import { readFile } from 'fs'
|
|
|
|
import path from 'path'
|
|
|
|
import yaml from 'js-yaml'
|
|
|
|
|
2018-11-30 10:53:50 +00:00
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
2018-11-30 17:36:30 +00:00
|
|
|
data_dir: '/home/lafrite/scripts/comptes/data/',
|
2018-11-30 21:07:08 +00:00
|
|
|
config_dir: '/home/lafrite/scripts/comptes/config/',
|
2018-12-02 17:02:44 +00:00
|
|
|
config_filename: 'config.yml',
|
2018-11-30 17:36:30 +00:00
|
|
|
postes: {}
|
2018-11-30 10:53:50 +00:00
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
data_dir: (state) => {
|
|
|
|
return state.data_dir
|
2018-11-30 17:36:30 +00:00
|
|
|
},
|
2018-11-30 21:07:08 +00:00
|
|
|
config_dir: (state) => {
|
|
|
|
return state.config_dir
|
|
|
|
},
|
2018-12-02 17:02:44 +00:00
|
|
|
config_filename: (state) => {
|
|
|
|
return state.config_filename
|
2018-11-30 17:36:30 +00:00
|
|
|
},
|
|
|
|
postes: (state) => {
|
|
|
|
return state.postes
|
2018-11-30 10:53:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mutations: {
|
2018-11-30 17:36:30 +00:00
|
|
|
SET_POSTES: (state, { postes }) => {
|
|
|
|
state.postes = postes
|
|
|
|
}
|
2018-11-30 10:53:50 +00:00
|
|
|
},
|
|
|
|
actions: {
|
2018-12-02 17:02:44 +00:00
|
|
|
load(context) {
|
|
|
|
readFile(path.join(context.getters.config_dir, context.getters.config_filename), 'utf8', (err, content) => {
|
2018-11-30 17:36:30 +00:00
|
|
|
if (err) {
|
|
|
|
console.log(err)
|
|
|
|
} else {
|
|
|
|
var parseConfig = {
|
|
|
|
header: true
|
|
|
|
}
|
|
|
|
var parsed = yaml.safeLoad(content, parseConfig)
|
|
|
|
context.commit('SET_POSTES', { postes: parsed.postes })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-11-30 10:53:50 +00:00
|
|
|
}
|
|
|
|
}
|