Skip to content

Commit

Permalink
Refs #4041, allow subtable template to be used if idSubtable is in re…
Browse files Browse the repository at this point in the history
…quest so Actions controller doesn't have to call setTemplate. Also did some mild refactoring for Piwik_ViewDataTable_HtmlTable::setRecursiveLoadDataTableIfSearchingForPattern.
  • Loading branch information
Benaka Moorthi committed Jul 10, 2013
1 parent 00839a2 commit 4f0e655
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
44 changes: 21 additions & 23 deletions core/ViewDataTable/HtmlTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function init($currentControllerName,
$this->setSortedColumn('nb_visits', 'desc');
$this->setLimit(Piwik_Config::getInstance()->General['datatable_default_limit']);
$this->handleLowPopulation();
$this->setSubtableTemplate("@CoreHome/_dataTable.twig");
}

protected function getViewDataTableId()
Expand Down Expand Up @@ -105,25 +106,28 @@ public function setJsType($type)
$this->dataTableJsType = $type;
}

public function showExpanded($subtableTemplate = false)
public function setSubtableTemplate($subtableTemplate)
{
$this->viewProperties['subtable_template'] = $subtableTemplate;
}

public function showExpanded()
{
$this->viewProperties['show_expanded'] = true;
if ($subtableTemplate !== false) {
$this->viewProperties['subtable_template'] = $subtableTemplate;
}
}

/**
* @return Piwik_View with all data set
*/
protected function buildView()
{
$view = new Piwik_View($this->dataTableTemplate);

if (empty($this->viewProperties['dataTableType'])) {
$this->viewProperties['dataTableType'] = $this->getDefaultDataTableType();
}

$template = $this->idSubtable ? $this->viewProperties['subtable_template'] : $this->dataTableTemplate;
$view = new Piwik_View($template);

if (!empty($this->dataTableJsType)) {
$view->dataTableJsType = $this->dataTableJsType;
}
Expand Down Expand Up @@ -206,13 +210,16 @@ public function addColumnToDisplay($columnName)
/**
* Sets the search on a table to be recursive (also searches in subtables)
* Works only on Actions/Downloads/Outlinks tables.
*
* @return bool If the pattern for a recursive search was set in the URL
*/
public function setSearchRecursive()
{
$this->variablesDefault['search_recursive'] = true;
return $this->setRecursiveLoadDataTableIfSearchingForPattern();
$this->setRecursiveLoadDataTableIfSearchingForPattern();
}

public function isLoadingExpandedDataTable()
{
return $this->recursiveDataTableLoad;
}

protected function getRequestString()
Expand All @@ -228,23 +235,14 @@ protected function getRequestString()

/**
* Set the flag to load the datatable recursively so we can search on subtables as well
*
* @return bool if recursive search is enabled
*/
protected function setRecursiveLoadDataTableIfSearchingForPattern()
{
try {
$requestValue = Piwik_Common::getRequestVar('filter_column_recursive');
$requestValue = Piwik_Common::getRequestVar('filter_pattern_recursive');
// if the 2 variables are set we are searching for something.
// we have to load all the children subtables in this case

$this->recursiveDataTableLoad = true;
return true;
} catch (Exception $e) {
$this->recursiveDataTableLoad = false;
return false;
}
// if the 2 variables are set we are searching for something.
// we have to load all the children subtables in this case
$this->recursiveDataTableLoad = Piwik_Common::getRequestVar('filter_column_recursive', false) !== false
&& Piwik_Common::getRequestVar('filter_pattern_recursive', false) !== false;
return $this->recursiveDataTableLoad;
}

/**
Expand Down
11 changes: 4 additions & 7 deletions plugins/Actions/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,11 @@ protected function configureGenericViewActions($view)
{
$view->setDataTableType('dataTableActions');
$view->setJsType('actionDataTable');
$view->setSubtableTemplate('@CoreHome/_dataTableActions_subDataTable.twig');


if (Piwik_Common::getRequestVar('idSubtable', -1) != -1) {
$view->setTemplate('@CoreHome/_dataTableActions_subDataTable');
}
$currentlySearching = $view->setSearchRecursive();
if ($currentlySearching) {
$view->showExpanded($subtableTemplate = '@CoreHome/_dataTableActions_subDataTable.twig');
$view->setSearchRecursive();
if ($view->isLoadingExpandedDataTable()) {
$view->showExpanded();

// set levelN css class for each row
$self = $this;
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/templates/_dataTable.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

{# display subtable if present and showing expanded datatable #}
{% if properties.show_expanded|default(false) and rowHasSubtable %}
{% include properties.subtable_template|default("@CoreHome/_dataTable.twig") with {'dataTable': row.getSubtable()} %}
{% include properties.subtable_template with {'dataTable': row.getSubtable()} %}
{% endif %}
{% endfor %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if arrayDataTable.result is defined and arrayDataTable.result == 'error' %}
{{ arrayDataTable.message }}
{% if error is defined %}
{{ error.message }}
{% else %}
{% if (dataTable is empty or dataTable.getRowsCount() == 0) and not properties.show_expanded|default(false) %}
<tr>
Expand Down

0 comments on commit 4f0e655

Please sign in to comment.