This commit is contained in:
Skylar Grant 2024-08-13 16:28:07 -04:00
parent da26029330
commit e374ef1677
2 changed files with 70 additions and 59 deletions

View File

@ -1,58 +1,60 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSV Filterer</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="CSVFilterer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.4.1/papaparse.js" integrity="sha512-M0cjXJTonbWEdLI3HJIoJSQBb9980RWmOCk+tvWkhgFrAZqSSIg1+1Db/vDu7Qk9W3L90gBynve17PYvarjfQA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<head> <body class="bg-gray-100 flex items-center justify-center min-h-screen">
<meta charset="UTF-8"> <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-2xl">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <h1 class="text-2xl font-semibold text-gray-800 mb-6 text-center">CSV Filterer</h1>
<title>CSV Filterer</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="CSVFilterer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.4.1/papaparse.js" integrity="sha512-M0cjXJTonbWEdLI3HJIoJSQBb9980RWmOCk+tvWkhgFrAZqSSIg1+1Db/vDu7Qk9W3L90gBynve17PYvarjfQA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen"> <div class="mb-4 flex items-center">
<div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-2xl"> <label for="usersCsv" class="block text-gray-700 font-medium mr-2">Users.csv</label>
<h1 class="text-2xl font-semibold text-gray-800 mb-6 text-center">CSV Filterer</h1> <input id="usersCsv" type="file" class="mt-2 p-2 border border-gray-300 rounded flex-grow">
<button onclick="parseUsers(document.getElementById('usersCsv'), document)" id="parseUsersBtn" class="ml-2 bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600 focus:outline-none">Parse Users</button>
</div>
<div class="mb-4 flex items-center"> <div class="mb-4 flex items-center">
<label for="usersCsv" class="block text-gray-700 font-medium mr-2">Users.csv</label> <label for="userEnrollmentsCsv" class="block text-gray-700 font-medium mr-2">UserEnrollments.csv</label>
<input id="usersCsv" type="file" class="mt-2 p-2 border border-gray-300 rounded flex-grow"> <input id="userEnrollmentsCsv" type="file" class="mt-2 p-2 border border-gray-300 rounded flex-grow">
<button onclick="parseUsers(document.getElementById('usersCsv'), document)" id="parseUsersBtn" class="ml-2 bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600 focus:outline-none">Parse Users</button> <button onclick="filterEnrollments(document)" id="filterEnrollmentsBtn" class="ml-2 bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 focus:outline-none">Filter Enrollments</button>
</div>
<div class="mb-4">
<label for="schoolSelect" class="block text-gray-700 font-medium">Select School</label>
<select id="schoolSelect" class="mt-2 p-2 border border-gray-300 rounded w-full">
<option value="KV Instructor">KVCC</option>
<option value="EM Instructor">EMCC</option>
<option value="CM Instructor">CMCC</option>
<option value="SM Instructor">SMCC</option>
<option value="YC Instructor">YCCC</option>
<option value="WC Instructor">WCCC</option>
<option value="NM Instructor">NMCC</option>
</select>
</div>
<div class="flex items-center justify-center space-x-4">
<button onclick="generateList(document)" id="downloadBtn" class="mt-6 bg-blue-500 text-white w-full px-4 py-2 rounded hover:bg-blue-600 focus:outline-none" style="display: none;">
Download Instructors CSV
</button>
<button onclick="refreshStatus(document)" id="refreshStatusBtn" class="bg-yellow-500 text-white px-4 py-2 rounded hover:bg-yellow-600 focus:outline-none">
Refresh Status
</button>
<span id="statusIndicator" class="text-gray-600 text-sm">
Enrollments: Not Filtered<br />Users: Not Parsed
</span>
</div>
<div class="flex items-center justify-center space-x-4"" id="downloadLinkContainer">
<a href="google.com" id="downloadLink" style="display: none;">Download CSV File</a>
</div>
</div> </div>
</body>
<div class="mb-4 flex items-center">
<label for="userEnrollmentsCsv" class="block text-gray-700 font-medium mr-2">UserEnrollments.csv</label>
<input id="userEnrollmentsCsv" type="file" class="mt-2 p-2 border border-gray-300 rounded flex-grow">
<button onclick="filterEnrollments(document)" id="filterEnrollmentsBtn" class="ml-2 bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 focus:outline-none">Filter Enrollments</button>
</div>
<div class="mb-4">
<label for="schoolSelect" class="block text-gray-700 font-medium">Select School</label>
<select id="schoolSelect" class="mt-2 p-2 border border-gray-300 rounded w-full">
<option value="KV Instructor">KVCC</option>
<option value="EM Instructor">EMCC</option>
<option value="CM Instructor">CMCC</option>
<option value="SM Instructor">SMCC</option>
<option value="YC Instructor">YCCC</option>
<option value="WC Instructor">WCCC</option>
<option value="NM Instructor">NMCC</option>
</select>
</div>
<div class="flex items-center justify-center space-x-4">
<button onclick="generateList(document)" id="downloadBtn" class="mt-6 bg-blue-500 text-white w-full px-4 py-2 rounded hover:bg-blue-600 focus:outline-none" style="display: none;">
Download Instructors CSV
</button>
<button onclick="refreshStatus(document)" id="refreshStatusBtn" class="bg-yellow-500 text-white px-4 py-2 rounded hover:bg-yellow-600 focus:outline-none">
Refresh Status
</button>
<span id="statusIndicator" class="text-gray-600 text-sm">
Enrollments: Not Filtered<br />Users: Not Parsed
</span>
</div>
</div>
</body>
</html> </html>

View File

@ -56,6 +56,7 @@ function filterEnrollments(document) {
states.enrollments = "Filtered"; states.enrollments = "Filtered";
refreshStatus(document); refreshStatus(document);
console.log(JSON.stringify(enrollments));
}, },
error: function(error) { error: function(error) {
console.error(error); console.error(error);
@ -83,6 +84,7 @@ const parseUsers = (usersFileInputs, document) => {
}); });
states.users = "Parsed"; states.users = "Parsed";
refreshStatus(document); refreshStatus(document);
console.log(users);
}, },
error: function(error) { error: function(error) {
console.error(error); console.error(error);
@ -98,21 +100,28 @@ const generateList = (document) => {
enrollments.forEach(e => { enrollments.forEach(e => {
// Get the associated user // Get the associated user
const user = users.get(e.userId); const user = users.get(e.userId);
preCSV.push(`${user.userId},${e.timestamp}.${user.fName},${user.sName},${user.uName}`); preCSV.push(`${user.userId},${e.timestamp},${user.fName},${user.sName},${user.uName}`);
}); });
const postCSV = preCSV.join('\n');
generateCSV(preCSV, document); generateCSV(postCSV, document);
} }
const generateCSV = (input, document) => { const generateCSV = (input, document) => {
const downloadLink = document.getElementById("downloadBtn"); const downloadLink = document.getElementById("downloadLink");
const blob = new Blob([input], { type: 'text/csv' }); const blob = new Blob([input], { type: 'text/csv' });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
console.log(url);
downloadLink.style = "display: inline;";
downloadLink.href = url;
downloadLink.download = 'Instructors.CSV';
downloadLink.onclick = `window.location = ${url}` // downloadBtn.onclick = function() {
downloadLink.style.display = 'block'; // const a = document.createElement('a');
downloadLink.textContent = 'Download Filtered CSV'; // a.href = url;
// a.download = 'data.csv';
// document.body.appendChild(a);
// };
} }
function refreshStatus(document) { function refreshStatus(document) {