2024-08-13 13:48:52 +00:00
|
|
|
class UserData {
|
|
|
|
constructor(dataRow) {
|
|
|
|
this.userId = dataRow[0];
|
|
|
|
this.uName = dataRow[1];
|
|
|
|
this.fName = dataRow[3];
|
|
|
|
this.sName = dataRow[5];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class EnrollmentData {
|
|
|
|
constructor(dataRow) {
|
|
|
|
this.orgUnitId = dataRow[0];
|
|
|
|
this.userId = dataRow[1];
|
|
|
|
this.roleName = dataRow[2];
|
|
|
|
this.timestamp = dataRow[3];
|
|
|
|
this.roleId = dataRow[5];
|
|
|
|
this.fName = "N/A";
|
|
|
|
this.sName = "N/A";
|
|
|
|
this.uName = "N/A";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create empty Maps to store the filtered enrollment data and user info in
|
|
|
|
// These will be cross checked later to generate the list of all instructors
|
|
|
|
const users = new Map();
|
|
|
|
const enrollments = new Map();
|
|
|
|
|
|
|
|
let states = {
|
2024-08-13 15:54:23 +00:00
|
|
|
enrollments: false,
|
|
|
|
users: false
|
2024-08-13 13:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function filterEnrollments(document) {
|
2024-08-13 15:54:23 +00:00
|
|
|
let fileInput = document.getElementById('userEnrollmentsCsv');
|
2024-08-13 13:48:52 +00:00
|
|
|
let filterValue = "KV Instructor";
|
2024-08-13 15:54:23 +00:00
|
|
|
document.getElementById('downloadBtn')
|
2024-08-13 13:48:52 +00:00
|
|
|
if (!fileInput.files.length) {
|
|
|
|
alert('Please select a CSV file.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const file = fileInput.files[0];
|
|
|
|
|
|
|
|
Papa.parse(file, {
|
|
|
|
complete: function(results) {
|
|
|
|
// Iterate over the entire data set
|
|
|
|
results.data.forEach(row => {
|
|
|
|
// Create an EnrollmentData object with it:
|
|
|
|
const enrollmentData = new EnrollmentData(row);
|
|
|
|
// If the row contains the filter string and is not in the 'seen' Set
|
|
|
|
if (row.some(cell => cell.includes(filterValue)) && !enrollments.has(enrollmentData.userId)) {
|
|
|
|
// Add it to the data array
|
|
|
|
enrollments.set(enrollmentData.userId, enrollmentData);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
states.enrollments = "Filtered";
|
|
|
|
refreshStatus(document);
|
|
|
|
},
|
|
|
|
error: function(error) {
|
|
|
|
console.error(error);
|
|
|
|
alert('An error occurred while processing the file.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const parseUsers = (usersFileInputs, document) => {
|
|
|
|
if (!usersFileInputs.files.length) {
|
|
|
|
alert('Please select a CSV file.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const usersFile = usersFileInputs.files[0];
|
|
|
|
|
|
|
|
Papa.parse(usersFile, {
|
|
|
|
complete: function(results) {
|
|
|
|
// Iterate over the entire data set
|
|
|
|
results.data.forEach(row => {
|
|
|
|
// Create an object with it:
|
|
|
|
const userData = new UserData(row);
|
|
|
|
// Add it to the data array
|
|
|
|
users.set(userData.userId, userData);
|
|
|
|
});
|
|
|
|
states.users = "Parsed";
|
|
|
|
refreshStatus(document);
|
|
|
|
},
|
|
|
|
error: function(error) {
|
|
|
|
console.error(error);
|
|
|
|
alert('An error occurred while processing the Users.csv file.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const generateList = (document) => {
|
|
|
|
const preCSV = [
|
|
|
|
"UserId,Timestamp,FirstName,LastName,Username"
|
|
|
|
];
|
|
|
|
enrollments.forEach(e => {
|
|
|
|
// Get the associated user
|
|
|
|
const user = users.get(e.userId);
|
|
|
|
preCSV.push(`${user.userId},${e.timestamp}.${user.fName},${user.sName},${user.uName}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
generateCSV(preCSV, document);
|
|
|
|
}
|
|
|
|
|
|
|
|
const generateCSV = (input, document) => {
|
2024-08-13 15:54:23 +00:00
|
|
|
const downloadLink = document.getElementById("downloadBtn");
|
2024-08-13 13:48:52 +00:00
|
|
|
|
2024-08-13 15:54:23 +00:00
|
|
|
const blob = new Blob([input], { type: 'text/csv' });
|
2024-08-13 13:48:52 +00:00
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
2024-08-13 15:54:23 +00:00
|
|
|
downloadLink.onclick = `window.location = ${url}`
|
2024-08-13 13:48:52 +00:00
|
|
|
downloadLink.style.display = 'block';
|
|
|
|
downloadLink.textContent = 'Download Filtered CSV';
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshStatus(document) {
|
2024-08-13 15:54:23 +00:00
|
|
|
let statusString = "";
|
|
|
|
let statusSpan = document.getElementById('statusIndicator')
|
|
|
|
states.enrollments ? statusString += "Enrollments: Filtered" : statusString += "Enrollments: Not Filtered";
|
|
|
|
states.users ? statusString += "<br />Users: Parsed" : statusString += "<br />Users: Not Parsed"
|
2024-08-13 13:48:52 +00:00
|
|
|
statusSpan.innerHTML = statusString;
|
2024-08-13 15:54:23 +00:00
|
|
|
|
|
|
|
if (states.enrollments && states.users) {
|
|
|
|
let refreshBtn = document.getElementById('refreshStatusBtn');
|
|
|
|
let downloadBtn = document.getElementById('downloadBtn');
|
|
|
|
refreshBtn.style = "display: none";
|
|
|
|
downloadBtn.style = "display: block";
|
|
|
|
}
|
2024-08-13 13:48:52 +00:00
|
|
|
}
|