fix handling of js @params (only global); fieldset/component: + 'domain'
This commit is contained in:
parent
4bbc3cad0a
commit
36abaf6f74
6 changed files with 17 additions and 17 deletions
|
@ -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) {
|
||||
|
|
|
@ -9,9 +9,6 @@ date: 2023-03-14
|
|||
author: helmutm
|
||||
draft: false
|
||||
weight: 100
|
||||
api:
|
||||
domain: system
|
||||
nopoll: false
|
||||
---
|
||||
|
||||
cyberscopes example site - Login Form
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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) -}}
|
||||
<script src="{{ $js.Permalink }}" defer></script>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<h3>Debug Information</h3>
|
||||
|
||||
<div @vue:mounted="mounted('conf')">
|
||||
<div>domain: {| conf.domain |}</div>
|
||||
<div>item id: {| conf.itemid |}</div>
|
||||
<div>session id: {| conf.sid |}</div>
|
||||
<div>interaction id: {| conf.iid |}</div>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{{- $name := .Get "name" | default "data" -}}
|
||||
{{- $action := .Get "action" | default "data" -}}
|
||||
{{- $domain := .Get "domain" -}}
|
||||
{{- $comp := .Get "component" | default "Data" -}}
|
||||
<div v-scope="{{ $comp }}('{{ $name }}', '{{ $action }}')">
|
||||
<div v-scope="{{ $comp }}('{{ $name }}', '{{ $action }}', '{{ $domain }}')">
|
||||
{{ .Inner }}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue