Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LB::JSON: Verbessern #873

Closed
christianTF opened this issue Dec 16, 2018 · 2 comments
Closed

LB::JSON: Verbessern #873

christianTF opened this issue Dec 16, 2018 · 2 comments

Comments

@christianTF
Copy link
Collaborator

  • JSON-Teil direkt aus Datei lesen
  • Und direkt als Template-Variable übergeben
@christianTF christianTF self-assigned this Dec 18, 2018
christianTF added a commit that referenced this issue Jan 14, 2019
->parse($jsonstring)
parses an already available string with json data

->filename($newfilename)
allows to set or change the filename of the json file

Enhancement regarding to #873
@mschlenstedt
Copy link
Owner

mschlenstedt commented Jan 14, 2019

Ich würde zwei Vereinfachungen gut finden:

1. Ersatz für das alte "associate => $cfg"

Z. B. hier:

Ich könnte mir vorstellen, dass es so funktioniert:

my $cfgfile = $lbpplugindir."/pluginconfig.json";
$jsonobj = LoxBerry::JSON->new();
$cfg = $jsonobj->open(filename => $cfgfile);
$jsonobj->associate(CFG);

Das erzeugt HTML::Template-Variablen mit dem Prefix CFG, z. B. <TMPL_VAR CFG.REMOTE.HTTPPORT>

CFG soll ein Präfix sein. Zu den Hierarchien: Ich dachte man macht das so: <TMPL_VAR PRÄFIX.GRUPPE1.GRUPPE2.VAR>, also z. B. <TMPL_VAR CFG.REMOTE.HTTPPORT>

2. Automatisch Javascript-Block erzeugen

Z. B, hier:
https://github.com/christianTF/LoxBerry-Plugin-MQTT-Gateway/blob/79421437b4b77d413386f1232cd3b3c5f0b756a3/templates/mqtt.html#L468

Ich könnte mir vorstellen, dass es so funktioniert:

my $cfgfile = $lbpplugindir."/pluginconfig.json";
$jsonobj = LoxBerry::JSON->new();
$cfg = $jsonobj->open(filename => $cfgfile);
$jsonobj->jsblock(PARSECFG);

Erzeugt eine HTML::Template-Variable <TMPL_VAR PARSECFG>, die obigen JS-Block enthält. Hier müssen wir aber noch beachten, dass es vermutlich recht viele Sonderfälle gibt. Ich brauche z. B. $("#"+elemname).flipswitch( "refresh" ); anstelle von checkboxradio, weil ich die Checkbox-Elemente als FlipSwitch nutze. Zudem muss bei der else-Verzweigung der ElementType "file" ausgenommen werden (Sicherheitsbedingungen aller moderner Browser).

christianTF added a commit that referenced this issue Jun 4, 2019
- FIXES a bug that hashref to the hash was not stored correctly in all situations
- Introducing ->flatten([$prefix])
- Introducing ->param (for use with HTML::Template)

The $jsonobj directly can be sent to HTML::Template with it's associate parameter

See the Wiki for examples:
https://www.loxwiki.eu/display/LOXBERRY/Perl+Modul+LoxBerry%3A%3AJSON

Refers to #873
@christianTF
Copy link
Collaborator Author

Ich glaub, alles drin:
Neu in V1.4.3:

  • $jsonobj->flatten liefert die Datenstruktur als flachen Hash, Hierarchien mit . getrennt.
  • $jsonobj kann direkt bei HTML::Tempate mit associate =>$jsonobj mitgegeben werden.
  • $jsonobj->encode liefert den aktuellen Daten-Hash als json-String (opt. mit pretty => 1)
  • $jsonobj->jsblock liefert ein JS-Statement, korrekt escaped, mit dem Variablennamen varname => "jsvarname"

https://www.loxwiki.eu/display/LOXBERRY/Perl+Modul+LoxBerry%3A%3AJSON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants