BeeBot/templates/filters.html

128 lines
3.9 KiB
HTML
Raw Permalink Normal View History

2021-10-05 22:52:59 +00:00
<!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 === 'Filters'">{{ 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-col cols="5">
<b-input placeholder="Key..." v-model="newfilters.name"></b-input>
</b-col>
<b-col cols="5">
<b-input placeholder="Value..." v-model="newfilters.regex"></b-input>
</b-col>
</b-row>
<b-row>
<b-col cols="10">
<b-input placeholder="Template..." v-model="newfilters.template"></b-input>
</b-col>
</b-row>
<b-row>
<b-col cols="2">
<b-button type="submit">Add</b-button>
</b-col>
</b-row>
</b-container>
</b-form>
<b-table
:items="filters"
: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: [],
filters: [],
newfilters: {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/filters')
.catch(err => console.log(err))
.then(resp => {
this.filters = resp.data
})
},
add: function(evt) {
if (evt) {
evt.preventDefault();
evt.stopPropagation();
}
axios.post('/api/v1/filters', this.newfilters)
.catch(err => console.log(err))
.then(resp => {
this.newfilters = {}
this.refresh()
})
},
rm: function(key) {
axios.delete('/api/v1/filters', {data: {key: key}})
.catch(err => console.log(err))
.then(resp => {
this.newfilters = {}
this.refresh()
})
}
}
})
</script>
</body>
</html>