mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-08-23 18:31:43 +02:00
[CHANGE] Switch to framework fetch functions
This commit is contained in:
parent
18e9453fed
commit
0028310aa5
@ -1,4 +1,4 @@
|
||||
/* global notificationUpdateSettings */
|
||||
/* global notificationUpdateSettings, fetchGet */
|
||||
|
||||
/**
|
||||
* This script refreshed the notification icon in the top menu
|
||||
@ -19,22 +19,9 @@ $(() => {
|
||||
* Update the notification icon in the top menu
|
||||
*/
|
||||
const updateNotificationIcon = () => {
|
||||
fetch(userNotificationCountViewUrl)
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
throw new Error('Something went wrong');
|
||||
})
|
||||
.then((responseJson) => {
|
||||
const unreadCount = responseJson.unread_count;
|
||||
|
||||
if (unreadCount > 0) {
|
||||
elementNotificationIcon.addClass('text-danger');
|
||||
} else {
|
||||
elementNotificationIcon.removeClass('text-danger');
|
||||
}
|
||||
fetchGet({url: userNotificationCountViewUrl})
|
||||
.then((data) => {
|
||||
elementNotificationIcon.toggleClass('text-danger', data.unread_count > 0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`Failed to load HTMl to render notifications item. Error: ${error.message}`);
|
||||
|
@ -8,30 +8,22 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const elemCard = document.getElementById("esi-alert");
|
||||
const elemMessage = document.getElementById("esi-data");
|
||||
const elemCode = document.getElementById("esi-code");
|
||||
const elemCard = document.getElementById('esi-alert');
|
||||
const elemMessage = document.getElementById('esi-data');
|
||||
const elemCode = document.getElementById('esi-code');
|
||||
|
||||
fetch('{% url "authentication:esi_check" %}')
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
throw new Error("Something went wrong");
|
||||
})
|
||||
.then((responseJson) => {
|
||||
console.log("ESI Check: ", JSON.stringify(responseJson, null, 2));
|
||||
fetchGet({url: '{% url "authentication:esi_check" %}'})
|
||||
.then((data) => {
|
||||
console.log('ESI Check: ', JSON.stringify(data, null, 2));
|
||||
|
||||
const status = responseJson.status;
|
||||
if (status !== 200) {
|
||||
elemCode.textContent = status
|
||||
elemMessage.textContent = responseJson.data.error;
|
||||
new bootstrap.Collapse(elemCard, {
|
||||
toggle: true
|
||||
})
|
||||
if (data.status !== 200) {
|
||||
elemCode.textContent = data.status;
|
||||
elemMessage.textContent = data.data.error;
|
||||
|
||||
new bootstrap.Collapse(elemCard, {toggle: true});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
console.error('Error fetching ESI check:', error);
|
||||
});
|
||||
</script>
|
||||
|
@ -133,34 +133,24 @@
|
||||
|
||||
|
||||
<script>
|
||||
const elemRunning = document.getElementById("task-counts");
|
||||
const elemQueued = document.getElementById("queued-tasks-count");
|
||||
const elemRunning = document.getElementById('task-counts');
|
||||
const elemQueued = document.getElementById('queued-tasks-count');
|
||||
|
||||
fetch('{% url "authentication:task_counts" %}')
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
throw new Error("Something went wrong");
|
||||
})
|
||||
.then((responseJson) => {
|
||||
const running = responseJson.tasks_running;
|
||||
if (running == null) {
|
||||
elemRunning.textContent = "N/A";
|
||||
} else {
|
||||
elemRunning.textContent = running.toLocaleString();
|
||||
}
|
||||
fetchGet({url: '{% url "authentication:task_counts" %}'})
|
||||
.then((data) => {
|
||||
const running = data.tasks_running;
|
||||
const queued = data.tasks_queued;
|
||||
|
||||
const queued = responseJson.tasks_queued;
|
||||
if (queued == null) {
|
||||
elemQueued.textContent = "N/A";
|
||||
} else {
|
||||
elemQueued.textContent = queued.toLocaleString();
|
||||
}
|
||||
const updateTaskCount = (element, value) => {
|
||||
element.textContent = value == null ? 'N/A' : value.toLocaleString();
|
||||
};
|
||||
|
||||
updateTaskCount(elemRunning, running);
|
||||
updateTaskCount(elemQueued, queued);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
elemRunning.textContent = "ERROR";
|
||||
elemQueued.textContent = "ERROR";
|
||||
console.error('Error fetching task queue:', error);
|
||||
|
||||
[elemRunning, elemQueued].forEach(elem => elem.textContent = 'ERROR');
|
||||
});
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user