Feat(tag): Can modify tags and save it into config.yml

This commit is contained in:
Bertrand Benjamin 2019-01-28 12:34:23 +01:00
parent 342b2efd1c
commit f5bbf195f3
3 changed files with 53 additions and 29 deletions

View File

@ -1,4 +1,3 @@
---
categories: categories:
tout: tout:
name: Tout name: Tout
@ -6,7 +5,6 @@ categories:
icon: file-invoice-dollar icon: file-invoice-dollar
color: '#78e08f' color: '#78e08f'
words: [] words: []
cash: cash:
name: Cash name: Cash
variant: info variant: info
@ -14,25 +12,22 @@ categories:
color: '#78e08f' color: '#78e08f'
words: words:
- RETRAIT - RETRAIT
cb:
CB:
name: CB name: CB
variant: info variant: info
icon: credit-card icon: credit-card
color: "#4a69bd" color: '#4a69bd'
words: words:
- PAIEMENT - PAIEMENT
virements: virements:
name: Virements name: Virements
variant: info variant: info
icon: directions icon: directions
invert: true invert: true
color: "#f6b93b" color: '#f6b93b'
words: words:
- PAIEMENT - PAIEMENT
- RETRAIT - RETRAIT
tags: tags:
cash: cash:
name: Cash name: Cash
@ -41,31 +36,28 @@ tags:
color: '#78e08f' color: '#78e08f'
words: words:
- RETRAIT - RETRAIT
virements: virements:
name: Virements name: Virements
variant: info variant: info
icon: directions icon: directions
invert: true invert: true
color: "#f6b93b" color: '#f6b93b'
words: words:
- PAIEMENT - PAIEMENT
- RETRAIT - RETRAIT
autoroute: autoroute:
name: Autoroute name: Autoroute
variant: danger variant: danger
icon: road icon: road
color: "#eb2f06" color: '#eb2f06'
words: words:
- AUTOROUTE - AUTOROUTE
- APRR - APRR
essence:
essence:
name: Essence name: Essence
variant: danger variant: danger
icon: charging-station icon: charging-station
color: "#0c2461" color: '#0c2461'
words: words:
- CARBU - CARBU
- TOTAL - TOTAL
@ -75,20 +67,18 @@ tags:
- ESSO - ESSO
- BELLEGARDE SU CARREFOUR - BELLEGARDE SU CARREFOUR
- ST CLAUDE CASINOCARB - ST CLAUDE CASINOCARB
train: train:
name: train name: train
variant: danger variant: danger
icon: train icon: train
color: "#eb2f06" color: '#eb2f06'
words: words:
- SNCF - SNCF
courses:
courses:
name: Courses name: Courses
variant: warning variant: warning
icon: shopping-cart icon: shopping-cart
color: "#665191" color: '#665191'
words: words:
- BIOCOOP - BIOCOOP
- LA VIE CLAIRE - LA VIE CLAIRE

View File

@ -1,4 +1,4 @@
import { readFile } from 'fs' import { readFile, writeFile } from 'fs'
import Vue from 'vue' import Vue from 'vue'
import path from 'path' import path from 'path'
import yaml from 'js-yaml' import yaml from 'js-yaml'
@ -50,6 +50,7 @@ export default {
}, },
actions: { actions: {
load (context) { load (context) {
// load config file
readFile(path.join(context.getters.config_dir, context.getters.config_filename), 'utf8', (err, content) => { readFile(path.join(context.getters.config_dir, context.getters.config_filename), 'utf8', (err, content) => {
if (err) { if (err) {
console.log(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) { edit_tag (context, tag) {
context.commit('APPEND_TAG', { tag: tag }) context.commit('APPEND_TAG', { tag: tag })
} context.dispatch('save')
},
} }
} }

View File

@ -2,12 +2,14 @@
<div class="tags"> <div class="tags">
<h1> <h1>
Fichiers CSV Fichiers CSV
<b-button @click="reload_csvs">
<font-awesome-icon icon="sync-alt" class="fa" />
</b-button>
</h1> </h1>
<p> <p>
Les fichiers csv sont cherché dans <span class="datadir">{{ data_dir }}</span> <b-button @click="reload_csvs" size="sm">
<font-awesome-icon icon="sync-alt" class="fa" /> Recharger
</b-button>
</p>
<p>
Les fichiers csv sont cherchés dans <span class="dir">{{ data_dir }}</span>
<!-- <!--
<b-button variant="link" @click="open_filebrowser(data_dir)"> Ouvrir <font-awesome-icon icon="folder-open" class="fa"/></b-button> <b-button variant="link" @click="open_filebrowser(data_dir)"> Ouvrir <font-awesome-icon icon="folder-open" class="fa"/></b-button>
--> -->
@ -24,13 +26,24 @@
</b-list-group-item> </b-list-group-item>
</b-list-group> </b-list-group>
</p> </p>
<h1>Tags</h1> <h1>
Config
</h1>
<p>
<b-button @click="reload_config" size="sm">
<font-awesome-icon icon="sync-alt" class="fa" /> Recharger
</b-button>
<p>
Le fichier configuration se trouve à <span class="dir">{{ config_dir + config_filename}}</span>
</p>
</p>
<h2>Tags</h2>
<b-list-group> <b-list-group>
<b-list-group-item v-for="tag in tags"> <b-list-group-item v-for="tag in tags">
<tag-item :tagname="tag.name"></tag-item> <tag-item :tagname="tag.name"></tag-item>
</b-list-group-item> </b-list-group-item>
</b-list-group> </b-list-group>
<h1>Categories</h1> <h2>Categories</h2>
<b-list-group> <b-list-group>
<b-list-group-item v-for="categorie in categories"> <b-list-group-item v-for="categorie in categories">
<categorie-item :categoriename="categorie.name"></categorie-item> <categorie-item :categoriename="categorie.name"></categorie-item>
@ -60,6 +73,8 @@ export default {
computed: { computed: {
...mapGetters({ ...mapGetters({
'data_dir': 'config/data_dir', 'data_dir': 'config/data_dir',
'config_dir': 'config/config_dir',
'config_filename': 'config/config_filename',
'csvs': 'datas/csvs', 'csvs': 'datas/csvs',
'tags': 'config/tags', 'tags': 'config/tags',
'categories': 'config/categories' 'categories': 'config/categories'
@ -69,6 +84,10 @@ export default {
...mapActions('datas', { ...mapActions('datas', {
'reload_csvs': 'load_csvs' 'reload_csvs': 'load_csvs'
}), }),
...mapActions('config', {
'reload_config': 'load',
'save_config': 'save'
}),
open_filebrowser (dir) { open_filebrowser (dir) {
console.log("plop") console.log("plop")
} }
@ -77,7 +96,7 @@ export default {
</script> </script>
<style scoped> <style scoped>
.datadir { .dir {
font-weight: bold; font-weight: bold;
} }
.left { .left {