2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 18:56:03 +00:00

longpollSVG added

git-svn-id: https://svn.fhem.de/fhem/trunk@3307 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-06-19 16:17:13 +00:00
parent d55d8e29b4
commit ad453f5cc5
5 changed files with 66 additions and 16 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII
- SVN
- feature: FHEMWEB: longpoll is default now, longpollSVG (default off) added
- feature: HUEDevice: allow usage of openautomation svg icons
- feature: FHEMWEB: svg icons / iconPath / www/images/openautomation added
- feature: FHEMWEB: SVGcache attribute & clearSvgCache set command added

View File

@ -118,8 +118,8 @@ FHEMWEB_Initialize($)
"plotmode:gnuplot,gnuplot-scroll,SVG plotsize endPlotToday:1,0 plotfork ".
"stylesheetPrefix touchpad:deprecated smallscreen:deprecated ".
"basicAuth basicAuthMsg hiddenroom hiddengroup HTTPS allowfrom CORS:0,1 ".
"refresh longpoll:1,0 redirectCmds:0,1 reverseLogs:0,1 menuEntries ".
"roomIcons SVGcache iconPath";
"refresh longpoll:0,1 longpollSVG:1,0 redirectCmds:0,1 reverseLogs:0,1 ".
"menuEntries roomIcons SVGcache iconPath";
###############
# Initialize internal structures
@ -550,7 +550,7 @@ FW_answerCall($)
FW_pO sprintf($jsTemplate, "$FW_ME/pgm2/svg.js") if($FW_plotmode eq "SVG");
FW_pO sprintf($jsTemplate, "$FW_ME/pgm2/fhemweb.js");
my $onload = AttrVal($FW_wname, "longpoll", undef) ?
my $onload = AttrVal($FW_wname, "longpoll", 1) ?
"onload=\"FW_delayedStart()\"" : "";
FW_pO "</head>\n<body name=\"$t\" $onload>";
@ -1527,7 +1527,7 @@ FW_showLog($)
FW_fC("get $d $file INT $f $t " . join(" ", @{$flog}), 1);
($cfg, $plot) = FW_substcfg(1, $wl, $cfg, $plot, $file, "<OuT>");
$ret = SVG_render($wl, $f, $t, $cfg,
$internal_data, $plot, $FW_wname, $FW_cssdir);
$internal_data, $plot, $FW_wname, $FW_cssdir, $flog);
FW_pO $ret;
if($SVGcache) {
mkdir($cDir) if(! -d $cDir);
@ -2319,7 +2319,7 @@ FW_roomStatesForInform($)
foreach my $dn (@rl) {
my ($allSet, $cmdlist, $txt) = FW_devState($dn, "", \%extPage);
$data .= "$dn<<$defs{$dn}{STATE}<<$txt\r\n"
if($defs{$dn} && $defs{$dn}{STATE});
if($defs{$dn} && $defs{$dn}{STATE} && $defs{$dn}{TYPE} ne "weblink");
}
return $data;
}
@ -2463,7 +2463,7 @@ FW_devState($$@)
}
$link .= "&room=$room";
}
if(AttrVal($FW_wname, "longpoll", undef)) {
if(AttrVal($FW_wname, "longpoll", 1)) {
$txt = "<a onClick=\"FW_cmd('$FW_ME$FW_subdir?XHR=1&$link')\">$txt</a>";
} elsif($FW_ss || $FW_tp) {
@ -2930,9 +2930,25 @@ FW_dropdownFn()
In this mode status update is refreshed more or less instantaneously,
and state change (on/off only) is done without requesting a complete
refresh from the server.
Default is on.
</li>
<br>
<a name="longpollSVG"></a>
<li>longpollSVG<br>
Reloads an SVG weblink, if an event should modify its content. Since
an exact determination of the affected events is too complicated, we
need some help from the #FileLog definition in the .gplot file: the
filter used there (second parameter) must either contain only the
deviceName or have the form deviceName.event or deviceName.*. This is
always the case when using the <a href="#weblinkEditor">Plot
editor</a>. The SVG will be reloaded for <b>any</b> event triggered by
this deviceName.
Default is off.
</li>
<br>
<a name="redirectCmds"></a>
<li>redirectCmds<br>
Clear the browser URL window after issuing the command by redirecting

View File

@ -385,7 +385,7 @@ FileLog_Get($@)
if($inf eq "-") {
# In case the plot is drawn afte midnight, before the first event is logged.
# In case now is after midnight, before the first event is logged.
FileLog_Switch($hash);
$inf = $hash->{currentlogfile};
@ -414,7 +414,6 @@ FileLog_Get($@)
if(!-f $linf) {
# ... or in the archivelog
$linf = AttrVal($hash->{NAME},"archivedir",".") ."/". $inf;
$linf = "";
}
$inf = $linf;
}

View File

@ -9,7 +9,7 @@ use POSIX;
sub SVG_render($$$$$$$$);
sub SVG_render($$$$$$$$$);
sub SVG_time_to_sec($);
sub SVG_fmtTime($$);
sub SVG_time_align($$);
@ -76,7 +76,7 @@ SVG_digestConf($$)
#####################################
sub
SVG_render($$$$$$$$)
SVG_render($$$$$$$$$)
{
my $name = shift; # e.g. wl_8
my $from = shift; # e.g. 2008-01-01
@ -86,6 +86,7 @@ SVG_render($$$$$$$$)
my $plot = shift; # Plot lines from the .gplot file
my $parent_name = shift; # e.g. FHEMWEB instance name
my $parent_dir = shift; # FW_dir
my $flog = shift; # #FileLog lines, as array pointer
$SVG_RET="";
@ -103,12 +104,17 @@ SVG_render($$$$$$$$)
my ($ow,$oh) = split(",", $ps); # Original width
my ($w, $h) = ($ow-2*$x, $oh-2*$y); # Rect size
# Keep only the Filter part of the #FileLog
$flog = join(" ", map { my @a=split(":",$_);
$a[1]=~s/\.[^\.]*$//; $a[1]; } @{$flog});
$flog = AttrVal($parent_name, "longpollSVG", 0) ? "flog=\"$flog\"" : "";
######################
# Html Header
SVG_pO '<?xml version="1.0" encoding="UTF-8"?>';
SVG_pO '<!DOCTYPE svg>';
SVG_pO '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" '.
'xmlns:xlink="http://www.w3.org/1999/xlink" >';
'xmlns:xlink="http://www.w3.org/1999/xlink" '.$flog.'>';
my $prf = AttrVal($parent_name, "stylesheetPrefix", "");
SVG_pO "<style type=\"text/css\"><![CDATA[";

View File

@ -28,6 +28,7 @@ FW_doUpdate()
//Pop the last (maybe empty) line after the last "\n"
//We wait until it is complete, i.e. terminated by "\n"
lines.pop();
var devs = new Array();
for(var i=FW_curLine; i < lines.length; i++) {
var d = lines[i].split("<<", 3); // Complete arg
if(d.length != 3)
@ -65,9 +66,33 @@ FW_doUpdate()
Slider(el, val);
}
}
if(d[0].indexOf("-") == -1) // Wont contain -
devs.push(d[0]);
}
//Next time, we continue at the next line
FW_curLine = lines.length;
// if matches, refresh the SVG by removing and readding the embed tag
var embArr = document.getElementsByTagName("embed");
for(var i = 0; i < embArr.length; i++) {
var svg = embArr[i].getSVGDocument();
if(svg == null) // too many events sometimes.
continue;
svg = svg.firstChild.nextSibling;
var flog = svg.getAttribute("flog");
for(var j=0; j < devs.length; j++) {
if(flog !== null && flog.match(" "+devs[j]+" ")) {
var e = embArr[i];
var newE = document.createElement("embed");
for(var k=0; k<e.attributes.length; k++)
newE.setAttribute(e.attributes[k].name, e.attributes[k].value);
e.parentNode.insertBefore(newE, e);
e.parentNode.removeChild(e);
break;
}
}
}
}
function
@ -81,11 +106,14 @@ FW_longpoll()
FW_pollConn = new XMLHttpRequest();
var room="room=all";
var embArr = document.getElementsByTagName("embed");
if(embArr.length == 0) { // SVG image content is not room dependent
var sa = document.location.search.substring(1).split("&");
for(var i = 0; i < sa.length; i++) {
if(sa[i].substring(0,5) == "room=")
room=sa[i];
}
}
var query = document.location.pathname+"?"+room+"&XHR=1&inform=1";
FW_pollConn.open("GET", query, true);
FW_pollConn.onreadystatechange = FW_doUpdate;