1313 */
1414use Cake \Routing \Router ;
1515?>
16+ <div id="request-history">
1617<?php if (empty ($ requests )): ?>
1718 <p class="warning"><?= __d ('debug_kit ' , 'No previous requests logged. ' ) ?> </p>
1819<?php else : ?>
@@ -39,12 +40,62 @@ use Cake\Routing\Router;
3940 <?php endforeach ; ?>
4041 </ul>
4142<?php endif ; ?>
43+ </div>
44+ <script type="text/html" id="list-template">
45+ <ul class="history-list">
46+ <li>
47+ <?= $ this ->Html ->link (
48+ __d ('debug_kit ' , 'Back to current request ' ),
49+ ['plugin ' => 'DebugKit ' , 'controller ' => 'Panels ' , 'action ' => 'index ' , $ panel ->request_id ],
50+ ['class ' => 'history-link ' , 'data-request ' => $ panel ->request_id ]
51+ ) ?>
52+ </li>
53+ </ul>
54+ </script>
55+
56+ <script type="text/html" id="list-item-template">
57+ <li>
58+ <?php $ url = ['plugin ' => 'DebugKit ' , 'controller ' => 'Panels ' , 'action ' => 'index ' ] ?>
59+ <a class="history-link" data-request="{id}" href="<?= $ this ->Url ->build ($ url ) ?> /{id}">
60+ <span class="history-time">{time}</span>
61+ <span class="history-bubble xhr">XHR</span>
62+ <span class="history-bubble">{method}</span>
63+ <span class="history-bubble">{status}</span>
64+ <span class="history-bubble">{type}</span>
65+ <span class="history-url">{url}</span>
66+ </a>
67+ </li>
68+ </script>
69+
4270<script>
4371$(document).ready(function() {
4472 var panelButtons = $('.panel');
4573 var thisPanel = '<?= h ($ panel ->id ) ?> ';
46- var buttons = $('.history-link');
74+ var toolbar = window.toolbar;
75+
76+ if (!$('#request-history > ul').length) {
77+ $('#request-history').html($('#list-template').html());
78+ }
4779
80+ var listItem = $('#list-item-template').html();
81+
82+ for (var i = 0; i < toolbar.ajaxRequests.length; i++) {
83+ var params = {
84+ id: toolbar.ajaxRequests[i].requestId,
85+ time: (new Date(toolbar.ajaxRequests[i].date)).toLocaleString(),
86+ method: toolbar.ajaxRequests[i].method,
87+ status: toolbar.ajaxRequests[i].status,
88+ url: toolbar.ajaxRequests[i].url,
89+ type: toolbar.ajaxRequests[i].type
90+ };
91+ var content = listItem.replace(/{([^{}]*)}/g, function(a, b) {
92+ var r = params[b];
93+ return typeof r === 'string' || typeof r === 'number' ? r : a;
94+ });
95+ $('ul.history-list li:first').after(content);
96+ }
97+
98+ var buttons = $('.history-link');
4899 // Highlight the active request.
49100 buttons.filter('[data-request=' + window.toolbar.currentRequest + ']').addClass('active');
50101
0 commit comments