mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 23:06:37 +00:00
98_weblink.pm: add associatedWith mode (Forum #114960)
git-svn-id: https://svn.fhem.de/fhem/trunk@23597 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
09e330dced
commit
71b61b1960
@ -30,9 +30,16 @@ weblink_Define($$)
|
|||||||
{
|
{
|
||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
my ($name, $type, $wltype, $link) = split("[ \t]+", $def, 4);
|
my ($name, $type, $wltype, $link) = split("[ \t]+", $def, 4);
|
||||||
my %thash = ( link=>1, image=>1, iframe=>1, htmlCode=>1,
|
my %thash = (
|
||||||
|
associatedWith=>1,
|
||||||
cmdList=>1,
|
cmdList=>1,
|
||||||
fileplot=>1, dbplot=>1);
|
dbplot=>1,
|
||||||
|
fileplot=>1,
|
||||||
|
htmlCode=>1,
|
||||||
|
iframe=>1,
|
||||||
|
image=>1,
|
||||||
|
link=>1,
|
||||||
|
);
|
||||||
|
|
||||||
if(!$link || !$thash{$wltype}) {
|
if(!$link || !$thash{$wltype}) {
|
||||||
return "Usage: define <name> weblink [" .
|
return "Usage: define <name> weblink [" .
|
||||||
@ -131,11 +138,97 @@ weblink_FwFn($$$$)
|
|||||||
}
|
}
|
||||||
$ret .= "</table></td></tr>";
|
$ret .= "</table></td></tr>";
|
||||||
$ret .= "</table><br>";
|
$ret .= "</table><br>";
|
||||||
|
|
||||||
|
} elsif($wltype eq "associatedWith") {
|
||||||
|
my $js = "$FW_ME/pgm2/zwave_neighborlist.js";
|
||||||
|
return
|
||||||
|
"<div id='ZWDongleNr'><a id='zw_snm' href='#'>Show neighbor map</a></div>".
|
||||||
|
"<div id='ZWDongleNrSVG'></div>".
|
||||||
|
"<script type='text/javascript' src='$js'></script>".
|
||||||
|
'<script type="text/javascript">'.<<"JSEND"
|
||||||
|
\$(document).ready(function() {
|
||||||
|
\$("div#ZWDongleNr a#zw_snm")
|
||||||
|
.click(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
zw_nl('webdev_AWData("$d")');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
JSEND
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
webdev_AWData($)
|
||||||
|
{
|
||||||
|
my ($me) = @_;
|
||||||
|
|
||||||
|
my (%h, @ds);
|
||||||
|
my ($fo, $foCount, $level) = ("", 0, 0);
|
||||||
|
my @l = split(" ", $defs{$me}{LINK});
|
||||||
|
|
||||||
|
@ds = devspec2array($l[0]);
|
||||||
|
for(;;) {
|
||||||
|
$level++;
|
||||||
|
my %new;
|
||||||
|
foreach my $d (@ds) {
|
||||||
|
next if($h{$d} || !$defs{$d} || $defs{$d}{TEMPORARY});
|
||||||
|
my @paw = getPawList($d);
|
||||||
|
map { $new{$_}=1 if(!$h{$_}) } @paw;
|
||||||
|
my $a = AttrVal($d,"alias","");
|
||||||
|
my $r = AttrVal($d,"room","");
|
||||||
|
$h{$d}{title} =
|
||||||
|
($a ? "Alias:$a ":"").
|
||||||
|
($r ? "room:$r ":"").
|
||||||
|
("type:".$defs{$d}{TYPE});
|
||||||
|
$h{$d}{neighbors} = \@paw;
|
||||||
|
$h{$d}{class} = ($level == 1 ? "zwDongle" : "zwBox");
|
||||||
|
$h{$d}{txt} = $d;
|
||||||
|
$h{$d}{neighbors} = \@paw;
|
||||||
|
|
||||||
|
$fo = $d if(!$fo);
|
||||||
|
if($level == 1 && $foCount < int(@paw)) {
|
||||||
|
$foCount = int(@paw);
|
||||||
|
$fo = $d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last if($l[1] && $l[1] <= $level);
|
||||||
|
@ds = keys %new;
|
||||||
|
last if(!@ds);
|
||||||
|
}
|
||||||
|
|
||||||
|
my @ret;
|
||||||
|
my @dp = split(" ", AttrVal($me, "htmlattr", ""));
|
||||||
|
my %dp = @dp;
|
||||||
|
for my $k (keys %h) {
|
||||||
|
my $n = $h{$k}{neighbors};
|
||||||
|
push @ret, '"'.$k.'":{'.
|
||||||
|
'"class":"'.$h{$k}{class}.' col_link col_oddrow",'.
|
||||||
|
'"txt":"'.$h{$k}{txt}.'",'.
|
||||||
|
'"title":"'.$h{$k}{title}.'",'.
|
||||||
|
'"pos":['.($dp{$k} ? $dp{$k} : '').'],'.
|
||||||
|
'"neighbors":['. (@{$n} ? ('"'.join('","',@{$n}).'"'):'').']}';
|
||||||
|
}
|
||||||
|
|
||||||
|
my $r = '{"firstObj":"'.$fo.'",'.
|
||||||
|
'"el":{'.join(",",@ret).'},'.
|
||||||
|
'"skipArrow":true,'.
|
||||||
|
'"saveFn":"{webdev_AWaddPos(\''.$me.'\',\'{1}\',\'{2}\')}" }';
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
webdev_AWaddPos($$$)
|
||||||
|
{
|
||||||
|
my ($me, $d, $pos) = @_;
|
||||||
|
my @dp = split(" ", AttrVal($me, "htmlattr", ""));
|
||||||
|
my %dp = @dp;
|
||||||
|
$dp{$d} = $pos;
|
||||||
|
CommandAttr(undef,"$me htmlattr ".join(" ",map {"$_ $dp{$_}"} sort keys %dp));
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
@ -150,7 +243,8 @@ weblink_FwFn($$$$)
|
|||||||
<a name="weblinkdefine"></a>
|
<a name="weblinkdefine"></a>
|
||||||
<b>Define</b>
|
<b>Define</b>
|
||||||
<ul>
|
<ul>
|
||||||
<code>define <name> weblink [link|image|iframe|htmlCode|cmdList]
|
<code>define <name> weblink
|
||||||
|
[link|image|iframe|htmlCode|cmdList|associatedWidth]
|
||||||
<argument></code>
|
<argument></code>
|
||||||
<br><br>
|
<br><br>
|
||||||
This is a placeholder device used with FHEMWEB to be able to add user
|
This is a placeholder device used with FHEMWEB to be able to add user
|
||||||
@ -167,14 +261,21 @@ weblink_FwFn($$$$)
|
|||||||
pair:Pair:set+cul2+hmPairForSec+60
|
pair:Pair:set+cul2+hmPairForSec+60
|
||||||
restart:Restart:shutdown+restart
|
restart:Restart:shutdown+restart
|
||||||
update:UpdateCheck:update+check
|
update:UpdateCheck:update+check
|
||||||
|
define aw weblink associatedWith rgr_Residents 3
|
||||||
</code>
|
</code>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
<ul>
|
<ul>
|
||||||
<li>For cmdList <argument> consists of a list of space
|
<li>For cmdList <argument> consists of a list of space separated
|
||||||
separated icon:label:cmd triples.</li>
|
icon:label:cmd triples.</li>
|
||||||
|
|
||||||
|
<li>the associatedWidth mode takes a devspec and an optional depth as
|
||||||
|
arguments, and follows the devices along the "probably associated with"
|
||||||
|
links seen on the detail page for depth iterations. The so collected data
|
||||||
|
can be displayed as an SVG graph.</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ zw_nl(fhemFn)
|
|||||||
zw_visible = !zw_visible;
|
zw_visible = !zw_visible;
|
||||||
var txt = (zw_visible ? 'Hide' : 'Show');
|
var txt = (zw_visible ? 'Hide' : 'Show');
|
||||||
|
|
||||||
var width=960,height=480;
|
var width=$("#content").width()-20,
|
||||||
|
height=$("#content").height()-20;
|
||||||
$('#ZWDongleNr a#zw_snm').html(txt+' neighbor map');
|
$('#ZWDongleNr a#zw_snm').html(txt+' neighbor map');
|
||||||
|
|
||||||
if(!zw_visible) {
|
if(!zw_visible) {
|
||||||
@ -51,8 +52,7 @@ zw_nl(fhemFn)
|
|||||||
el.x = el.pos[0]; el.y = el.pos[1];
|
el.x = el.pos[0]; el.y = el.pos[1];
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
if(height < cnt*35)
|
|
||||||
height = cnt*35;
|
|
||||||
zw_draw(fnRet, width, height);
|
zw_draw(fnRet, width, height);
|
||||||
$('#ZWDongleNr a#zw_al').click(function(){ zw_al(fnRet, width, height); });
|
$('#ZWDongleNr a#zw_al').click(function(){ zw_al(fnRet, width, height); });
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ zw_draw(fnRet, width, height)
|
|||||||
for(var o in h) {
|
for(var o in h) {
|
||||||
if(h[o].txt && h[o].neighbors)
|
if(h[o].txt && h[o].neighbors)
|
||||||
for(var i1=0; i1<h[o].neighbors.length; i1++)
|
for(var i1=0; i1<h[o].neighbors.length; i1++)
|
||||||
svg += zw_drawline(ld, h, o, i1);
|
svg += zw_drawline(fnRet, ld, h, o, i1);
|
||||||
}
|
}
|
||||||
for(var o in h)
|
for(var o in h)
|
||||||
if(h[o].txt)
|
if(h[o].txt)
|
||||||
@ -179,16 +179,18 @@ zw_calcPos(o, n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function
|
function
|
||||||
zw_drawline(ld, h, o, i1)
|
zw_drawline(fnRet, ld, h, o, i1)
|
||||||
{
|
{
|
||||||
var n = h[o].neighbors[i1];
|
var n = h[o].neighbors[i1];
|
||||||
var ns = (h[o].neighborstyles ? h[o].neighborstyles[i1] : "")
|
var ns = (h[o].neighborstyles ? h[o].neighborstyles[i1] : "")
|
||||||
if(!h[o] || !h[n])
|
if(!h[o] || !h[n])
|
||||||
return "";
|
return "";
|
||||||
var bidi = false;
|
var bidi = false;
|
||||||
|
if(!fnRet.skipArrow) {
|
||||||
for(var i1=0; i1<h[n].neighbors.length; i1++)
|
for(var i1=0; i1<h[n].neighbors.length; i1++)
|
||||||
if(h[n].neighbors[i1] == o)
|
if(h[n].neighbors[i1] == o)
|
||||||
bidi = true;
|
bidi = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(n < o) {
|
if(n < o) {
|
||||||
var t = n; n = o; o = t;
|
var t = n; n = o; o = t;
|
||||||
@ -204,7 +206,7 @@ zw_drawline(ld, h, o, i1)
|
|||||||
return '<line class="zwLine col_link '+ns+'" data-name="'+cl+
|
return '<line class="zwLine col_link '+ns+'" data-name="'+cl+
|
||||||
'" x1="'+fr.x+'" y1="'+fr.y+
|
'" x1="'+fr.x+'" y1="'+fr.y+
|
||||||
'" x2="'+to.x+'" y2="'+to.y+'"'+
|
'" x2="'+to.x+'" y2="'+to.y+'"'+
|
||||||
' marker-end="url(#endarrow)"'+
|
(!fnRet.skipArrow ? ' marker-end="url(#endarrow)"':'')+
|
||||||
(bidi?' marker-start="url(#startarrow)"':'')+
|
(bidi?' marker-start="url(#startarrow)"':'')+
|
||||||
'/>';
|
'/>';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user