Feat(Store): Start store and read csv
This commit is contained in:
11
src/store/index.js
Normal file
11
src/store/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import configModule from './modules/config'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
config: configModule
|
||||
}
|
||||
})
|
||||
53
src/store/modules/<
Normal file
53
src/store/modules/<
Normal file
@@ -0,0 +1,53 @@
|
||||
import { readdir, readFile } from 'fs'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
data_dir: '/home/lafrite/scripts/comptes/data/',
|
||||
csv_files: [],
|
||||
data: []
|
||||
},
|
||||
getters: {
|
||||
data_dir: (state) => {
|
||||
return state.data_dir
|
||||
},
|
||||
csvs: (state) => {
|
||||
return state.csv_files
|
||||
},
|
||||
data: (state) => {
|
||||
return state.data
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
APPEND_DATA: (state, { data }) => {
|
||||
state.data.push(data)
|
||||
},
|
||||
SET_CSV_FILES: (state, { csvs }) => {
|
||||
state.csv_files = csvs
|
||||
}
|
||||
|
||||
},
|
||||
actions: {
|
||||
async find_csv (context) {
|
||||
readdir(context.getters.data_dir, (err, list) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
var csvs = list.filter(x => {
|
||||
return x.split('.').pop() == 'csv'
|
||||
})
|
||||
context.commit('SET_CSV_FILES', { csvs })
|
||||
}
|
||||
})
|
||||
},
|
||||
async load_csv (context, csv) {
|
||||
readFile(path.join(context.getters.data_dir, csv) , (err, content) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
context.commit('APPEND_DATA', { content })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
57
src/store/modules/config.js
Normal file
57
src/store/modules/config.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { readdir, readFile } from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
data_dir: '/home/lafrite/scripts/comptes/data/',
|
||||
csv_files: [],
|
||||
datas: []
|
||||
},
|
||||
getters: {
|
||||
data_dir: (state) => {
|
||||
return state.data_dir
|
||||
},
|
||||
csvs: (state) => {
|
||||
return state.csv_files
|
||||
},
|
||||
datas: (state) => {
|
||||
return state.datas
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
APPEND_DATA: (state, { content }) => {
|
||||
state.datas.push(content)
|
||||
},
|
||||
SET_CSV_FILES: (state, { csvs }) => {
|
||||
state.csv_files = csvs
|
||||
}
|
||||
|
||||
},
|
||||
actions: {
|
||||
async find_csv (context) {
|
||||
readdir(context.getters.data_dir, (err, list) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
var csvs = list.filter(x => {
|
||||
return x.split('.').pop() === 'csv'
|
||||
})
|
||||
for (var i in csvs) {
|
||||
context.dispatch('load_csv', csvs[i])
|
||||
}
|
||||
context.commit('SET_CSV_FILES', { csvs })
|
||||
}
|
||||
})
|
||||
},
|
||||
async load_csv (context, csv) {
|
||||
readFile(path.join(context.getters.data_dir, csv), 'utf8', (err, content) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
context.commit('APPEND_DATA', { content })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user