Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into cevents
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Oct 21, 2013
2 parents 57d46e2 + 2192359 commit b12d4b9
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 148 deletions.
6 changes: 3 additions & 3 deletions core/Plugin/Visualization.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function buildView()

$this->beforeLoadDataTable();

$this->loadDataTableFromAPI(array('disable_generic_filters' => 1));
$this->loadDataTableFromAPI(array('disable_generic_filters' => 1, 'disable_queued_filters' => 1));
$this->postDataTableLoadedFromAPI();

$requestPropertiesAfterLoadDataTable = $this->requestConfig->getProperties();
Expand Down Expand Up @@ -194,7 +194,7 @@ private function applyFilters()

$this->beforeGenericFiltersAreAppliedToLoadedDataTable();

if (!$this->config->areGenericFiltersDisabled()) {
if (!$this->requestConfig->areGenericFiltersDisabled()) {
$this->applyGenericFilters();
}

Expand All @@ -207,7 +207,7 @@ private function applyFilters()

// Finally, apply datatable filters that were queued (should be 'presentation' filters that
// do not affect the number of rows)
if (!$this->config->areQueuedFiltersDisabled()) {
if (!$this->requestConfig->areQueuedFiltersDisabled()) {
$this->dataTable->applyQueuedFilters();
}
}
Expand Down
49 changes: 0 additions & 49 deletions core/ViewDataTable/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class Config
*/
public $overridableProperties = array(
'show_goals',
'disable_generic_filters',
'disable_queued_filters',
'show_exclude_low_population',
'show_flatten_table',
'show_table',
Expand Down Expand Up @@ -235,24 +233,6 @@ class Config
*/
public $custom_parameters = array();

/**
* Whether to run generic filters on the DataTable before rendering or not.
*
* @see Piwik_API_DataTableGenericFilter
*
* Default value: false
*/
public $disable_generic_filters = false;

/**
* Whether to run ViewDataTable's list of queued filters or not.
*
* NOTE: Priority queued filters are always run.
*
* Default value: false
*/
public $disable_queued_filters = false;

/**
* Controls whether the limit dropdown (which allows users to change the number of data shown)
* is always shown or not.
Expand Down Expand Up @@ -496,35 +476,6 @@ public function getProperties()
return get_object_vars($this);
}

/**
* Returns true if queued filters have been disabled, false if otherwise.
*
* @return bool
*/
public function areQueuedFiltersDisabled()
{
return isset($this->disable_queued_filters) && $this->disable_queued_filters;
}

/**
* Returns true if generic filters have been disabled, false if otherwise.
*
* @return bool
*/
public function areGenericFiltersDisabled()
{
// if disable_generic_filters query param is set to '1', generic filters are disabled
if (Common::getRequestVar('disable_generic_filters', '0', 'string') == 1) {
return true;
}

if (isset($this->disable_generic_filters) && true === $this->disable_generic_filters) {
return true;
}

return false;
}

public function setDefaultColumnsToDisplay($columns, $hasNbVisits, $hasNbUniqVisitors)
{
if ($hasNbVisits || $hasNbUniqVisitors) {
Expand Down
52 changes: 51 additions & 1 deletion core/ViewDataTable/RequestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

namespace Piwik\ViewDataTable;
use Piwik\Common;

/**
* Renders a sparkline image given a PHP data array.
Expand Down Expand Up @@ -43,7 +44,9 @@ class RequestConfig
'filter_pattern',
'filter_column',
'filter_excludelowpop',
'filter_excludelowpop_value'
'filter_excludelowpop_value',
'disable_generic_filters',
'disable_queued_filters'
);

/**
Expand Down Expand Up @@ -119,6 +122,24 @@ class RequestConfig
*/
public $request_parameters_to_modify = array();

/**
* Whether to run generic filters on the DataTable before rendering or not.
*
* @see Piwik_API_DataTableGenericFilter
*
* Default value: false
*/
public $disable_generic_filters = false;

/**
* Whether to run ViewDataTable's list of queued filters or not.
*
* NOTE: Priority queued filters are always run.
*
* Default value: false
*/
public $disable_queued_filters = false;

public $apiMethodToRequestDataTable = '';

/**
Expand Down Expand Up @@ -159,6 +180,35 @@ public function setDefaultSort($columnsToDisplay, $hasNbUniqVisitors)
$this->filter_sort_order = 'desc';
}

/**
* Returns true if queued filters have been disabled, false if otherwise.
*
* @return bool
*/
public function areQueuedFiltersDisabled()
{
return isset($this->disable_queued_filters) && $this->disable_queued_filters;
}

/**
* Returns true if generic filters have been disabled, false if otherwise.
*
* @return bool
*/
public function areGenericFiltersDisabled()
{
// if disable_generic_filters query param is set to '1', generic filters are disabled
if (Common::getRequestVar('disable_generic_filters', '0', 'string') == 1) {
return true;
}

if (isset($this->disable_generic_filters) && true === $this->disable_generic_filters) {
return true;
}

return false;
}

public function getApiModuleToRequest()
{
list($module, $method) = explode('.', $this->apiMethodToRequestDataTable);
Expand Down
20 changes: 15 additions & 5 deletions plugins/ExampleUI/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ public function dataTables()
$controllerAction = $this->pluginName . '.' . __FUNCTION__;
$apiAction = 'ExampleUI.getTemperatures';

/**
* this is an example how you can make a custom visualization reusable.
*/
$table = new CustomDataTable();
$view = Factory::build('table', $apiAction, $controllerAction);

echo $table->render('Temperature in °C', 'Hour of day', $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');

echo $view->render();
}

public function evolutionGraph()
Expand Down
38 changes: 0 additions & 38 deletions plugins/ExampleUI/CustomDataTable.php

This file was deleted.

52 changes: 0 additions & 52 deletions plugins/Live/Live.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function getListHooksRegistered()
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'WidgetsList.addWidgets' => 'addWidget',
'Menu.Reporting.addItems' => 'addMenu',
'ViewDataTable.configure' => 'configureViewDataTable',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'ViewDataTable.getDefaultType' => 'getDefaultTypeViewDataTable'
);
Expand Down Expand Up @@ -76,59 +75,8 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = "Live_PageRefreshed";
}

public function configureViewDataTable(ViewDataTable $view)
{
switch ($view->requestConfig->apiMethodToRequestDataTable) {
case 'Live.getLastVisitsDetails':
$this->configureViewForGetLastVisitsDetails($view);
break;
}
}

public function getDefaultTypeViewDataTable(&$defaultViewTypes)
{
$defaultViewTypes['Live.getLastVisitsDetails'] = VisitorLog::ID;
}

private function configureViewForGetLastVisitsDetails(ViewDataTable $view)
{
$view->config->disable_generic_filters = true;
$view->config->enable_sort = false;
$view->config->show_search = false;
$view->config->show_exclude_low_population = false;
$view->config->show_offset_information = false;
$view->config->show_all_views_icons = false;
$view->config->show_table_all_columns = false;
$view->config->show_export_as_rss_feed = false;

$view->requestConfig->filter_sort_column = 'idVisit';
$view->requestConfig->filter_sort_order = 'asc';
$view->requestConfig->filter_limit = 20;

$view->config->documentation = Piwik::translate('Live_VisitorLogDocumentation', array('<br />', '<br />'));
$view->config->custom_parameters = array(
// set a very high row count so that the next link in the footer of the data table is always shown
'totalRows' => 10000000,

'filterEcommerce' => Common::getRequestVar('filterEcommerce', 0, 'int'),
'pageUrlNotDefined' => Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageURL'))
);

$view->config->footer_icons = array(
array(
'class' => 'tableAllColumnsSwitch',
'buttons' => array(
array(
'id' => 'Piwik\\Plugins\\Live\\VisitorLog',
'title' => Piwik::translate('Live_LinkVisitorLog'),
'icon' => 'plugins/Zeitgeist/images/table.png'
)
)
)
);

if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->disable_row_actions = true;
}
}
}
36 changes: 36 additions & 0 deletions plugins/Live/VisitorLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
namespace Piwik\Plugins\Live;

use Piwik\Common;
use Piwik\Piwik;
use Piwik\View;
use Piwik\Plugin\Visualization;

Expand All @@ -29,6 +31,11 @@ public function beforeLoadDataTable()
'filter_sort_column',
'filter_sort_order',
));

$this->requestConfig->filter_sort_column = 'idVisit';
$this->requestConfig->filter_sort_order = 'asc';
$this->requestConfig->filter_limit = 20;
$this->requestConfig->disable_generic_filters = true;
}

/**
Expand All @@ -37,5 +44,34 @@ public function beforeLoadDataTable()
public function beforeRender()
{
$this->config->datatable_js_type = 'VisitorLog';
$this->config->enable_sort = false;
$this->config->show_search = false;
$this->config->show_exclude_low_population = false;
$this->config->show_offset_information = false;
$this->config->show_all_views_icons = false;
$this->config->show_table_all_columns = false;
$this->config->show_export_as_rss_feed = false;

$this->config->documentation = Piwik::translate('Live_VisitorLogDocumentation', array('<br />', '<br />'));
$this->config->custom_parameters = array(
// set a very high row count so that the next link in the footer of the data table is always shown
'totalRows' => 10000000,

'filterEcommerce' => Common::getRequestVar('filterEcommerce', 0, 'int'),
'pageUrlNotDefined' => Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageURL'))
);

$this->config->footer_icons = array(
array(
'class' => 'tableAllColumnsSwitch',
'buttons' => array(
array(
'id' => 'Piwik\\Plugins\\Live\\VisitorLog',
'title' => Piwik::translate('Live_LinkVisitorLog'),
'icon' => 'plugins/Zeitgeist/images/table.png'
)
)
)
);
}
}

0 comments on commit b12d4b9

Please sign in to comment.