`;
});
board.appendChild(column);
});
addDragDropListeners();
}
function renderBugsTable() {
const table = document.getElementById('bugs-table');
table.innerHTML = `
| ID | Title | Status | Priority | Assignee | Reporter | Date | Actions |
${bugsData.map(b => `
| ${b.ID} |
|
|
|
|
|
|
|
`).join('')}
`;
}
function addDragDropListeners() {
document.querySelectorAll('.brd-task-card').forEach(card => {
card.addEventListener('dragstart', e => e.dataTransfer.setData('text/plain', e.target.dataset.id));
});
document.querySelectorAll('.brd-board-column').forEach(col => {
col.addEventListener('dragover', e => e.preventDefault());
col.addEventListener('drop', e => {
e.preventDefault();
const id = parseInt(e.dataTransfer.getData('text/plain'));
const newStatus = e.currentTarget.dataset.status;
const bug = bugsData.find(b => b.id === id);
if (bug && bug.Status !== newStatus) {
bug.Status = newStatus;
renderAll();
}
});
});
}
function addBug() {
const newId = `BUG-${Math.floor(1000 + Math.random() * 9000)}`;
bugsData.unshift({ id: Date.now(), ID: newId, Title: 'New bug report', Status: 'New', Priority: 'Medium', Assignee: ASSIGNEES[0], Reporter: REPORTERS[0], Date: new Date().toISOString().split('T')[0] });
renderAll();
}
function handleTableEvents(e) {
const target = e.target; if (!target) return;
const id = parseInt(target.closest('tr')?.dataset.id); if (!id) return;
if (target.classList.contains('remove-bug-btn')) {
bugsData = bugsData.filter(b => b.id !== id);
} else if (target.tagName === 'INPUT' || target.tagName === 'SELECT') {
const key = target.dataset.key;
const item = bugsData.find(b => b.id === id);
if(item) item[key] = target.value;
}
renderAll();
}
document.getElementById('brd-add-bug-btn').addEventListener('click', addBug);
const bugsTable = document.getElementById('bugs-table');
bugsTable.addEventListener('change', handleTableEvents);
bugsTable.addEventListener('click', handleTableEvents);
function initialize() {
bugsData = [
{ id: 1, ID: 'BUG-4815', Title: 'User cannot log in with valid credentials', Status: 'In Progress', Priority: 'High', Assignee: 'Alice', Reporter: 'User Feedback', Date: '2025-07-06' },
{ id: 2, ID: 'BUG-4816', Title: 'Save button is disabled on settings page', Status: 'In Progress', Priority: 'Medium', Assignee: 'Bob', Reporter: 'QA Team (USA)', Date: '2025-07-05' },
{ id: 3, ID: 'BUG-4817', Title: 'Export to CSV function throws an error', Status: 'New', Priority: 'High', Assignee: 'Charlie', Reporter: 'User Feedback', Date: '2025-07-07' },
{ id: 4, ID: 'BUG-4818', Title: 'Incorrect calculation in monthly report', Status: 'In Review', Priority: 'Medium', Assignee: 'Diana', Reporter: 'Dev Team (USA)', Date: '2025-07-04' },
{ id: 5, ID: 'BUG-4819', Title: 'UI text overlaps on mobile view', Status: 'Done', Priority: 'Low', Assignee: 'Alice', Reporter: 'QA Team (USA)', Date: '2025-07-01' },
];
renderAll();
}
initialize();
});