vue webui autodetects queue_num

This commit is contained in:
boyska 2022-08-20 17:52:55 +02:00
parent a0dc1d5715
commit 9413862186
3 changed files with 53 additions and 30 deletions

View file

@ -1,40 +1,24 @@
const { createApp } = Vue const { createApp } = Vue
function range(start, end) {
var ans = [];
for (let i = start; i <= end; i++) {
ans.push(i);
}
return ans;
}
var app = createApp({ var app = createApp({
data() {
return {
counter: -1,
}
},
components: { components: {
'CounterController': Vue.defineAsyncComponent( () => import('/static/vue/counter.js') ) 'CounterList': Vue.defineAsyncComponent( () => import('/static/vue/counterlist.js') ),
}, },
template: `
<CounterController queue_num="0"></CounterController> template: ` <CounterList></CounterList> `
<CounterController queue_num="1"></CounterController>
`,
}) })
app.mount('#app') app.mount('#app')
app.component(
'counter-controller',
{
data: () => { counter: 0; },
template: `<div class="counter">{{counter}}</div>`,
}
)
function get_cid() {
return document.getElementsByTagName('body')[0].dataset.cid;
}
function get_url(cid) function get_url(cid)
{ {
if(cid === undefined) {
cid = get_cid()
}
var url = ""; var url = "";
if(window.location.protocol == "http:") { if(window.location.protocol == "http:") {
url += "ws://" url += "ws://"
@ -77,4 +61,3 @@ function printToLetter(number, recursive){
var quotient = Math.floor((number-1)/alphabet.length) var quotient = Math.floor((number-1)/alphabet.length)
return printToLetter(quotient, true) + printToLetter(remainder, true) return printToLetter(quotient, true) + printToLetter(remainder, true)
} }

View file

@ -5,8 +5,7 @@ export default {
props: ["queue_num"], props: ["queue_num"],
data() { data() {
var me = this; var me = this;
console.log("I am", this); do_websocket(parseInt(me.queue_num, 10), function(new_value) {
do_websocket(me.queue_num, function(new_value) {
me.counter = new_value me.counter = new_value
}) })
return { counter: -1 } return { counter: -1 }

View file

@ -0,0 +1,41 @@
const template = `
<CounterController v-for="q in queues" :queue_num="q"></CounterController>
`
export default {
template: template,
components: {
'CounterController': Vue.defineAsyncComponent( () => import('/static/vue/counter.js') ),
},
data() {
return {
queue_count: 0,
}
},
mounted: function () {
this.updateGlobalProperties()
},
methods: {
updateGlobalProperties() {
var me = this
fetch('/v1/counter/')
.then((response) => response.json())
.then(function(data) {
me.queue_count = data.counters
console.log('qc', me.queue_count)
})
}
},
computed: {
queues() {
return range(0, this.queue_count-1)
}
},
}