ADMIN UI DONE

This commit is contained in:
andrei-mihnea-cerbu
2024-04-03 05:57:01 +03:00
parent 5e4a488bfd
commit 5e5bab933b
15 changed files with 229 additions and 13 deletions
+110 -1
View File
@@ -62,14 +62,122 @@ document.addEventListener('DOMContentLoaded', function() {
ceoInfoButton.addEventListener('click', () => {
console.log('Ceo Info Button pressed');
const domain = window.location.hostname;
const endpoint = 'http://' + domain + ':5000/admin/ceo';
const id = getCookie('id');
fetch(endpoint, {
method: 'GET',
headers: {
'Authorization': id
},
})
.then(async response => {
if (!response.ok) {
const responseData = await response.json();
throw new Error(responseData.message);
}
return await response.json()
})
.then(data => {
alert(data.message);
// Assuming 'data' is the property you want to download
const toDownload = data.data;
const jsonStr = JSON.stringify(toDownload, null, 2);
const blob = new Blob([jsonStr], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'ceo.json';
document.body.appendChild(a);
a.click();
// Cleanup: remove the link and revoke the URL
document.body.removeChild(a);
URL.revokeObjectURL(url);
})
.catch(error => {
alert(error)
console.error('Error: '+ error)
});
})
usersInfoButton.addEventListener('click', () => {
console.log('Users Info Button pressed');
const domain = window.location.hostname;
const endpoint = 'http://' + domain + ':5000/admin/users';
const id = getCookie('id');
fetch(endpoint, {
method: 'GET',
headers: {
'Authorization': id
},
})
.then(async response => {
if (!response.ok) {
const responseData = await response.json();
throw new Error(responseData.message);
}
return await response.json()
})
.then(data => {
alert(data.message);
const toDownload = data.data;
const jsonStr = JSON.stringify(toDownload, null, 2);
const blob = new Blob([jsonStr], { type: 'application/json' });
const url = URL.createObjectURL(blob);
// Create a temporary link to trigger the download
const a = document.createElement('a');
a.href = url;
a.download = 'users.json';
document.body.appendChild(a);
a.click();
// Cleanup: remove the link and revoke the URL
document.body.removeChild(a);
URL.revokeObjectURL(url);
})
.catch(error => {
alert(error)
console.error('Error: '+ error)
});
})
resetUcButton.addEventListener('click', () => {
console.log('Set Conf Button pressed');
console.log('Reset UC Button pressed');
const domain = window.location.hostname;
const endpoint = 'http://' + domain + ':5000/admin/reset_server';
const id = getCookie('id');
fetch(endpoint, {
method: 'GET',
headers: {
'Authorization': id
},
})
.then(async response => {
if (!response.ok) {
const responseData = await response.json();
throw new Error(responseData.message);
}
return await response.json()
})
.then(data => alert(data.message))
.catch(error => {
alert(error)
console.error('Error: '+ error)
});
})
logoutButton.addEventListener('click', () => {
@@ -81,6 +189,7 @@ document.addEventListener('DOMContentLoaded', function() {
deleteCookie('email');
deleteCookie('name');
deleteCookie('id');
fadeOut('/login');
});