diff --git a/assets/js/common.ts b/assets/js/common.ts index 8d6e633..6884a2c 100644 --- a/assets/js/common.ts +++ b/assets/js/common.ts @@ -1,6 +1,6 @@ import { createApp } from 'petite-vue' -import { pageid, domain, nopoll } from '@params' +import { domain, nopoll } from '@params' type Config = { apiurl: string @@ -51,10 +51,12 @@ const appdata = { // components -function Data(name: string, action: string): object { +function Data(name, action, domain: string): object { + domain = domain || this.conf.domain const comp = { - name: name, // matches/determines class of incoming/outgoing message + name: name, // -> class of incoming/outgoing message action: action, // (default) action of outgoing message + domain: domain, // domain of incoming/outgoing message data: {}, // model (2-way data store) exec // default function to execute upon button click } @@ -76,21 +78,24 @@ function exec() { sendMsg(conf, [conf.domain, this.action, this.name, data.id], data) } -function poll() { - dopoll(this) -} - function handle(msg) { const data = JSON.parse(msg.payload) const [ domain, action, class_, item ] = msg.path.split('/') //console.log('msgbase: ', domain, action, class_, item) // TODO: check message parts (using default values), select handler fct const comp = this.components[class_ || data] + if (domain && domain != comp.domain) { + return + } if (comp != undefined) { Object.assign(comp.data, data) } } +function poll() { + dopoll(this) +} + // basic functions - move to api.ts async function sendMsg(conf: Config, basemsg: string[], data: any) { diff --git a/exampleSite/content/app/login.md b/exampleSite/content/app/login.md index 860361f..1a3f1a7 100644 --- a/exampleSite/content/app/login.md +++ b/exampleSite/content/app/login.md @@ -9,9 +9,6 @@ date: 2023-03-14 author: helmutm draft: false weight: 100 -api: - domain: system - nopoll: false --- cyberscopes example site - Login Form diff --git a/exampleSite/content/app/test1.md b/exampleSite/content/app/test1.md index aa72d0e..373ec3f 100644 --- a/exampleSite/content/app/test1.md +++ b/exampleSite/content/app/test1.md @@ -9,8 +9,6 @@ date: 2023-03-12 author: helmutm draft: false weight: 100 -api: - domain: test --- cyberscopes example site - use petite-vue in Hugo-generated sites. diff --git a/layouts/partials/js.html b/layouts/partials/js.html index 8529d30..ab140cb 100644 --- a/layouts/partials/js.html +++ b/layouts/partials/js.html @@ -1,8 +1,6 @@ {{- if $jsmod := $.Param "api.module" -}} - {{- $pageid := or .Params.Pageid (and .File .File.UniqueID) "unknown" -}} - {{- $params := dict "pageid" $pageid - "domain" ($.Param "api.domain") - "nopoll" ($.Param "api.nopoll") | default false -}} + {{- $params := dict "domain" .Site.Params.api.domain + "nopoll" .Site.Params.api.nopoll | default false -}} {{- $js := resources.Get (printf "js/%s" $jsmod) | js.Build ( dict "minify" false "params" $params) -}} diff --git a/layouts/shortcodes/pv/debug.html b/layouts/shortcodes/pv/debug.html index ee27f27..b886517 100644 --- a/layouts/shortcodes/pv/debug.html +++ b/layouts/shortcodes/pv/debug.html @@ -2,6 +2,7 @@