44 lines
992 B
JavaScript
44 lines
992 B
JavaScript
import { readFile } from 'fs'
|
|
import path from 'path'
|
|
import yaml from 'js-yaml'
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
data_dir: '/home/lafrite/scripts/comptes/data/',
|
|
postes_filename: 'postes.yml',
|
|
postes: {}
|
|
},
|
|
getters: {
|
|
data_dir: (state) => {
|
|
return state.data_dir
|
|
},
|
|
postes_filename: (state) => {
|
|
return state.postes_filename
|
|
},
|
|
postes: (state) => {
|
|
return state.postes
|
|
}
|
|
},
|
|
mutations: {
|
|
SET_POSTES: (state, { postes }) => {
|
|
state.postes = postes
|
|
}
|
|
},
|
|
actions: {
|
|
async load_postes (context) {
|
|
readFile(path.join(context.getters.data_dir, context.getters.postes_filename), 'utf8', (err, content) => {
|
|
if (err) {
|
|
console.log(err)
|
|
} else {
|
|
var parseConfig = {
|
|
header: true
|
|
}
|
|
var parsed = yaml.safeLoad(content, parseConfig)
|
|
context.commit('SET_POSTES', { postes: parsed.postes })
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|