Skip to content

Commit

Permalink
Remove usage of synchronous ajax requests (#12546)
Browse files Browse the repository at this point in the history
* Do not use sync ajax requests

* adds deprecation comments

* convert some methods to be fully async

* adds minimum waittime after page load in ui tests

* improve wait times
  • Loading branch information
sgiehl authored and diosmosis committed Jun 14, 2018
1 parent 8b5f334 commit 6a0c960
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 185 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)*

### Breaking Changes
`piwik` font is deprecated and will be removed in Matomo 4.0. Please use new `matomo` font instead
Sending synchronous requests using ajaxHelper is now deprecated. All requests will be send async as of Matomo 4.0

### New APIs
* A new JavaScript tracker method `resetUserId` has been added to allow clearing user and visitor id.
Expand Down
10 changes: 5 additions & 5 deletions plugins/Annotations/javascripts/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ajaxRequest.addParams(ajaxParams, 'get');
ajaxRequest.setCallback(callback);
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
},

// calls Annotations.addAnnotation
Expand All @@ -49,7 +49,7 @@
ajaxRequest.withTokenInUrl();
ajaxRequest.setCallback(callback);
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
},

// calls Annotations.saveAnnotation
Expand All @@ -72,7 +72,7 @@
ajaxRequest.withTokenInUrl();
ajaxRequest.setCallback(callback);
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
},

// calls Annotations.deleteAnnotation
Expand All @@ -92,7 +92,7 @@
ajaxRequest.withTokenInUrl();
ajaxRequest.setCallback(callback);
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
},

// calls Annotations.getEvolutionIcons
Expand All @@ -114,7 +114,7 @@
ajaxRequest.addParams(ajaxParams, 'get');
ajaxRequest.setFormat('html');
ajaxRequest.setCallback(callback);
ajaxRequest.send(false);
ajaxRequest.send();
}
};

Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/javascripts/corehome.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
});
});
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();

return false;
});
Expand Down
4 changes: 2 additions & 2 deletions plugins/CoreHome/javascripts/dataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ $.extend(DataTable.prototype, UIControl.prototype, {
});
ajaxRequest.setFormat('html');

ajaxRequest.send(false);
ajaxRequest.send();
},

// Function called when the AJAX request is successful
Expand Down Expand Up @@ -1361,7 +1361,7 @@ $.extend(DataTable.prototype, UIControl.prototype, {
}, 'post');
ajaxRequest.setCallback(function () {});
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
}
},

Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/javascripts/dataTable_rowactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,5 +426,5 @@ DataTable_RowActions_RowEvolution.prototype.showRowEvolution = function (apiMeth
ajaxRequest.addParams(requestParams, 'get');
ajaxRequest.setCallback(callback);
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
};
2 changes: 1 addition & 1 deletion plugins/CoreHome/javascripts/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ var Piwik_Popover = (function () {
ajaxRequest.addParams(piwikHelper.getArrayFromQueryString(url), 'get');
ajaxRequest.setCallback(callback);
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
}
};
})();
2 changes: 1 addition & 1 deletion plugins/DBStats/templates/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
piwikHelper.compileAngularComponents(self);
});
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
});
});
})(jQuery);
Expand Down
13 changes: 7 additions & 6 deletions plugins/Dashboard/javascripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function createDashboard() {
});
}
);
ajaxRequest.send(true);
ajaxRequest.send();
}});
}

Expand Down Expand Up @@ -120,7 +120,7 @@ function copyDashboardToUser() {
});
}
);
ajaxRequest.send(true);
ajaxRequest.send();

piwikHelper.modalConfirm(makeSelectorLastId('copyDashboardToUserConfirm'), {
yes: function () {
Expand All @@ -145,7 +145,7 @@ function copyDashboardToUser() {
}
);
ajaxRequest.withTokenInUrl();
ajaxRequest.send(true);
ajaxRequest.send();
}
});
}
Expand Down Expand Up @@ -199,10 +199,11 @@ function copyDashboardToUser() {
return self.isWidgetAvailable(widgetUniqueId);
},
onSelect: function (widgetUniqueId) {
var widget = widgetsHelper.getWidgetObjectFromUniqueId(widgetUniqueId);
self.$element.removeClass('expanded');
widgetsHelper.getWidgetObjectFromUniqueId(widgetUniqueId, function(widget){
self.$element.removeClass('expanded');
self.widgetSelected(widget);
});

self.widgetSelected(widget);
},
resetOnSelect: true
});
Expand Down
6 changes: 3 additions & 3 deletions plugins/Dashboard/javascripts/dashboardObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
);
ajaxRequest.setLoadingElement();
ajaxRequest.setFormat('html');
ajaxRequest.send(true);
ajaxRequest.send();
},

rebuildMenu: rebuildMenu,
Expand Down Expand Up @@ -211,7 +211,7 @@
);
ajaxRequest.withTokenInUrl();
ajaxRequest.setFormat('html');
ajaxRequest.send(true);
ajaxRequest.send();
},

/**
Expand Down Expand Up @@ -647,7 +647,7 @@

ajaxRequest.withTokenInUrl();
ajaxRequest.setFormat('html');
ajaxRequest.send(false);
ajaxRequest.send();
}
}

Expand Down
137 changes: 69 additions & 68 deletions plugins/Dashboard/javascripts/dashboardWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,81 +204,83 @@
*/
_createDashboardWidget: function (uniqueId) {

var widgetName = widgetsHelper.getWidgetNameFromUniqueId(uniqueId);
if (!widgetName) {
widgetName = _pk_translate('Dashboard_WidgetNotFound');
}
var self = this;

var title = this.options.title === null ? $('<span/>').text(widgetName) : this.options.title;
var emptyWidgetContent = require('piwik/UI/Dashboard').WidgetFactory.make(uniqueId, title);
this.element.html(emptyWidgetContent);
widgetsHelper.getWidgetNameFromUniqueId(uniqueId, function(widgetName) {
if (!widgetName) {
widgetName = _pk_translate('Dashboard_WidgetNotFound');
}

var widgetElement = $('[id="' + uniqueId + '"]', this.element);
var self = this;
widgetElement
.on('mouseenter.dashboardWidget', function () {
if (!self.isMaximised) {
$(this).addClass('widgetHover');
$('.widgetTop', this).addClass('widgetTopHover');
}
})
.on('mouseleave.dashboardWidget', function () {
if (!self.isMaximised) {
$(this).removeClass('widgetHover');
$('.widgetTop', this).removeClass('widgetTopHover');
}
});

if (this.options.isHidden) {
$('.widgetContent', widgetElement).toggleClass('hidden').closest('.widget').toggleClass('hiddenContent');
}
var title = self.options.title === null ? $('<span/>').text(widgetName) : self.options.title;
var emptyWidgetContent = require('piwik/UI/Dashboard').WidgetFactory.make(uniqueId, title);
self.element.html(emptyWidgetContent);

$('.button#close', widgetElement)
.on('click.dashboardWidget', function (ev) {
piwikHelper.modalConfirm('#confirm', {yes: function () {
if (self.options.onRemove) {
self.options.onRemove(self.element);
var widgetElement = $('[id="' + uniqueId + '"]', self.element);
widgetElement
.on('mouseenter.dashboardWidget', function () {
if (!self.isMaximised) {
$(this).addClass('widgetHover');
$('.widgetTop', this).addClass('widgetTopHover');
}
})
.on('mouseleave.dashboardWidget', function () {
if (!self.isMaximised) {
$(this).removeClass('widgetHover');
$('.widgetTop', this).removeClass('widgetTopHover');
}
});

if (self.options.isHidden) {
$('.widgetContent', widgetElement).toggleClass('hidden').closest('.widget').toggleClass('hiddenContent');
}

$('.button#close', widgetElement)
.on('click.dashboardWidget', function (ev) {
piwikHelper.modalConfirm('#confirm', {yes: function () {
if (self.options.onRemove) {
self.options.onRemove(self.element);
} else {
self.element.remove();
self.options.onChange();
}
}});
});

$('.button#maximise', widgetElement)
.on('click.dashboardWidget', function (ev) {
if (self.options.onMaximise) {
self.options.onMaximise(self.element);
} else {
self.element.remove();
self.options.onChange();
if ($('.widgetContent', $(this).parents('.widget')).hasClass('hidden')) {
self.showContent();
} else {
self.maximise();
}
}
}});
});

$('.button#maximise', widgetElement)
.on('click.dashboardWidget', function (ev) {
if (self.options.onMaximise) {
self.options.onMaximise(self.element);
} else {
if ($('.widgetContent', $(this).parents('.widget')).hasClass('hidden')) {
self.showContent();
});

$('.button#minimise', widgetElement)
.on('click.dashboardWidget', function (ev) {
if (self.options.onMinimise) {
self.options.onMinimise(self.element);
} else {
self.maximise();
if (!self.isMaximised) {
self.hideContent();
} else {
self.element.dialog("close");
}
}
}
});

$('.button#minimise', widgetElement)
.on('click.dashboardWidget', function (ev) {
if (self.options.onMinimise) {
self.options.onMinimise(self.element);
} else {
if (!self.isMaximised) {
self.hideContent();
});

$('.button#refresh', widgetElement)
.on('click.dashboardWidget', function (ev) {
if (self.options.onRefresh) {
self.options.onRefresh(self.element);
} else {
self.element.dialog("close");
self.reload(false, true);
}
}
});

$('.button#refresh', widgetElement)
.on('click.dashboardWidget', function (ev) {
if (self.options.onRefresh) {
self.options.onRefresh(self.element);
} else {
self.reload(false, true);
}
});
});
});
},

/**
Expand Down Expand Up @@ -350,8 +352,7 @@
*/
detachWidget: function () {
this.element.before('<div id="' + this.uniqueId + '-placeholder" class="widgetPlaceholder widget"> </div>');
var placeholder = $('[id="' + self.uniqueId + '-placeholder"]')

var placeholder = $('[id="' + self.uniqueId + '-placeholder"]');

$('#' + this.uniqueId + '-placeholder').height(this.element.height());
$('#' + this.uniqueId + '-placeholder').width(this.element.width() - 16);
Expand Down
Loading

0 comments on commit 6a0c960

Please sign in to comment.