work in progress: set up structures and processes in common.ts
This commit is contained in:
parent
ba2a58353c
commit
1ad9e70c00
4 changed files with 57 additions and 10 deletions
44
assets/js/common.ts
Normal file
44
assets/js/common.ts
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import { api, polling } from './settings'
|
||||||
|
|
||||||
|
const confdata = {
|
||||||
|
pollurl: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
export function config (api, polling) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export const pvapp = {
|
||||||
|
$delimiters: ['{|', '|}'],
|
||||||
|
conf: confdata,
|
||||||
|
data: {},
|
||||||
|
output: '',
|
||||||
|
save,
|
||||||
|
poll
|
||||||
|
}
|
||||||
|
|
||||||
|
// method definitions
|
||||||
|
|
||||||
|
function save(value: string) {
|
||||||
|
this.output += '\n' + value
|
||||||
|
//this.newdata = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
async function dopoll(app: typeof pvapp) {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
let res = await fetch(pvapp.conf.pollurl)
|
||||||
|
let data = await res.json()
|
||||||
|
console.log(data)
|
||||||
|
//obj.newdata = data['status']
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
await new Promise(r => setTimeout(r, 10000))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function poll() {
|
||||||
|
dopoll(this)
|
||||||
|
}
|
||||||
|
|
|
@ -2,16 +2,13 @@ import { createApp } from './lib/petite-vue.es.js'
|
||||||
import { pageid } from '@params'
|
import { pageid } from '@params'
|
||||||
console.log("pageid:", pageid)
|
console.log("pageid:", pageid)
|
||||||
|
|
||||||
// import { config, pvapp } from './common'
|
|
||||||
import { api, polling } from './settings'
|
import { api, polling } from './settings'
|
||||||
|
import { config, pvapp } from './common'
|
||||||
// pvapp.run(config(api, polling))
|
// pvapp.run(config(api, polling))
|
||||||
|
|
||||||
const [domain, action, class_, item] = Object.values(polling)
|
const pollUrl = `${api.path}/${polling.msgbase.join('/')}`
|
||||||
const pollUrl = `${api.path}/${domain}/${action}/${class_}/${item}`
|
|
||||||
console.log("pollUrl:", pollUrl)
|
console.log("pollUrl:", pollUrl)
|
||||||
|
|
||||||
//const apiUrl = '/api/system/poll/service/pclt-0001'
|
|
||||||
|
|
||||||
const appdata = {
|
const appdata = {
|
||||||
$delimiters: ['{|', '|}'],
|
$delimiters: ['{|', '|}'],
|
||||||
urlParams: new URL(location.href).searchParams,
|
urlParams: new URL(location.href).searchParams,
|
||||||
|
|
|
@ -2,5 +2,10 @@
|
||||||
// imported by tsc via "import {...} from @params".
|
// imported by tsc via "import {...} from @params".
|
||||||
// Hugo / ESBuild will provide js.Build params in @params
|
// Hugo / ESBuild will provide js.Build params in @params
|
||||||
// (see layout/partials/js.html).
|
// (see layout/partials/js.html).
|
||||||
|
|
||||||
|
export const apipath = 'apipath-dummy' // obsolete? see settings.ts
|
||||||
|
|
||||||
export const pageid = 'pageid-dummy'
|
export const pageid = 'pageid-dummy'
|
||||||
export const apipath = 'apipath-dummy'
|
export const domain = 'domain-dummy'
|
||||||
|
export const action = 'action-dummy'
|
||||||
|
export const class_ = 'class-dummy'
|
||||||
|
|
|
@ -3,8 +3,9 @@ export const api = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const polling = {
|
export const polling = {
|
||||||
domain: 'system',
|
msgbase: ['system', 'poll', 'service', 'pclt-0001']
|
||||||
action: 'poll',
|
//msgbase: ['system', 'poll', 'session']
|
||||||
class: 'service',
|
//msgbase: ['system', 'poll', 'interaction']
|
||||||
item: 'pclt-0001'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// export const polling = null // suppress polling
|
||||||
|
|
Loading…
Add table
Reference in a new issue