Skip to content

Commit

Permalink
Refs matomo-org#4041, remove DatatableManager class and replace with …
Browse files Browse the repository at this point in the history
…UIControl code.
  • Loading branch information
Benaka Moorthi committed Sep 20, 2013
1 parent ef90542 commit 4d5d101
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 136 deletions.
1 change: 0 additions & 1 deletion plugins/CoreHome/CoreHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function getJsFiles(&$jsFiles)
$jsFiles[] = "plugins/CoreHome/javascripts/autocomplete.js";
$jsFiles[] = "plugins/CoreHome/javascripts/sparkline.js";
$jsFiles[] = "plugins/CoreHome/javascripts/corehome.js";
$jsFiles[] = "plugins/CoreHome/javascripts/dataTable_manager.js";
$jsFiles[] = "plugins/CoreHome/javascripts/donate.js";
$jsFiles[] = "libs/jqplot/jqplot-custom.min.js";
$jsFiles[] = "plugins/CoreHome/javascripts/promo.js";
Expand Down
44 changes: 39 additions & 5 deletions plugins/CoreHome/javascripts/dataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var exports = require('piwik/UI'),
* This class contains the client side logic for viewing and interacting with
* Piwik datatables.
*
* The id attribute for DataTables is set dynamically by the DataTableManager
* class, and this class instance is stored using the jQuery $.data function
* The id attribute for DataTables is set dynamically by the initNewDataTables
* method, and this class instance is stored using the jQuery $.data function
* with the 'uiControlObject' key.
*
* To find a datatable element by report (ie, 'UserSettings.getBrowser'),
* use piwik.DataTableManager.getDataTableByReport.
* use piwik.DataTable.getDataTableByReport.
*
* To get the dataTable JS instance (an instance of this class) for a
* datatable HTML element, use $(element).data('uiControlObject').
Expand All @@ -33,11 +33,21 @@ var exports = require('piwik/UI'),
function DataTable(element) {
UIControl.call(this, element);

this.param = {};
this.init();
}

DataTable._footerIconHandlers = {}

DataTable.initNewDataTables = function () {
$('div.dataTable').each(function () {
if (!$(this).attr('id')) {
var tableType = $(this).attr('data-table-type') || 'DataTable',
klass = require('piwik/UI')[tableType] || require(tableType),
table = new klass(this);
}
});
};

DataTable.registerFooterIconHandler = function (id, handler) {
var handlers = DataTable._footerIconHandlers;

Expand All @@ -51,13 +61,33 @@ DataTable.registerFooterIconHandler = function (id, handler) {
handlers[id] = handler;
};

/**
* Returns the first datatable div displaying a specific report.
*
* @param {string} report The report, eg, UserSettings.getWideScreen
* @return {Element} The datatable div displaying the report, or undefined if
* it cannot be found.
*/
DataTable.getDataTableByReport = function (report) {
var result = undefined;
$('.dataTable').each(function () {
if ($(this).attr('data-report') == report) {
result = this;
return false;
}
});
return result;
};

$.extend(DataTable.prototype, UIControl.prototype, {

//initialisation function
init: function () {
var domElem = this.$element;

this.workingDivId = domElem.attr('id');
this.workingDivId = this._createDivId();
domElem.attr('id', this.workingDivId);

this.loadedSubDataTable = {};
this.isEmpty = $('.pk-emptyDataTable', domElem).length > 0;
this.bindEventsAndApplyStyle(domElem);
Expand Down Expand Up @@ -1516,6 +1546,10 @@ $.extend(DataTable.prototype, UIControl.prototype, {
h2 = $('h2', domElem);
}
return h2;
},

_createDivId: function () {
return 'dataTable_' + this._controlId;
}
});

Expand Down
123 changes: 0 additions & 123 deletions plugins/CoreHome/javascripts/dataTable_manager.js

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/CoreHome/javascripts/dataTable_rowactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ DataTable_RowActions_Registry.register({
// when row evolution is triggered from the url (not a click on the data table)
// we look for the data table instance in the dom
var report = param.split(':')[0];
var div = $(piwik.DataTableManager.getDataTableByReport(report));
var div = $(require('piwik/UI').DataTable.getDataTableByReport(report));
if (div.size() > 0 && div.data('uiControlObject')) {
dataTable = div.data('uiControlObject');
if (typeof dataTable.rowEvolutionActionInstance != 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/javascripts/sparkline.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ window.initializeSparklines = function () {
// on click, reload the graph with the new url
$(this).click(function () {
var reportId = graph.attr('data-graph-id'),
dataTable = $(piwik.DataTableManager.getDataTableByReport(reportId));
dataTable = $(require('piwik/UI').DataTable.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.
Expand Down
13 changes: 12 additions & 1 deletion plugins/CoreHome/javascripts/uiControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@
* @param {Element} element The root element of the control.
*/
var UIControl = function (element) {
this._controlIndex = UIControl._controls.length;
this._controlId = UIControl._controls.length;
UIControl._controls.push(this);

var $element = this.$element = $(element);
$element.data('uiControlObject', this);

// convert values in params that are arrays to comma separated string lists
var params = JSON.parse($element.attr('data-params') || '{}');
for (var key in params) {
if (params[key] instanceof Array) {
params[key] = params[key].join(',');
}
}
this.param = params;

this.props = JSON.parse($element.attr('data-props') || '{}');
};

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/templates/_dataTableJS.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script type="text/javascript" defer="defer">
$(document).ready(function () {
piwik.DataTableManager.initNewDataTables();
require('piwik/UI/DataTable').initNewDataTables();
});
</script>
2 changes: 1 addition & 1 deletion plugins/UserCountryMap/javascripts/realtime-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}

// set unique ID for kartograph map div
this.uniqueId = 'RealTimeMap_map-' + this._controlIndex;
this.uniqueId = 'RealTimeMap_map-' + this._controlId;
$('.RealTimeMap_map', $element).attr('id', this.uniqueId);

// create the map
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/UI
Submodule UI updated from 91a83c to f8ddb7
2 changes: 1 addition & 1 deletion tests/PHPUnit/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ then
else
if [ -n "$TEST_DIR" ]
then
phpunit --colors $TEST_DIR
phpunit --colors $TEST_DIR
else
phpunit --configuration phpunit.xml --coverage-text --colors
fi
Expand Down

0 comments on commit 4d5d101

Please sign in to comment.