diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-07-03 03:54:27 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2015-10-06 18:25:13 +0300 |
commit | 9ba8f216fd7856ce5fef06bf82ecb8f8a2e7e630 (patch) | |
tree | 6ce07d18a85d00b39ab720abe042361c0775aead /plugins/Dashboard/Dashboard.php | |
parent | 8ccc9dc05da021325cdbf141a548637fa52f16b2 (diff) |
generate pages instead of implementing them in each controller
Diffstat (limited to 'plugins/Dashboard/Dashboard.php')
-rw-r--r-- | plugins/Dashboard/Dashboard.php | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index 9ccbb822e4..5a0a7cc0ec 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -11,7 +11,8 @@ namespace Piwik\Plugins\Dashboard; use Piwik\Common; use Piwik\Db; use Piwik\Piwik; -use Piwik\WidgetsList; +use Piwik\Category\Subcategory; +use Piwik\Widget\WidgetConfig; /** */ @@ -26,10 +27,43 @@ class Dashboard extends \Piwik\Plugin 'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'UsersManager.deleteUser' => 'deleteDashboardLayout', - 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys' + 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', + 'Widget.addWidgetConfigs' => 'addWidgetConfigs', + 'Category.addSubcategories' => 'addSubcategories' ); } + public function addWidgetConfigs(&$widgets) + { + $dashboards = API::getInstance()->getDashboards(); + + foreach ($dashboards as $dashboard) { + $config = new WidgetConfig(); + $config->setIsNotWidgetizable(); + $config->setModule('Dashboard'); + $config->setAction('embeddedIndex'); + $config->setCategoryId('Dashboard_Dashboard'); + $config->setSubcategoryId($dashboard['id']); + $config->setParameters(array('idDashboard' => $dashboard['id'])); + $widgets[] = $config; + } + } + + public function addSubcategories(&$subcategories) + { + $dashboards = API::getInstance()->getDashboards(); + + $order = 0; + foreach ($dashboards as $dashboard) { + $subcategory = new Subcategory(); + $subcategory->setName($dashboard['name']); + $subcategory->setCategoryId('Dashboard_Dashboard'); + $subcategory->setId($dashboard['id']); + $subcategory->setOrder($order++); + $subcategories[] = $subcategory; + } + } + /** * Returns the layout in the DB for the given user, or false if the layout has not been set yet. * Parameters must be checked BEFORE this function call @@ -70,14 +104,14 @@ class Dashboard extends \Piwik\Plugin $defaultLayout = '[ [ - {"uniqueId":"widgetVisitsSummarygetEvolutionGraphcolumnsArray","parameters":{"module":"VisitsSummary","action":"getEvolutionGraph","columns":"nb_visits"}}, + {"uniqueId":"widgetVisitsSummarygetEvolutionGraphforceView1viewDataTablegraphEvolution","parameters":{"forceView":"1","viewDataTable":"graphEvolution","module":"VisitsSummary","action":"getEvolutionGraph"}}, {"uniqueId":"widgetLivewidget","parameters":{"module":"Live","action":"widget"}}, - {"uniqueId":"widgetVisitorInterestgetNumberOfVisitsPerVisitDuration","parameters":{"module":"VisitorInterest","action":"getNumberOfVisitsPerVisitDuration"}} + {"uniqueId":"widgetVisitorInterestgetNumberOfVisitsPerVisitDurationviewDataTablecloud","parameters":{"viewDataTable":"cloud","module":"VisitorInterest","action":"getNumberOfVisitsPerVisitDuration"}} ], [ ' . $topWidget . ' {"uniqueId":"widgetReferrersgetWebsites","parameters":{"module":"Referrers","action":"getWebsites"}}, - {"uniqueId":"widgetVisitTimegetVisitInformationPerServerTime","parameters":{"module":"VisitTime","action":"getVisitInformationPerServerTime"}} + {"uniqueId":"widgetVisitTimegetVisitInformationPerServerTimeviewDataTablegraphVerticalBar","parameters":{"viewDataTable": "graphVerticalBar","module":"VisitTime","action":"getVisitInformationPerServerTime"}} ], [ {"uniqueId":"widgetUserCountryMapvisitorMap","parameters":{"module":"UserCountryMap","action":"visitorMap"}}, @@ -160,24 +194,6 @@ class Dashboard extends \Piwik\Plugin ); } - foreach ($layoutObject->columns 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 (!WidgetsList::isDefined($controllerName, $controllerAction)) { - unset($row[$widgetId]); - } - } else { - unset($row[$widgetId]); - } - } - } $layout = $this->encodeLayout($layoutObject); return $layout; } @@ -202,11 +218,13 @@ class Dashboard extends \Piwik\Plugin public function getJsFiles(&$jsFiles) { + $jsFiles[] = "plugins/Dashboard/angularjs/common/services/dashboards-model.js"; $jsFiles[] = "plugins/Dashboard/javascripts/widgetMenu.js"; $jsFiles[] = "libs/javascript/json2.js"; $jsFiles[] = "plugins/Dashboard/javascripts/dashboardObject.js"; $jsFiles[] = "plugins/Dashboard/javascripts/dashboardWidget.js"; $jsFiles[] = "plugins/Dashboard/javascripts/dashboard.js"; + $jsFiles[] = "plugins/Dashboard/angularjs/dashboard/dashboard.directive.js"; } public function getStylesheetFiles(&$stylesheets) |