Skip to content

Commit

Permalink
Adds option to format metrics in export overlay (matomo-org#12987)
Browse files Browse the repository at this point in the history
* Adds option to format metrics in export overlay

* update ui test

* Make it possible to show the export url
  • Loading branch information
sgiehl authored and InfinityVoid committed Oct 11, 2018
1 parent 7dcb1ed commit 407cb30
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 73 deletions.
3 changes: 3 additions & 0 deletions plugins/CoreHome/CoreHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = 'CoreHome_DataTableExcludeAggregateRows';
$translationKeys[] = 'CoreHome_Default';
$translationKeys[] = 'CoreHome_PageOf';
$translationKeys[] = 'CoreHome_FormatMetrics';
$translationKeys[] = 'CoreHome_ShowExportUrl';
$translationKeys[] = 'CoreHome_HideExportUrl';
$translationKeys[] = 'CoreHome_FlattenDataTable';
$translationKeys[] = 'CoreHome_UnFlattenDataTable';
$translationKeys[] = 'CoreHome_ExternalHelp';
Expand Down
28 changes: 20 additions & 8 deletions plugins/CoreHome/angularjs/report-export/reportexport.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

var popoverParamBackup;

scope.processExport = function() {
scope.showUrl = false;

scope.getExportLink = function() {

var dataTable = scope.dataTable;
var format = scope.reportFormat;
Expand Down Expand Up @@ -117,6 +119,10 @@
exportUrlParams.expanded = 1;
}

if (scope.optionFormatMetrics) {
exportUrlParams.format_metrics = 1;
}

if (dataTable.param.pivotBy) {
exportUrlParams.pivotBy = dataTable.param.pivotBy;
exportUrlParams.pivotByColumnLimit = 20;
Expand Down Expand Up @@ -155,7 +161,12 @@
exportUrlParams.token_auth = piwik.token_auth;
exportUrlParams.filter_limit = limit;

window.open('index.php?' + $httpParamSerializerJQLike(exportUrlParams));
var currentUrl = $location.absUrl();
var urlParts = currentUrl.split('/');
urlParts.pop();
var url = urlParts.join('/');

return url + '/index.php?' + $httpParamSerializerJQLike(exportUrlParams);
};

element.on('click', function () {
Expand All @@ -166,12 +177,13 @@
var popover = Piwik_Popover.showLoading('Export');
var formats = JSON.parse(scope.reportFormats);

scope.reportType = 'default';
scope.reportLimit = dataTable.param.filter_limit > 0 ? dataTable.param.filter_limit : 100;
scope.reportLimitAll = dataTable.param.filter_limit == -1 ? 'yes' : 'no';
scope.optionFlat = dataTable.param.flat;
scope.optionExpanded = 1;
scope.hasSubtables = dataTable.param.flat == 1 || dataTable.numberOfSubtables > 0;
scope.reportType = 'default';
scope.reportLimit = dataTable.param.filter_limit > 0 ? dataTable.param.filter_limit : 100;
scope.reportLimitAll = dataTable.param.filter_limit == -1 ? 'yes' : 'no';
scope.optionFlat = dataTable.param.flat;
scope.optionExpanded = 1;
scope.optionFormatMetrics = 0;
scope.hasSubtables = dataTable.param.flat == 1 || dataTable.numberOfSubtables > 0;

scope.availableReportFormats = {
default: formats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
ng-model="$parent.optionExpanded" ng-show="$parent.hasSubtables && !$parent.optionFlat"
>
</div>
<div piwik-field uicontrol="checkbox" name="option_format_metrics"
title="{{ 'CoreHome_FormatMetrics'|translate }}"
ng-model="$parent.optionFormatMetrics"
>
</div>
</div>

<div class="col l6">
Expand All @@ -44,8 +49,16 @@
</div>
</div>

<div class="col l12" ng-show="showUrl">
<textarea readonly>{{ getExportLink() }}</textarea>
</div>

<div class="col l12">
<div piwik-save-button value="{{ 'General_Export'|translate }}" ng-click="processExport()"></div>
<a class="btn" ng-attr-href="{{ getExportLink() }}" target="_new">{{ 'General_Export'|translate }}</a>
<a href="javascript:;" ng-click="showUrl=!showUrl" class="toggle-export-url">
<span ng-show="!showUrl">{{ 'CoreHome_ShowExportUrl'|translate }}</span>
<span ng-show="showUrl">{{ 'CoreHome_HideExportUrl'|translate }}</span>
</a>
</div>

</div>
11 changes: 11 additions & 0 deletions plugins/CoreHome/angularjs/report-export/reportexport.popover.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
}
}

textarea {
word-break: break-all;
padding: 5px;
height: 80px;
}

.toggle-export-url {
font-size: 14px;
margin-left: 20px;
}

.filter_limit {
clear: both;
float: none;
Expand Down
3 changes: 3 additions & 0 deletions plugins/CoreHome/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"ExcludeRowsWithLowPopulation": "All rows are shown %s Exclude low population",
"ExternalHelp": "Help (opens in new tab)",
"FlattenDataTable": "The report is hierarchical %s Make it flat",
"FormatMetrics": "Format metrics",
"ShowExportUrl": "Show Export URL",
"HideExportUrl": "Hide Export URL",
"HomeShortcut": "Home",
"HowMuchIsPiwikWorth": "How much is Matomo worth to you?",
"IncludeRowsWithLowPopulation": "Rows with low population are hidden %s Show all rows",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 3 additions & 62 deletions tests/UI/specs/ReportExporting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@
describe("ReportExporting", function () {
this.timeout(0);

function setWindowOpen(page) {
page.evaluate(function(){
window.downloadUrl = null;
window.openBackup = window.open;

window.open = function(url) {
window.downloadUrl = url;
return false;
}
})
}

function unsetWindowOpen(page) {
page.evaluate(function() {
window.open = window.openBackup;
});
}

var baseUrl = "?module=Widgetize&action=iframe&idSite=1&period=year&date=2012-08-09&isFooterExpandedInDashboard=1",
referrersGetWebsitesUrl = baseUrl + "&moduleToWidgetize=Referrers&actionToWidgetize=getWebsites&filter_limit=5",
visitsSummaryGetUrl = baseUrl + "&moduleToWidgetize=VisitsSummary&actionToWidgetize=get&forceView=1&viewDataTable=graphEvolution";
Expand All @@ -39,29 +21,16 @@ describe("ReportExporting", function () {
if (page.getCurrentUrl() != referrersGetWebsitesUrl) {
page.load(referrersGetWebsitesUrl);
page.click('.activateExportSelection');
page.evaluate(function(){
$('<a>').attr('id', 'downloadLink').appendTo('body');
});
}

setWindowOpen(page);

page.click('[name=format] input[value='+format+'] + label', 100);
page.click('[name=filter_limit_all] input[value=no] + label', 100);
page.evaluate(function(){
$('[name=filter_limit] input').val(100).trigger('change');
});
page.click('[ng-click="processExport()"]', 100);

unsetWindowOpen(page);

page.execCallback(function () {
page.webpage.evaluate(function () {
$('a#downloadLink').attr('href', window.downloadUrl);
});
});

page.downloadLink('a#downloadLink');
page.downloadLink('#reportExport a.btn');
}, done);
});
}
Expand All @@ -72,29 +41,15 @@ describe("ReportExporting", function () {
if (page.getCurrentUrl() != visitsSummaryGetUrl) {
page.load(visitsSummaryGetUrl);
page.click('.activateExportSelection');
page.evaluate(function(){
$('<a>').attr('id', 'downloadLink').appendTo('body');
});
}

setWindowOpen(page);

page.click('[name=format] input[value='+format+'] + label', 100);
page.click('[name=filter_limit_all] input[value=no] + label', 100);
page.evaluate(function(){
$('[name=filter_limit] input').val(100).trigger('change');
});
page.click('[ng-click="processExport()"]', 100);

unsetWindowOpen(page);

page.execCallback(function () {
page.webpage.evaluate(function () {
$('a#downloadLink').attr('href', window.downloadUrl);
});
});

page.downloadLink('a#downloadLink');
page.downloadLink('#reportExport a.btn');
}, done);
});
}
Expand All @@ -108,29 +63,15 @@ describe("ReportExporting", function () {
page.mouseMove('a.actionRowEvolution:visible'); // necessary to get popover to display
page.click('a.actionRowEvolution:visible');
page.click('.ui-dialog .activateExportSelection');
page.evaluate(function(){
$('<a>').attr('id', 'downloadLink').appendTo('body');
});
}

setWindowOpen(page);

page.click('[name=format] input[value='+format+'] + label', 100);
page.click('[name=filter_limit_all] input[value=no] + label', 100);
page.evaluate(function(){
$('[name=filter_limit] input').val(100).trigger('change');
});
page.click('[ng-click="processExport()"]', 100);

unsetWindowOpen(page);

page.execCallback(function () {
page.webpage.evaluate(function () {
$('a#downloadLink').attr('href', window.downloadUrl);
});
});

page.downloadLink('a#downloadLink');
page.downloadLink('#reportExport a.btn');
}, done);
});
}
Expand Down

0 comments on commit 407cb30

Please sign in to comment.