From 52a2f4e65638056e6de6bb95991c436a6408d9de Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Fri, 20 Sep 2019 10:48:29 +0000
Subject: [PATCH] AttrTemplate.pm: add order and "online" help (Forum #94495)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@20206 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
FHEM/01_FHEMWEB.pm | 2 ++
FHEM/AttrTemplate.pm | 53 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/FHEM/01_FHEMWEB.pm b/FHEM/01_FHEMWEB.pm
index 952e54c00..e69301422 100644
--- a/FHEM/01_FHEMWEB.pm
+++ b/FHEM/01_FHEMWEB.pm
@@ -89,6 +89,7 @@ use vars qw(%FW_visibleDeviceHash);
use vars qw(@FW_httpheader); # HTTP header, line by line
use vars qw(%FW_httpheader); # HTTP header, as hash
use vars qw($FW_userAgent); # user agent string
+use vars qw($FW_addJs); # Only for helper like AttrTemplate
$FW_formmethod = "post";
@@ -1064,6 +1065,7 @@ FW_answerCall($)
my $n = $_; $n =~ s+.*/++; $n =~ s/.js$//; $n =~ s/fhem_//; $n .= "Param";
FW_pO sprintf($jsTemplate, AttrVal($FW_wname, $n, ""), "$FW_ME/$_");
} @jsList;
+ FW_pO $FW_addJs if($FW_addJs);
########################
# FW Extensions
diff --git a/FHEM/AttrTemplate.pm b/FHEM/AttrTemplate.pm
index 2010c821a..313708e47 100644
--- a/FHEM/AttrTemplate.pm
+++ b/FHEM/AttrTemplate.pm
@@ -5,6 +5,7 @@ package main;
my %templates;
my $initialized;
my %cachedUsage;
+use vars qw($FW_addJs); # Only for helper like AttrTemplate
sub
AttrTemplate_Initialize()
@@ -68,6 +69,9 @@ AttrTemplate_Initialize()
} elsif($line =~ m/^farewell:(.*)/) {
$templates{$name}{farewell} = $1;
+ } elsif($line =~ m/^order:(.*)/) {
+ $templates{$name}{order} = $1;
+
} else {
push(@{$templates{$name}{cmds}}, $line);
@@ -80,9 +84,52 @@ AttrTemplate_Initialize()
delete($templates{$name});
}
- my $nr = (int keys %templates);
+ @templates = sort {
+ my $ao = $templates{$a}{order};
+ my $bo = $templates{$b}{order};
+ $ao = (defined($ao) ? $ao : $a);
+ $bo = (defined($bo) ? $bo : $b);
+ return $ao cmp $bo;
+ } keys %templates;
+
+ my $nr = @templates;
$initialized = 1;
Log 2, "AttrTemplates: got $nr entries" if($nr);
+ $FW_addJs = "" if(!defined($FW_addJs));
+ $FW_addJs .= << 'JSEND';
+
+JSEND
+}
+
+sub
+AttrTemplate_Help($)
+{
+ my ($n) = @_;
+ return "" if(!$templates{$n});
+ my $ret = "";
+ $ret = $templates{$n}{desc} if($templates{$n}{desc});
+ $ret .= "
".join("\n",@{$templates{$n}{cmds}}).""; + return $ret; } sub @@ -100,7 +147,7 @@ AttrTemplate_Set($$@) if($cmd ne "attrTemplate") { if(!$cachedUsage{$name}) { my @list; - for my $k (sort keys %templates) { + for my $k (@templates) { my $h = $templates{$k}; my $matches; $matches = devspec2array($h->{filter}, undef, [$name]) if($h->{filter}); @@ -121,7 +168,7 @@ AttrTemplate_Set($$@) if($entry eq "?") { my @hlp; - for my $k (sort keys %templates) { + for my $k (@templates) { my $h = $templates{$k}; my $matches; $matches = devspec2array($h->{filter}, undef, [$name]) if($h->{filter});