From 2dca568ee874a4dc7cd09d2efffce67f316cd97b Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 27 Feb 2023 10:40:10 +0100 Subject: [PATCH] refactoring, config stuff basically OK --- assets/js/common.ts | 38 +++++++++++++++++++++------ assets/js/main.ts | 49 +---------------------------------- assets/js/params-tsc.ts | 2 ++ layouts/shortcodes/input.html | 11 ++++---- 4 files changed, 39 insertions(+), 61 deletions(-) diff --git a/assets/js/common.ts b/assets/js/common.ts index c94cd46..230d068 100644 --- a/assets/js/common.ts +++ b/assets/js/common.ts @@ -1,11 +1,18 @@ +import { createApp } from './lib/petite-vue.es.js' + import { api, polling } from './settings' +import { pageid } from '@params' type confdata = { + apiurl: string pollurl: string + itemid: string } export function config (api, polling): confdata { - return { pollurl: '' } + const pu = `${api.path}/${polling.msgbase.join('/')}` + const urlparams = new URL(location.href).searchParams + return { apiurl: api.path, pollurl: pu, itemid: urlparams.get('id') } } export const pvapp = { @@ -13,17 +20,36 @@ export const pvapp = { conf: {} as confdata, data: {}, output: '', + run, save, - poll + poll, + newdata: '', + mounted(name: string) { + console.log('app mounted: ', name) + } } -// method definitions +// pvapp method definitions + +function run(conf: confdata) { + this.conf = conf + createApp(this).mount() + if (this.conf.pollurl) { + this.poll() + } +} function save(value: string) { this.output += '\n' + value - //this.newdata = '' + console.log('save:', value) } +function poll() { + dopoll(this) +} + +// basic functions + async function dopoll(app: typeof pvapp) { while (true) { try { @@ -39,7 +65,3 @@ async function dopoll(app: typeof pvapp) { } } -function poll() { - dopoll(this) -} - diff --git a/assets/js/main.ts b/assets/js/main.ts index b808deb..b06714d 100644 --- a/assets/js/main.ts +++ b/assets/js/main.ts @@ -1,52 +1,5 @@ -import { createApp } from './lib/petite-vue.es.js' -import { pageid } from '@params' -console.log("pageid:", pageid) - import { api, polling } from './settings' import { config, pvapp } from './common' -// pvapp.run(config(api, polling)) -const pollUrl = `${api.path}/${polling.msgbase.join('/')}` -console.log("pollUrl:", pollUrl) - -const appdata = { - $delimiters: ['{|', '|}'], - urlParams: new URL(location.href).searchParams, - poll, - newdata: '', - data: '', - save, - mounted(name: string) { - console.log('app mounted: ', name) - } -} - -createApp(appdata).mount() - -appdata.poll() - -// method definitions - -function save() { - this.data += '\n' + this.newdata - this.newdata = '' -} - -async function dopoll(obj: typeof appdata, url: string) { - while (true) { - try { - let res = await fetch(url) - 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, pollUrl) -} +pvapp.run(config(api, polling)) diff --git a/assets/js/params-tsc.ts b/assets/js/params-tsc.ts index 9a37b14..b8747c9 100644 --- a/assets/js/params-tsc.ts +++ b/assets/js/params-tsc.ts @@ -9,3 +9,5 @@ export const pageid = 'pageid-dummy' export const domain = 'domain-dummy' export const action = 'action-dummy' export const class_ = 'class-dummy' + +export const nopolling = false diff --git a/layouts/shortcodes/input.html b/layouts/shortcodes/input.html index 26c2b3d..2782d14 100644 --- a/layouts/shortcodes/input.html +++ b/layouts/shortcodes/input.html @@ -1,18 +1,19 @@
+ v-model="data.txt" + @vue:mounted="$el.value = ''" + @change="save($el.value)" />

 
-
-

+
+

 
-
id = {| urlParams.get('id') |}
+
id = {| conf.itemid |}