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>
|
2019-05-28 03:14:05 +00:00
|
|
|
<title>Counters</title>
|
2019-05-27 18:27:34 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="app">
|
2019-06-09 04:15:06 +00:00
|
|
|
<b-navbar>
|
|
|
|
<b-navbar-brand>Counters</b-navbar-brand>
|
|
|
|
<b-navbar-nav>
|
2021-01-09 18:46:28 +00:00
|
|
|
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'Counter'">{{ item.name }}</b-nav-item>
|
2019-06-09 04:15:06 +00:00
|
|
|
</b-navbar-nav>
|
|
|
|
</b-navbar>
|
2019-05-27 18:27:34 +00:00
|
|
|
<b-alert
|
|
|
|
dismissable
|
2019-06-13 14:04:06 +00:00
|
|
|
:show="err"
|
|
|
|
variant="error">
|
2021-01-09 18:46:28 +00:00
|
|
|
{{ err }}
|
2019-05-27 18:27:34 +00:00
|
|
|
</b-alert>
|
|
|
|
<b-container>
|
|
|
|
<b-row>
|
2019-06-13 14:04:06 +00:00
|
|
|
<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">
|
2021-01-09 18:46:28 +00:00
|
|
|
{{ user }}:
|
2019-05-27 18:27:34 +00:00
|
|
|
<b-container>
|
|
|
|
<b-row v-for="(count, thing) in counter">
|
|
|
|
<b-col offset="1">
|
2021-01-09 18:46:28 +00:00
|
|
|
{{ thing }}:
|
2019-05-27 18:27:34 +00:00
|
|
|
</b-col>
|
|
|
|
<b-col>
|
2021-01-09 18:46:28 +00:00
|
|
|
{{ count }}
|
2019-05-27 18:27:34 +00:00
|
|
|
</b-col>
|
|
|
|
<b-col cols="2">
|
2019-06-13 14:04:06 +00:00
|
|
|
<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: {
|
2019-06-09 04:15:06 +00:00
|
|
|
err: '',
|
2021-01-09 18:46:28 +00:00
|
|
|
nav: [],
|
2019-05-27 18:27:34 +00:00
|
|
|
answer: '',
|
|
|
|
correct: 0,
|
2019-06-13 14:04:06 +00:00
|
|
|
counters: {}
|
2019-05-27 18:27:34 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2021-01-09 18:46:28 +00:00
|
|
|
axios.get('/nav')
|
|
|
|
.then(resp => {
|
|
|
|
this.nav = resp.data;
|
|
|
|
})
|
|
|
|
.catch(err => console.log(err))
|
2019-05-27 18:27:34 +00:00
|
|
|
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',
|
2019-06-13 14:04:06 +00:00
|
|
|
{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',
|
2019-06-13 14:04:06 +00:00
|
|
|
{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>
|
|
|
|
`
|