Almost working

This commit is contained in:
Skylar Grant 2024-08-13 11:54:23 -04:00
parent 886eb58842
commit da26029330
2 changed files with 67 additions and 28 deletions

View File

@ -1,25 +1,58 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSV Filterer</title> <title>CSV Filterer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script> <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="./CSVFilterer.js"></script> <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>
<h1>CSV Filterer</h1>
<label for="ueFileInput">UserEnrollments.csv:</label>
<input type="file" id="ueFileInput" accept=".csv">
<button onclick="filterEnrollments(document)">Filter Enrollments</button>
<br />
<label for="usersFileInput">Users.csv:</label>
<input type="file" id="usersFileInput" accept=".csv">
<button onclick="parseUsers(document.getElementById('usersFileInput'), document)">Parse Users</button>
<br />
<button onclick="refreshStatus(document)">Refresh Status</button> <body class="bg-gray-100 flex items-center justify-center min-h-screen">
<p>Status: <span id="status">Unknown</span></p> <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-2xl">
<a id="downloadLink" style="display:none;">Download Filtered CSV</a> <h1 class="text-2xl font-semibold text-gray-800 mb-6 text-center">CSV Filterer</h1>
<div class="mb-4 flex items-center">
<label for="usersCsv" class="block text-gray-700 font-medium mr-2">Users.csv</label>
<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">
<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> </body>
</html>
</html>

View File

@ -26,14 +26,14 @@ const users = new Map();
const enrollments = new Map(); const enrollments = new Map();
let states = { let states = {
enrollments: "Unfiltered", enrollments: false,
users: "Unparsed" users: false
} }
function filterEnrollments(document) { function filterEnrollments(document) {
let fileInput = document.getElementById('ueFileInput'); let fileInput = document.getElementById('userEnrollmentsCsv');
let filterValue = "KV Instructor"; let filterValue = "KV Instructor";
document.getElementById('downloadLink') document.getElementById('downloadBtn')
if (!fileInput.files.length) { if (!fileInput.files.length) {
alert('Please select a CSV file.'); alert('Please select a CSV file.');
return; return;
@ -83,7 +83,6 @@ const parseUsers = (usersFileInputs, document) => {
}); });
states.users = "Parsed"; states.users = "Parsed";
refreshStatus(document); refreshStatus(document);
generateList(document);
}, },
error: function(error) { error: function(error) {
console.error(error); console.error(error);
@ -106,20 +105,27 @@ const generateList = (document) => {
} }
const generateCSV = (input, document) => { const generateCSV = (input, document) => {
const downloadLink = document.getElementById("downloadLink"); const downloadLink = document.getElementById("downloadBtn");
const csv = Papa.unparse(input);
const blob = new Blob([csv], { type: 'text/csv' }); const blob = new Blob([input], { type: 'text/csv' });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
downloadLink.href = url; downloadLink.onclick = `window.location = ${url}`
downloadLink.download = 'filtered.csv';
downloadLink.style.display = 'block'; downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Filtered CSV'; downloadLink.textContent = 'Download Filtered CSV';
} }
function refreshStatus(document) { function refreshStatus(document) {
let statusSpan = document.getElementById('status') let statusString = "";
let statusString = `Enrollments: ${states.enrollments} | Users: ${states.users}`; 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"
statusSpan.innerHTML = statusString; statusSpan.innerHTML = statusString;
if (states.enrollments && states.users) {
let refreshBtn = document.getElementById('refreshStatusBtn');
let downloadBtn = document.getElementById('downloadBtn');
refreshBtn.style = "display: none";
downloadBtn.style = "display: block";
}
} }