Skip to content

Commit

Permalink
Refs #4040, #4041, move more logic out of HtmlTable ViewDataTable class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benaka Moorthi committed Aug 1, 2013
1 parent 0f61caa commit 883c322
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
33 changes: 24 additions & 9 deletions core/ViewDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* @package Piwik
* @subpackage ViewDataTable
*/
abstract class ViewDataTable
class ViewDataTable
{
/**
* TODO
Expand Down Expand Up @@ -137,8 +137,10 @@ abstract class ViewDataTable
/**
* Default constructor.
*/
public function __construct()
public function __construct($visualization = null)
{
$this->visualization = $visualization;

$this->viewProperties['visualization_properties'] = new VisualizationPropertiesProxy(null);
$this->viewProperties['datatable_template'] = '@CoreHome/_dataTable';
$this->viewProperties['show_goals'] = false;
Expand Down Expand Up @@ -255,7 +257,13 @@ public function main()
*
* @return string
*/
abstract protected function getViewDataTableId();
protected function getViewDataTableId()
{
if (method_exists($this->visualization, 'getViewDataTableId')) {
return $this->visualization->getViewDataTableId();
}
return false;
}

/**
* Returns a Piwik_ViewDataTable_* object.
Expand Down Expand Up @@ -318,7 +326,7 @@ static public function factory($defaultType = null, $apiAction = false, $control

case 'table':
default:
$result = new ViewDataTable\HtmlTable();
$result = new ViewDataTable(new Visualization\HtmlTable());
break;
}

Expand Down Expand Up @@ -372,7 +380,7 @@ public function getOverridableProperties()
*/
public function getJavaScriptProperties()
{
return array(
$result = array(
'enable_sort',
'disable_generic_filters',
'disable_queued_filters',
Expand All @@ -385,6 +393,12 @@ public function getJavaScriptProperties()
'filter_sort_column',
'filter_sort_order',
);

if (method_exists($this->visualization, 'getJavaScriptProperties')) {
$result = array_merge($result, $this->visualization->getJavaScriptProperties());
}

return $result;
}

/**
Expand Down Expand Up @@ -622,6 +636,8 @@ protected function checkStandardDataTable()
*/
protected function postDataTableLoadedFromAPI()
{
$this->overrideViewProperties();

if (empty($this->dataTable)) {
return false;
}
Expand Down Expand Up @@ -1206,8 +1222,6 @@ protected function buildView($visualization)
$this->setPropertyDefaults($visualization->getDefaultPropertyValues());
}

$this->overrideViewProperties();

$template = $this->viewProperties['datatable_template'];
$view = new View($template);

Expand All @@ -1234,11 +1248,12 @@ protected function buildView($visualization)

public function getDefaultDataTableCssClass()
{
return false;
$parts = explode('\\', get_class($this->visualization));
return 'dataTableViz' . end($parts);
}

/**
* TODO
* Sets view properties if they have not been set already.
*/
private function setPropertyDefaults($defaultValues)
{
Expand Down
16 changes: 0 additions & 16 deletions core/ViewDataTable/HtmlTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,4 @@ public function __construct()

$this->visualization = new Visualization\HtmlTable();
}

public function getJavaScriptProperties()
{
return array_merge(parent::getJavaScriptProperties(), $this->visualization->getJavaScriptProperties());
}

protected function getViewDataTableId()
{
return $this->visualization->getViewDataTableId();
}

public function getDefaultDataTableCssClass()
{
$parts = explode('\\', get_class($this));
return 'dataTableViz' . end($parts);
}
}

0 comments on commit 883c322

Please sign in to comment.