From f5bbf195f3faf8e99dc256c84bb3ed1ae4aff16d Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Mon, 28 Jan 2019 12:34:23 +0100 Subject: [PATCH] Feat(tag): Can modify tags and save it into config.yml --- config/config.yml | 30 ++++++++++-------------------- src/store/modules/config.js | 19 +++++++++++++++++-- src/views/config.vue | 33 ++++++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/config/config.yml b/config/config.yml index 5e405a2..90469f4 100644 --- a/config/config.yml +++ b/config/config.yml @@ -1,4 +1,3 @@ ---- categories: tout: name: Tout @@ -6,7 +5,6 @@ categories: icon: file-invoice-dollar color: '#78e08f' words: [] - cash: name: Cash variant: info @@ -14,25 +12,22 @@ categories: color: '#78e08f' words: - RETRAIT - - CB: + cb: name: CB variant: info icon: credit-card - color: "#4a69bd" + color: '#4a69bd' words: - PAIEMENT - virements: name: Virements variant: info icon: directions invert: true - color: "#f6b93b" + color: '#f6b93b' words: - PAIEMENT - RETRAIT - tags: cash: name: Cash @@ -41,31 +36,28 @@ tags: color: '#78e08f' words: - RETRAIT - virements: name: Virements variant: info icon: directions invert: true - color: "#f6b93b" + color: '#f6b93b' words: - PAIEMENT - RETRAIT - autoroute: name: Autoroute variant: danger icon: road - color: "#eb2f06" + color: '#eb2f06' words: - AUTOROUTE - APRR - - essence: + essence: name: Essence variant: danger icon: charging-station - color: "#0c2461" + color: '#0c2461' words: - CARBU - TOTAL @@ -75,20 +67,18 @@ tags: - ESSO - BELLEGARDE SU CARREFOUR - ST CLAUDE CASINOCARB - train: name: train variant: danger icon: train - color: "#eb2f06" + color: '#eb2f06' words: - SNCF - - courses: + courses: name: Courses variant: warning icon: shopping-cart - color: "#665191" + color: '#665191' words: - BIOCOOP - LA VIE CLAIRE diff --git a/src/store/modules/config.js b/src/store/modules/config.js index 94298db..4a83cd6 100644 --- a/src/store/modules/config.js +++ b/src/store/modules/config.js @@ -1,4 +1,4 @@ -import { readFile } from 'fs' +import { readFile, writeFile } from 'fs' import Vue from 'vue' import path from 'path' import yaml from 'js-yaml' @@ -50,6 +50,7 @@ export default { }, actions: { load (context) { + // load config file readFile(path.join(context.getters.config_dir, context.getters.config_filename), 'utf8', (err, content) => { if (err) { console.log(err) @@ -63,8 +64,22 @@ export default { } }) }, + save (context) { + // save config file + var config = { + categories: context.state.categories, + 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!') + }) + + }, edit_tag (context, tag) { context.commit('APPEND_TAG', { tag: tag }) - } + context.dispatch('save') + }, } } diff --git a/src/views/config.vue b/src/views/config.vue index 23f5897..d3d6679 100644 --- a/src/views/config.vue +++ b/src/views/config.vue @@ -2,12 +2,14 @@

Fichiers CSV - - -

- Les fichiers csv sont cherché dans {{ data_dir }} + + Recharger + +

+

+ Les fichiers csv sont cherchés dans {{ data_dir }} @@ -24,13 +26,24 @@

-

Tags

+

+ Config +

+

+ + Recharger + +

+ Le fichier configuration se trouve à {{ config_dir + config_filename}} +

+

+

Tags

-

Categories

+

Categories

@@ -60,6 +73,8 @@ export default { computed: { ...mapGetters({ 'data_dir': 'config/data_dir', + 'config_dir': 'config/config_dir', + 'config_filename': 'config/config_filename', 'csvs': 'datas/csvs', 'tags': 'config/tags', 'categories': 'config/categories' @@ -69,6 +84,10 @@ export default { ...mapActions('datas', { 'reload_csvs': 'load_csvs' }), + ...mapActions('config', { + 'reload_config': 'load', + 'save_config': 'save' + }), open_filebrowser (dir) { console.log("plop") } @@ -77,7 +96,7 @@ export default {