rename shortcodes; back to ?id=<item> (instead of #<item>)
This commit is contained in:
parent
d82d36cef7
commit
4cd5021a63
16 changed files with 50 additions and 45 deletions
|
@ -1,7 +1,7 @@
|
||||||
// app-demo.ts - petite-vue application using dummy localStorage backend
|
// app-demo.ts - petite-vue application using dummy localStorage backend
|
||||||
|
|
||||||
import { createApp } from 'petite-vue'
|
import { createApp } from 'petite-vue'
|
||||||
import { Config, register, handle, createRandString, sleep} from './common'
|
import { Config, register, handle, createRandString} from './common'
|
||||||
|
|
||||||
export const pvapp = {
|
export const pvapp = {
|
||||||
run(conf: Config, components: any[]) {
|
run(conf: Config, components: any[]) {
|
||||||
|
@ -27,7 +27,6 @@ const store_prefix = 'api.storage'
|
||||||
// methods
|
// methods
|
||||||
|
|
||||||
async function sendMsg(basemsg: string[], data: any) {
|
async function sendMsg(basemsg: string[], data: any) {
|
||||||
await sleep(50)
|
|
||||||
const [ domain, action, class_, item ] = basemsg
|
const [ domain, action, class_, item ] = basemsg
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'data':
|
case 'data':
|
||||||
|
|
|
@ -13,9 +13,11 @@ export type Config = {
|
||||||
|
|
||||||
export function config (api): Config {
|
export function config (api): Config {
|
||||||
const pu = api.polling ? `${api.path}/${api.polling.msgbase.join('/')}` : ''
|
const pu = api.polling ? `${api.path}/${api.polling.msgbase.join('/')}` : ''
|
||||||
|
const urlparams = new URL(location.href).searchParams
|
||||||
return {
|
return {
|
||||||
domain: domain,
|
domain: domain,
|
||||||
itemid: location.hash.substring(1),
|
//itemid: location.hash.substring(1),
|
||||||
|
itemid: urlparams.get('id'),
|
||||||
sid: getSid(),
|
sid: getSid(),
|
||||||
iid: createRandString(1),
|
iid: createRandString(1),
|
||||||
apiurl: api.path,
|
apiurl: api.path,
|
||||||
|
@ -27,6 +29,7 @@ export function config (api): Config {
|
||||||
|
|
||||||
export function register(name: string, comp: any) {
|
export function register(name: string, comp: any) {
|
||||||
this.components[name] = comp
|
this.components[name] = comp
|
||||||
|
comp.initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// common functions
|
// common functions
|
||||||
|
@ -34,12 +37,13 @@ export function register(name: string, comp: any) {
|
||||||
export function handle(app, msg) {
|
export function handle(app, msg) {
|
||||||
const [ domain, action, class_, item ] = msg.path.split('/')
|
const [ domain, action, class_, item ] = msg.path.split('/')
|
||||||
const comp = app.components[class_ || 'data']
|
const comp = app.components[class_ || 'data']
|
||||||
|
if (!comp) {
|
||||||
|
msg.log(`**** handle: component ${class_} not found.`)
|
||||||
|
}
|
||||||
if (domain && domain !== comp.domain) {
|
if (domain && domain !== comp.domain) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (comp) {
|
comp.handle(domain, action, class_, item, msg.payload)
|
||||||
comp.handle(domain, action, class_, item, msg.payload)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createRandString(size: number): string {
|
export function createRandString(size: number): string {
|
||||||
|
|
|
@ -12,21 +12,25 @@ export function Data(name: string, conf: any): object {
|
||||||
domain: domain, // domain of incoming/outgoing message
|
domain: domain, // domain of incoming/outgoing message
|
||||||
data: {}, // model (2-way data store)
|
data: {}, // model (2-way data store)
|
||||||
meta: {}, // metadata (params) for each data field
|
meta: {}, // metadata (params) for each data field
|
||||||
|
initialize,
|
||||||
handle, // handle incoming messages
|
handle, // handle incoming messages
|
||||||
exec, // default function to execute upon button click
|
exec, // default function to execute upon button click
|
||||||
initField, // initialize field (= @mounted)
|
initField, // initialize field (= @mounted), collect metadata
|
||||||
chmode,
|
chmode,
|
||||||
copynew
|
copynew
|
||||||
}
|
}
|
||||||
//this.components[name] = comp
|
//this.components[name] = comp
|
||||||
if (comp.state.id) {
|
|
||||||
this.sendMsg([domain, 'query', name, comp.state.id], {})
|
|
||||||
}
|
|
||||||
return comp
|
return comp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data methods
|
// Data methods
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
|
if (this.state.id) {
|
||||||
|
this.sendMsg([this.domain, 'query', this.name, this.state.id], {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handle(domain, action, class_, item, payload: string) {
|
function handle(domain, action, class_, item, payload: string) {
|
||||||
const data = JSON.parse(payload)
|
const data = JSON.parse(payload)
|
||||||
console.log('handle - action: ', action, ', data: ', data)
|
console.log('handle - action: ', action, ', data: ', data)
|
||||||
|
@ -35,8 +39,9 @@ function handle(domain, action, class_, item, payload: string) {
|
||||||
this.state.mode = 'view'
|
this.state.mode = 'view'
|
||||||
} else if (action === 'response') { // && data.rc == 3) {
|
} else if (action === 'response') { // && data.rc == 3) {
|
||||||
this.state.id = item
|
this.state.id = item
|
||||||
window.location.hash = item
|
//window.location.hash = item
|
||||||
this.sendMsg([this.domain, 'query', this.name, item], {})
|
window.location.assign(`?id=${item}`)
|
||||||
|
//this.sendMsg([this.domain, 'query', this.name, item], {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,16 +12,19 @@ export function List(name: string, conf: any): object {
|
||||||
domain: domain, // domain of incoming/outgoing message
|
domain: domain, // domain of incoming/outgoing message
|
||||||
data: [], // model = list of rows
|
data: [], // model = list of rows
|
||||||
meta: {}, // metadata (params) for each field (table column)
|
meta: {}, // metadata (params) for each field (table column)
|
||||||
|
initialize,
|
||||||
handle, // handle incoming messages
|
handle, // handle incoming messages
|
||||||
initField // initialize field (= @mounted)
|
initField // initialize field (= @mounted)
|
||||||
}
|
}
|
||||||
//this.components[name] = comp
|
|
||||||
this.sendMsg([domain, 'query', name], {})
|
|
||||||
return comp
|
return comp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data methods
|
// Data methods
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
|
this.sendMsg([this.domain, 'query', this.name], {})
|
||||||
|
}
|
||||||
|
|
||||||
function handle(domain, action, class_, item: string, payload) {
|
function handle(domain, action, class_, item: string, payload) {
|
||||||
if (action == 'list') {
|
if (action == 'list') {
|
||||||
const rows = payload.split('\n')
|
const rows = payload.split('\n')
|
||||||
|
|
|
@ -5,23 +5,22 @@ img:
|
||||||
pageid: app-login
|
pageid: app-login
|
||||||
domains: [App]
|
domains: [App]
|
||||||
topics: [Examples]
|
topics: [Examples]
|
||||||
date: 2023-03-14
|
date: 2023-03-27
|
||||||
author: helmutm
|
|
||||||
draft: false
|
draft: false
|
||||||
weight: 100
|
weight: 400
|
||||||
api:
|
api:
|
||||||
domain: system
|
domain: system
|
||||||
---
|
---
|
||||||
|
|
||||||
cyberscopes example site - Login Form
|
cyberscopes example site - Login Form
|
||||||
|
|
||||||
{{< pv/fieldset name="login" >}}
|
{{< pv/data name="login" >}}
|
||||||
|
|
||||||
Login: {{< pv/input-textline name="login" attrs="autofocus" >}}
|
Login: {{< pv/data-field-line name="login" attrs="autofocus" >}}
|
||||||
Password: {{< pv/input-textline type="password" name="password" >}}
|
Password: {{< pv/data-field-line type="password" name="password" >}}
|
||||||
{{< pv/button label="Login" action="login" >}}
|
{{< pv/button label="Login" action="login" >}}
|
||||||
|
|
||||||
{{< /pv/fieldset >}}
|
{{< /pv/data >}}
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ img:
|
||||||
pageid: app_list_person
|
pageid: app_list_person
|
||||||
domains: [App]
|
domains: [App]
|
||||||
topics: [Examples]
|
topics: [Examples]
|
||||||
date: 2023-03-22
|
date: 2023-03-27
|
||||||
author: helmutm
|
|
||||||
draft: false
|
draft: false
|
||||||
weight: 100
|
weight: 100
|
||||||
---
|
---
|
||||||
|
|
|
@ -5,21 +5,20 @@ img:
|
||||||
pageid: app_form_person
|
pageid: app_form_person
|
||||||
domains: [App]
|
domains: [App]
|
||||||
topics: [Examples]
|
topics: [Examples]
|
||||||
date: 2023-03-19
|
date: 2023-03-27
|
||||||
author: helmutm
|
|
||||||
draft: false
|
draft: false
|
||||||
weight: 100
|
weight: 100
|
||||||
---
|
---
|
||||||
|
|
||||||
cyberscopes example site - view / edit person (user) data.
|
cyberscopes example site - view / edit person (user) data.
|
||||||
|
|
||||||
{{< pv/fieldset name="person" >}}
|
{{< pv/data name="person" >}}
|
||||||
|
|
||||||
{{< pv/tabs-mode >}}
|
{{< pv/data-tabs >}}
|
||||||
|
|
||||||
First Name: {{< pv/input-textline name="firstname" attrs="autofocus" >}}
|
First Name: {{< pv/data-field-line name="firstname" attrs="autofocus" >}}
|
||||||
Last Name: {{< pv/input-textline name="lastname" >}}
|
Last Name: {{< pv/data-field-line name="lastname" >}}
|
||||||
Email: {{< pv/input-textline name="email" default="hm@cy55.de" >}}
|
Email: {{< pv/data-field-line name="email" default="hm@cy55.de" >}}
|
||||||
|
|
||||||
{{< pv/button mode="edit" label="Save Changes" >}}
|
{{< pv/button mode="edit" label="Save Changes" >}}
|
||||||
{{< pv/button mode="edit" exec="copynew" label="Copy Data" >}}
|
{{< pv/button mode="edit" exec="copynew" label="Copy Data" >}}
|
||||||
|
@ -27,14 +26,15 @@ cyberscopes example site - view / edit person (user) data.
|
||||||
{{< pv/button mode="new" label="Create Item" >}}
|
{{< pv/button mode="new" label="Create Item" >}}
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
{{< pv/display linkto="state.id"
|
{{< pv/data-display
|
||||||
expr="`${data.firstname} ${data.lastname}`.trim() || '???'" >}}
|
expr="`${data.firstname} ${data.lastname}`.trim() || '???'" >}}
|
||||||
|
{{< pv/data-display expr="state.id ? ` (Id: ${state.id})` : ''" >}}
|
||||||
<br>
|
<br>
|
||||||
{{< pv/link >}}
|
{{< pv/link >}}
|
||||||
Reload page with id {{< pv/display expr="state.id" >}}
|
Reload page with id {{< pv/data-display expr="state.id" >}}
|
||||||
{{< /pv/link >}}
|
{{< /pv/link >}}
|
||||||
|
|
||||||
{{< /pv/fieldset >}}
|
{{< /pv/data >}}
|
||||||
|
|
||||||
{{< pv/debug >}}
|
{{< pv/debug >}}
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,17 @@ img:
|
||||||
pageid: test0
|
pageid: test0
|
||||||
domains: [App]
|
domains: [App]
|
||||||
topics: [Examples]
|
topics: [Examples]
|
||||||
date: 2023-03-12
|
date: 2023-03-27
|
||||||
author: helmutm
|
|
||||||
draft: false
|
draft: false
|
||||||
weight: 110
|
weight: 510
|
||||||
---
|
---
|
||||||
|
|
||||||
cyberscopes example site - use petite-vue in Hugo-generated sites.
|
cyberscopes example site - use petite-vue in Hugo-generated sites.
|
||||||
|
|
||||||
{{< pv/count >}}
|
{{< pv/xplore/count >}}
|
||||||
|
|
||||||
{{< pv/count init="7" expr="count--" label="dec" >}}
|
{{< pv/xplore/count init="7" expr="count--" label="dec" >}}
|
||||||
|
|
||||||
{{< pv/count init="99" expr="save()" label="log" >}}
|
{{< pv/xplore/count init="99" expr="save()" label="log" >}}
|
||||||
|
|
||||||
{{< pv/explore >}}
|
{{< pv/xplore/explore >}}
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
{{- $name := .Get "name" | default "textline" -}}
|
{{- $name := .Get "name" | default "textline" -}}
|
||||||
{{- $expr := .Get "expr" | default (printf "data.%s" $name) -}}
|
{{- $expr := .Get "expr" | default (printf "data.%s" $name) -}}
|
||||||
{{- $linkto := .Get "linkto" -}}
|
|
||||||
{{- if $linkto }}<a :href="'#' + {{ $linkto }}">{{ end -}}
|
|
||||||
<span v-text="{{ $expr }}"></span>
|
<span v-text="{{ $expr }}"></span>
|
||||||
{{- if $linkto }}</a>{{ end -}}
|
|
|
@ -1,3 +1,3 @@
|
||||||
{{- $target := .Get "target" | default "state.id" -}}
|
{{- $target := .Get "target" | default "state.id" -}}
|
||||||
{{- $prefix := .Get "prefix" | default "#" -}}
|
{{- $prefix := .Get "prefix" | default "?id=" -}}
|
||||||
<a :href="'{{ $prefix }}' + {{ $target }}">{{ .Inner }}</a>
|
<a :href="'{{ $prefix }}' + {{ $target }}">{{ .Inner }}</a>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<tr>{{- .Inner -}}</tr>
|
<tr>{{- .Inner -}}</tr>
|
||||||
<tr v-for="item in data" :key="item._item">
|
<tr v-for="item in data" :key="item._item">
|
||||||
<td v-for="(col, fname) in meta">
|
<td v-for="(col, fname) in meta">
|
||||||
<a :href="`../${name}/#${item._item}`">{| item[fname] |}</a>
|
<a :href="`../${name}/?id=${item._item}`">{| item[fname] |}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Add table
Reference in a new issue