Make a simple javascript/html/css page that can take CSV data and display a nice UI to…
- User
Make a simple javascript/html/css page that can take CSV data and display a nice UI to modify it. The UI should contain the following:
-
A box for each PI (Program Increment):
- A card for each epic in the PI and the number of points associated (editiable, and possible to leave blank)
- A display of the total number of points within that epic
- A capcity field for that epic, which is editable.
- A display of how many points over or under capacity that epic is.
-
This UI should have the ability to drag epics from one epic to another, causing the total point calculations to automatically update.
-
A sidebar should exist for epics not assigned to a PI. These can be dragged into PIs.
-
The UI should look nice, yet simple and functional. Dark mode style preferred.
-
The enitre site should be output as a single HMTL file. Even the CSV data can be embedded directly in the page.
-
The current state of the page should be saved in cookies, so it canbe reloaded and edited.
-
There should be a button to export the updated CSV reflecting the current state of the page.
Here is an example of how the CSV data will be formatted:
Program Increment,1 Epic Name,Points Example Epic #1,5 Example Epic #2,3 Total,8 Capacity, Program Increment,2 Epic Name,Points Example Epic #1,2 Example Epic #2,2 Total,4 Capacity, NOT ASSIGNED,SIDEBAR Example Epic #1,4
-
- Assistant
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PI Epic Manager</title> <style> body { background-color: #121212; color: #e0e0e0; font-family: Arial, sans-serif; margin: 0; padding: 0; } .container { display: flex; min-height: 100vh; } .sidebar, .pi { border: 1px solid #333; padding: 10px; margin: 10px; flex: 1; border-radius: 5px; background-color: #1e1e1e; } .pi-header { display: flex; justify-content: space-between; align-items: center; } .epic-list { min-height: 100px; border: 1px dashed #555; padding: 5px; margin-top: 10px; border-radius: 5px; } .epic { background-color: #2e2e2e; margin: 5px 0; padding: 5px; border-radius: 3px; cursor: move; display: flex; justify-content: space-between; align-items: center; } .epic input { width: 50px; margin-left: 10px; background-color: #424242; border: 1px solid #555; color: #e0e0e0; } .pi-footer { margin-top: 10px; } .pi-footer input { width: 80px; background-color: #424242; border: 1px solid #555; color: #e0e0e0; } button { background-color: #424242; color: #e0e0e0; border: 1px solid #555; padding: 5px 10px; margin: 10px; cursor: pointer; } button:hover { background-color: #555; } </style> </head> <body> <div class="container"> <div class="sidebar" id="sidebar"> <h2>Unassigned Epics</h2> <div class="epic-list" id="unassignedEpics"></div> </div> <div class="pi" id="piContainer"></div> </div> <button id="exportBtn">Export CSV</button> <script> // Embedded CSV Data const csvData = `Program Increment,1 Epic Name,Points Example Epic #1,5 Example Epic #2,3 Total,8 Capacity, Program Increment,2 Epic Name,Points Example Epic #1,2 Example Epic #2,2 Total,4 Capacity, NOT ASSIGNED,SIDEBAR Example Epic #1,4`; // Parse CSV Data function parseCSV(data) { const lines = data.trim().split('\n'); const pis = {}; let currentPI = null; for (let i = 0; i < lines.length; i++) { const [key, value] = lines[i].split(','); if (key === 'Program Increment') { currentPI = value.trim(); pis[currentPI] = { epics: [], capacity: '', total: 0 }; i += 1; // Skip header } else if (key === 'NOT ASSIGNED') { currentPI = 'Unassigned'; pis[currentPI] = { epics: [], capacity: '', total: 0 }; i += 1; // Skip header } else if (key === 'Total') { pis[currentPI].total = parseInt(value) || 0; } else if (key === 'Capacity') { pis[currentPI].capacity = value || ''; } else { // Epic data pis[currentPI].epics.push({ name: key, points: parseInt(value) || '' }); } } return pis; } // Save and Load State function saveState(pis) { document.cookie = "piData=" + encodeURIComponent(JSON.stringify(pis)) + "; path=/"; } function loadState() { const cookies = document.cookie.split(';').map(c => c.trim()); for (let cookie of cookies) { if (cookie.startsWith('piData=')) { return JSON.parse(decodeURIComponent(cookie.substring('piData='.length))); } } return null; } // Initialize Data let piData = loadState(); if (!piData) { piData = parseCSV(csvData); } // Rendering Functions function createEpicElement(epic, piKey) { const epicDiv = document.createElement('div'); epicDiv.className = 'epic'; epicDiv.draggable = true; epicDiv.dataset.name = epic.name; epicDiv.dataset.points = epic.points; epicDiv.dataset.pi = piKey; epicDiv.innerHTML = `<span>${epic.name}</span><input type="number" value="${epic.points}" min="0"/>`; epicDiv.addEventListener('dragstart', dragStart); epicDiv.addEventListener('dragend', dragEnd); const input = epicDiv.querySelector('input'); input.addEventListener('change', (e) => { epic.points = parseInt(e.target.value) || ''; updateTotals(); saveState(piData); }); return epicDiv; } function renderPI(piKey, pi) { const piDiv = document.createElement('div'); piDiv.className = 'pi'; piDiv.dataset.pi = piKey; const header = document.createElement('div'); header.className = 'pi-header'; header.innerHTML = `<h2>Program Increment ${piKey}</h2>`; piDiv.appendChild(header); const epicList = document.createElement('div'); epicList.className = 'epic-list'; epicList.dataset.pi = piKey; epicList.addEventListener('dragover', dragOver); epicList.addEventListener('drop', drop); piDiv.appendChild(epicList); pi.epics.forEach(epic => { const epicDiv = createEpicElement(epic, piKey); epicList.appendChild(epicDiv); }); const footer = document.createElement('div'); footer.className = 'pi-footer'; footer.innerHTML = ` <div>Total Points: <span class="total-points">${pi.total}</span></div> <div>Capacity: <input type="number" value="${pi.capacity}" min="0"/></div> <div>Remaining Capacity: <span class="remaining-capacity">${pi.capacity - pi.total || 0}</span></div> `; piDiv.appendChild(footer); const capacityInput = footer.querySelector('input'); capacityInput.addEventListener('change', (e) => { pi.capacity = parseInt(e.target.value) || ''; updateTotals(); saveState(piData); }); return piDiv; } function renderAll() { const piContainer = document.getElementById('piContainer'); piContainer.innerHTML = ''; for (let [piKey, pi] of Object.entries(piData)) { if (piKey !== 'Unassigned') { const piDiv = renderPI(piKey, pi); piContainer.appendChild(piDiv); } } // Render Unassigned Epics const unassigned = document.getElementById('unassignedEpics'); unassigned.innerHTML = ''; piData['Unassigned'].epics.forEach(epic => { const epicDiv = createEpicElement(epic, 'Unassigned'); unassigned.appendChild(epicDiv); }); } function updateTotals() { for (let [piKey, pi] of Object.entries(piData)) { let total = 0; pi.epics.forEach(epic => { total += parseInt(epic.points) || 0; }); pi.total = total; const piDiv = document.querySelector(`.pi[data-pi="${piKey}"]`); if (piDiv) { piDiv.querySelector('.total-points').textContent = total; const remaining = (parseInt(pi.capacity) || 0) - total; piDiv.querySelector('.remaining-capacity').textContent = remaining; } } } function dragStart(e) { e.dataTransfer.setData('text/plain', JSON.stringify({ name: this.dataset.name, points: this.dataset.points, fromPI: this.dataset.pi })); } function dragEnd(e) { // Placeholder for any drag end functionality } function dragOver(e) { e.preventDefault(); } function drop(e) { e.preventDefault(); const data = JSON.parse(e.dataTransfer.getData('text/plain')); const fromPI = data.fromPI; const toPI = this.dataset.pi; // Remove from old PI const epicIndex = piData[fromPI].epics.findIndex(epic => epic.name === data.name); if (epicIndex > -1) { const [epic] = piData[fromPI].epics.splice(epicIndex, 1); epic.points = data.points; // Add to new PI piData[toPI].epics.push(epic); saveState(piData); renderAll(); updateTotals(); } } // Export CSV function exportCSV() { let csvContent = ''; for (let [piKey, pi] of Object.entries(piData)) { if (piKey !== 'Unassigned') { csvContent += `Program Increment,${piKey}\n`; csvContent += `Epic Name,Points\n`; pi.epics.forEach(epic => { csvContent += `${epic.name},${epic.points}\n`; }); csvContent += `Total,${pi.total}\n`; csvContent += `Capacity,${pi.capacity}\n`; } } // Unassigned Epics csvContent += `NOT ASSIGNED,SIDEBAR\n`; piData['Unassigned'].epics.forEach(epic => { csvContent += `${epic.name},${epic.points}\n`; }); const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'updated_data.csv'; link.style.display = 'none'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } // Initial Render renderAll(); updateTotals(); // Event Listeners document.getElementById('exportBtn').addEventListener('click', exportCSV); </script> </body> </html>Explanation:
-
HTML Structure: The page is structured with a sidebar for unassigned epics and a container for PIs.
-
CSS Styling: Dark mode styling is applied with appropriate colors for background, text, and elements.
-
Parsing CSV Data: The embedded CSV data is parsed into a JavaScript object (
piData) for easy manipulation. -
Rendering Function: The
renderAll()function renders all PIs and epics on the page. Each epic is created with its own element, including an input for points. -
Drag-and-Drop Functionality: Epics are draggable. Event listeners (
dragstart,dragover,drop) handle the drag-and-drop between PIs and the unassigned sidebar. -
Updating Totals and Capacity: When points are edited or epics are moved, totals and remaining capacities are recalculated and displayed.
-
Saving State in Cookies: The current state of
piDatais saved in a cookie whenever changes are made, so the data persists on reload. -
Exporting CSV: Clicking the "Export CSV" button triggers the
exportCSV()function, which reconstructs the CSV data from the current state and initiates a download.
How to Use:
-
Edit Points: In each epic card, you can edit the points directly in the input field.
-
Drag Epics: Click and hold on an epic to drag it to another PI or to the unassigned sidebar.
-
Edit Capacity: In each PI, you can set the capacity in the input field provided.
-
Export Data: Click the "Export CSV" button to download the updated CSV data.
Note: This page is entirely self-contained and does not require any external resources. The state is preserved using cookies, so you can reload the page, and your changes will remain.
-