Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Dec 3, 2014
2 parents 150072c + 79ea4ec commit e6aa8ee
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
src_dir: .
coverage_clover: build/logs/clover-*.xml
12 changes: 7 additions & 5 deletions core/Plugin/Visualization.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,13 @@ private function applyFilters()
$this->dataTable->applyQueuedFilters();
}

$formatter = $this->metricsFormatter;
$report = $this->report;
$this->dataTable->filter(function (DataTable $table) use ($formatter, $report) {
$formatter->formatMetrics($table, $report);
});
if ($this->requestConfig->shouldFormatMetrics()) {
$formatter = $this->metricsFormatter;
$report = $this->report;
$this->dataTable->filter(function (DataTable $table) use ($formatter, $report) {
$formatter->formatMetrics($table, $report);
});
}
}

private function removeEmptyColumnsFromDisplay()
Expand Down
5 changes: 5 additions & 0 deletions core/ViewDataTable/RequestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,9 @@ public function getApiMethodToRequest()

return $method;
}

public function shouldFormatMetrics()
{
return Common::getRequestVar('format_metrics', '1', 'string', $this->request_parameters_to_modify) != 0;
}
}
7 changes: 4 additions & 3 deletions plugins/API/RowEvolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ private function loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date,
// note: some reports should not be filtered with AddColumnProcessedMetrics
// specifically, reports without the Metrics::INDEX_NB_VISITS metric such as Goals.getVisitsUntilConversion & Goal.getDaysToConversion
// this is because the AddColumnProcessedMetrics filter removes all datable rows lacking this metric
if ( isset($metadata['metrics']['nb_visits'])
&& !empty($label)) {
$parameters['filter_add_columns_when_show_all_columns'] = '1';
if (isset($metadata['metrics']['nb_visits'])
&& !empty($label)
) {
$parameters['filter_add_columns_when_show_all_columns'] = '0';
}

$url = Url::getQueryStringFromParameters($parameters);
Expand Down
19 changes: 17 additions & 2 deletions plugins/CoreHome/javascripts/dataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1890,11 +1890,26 @@ var switchToHtmlTable = function (dataTable, viewDataTable) {
dataTable.notifyWidgetParametersChange(dataTable.$element, {viewDataTable: viewDataTable});
};

var switchToEcommerceView = function (dataTable, viewDataTable) {
if (viewDataTable == 'ecommerceOrder') {
dataTable.param.abandonedCarts = '0';
} else {
dataTable.param.abandonedCarts = '1';
}

var viewDataTable = dataTable.param.viewDataTable;
if (viewDataTable == 'ecommerceOrder' || viewDataTable == 'ecommerceAbandonedCart') {
viewDataTable = 'table';
}

switchToHtmlTable(dataTable, viewDataTable);
};

DataTable.registerFooterIconHandler('table', switchToHtmlTable);
DataTable.registerFooterIconHandler('tableAllColumns', switchToHtmlTable);
DataTable.registerFooterIconHandler('tableGoals', switchToHtmlTable);
DataTable.registerFooterIconHandler('ecommerceOrder', switchToHtmlTable);
DataTable.registerFooterIconHandler('ecommerceAbandonedCart', switchToHtmlTable);
DataTable.registerFooterIconHandler('ecommerceOrder', switchToEcommerceView);
DataTable.registerFooterIconHandler('ecommerceAbandonedCart', switchToEcommerceView);

// generic function to handle switch to graph visualizations
DataTable.switchToGraph = function (dataTable, viewDataTable) {
Expand Down
60 changes: 34 additions & 26 deletions plugins/CoreHome/javascripts/dataTable_rowactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,22 @@ DataTable_RowActions_RowEvolution.prototype.performAction = function (label, tr,
return;
}

// check whether we have rows marked for multi row evolution
var isMultiRowEvolution = '0';
this.addMultiEvolutionRow(label);

// check whether we have rows marked for multi row evolution
var extraParams = {};
if (this.multiEvolutionRows.length > 1) {
isMultiRowEvolution = '1';
extraParams.action = 'getMultiRowEvolutionPopover';
label = this.multiEvolutionRows.join(',');
}

// check if abandonedCarts is in the dataTable params and if so, propagate to row evolution request
if (this.dataTable.param.abandonedCarts !== undefined) {
extraParams['abandonedCarts'] = this.dataTable.param.abandonedCarts;
}

var apiMethod = this.dataTable.param.module + '.' + this.dataTable.param.action;
this.openPopover(apiMethod, isMultiRowEvolution, label);
this.openPopover(apiMethod, extraParams, label);
};

DataTable_RowActions_RowEvolution.prototype.addMultiEvolutionRow = function (label) {
Expand All @@ -292,27 +298,37 @@ DataTable_RowActions_RowEvolution.prototype.addMultiEvolutionRow = function (lab
}
};

DataTable_RowActions_RowEvolution.prototype.openPopover = function (apiMethod, multiRowEvolutionParam, label) {
var urlParam = apiMethod + ':' + multiRowEvolutionParam + ':' + label;
DataTable_RowActions_RowEvolution.prototype.openPopover = function (apiMethod, extraParams, label) {
var urlParam = apiMethod + ':' + encodeURIComponent(JSON.stringify(extraParams)) + ':' + label;
DataTable_RowAction.prototype.openPopover.apply(this, [urlParam]);
};

DataTable_RowActions_RowEvolution.prototype.doOpenPopover = function (urlParam) {
var urlParamParts = urlParam.split(':');

var apiMethod = urlParamParts[0];
urlParamParts.shift();

var multiRowEvolutionParam = urlParamParts[0];
urlParamParts.shift();
var apiMethod = urlParamParts.shift();

var extraParamsString = urlParamParts.shift(),
extraParams = {}; // 0/1 or "0"/"1"
try {
extraParams = JSON.parse(decodeURIComponent(extraParamsString));
} catch (e) {
// assume the parameter is an int/string describing whether to use multi row evolution
if (extraParamsString == '1') {
extraParams.action = 'getMultiRowEvolutionPopover';
} else if (extraParamsString != '0') {
extraParams.action = 'getMultiRowEvolutionPopover';
extraParams.column = extraParamsString;
}
}

var label = urlParamParts.join(':');

this.showRowEvolution(apiMethod, label, multiRowEvolutionParam);
this.showRowEvolution(apiMethod, label, extraParams);
};

/** Open the row evolution popover */
DataTable_RowActions_RowEvolution.prototype.showRowEvolution = function (apiMethod, label, multiRowEvolutionParam) {
DataTable_RowActions_RowEvolution.prototype.showRowEvolution = function (apiMethod, label, extraParams) {

var self = this;

Expand All @@ -327,17 +343,6 @@ DataTable_RowActions_RowEvolution.prototype.showRowEvolution = function (apiMeth
disableLink: 1
};

// derive api action and requested column from multiRowEvolutionParam
var action;
if (multiRowEvolutionParam == '0') {
action = 'getRowEvolutionPopover';
} else if (multiRowEvolutionParam == '1') {
action = 'getMultiRowEvolutionPopover';
} else {
action = 'getMultiRowEvolutionPopover';
requestParams.column = multiRowEvolutionParam;
}

var callback = function (html) {
Piwik_Popover.setContent(html);

Expand Down Expand Up @@ -371,15 +376,18 @@ DataTable_RowActions_RowEvolution.prototype.showRowEvolution = function (apiMeth
box.find('select.multirowevoltion-metric').change(function () {
var metric = $(this).val();
Piwik_Popover.onClose(false); // unbind listener that resets multiEvolutionRows
self.openPopover(apiMethod, metric, label);
var extraParams = {action: 'getMultiRowEvolutionPopover', column: metric};
self.openPopover(apiMethod, extraParams, label);
return true;
});
};

requestParams.module = 'CoreHome';
requestParams.action = action;
requestParams.action = 'getRowEvolutionPopover';
requestParams.colors = JSON.stringify(piwik.getSparklineColors());

$.extend(requestParams, extraParams);

var ajaxRequest = new ajaxHelper();
ajaxRequest.addParams(requestParams, 'get');
ajaxRequest.setCallback(callback);
Expand Down
7 changes: 5 additions & 2 deletions plugins/CoreHome/templates/_dataTableFooter.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
<div class="tableIconsGroup">
<span class="{{ footerIconGroup.class }}">
{% for footerIcon in footerIconGroup.buttons %}
{% set isActiveEcommerceView = clientSideParameters.abandonedCarts is defined and
((footerIcon.id == 'ecommerceOrder' and clientSideParameters.abandonedCarts == 0) or
(footerIcon.id == 'ecommerceAbandonedCart' and clientSideParameters.abandonedCarts == 1)) %}
<span>
{% if properties.show_active_view_icon and clientSideParameters.viewDataTable == footerIcon.id %}
{% if properties.show_active_view_icon and (clientSideParameters.viewDataTable == footerIcon.id or isActiveEcommerceView) %}
<img src="plugins/Morpheus/images/data_table_footer_active_item.png" class="dataTableFooterActiveItem"/>
{% endif %}
<a class="tableIcon {% if clientSideParameters.viewDataTable == footerIcon.id %}activeIcon{% endif %}" data-footer-icon-id="{{ footerIcon.id }}">
<a class="tableIcon {% if clientSideParameters.viewDataTable == footerIcon.id or isActiveEcommerceView %}activeIcon{% endif %}" data-footer-icon-id="{{ footerIcon.id }}">
<img width="16" height="16" title="{{ footerIcon.title }}" src="{{ footerIcon.icon }}"/>
{% if footerIcon.text is defined %}<span>{{ footerIcon.text }}</span>{% endif %}
</a>
Expand Down
1 change: 1 addition & 0 deletions plugins/CoreVisualizations/Visualizations/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function beforeLoadDataTable()
}

$this->requestConfig->request_parameters_to_modify['disable_queued_filters'] = 1;
$this->requestConfig->request_parameters_to_modify['format_metrics'] = 0;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions plugins/Goals/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ private function getGoalReportsByDimensionTable($conversions, $ecommerce = false
$ecommerceCustomParams = array();
if ($ecommerce) {
if ($preloadAbandonedCart) {
$ecommerceCustomParams['viewDataTable'] = 'ecommerceAbandonedCart';
$ecommerceCustomParams['abandonedCarts'] = '1';
} else {
$ecommerceCustomParams['abandonedCarts'] = '0';
}

$goalReportsByDimension->addReport(
Expand All @@ -457,7 +459,9 @@ private function getGoalReportsByDimensionTable($conversions, $ecommerce = false
foreach ($allReports as $category => $reports) {
$categoryText = Piwik::translate('Goals_ViewGoalsBy', $category);
foreach ($reports as $report) {
if (empty($report['viewDataTable'])) {
if (empty($report['viewDataTable'])
&& empty($report['abandonedCarts'])
) {
$report['viewDataTable'] = 'tableGoals';
}
$customParams['viewDataTable'] = $report['viewDataTable'];
Expand Down
36 changes: 26 additions & 10 deletions plugins/Goals/Reports/BaseEcommerceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Piwik\Piwik;
use Piwik\Plugin\Report;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution;
use Piwik\Plugins\Goals\Goals;
use Piwik\Plugins\Goals\Columns\Metrics\AveragePrice;
use Piwik\Plugins\Goals\Columns\Metrics\AverageQuantity;
Expand Down Expand Up @@ -69,9 +70,11 @@ public function configureView(ViewDataTable $view)
$view->config->show_exclude_low_population = false;
$view->config->show_table_all_columns = false;

$moneyColumns = array('revenue');
$formatter = array(new Formatter(), 'getPrettyMoney');
$view->config->filters[] = array('ColumnCallbackReplace', array($moneyColumns, $formatter, array($idSite)));
if (!($view instanceof Evolution)) {
$moneyColumns = array('revenue');
$formatter = array(new Formatter(), 'getPrettyMoney');
$view->config->filters[] = array('ColumnCallbackReplace', array($moneyColumns, $formatter, array($idSite)));
}

$view->requestConfig->filter_limit = 10;
$view->requestConfig->filter_sort_column = 'revenue';
Expand All @@ -85,7 +88,19 @@ public function configureView(ViewDataTable $view)
$columnsOrdered = array('label', 'revenue', 'quantity', 'orders', 'avg_price', 'avg_quantity',
'nb_visits', 'conversion_rate');

$abandonedCart = $this->isAbandonedCart();
// handle old case where viewDataTable is set to ecommerceOrder/ecommerceAbandonedCart. in this case, we
// set abandonedCarts accordingly and remove the ecommerceOrder/ecommerceAbandonedCart as viewDataTable.
$viewDataTable = Common::getRequestVar('viewDataTable', '');
if ($viewDataTable == 'ecommerceOrder') {
$view->config->custom_parameters['viewDataTable'] = 'table';
$abandonedCart = false;
} else if ($viewDataTable == 'ecommerceAbandonedCart') {
$view->config->custom_parameters['viewDataTable'] = 'table';
$abandonedCart = true;
} else {
$abandonedCart = $this->isAbandonedCart();
}

if ($abandonedCart) {
$columns['abandoned_carts'] = Piwik::translate('General_AbandonedCarts');
$columns['revenue'] = Piwik::translate('Goals_LeftInCart', $columns['revenue']);
Expand All @@ -94,23 +109,24 @@ public function configureView(ViewDataTable $view)
unset($columns['orders']);
unset($columns['conversion_rate']);

$view->requestConfig->request_parameters_to_modify['abandonedCarts'] = '1';

$columnsOrdered = array('label', 'revenue', 'quantity', 'avg_price', 'avg_quantity', 'nb_visits',
'abandoned_carts');

$view->config->custom_parameters['abandonedCarts'] = '1';
} else {
$view->config->custom_parameters['abandonedCarts'] = '0';
}

$view->requestConfig->request_parameters_to_modify['abandonedCarts'] = $view->config->custom_parameters['abandonedCarts'];

$translations = array_merge(array('label' => $this->name), $columns);

$view->config->addTranslations($translations);
$view->config->columns_to_display = $columnsOrdered;

$view->config->custom_parameters['viewDataTable'] =
$abandonedCart ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART : Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER;
}

private function isAbandonedCart()
{
return Common::getRequestVar('viewDataTable', 'ecommerceOrder', 'string') == 'ecommerceAbandonedCart';
return Common::getRequestVar('abandonedCarts', '0', 'string') == 1;
}
}
2 changes: 1 addition & 1 deletion tests/PHPUnit/UI
Submodule UI updated from 293156 to e1361b

0 comments on commit e6aa8ee

Please sign in to comment.