Commit 49bdb6dc authored by Benjamin Franzke's avatar Benjamin Franzke Committed by Benni Mack
Browse files

[TASK] Use core AjaxRequest instead d3.request

d3 is currently manually patched to avoid a
d3.request()/d3.json() bug in chome >= 64 – see #83741.
The patch has not been merged in two years, and d3.request
is deprecated, so it is now replaced.
This will also help to upgrade to D3.js v5/v6 at some
point.

This allows to use an unpatched, vanilla D3.js build again.
While at it, we also streamline the contrib path to avoid the
unecessary d3/ subdirectory.

Commands used:

  grunt build

Resolves: #93186
Related: #83741
Releases: master
Change-Id: I142462272b03edc53c33b2b7233d1902911fc837
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67313

Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent a4c46863
......@@ -620,12 +620,7 @@ module.exports = function (grunt) {
/* disabled until autocomplete formatGroup is fixed to pass on the index too
'jquery.autocomplete.js': '../node_modules/devbridge-autocomplete/dist/jquery.autocomplete.min.js',
*/
/**
* d3/d3.js requires a patch https://github.com/d3/d3-request/pull/34/files
* to solve issue with basic auth in Chrome 64, see https://forge.typo3.org/issues/83741
* for now the file is manually patched by us, thus can't be automatically updated
*/
// 'd3/d3.js': 'd3/build/d3.min.js',
'd3.js': 'd3/build/d3.min.js',
/**
* copy needed parts of jquery
*/
......
......@@ -16,6 +16,7 @@
*/
define(['jquery',
'd3',
'TYPO3/CMS/Core/Ajax/AjaxRequest',
'TYPO3/CMS/Backend/Icons',
'TYPO3/CMS/Backend/PageTree/PageTreeDragDrop',
'TYPO3/CMS/Backend/SvgTree',
......@@ -23,7 +24,7 @@ define(['jquery',
'TYPO3/CMS/Backend/Storage/Persistent',
'TYPO3/CMS/Backend/Notification'
],
function($, d3, Icons, PageTreeDragDrop, SvgTree, ContextMenu, Persistent, Notification) {
function($, d3, AjaxRequest, Icons, PageTreeDragDrop, SvgTree, ContextMenu, Persistent, Notification) {
'use strict';
/**
......@@ -169,38 +170,35 @@ define(['jquery',
_this.nodesAddPlaceholder();
d3.request(top.TYPO3.settings.ajaxUrls.record_process)
.header('X-Requested-With', 'XMLHttpRequest')
.header('Content-Type', 'application/x-www-form-urlencoded')
.on('error', function(error) {
_this.errorNotification(error);
throw error;
(new AjaxRequest(top.TYPO3.settings.ajaxUrls.record_process))
.post(params, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest'},
})
.post(params, function(data) {
if (data) {
var response = JSON.parse(data.response);
if (response && response.hasErrors) {
if (response.messages) {
$.each(response.messages, function(id, message) {
Notification.error(
message.title,
message.message
);
});
} else {
_this.errorNotification();
}
_this.nodesContainer.selectAll('.node').remove();
_this.update();
_this.nodesRemovePlaceholder();
.then(function(response) {
return response.resolve();
})
.then(function(response) {
if (response && response.hasErrors) {
if (response.messages) {
$.each(response.messages, function(id, message) {
Notification.error(
message.title,
message.message
);
});
} else {
_this.refreshOrFilterTree();
_this.errorNotification();
}
_this.nodesContainer.selectAll('.node').remove();
_this.update();
_this.nodesRemovePlaceholder();
} else {
_this.errorNotification();
_this.refreshOrFilterTree();
}
})
.catch(function(error) {
_this.errorNotification(error);
});
};
......@@ -315,23 +313,14 @@ define(['jquery',
}
var _this = this;
_this.nodesAddPlaceholder();
d3.json(_this.settings.dataUrl + '&pid=' + parentNode.identifier + '&mount=' + parentNode.mountPoint + '&pidDepth=' + parentNode.depth, function(error, json) {
if (error) {
var title = TYPO3.lang.pagetree_networkErrorTitle;
var desc = TYPO3.lang.pagetree_networkErrorDesc;
if (error && error.target && (error.target.status || error.target.statusText)) {
title += ' - ' + (error.target.status || '') + ' ' + (error.target.statusText || '');
}
Notification.error(
title,
desc);
_this.nodesRemovePlaceholder();
throw error;
}
(new AjaxRequest(_this.settings.dataUrl + '&pid=' + parentNode.identifier + '&mount=' + parentNode.mountPoint + '&pidDepth=' + parentNode.depth))
.get({cache: 'no-cache'})
.then(function(response) {
return response.resolve();
})
.then(function(json) {
var nodes = Array.isArray(json) ? json : [];
//first element is a parent
nodes.shift();
......@@ -347,8 +336,22 @@ define(['jquery',
_this.update();
_this.nodesRemovePlaceholder();
_this.switchFocusNode(parentNode);
});
})
.catch(function (error) {
var title = TYPO3.lang.pagetree_networkErrorTitle;
var desc = TYPO3.lang.pagetree_networkErrorDesc;
if (error && error.target && (error.target.status || error.target.statusText)) {
title += ' - ' + (error.target.status || '') + ' ' + (error.target.statusText || '');
}
Notification.error(
title,
desc);
_this.nodesRemovePlaceholder();
throw error;
});
};
PageTree.prototype.updateNodeBgClass = function(nodeBg) {
......@@ -457,8 +460,22 @@ define(['jquery',
var _this = this;
_this.nodesAddPlaceholder();
d3.json(_this.settings.filterUrl + '&q=' + _this.searchQuery, function(error, json) {
if (error) {
(new AjaxRequest(_this.settings.filterUrl + '&q=' + _this.searchQuery))
.get({cache: 'no-cache'})
.then(function(response) {
return response.resolve();
})
.then(function(json) {
var nodes = Array.isArray(json) ? json : [];
if (nodes.length > 0) {
if (_this.originalNodes.length === 0) {
_this.originalNodes = JSON.stringify(_this.nodes);
}
_this.replaceData(nodes);
}
_this.nodesRemovePlaceholder();
})
.catch(function(error) {
var title = TYPO3.lang.pagetree_networkErrorTitle;
var desc = TYPO3.lang.pagetree_networkErrorDesc;
......@@ -472,17 +489,7 @@ define(['jquery',
_this.nodesRemovePlaceholder();
throw error;
}
var nodes = Array.isArray(json) ? json : [];
if (nodes.length > 0) {
if (_this.originalNodes.length === 0) {
_this.originalNodes = JSON.stringify(_this.nodes);
}
_this.replaceData(nodes);
}
_this.nodesRemovePlaceholder();
});
});
};
PageTree.prototype.refreshOrFilterTree = function() {
......@@ -520,37 +527,34 @@ define(['jquery',
var params = 'pid=' + pid;
var _this = this;
d3.request(top.TYPO3.settings.ajaxUrls.page_tree_set_temporary_mount_point)
.header('X-Requested-With', 'XMLHttpRequest')
.header('Content-Type', 'application/x-www-form-urlencoded')
.on('error', function(error) {
_this.errorNotification(error);
throw error;
(new AjaxRequest(top.TYPO3.settings.ajaxUrls.page_tree_set_temporary_mount_point))
.post(params, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest'},
})
.then(function(response) {
return response.resolve();
})
.post(params, function(data) {
if (data) {
var response = JSON.parse(data.response);
if (response && response.hasErrors) {
if (response.messages) {
$.each(response.messages, function(id, message) {
Notification.error(
message.title,
message.message
);
});
} else {
_this.errorNotification();
}
_this.update();
.then(function(response) {
if (response && response.hasErrors) {
if (response.messages) {
$.each(response.messages, function(id, message) {
Notification.error(
message.title,
message.message
);
});
} else {
_this.addMountPoint(response.mountPointPath);
_this.refreshOrFilterTree();
_this.errorNotification();
}
_this.update();
} else {
_this.errorNotification();
_this.addMountPoint(response.mountPointPath);
_this.refreshOrFilterTree();
}
})
.catch(function(error) {
_this.errorNotification(error);
});
};
......@@ -569,41 +573,37 @@ define(['jquery',
//remove old node from svg tree
_this.nodesAddPlaceholder(node);
d3.request(top.TYPO3.settings.ajaxUrls.record_process)
.header('X-Requested-With', 'XMLHttpRequest')
.header('Content-Type', 'application/x-www-form-urlencoded')
.on('error', function(error) {
_this.errorNotification(error);
throw error;
(new AjaxRequest(top.TYPO3.settings.ajaxUrls.record_process))
.post(params, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest'},
})
.post(params, function(data) {
if (data) {
var response = JSON.parse(data.response);
if (response && response.hasErrors) {
if (response.messages) {
$.each(response.messages, function(id, message) {
Notification.error(
message.title,
message.message
);
});
} else {
_this.errorNotification();
}
_this.nodesAddPlaceholder();
_this.refreshOrFilterTree();
.then(function(response) {
return response.resolve();
})
.then(function(response) {
if (response && response.hasErrors) {
if (response.messages) {
$.each(response.messages, function(id, message) {
Notification.error(
message.title,
message.message
);
});
} else {
node.name = node.newName;
_this.svg.select('.node-placeholder[data-uid="' + node.stateIdentifier + '"]').remove();
_this.refreshOrFilterTree();
_this.nodesRemovePlaceholder();
_this.errorNotification();
}
_this.nodesAddPlaceholder();
_this.refreshOrFilterTree();
} else {
_this.errorNotification();
node.name = node.newName;
_this.svg.select('.node-placeholder[data-uid="' + node.stateIdentifier + '"]').remove();
_this.refreshOrFilterTree();
_this.nodesRemovePlaceholder();
}
})
.catch(function(error) {
_this.errorNotification(error);
});
};
......
......@@ -18,6 +18,7 @@ define(
[
'jquery',
'd3',
'TYPO3/CMS/Core/Ajax/AjaxRequest',
'TYPO3/CMS/Backend/ContextMenu',
'TYPO3/CMS/Backend/Modal',
'TYPO3/CMS/Backend/Severity',
......@@ -26,7 +27,7 @@ define(
'TYPO3/CMS/Backend/Tooltip',
'TYPO3/CMS/Backend/Enum/KeyTypes'
],
function($, d3, ContextMenu, Modal, Severity, Notification, Icons, Tooltip, KeyTypes) {
function($, d3, AjaxRequest, ContextMenu, Modal, Severity, Notification, Icons, Tooltip, KeyTypes) {
'use strict';
/**
......@@ -416,8 +417,17 @@ define(
var _this = this;
_this.nodesAddPlaceholder();
d3.json(this.settings.dataUrl, function(error, json) {
if (error) {
(new AjaxRequest(this.settings.dataUrl))
.get({cache: 'no-cache'})
.then(function(response) {
return response.resolve();
})
.then(function(json) {
var nodes = Array.isArray(json) ? json : [];
_this.replaceData(nodes);
_this.nodesRemovePlaceholder();
})
.catch(function(error) {
var title = TYPO3.lang.pagetree_networkErrorTitle;
var desc = TYPO3.lang.pagetree_networkErrorDesc;
......@@ -431,12 +441,7 @@ define(
_this.nodesRemovePlaceholder();
throw error;
}
var nodes = Array.isArray(json) ? json : [];
_this.replaceData(nodes);
_this.nodesRemovePlaceholder();
});
});
},
/**
......
......@@ -1388,7 +1388,7 @@ class PageRenderer implements SingletonInterface
'taboverride' => $corePath . 'taboverride.min',
'jquery/autocomplete' => $corePath . 'jquery.autocomplete',
'jquery/minicolors' => $corePath . 'jquery.minicolors',
'd3' => $corePath . 'd3/d3',
'd3' => $corePath . 'd3',
'Sortable' => $corePath . 'Sortable.min',
'tablesort' => $corePath . 'tablesort',
'tablesort.dotsep' => $corePath . 'tablesort.dotsep',
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment