ADMIN UI DONE
This commit is contained in:
@@ -22,7 +22,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok && result.success) {
|
||||
// Set cookie with email and name
|
||||
document.cookie = `id=${result.user.id};`;
|
||||
document.cookie = `email=${result.user.email};`;
|
||||
document.cookie = `name=${result.user.name};`;
|
||||
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user