comptes/src/store/modules/config.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

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/',
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
},
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: {
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
}
}