diff options
Diffstat (limited to 'plugins/Dashboard')
-rw-r--r-- | plugins/Dashboard/Controller.php | 96 | ||||
-rw-r--r-- | plugins/Dashboard/Dashboard.php | 23 | ||||
-rw-r--r-- | plugins/Dashboard/templates/Dashboard.js | 42 | ||||
-rw-r--r-- | plugins/Dashboard/templates/dashboard.css | 7 | ||||
-rw-r--r-- | plugins/Dashboard/templates/index.tpl | 42 | ||||
-rw-r--r-- | plugins/Dashboard/templates/widgetMenu.js | 12 |
6 files changed, 146 insertions, 76 deletions
diff --git a/plugins/Dashboard/Controller.php b/plugins/Dashboard/Controller.php index 863883f6be..bdfe1acf2e 100644 --- a/plugins/Dashboard/Controller.php +++ b/plugins/Dashboard/Controller.php @@ -21,16 +21,12 @@ class Piwik_Dashboard_Controller extends Piwik_Controller $view = Piwik_View::factory($template); $this->setGeneralVariablesView($view); - // layout was JSON.stringified - $layout = html_entity_decode($this->getLayout()); - $layout = str_replace("\\\"", "\"", $layout); - - if(!empty($layout) - && strstr($layout, '[[') == false) { - $layout = "'$layout'"; + $view->availableWidgets = json_encode(Piwik_GetWidgetsList()); + $layout = $this->getLayout(); + if(empty($layout)) { + $layout = $this->getDefaultLayout(); } $view->layout = $layout; - $view->availableWidgets = json_encode(Piwik_GetWidgetsList()); return $view; } @@ -56,7 +52,7 @@ class Piwik_Dashboard_Controller extends Piwik_Controller protected function saveLayoutForUser( $login, $idDashboard, $layout) { $paramsBind = array($login, $idDashboard, $layout, $layout); - Piwik_Query('INSERT INTO '.Piwik::prefixTable('user_dashboard') . + Piwik_Query('INSERT INTO '.Piwik_Common::prefixTable('user_dashboard') . ' (login, iddashboard, layout) VALUES (?,?,?) ON DUPLICATE KEY UPDATE layout=?', @@ -74,7 +70,7 @@ class Piwik_Dashboard_Controller extends Piwik_Controller protected function getLayoutForUser( $login, $idDashboard) { $paramsBind = array($login, $idDashboard); - $return = Piwik_FetchAll('SELECT layout FROM '.Piwik::prefixTable('user_dashboard') . + $return = Piwik_FetchAll('SELECT layout FROM '.Piwik_Common::prefixTable('user_dashboard') . ' WHERE login = ? AND iddashboard = ?', $paramsBind); if(count($return) == 0) { @@ -90,14 +86,14 @@ class Piwik_Dashboard_Controller extends Piwik_Controller */ public function saveLayout() { + $this->checkTokenInUrl(); $layout = Piwik_Common::getRequestVar('layout'); $idDashboard = Piwik_Common::getRequestVar('idDashboard', 1, 'int' ); $currentUser = Piwik::getCurrentUserLogin(); - if($currentUser == 'anonymous') { $session = new Zend_Session_Namespace("Piwik_Dashboard"); - $session->idDashboard = $layout; + $session->dashboardLayout = $layout; } else { @@ -119,16 +115,84 @@ class Piwik_Dashboard_Controller extends Piwik_Controller { $session = new Zend_Session_Namespace("Piwik_Dashboard"); - if(!isset($session->idDashboard)) + if(!isset($session->dashboardLayout)) { return false; } - return $session->idDashboard; + $layout = $session->dashboardLayout; } else { - return $this->getLayoutForUser($currentUser,$idDashboard); - } + $layout = $this->getLayoutForUser($currentUser,$idDashboard); + } + + // layout was JSON.stringified + $layout = html_entity_decode($layout); + $layout = str_replace("\\\"", "\"", $layout); + + // compatibility with the old layout format + if(!empty($layout) + && strstr($layout, '[[') == false) { + $layout = "'$layout'"; + } + $layout = $this->removeDisabledPluginFromLayout($layout); + return $layout; + } + + protected function removeDisabledPluginFromLayout($layout) + { + $layout = str_replace("\n", "", $layout); + // if the json decoding works (ie. new Json format) + // we will only return the widgets that are from enabled plugins + if($layoutObject = json_decode($layout, $assoc = false)) + { + foreach($layoutObject as &$row) + { + if(!is_array($row)) + { + $row = array(); + continue; + } + + foreach($row as $widgetId => $widget) + { + if(isset($widget->parameters->module)) { + $controllerName = $widget->parameters->module; + $controllerAction = $widget->parameters->action; + if(!Piwik_IsWidgetDefined($controllerName, $controllerAction)) + { + unset($row[$widgetId]); + } + } + } + } + $layout = json_encode($layoutObject); + } + return $layout; + } + + protected function getDefaultLayout() + { + $defaultLayout = '[ + [ + {"uniqueId":"widgetVisitsSummarygetEvolutionGraphcolumnsArray","parameters":{"module":"VisitsSummary","action":"getEvolutionGraph","columns":["nb_visits"]}}, + {"uniqueId":"widgetVisitorInterestgetNumberOfVisitsPerVisitDuration","parameters":{"module":"VisitorInterest","action":"getNumberOfVisitsPerVisitDuration"}}, + {"uniqueId":"widgetUserSettingsgetBrowser","parameters":{"module":"UserSettings","action":"getBrowser"}}, + {"uniqueId":"widgetUserCountrygetCountry","parameters":{"module":"UserCountry","action":"getCountry"}}, + {"uniqueId":"widgetExampleFeedburnerfeedburner","parameters":{"module":"ExampleFeedburner","action":"feedburner"}} + ], + [ + {"uniqueId":"widgetReferersgetKeywords","parameters":{"module":"Referers","action":"getKeywords"}}, + {"uniqueId":"widgetReferersgetWebsites","parameters":{"module":"Referers","action":"getWebsites"}} + ], + [ + {"uniqueId":"widgetReferersgetSearchEngines","parameters":{"module":"Referers","action":"getSearchEngines"}}, + {"uniqueId":"widgetVisitTimegetVisitInformationPerServerTime","parameters":{"module":"VisitTime","action":"getVisitInformationPerServerTime"}}, + {"uniqueId":"widgetExampleRssWidgetrssPiwik","parameters":{"module":"ExampleRssWidget","action":"rssPiwik"}} + ] + ]'; + $defaultLayout = $this->removeDisabledPluginFromLayout($defaultLayout); + return $defaultLayout; } } diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index 5e977160ea..cf9cacfb06 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -11,7 +11,6 @@ */ /** - * * @package Piwik_Dashboard */ class Piwik_Dashboard extends Piwik_Plugin @@ -19,11 +18,10 @@ class Piwik_Dashboard extends Piwik_Plugin public function getInformation() { return array( - 'name' => 'Dashboard', - 'description' => 'Your Web Analytics Dashboard. You can customize Your Dashboard: add new widgets, change the order of your widgets. Each user can access his own custom Dashboard.', + 'description' => Piwik_Translate('Dashboard_PluginDescription'), 'author' => 'Piwik', - 'homepage' => 'http://piwik.org/', - 'version' => '0.1', + 'author_homepage' => 'http://piwik.org/', + 'version' => Piwik_Version::VERSION, ); } @@ -32,6 +30,7 @@ class Piwik_Dashboard extends Piwik_Plugin return array( 'template_js_import' => 'js', 'template_css_import' => 'css', + 'UsersManager.deleteUser' => 'deleteDashboardLayout', ); } @@ -48,19 +47,25 @@ class Piwik_Dashboard extends Piwik_Plugin { echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"plugins/Dashboard/templates/dashboard.css\" />\n"; } - + + function deleteDashboardLayout($notification) + { + $userLogin = $notification->getNotificationObject(); + Piwik_Query('DELETE FROM ' . Piwik_Common::prefixTable('user_dashboard') . ' WHERE login = ?', array($userLogin)); + } + public function install() { // we catch the exception try{ - $sql = "CREATE TABLE ". Piwik::prefixTable('user_dashboard')." ( + $sql = "CREATE TABLE ". Piwik_Common::prefixTable('user_dashboard')." ( login VARCHAR( 100 ) NOT NULL , iddashboard INT NOT NULL , layout TEXT NOT NULL, PRIMARY KEY ( login , iddashboard ) ) DEFAULT CHARSET=utf8 " ; Piwik_Exec($sql); - } catch(Zend_Db_Statement_Exception $e){ + } catch(Exception $e){ // mysql code error 1050:table already exists // see bug #153 http://dev.piwik.org/trac/ticket/153 if(!Zend_Registry::get('db')->isErrNo($e, '1050')) @@ -72,7 +77,7 @@ class Piwik_Dashboard extends Piwik_Plugin public function uninstall() { - $sql = "DROP TABLE ". Piwik::prefixTable('user_dashboard') ; + $sql = "DROP TABLE ". Piwik_Common::prefixTable('user_dashboard') ; Piwik_Exec($sql); } diff --git a/plugins/Dashboard/templates/Dashboard.js b/plugins/Dashboard/templates/Dashboard.js index 73f15ecb04..74d81ec3b7 100644 --- a/plugins/Dashboard/templates/Dashboard.js +++ b/plugins/Dashboard/templates/Dashboard.js @@ -79,15 +79,30 @@ dashboard.prototype = // load all widgets $('.widget', self.dashboardElement).each( function() { var uniqueId = $(this).attr('id'); - function onWidgetLoadedReplaceElementWithContent(loadedContent) - { - $('#'+uniqueId+'>.widgetContent', self.dashboardElement).html(loadedContent); - } - widget = widgetsHelper.getWidgetObjectFromUniqueId(uniqueId); - widgetParameters = widget["parameters"]; - $.ajax(widgetsHelper.getLoadWidgetAjaxRequest(uniqueId, widgetParameters, onWidgetLoadedReplaceElementWithContent)); + self.reloadWidget(uniqueId); }); }, + + reloadEnclosingWidget: function(domNodeInsideWidget) + { + var uniqueId = $(domNodeInsideWidget).parents('.widget').attr('id'); + this.reloadWidget(uniqueId); + }, + + reloadWidget: function(uniqueId) + { + function onWidgetLoadedReplaceElementWithContent(loadedContent) + { + $('#'+uniqueId+'>.widgetContent', self.dashboardElement).html(loadedContent); + } + widget = widgetsHelper.getWidgetObjectFromUniqueId(uniqueId); + if(widget == false) + { + return; + } + widgetParameters = widget["parameters"]; + $.ajax(widgetsHelper.getLoadWidgetAjaxRequest(uniqueId, widgetParameters, onWidgetLoadedReplaceElementWithContent)); + }, addDummyWidgetAtBottomOfColumn: function(columnNumber) { @@ -109,13 +124,14 @@ dashboard.prototype = } columnElement = $(self.dashboardColumnsElement[columnNumber]); emptyWidgetContent = '<div class="sortable">'+ - widgetsHelper.getEmptyWidgetHtml(uniqueId, widgetName, _pk_translate('Dashboard_LoadingWidget_js'))+ + widgetsHelper.getEmptyWidgetHtml(uniqueId, widgetName)+ '</div>'; if(addWidgetOnTop) { columnElement.prepend(emptyWidgetContent); } else { columnElement.append(emptyWidgetContent); } + widgetElement = $('#'+ uniqueId); widgetElement .hover( function() { @@ -141,10 +157,14 @@ dashboard.prototype = { var self = this; - function onStart() { + function onStart(event, ui) { + if(!jQuery.support.noCloneEvent) { + $('object', this).hide(); + } } function onStop(event, ui) { + $('object', this).show(); $('.widgetHover', this).removeClass('widgetHover'); $('.widgetTopHover', this).removeClass('widgetTopHover'); $('.button#close', this).hide(); @@ -161,7 +181,7 @@ dashboard.prototype = forcePlaceholderSize: true, placeholder: 'hover', handle: '.widgetTop', - helper: 'original', + helper: 'clone', start: onStart, stop: onStop }); @@ -221,7 +241,7 @@ dashboard.prototype = var ajaxRequest = { type: 'POST', - url: 'index.php?module=Dashboard&action=saveLayout', + url: 'index.php?module=Dashboard&action=saveLayout&token_auth='+piwik.token_auth, dataType: 'html', async: true, error: piwikHelper.ajaxHandleError, diff --git a/plugins/Dashboard/templates/dashboard.css b/plugins/Dashboard/templates/dashboard.css index 7c78adcbcb..2551c8cff7 100644 --- a/plugins/Dashboard/templates/dashboard.css +++ b/plugins/Dashboard/templates/dashboard.css @@ -18,14 +18,21 @@ margin-right: 5px; margin-left: 5px; overflow: hidden; + -moz-border-radius:4px; + -webkit-border-radius:4px; } .widgetHover { border: 1px solid #CBD3E7; } +.widgetContent h2 { + font-size:1.2em; +} .widgetTop { background: #F0F0FA; + -moz-border-radius:4px 4px 0 0; + -webkit-border-radius:4px 4px 0 0; border-bottom: 1px solid #D2D9EB; width: 100%; cursor: move; diff --git a/plugins/Dashboard/templates/index.tpl b/plugins/Dashboard/templates/index.tpl index faf0a11323..ae957e33f7 100644 --- a/plugins/Dashboard/templates/index.tpl +++ b/plugins/Dashboard/templates/index.tpl @@ -1,56 +1,32 @@ {loadJavascriptTranslations plugins='CoreHome Dashboard'} <script type="text/javascript"> -{if !empty($layout) } piwik.dashboardLayout = {$layout}; -{else} -{literal} - piwik.dashboardLayout = - [ - [ - {"uniqueId":"widgetVisitsSummarygetEvolutionGraph","parameters":{"module":"VisitsSummary","action":"getEvolutionGraph","columns":["nb_visits"]}}, - {"uniqueId":"widgetVisitorInterestgetNumberOfVisitsPerVisitDuration","parameters":{"module":"VisitorInterest","action":"getNumberOfVisitsPerVisitDuration"}}, - {"uniqueId":"widgetUserSettingsgetBrowser","parameters":{"module":"UserSettings","action":"getBrowser"}}, - {"uniqueId":"widgetUserCountrygetCountry","parameters":{"module":"UserCountry","action":"getCountry"}}, - {"uniqueId":"widgetExampleFeedburnerfeedburner","parameters":{"module":"ExampleFeedburner","action":"feedburner"}} - ], - [ - {"uniqueId":"widgetReferersgetKeywords","parameters":{"module":"Referers","action":"getKeywords"}}, - {"uniqueId":"widgetReferersgetWebsites","parameters":{"module":"Referers","action":"getWebsites"}} - ], - [ - {"uniqueId":"widgetReferersgetSearchEngines","parameters":{"module":"Referers","action":"getSearchEngines"}}, - {"uniqueId":"widgetVisitTimegetVisitInformationPerServerTime","parameters":{"module":"VisitTime","action":"getVisitInformationPerServerTime"}}, - {"uniqueId":"widgetExampleRssWidgetrssPiwik","parameters":{"module":"ExampleRssWidget","action":"rssPiwik"}} - ] - ]; -{/literal} {* the old dashboard layout style is: piwik.dashboardLayout = 'VisitsSummary.getEvolutionGraph~VisitorInterest.getNumberOfVisitsPerVisitDuration~UserSettings.getBrowser~ExampleFeedburner.feedburner|Referers.getKeywords~Referers.getWebsites|Referers.getSearchEngines~VisitTime.getVisitInformationPerServerTime~ExampleRssWidget.rssPiwik|'; *} -{/if} -piwik.availableWidgets = {$availableWidgets}; + piwik.availableWidgets = {$availableWidgets}; </script> {literal} <script type="text/javascript"> $(document).ready( function() { - var dashboardObject = new dashboard(); - var widgetMenuObject = new widgetMenu(dashboardObject); - dashboardObject.init(piwik.dashboardLayout); + piwik.dashboardObject = new dashboard(); + var widgetMenuObject = new widgetMenu(piwik.dashboardObject); + piwik.dashboardObject.init(piwik.dashboardLayout); widgetMenuObject.init(); - $('.button#addWidget').click(function(){widgetMenuObject.show();}); + $('#addWidget.button').click(function(){widgetMenuObject.show();}); }); </script> {/literal} <div id="dashboard"> <div class="dialog" id="confirm"> - <img src="themes/default/images/delete.png" style="padding: 10px; position: relative; margin-top: 10%; float: left;"/> + <img src="themes/default/images/delete.png" style="padding: 10px; position: relative; margin-top: 10%; float: left;" /> <p>{'Dashboard_DeleteWidgetConfirm'|translate}</p> - <input id="yes" type="button" value="{'General_Yes'|translate}"/> - <input id="no" type="button" value="{'General_No'|translate}"/> + <input id="yes" type="button" value="{'General_Yes'|translate}" /> + <input id="no" type="button" value="{'General_No'|translate}" /> </div> <div class="button" id="addWidget"> @@ -58,7 +34,7 @@ $(document).ready( function() { </div> <div class="menu" id="widgetChooser"> - <div id="closeMenuIcon"><img src="themes/default/images/close_medium.png" title="{'General_Close'|translate}"/></div> + <div id="closeMenuIcon"><img src="themes/default/images/close_medium.png" title="{'General_Close'|translate}" /></div> <div id="menuTitleBar">{'Dashboard_SelectWidget'|translate}</div> <div class="subMenu" id="sub1"></div> diff --git a/plugins/Dashboard/templates/widgetMenu.js b/plugins/Dashboard/templates/widgetMenu.js index 6556b9085f..997c87158f 100644 --- a/plugins/Dashboard/templates/widgetMenu.js +++ b/plugins/Dashboard/templates/widgetMenu.js @@ -55,7 +55,7 @@ widgetsHelper.getLoadWidgetAjaxRequest = function (widgetUniqueId, widgetParamet return ajaxRequest; }; -widgetsHelper.getEmptyWidgetHtml = function (uniqueId, widgetName, widgetLoadingString) +widgetsHelper.getEmptyWidgetHtml = function (uniqueId, widgetName) { return '<div id="'+uniqueId+'" class="widget">'+ '<div class="widgetTop">'+ @@ -66,7 +66,7 @@ widgetsHelper.getEmptyWidgetHtml = function (uniqueId, widgetName, widgetLoading '</div>'+ '<div class="widgetContent">'+ '<div class="widgetLoading">'+ - widgetLoadingString + + _pk_translate('Dashboard_LoadingWidget_js') + '</div>'+ '</div>'+ '</div>'; @@ -194,10 +194,7 @@ widgetMenu.prototype = widgetUniqueId, '<div title="'+_pk_translate("Dashboard_AddPreviewedWidget_js")+'">'+ _pk_translate('Dashboard_WidgetPreview_js')+ - '</div>', - '<span id="loadingPiwik">'+ - '<img src="themes/default/images/loading-blue.gif"> ' +_pk_translate('Dashboard_LoadingWidget_js') + - '</span>' + '</div>' ); $('#sub3').html(emptyWidgetHtml); @@ -231,6 +228,7 @@ widgetMenu.prototype = self.filterOutAlreadyLoadedWidget(); $.blockUI({ message: self.menuElement, + centerY: 0, css: {width:'', top: '5%',left:'10%', right:'10%', margin:"0px", textAlign:'', cursor:'', border:'0px'} }); } @@ -309,7 +307,7 @@ widgetMenu.prototype = ); $.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#000000', opacity: '0.4'}); $.extend($.blockUI.defaults,{ fadeIn: 0, fadeOut: 0 }); - $(window).keydown( function(e) { + $(document).keydown( function(e) { var key = e.keyCode || e.which; if(key == 27) { self.hideMenu(); |