v2.9
This commit is contained in:
@@ -1,68 +1,64 @@
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
await insertUsername();
|
||||
setInterval(loadReceivedFiles, 3000); // Call loadReceivedFiles every 5000 ms (5 seconds)
|
||||
|
||||
const backupButton = document.getElementById('backup_dir');
|
||||
const backupButton = document.getElementById('backup');
|
||||
const shareButton = document.getElementById('share_dir');
|
||||
const departmentButton = document.getElementById('department_dir');
|
||||
|
||||
const changeDepartmentButton = document.getElementById('change_department');
|
||||
const manageDepartmentButton = document.getElementById('manage_department');
|
||||
const manageUsersButton = document.getElementById('manage_users');
|
||||
const changeInfoButton = document.getElementById('change_info');
|
||||
const shareFileButton = document.getElementById('share_file');
|
||||
const decryptButton = document.getElementById('decrypt');
|
||||
const logoutButton = document.getElementById('logout');
|
||||
|
||||
const overlay = document.getElementById('overlay');
|
||||
const ceoBackButton = document.getElementById('back_button');
|
||||
const ceoSubmitButton = document.getElementById('submit_button');
|
||||
async function loadReceivedFiles() {
|
||||
const checkFileReceived = await window.electronAPI.checkFileExists('filesReceived.json');
|
||||
if (!checkFileReceived) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ip = '';
|
||||
await window.electronAPI.readFile('ipConfig.json')
|
||||
.then(result => {
|
||||
const jsonData = JSON.parse(result.content);
|
||||
ip = jsonData.ip;
|
||||
})
|
||||
try {
|
||||
const fileData = await window.electronAPI.readFile('filesReceived.json');
|
||||
const filesJson = JSON.parse(fileData.content);
|
||||
const receivedFiles = filesJson.receivedFiles;
|
||||
|
||||
let triggerSource = '';
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const existingButtons = Array.from(notificationsDiv.children).map(button => button.getAttribute('data-filepath'));
|
||||
|
||||
function handleOverlayOpen(buttonId) {
|
||||
overlay.style.display = 'block';
|
||||
triggerSource = buttonId; // Remember the button that triggered the overlay
|
||||
console.log(`${buttonId} button clicked!`);
|
||||
receivedFiles.forEach(filePath => {
|
||||
// Check if the button for this file path already exists
|
||||
if (!existingButtons.includes(filePath)) {
|
||||
const button = document.createElement('button');
|
||||
button.setAttribute('data-filepath', filePath); // Set a custom attribute to track the file path
|
||||
button.name = 'notification';
|
||||
button.textContent = 'You received a file';
|
||||
button.addEventListener('click', () => handleFileReceivedButtonPressed(filePath, button));
|
||||
notificationsDiv.appendChild(button);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error loading received files:', error);
|
||||
}
|
||||
}
|
||||
|
||||
ceoBackButton.addEventListener('click', function () {
|
||||
overlay.style.display = 'none';
|
||||
});
|
||||
async function handleFileReceivedButtonPressed(filePath, button) {
|
||||
console.log('Notification button clicked!');
|
||||
|
||||
ceoSubmitButton.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const password = document.getElementById('ceo_password').value;
|
||||
// Open file in file explorer
|
||||
await window.electronAPI.showFileInExplorer(filePath)
|
||||
.then(() => console.log('File explorer opened'))
|
||||
.catch(error => console.error('Error opening file explorer:', error));
|
||||
|
||||
await fetch(`http://${ip}/users/validate_ceo_password`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-api-key': 'uc_api',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
password: password
|
||||
})
|
||||
}).then(async result => {
|
||||
const data = await result.json();
|
||||
if (!result.ok) {
|
||||
throw new Error(data.message);
|
||||
}
|
||||
if (triggerSource === 'change_department') {
|
||||
fadeOut('change_department.html');
|
||||
} else if (triggerSource === 'decrypt') {
|
||||
console.log('astept decryptarea')
|
||||
fadeOut('decrypting_backup.html');
|
||||
}
|
||||
})
|
||||
// Remove the button
|
||||
button.remove();
|
||||
|
||||
// Call to remove the path from the JSON file
|
||||
await window.electronAPI.removePathFromReceivedFiles(filePath)
|
||||
.then(() => console.log('Path removed from received files'))
|
||||
.catch(error => console.error('Error removing path:', error));
|
||||
}
|
||||
|
||||
overlay.style.display = 'none';
|
||||
triggerSource = '';
|
||||
});
|
||||
|
||||
checkDirBackupFileExists()
|
||||
.then(() => console.log('verificare backupDir facuta'));
|
||||
@@ -70,9 +66,6 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
checkShareDirFileExists()
|
||||
.then(() => console.log('verificare ShareDir facuta'));
|
||||
|
||||
checkDepartmentDirFileExists()
|
||||
.then(() => {console.log('verificare departmentDir facuta')})
|
||||
|
||||
backupButton.addEventListener('click', function () {
|
||||
console.log('Set backup directory button clicked!');
|
||||
|
||||
@@ -87,20 +80,14 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
console.log('Set backup directory button clicked!');
|
||||
|
||||
window.electronAPI.openJsonDirConfigDialog('dirShare.json')
|
||||
.then(() => console.log('Share directory set'))
|
||||
.then(() => console.log('Back-up directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
});
|
||||
|
||||
departmentButton.addEventListener('click', function () {
|
||||
console.log('Set backup directory button clicked!');
|
||||
|
||||
window.electronAPI.openJsonDirConfigDialog('dirDepartment.json')
|
||||
.then(() => console.log('Department directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
manageUsersButton.addEventListener('click', async function(){
|
||||
fadeOut('manage_users.html');
|
||||
});
|
||||
|
||||
changeInfoButton.addEventListener('click', function () {
|
||||
@@ -108,12 +95,13 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
fadeOut('profile.html');
|
||||
});
|
||||
|
||||
changeDepartmentButton.addEventListener('click', function () {
|
||||
handleOverlayOpen('change_department');
|
||||
decryptButton.addEventListener('click', function () {
|
||||
fadeOut('decrypting_backup.html');
|
||||
});
|
||||
|
||||
decryptButton.addEventListener('click', function () {
|
||||
handleOverlayOpen('decrypt');
|
||||
changeInfoButton.addEventListener('click', function () {
|
||||
console.log('Change your info button clicked!');
|
||||
fadeOut('profile.html');
|
||||
});
|
||||
|
||||
shareFileButton.addEventListener('click', function () {
|
||||
@@ -121,6 +109,10 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
fadeOut('share_file.html');
|
||||
});
|
||||
|
||||
manageDepartmentButton.addEventListener('click', function() {
|
||||
fadeOut('manage_departments.html');
|
||||
})
|
||||
|
||||
logoutButton.addEventListener('click', async function () {
|
||||
console.log('Logout button clicked!');
|
||||
await window.electronAPI.killBeforeLogout();
|
||||
@@ -128,6 +120,9 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
fadeOut('login.html');
|
||||
});
|
||||
|
||||
decryptButton.addEventListener('click', async function (){
|
||||
|
||||
});
|
||||
async function checkDirBackupFileExists() {
|
||||
try {
|
||||
// Make an IPC call to check file existence
|
||||
@@ -154,7 +149,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
if (!fileExists) {
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const button = document.createElement('button');
|
||||
button.id = 'share_dir_alert';
|
||||
button.id = 'share_file_alert';
|
||||
button.name = 'alert';
|
||||
button.textContent = 'Set your share directory!';
|
||||
button.addEventListener('click', handleShareButtonPressed);
|
||||
@@ -165,24 +160,6 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkDepartmentDirFileExists() {
|
||||
try {
|
||||
const fileExists = await window.electronAPI.checkFileExists('dirDepartment.json');
|
||||
|
||||
if (!fileExists) {
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const button = document.createElement('button');
|
||||
button.id = 'department_alert';
|
||||
button.name = 'alert';
|
||||
button.textContent = 'Set your department directory!';
|
||||
button.addEventListener('click', handleDepartmentButtonPressed);
|
||||
notificationsDiv.appendChild(button);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking file existence:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleBackupButtonPressed() {
|
||||
console.log('Button clicked!');
|
||||
|
||||
@@ -205,20 +182,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
|
||||
const button = document.getElementById('share_dir_alert');
|
||||
button.remove();
|
||||
}
|
||||
|
||||
async function handleDepartmentButtonPressed() {
|
||||
console.log('Button clicked!');
|
||||
|
||||
await window.electronAPI.openJsonDirConfigDialog('dirDepartment.json')
|
||||
.then(() => console.log('Department directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
|
||||
const button = document.getElementById('department_alert');
|
||||
const button = document.getElementById('share_alert');
|
||||
button.remove();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user