PluginProbe
Debug Log Manager – Conveniently Monitor and Inspect Errors / 2.3.1
Debug Log Manager – Conveniently Monitor and Inspect Errors v2.3.1
2.5.2 2.5.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.8.0 1.8.2 1.8.3 1.8.4 All 49 releases
debug-log-manager / assets / js / admin.js

admin.js in Debug Log Manager – Conveniently Monitor and Inspect Errors 2.3.1, at assets/js/admin.js

364 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2 'use strict';
3
4 let autoRefreshIntervalId; // variable to store auto refresh interval ID
5
6 $(document).ready( function() {
7
8 // Make page header sticky on scroll. Using https://github.com/AndrewHenderson/jSticky
9
10 $('#dlm-header').sticky({
11 topSpacing: 0, // Space between element and top of the viewport (in pixels)
12 zIndex: 100, // z-index
13 stopper: '', // Id, class, or number value
14 stickyClass: 'dlm-sticky' // Class applied to element when it's stuck. Class name or false.
15 })
16
17 // Get WP_DEBUG logging status toggle/switcher position on page load
18
19 var logStatus = dlmVars.logStatus;
20 $('.debug-log-switcher').attr('data-status',logStatus);
21
22 if ( logStatus == 'enabled' ) {
23 $('.debug-log-checkbox').prop('checked', true);
24 $('#dlm-disable-wp-file-editor-section').fadeOut();
25 } else {
26 $('.debug-log-checkbox').prop('checked', false);
27 $('#dlm-disable-wp-file-editor-section').fadeIn();
28 }
29
30 // Get auto-refresh feature status on page load
31
32 var autorefreshStatus = dlmVars.autorefreshStatus;
33
34 $('.debug-autorefresh-switcher').attr('data-status',autorefreshStatus);
35
36 if ( autorefreshStatus == 'enabled' ) {
37 $('.debug-autorefresh-checkbox').prop('checked', true);
38 if ( logStatus == 'enabled' ) {
39 autoRefreshIntervalId = setInterval(getLatestEntries, 5000);
40 } else {
41 clearInterval(autoRefreshIntervalId);
42 }
43 } else {
44 $('.debug-autorefresh-checkbox').prop('checked', false);
45 clearInterval(autoRefreshIntervalId);
46 }
47
48 // Toggle WP_DEBUG logging status on click
49
50 $('.debug-log-switcher').click( function() {
51
52 var autorefreshStatus = $('.debug-autorefresh-switcher')[0].dataset.status;
53
54 $.ajax({
55 url: ajaxurl,
56 data: {
57 'action': 'toggle_debugging'
58 },
59 success:function(data) {
60 var data = data.slice(0,-1); // remove strange trailing zero in string returned by AJAX call
61 const dataObject = JSON.parse(data); // create an object
62 // console.log(dataObject);
63 $('#debug-log-status').empty();
64 $('#debug-log-status').prepend(dataObject.message);
65 // console.log('WP_DEBUG: ' + dataObject.status)
66
67 if ( dataObject.status == 'enabled' ) {
68 $('.debug-log-switcher').attr('data-status','enabled');
69 getLatestEntries();
70 $('#dlm-disable-wp-file-editor-section').fadeOut();
71 if ( dataObject.copy == false ) {
72 $.toast({
73 // heading: 'Success!',
74 text: dlmVars.toastMessage.toggleDebugSuccess,
75 showHideTransition: 'slide',
76 icon: 'success',
77 allowToastClose: true,
78 hideAfter: 7500, // true, false or number (miliseconds)
79 position: 'bottom-right',
80 bgColor: '#52a552',
81 textColor: '#ffffff'
82 });
83 }
84 if ( autorefreshStatus == 'enabled' ) {
85 autoRefreshIntervalId = setInterval(getLatestEntries, 5000);
86 } else {
87 clearInterval(autoRefreshIntervalId);
88 }
89 } else if ( dataObject.status == 'disabled' ) {
90 $('.debug-log-switcher').attr('data-status','disabled');
91 $('#dlm-disable-wp-file-editor-section').fadeIn();
92 clearInterval(autoRefreshIntervalId);
93 if ( autorefreshStatus == 'enabled' ) {
94 $('.debug-autorefresh-switcher').click();
95 }
96 } else {}
97
98 if ( dataObject.copy == true ) {
99 // When entries are copied from an existing debug.log file
100 $.toast({
101 // heading: 'Success!',
102 text: dlmVars.toastMessage.copySuccess,
103 showHideTransition: 'slide',
104 icon: 'success',
105 allowToastClose: true,
106 hideAfter: 7500, // true, false or number (miliseconds)
107 position: 'bottom-right',
108 bgColor: '#52a552',
109 textColor: '#ffffff'
110 });
111 $('#dlm-log-file-size').empty();
112 $('#dlm-log-file-size').prepend(dataObject.size); // fill in debug.log file size
113 }
114 },
115 error:function(errorThrown) {
116 console.log(errorThrown);
117 }
118 });
119
120 });
121
122 // Toggle auto-refresh feature on click
123
124 $('.debug-autorefresh-switcher').click( function() {
125
126 var logStatus = $('.debug-log-switcher')[0].dataset.status;
127
128 $.ajax({
129 url: ajaxurl,
130 data: {
131 'action': 'toggle_autorefresh'
132 },
133 success:function(data) {
134 var data = data.slice(0,-1); // remove strange trailing zero in string returned by AJAX call
135 const dataObject = JSON.parse(data); // create an object
136 $('#debug-autorefresh-status').empty();
137 $('#debug-autorefresh-status').prepend(dataObject.message);
138 // console.log('Auto refresh: ' + dataObject.status)
139 if ( dataObject.status == 'enabled' ) {
140 $('.debug-autorefresh-switcher').attr('data-status','enabled');
141 if ( logStatus == 'enabled' ) {
142 autoRefreshIntervalId = setInterval(getLatestEntries, 5000); // every 5 seconds
143 } else {
144 clearInterval(autoRefreshIntervalId);
145 }
146 } else if ( dataObject.status == 'disabled' ) {
147 $('.debug-autorefresh-switcher').attr('data-status','disabled');
148 clearInterval(autoRefreshIntervalId);
149 }
150 },
151 error:function(errorThrown) {
152 console.log(errorThrown);
153 }
154 });
155
156 });
157
158 // Clear log file
159
160 $('#dlm-log-clear').click( function() {
161
162 $.ajax({
163 url: ajaxurl,
164 data: {
165 'action': 'clear_log',
166 'nonce': dlmVars.nonce
167 },
168 success:function() {
169 var table = $("#debug-log").DataTable();
170 table.clear().draw();
171 $('#dlm-log-file-size').empty();
172 $('#dlm-log-file-size').prepend('0 B');
173 $.toast({
174 // heading: 'Success!',
175 text: dlmVars.toastMessage.logFileCleared,
176 showHideTransition: 'slide',
177 icon: 'success',
178 allowToastClose: true,
179 hideAfter: 7500, // true, false or number (miliseconds)
180 position: 'bottom-right',
181 bgColor: '#52a552',
182 textColor: '#ffffff'
183 });
184 },
185 error:function(errorThrown) {
186 console.log(errorThrown);
187 }
188 });
189 });
190
191 // Disable WP core's plugin/theme editor
192
193 $('#dlm-disable-wp-file-editor').click( function() {
194
195 $.ajax({
196 url: ajaxurl,
197 data: {
198 'action': 'disable_wp_file_editor'
199 },
200 success:function(data) {
201 var data = data.slice(0,-1); // remove strange trailing zero in string returned by AJAX call
202 const dataObject = JSON.parse(data); // create an object
203 if ( dataObject.status == 'disabled' ) { // plugin/theme editor has been disabled
204 // Redraw table with new data: https://stackoverflow.com/a/25929434
205 getLatestEntries();
206 $.toast({
207 // heading: 'Success!',
208 text: dlmVars.toastMessage.editoDisabled,
209 showHideTransition: 'slide',
210 icon: 'success',
211 allowToastClose: true,
212 hideAfter: 7500, // true, false or number (miliseconds)
213 position: 'bottom-right',
214 bgColor: '#52a552',
215 textColor: '#ffffff'
216 });
217 }
218 },
219 error:function(errorThrown) {
220 console.log(errorThrown);
221 }
222 });
223 });
224
225 // Initialize log entries dataTable with localization enabled
226 // https://datatables.net/manual/i18n
227 // https://datatables.net/plug-ins/i18n/
228 // https://datatables.net/plug-ins/i18n/English.html
229
230 $("#debug-log").DataTable({
231 pageLength: 10,
232 order: [ 0, "asc" ],
233 searching: true,
234 language: {
235 emptyTable: dlmVars.dataTable.emptyTable,
236 info: dlmVars.dataTable.info,
237 infoEmpty: dlmVars.dataTable.infoEmpty,
238 infoFiltered: dlmVars.dataTable.infoFiltered,
239 lengthMenu: dlmVars.dataTable.lengthMenu,
240 search: dlmVars.dataTable.search,
241 zeroRecords: dlmVars.dataTable.zeroRecords,
242 paginate: {
243 first: dlmVars.dataTable.paginate.first,
244 last: dlmVars.dataTable.paginate.last,
245 next: dlmVars.dataTable.paginate.next,
246 previous: dlmVars.dataTable.paginate.previous
247 },
248 }
249 });
250
251 // Create Error Type filter drop down
252 // https://clintmcmahon.com/add-a-custom-search-filter-to-datatables-header/
253
254 var debugLogTable = $("#debug-log").DataTable();
255 $("#debug-log_filter.dataTables_filter").append($("#errorTypeFilter"));
256
257 var errorTypeIndex = 0;
258
259 $("#debug-log th").each(function (i) {
260 if ( $($(this)).html() == "Error Type" ) {
261 errorTypeIndex = i;
262 return false;
263 }
264 });
265
266 $.fn.dataTable.ext.search.push(
267 function (settings, data, dataIndex) {
268 var selectedItem = $("#errorTypeFilter").val();
269 var errorType = data[errorTypeIndex];
270 if (selectedItem === "" || errorType.includes(selectedItem)) {
271 return true;
272 }
273 return false;
274 }
275 );
276
277 $("#errorTypeFilter").change(function (e) {
278 debugLogTable.draw();
279 });
280
281 debugLogTable.draw();
282
283 // Disable auto-refresh if pagination button is clicked, otherwise it will cause the refresh to return pagination to page 1
284
285 $('#debug-log_paginate').click( function() {
286
287 var autorefreshStatus = $('.debug-autorefresh-switcher')[0].dataset.status;
288
289 if ( autorefreshStatus == 'enabled' ) {
290 $('.debug-autorefresh-switcher').click();
291 $.toast({
292 // heading: 'Success!',
293 text: dlmVars.toastMessage.paginationActive,
294 showHideTransition: 'slide',
295 // icon: 'success',
296 allowToastClose: false,
297 hideAfter: 5000, // true, false or number (miliseconds)
298 position: 'bottom-right',
299 // bgColor: '#52a552',
300 // textColor: '#ffffff'
301 });
302 }
303
304 });
305
306 // Auto reload page / refresh table
307
308 function getLatestEntries() {
309 $.ajax({
310 url: ajaxurl,
311 data: {
312 'action': 'get_latest_entries'
313 },
314 success:function(data) {
315 var data = data.slice(0,-1); // remove strange trailing zero in string returned by AJAX call
316 const dataObject = JSON.parse(data); // create an object
317 // Redraw table with new data: https://stackoverflow.com/a/25929434
318 var table = $("#debug-log").DataTable();
319 table.clear().rows.add(dataObject.entries);
320 table.columns.adjust().draw();
321 $("#debug-log").css("width","100%"); // prevent strange table width shrinkage issue
322 $("#debug-log .dlm-entry-no").css("width","16px"); // prevent strange table width shrinkage issue
323 $("#debug-log .dlm-entry-type").css("width","96px"); // prevent strange table width shrinkage issue
324 $("#debug-log .dlm-entry-datetime").css("width","160px"); // prevent strange table width shrinkage issue
325 $("#debug-log .dlm-entry-details").css("width","calc(100% - 16px - 96px - 160px)"); // prevent strange table width shrinkage issue
326 },
327 error:function(errorThrown) {
328 console.log(errorThrown);
329 }
330 });
331 }
332
333 }); // end of (document).ready();
334
335 // if WP_DEBUG is enabled
336
337 if ( dlmVars.logStatus == 'enabled' ) {
338
339 // Log javascript errors in wp-admin via XHR https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
340 // Code source: https://plugins.svn.wordpress.org/javascript-error-reporting-client/tags/1.0.3/public/js/jerc.js
341
342 window.onerror = function(msg, url, lineNo, columnNo, error) {
343
344 var data = {
345 nonce: dlmVars.jsErrorLogging.nonce,
346 message: msg,
347 script: url,
348 lineNo: lineNo,
349 columnNo: columnNo,
350 pageUrl: window.location.pathname + window.location.search,
351 type: 'wp-admin'
352 }
353
354 var xhr = new XMLHttpRequest();
355 xhr.open("POST", dlmVars.jsErrorLogging.url + "?action=" + dlmVars.jsErrorLogging.action );
356 xhr.setRequestHeader('Content-type', 'application/json');
357 xhr.send(encodeURI(JSON.stringify(data)));
358 return false;
359
360 }
361
362 }
363
364 })( jQuery );