Skip to content

Commit cc64663

Browse files
authored
Merge pull request #5102 from Catrobat/jquery3
Remove Jquery
2 parents f0e49e9 + 98038da commit cc64663

File tree

4 files changed

+291
-597
lines changed

4 files changed

+291
-597
lines changed

assets/js/custom/AdminLogs.js

Lines changed: 72 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,82 @@
1-
/* eslint-env jquery */
2-
31
// eslint-disable-next-line no-unused-vars
42
function AdminLogs() {
5-
$(document).on('click', '.line-head', function () {
6-
$(this)
7-
.parent('.panel-heading')
8-
.siblings('.panel-collapse')
9-
.toggleClass('hide')
10-
})
3+
document.addEventListener('click', function (event) {
4+
if (event.target.classList.contains('line-head')) {
5+
const panelHeading = event.target.closest('.panel-heading')
6+
if (panelHeading) {
7+
const panelCollapse = panelHeading.nextElementSibling
8+
if (
9+
panelCollapse &&
10+
panelCollapse.classList.contains('panel-collapse')
11+
) {
12+
panelCollapse.classList.toggle('hide')
13+
}
14+
}
15+
}
1116

12-
$(document).on('click', '#search', function () {
13-
loadFileContent(
14-
$('#currentFile').val(),
15-
$('#logLevelSelect').val(),
16-
$('#lineNumber').val(),
17-
$('.greaterThanRB:checked').val(),
18-
)
19-
})
20-
$(document).on('click', '.files', function () {
21-
loadFileContent(
22-
$(this).val(),
23-
$('#logLevelSelect').val(),
24-
$('#lineNumber').val(),
25-
$('.greaterThanRB:checked').val(),
26-
)
27-
$('#currentFile').val($(this).val())
17+
if (event.target.id === 'search') {
18+
loadFileContent(
19+
document.getElementById('currentFile').value,
20+
document.getElementById('logLevelSelect').value,
21+
document.getElementById('lineNumber').value,
22+
document.querySelector('.greaterThanRB:checked').value,
23+
)
24+
}
25+
26+
if (event.target.classList.contains('files')) {
27+
loadFileContent(
28+
event.target.value,
29+
document.getElementById('logLevelSelect').value,
30+
document.getElementById('lineNumber').value,
31+
document.querySelector('.greaterThanRB:checked').value,
32+
)
33+
document.getElementById('currentFile').value = event.target.value
34+
}
2835
})
2936
}
3037

3138
function loadFileContent(file, filter, count, greaterThan) {
32-
$('#loading-spinner').show()
33-
$('#innerLogContainer').html('')
34-
$.ajax({
35-
type: 'get',
36-
data: {
37-
file,
38-
filter,
39-
count,
40-
greaterThan,
41-
},
42-
success: function (data) {
43-
$('#loading-spinner').hide()
44-
const innerLogContainerString = $('<div>', { html: data }).find(
45-
'#innerLogContainer',
46-
)
47-
$('#outerLogContainer').html(innerLogContainerString)
48-
},
49-
error: function () {
50-
$('#loading-spinner').hide()
39+
const loadingSpinner = document.getElementById('loading-spinner')
40+
const innerLogContainer = document.getElementById('innerLogContainer')
41+
const outerLogContainer = document.getElementById('outerLogContainer')
42+
43+
loadingSpinner.style.display = 'block'
44+
innerLogContainer.innerHTML = ''
45+
46+
const xhr = new XMLHttpRequest()
47+
xhr.open(
48+
'GET',
49+
`/your-endpoint?file=${file}&filter=${filter}&count=${count}&greaterThan=${greaterThan}`,
50+
true,
51+
)
52+
53+
xhr.onload = function () {
54+
loadingSpinner.style.display = 'none'
55+
if (xhr.status >= 200 && xhr.status < 300) {
56+
try {
57+
const data = JSON.parse(xhr.responseText)
58+
outerLogContainer.innerHTML = formatLogData(data)
59+
} catch (error) {
60+
alert('Error parsing data: ' + error.message)
61+
}
62+
} else {
5163
alert('something went terribly wrong')
52-
},
64+
}
65+
}
66+
67+
xhr.onerror = function () {
68+
loadingSpinner.style.display = 'none'
69+
alert('something went terribly wrong')
70+
}
71+
72+
xhr.send()
73+
}
74+
75+
function formatLogData(data) {
76+
let formattedData = '<ul>'
77+
data.forEach((log) => {
78+
formattedData += `<li>${log}</li>`
5379
})
80+
formattedData += '</ul>'
81+
return formattedData
5482
}

0 commit comments

Comments
 (0)