filebrowser/assets/src/components/GlobalSettings.vue
Henrique Dias 7abb3c7df2 Commands on settings
Former-commit-id: 796b8028e5a4cad7b898d05f8ae8dc5eaffe388d [formerly 287049a1fc824af552e73474769355bd9458df60] [formerly b34c228a89e28f55f87bcbbfefa066bf658fc03b [formerly 940505edec]]
Former-commit-id: bda53abd867dac3368108ef7ac966d4f8a3cbc20 [formerly 2beb3f01ed39c031059c00208d36f438abbf4f2c]
Former-commit-id: 3183968b8a27dd568655875cec9aff69a0d1d0a1
2017-07-08 20:27:26 +01:00

71 lines
1.9 KiB
Vue

<template>
<div class="dashboard">
<h1>Global Settings</h1>
<ul>
<li><router-link v-if="user.admin" to="/users">Go to User Management</router-link></li>
</ul>
<form @submit="saveCommands">
<h2>Commands</h2>
<p class="small">Here you can set commands that are executed in the named events. You write one command
per line. If the event is related to files, such as before and after saving, the environment variable
<code>file</code> will be available with the path of the file.</p>
<h3>Before Save</h3>
<textarea v-model.trim="beforeSave"></textarea>
<h3>After Save</h3>
<textarea v-model.trim="afterSave"></textarea>
<p><input type="submit" value="Save"></p>
</form>
</div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'
import api from '@/utils/api'
export default {
name: 'settings',
data: function () {
return {
beforeSave: '',
afterSave: ''
}
},
computed: {
...mapState([ 'user' ])
},
created () {
api.getCommands()
.then(commands => {
this.beforeSave = commands['before_save'].join('\n')
this.afterSave = commands['after_save'].join('\n')
})
.catch(error => { this.showError(error) })
},
methods: {
...mapMutations([ 'showSuccess', 'showError' ]),
saveCommands (event) {
event.preventDefault()
let commands = {
'before_save': this.beforeSave.split('\n'),
'after_save': this.afterSave.split('\n')
}
if (commands['before_save'].length === 1 && commands['before_save'][0] === '') commands['before_save'] = []
if (commands['after_save'].length === 1 && commands['after_save'][0] === '') commands['after_save'] = []
api.updateCommands(commands)
.then(() => { this.showSuccess('Commands updated!') })
.catch(error => { this.showError(error) })
}
}
}
</script>