catbase/plugins/counter/html.go

104 lines
3.5 KiB
Go
Raw Normal View History

2019-05-27 18:27:34 +00:00
package counter
var html = `
<html>
<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/axios/dist/axios.min.js"></script>
<title>Counters</title>
2019-05-27 18:27:34 +00:00
</head>
<body>
<div id="app">
<b-navbar>
<b-navbar-brand>Counters</b-navbar-brand>
<b-navbar-nav>
<b-nav-item v-for="item in nav" :href="item.URL" :active="item.Name === 'Counter'">{{ "{{ item.Name }}" }}</b-nav-item>
</b-navbar-nav>
</b-navbar>
2019-05-27 18:27:34 +00:00
<b-alert
dismissable
:show="err"
variant="error">
{{ "{{ err }}" }}
2019-05-27 18:27:34 +00:00
</b-alert>
<b-container>
<b-row>
<b-col cols="5">Password:</b-col>
2019-05-27 18:27:34 +00:00
<b-col><b-input v-model="answer"></b-col>
</b-row>
<b-row v-for="(counter, user) in counters">
{{ "{{ user }}" }}:
2019-05-27 18:27:34 +00:00
<b-container>
<b-row v-for="(count, thing) in counter">
<b-col offset="1">
{{ "{{ thing }}" }}:
2019-05-27 18:27:34 +00:00
</b-col>
<b-col>
{{ "{{ count }}" }}
2019-05-27 18:27:34 +00:00
</b-col>
<b-col cols="2">
<button @click="subtract(user,thing,count)">-</button>
<button @click="add(user,thing,count)">+</button>
2019-05-27 18:27:34 +00:00
</b-col>
</b-row>
</b-container>
</b-row>
</b-container>
</div>
<script>
function convertData(data) {
var newData = {};
for (let i = 0; i < data.length; i++) {
let entry = data[i]
if (newData[entry.Nick] === undefined) {
newData[entry.Nick] = {}
}
newData[entry.Nick][entry.Item] = entry.Count;
}
return newData;
}
var app = new Vue({
el: '#app',
data: {
err: '',
nav: {{ .Nav }},
2019-05-27 18:27:34 +00:00
answer: '',
correct: 0,
counters: {}
2019-05-27 18:27:34 +00:00
},
mounted() {
axios.get('/counter/api')
.then(resp => (this.counters = convertData(resp.data)))
.catch(err => (this.err = err));
},
methods: {
add(user, thing, count) {
axios.post('/counter/api',
{user: user, thing: thing, action: '++', password: this.answer})
.then(resp => {this.counters = convertData(resp.data); this.err = '';})
.catch(err => this.err = err);
2019-05-27 18:27:34 +00:00
},
subtract(user, thing, count) {
axios.post('/counter/api',
{user: user, thing: thing, action: '--', password: this.answer})
.then(resp => {this.counters = convertData(resp.data); this.err = '';})
.catch(err => this.err = err);
2019-05-27 18:27:34 +00:00
}
}
})
</script>
</body>
</html>
`