2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 19:04:20 +00:00

console.js: add filter (Forum #35421)

git-svn-id: https://svn.fhem.de/fhem/trunk@8288 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2015-03-26 13:53:13 +00:00
parent 2c3fe0633d
commit 4873e5711a
2 changed files with 34 additions and 21 deletions

View File

@ -1840,14 +1840,9 @@ FW_style($$)
FW_pO "<script type=\"text/javascript\" src=\"$FW_ME/pgm2/console.js\">". FW_pO "<script type=\"text/javascript\" src=\"$FW_ME/pgm2/console.js\">".
"</script>"; "</script>";
FW_pO "<div id=\"content\">"; FW_pO "<div id=\"content\">";
if($a[2] && $a[2] ne "1") { my $filter = ($a[2] && $a[2] ne "1") ? $a[2] : ".*";
FW_pO "<div id=\"console\" filter=\"$a[2]\">"; FW_pO "Events (Filter:<a href=\"#\" id=\"eventFilter\">$filter</a>):<br>\n";
FW_pO "Events ($a[2] only):<br>\n"; FW_pO "<div id=\"console\"></div>";
} else {
FW_pO "<div id=\"console\">";
FW_pO "Events:<br>\n";
}
FW_pO "</div>";
FW_pO "</div>"; FW_pO "</div>";
} }
@ -2305,9 +2300,10 @@ FW_Notify($$)
my ($ntfy, $dev) = @_; my ($ntfy, $dev) = @_;
my $h = $ntfy->{inform}; my $h = $ntfy->{inform};
return undef if(!$h); return undef if(!$h);
my $isStatus = ($h->{type} =~ m/status/);
my $dn = $dev->{NAME}; my $dn = $dev->{NAME};
if($dn eq "global" && $h->{type} =~ m/status/) { if($dn eq "global" && $isStatus) {
my $vs = int(@structChangeHist) ? 'visible' : 'hidden'; my $vs = int(@structChangeHist) ? 'visible' : 'hidden';
my $data = FW_longpollInfo($h->{fmt}, my $data = FW_longpollInfo($h->{fmt},
"#FHEMWEB:$ntfy->{NAME}","\$('#saveCheck').css('visibility','$vs')",""); "#FHEMWEB:$ntfy->{NAME}","\$('#saveCheck').css('visibility','$vs')","");
@ -2323,18 +2319,14 @@ FW_Notify($$)
return; return;
} }
if($h->{type} eq "raw") { return undef if($isStatus && !$h->{devices}{$dn});
return undef if($dn !~ m/$h->{filter}/);
} else { # Status
return undef if(!$h->{devices}{$dn});
}
my @data; my @data;
my %extPage; my %extPage;
my $isRaw = ($h->{type} =~ m/raw/); my $isRaw = ($h->{type} =~ m/raw/);
my $events = deviceEvents($dev, AttrVal($FW_wname, "addStateEvent",!$isRaw)); my $events = deviceEvents($dev, AttrVal($FW_wname, "addStateEvent",!$isRaw));
if($h->{type} =~ m/status/) { if($isStatus) {
# Why is saving this stuff needed? FLOORPLAN? # Why is saving this stuff needed? FLOORPLAN?
my @old = ($FW_wname, $FW_ME, $FW_ss, $FW_tp, $FW_subdir); my @old = ($FW_wname, $FW_ME, $FW_ss, $FW_tp, $FW_subdir);
$FW_wname = $ntfy->{SNAME}; $FW_wname = $ntfy->{SNAME};
@ -2382,7 +2374,8 @@ FW_Notify($$)
my $max = int(@{$events}); my $max = int(@{$events});
my $dt = $dev->{TYPE}; my $dt = $dev->{TYPE};
for(my $i = 0; $i < $max; $i++) { for(my $i = 0; $i < $max; $i++) {
push @data,("$tn $dt $dn ".$events->[$i]."<br>"); my $line = ("$tn $dt $dn ".$events->[$i]."<br>");
push @data,$line if($line =~ m/$h->{filter}/);
} }
} }
} }

View File

@ -17,11 +17,9 @@ consUpdate()
if(consConn.readyState != 3) if(consConn.readyState != 3)
return; return;
var el = document.getElementById("console"); $("#console")
if(el) { .html(consTxt+consConn.responseText)
el.innerHTML=consTxt+consConn.responseText; .scrollTop($("#console")[0].scrollHeight);
el.scrollTop = el.scrollHeight;
}
} }
function function
@ -49,6 +47,28 @@ consStart()
consFilter = ".*"; consFilter = ".*";
consTxt = el.innerHTML; consTxt = el.innerHTML;
setTimeout("consFill()", 1000); setTimeout("consFill()", 1000);
$("a#eventFilter").click(function(evt){ // Event-Filter Dialog
$('body').append(
'<div id="evtfilterdlg">'+
'<div>Filter:</div><br>'+
'<div><input id="filtertext" value="'+consFilter+'"></div>'+
'</div>');
$('#evtfilterdlg').dialog({ modal:true,
close:function(){$('#evtfilterdlg').remove();},
buttons:[
{ text:"Cancel", click:function(){ $(this).dialog('close'); }},
{ text:"OK", click:function(){
var val = $("#filtertext").val().trim();
consFilter = val ? val : ".*";
$(this).dialog('close');
$("a#eventFilter").html(consFilter);
$("#console").html(consTxt);
consFill();
}}]
});
});
} }
window.onload = consStart; window.onload = consStart;