From 68653aaabecbe112567470747d8186d1ba0a087a Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 30 Jan 2019 16:03:20 +0100 Subject: [PATCH] Feat(data): Compute tags instead of read again csv --- src/store/modules/config.js | 3 ++- src/store/modules/datas.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/store/modules/config.js b/src/store/modules/config.js index ba85677..dfd4d33 100644 --- a/src/store/modules/config.js +++ b/src/store/modules/config.js @@ -74,13 +74,14 @@ export default { // save config file var config = { categories: context.state.categories, - tags: context.state.tags, + tags: context.state.tags } var yamlConfig = yaml.safeDump(config) writeFile(path.join(context.getters.config_dir, context.getters.config_filename), yamlConfig, (err) => { if (err) throw err console.log('The file has been saved!') }) + context.dispatch('datas/compute_tags', null, { root: true }) }, edit_tag (context, tag) { // Edit or append a tag to config diff --git a/src/store/modules/datas.js b/src/store/modules/datas.js index b53ad64..976814b 100644 --- a/src/store/modules/datas.js +++ b/src/store/modules/datas.js @@ -192,6 +192,19 @@ export default { { filename: filename, data: parsed } ) }, + compute_tags (context) { + var tags = Object.values(context.rootGetters['config/tags']) + var categories = Object.values(context.rootGetters['config/categories']) + Object.values(context.state.csv).forEach(csv => { + csv.data.forEach(row => { + appendKeywordField(row, 'tags', tags, 'Libellé') + appendKeywordField(row, 'categorie', categories, 'Libellé') + }) + context.commit('SET_DATA', + { filename: csv.filename, data: csv } + ) + }) + }, next_month (context) { var next = moment(context.getters.month).add(1, 'months') context.commit('SET_MONTH', { month: next })