Skip to content

Commit

Permalink
Refs matomo-org#4041, force DataTable visualizations to specify which…
Browse files Browse the repository at this point in the history
… properties should be overridable and move some view properties to different visualizations.
  • Loading branch information
Benaka Moorthi committed Sep 14, 2013
1 parent c1aad8d commit b1205a5
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 90 deletions.
70 changes: 41 additions & 29 deletions core/DataTableVisualization.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,14 @@ public static function getDefaultPropertyValues()
* in every AJAX request.
*
* Derived DataTableVisualizations can specify client side parameters by declaring
* a static $clientSideParameters field.
* a static $clientSideParameters field that contains a list of view property
* names.
*
* @return array
*/
public static function getClientSideParameters()
{
if (isset(static::$clientSideParameters)) {
$result = array();

$lineage = static::getVisualizationClassLineage(get_called_class());
foreach ($lineage as $klass) {
if (isset($klass::$clientSideParameters)) {
$result = array_merge($result, $klass::$clientSideParameters);
}
}

return array_unique($result);
} else {
return array();
}
return self::getPropertyNameListWithMetaProperty('clientSideParameters');
}

/**
Expand All @@ -83,26 +71,28 @@ public static function getClientSideParameters()
* these will not be passed with AJAX requests as query parameters.
*
* Derived DataTableVisualizations can specify client side properties by declaring
* a static $clientSideProperties field.
* a static $clientSideProperties field that contains a list of view property
* names.
*
* @return array
*/
public static function getClientSideProperties()
{
if (isset(static::$clientSideProperties)) {
$result = array();
return self::getPropertyNameListWithMetaProperty('clientSideProperties');
}

$lineage = static::getVisualizationClassLineage(get_called_class());
foreach ($lineage as $klass) {
if (isset($klass::$clientSideProperties)) {
$result = array_merge($result, $klass::$clientSideProperties);
}
}

return array_unique($result);
} else {
return array();
}
/**
* Returns an array of view property names that can be overriden by query parameters.
* If a query parameter is sent with the same name as a view property, the view
* property will be set to the value of the query parameter.
*
* Derived DataTableVisualizations can specify overridable properties by declaring
* a static $overridableProperties field that contains a list of view property
* names.
*/
public static function getOverridableProperties()
{
return self::getPropertyNameListWithMetaProperty('overridableProperties');
}

/**
Expand Down Expand Up @@ -240,4 +230,26 @@ public static function getClassFromId($id)
}
return $visualizationClasses[$id];
}

/**
* Helper function that merges the static field values of every class in this
* classes inheritance hierarchy. Uses late-static binding.
*/
private static function getPropertyNameListWithMetaProperty($staticFieldName)
{
if (isset(static::$$staticFieldName)) {
$result = array();

$lineage = static::getVisualizationClassLineage(get_called_class());
foreach ($lineage as $klass) {
if (isset($klass::$$staticFieldName)) {
$result = array_merge($result, $klass::$$staticFieldName);
}
}

return array_unique($result);
} else {
return array();
}
}
}
72 changes: 40 additions & 32 deletions core/ViewDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function __construct($currentControllerAction,

$this->setDefaultProperties();
$this->setViewProperties($viewProperties);
$this->overrideViewPropertiesWithQueryParams();

$this->idSubtable = Common::getRequestVar('idSubtable', false, 'int');
$this->viewProperties['show_footer_icons'] = ($this->idSubtable == false);
Expand All @@ -154,6 +153,8 @@ public function __construct($currentControllerAction,
$this->viewProperties['report_id'] = $currentControllerName . '.' . $currentControllerAction;
$this->viewProperties['self_url'] = $this->getBaseReportUrl($currentControllerName, $currentControllerAction);

$this->overrideViewPropertiesWithQueryParams();

// the exclude low population threshold value is sometimes obtained by requesting data.
// to avoid issuing unecessary requests when display properties are determined by metadata,
// we allow it to be a closure.
Expand Down Expand Up @@ -282,14 +283,7 @@ static public function factory($defaultType = null, $apiAction = false, $control
*/
public function getClientSideProperties()
{
$result = array();

if ($this->visualizationClass) {
$klass = $this->visualizationClass;
$result = array_merge($result, $klass::getClientSideProperties());
}

return $result;
return $this->getPropertyNameListWithMetaProperty(Properties::$clientSideProperties, __FUNCTION__);
}

/**
Expand All @@ -300,19 +294,17 @@ public function getClientSideProperties()
*/
public function getClientSideParameters()
{
$result = array(
'filter_excludelowpop',
'filter_excludelowpop_value',
'filter_pattern',
'filter_column',
);

if ($this->visualizationClass) {
$klass = $this->visualizationClass;
$result = array_merge($result, $klass::getClientSideParameters());
}
return $this->getPropertyNameListWithMetaProperty(Properties::$clientSideParameters, __FUNCTION__);
}

return $result;
/**
* Returns the list of view properties that can be overriden by query parameters.
*
* @return array
*/
public function getOverridableProperties()
{
return $this->getPropertyNameListWithMetaProperty(Properties::$overridableProperties, __FUNCTION__);
}

public function getCurrentControllerAction()
Expand Down Expand Up @@ -1244,20 +1236,36 @@ private function convertForJson($value)

private function overrideViewPropertiesWithQueryParams()
{
// TODO: should mark properties that are overridable so not all properties can be overidden this way
$queryParams = $_GET + $_POST;
foreach ($queryParams as $name => $value) {
if (empty($value)) {
continue;
}

$value = Common::getRequestVar($name, $default = null, $type = null, $queryParams);

$properties = $this->getOverridableProperties();
foreach ($properties as $name) {
if (Properties::isCoreViewProperty($name)) {
$this->viewProperties[$name] = $value;
$default = $this->viewProperties[$name];

$this->viewProperties[$name] = $this->getPropertyFromQueryParam($name, $default);
} else if (Properties::isValidVisualizationProperty($this->visualizationClass, $name)) {
$this->viewProperties['visualization_properties']->$name = $value;
$default = $this->viewProperties['visualization_properties']->$name;

$this->viewProperties['visualization_properties']->$name =
$this->getPropertyFromQueryParam($name, $default);
}
}
}

private function getPropertyFromQueryParam($name, $defaultValue)
{
$type = is_numeric($defaultValue) ? 'int' : null;
return Common::getRequestVar($name, $defaultValue, $type);
}

/**
* Helper function for getCliendSiteProperties/getClientSideParameters/etc.
*/
private function getPropertyNameListWithMetaProperty($propertyNames, $getPropertiesFunctionName)
{
if ($this->visualizationClass) {
$klass = $this->visualizationClass;
$propertyNames = array_merge($propertyNames, $klass::$getPropertiesFunctionName());
}
return $propertyNames;
}
}
85 changes: 63 additions & 22 deletions core/ViewDataTable/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ class Properties
*/
const COLUMNS_TO_DISPLAY = 'columns_to_display';

/**
* Whether to display the logo assocatied with a DataTable row (stored as 'logo' row metadata)
* isntead of the label in Tag Clouds.
*/
const DISPLAY_LOGO_INSTEAD_OF_LABEL = 'display_logo_instead_of_label';

/**
* Controls whether the footer icons that change the ViewDataTable type of a view are shown
* or not.
Expand Down Expand Up @@ -244,13 +238,6 @@ class Properties
*/
const SHOW_ECOMMERCE_FOOTER_ICONS = 'show_ecommerce';

/**
* Controls whether the summary row is displayed on every page of the datatable view or not.
* If false, the summary row will be treated as the last row of the dataset and will only visible
* when viewing the last rows.
*/
const KEEP_SUMMARY_ROW = 'keep_summary_row';

/**
* Stores the column name to filter when filtering out rows with low values.
*
Expand Down Expand Up @@ -279,13 +266,6 @@ class Properties
*/
const METRIC_DOCUMENTATION = 'metrics_documentation';

/**
* If true, the summary row will be colored differently than all other DataTable rows.
*
* @see also self::KEEP_SUMMARY_ROW
*/
const HIGHLIGHT_SUMMARY_ROW = 'highlight_summary_row';

/**
* Row metadata name that contains the tooltip for the specific row.
*/
Expand Down Expand Up @@ -399,6 +379,67 @@ class Properties
*/
const SHOW_NON_CORE_VISUALIZATIONS = 'show_non_core_visualizations';

/**
* The list of ViewDataTable properties that are 'Client Side Parameters'.
*
* @see Piwik\DataTableVisualization::getClientSideParameters
*/
public static $clientSideParameters = array(
'filter_excludelowpop',
'filter_excludelowpop_value',
'filter_pattern',
'filter_column',
);

/**
* The list of ViewDataTable properties that are 'Client Side Properties'.
*
* @see Piwik\DataTableVisualization::getClientSideProperties
*/
public static $clientSideProperties = array();

/**
* The list of ViewDataTable properties that can be overriden by query parameters.
*
* @see Piwik\DataTableVisualization::getOverridableProperties
*/
public static $overridableProperties = array(
'show_goals',
'filter_sort_column',
'filter_sort_order',
'filter_limit',
'filter_offset',
'filter_pattern',
'filter_column',
'disable_generic_filters',
'disable_queued_filters',
'show_exclude_low_population',
'show_table',
'show_table_all_columns',
'show_footer',
'show_footer_icons',
'show_all_views_icons',
'show_active_view_icon',
'show_related_reports',
'show_limit_control',
'show_search',
'enable_sort',
'show_bar_chart',
'show_pie_chart',
'show_tag_cloud',
'show_export_as_rss_feed',
'show_ecommerce',
'filter_excludelowpop',
'filter_excludelowpop_value',
'search_recursive',
'show_export_as_image_icon',
'show_pagination_control',
'show_offset_information',
'hide_annotations_view',
'export_limit',
'show_non_core_visualizations'
);

/**
* Returns the set of all valid ViewDataTable properties. The result is an array with property
* names as keys. Values of the array are undefined.
Expand Down Expand Up @@ -521,17 +562,17 @@ public static function getDefaultPropertyValues()
'show_pagination_control' => true,
'show_limit_control' => false,
'show_footer' => true,
'show_footer_icons' => true,
'show_related_reports' => true,
'show_non_core_visualizations' => true,
'export_limit' => Config::getInstance()->General['API_datatable_default_limit'],
'highlight_summary_row' => false,
'related_reports' => array(),
'title' => '',
'tooltip_metadata_name' => false,
'enable_sort' => true,
'disable_generic_filters' => false,
'disable_queued_filters' => false,
'keep_summary_row' => false,
'search_recursive' => false,
'filter_excludelowpop' => false,
'filter_excludelowpop_value' => false,
'filter_pattern' => false,
Expand Down
5 changes: 5 additions & 0 deletions core/Visualization/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ abstract class Graph extends DataTableVisualization
'columns'
);

public static $overridableProperties = array(
'show_all_ticks',
'show_series_picker'
);

/**
* Constructor.
*
Expand Down
2 changes: 1 addition & 1 deletion plugins/Actions/javascripts/actionsDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

/**
* TODO
* UI control that handles extra functionality for Actions datatables.
*
* @constructor
*/
Expand Down
Loading

0 comments on commit b1205a5

Please sign in to comment.