From 2aab6090de6fb46e5424095564ef5dec1b9d6891 Mon Sep 17 00:00:00 2001 From: svenson08 <> Date: Wed, 1 Jan 2014 20:55:13 +0000 Subject: [PATCH] fixed bugs. git-svn-id: https://svn.fhem.de/fhem/trunk@4521 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/95_Dashboard.pm | 303 +++++++++++++++++++++++++++++++------ fhem/www/pgm2/dashboard.js | 19 +-- 2 files changed, 266 insertions(+), 56 deletions(-) diff --git a/fhem/FHEM/95_Dashboard.pm b/fhem/FHEM/95_Dashboard.pm index d5bfacc2e..fb3ecc8ed 100644 --- a/fhem/FHEM/95_Dashboard.pm +++ b/fhem/FHEM/95_Dashboard.pm @@ -19,12 +19,16 @@ # Fix duplicated run of JS Script. Dashboard STAT show "Missing File" Information if installation is wrong. # 0007: use jquery.min and jquery-ui.min. add dashboard_debug attribute. Check dashboard_sorting value plausibility. # Change default Values. First Release to FHEM SVN. +# 0008: Add Germyn command_ref Text. Add Default Values to command_ref (@cotecmania). Fix identification of an existing +# Dashboard-Weblink (Message *_weblink already defined, delete it first on rereadcfg). Remove white space from +# both ends of a group in dashboard_groups. Fix dashboard_sorting check. Wrong added hiddenroom to FHEMWEB +# Browsersession fixed. Buttonbar can now placed on top or bottom of the Dashboard (@cotecmania). +# Dashboard is always edited out the Room Dashboard (@justme1968) +# Fix Dashboard Entry over the Room-List after 01_FHEMWEB.pm changes # # Known Bugs/Todos: -# 95_Dashboard.pm : Message *_weblink already defined, delete it first on rereadcfg -# Dashboard.js : No Change to iconplus on restoreOrder -# Add German commandref =begin html_DE / =end html_DE # Add/Write FHEM Wiki-Doku +# Nachträglich hinzufügen von gruppen ######################################################################################## # # This program is free software: you can redistribute it and/or modify @@ -59,12 +63,14 @@ use vars qw($FW_room); # currently selected room use vars qw(%defs); # FHEM device/button definitions use vars qw($FW_wname); # Web instance use vars qw(%FW_hiddenroom);# hash of hidden rooms, used by weblink -use vars qw(%FW_types); # device types, +use vars qw(%FW_types); # device types -# --------------------------- Globale Variabeln ---------------------------------------------- +# --------------------------- Global Variable ----------------------------------------------- my %group; my $fwjquery = "jquery.min.js"; my $fwjqueryui = "jquery-ui.min.js"; +my $dashboardname = "Dashboard"; # Link Text +my $dashboardhiddenroom = "DashboardRoom"; # Hiddenroom # ------------------------------------------------------------------------------------------- sub Dashboard_Initialize ($) { @@ -82,15 +88,15 @@ sub Dashboard_Initialize ($) { "dashboard_groups ". "dashboard_lockstate:unlock,lock ". "dashboard_colcount:1,2,3,4,5 ". - "dashboard_showbuttonbar:0,1 ". + "dashboard_showbuttonbar:top,bottom,hidden ". "dashboard_showhelper:0,1 ". "dashboard_showtooglebuttons:0,1 ". "dashboard_row:top,center,bottom,top-center,center-bottom,top-center-bottom ". "dashboard_debug:0,1 ". $readingFnAttributes; - $data{FWEXT}{Dashboard}{LINK} = "?room=Dashboard"; - $data{FWEXT}{Dashboard}{NAME} = "Dashboard"; + $data{FWEXT}{Dashboardx}{LINK} = "?room=".$dashboardhiddenroom; + $data{FWEXT}{Dashboardx}{NAME} = $dashboardname; return undef; } @@ -105,6 +111,8 @@ sub DashboardAsHtml($) my $h = $defs{$d}; my $name = $defs{$d}{NAME}; my $id = $defs{$d}{NR}; + + ############# Read Dashboard Attributes and set Default-Values ############################## my $disable = AttrVal($defs{$d}{NAME}, "disable", 0); my $sorting = AttrVal($defs{$d}{NAME}, "dashboard_sorting", ","); my $colcount = AttrVal($defs{$d}{NAME}, "dashboard_colcount", 1); @@ -114,31 +122,43 @@ sub DashboardAsHtml($) my $rowbottomheight = AttrVal($defs{$d}{NAME}, "dashboard_rowbottomheight", 250); my $showhelper = AttrVal($defs{$d}{NAME}, "dashboard_showhelper", 1); my $lockstate = AttrVal($defs{$d}{NAME}, "dashboard_lockstate", "unlock"); - my $showbuttonbar = AttrVal($defs{$d}{NAME}, "dashboard_showbuttonbar", 1); + my $showbuttonbar = AttrVal($defs{$d}{NAME}, "dashboard_showbuttonbar", "top"); my $showtooglebuttons = AttrVal($defs{$d}{NAME}, "dashboard_showtooglebuttons", 1); my $row = AttrVal($defs{$d}{NAME}, "dashboard_row", "center"); my $debug = AttrVal($defs{$d}{NAME}, "dashboard_debug", "0"); my $dashboardgroups = AttrVal($defs{$d}{NAME}, "dashboard_groups", ""); - - if ($sorting !~ /,:[0-9]/ && $sorting ne ",") {Log3 $d, 3, "[".$name. "] Value of attribut dashboard_sorting is wrong. Saved sorting can not be set. Fix Value or delete the Attribute.";} + ############################################################################################# + + #---------------- Dashboard is always edited out the Room Dashboard ------------------------- + if ($FW_room ne $dashboardhiddenroom) { #Dashboard is always edited out the Room Dashboard + if ($showbuttonbar eq "hidden") {$showbuttonbar = "top" }; + $showhelper = 1; + $showtooglebuttons = 1; + $lockstate = "unlock"; + } + #---------------------------------------------------------------------------- + if ($disable == 1) { $defs{$d}{STATE} = "disabled"; } + if ($dashboardgroups eq "") { $defs{$d}{STATE} = "No Groups set"; } return $ret if (($dashboardgroups eq "") || ($disable == 1)); + if ($debug == 1) { $debugfield = "edit" }; + if ($showbuttonbar eq "hidden") { $lockstate = "lock" }; if (not ($colwidth =~ /^\d+$/)) { $colwidth = 320 }; if (not ($colheight =~ /^\d+$/)) { $colheight = 400 }; if (not ($rowtopheight =~ /^\d+$/)) { $rowtopheight = 50 }; - if (not ($rowbottomheight =~ /^\d+$/)) { $rowbottomheight = 50 }; + if (not ($rowbottomheight =~ /^\d+$/)) { $rowbottomheight = 50 }; + #------------------- Check dashboard_sorting on false content ------------------------------------ + if (($sorting !~ /[0-9]/ || $sorting !~ /:/ || $sorting !~ /,/ ) && ($sorting ne ",")){ + Log3 $d, 3, "[".$name."] Value of attribut dashboard_sorting is wrong. Saved sorting can not be set. Fix Value or delete the Attribute."; + } else { Log3 $d, 5, "[".$name."] Sorting OK: ".$sorting; } + #------------------------------------------------------------------------------------------------- + %group = BuildGroupList($dashboardgroups); $ret .= ""; - ############################ Dashboard-Optionbar ################################################# - if ($showbuttonbar == 1) { - $ret .= ""; - } else { $lockstate = "lock"; } + ############################ Dashboard-Optionbar ############################################ + if ($showbuttonbar eq "top") { $ret .= BuildButtonBar($d); } ############################################################################################# $ret .= ""; } ############################################################################################# + + ############################ Dashboard-Optionbar ############################################ + if ($showbuttonbar eq "bottom") { $ret .= BuildButtonBar($d); } + ############################################################################################# + $ret .= "
"; - $ret .= "
Set
"; - $ret .= " "; - $ret .= " "; - $ret .= "
"; @@ -165,6 +185,7 @@ sub DashboardAsHtml($) $ret .= "
"; my @dashboardgroups = split(",", $dashboardgroups); for (my $i=0;$i<@dashboardgroups;$i++){ + $dashboardgroups[$i] = trim($dashboardgroups[$i]); #remove white space from both ends of a string $dashboardgroups[$i] =~ tr/<+>/ /; #Fix Groupname if use wrong Groupnames from Bestpractice beginner configuration $ret .= "
"; $ret .= "
"; @@ -174,7 +195,7 @@ sub DashboardAsHtml($) $ret .= "
"; $ret .= "
"; $ret .= "
"; - } + } $ret .= "
"; $ret .= BuildEmptyColumn($colcount); $ret .= ""; @@ -192,11 +213,26 @@ sub DashboardAsHtml($) $ret .= "
"; return $ret; } +sub BuildButtonBar($){ + my ($d) = @_; + my $ret; + $ret .= "
"; + $ret .= "
Set
"; + $ret .= "
Lock
"; + $ret .= "
Detail
"; + $ret .= "
"; +} + sub BuildGroupList($) { #---------------------------------------------------------------------------------------------------------- my @dashboardgroups = split(",", $_[0]); #array for all groups to build an widget @@ -204,9 +240,13 @@ sub BuildGroupList($) { foreach my $d (sort keys %defs) { foreach my $grp (split(",", AttrVal($d, "group", ""))) { - foreach my $g (@dashboardgroups){ $group{$grp}{$d} = 1 if($g eq $grp); } + $grp = trim($grp); + foreach my $g (@dashboardgroups){ + $g = trim($g); + $group{$grp}{$d} = 1 if($g eq $grp); + } } - } + } #---------------------------------------------------------------------------------------------------------- return %group; } @@ -314,42 +354,82 @@ sub CheckInstallation($) { } } +sub CheckDashboardEntry($) { + my ($hash) = @_; + my $now = time(); + my $timeToExec = $now + 5; + + RemoveInternalTimer($hash); + InternalTimer ($timeToExec, 'CreateDashboardEntry', $hash, 0); + InternalTimer ($timeToExec, 'CheckDashboardAttributUssage', $hash, 0); +} + +sub CheckDashboardAttributUssage($) { # replaces old disused attributes and their values + my ($hash) = @_; + my $d = $hash->{NAME}; + + # Replae older dashboard_showbuttonbar value (outdated 01.2014) + my $showbuttonbarvalue = AttrVal($defs{$d}{NAME}, "dashboard_showbuttonbar", "top"); + if ($showbuttonbarvalue eq "0") { FW_fC("attr ".$d." dashboard_showbuttonbar hidden"); } + if ($showbuttonbarvalue eq "1") { FW_fC("attr ".$d." dashboard_showbuttonbar top"); } + + # Get out any change to the Logfile + if ($showbuttonbarvalue eq "0" || $showbuttonbarvalue eq "1") { + Log3 $hash, 3, "[".$hash->{NAME}. "]"." Using an outdated no longer used Attribute or Value. This has been corrected. Don't forget to save config."; + } +} + sub CreateDashboardEntry($) { my ($hash) = @_; - + my $h = $hash->{NAME}; if (!defined $defs{$h."_weblink"}) { FW_fC("define ".$h."_weblink weblink htmlCode {DashboardAsHtml(\"".$h."\")}"); Log3 $hash, 3, "[".$hash->{NAME}. "]"." Weblink dosen't exists. Created weblink ".$h."_weblink. Don't forget to save config."; } - FW_fC("attr ".$h."_weblink room Dashboard"); + FW_fC("attr ".$h."_weblink room ".$dashboardhiddenroom); foreach my $dn (sort keys %defs) { - if ($defs{$dn}{TYPE} eq "FHEMWEB") { + if ($defs{$dn}{TYPE} eq "FHEMWEB" && $defs{$dn}{NAME} !~ /FHEMWEB:/) { my $hr = AttrVal($defs{$dn}{NAME}, "hiddenroom", ""); - if (index($hr,"Dashboard") == -1){ - if ($hr eq "") {FW_fC("attr ".$defs{$dn}{NAME}." hiddenroom Dashboard");} - else {FW_fC("attr ".$defs{$dn}{NAME}." hiddenroom ".$hr.",Dashboard");} - Log3 $hash, 3, "[".$hash->{NAME}. "]"." Added hiddenroom \"Dashboard\" to ".$defs{$dn}{NAME}.". Don't forget to save config."; - } + + #---------- Delete older Hiddenroom for Dashboard due changes in 01_FHEMWEB.pm (01.2014) --------- + if (index($hr,$dashboardname) != -1 && index($hr,$dashboardhiddenroom) == -1) { + $hr =~ s/$dashboardname/$dashboardhiddenroom/g; + FW_fC("attr ".$defs{$dn}{NAME}." hiddenroom ".$hr); + Log3 $hash, 3, "[".$hash->{NAME}. "]"." Corrected hiddenroom '".$dashboardname."' -> '".$dashboardhiddenroom."' in ".$defs{$dn}{NAME}.". Don't forget to save config."; + } + #------------------------------------------------------------------------------------------------- + + if (index($hr,$dashboardhiddenroom) == -1){ + if ($hr eq "") {FW_fC("attr ".$defs{$dn}{NAME}." hiddenroom ".$dashboardhiddenroom);} + else {FW_fC("attr ".$defs{$dn}{NAME}." hiddenroom ".$hr.",".$dashboardhiddenroom);} + Log3 $hash, 3, "[".$hash->{NAME}. "]"." Added hiddenroom '".$dashboardhiddenroom."' to ".$defs{$dn}{NAME}.". Don't forget to save config."; + } } } -} + +} -sub Dashboard_define ($@) { +sub Dashboard_define ($$) { my ($hash, $def) = @_; + my $name = $hash->{NAME}; + $data{FWEXT}{jquery}{SCRIPT} = "/pgm2/".$fwjquery; $data{FWEXT}{jqueryui}{SCRIPT} = "/pgm2/".$fwjqueryui; $data{FWEXT}{testjs}{SCRIPT} = "/pgm2/dashboard.js"; $hash->{STATE} = 'Initialized'; CheckInstallation($hash); - CreateDashboardEntry($hash); + CheckDashboardEntry($hash); return; } sub Dashboard_Undef ($$) { my ($hash,$arg) = @_; + + RemoveInternalTimer($hash); + return undef; } @@ -412,23 +492,28 @@ sub Dashboard_detailFn() {
  • dashboard_row
    - To select which rows are displayed. top only; center only; bottom only; top and center; center and bottom; top,center and bottom. + To select which rows are displayed. top only; center only; bottom only; top and center; center and bottom; top,center and bottom.
    + Default: center

  • dashboard_colwidth
    - Width of each column in which the groups may be positioned. + Width of each column in which the groups may be positioned.
    + Default: 320

  • dashboard_colheight
    - Height of each column in which the groups may be positioned. + Height of each column in which the groups may be positioned.
    + Default: 400

  • -
  • vdashboard_rowtopheight
    - Height of the top row in which the groups may be positioned. +
  • dashboard_rowtopheight
    + Height of the top row in which the groups may be positioned.
    + Default: 250

  • "dashboard_rowbottomheight
    - Height of the bottom row in which the groups may be positioned. + Height of the bottom row in which the groups may be positioned.
    + Default: 250

  • dashboard_groups
    @@ -437,28 +522,152 @@ sub Dashboard_detailFn() {
  • dashboard_lockstate
    When set to "unlock" you can edit the Dashboard. When set to "lock" no change can be made.
    - If the bar is hidden dashboard_lockstate is "lock". Editing is possible only with activated switch panel. + If the bar is hidden dashboard_lockstate is "lock". Editing is possible only with activated switch panel.
    + Default: unlock

  • dashboard_colcount
    Number of columns in which the groups can be displayed. Nevertheless, it is possible to have multiple groups
    - to be positioned in a column next to each other. This is dependent on the width of columns and groups. + to be positioned in a column next to each other. This is dependent on the width of columns and groups.
    + Default: 1

  • dashboard_showbuttonbar
    - Displayed above the Dashboard a buttonbar panel. If the bar is hidden dashboard_lockstate the "lock" is used. + Displayed a buttonbar panel. Can set on Top or on Bottom of the Dashboard If the bar is hidden dashboard_lockstate the "lock" is used.
    + Default: top

  • dashboard_showhelper
    - Displays frames in order to facilitate the positioning of the groups. + Displays frames in order to facilitate the positioning of the groups.
    + Default: 1

  • dashboard_showtooglebuttons
    - Displays a Toogle Button on each Group do collapse. + Displays a Toogle Button on each Group do collapse.
    + Default: 1

  • -
    + +
  • dashboard_debug
    + Show Hiddenfields. Only for Maintainer's use.
    + Default: 0 +

  • + =end html +=begin html_DE + + +

    Dashboard

    + + +=end html_DE =cut diff --git a/fhem/www/pgm2/dashboard.js b/fhem/www/pgm2/dashboard.js index 12aa52c34..e039a5bab 100644 --- a/fhem/www/pgm2/dashboard.js +++ b/fhem/www/pgm2/dashboard.js @@ -5,13 +5,13 @@ // Version : 1.00 // Revisions: // 0001: Released to testers -// 0002: Add DebugMsg. Fix independent Groupsize adjustment after set & siterefresh. -// First Release to FHEM SVN -// +// 0002: Add DebugMsg. Fix independent Groupsize adjustment after set & siterefresh. Fix +// wrong set of +Toogle Icon on Siderefresh // // Known Bugs/Todo's // See 95_Dashboard.pm //######################################################################################## +//######################################################################################## function saveOrder() { var SaveResult = ""; @@ -88,11 +88,12 @@ function restoreOrder() { portlet.outerWidth(width); if (params[2] == 1) { portlet.addClass("dashboard_widgethelper"); } else { portlet.removeClass("dashboard_widgethelper"); }//Show Widget-Helper Frame if (visible === 'false') { -// Icon plus is not set on restore order, why? - if (portlet.find(".dashboard_widgetheader").find(".dashboard_button_icon").hasClass("dashboard_button_iconminus")) { + + if (portlet.find(".dashboard_widgetheader").find(".dashboard_button_icon").hasClass("dashboard_button_iconminus")) { portlet.find(".dashboard_widgetheader").find(".dashboard_button_icon").removeClass( "dashboard_button_iconminus" ); portlet.find(".dashboard_widgetheader").find(".dashboard_button_icon").addClass( "dashboard_button_iconplus" ); } + var currHeigth = Math.round(portlet.height()); portlet.find(".dashboard_content").data("userheight", currHeigth); portlet.find(".dashboard_content").hide(); @@ -105,7 +106,7 @@ function restoreOrder() { }); } -//Only use vor debugging +//Only use for debugging function showdebugMessage(msg){ document.getElementById("dashboard_jsdebug").value = document.getElementById("dashboard_jsdebug").value+" "+msg; } @@ -208,8 +209,6 @@ $(document).ready( function () { dashboard_setlock(); } - restoreOrder(); - if (params[6] == 1){ //ToogleButton show/hide $(".dashboard_widget") .addClass( "dashboard_widget dashboard_content ui-corner-all" ) @@ -237,7 +236,7 @@ $(document).ready( function () { event.stopImmediatePropagation(); }); } - + $("#dashboard_button_set").button({ create: function( event, ui ) { $(this).addClass("dashboard_button_iconset"); @@ -262,6 +261,8 @@ $(document).ready( function () { } } }); + + restoreOrder(); });