Skip to content

Commit

Permalink
Refs #4040, #4041, fix sparklines regression caused by datatable css …
Browse files Browse the repository at this point in the history
…refactoring and clean up the getLastUnitGraphAcrossPlugins function (modified to set properties directly).
  • Loading branch information
Benaka Moorthi committed Jul 30, 2013
1 parent 0ea1a94 commit 13f657c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
24 changes: 4 additions & 20 deletions core/Controller.php
Expand Up @@ -186,14 +186,6 @@ protected function getLastUnitGraph($currentModuleName, $currentControllerAction
protected function getLastUnitGraphAcrossPlugins($currentModuleName, $currentControllerAction,
$columnsToDisplay, $selectableColumns = array(), $reportDocumentation = false, $apiMethod = 'API.get')
{
// back up and manipulate the columns parameter
$backupColumns = false;
if (isset($_GET['columns'])) {
$backupColumns = $_GET['columns'];
}

$_GET['columns'] = implode(',', $columnsToDisplay);

// load translations from meta data
$idSite = Piwik_Common::getRequestVar('idSite');
$period = Piwik_Common::getRequestVar('period');
Expand All @@ -214,23 +206,15 @@ protected function getLastUnitGraphAcrossPlugins($currentModuleName, $currentCon

// initialize the graph and load the data
$view = $this->getLastUnitGraph($currentModuleName, $currentControllerAction, $apiMethod);
$view->setColumnsToDisplay($columnsToDisplay);
$view->setSelectableColumns($selectableColumns);
$view->setColumnsTranslations($translations);
$view->columns_to_display = $columnsToDisplay;
$view->selectable_columns = array_merge($view->selectable_columns, $selectableColumns);
$view->translations += $translations;

if ($reportDocumentation) {
$view->setReportDocumentation($reportDocumentation);
$view->documentation = $reportDocumentation;
}

$view->main();

// restore the columns parameter
if ($backupColumns !== false) {
$_GET['columns'] = $backupColumns;
} else {
unset($_GET['columns']);
}

return $view;
}

Expand Down
1 change: 1 addition & 0 deletions core/ViewDataTable.php
Expand Up @@ -164,6 +164,7 @@ public function __construct()
$this->viewProperties['documentation'] = false;
$this->viewProperties['subtable_controller_action'] = false;
$this->viewProperties['datatable_css_class'] = $this->getDefaultDataTableCssClass();
$this->viewProperties['selectable_columns'] = array(); // TODO: only valid for graphs... shouldn't be here.
$this->viewProperties['columns_to_display'] = array();

$columns = Piwik_Common::getRequestVar('columns', false);
Expand Down
17 changes: 17 additions & 0 deletions core/ViewDataTable/Properties.php
Expand Up @@ -127,6 +127,23 @@ class Piwik_ViewDataTable_Properties
*/
const EXTERNAL_SERIES_TOGGLE_SHOW_ALL = 'external_series_toggle_show_all';

/**
* Controls whether a report's related reports are listed with the view or not.
*/
const SHOW_RELATED_REPORTS = 'show_related_reports';

/**
* Array property that contains the names of columns that can be selected in the Series Picker.
*
* TODO: this is only applicable to graph views. move this.
*/
const SELECTABLE_COLUMNS = 'selectable_columns';

/**
* Contains the documentation for a report.
*/
const REPORT_DOCUMENTATION = 'documentation';

/**
* Returns the set of all valid ViewDataTable properties. The result is an array with property
* name as a key. Values of the array are undefined.
Expand Down
10 changes: 5 additions & 5 deletions plugins/CoreHome/javascripts/sparkline.js
Expand Up @@ -15,7 +15,7 @@ piwik.getSparklineColors = function () {

// initializes each sparkline so they use colors defined in CSS
piwik.initSparklines = function () {
$('.sparkline').each(function () {
$('img.sparkline').each(function () {
var $self = $(this);

if ($self.attr('src')) {
Expand All @@ -36,7 +36,7 @@ window.initializeSparklines = function () {
// try to find sparklines and add them clickable behaviour
graph.parent().find('div.sparkline').each(function () {
// find the sparkline and get it's src attribute
var sparklineUrl = $('img.sparkline', this).attr('src');
var sparklineUrl = $('img.sparkline', this).attr('data-src');

if (sparklineUrl != "") {
var params = broadcast.getValuesFromUrl(sparklineUrl);
Expand All @@ -54,15 +54,15 @@ window.initializeSparklines = function () {

// on click, reload the graph with the new url
$(this).click(function () {
var idDataTable = graph.attr('data-graph-id'),
dataTable = $('#' + idDataTable);
var reportId = graph.attr('data-graph-id'),
dataTable = $(piwik.DataTableManager.getDataTableByReport(reportId));

// when the metrics picker is used, the id of the data table might be updated (which is correct behavior).
// for example, in goal reports it might change from GoalsgetEvolutionGraph to GoalsgetEvolutionGraph1.
// if this happens, we can't find the graph using $('#'+idDataTable+"Chart");
// instead, we just use the first evolution graph we can find.
if (dataTable.length == 0) {
dataTable = $('div.dataTableGraphEvolutionWrapper').first().closest('.dataTable');
dataTable = $('div.dataTableEvolutionGraph');
}

// reload the datatable w/ a new column & scroll to the graph
Expand Down
2 changes: 1 addition & 1 deletion plugins/Goals/Controller.php
Expand Up @@ -122,7 +122,7 @@ protected function getGoalReportView($idGoal = false)
$view->goalName = $goalDefinition['name'];
$view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple'];
$view->graphEvolution = $this->getEvolutionGraph(true, array('nb_conversions'), $idGoal);
$view->nameGraphEvolution = 'GoalsgetEvolutionGraph' . $idGoal;
$view->nameGraphEvolution = 'Goals.getEvolutionGraph' . $idGoal;
$view->topDimensions = $this->getTopDimensions($idGoal);

// conversion rate for new and returning visitors
Expand Down
2 changes: 1 addition & 1 deletion plugins/Live/templates/getVisitorLog.twig
Expand Up @@ -7,7 +7,7 @@
{% endif %}
{% set displayVisitorsInOwnColumn %}{% if isWidget %}0{% else %}1{% endif %}{% endset %}

<span data-graph-id="VisitsSummarygetEvolutionGraph"></span>
<span data-graph-id="VisitsSummary.getEvolutionGraph"></span>

{% if error is defined %}
{{ error.message }}
Expand Down
2 changes: 1 addition & 1 deletion plugins/Referers/Controller.php
Expand Up @@ -20,7 +20,7 @@ public function index()
$view = new Piwik_View('@Referers/index');

$view->graphEvolutionReferers = $this->getEvolutionGraph(true, Piwik_Common::REFERER_TYPE_DIRECT_ENTRY, array('nb_visits'));
$view->nameGraphEvolutionReferers = 'ReferersgetEvolutionGraph';
$view->nameGraphEvolutionReferers = 'Referers.getEvolutionGraph';

// building the referers summary report
$view->dataTableRefererType = $this->getRefererType(true);
Expand Down
2 changes: 1 addition & 1 deletion plugins/VisitFrequency/templates/index.twig
@@ -1,6 +1,6 @@
{{ postEvent("template_headerVisitsFrequency") }}

<h2 data-graph-id="VisitFrequencygetEvolutionGraph">{{ 'VisitFrequency_ColumnReturningVisits'|translate }}</h2>
<h2 data-graph-id="VisitFrequency.getEvolutionGraph">{{ 'VisitFrequency_ColumnReturningVisits'|translate }}</h2>
{{ graphEvolutionVisitFrequency|raw }}
<br/>

Expand Down
2 changes: 1 addition & 1 deletion plugins/VisitsSummary/templates/index.twig
@@ -1,5 +1,5 @@
{# This graphId must be unique for this report #}
<h2 data-graph-id="VisitsSummarygetEvolutionGraph">{{ 'Referers_Evolution'|translate }}</h2>
<h2 data-graph-id="VisitsSummary.getEvolutionGraph">{{ 'Referers_Evolution'|translate }}</h2>

{{ graphEvolutionVisitsSummary|raw }}

Expand Down

0 comments on commit 13f657c

Please sign in to comment.