program finalizat
This commit is contained in:
+80
-72
@@ -1,62 +1,13 @@
|
||||
let pathToFile = '';
|
||||
let fetchUsersInterval = null;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
let user_info = {};
|
||||
let pathToFile = '';
|
||||
const selectFileButton = document.getElementById('selectFile');
|
||||
const submitButton = document.getElementById('submitButton');
|
||||
const backButton = document.getElementById('backButton');
|
||||
|
||||
user_info = await window.electronAPI.readUserConfig('user_info');
|
||||
if (!user_info) {
|
||||
await window.electronAPI.showAlert('No user_info entry found.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Function to update the file name display
|
||||
function updateFileName() {
|
||||
const fileNameElement = document.getElementById('fileName');
|
||||
if (!fileNameElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathToFile.trim() === '') {
|
||||
fileNameElement.textContent = 'No file chosen';
|
||||
} else {
|
||||
fileNameElement.textContent = pathToFile.split('\\').pop().split('/').pop();
|
||||
}
|
||||
}
|
||||
|
||||
updateFileName();
|
||||
|
||||
// Fetch user information from applicationInfo and create checkboxes for selecting users
|
||||
async function fetchUsersAndCreateCheckboxes() {
|
||||
const usersInfoId = await window.electronAPI.readApplicationInfo('active_users_info');
|
||||
if (!usersInfoId) {
|
||||
await window.electronAPI.showAlert('Internal error.');
|
||||
return;
|
||||
}
|
||||
|
||||
const usersInfo = await window.electronAPI.readMemoryEntry(usersInfoId);
|
||||
if (!usersInfo || usersInfo.length === 0) {
|
||||
await window.electronAPI.showAlert('No active users found.');
|
||||
await window.electronAPI.changeContent('main_menu');
|
||||
return;
|
||||
}
|
||||
|
||||
const usersDiv = document.querySelector('.choose_user_form_content');
|
||||
usersDiv.innerHTML = '';
|
||||
usersInfo.forEach(user => {
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.name = 'users';
|
||||
checkbox.value = user.ip; // Store user's IP in the value
|
||||
|
||||
const label = document.createElement('label');
|
||||
label.innerHTML = `${user.user_info.name}`; // Display user's name
|
||||
label.insertBefore(checkbox, label.firstChild);
|
||||
|
||||
usersDiv.appendChild(label);
|
||||
});
|
||||
}
|
||||
|
||||
// Event listener for selecting the file
|
||||
document.getElementById('selectFile').addEventListener('click', async function () {
|
||||
selectFileButton.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
try {
|
||||
pathToFile = await window.electronAPI.selectFile();
|
||||
updateFileName();
|
||||
@@ -64,14 +15,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
console.error('Error opening file dialog:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Event listener for back button to navigate to main menu
|
||||
document.getElementById('backButton').addEventListener('click', function () {
|
||||
fadeOut('main_menu');
|
||||
});
|
||||
|
||||
// Submit button logic to queue file send tasks and then navigate to main_menu.html
|
||||
document.getElementById('submitButton').addEventListener('click', async function (event) {
|
||||
submitButton.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
// Check if a file was chosen
|
||||
@@ -80,6 +24,11 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
return;
|
||||
}
|
||||
|
||||
const user_info = await window.electronAPI.readUserConfig('user_info');
|
||||
if (!user_info) {
|
||||
return;
|
||||
}
|
||||
|
||||
const form = document.getElementById('userDestForm');
|
||||
const checkboxes = form.querySelectorAll('input[name="users"]');
|
||||
const selectedUserIps = Array.from(checkboxes)
|
||||
@@ -100,19 +49,78 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
userName: user_info.name // Sender's username from userConfig
|
||||
};
|
||||
await window.electronAPI.addTaskToSendFileQueue(task);
|
||||
|
||||
await window.electronAPI.showAlert('File sent to the queue.');
|
||||
console.log(`Task added to send file to IP ${selectedUserIp}`);
|
||||
} catch (error) {
|
||||
console.error(`Error processing IP ${selectedUserIp}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Navigate back to the main menu after all tasks are queued
|
||||
fadeOut('main_menu'); // Navigate to the main menu
|
||||
});
|
||||
backButton.addEventListener('click', function (event) {
|
||||
event.preventDefault();
|
||||
fadeOut('main_menu');
|
||||
});
|
||||
|
||||
// Fetch users and create checkboxes every 5 seconds (in case of updates)
|
||||
setInterval(fetchUsersAndCreateCheckboxes, 5000);
|
||||
|
||||
fetchUsersAndCreateCheckboxes().then(() => console.log('User checkboxes rendered'));
|
||||
});
|
||||
|
||||
// Function to update the file name display
|
||||
function updateFileName() {
|
||||
const fileNameElement = document.getElementById('selectFile');
|
||||
if (!fileNameElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathToFile.trim() === '') {
|
||||
fileNameElement.textContent = 'No file chosen';
|
||||
} else {
|
||||
fileNameElement.textContent = pathToFile.split('\\').pop().split('/').pop();
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchUsersAndCreateCheckboxes() {
|
||||
// Step 1: Get the currently checked users before refreshing the list
|
||||
const selectedUserIps = new Set(
|
||||
Array.from(document.querySelectorAll('input[name="users"]:checked'))
|
||||
.map(checkbox => checkbox.value)
|
||||
);
|
||||
|
||||
const usersInfoId = await window.electronAPI.readApplicationInfo('active_users_info');
|
||||
if (!usersInfoId) {
|
||||
await window.electronAPI.showAlert('Internal error.');
|
||||
return;
|
||||
}
|
||||
|
||||
const usersInfo = await window.electronAPI.readMemoryEntry(usersInfoId);
|
||||
if (!usersInfo || usersInfo.length === 0) {
|
||||
await window.electronAPI.showAlert('No active users found.');
|
||||
clearInterval(fetchUsersInterval);
|
||||
fetchUsersInterval = null;
|
||||
await window.electronAPI.changeContent('main_menu');
|
||||
return;
|
||||
}
|
||||
|
||||
const usersDiv = document.getElementById('choose_user_form_content');
|
||||
usersDiv.innerHTML = ''; // Clear the list before updating
|
||||
|
||||
usersInfo.forEach(user => {
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.name = 'users';
|
||||
checkbox.value = user.ip; // Store user's IP in the value
|
||||
|
||||
// Step 2: Check if this user was previously selected
|
||||
if (selectedUserIps.has(user.ip)) {
|
||||
checkbox.checked = true; // Restore checked state
|
||||
}
|
||||
|
||||
const label = document.createElement('label');
|
||||
label.innerHTML = `${user.user_info.name}`; // Display user's name
|
||||
label.insertBefore(checkbox, label.firstChild);
|
||||
|
||||
usersDiv.appendChild(label);
|
||||
});
|
||||
|
||||
toggleScroll('choose_user_form_content');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user