mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-17 17:36:01 +00:00
New Modul *BETA*
git-svn-id: https://svn.fhem.de/fhem/trunk@898 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
91f58a9379
commit
949016ddf5
@ -1,4 +1,4 @@
|
||||
################################################################################
|
||||
################################################################################
|
||||
# 95 VIEW
|
||||
# Feedback: http://groups.google.com/group/fhem-users
|
||||
# Define Custom View
|
||||
@ -20,21 +20,7 @@
|
||||
# Show all Warnings of ALL Devices
|
||||
# attr MyFHT ViewRegExType * or NotSet
|
||||
# attr MyFHT ViewRegExName * or NotSet
|
||||
# attr MyFHT ViewRegExReading Warning
|
||||
#
|
||||
# Ausgabe
|
||||
# <Device-Name> <Device-Type>
|
||||
# <READING-Name> <Reading-Value> <Reading-Time>
|
||||
# Reihenfolge
|
||||
# foreach $d (sort keys %defs){
|
||||
# if($defs{$defs{$d}{TYPE}}{TYPE} =~ m/$attr{$d}{Type}/ && $d =~ m/$attr{<NAME>}{NAME}/){
|
||||
# foreach $r (sort keys %{$defs{$d}{READINGS}}) {
|
||||
# if($r =~ m/$attr{$d}{Reading}/) {
|
||||
# print $d . ": " $r;
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# attr MyFHT ViewRegExReading warnings
|
||||
################################################################################
|
||||
package main;
|
||||
use strict;
|
||||
@ -46,13 +32,16 @@ sub VIEW_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{DefFn} = "VIEW_Define";
|
||||
$hash->{AttrList} = "ViewRegExType ViewRegExName ViewRegExReading loglevel:0,5";
|
||||
$hash->{AttrList} = "ViewRegExType ViewRegExName ViewRegExReading ViewRegExReadingStringCompare loglevel:0,5";
|
||||
# CGI
|
||||
my $name = "MyVIEWS";
|
||||
my $fhem_url = "/" . $name ;
|
||||
$data{FWEXT}{$fhem_url}{FUNC} = "VIEW_CGI";
|
||||
$data{FWEXT}{$fhem_url}{LINK} = $name;
|
||||
$data{FWEXT}{$fhem_url}{NAME} = $name;
|
||||
# Global-Config for CSS
|
||||
# $attr{global}{VIEW_CSS} = "";
|
||||
$modules{_internal_}{AttrList} .= " VIEW_CSS";
|
||||
return undef;
|
||||
}
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -66,7 +55,7 @@ sub VIEW_CGI(){
|
||||
my ($htmlarg) = @_;
|
||||
# Remove trailing slash
|
||||
$htmlarg =~ s/^\///;
|
||||
Log 0,"VIEW: htmlarg: " . $htmlarg ."\n";
|
||||
# Log 0,"VIEW: htmlarg: " . $htmlarg ."\n";
|
||||
# URL: http(s)://[FHEM:xxxx]/fhem/MyVIEWS/<View-Name>
|
||||
my @params = split(/\//,$htmlarg);
|
||||
my $ret_html;
|
||||
@ -81,13 +70,14 @@ sub VIEW_CGI(){
|
||||
return ("text/plain; charset=ISO-8859-1", $ret_html);
|
||||
}
|
||||
}
|
||||
$ret_html .= "VIEW: $view\n";
|
||||
$ret_html = "<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01\/\/EN\" \"http:\/\/www.w3.org\/TR\/html4\/strict.dtd\">\n";
|
||||
$ret_html = "<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01\/\/EN\" \"http:\/\/www.w3.org\/TR\/html4\/strict.dtd\">\n";
|
||||
$ret_html .= "<html>\n";
|
||||
$ret_html .= "<head>\n";
|
||||
$ret_html .= &VIEW_CGI_CSS();
|
||||
$ret_html .= "<title>FHEM GROUPS<\/title>\n";
|
||||
$ret_html .= "<link href=\"$FW_ME/style.css\" rel=\"stylesheet\"/>\n";
|
||||
# Select CSS-Style-Sheet
|
||||
my $css = $attr{global}{VIEW_CSS};
|
||||
if($css eq ""){$ret_html .= "<link href=\"$FW_ME/style.css\" rel=\"stylesheet\"/>\n";}
|
||||
else {$ret_html .= "<link href=\"$FW_ME/$css\" rel=\"stylesheet\"/>\n";}
|
||||
$ret_html .= "<title>FHEM VIEWS<\/title>\n";
|
||||
$ret_html .= "<\/head>\n";
|
||||
$ret_html .= "<body>\n";
|
||||
# DIV HDR
|
||||
@ -95,24 +85,17 @@ sub VIEW_CGI(){
|
||||
# DIV LEFT
|
||||
$ret_html .= &VIEW_CGI_LEFT();
|
||||
# DIV RIGHT
|
||||
$ret_html .= &VIEW_CGI_RIGHT($view);
|
||||
if($view) {
|
||||
$ret_html .= &VIEW_CGI_RIGHT($view);
|
||||
}
|
||||
else{
|
||||
$ret_html .= "<div id=\"content\">\n";
|
||||
$ret_html .= "</div>\n";
|
||||
}
|
||||
# HTML
|
||||
$ret_html .= "</body>\n";
|
||||
$ret_html .= "</html>\n";
|
||||
return ("text/html; charset=ISO-8859-1", $ret_html);
|
||||
# return ("text/plain; charset=ISO-8859-1", $ret_html);
|
||||
}
|
||||
#-------------------------------------------------------------------------------
|
||||
sub VIEW_CGI_CSS() {
|
||||
my $css;
|
||||
$css = "<style type=\"text/css\"><!--\n";
|
||||
$css .= "\#left {float: left; width: 15%; height:100%;}\n";
|
||||
$css .= "table.VIEW { border:thin solid; background: #E0E0E0; text-align:left;}\n";
|
||||
$css .= "table.VIEW tr.odd { background: #F0F0F0;}\n";
|
||||
$css .= "table.VIEW td.odd { background: #F0F0F0;}\n";
|
||||
$css .= "table.VIEW td {nowrap;}";
|
||||
$css .= "\/\/--><\/style>";
|
||||
return $css;
|
||||
}
|
||||
#-------------------------------------------------------------------------------
|
||||
sub VIEW_CGI_TOP($) {
|
||||
@ -123,7 +106,12 @@ sub VIEW_CGI_TOP($) {
|
||||
$rh .= "<form method=\"get\" action=\"" . $FW_ME . "\">\n";
|
||||
$rh .= "<table WIDTH=\"100%\">\n";
|
||||
$rh .= "<tr>";
|
||||
$rh .= "<td><a href=\"" . $FW_ME . "\">FHEM:</a>$v</td>";
|
||||
if($v) {
|
||||
$rh .= "<td><a href=\"" . $FW_ME . "\">FHEM:</a>$v</td>";
|
||||
}
|
||||
else {
|
||||
$rh .= "<td><a href=\"" . $FW_ME . "\">FHEM:</a></td>";
|
||||
}
|
||||
$rh .= "<td><input type=\"text\" name=\"cmd\" size=\"30\"/></td>";
|
||||
$rh .= "</tr>\n";
|
||||
$rh .= "</table>\n";
|
||||
@ -136,7 +124,6 @@ sub VIEW_CGI_TOP($) {
|
||||
sub VIEW_CGI_LEFT(){
|
||||
# rh = return-Html
|
||||
my $rh;
|
||||
# $rh = "<div id=\"left\">\n";
|
||||
$rh = "<div id=\"logo\"><img src=\"" . $FW_ME . "/fhem.png\"></div>";
|
||||
$rh .= "<div id=\"menu\">\n";
|
||||
# Print VIEWS
|
||||
@ -169,60 +156,119 @@ sub VIEW_CGI_RIGHT(){
|
||||
if(defined($attr{$v}{ViewRegExReading})) {
|
||||
$f_reading = $attr{$v}{ViewRegExReading};
|
||||
}
|
||||
my $f_reading_val = ".*";
|
||||
if(defined($attr{$v}{ViewRegExReadingStringCompare})) {
|
||||
$f_reading_val = $attr{$v}{ViewRegExReadingStringCompare};
|
||||
}
|
||||
my $row = 1;
|
||||
$rh = "<div id=\"content\">\n";
|
||||
$rh .= "<hr>\n";
|
||||
$rh .= "[RegEx] Type: \"$f_type\" Name: \"$f_name\" Reading: \"$f_reading\"\n";
|
||||
$rh .= "[RegEx] Type: \"$f_type\" Name: \"$f_name\" Reading: \"$f_reading\" Value:\"$f_reading_val\"\n";
|
||||
$rh .= "<hr>\n";
|
||||
my ($d,$r,$tr_class);
|
||||
my $th = undef;
|
||||
# Get Devices and Readings
|
||||
# $rh .= "<table class=\"VIEW\" WIDTH=\"85%\">\n";
|
||||
foreach $d (sort keys %defs){
|
||||
if($defs{$d}{TYPE} =~ m/$f_type/ && $d =~ m/$f_name/){
|
||||
# Weblink
|
||||
if($defs{$d}{TYPE} eq "weblink") {
|
||||
$rh .= "<table class=\"VIEW\">\n";
|
||||
$rh .= FW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
||||
$rh .= "</table>\n";
|
||||
}
|
||||
else {
|
||||
foreach $r (sort keys %{$defs{$d}{READINGS}}) {
|
||||
if($r =~ m/$f_reading/) {
|
||||
$tr_class = $row?"odd":"even";
|
||||
if(!$th) {
|
||||
$rh .= "<br>\n";
|
||||
$rh .= "<table class=\"VIEW\">\n";
|
||||
# $rh .= "<table class=\"VIEW\" WIDTH=\"85%\">\n";
|
||||
$rh .= "<tr class=\"" . $tr_class . "\">";
|
||||
$rh .= "<td align=\"left\"><a href=\"$FW_ME?detail=$d\">$d</a></td>";
|
||||
$rh .= "<td></td>";
|
||||
$rh .= "<td>" . $defs{$d}{TYPE} . "</td>";
|
||||
$rh .= "<td>" . $defs{$d}{STATE} . "</td>";
|
||||
$rh .= "</tr>\n";
|
||||
$th = 1;
|
||||
$row = ($row+1)%2;
|
||||
$tr_class = $row?"odd":"even";
|
||||
}
|
||||
$rh .= "<tr class=\"" . $tr_class . "\">";
|
||||
$rh .= "<td></td>";
|
||||
$rh .= "<td>$r</td>";
|
||||
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{VAL} . "</td>";
|
||||
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{TIME} . "</td>";
|
||||
$rh .= "</tr>\n";
|
||||
$row = ($row+1)%2;
|
||||
}
|
||||
if($defs{$d}{TYPE} =~ m/$f_type/ && $d =~ m/$f_name/){
|
||||
# Log 0,"VIEW-RIGHT: Device-Match $d";
|
||||
# Weblink
|
||||
my $web_rt;
|
||||
if($defs{$d}{TYPE} eq "weblink" && $f_reading eq ".*" && $f_reading_val eq ".*") {
|
||||
$rh .= "<table class=\"block\">\n";
|
||||
$rh .="<tr><td>WEBLINK: $d</td></tr>\n";
|
||||
# $rh .= FW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
||||
$rh .= VIEW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
||||
# Log 0,"VIEW-RIGHT: FW_showWeblink \n $web_rt\n";
|
||||
# FW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
||||
# Log 0,"VIEW-RIGHT: Render-Weblink $d";
|
||||
$rh .= "</table>\n";
|
||||
}
|
||||
else {
|
||||
foreach $r (sort keys %{$defs{$d}{READINGS}}) {
|
||||
if($r =~ m/$f_reading/) {
|
||||
# ViewRegExReadingStringCompare
|
||||
if($defs{$d}{READINGS}{$r}{VAL} =~ m/$f_reading_val/){
|
||||
$tr_class = $row?"odd":"even";
|
||||
if(!$th) {
|
||||
$rh .= "<br>\n";
|
||||
$rh .= "<table class=\"block\" id=\"" . $defs{$d}{TYPE} . "\" >\n";
|
||||
$rh .= "<tr class=\"" . $tr_class . "\">";
|
||||
$rh .= "<td align=\"left\"><a href=\"$FW_ME?detail=$d\">$d</a></td>";
|
||||
if(defined($attr{$d}{comment})) {
|
||||
$rh .= "<td>" . $attr{$d}{comment} . "</td>";
|
||||
}
|
||||
else {
|
||||
$rh .= "<td>" . $defs{$d}{TYPE} . "</td>";
|
||||
}
|
||||
$rh .= "<td>" . $defs{$d}{STATE} . "</td>";
|
||||
$rh .= "</tr>\n";
|
||||
$th = 1;
|
||||
$row = ($row+1)%2;
|
||||
$tr_class = $row?"odd":"even";
|
||||
}
|
||||
$rh .= "<tr class=\"" . $tr_class . "\">";
|
||||
$rh .= "<td>$r</td>";
|
||||
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{VAL} . "</td>";
|
||||
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{TIME} . "</td>";
|
||||
$rh .= "</tr>\n";
|
||||
$row = ($row+1)%2;
|
||||
# ViewRegExReadingStringCompare
|
||||
}
|
||||
}
|
||||
}
|
||||
$rh .= "</table>\n";
|
||||
}
|
||||
$rh .= "</table>\n";
|
||||
# $rh .= "<br>\n";
|
||||
}
|
||||
}
|
||||
$th = undef;
|
||||
|
||||
}
|
||||
# $rh .= "</table>\n";
|
||||
$rh .= "</div>\n";
|
||||
return $rh;
|
||||
}
|
||||
#-------------------------------------------------------------------------------
|
||||
sub VIEW_showWeblink($$$)
|
||||
{
|
||||
# Customized Function from 01_FHEMWEB.pm
|
||||
my $FW_plotmode = "gnuplot-scroll";
|
||||
my $FW_plotsize = "800,225";
|
||||
my ($d, $v, $t) = @_;
|
||||
my $rh;
|
||||
if($t eq "link") {
|
||||
$rh .= "<td><a href=\"$v\">$d</a></td>\n"; # no pH, want to open extra browser
|
||||
}
|
||||
elsif($t eq "image") {
|
||||
$rh .= "<td><img src=\"$v\"><br>";
|
||||
$rh .= "<a href=\"$FW_ME?detail=$d\">$d</a>";
|
||||
$rh .= "</td>\n";
|
||||
}
|
||||
elsif($t eq "fileplot") {
|
||||
my @va = split(":", $v, 3);
|
||||
if(@va != 3 || !$defs{$va[0]} || !$defs{$va[0]}{currentlogfile}) {
|
||||
$rh .= "<td>Broken definition: $v</td>\n";
|
||||
}
|
||||
else {
|
||||
if($va[2] eq "CURRENT") {
|
||||
$defs{$va[0]}{currentlogfile} =~ m,([^/]*)$,;
|
||||
$va[2] = $1;
|
||||
}
|
||||
$rh .= "<table><tr><td>";
|
||||
my $wl = "&pos=";
|
||||
my $arg="$FW_ME?cmd=showlog $d $va[0] $va[1] $va[2]$wl";
|
||||
if(AttrVal($d,"plotmode",$FW_plotmode) eq "SVG") {
|
||||
my ($w, $h) = split(",", AttrVal($d,"plotsize",$FW_plotsize));
|
||||
$rh .= "<embed src=\"$arg\" type=\"image/svg+xml\"" .
|
||||
"width=\"$w\" height=\"$h\" name=\"$d\"/>\n";
|
||||
}
|
||||
else {
|
||||
$rh .= "<img src=\"$arg\"/>";
|
||||
}
|
||||
$rh .= "</td>\n";
|
||||
$rh .= "<td><a href=\"$FW_ME?detail=$d\">$d</a></td>\n";
|
||||
$rh .= "</tr></table>";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user