Skip to content

Commit

Permalink
Refs matomo-org#4041, remove subtable_template property and _dataTabl…
Browse files Browse the repository at this point in the history
…eActions_subDataTable.twig file.
  • Loading branch information
Benaka Moorthi committed Sep 17, 2013
1 parent 2794144 commit 4bb2de9
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 67 deletions.
1 change: 1 addition & 0 deletions core/ViewDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ protected function buildView()
$view->showReportDataWasPurgedMessage = $this->hasReportBeenPurged();
$view->deleteReportsOlderThan = Piwik_GetOption('delete_reports_older_than');
}
$view->idSubtable = $this->idSubtable;
$view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
$view->clientSidePropertiesToSet = $this->getClientSidePropertiesToSet();
$view->properties = $this->viewProperties; // TODO: should be $this. need to move non-view properties from the class
Expand Down
11 changes: 11 additions & 0 deletions core/ViewDataTable/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Properties
* This property is only valid for reports whose properties are determined by the
* ViewDataTable.getReportDisplayProperties event. When manually creating ViewDataTables,
* setting this property will have no effect.
*
* Default value: 'table'
*/
const DEFAULT_VIEW_TYPE = 'default_view_type';

Expand All @@ -42,6 +44,14 @@ class Properties
*/
const DATATABLE_TEMPLATE = 'datatable_template';

/**
* Controls whether the buttons and UI controls around the visualization or shown or
* if just the visualization alone is shown.
*
* Default: false
*/
const SHOW_VISUALIZATION_ONLY = 'show_visualization_only';

/**
* Controls whether the goals footer icon is shown.
*/
Expand Down Expand Up @@ -552,6 +562,7 @@ public static function getDefaultPropertyValues()
{
$result = array(
'datatable_template' => '@CoreHome/_dataTable',
'show_visualization_only' => false,
'datatable_js_type' => 'DataTable',
'show_goals' => false,
'show_ecommerce' => false,
Expand Down
3 changes: 1 addition & 2 deletions plugins/Actions/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,7 @@ public function getReportDisplayProperties(&$properties)
private function addBaseDisplayProperties(&$result)
{
$result['datatable_js_type'] = 'ActionsDataTable';
$result['visualization_properties']['table']['subtable_template'] =
'@CoreHome/_dataTableActions_subDataTable.twig';
$result['visualization_properties']['table']['show_embedded_subtable'] = true;
$result['search_recursive'] = true;
$result['show_all_views_icons'] = false;
$result['show_table_all_columns'] = false;
Expand Down
6 changes: 6 additions & 0 deletions plugins/CoreHome/templates/_dataTable.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{% if properties.show_visualization_only %}
{{ visualization.render(dataTable, properties)|raw }}
{%- else -%}

{% set summaryRowId = constant('Piwik\\DataTable::ID_SUMMARY_ROW') %}{# ID_SUMMARY_ROW #}
{% set isSubtable = javascriptVariablesToSet.idSubtable is defined and javascriptVariablesToSet.idSubtable != 0 %}
<div class="dataTable {{ visualizationCssClass }} {{ properties.datatable_css_class|default('') }} {% if isSubtable %}subDataTable{% endif %}"
Expand Down Expand Up @@ -32,3 +36,5 @@
{% endif %}
</div>
</div>

{%- endif %}
28 changes: 0 additions & 28 deletions plugins/CoreHome/templates/_dataTableActions_subDataTable.twig

This file was deleted.

19 changes: 10 additions & 9 deletions plugins/CoreVisualizations/Visualizations/HtmlTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class HtmlTable extends DataTableVisualization
const ID = 'table';

/**
* Custom template used if displaying a subtable.
*
* TODO: Should be replaced w/ allowing custom visualization for
* subtables. Should not directly touch template.
* If this property is set to true, subtables will be shown as embedded in the original table.
* If false, subtables will be shown as whole tables between rows.
*
* Default value: false
*/
const SUBTABLE_TEMPLATE = 'subtable_template';
const SHOW_EMBEDDED_SUBTABLE = 'show_embedded_subtable';

/**
* Controls whether the entire DataTable should be rendered (including subtables) or just one
Expand Down Expand Up @@ -135,9 +135,9 @@ class HtmlTable extends DataTableVisualization
public function __construct($view)
{
if (Common::getRequestVar('idSubtable', false)
&& $view->visualization_properties->subtable_template
&& $view->visualization_properties->show_embedded_subtable
) {
$view->datatable_template = $view->visualization_properties->subtable_template;
$view->show_visualization_only = true;
}

if ($view->visualization_properties->show_extra_columns) {
Expand All @@ -161,6 +161,7 @@ public function render($dataTable, $properties) // TODO: $properties should be a
$view = new View("@CoreVisualizations/_dataTableViz_htmlTable.twig");
$view->properties = $properties;
$view->dataTable = $dataTable;
$view->idSubtable = Common::getRequestVar('idSubtable', false);
return $view->render();
}

Expand All @@ -174,13 +175,13 @@ public static function getDefaultPropertyValues()
'table' => array(
'disable_row_evolution' => false,
'disable_row_actions' => false,
'subtable_template' => "@CoreHome/_dataTable.twig",
'show_extra_columns' => false,
'show_goals_columns' => false,
'disable_subtable_when_show_goals' => false,
'keep_summary_row' => false,
'highlight_summary_row' => false,
'show_expanded' => false
'show_expanded' => false,
'show_embedded_subtable' => false
),
),
);
Expand Down
72 changes: 44 additions & 28 deletions plugins/CoreVisualizations/templates/_dataTableViz_htmlTable.twig
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
{%- set subtablesAreDisabled = properties.visualization_properties.show_goals_columns|default(false)
and properties.visualization_properties.disable_subtable_when_show_goals|default(false) -%}
<table cellspacing="0" class="dataTable">
{% include "@CoreHome/_dataTableHead.twig" %}
{%- set showingEmbeddedSubtable = properties.visualization_properties.show_embedded_subtable is not empty
and idSubtable is not empty -%}
{% if error is defined %}
{{ error.message }}
{% else %}
{%- if not showingEmbeddedSubtable -%}
<table cellspacing="0" class="dataTable">
{% include "@CoreHome/_dataTableHead.twig" %}

<tbody>
{% for rowId, row in dataTable.getRows() %}
{%- set rowHasSubtable = not subtablesAreDisabled and row.getIdSubDataTable() and properties.subtable_controller_action is not null -%}
{%- set shouldHighlightRow = rowId == constant('Piwik\\DataTable::ID_SUMMARY_ROW') and properties.highlight_summary_row -%}
<tbody>
{%- endif -%}
{% if showingEmbeddedSubtable and dataTable.getRowsCount() == 0 %}
<tr>
<td colspan="{{ properties.columns_to_display|length }}">{{ 'CoreHome_CategoryNoData'|translate }}</td>
</tr>
{% else %}
{%- for rowId, row in dataTable.getRows() -%}
{%- set rowHasSubtable = not subtablesAreDisabled and row.getIdSubDataTable() and properties.subtable_controller_action is not null -%}
{%- set shouldHighlightRow = rowId == constant('Piwik\\DataTable::ID_SUMMARY_ROW') and properties.highlight_summary_row -%}

{# display this row if it doesn't have a subtable or if we don't replace the row with the subtable #}
{%- set showRow = subtablesAreDisabled
or not rowHasSubtable
or not properties.visualization_properties.show_expanded|default(false)
or not properties.visualization_properties.replace_row_with_subtable|default(false) -%}
{# display this row if it doesn't have a subtable or if we don't replace the row with the subtable #}
{%- set showRow = subtablesAreDisabled
or not rowHasSubtable
or not properties.visualization_properties.show_expanded|default(false)
or not properties.visualization_properties.replace_row_with_subtable|default(false) -%}

{% if showRow %}
<tr {% if rowHasSubtable %}id="{{ row.getIdSubDataTable() }}"{% endif %}
class="{{ row.getMetadata('css_class') }} {% if rowHasSubtable %}subDataTable{% endif %}{% if shouldHighlightRow %} highlight{% endif %}">
{% for column in properties.columns_to_display %}
<td>
{% include "@CoreHome/_dataTableCell.twig" with properties %}
</td>
{% endfor %}
</tr>
{% if showRow %}
<tr {% if rowHasSubtable %}id="{{ row.getIdSubDataTable() }}"{% endif %}
class="{{ row.getMetadata('css_class') }} {% if rowHasSubtable %}subDataTable{% endif %}{% if shouldHighlightRow %} highlight{% endif %}">
{% for column in properties.columns_to_display %}
<td>
{% include "@CoreHome/_dataTableCell.twig" with properties %}
</td>
{% endfor %}
</tr>
{% endif %}

{# display subtable if present and showing expanded datatable #}
{% if properties.visualization_properties.show_expanded|default(false) and rowHasSubtable %}
{% include "@CoreVisualizations/_dataTableViz_htmlTable.twig" with {'dataTable': row.getSubtable(), 'idSubtable': row.getIdSubDataTable()} %}
{% endif %}
{%- endfor -%}
{% endif %}

{# display subtable if present and showing expanded datatable #}
{% if properties.visualization_properties.show_expanded|default(false) and rowHasSubtable %}
{% include properties.visualization_properties.subtable_template with {'dataTable': row.getSubtable()} %}
{% endif %}
{% endfor %}
</tbody>
</table>
{%- if not showingEmbeddedSubtable -%}
</tbody>
</table>
{%- endif -%}
{% endif %}

0 comments on commit 4bb2de9

Please sign in to comment.