BeeBot/templates/config.html

123 lines
3.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<!-- Load required Bootstrap and BootstrapVue CSS -->
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
<!-- Load polyfills to support older browsers -->
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
<!-- Load Vue followed by BootstrapVue -->
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
<script src="https://unpkg.com/vue-router"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<meta charset="UTF-8">
<title>Memes</title>
</head>
<body>
<div id="app">
<b-navbar>
<b-navbar-brand>BeeBot</b-navbar-brand>
<b-navbar-nav>
<b-nav-item v-for="(url, name) in nav" :href="url" :active="name === 'Config'">{{ name }}</b-nav-item>
</b-navbar-nav>
</b-navbar>
<b-alert
dismissable
variant="error"
v-if="err"
@dismissed="err = ''">
{{ err }}
</b-alert>
<b-form @submit="add">
<b-container>
<b-row>
<b>Note:</b> Environmental configuration values will not be displayed in this list. Unset configuration options appear in the logs.
</b-row>
<b-row>
<b-col cols="5">
<b-input placeholder="Key..." v-model="newConfig.key"></b-input>
</b-col>
<b-col cols="5">
<b-input placeholder="Value..." v-model="newConfig.value"></b-input>
</b-col>
<b-col cols="2">
<b-button type="submit">Add</b-button>
</b-col>
</b-row>
</b-container>
</b-form>
<b-table
:items="config"
:fields="fields">
<template v-slot:cell(rm)="data">
<b-button @click="rm(data.item.key)">X</b-button>
</template>
</table>
</div>
<script>
var router = new VueRouter({
mode: 'history',
routes: [],
});
var app = new Vue({
el: '#app',
router,
data: {
err: '',
nav: [],
config: [],
newConfig: {key: '', value: ''},
fields: [
{key: 'key'},
{key: 'value'},
{key: 'rm', sortable: false}
],
},
mounted() {
axios.get('/api/v1/nav')
.catch(err => this.err = err)
.then(resp => {
this.nav = resp.data;
})
this.refresh()
},
methods: {
refresh: function() {
axios.get('/api/v1/config')
.catch(err => console.log(err))
.then(resp => {
this.config = resp.data
})
},
add: function(evt) {
if (evt) {
evt.preventDefault();
evt.stopPropagation();
}
axios.post('/api/v1/config', this.newConfig)
.catch(err => console.log(err))
.then(resp => {
this.newConfig = {}
this.refresh()
})
},
rm: function(key) {
axios.delete('/api/v1/config/', {data: {key: key}})
.catch(err => console.log(err))
.then(resp => {
this.newConfig = {}
this.refresh()
})
}
}
})
</script>
</body>
</html>