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/ExampleUI | |
parent | 8ccc9dc05da021325cdbf141a548637fa52f16b2 (diff) |
generate pages instead of implementing them in each controller
Diffstat (limited to 'plugins/ExampleUI')
-rw-r--r-- | plugins/ExampleUI/API.php | 1 | ||||
-rw-r--r-- | plugins/ExampleUI/Categories/ExampleUiCategory.php | 17 | ||||
-rw-r--r-- | plugins/ExampleUI/Controller.php | 154 | ||||
-rw-r--r-- | plugins/ExampleUI/Menu.php | 25 | ||||
-rw-r--r-- | plugins/ExampleUI/Reports/Base.php | 19 | ||||
-rw-r--r-- | plugins/ExampleUI/Reports/GetPlanetRatios.php | 74 | ||||
-rw-r--r-- | plugins/ExampleUI/Reports/GetPlanetRatiosWithLogos.php | 44 | ||||
-rw-r--r-- | plugins/ExampleUI/Reports/GetTemperatures.php | 93 | ||||
-rw-r--r-- | plugins/ExampleUI/Reports/GetTemperaturesEvolution.php | 95 | ||||
-rw-r--r-- | plugins/ExampleUI/lang/en.json | 8 | ||||
-rw-r--r-- | plugins/ExampleUI/plugin.json | 17 |
11 files changed, 364 insertions, 183 deletions
diff --git a/plugins/ExampleUI/API.php b/plugins/ExampleUI/API.php index 7b6e0c508a..ae9beae05f 100644 --- a/plugins/ExampleUI/API.php +++ b/plugins/ExampleUI/API.php @@ -99,4 +99,5 @@ class API extends \Piwik\Plugin\API return $planetsDataTable; } + } diff --git a/plugins/ExampleUI/Categories/ExampleUiCategory.php b/plugins/ExampleUI/Categories/ExampleUiCategory.php new file mode 100644 index 0000000000..cc7d2fd219 --- /dev/null +++ b/plugins/ExampleUI/Categories/ExampleUiCategory.php @@ -0,0 +1,17 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExampleUI\Categories; + +use Piwik\Category\Category; + +class ExampleUiCategory extends Category +{ + protected $id = 'ExampleUI_UiFramework'; + protected $order = 90; +} diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php index 210093c8b5..c032d449fa 100644 --- a/plugins/ExampleUI/Controller.php +++ b/plugins/ExampleUI/Controller.php @@ -18,38 +18,6 @@ use Piwik\ViewDataTable\Factory as ViewDataTableFactory; */ class Controller extends \Piwik\Plugin\Controller { - public function dataTables() - { - $controllerAction = $this->pluginName . '.' . __FUNCTION__; - $apiAction = 'ExampleUI.getTemperatures'; - - $view = ViewDataTableFactory::build('table', $apiAction, $controllerAction); - - $view->config->translations['value'] = 'Temperature in °C'; - $view->config->translations['label'] = 'Hour of day'; - $view->requestConfig->filter_sort_column = 'label'; - $view->requestConfig->filter_sort_order = 'asc'; - $view->requestConfig->filter_limit = 24; - $view->config->columns_to_display = array('label', 'value'); - $view->config->y_axis_unit = '°C'; // useful if the user requests the bar graph - $view->config->show_exclude_low_population = false; - $view->config->show_table_all_columns = false; - $view->config->disable_row_evolution = true; - $view->config->max_graph_elements = 24; - $view->config->metrics_documentation = array('value' => 'Documentation for temperature metric'); - - return $view->render(); - } - - public function evolutionGraph() - { - $view = new View('@ExampleUI/evolutiongraph'); - - $this->setPeriodVariablesView($view); - $view->evolutionGraph = $this->getEvolutionGraph(array(), array('server1', 'server2')); - - return $view->render(); - } public function notifications() { @@ -78,126 +46,4 @@ class Controller extends \Piwik\Plugin\Controller return $view->render(); } - public function getEvolutionGraph(array $columns = array(), array $defaultColumns = array()) - { - if (empty($columns)) { - $columns = Common::getRequestVar('columns', false); - if (false !== $columns) { - $columns = Piwik::getArrayFromApiParameter($columns); - } - } - - $view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns, - $selectableColumns = array('server1', 'server2'), 'My documentation', 'ExampleUI.getTemperaturesEvolution'); - $view->requestConfig->filter_sort_column = 'label'; - $view->requestConfig->filter_sort_order = 'asc'; - - if (empty($view->config->columns_to_display) && !empty($defaultColumns)) { - $view->config->columns_to_display = $defaultColumns; - } - - return $this->renderView($view); - } - - public function barGraph() - { - $view = ViewDataTableFactory::build( - 'graphVerticalBar', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.barGraph'); - - $view->config->y_axis_unit = '°C'; - $view->config->show_footer = false; - $view->config->translations['value'] = "Temperature"; - $view->config->selectable_columns = array("value"); - $view->config->max_graph_elements = 24; - - return $view->render(); - } - - public function pieGraph() - { - $view = ViewDataTableFactory::build( - 'graphPie', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.pieGraph'); - - $view->config->columns_to_display = array('value'); - $view->config->translations['value'] = "times the diameter of Earth"; - $view->config->show_footer_icons = false; - $view->config->selectable_columns = array("value"); - $view->config->max_graph_elements = 10; - - return $view->render(); - } - - public function tagClouds() - { - $output = "<h2>Simple tag cloud</h2>"; - $output .= $this->echoSimpleTagClouds(); - - $output .= "<br /><br /><h2>Advanced tag cloud: with logos and links</h2> - <ul style='list-style-type:disc;margin-left:50px'> - <li>The logo size is proportional to the value returned by the API</li> - <li>The logo is linked to a specific URL</li> - </ul><br /><br />"; - $output .= $this->echoAdvancedTagClouds(); - - return $output; - } - - public function echoSimpleTagClouds() - { - $view = ViewDataTableFactory::build( - 'cloud', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.echoSimpleTagClouds'); - - $view->config->columns_to_display = array('label', 'value'); - $view->config->translations['value'] = "times the diameter of Earth"; - $view->config->show_footer = false; - - return $view->render(); - } - - public function echoAdvancedTagClouds() - { - $view = ViewDataTableFactory::build( - 'cloud', 'ExampleUI.getPlanetRatiosWithLogos', $controllerAction = 'ExampleUI.echoAdvancedTagClouds'); - - $view->config->display_logo_instead_of_label = true; - $view->config->columns_to_display = array('label', 'value'); - $view->config->translations['value'] = "times the diameter of Earth"; - - return $view->render(); - } - - public function sparklines() - { - $view = new View('@ExampleUI/sparklines'); - $view->urlSparkline1 = $this->getUrlSparkline('generateSparkline', array('server' => 'server1', 'rand' => mt_rand())); - $view->urlSparkline2 = $this->getUrlSparkline('generateSparkline', array('server' => 'server2', 'rand' => mt_rand())); - - return $view->render(); - } - - public function generateSparkline() - { - $view = ViewDataTableFactory::build( - 'sparkline', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.generateSparkline'); - - $serverRequested = Common::getRequestVar('server', false); - if (false !== $serverRequested) { - $view->config->columns_to_display = array($serverRequested); - } - - return $view->render(); - } - - public function treemap() - { - $view = ViewDataTableFactory::build( - 'infoviz-treemap', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.treemap'); - - $view->config->translations['value'] = "Temperature"; - $view->config->columns_to_display = array("label", "value"); - $view->config->selectable_columns = array("value"); - $view->config->show_evolution_values = 0; - - return $view->render(); - } } diff --git a/plugins/ExampleUI/Menu.php b/plugins/ExampleUI/Menu.php index e25bd10817..35cf0d70b5 100644 --- a/plugins/ExampleUI/Menu.php +++ b/plugins/ExampleUI/Menu.php @@ -8,37 +8,12 @@ */ namespace Piwik\Plugins\ExampleUI; -use Piwik\Menu\MenuReporting; use Piwik\Menu\MenuUser; -use Piwik\Plugin\Manager as PluginManager; -/** - */ class Menu extends \Piwik\Plugin\Menu { - public function configureReportingMenu(MenuReporting $menu) - { - $menu->addItem('UI Framework', '', $this->urlForAction('dataTables'), 30); - - $this->addSubMenu($menu, 'Data tables', 'dataTables', 1); - $this->addSubMenu($menu, 'Bar graph', 'barGraph', 2); - $this->addSubMenu($menu, 'Pie graph', 'pieGraph', 3); - $this->addSubMenu($menu, 'Tag clouds', 'tagClouds', 4); - $this->addSubMenu($menu, 'Sparklines', 'sparklines', 5); - $this->addSubMenu($menu, 'Evolution Graph', 'evolutionGraph', 6); - - if (PluginManager::getInstance()->isPluginActivated('TreemapVisualization')) { - $this->addSubMenu($menu, 'Treemap', 'treemap', 7); - } - } - public function configureUserMenu(MenuUser $menu) { $menu->addPlatformItem('UI Notifications', $this->urlForAction('notifications'), $order = 10); } - - private function addSubMenu(MenuReporting $menu, $subMenu, $action, $order) - { - $menu->addItem('UI Framework', $subMenu, $this->urlForAction($action), $order); - } } diff --git a/plugins/ExampleUI/Reports/Base.php b/plugins/ExampleUI/Reports/Base.php new file mode 100644 index 0000000000..88fa676754 --- /dev/null +++ b/plugins/ExampleUI/Reports/Base.php @@ -0,0 +1,19 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExampleUI\Reports; + +use Piwik\Plugin\Report; + +abstract class Base extends Report +{ + protected function init() + { + $this->categoryId = 'ExampleUI_UiFramework'; + } +} diff --git a/plugins/ExampleUI/Reports/GetPlanetRatios.php b/plugins/ExampleUI/Reports/GetPlanetRatios.php new file mode 100644 index 0000000000..244e8f79c8 --- /dev/null +++ b/plugins/ExampleUI/Reports/GetPlanetRatios.php @@ -0,0 +1,74 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\ExampleUI\Reports; + +use Piwik\Plugin\Report; +use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\CoreVisualizations\Visualizations\Cloud; +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; +use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; + +/** + * This class defines a new report. + * + * See {@link http://developer.piwik.org/api-reference/Piwik/Plugin/Report} for more information. + */ +class GetPlanetRatios extends Base +{ + protected function init() + { + parent::init(); + + $this->name = 'Pie graph'; + $this->subcategoryId = $this->name; + $this->order = 112; + } + + public function getDefaultTypeViewDataTable() + { + return PIE::ID; + } + + public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory) + { + $widgetsList->addWidgetConfig( + // in this case it will render PIE as configured as default + $factory->createWidget() + ); + + $widgetsList->addWidgetConfig( + $factory->createWidget() + ->setName('Simple tag cloud') + ->setSubcategoryId('Tag clouds') + ->forceViewDataTable(Cloud::ID) + ->setOrder(5) + ); + } + + public function configureView(ViewDataTable $view) + { + $view->config->addTranslation('value', 'times the diameter of Earth'); + + if ($view->isViewDataTableId(PIE::ID)) { + + $view->config->columns_to_display = array('value'); + $view->config->selectable_columns = array('value'); + $view->config->show_footer_icons = false; + $view->config->max_graph_elements = 10; + + } else if ($view->isViewDataTableId(Cloud::ID)) { + + $view->config->columns_to_display = array('label', 'value'); + $view->config->show_footer = false; + + } + } + +} diff --git a/plugins/ExampleUI/Reports/GetPlanetRatiosWithLogos.php b/plugins/ExampleUI/Reports/GetPlanetRatiosWithLogos.php new file mode 100644 index 0000000000..d4d205e6c9 --- /dev/null +++ b/plugins/ExampleUI/Reports/GetPlanetRatiosWithLogos.php @@ -0,0 +1,44 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\ExampleUI\Reports; + +use Piwik\Piwik; +use Piwik\Plugin\Report; +use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\CoreVisualizations\Visualizations\Cloud; + +/** + * This class defines a new report. + * + * See {@link http://developer.piwik.org/api-reference/Piwik/Plugin/Report} for more information. + */ +class GetPlanetRatiosWithLogos extends Base +{ + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('Advanced tag cloud: with logos and links'); + $this->subcategoryId = 'Tag clouds'; + $this->order = 113; + } + + public function getDefaultTypeViewDataTable() + { + return Cloud::ID; + } + + public function configureView(ViewDataTable $view) + { + $view->config->display_logo_instead_of_label = true; + $view->config->columns_to_display = array('label', 'value'); + $view->config->addTranslation('value', 'times the diameter of Earth'); + } + +} diff --git a/plugins/ExampleUI/Reports/GetTemperatures.php b/plugins/ExampleUI/Reports/GetTemperatures.php new file mode 100644 index 0000000000..0449e8b3e2 --- /dev/null +++ b/plugins/ExampleUI/Reports/GetTemperatures.php @@ -0,0 +1,93 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\ExampleUI\Reports; + +use Piwik\Piwik; +use Piwik\Plugin\Report; +use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Bar; +use Piwik\Plugin\Manager as PluginManager; +use Piwik\Report\ReportWidgetFactory; +use Piwik\View; +use Piwik\Widget\WidgetsList; + +/** + * This class defines a new report. + * + * See {@link http://developer.piwik.org/api-reference/Piwik/Plugin/Report} for more information. + */ +class GetTemperatures extends Base +{ + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('ExampleUI_GetTemperaturesDataTable'); + $this->subcategoryId = 'ExampleUI_GetTemperaturesDataTable'; + $this->order = 110; + } + + public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory) + { + // this will render the default view, in this case an Html Table + $widgetsList->addWidgetConfig($factory->createWidget()); + + $widgetsList->addWidgetConfig( + $factory->createWidget() + ->forceViewDataTable(Bar::ID) + ->setSubcategoryId('Bar graph') + ); + + if (PluginManager::getInstance()->isPluginActivated('TreemapVisualization')) { + $widgetsList->addWidgetConfig( + $factory->createWidget() + ->setName('Treemap example') + ->setSubcategoryId('Treemap') + ->forceViewDataTable('infoviz-treemap') + ); + + } + } + + public function configureView(ViewDataTable $view) + { + if ($view->isViewDataTableId(BAR::ID)) { + + $view->config->y_axis_unit = '°C'; + $view->config->show_footer = false; + $view->config->translations['value'] = "Temperature"; + $view->config->selectable_columns = array("value"); + $view->config->max_graph_elements = 24; + + } elseif ($view->isViewDataTableId('infoviz-treemap')) { + + $view->config->translations['value'] = "Temperature"; + $view->config->columns_to_display = array("label", "value"); + $view->config->selectable_columns = array("value"); + $view->config->show_evolution_values = 0; + + } else { + // for default view datatable, eg HtmlTable + + $view->config->translations['value'] = 'Temperature in °C'; + $view->config->translations['label'] = 'Hour of day'; + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'asc'; + $view->requestConfig->filter_limit = 24; + $view->config->columns_to_display = array('label', 'value'); + $view->config->y_axis_unit = '°C'; // useful if the user requests the bar graph + $view->config->show_exclude_low_population = false; + $view->config->show_table_all_columns = false; + $view->config->disable_row_evolution = true; + $view->config->max_graph_elements = 24; + $view->config->metrics_documentation = array('value' => 'Documentation for temperature metric'); + } + } + +} diff --git a/plugins/ExampleUI/Reports/GetTemperaturesEvolution.php b/plugins/ExampleUI/Reports/GetTemperaturesEvolution.php new file mode 100644 index 0000000000..ff8ea66e10 --- /dev/null +++ b/plugins/ExampleUI/Reports/GetTemperaturesEvolution.php @@ -0,0 +1,95 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\ExampleUI\Reports; + +use Piwik\Common; +use Piwik\Piwik; +use Piwik\Plugin\Report; +use Piwik\Plugin\ViewDataTable; + +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Bar; +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution; +use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; +use Piwik\Plugins\CoreVisualizations\Visualizations\Sparklines; +use Piwik\Report\ReportWidgetFactory; +use Piwik\View; +use Piwik\Widget\WidgetsList; + +/** + * This class defines a new report. + * + * See {@link http://developer.piwik.org/api-reference/Piwik/Plugin/Report} for more information. + */ +class GetTemperaturesEvolution extends Base +{ + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('ExampleUI_GetTemperaturesEvolution'); + $this->order = 111; + } + + public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory) + { + $widgetsList->addWidgetConfig( + $factory->createWidget() + ->setSubcategoryId('Sparklines') + ->forceViewDataTable(Sparklines::ID) + ); + + $widgetsList->addWidgetConfig( + $factory->createWidget() + ->setName('ExampleUI_TemperaturesEvolution') + ->setSubcategoryId('Evolution Graph') + ->forceViewDataTable(Evolution::ID) + ->setParameters(array('columns' => array('server1', 'server2'))) + ); + + } + + /** + * Here you can configure how your report should be displayed. For instance whether your report supports a search + * etc. You can also change the default request config. For instance change how many rows are displayed by default. + * + * @param ViewDataTable $view + */ + public function configureView(ViewDataTable $view) + { + if ($view->isViewDataTableId(Sparklines::ID)) { + + /** @var Sparklines $view */ + $view->config->addSparklineMetric(array('server1')); + $view->config->addSparklineMetric(array('server2')); + $view->config->addTranslations(array('server1' => 'Evolution of temperature for server piwik.org')); + $view->config->addTranslations(array('server2' => 'Evolution of temperature for server dev.piwik.org')); + + } elseif ($view->isViewDataTableId(Evolution::ID)) { + + /** @var Evolution $view */ + $selectableColumns = array('server1', 'server2'); + + $columns = Common::getRequestVar('columns', false); + if (!empty($columns)) { + $columns = Piwik::getArrayFromApiParameter($columns); + } + + $columns = array_merge($columns ? $columns : array(), $selectableColumns); + $view->config->columns_to_display = $columns; + + $view->config->addTranslations(array_combine($columns, $columns)); + $view->config->selectable_columns = $selectableColumns; + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'asc'; + $view->config->documentation = 'My documentation'; + $view->config->show_goals = false; + } + } + +} diff --git a/plugins/ExampleUI/lang/en.json b/plugins/ExampleUI/lang/en.json new file mode 100644 index 0000000000..e0c05c5411 --- /dev/null +++ b/plugins/ExampleUI/lang/en.json @@ -0,0 +1,8 @@ +{ + "ExampleUI": { + "UiFramework": "UI Framework", + "GetTemperaturesDataTable": "Data tables", + "GetTemperaturesEvolution": "Temperatures evolution over time", + "TemperaturesEvolution": "Evolution of server temperatures over the last few days" + } +}
\ No newline at end of file diff --git a/plugins/ExampleUI/plugin.json b/plugins/ExampleUI/plugin.json index ec2fcfe025..8a39e0a2a2 100644 --- a/plugins/ExampleUI/plugin.json +++ b/plugins/ExampleUI/plugin.json @@ -2,14 +2,23 @@ "name": "ExampleUI", "description": "Piwik Platform showcase: how to display data tables, graphs, and the UI framework.", "version": "1.0.1", - "keywords": ["example", "framework", "platform", "ui", "visualization"], - "homepage": "http://piwik.org", + "keywords": [ + "example", + "framework", + "platform", + "ui", + "visualization" + ], + "homepage": "http:\/\/piwik.org", "license": "GPL v3+", "authors": [ { "name": "Piwik", "email": "hello@piwik.org", - "homepage": "http://piwik.org" + "homepage": "http:\/\/piwik.org" } - ] + ], + "require": { + "piwik": ">=2.13.1" + } }
\ No newline at end of file |