Former-commit-id: 5624723eeb939734902eeaa6c2f132c4beffa911 [formerly a83456d3eda5175e2941b2deeb58b5da323ff678] [formerly a6b3ac7942dbf48d7d9b3f8db5e5041a93143f19 [formerly 4d6b54c63ee21bd01854188b2ad82115948ff7fe]] Former-commit-id: d03621c16b2c892701d678361b6c0a7d5dbec620 [formerly d818b6751e035f283e1c8390d7993a33a459a7dd] Former-commit-id: 3539ee68532135467daa2cc175482769b1efb592
182 lines
4.7 KiB
Vue
182 lines
4.7 KiB
Vue
<template>
|
|
<div class="dashboard">
|
|
<form class="card" @submit.prevent="saveStaticGen">
|
|
<div class="card-title">
|
|
<h2>{{ capitalize($store.state.staticGen) }}</h2>
|
|
</div>
|
|
|
|
<div class="card-content">
|
|
<p v-for="field in staticGen" :key="field.variable">
|
|
<label v-if="field.type !== 'checkbox'">{{ field.name }}</label>
|
|
<input v-if="field.type === 'text'" type="text" v-model.trim="field.value">
|
|
<input v-else-if="field.type === 'checkbox'" type="checkbox" v-model.trim="field.value">
|
|
<template v-if="field.type === 'checkbox'">{{ capitalize(field.name, 'caps') }}</template>
|
|
</p>
|
|
</div>
|
|
|
|
<div class="card-action">
|
|
<input class="flat" type="submit" :value="$t('buttons.update')">
|
|
</div>
|
|
</form>
|
|
|
|
<form class="card" @submit.prevent="saveCSS">
|
|
<div class="card-title">
|
|
<h2>{{ $t('settings.customStylesheet') }}</h2>
|
|
</div>
|
|
|
|
<div class="card-content">
|
|
<textarea v-model="css"></textarea>
|
|
</div>
|
|
|
|
<div class="card-action">
|
|
<input class="flat" type="submit" :value="$t('buttons.update')">
|
|
</div>
|
|
</form>
|
|
|
|
<form class="card" @submit.prevent="saveCommands">
|
|
<div class="card-title">
|
|
<h2>{{ $t('settings.commands') }}</h2>
|
|
</div>
|
|
|
|
<div class="card-content">
|
|
<p class="small">{{ $t('settings.commandsHelp') }}</p>
|
|
<template v-for="command in commands">
|
|
<h3>{{ capitalize(command.name) }}</h3>
|
|
<textarea v-model.trim="command.value"></textarea>
|
|
</template>
|
|
</div>
|
|
|
|
<div class="card-action">
|
|
<input class="flat" type="submit" :value="$t('buttons.update')">
|
|
</div>
|
|
</form>
|
|
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapState } from 'vuex'
|
|
import { getSettings, updateSettings } from '@/utils/api'
|
|
|
|
export default {
|
|
name: 'settings',
|
|
data: function () {
|
|
return {
|
|
commands: [],
|
|
staticGen: [],
|
|
css: ''
|
|
}
|
|
},
|
|
computed: {
|
|
...mapState([ 'user' ])
|
|
},
|
|
created () {
|
|
getSettings()
|
|
.then(settings => {
|
|
if (this.$store.state.staticGen.length > 0) {
|
|
this.parseStaticGen(settings.staticGen)
|
|
}
|
|
|
|
for (let key in settings.commands) {
|
|
this.commands.push({
|
|
name: key,
|
|
value: settings.commands[key].join('\n')
|
|
})
|
|
}
|
|
|
|
this.css = settings.css
|
|
})
|
|
.catch(this.$showError)
|
|
},
|
|
methods: {
|
|
capitalize (name, where = '_') {
|
|
if (where === 'caps') where = /(?=[A-Z])/
|
|
let splitted = name.split(where)
|
|
name = ''
|
|
|
|
for (let i = 0; i < splitted.length; i++) {
|
|
name += splitted[i].charAt(0).toUpperCase() + splitted[i].slice(1) + ' '
|
|
}
|
|
|
|
return name.slice(0, -1)
|
|
},
|
|
saveCommands (event) {
|
|
let commands = {}
|
|
|
|
for (let command of this.commands) {
|
|
let value = command.value.split('\n')
|
|
if (value.length === 1 && value[0] === '') {
|
|
value = []
|
|
}
|
|
|
|
commands[command.name] = value
|
|
}
|
|
|
|
updateSettings(commands, 'commands')
|
|
.then(() => { this.$showSuccess(this.$t('settings.commandsUpdated')) })
|
|
.catch(this.$showError)
|
|
},
|
|
saveCSS (event) {
|
|
updateSettings(this.css, 'css')
|
|
.then(() => {
|
|
this.$showSuccess(this.$t('settings.settingsUpdated'))
|
|
let style = document.querySelector('style[title="global-css"]')
|
|
style.innerHTML = ''
|
|
style.appendChild(document.createTextNode(this.css))
|
|
})
|
|
.catch(this.$showError)
|
|
},
|
|
saveStaticGen (event) {
|
|
let staticGen = {}
|
|
|
|
for (let field of this.staticGen) {
|
|
staticGen[field.variable] = field.value
|
|
|
|
if (field.original === 'array') {
|
|
let val = field.value.split(' ')
|
|
if (val[0] === '') {
|
|
val.shift()
|
|
}
|
|
|
|
staticGen[field.variable] = val
|
|
}
|
|
}
|
|
|
|
updateSettings(staticGen, 'staticGen')
|
|
.then(() => { this.$showSuccess(this.$t('settings.settingsUpdated')) })
|
|
.catch(this.$showError)
|
|
},
|
|
parseStaticGen (staticgen) {
|
|
for (let option of staticgen) {
|
|
let value = option.value
|
|
|
|
let field = {
|
|
name: option.name,
|
|
variable: option.variable,
|
|
type: 'text',
|
|
original: 'text',
|
|
value: value
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
field.original = 'array'
|
|
field.value = value.join(' ')
|
|
|
|
this.staticGen.push(field)
|
|
continue
|
|
}
|
|
|
|
switch (typeof value) {
|
|
case 'boolean':
|
|
field.type = 'checkbox'
|
|
field.original = 'boolean'
|
|
break
|
|
}
|
|
|
|
this.staticGen.push(field)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|