Skip to content

Commit 18b3371

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Console] Restore psr/log >= 3.0 conflict [Security] Make the abstract Voter class implement CacheableVoterInterface Add generic types to traversable implementations [Security] Fix TypeError message [Security] Fix deprecation layer [FrameworkBundle] Add completion for workflow:dump Fix cancel button Fix misleading error on missing provider with authenticator manager Don't limit retries of toolbar loading
2 parents f021d9d + 80ff732 commit 18b3371

File tree

5 files changed

+146
-51
lines changed

5 files changed

+146
-51
lines changed

Resources/views/Profiler/base_js.html.twig

Lines changed: 103 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,23 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
5050
var request = function(url, onSuccess, onError, payload, options, tries) {
5151
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
5252
options = options || {};
53-
options.maxTries = options.maxTries || 0;
53+
options.retry = options.retry || false;
5454
tries = tries || 1;
55-
var delay = Math.pow(2, tries - 1) * 1000;
55+
/* this delays for 125, 375, 625, 875, and 1000, ... */
56+
var delay = tries < 5 ? (tries - 0.5) * 250 : 1000;
57+
5658
xhr.open(options.method || 'GET', url, true);
5759
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
5860
xhr.onreadystatechange = function(state) {
5961
if (4 !== xhr.readyState) {
6062
return null;
6163
}
6264
63-
if (xhr.status == 404 && options.maxTries > 1) {
64-
setTimeout(function(){
65-
options.maxTries--;
65+
if (xhr.status == 404 && options.retry && !options.stop) {
66+
setTimeout(function() {
67+
if (options.stop) {
68+
return;
69+
}
6670
request(url, onSuccess, onError, payload, options, tries + 1);
6771
}, delay);
6872
@@ -75,6 +79,11 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
7579
(onError || noop)(xhr);
7680
}
7781
};
82+
83+
if (options.onSend) {
84+
options.onSend(tries);
85+
}
86+
7887
xhr.send(payload || '');
7988
};
8089
@@ -430,8 +439,94 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
430439
return this;
431440
},
432441
442+
showToolbar: function(token) {
443+
var sfwdt = document.getElementById('sfwdt' + token);
444+
removeClass(sfwdt, 'sf-display-none');
445+
446+
if (getPreference('toolbar/displayState') == 'none') {
447+
document.getElementById('sfToolbarMainContent-' + token).style.display = 'none';
448+
document.getElementById('sfToolbarClearer-' + token).style.display = 'none';
449+
document.getElementById('sfMiniToolbar-' + token).style.display = 'block';
450+
} else {
451+
document.getElementById('sfToolbarMainContent-' + token).style.display = 'block';
452+
document.getElementById('sfToolbarClearer-' + token).style.display = 'block';
453+
document.getElementById('sfMiniToolbar-' + token).style.display = 'none';
454+
}
455+
},
456+
457+
hideToolbar: function(token) {
458+
var sfwdt = document.getElementById('sfwdt' + token);
459+
addClass(sfwdt, 'sf-display-none');
460+
},
461+
462+
initToolbar: function(token) {
463+
this.showToolbar(token);
464+
465+
var hideButton = document.getElementById('sfToolbarHideButton-' + token);
466+
var hideButtonSvg = hideButton.querySelector('svg');
467+
hideButtonSvg.setAttribute('aria-hidden', 'true');
468+
hideButtonSvg.setAttribute('focusable', 'false');
469+
addEventListener(hideButton, 'click', function (event) {
470+
event.preventDefault();
471+
472+
var p = this.parentNode;
473+
p.style.display = 'none';
474+
(p.previousElementSibling || p.previousSibling).style.display = 'none';
475+
document.getElementById('sfMiniToolbar-' + token).style.display = 'block';
476+
setPreference('toolbar/displayState', 'none');
477+
});
478+
479+
var showButton = document.getElementById('sfToolbarMiniToggler-' + token);
480+
var showButtonSvg = showButton.querySelector('svg');
481+
showButtonSvg.setAttribute('aria-hidden', 'true');
482+
showButtonSvg.setAttribute('focusable', 'false');
483+
addEventListener(showButton, 'click', function (event) {
484+
event.preventDefault();
485+
486+
var elem = this.parentNode;
487+
if (elem.style.display == 'none') {
488+
document.getElementById('sfToolbarMainContent-' + token).style.display = 'none';
489+
document.getElementById('sfToolbarClearer-' + token).style.display = 'none';
490+
elem.style.display = 'block';
491+
} else {
492+
document.getElementById('sfToolbarMainContent-' + token).style.display = 'block';
493+
document.getElementById('sfToolbarClearer-' + token).style.display = 'block';
494+
elem.style.display = 'none'
495+
}
496+
497+
setPreference('toolbar/displayState', 'block');
498+
});
499+
},
500+
433501
loadToolbar: function(token, newToken) {
502+
var that = this;
503+
var triesCounter = document.getElementById('sfLoadCounter-' + token);
504+
505+
var options = {
506+
retry: true,
507+
onSend: function (count) {
508+
if (count === 3) {
509+
that.initToolbar(token);
510+
}
511+
512+
if (triesCounter) {
513+
triesCounter.textContent = count;
514+
}
515+
},
516+
};
517+
518+
var cancelButton = document.getElementById('sfLoadCancel-' + token);
519+
if (cancelButton) {
520+
addEventListener(cancelButton, 'click', function (event) {
521+
event.preventDefault();
522+
523+
options.stop = true;
524+
that.hideToolbar(token);
525+
});
526+
}
527+
434528
newToken = (newToken || token);
529+
435530
this.load(
436531
'sfwdt' + token,
437532
'{{ url("_wdt", { "token": "xxxxxx" })|escape('js') }}'.replace(/xxxxxx/, newToken),
@@ -453,15 +548,7 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
453548
return;
454549
}
455550
456-
if (getPreference('toolbar/displayState') == 'none') {
457-
document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'none';
458-
document.getElementById('sfToolbarClearer-' + newToken).style.display = 'none';
459-
document.getElementById('sfMiniToolbar-' + newToken).style.display = 'block';
460-
} else {
461-
document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'block';
462-
document.getElementById('sfToolbarClearer-' + newToken).style.display = 'block';
463-
document.getElementById('sfMiniToolbar-' + newToken).style.display = 'none';
464-
}
551+
that.initToolbar(newToken);
465552
466553
/* Handle toolbar-info position */
467554
var toolbarBlocks = [].slice.call(el.querySelectorAll('.sf-toolbar-block'));
@@ -489,39 +576,7 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
489576
}
490577
};
491578
}
492-
var hideButton = document.getElementById('sfToolbarHideButton-' + newToken);
493-
var hideButtonSvg = hideButton.querySelector('svg');
494-
hideButtonSvg.setAttribute('aria-hidden', 'true');
495-
hideButtonSvg.setAttribute('focusable', 'false');
496-
addEventListener(hideButton, 'click', function (event) {
497-
event.preventDefault();
498-
499-
var p = this.parentNode;
500-
p.style.display = 'none';
501-
(p.previousElementSibling || p.previousSibling).style.display = 'none';
502-
document.getElementById('sfMiniToolbar-' + newToken).style.display = 'block';
503-
setPreference('toolbar/displayState', 'none');
504-
});
505-
var showButton = document.getElementById('sfToolbarMiniToggler-' + newToken);
506-
var showButtonSvg = showButton.querySelector('svg');
507-
showButtonSvg.setAttribute('aria-hidden', 'true');
508-
showButtonSvg.setAttribute('focusable', 'false');
509-
addEventListener(showButton, 'click', function (event) {
510-
event.preventDefault();
511579
512-
var elem = this.parentNode;
513-
if (elem.style.display == 'none') {
514-
document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'none';
515-
document.getElementById('sfToolbarClearer-' + newToken).style.display = 'none';
516-
elem.style.display = 'block';
517-
} else {
518-
document.getElementById('sfToolbarMainContent-' + newToken).style.display = 'block';
519-
document.getElementById('sfToolbarClearer-' + newToken).style.display = 'block';
520-
elem.style.display = 'none'
521-
}
522-
523-
setPreference('toolbar/displayState', 'block');
524-
});
525580
renderAjaxRequests();
526581
addEventListener(document.querySelector('.sf-toolbar-ajax-clear'), 'click', function() {
527582
requestStack = [];
@@ -550,7 +605,7 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
550605
}
551606
},
552607
function(xhr) {
553-
if (xhr.status !== 0) {
608+
if (xhr.status !== 0 && !options.stop) {
554609
var sfwdt = document.getElementById('sfwdt' + token);
555610
sfwdt.innerHTML = '\
556611
<div class="sf-toolbarreset">\
@@ -561,7 +616,7 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
561616
sfwdt.setAttribute('class', 'sf-toolbar sf-error-toolbar');
562617
}
563618
},
564-
{ maxTries: 5 }
619+
options
565620
);
566621
567622
return this;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% block toolbar %}
2+
{% set icon %}
3+
{{ include('@WebProfiler/Icon/symfony.svg') }}
4+
5+
<span class="sf-toolbar-value sf-toolbar-ajax-request-counter">
6+
Loading&hellip;
7+
</span>
8+
{% endset %}
9+
10+
{% set text %}
11+
<div class="sf-toolbar-info-piece">
12+
<b>Loading the web debug toolbar&hellip;</b>
13+
</div>
14+
<div class="sf-toolbar-info-piece">
15+
Attempt #<span id="sfLoadCounter-{{ token }}"></span>
16+
</div>
17+
<div class="sf-toolbar-info-piece">
18+
<b>
19+
<button class="sf-cancel-button" type="button" id="sfLoadCancel-{{ token }}" title="Cancel loading">Cancel</button>
20+
</b>
21+
</div>
22+
{% endset %}
23+
24+
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { link: profiler_url }) }}
25+
{% endblock %}

Resources/views/Profiler/toolbar.css.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
display: inline-block;
7474
}
7575

76+
.sf-toolbarreset .sf-cancel-button {
77+
color: #444;
78+
}
79+
7680
.sf-toolbarreset .hide-button {
7781
background: #444;
7882
display: block;

Resources/views/Profiler/toolbar.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
{% for name, template in templates %}
1111
{% if block('toolbar', template) is defined %}
1212
{% with {
13-
collector: profile.getcollector(name),
13+
collector: profile ? profile.getcollector(name) : null,
1414
profiler_url: profiler_url,
15-
token: profile.token,
15+
token: token ?? (profile ? profile.token : null),
1616
name: name,
1717
profiler_markup_version: profiler_markup_version,
1818
csp_script_nonce: csp_script_nonce,

Resources/views/Profiler/toolbar_js.html.twig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
<div id="sfwdt{{ token }}" class="sf-toolbar sf-display-none" role="region" aria-label="Symfony Web Debug Toolbar"></div>
1+
<div id="sfwdt{{ token }}" class="sf-toolbar sf-display-none" role="region" aria-label="Symfony Web Debug Toolbar">
2+
{% include('@WebProfiler/Profiler/toolbar.html.twig') with {
3+
templates: {
4+
'request': '@WebProfiler/Profiler/cancel.html.twig'
5+
},
6+
profile: null,
7+
profiler_url: url('_profiler', {token: token}),
8+
profiler_markup_version: 2,
9+
} %}
10+
</div>
11+
212
{{ include('@WebProfiler/Profiler/base_js.html.twig') }}
13+
314
<style{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}>
415
{{ include('@WebProfiler/Profiler/toolbar.css.twig') }}
516
</style>

0 commit comments

Comments
 (0)