From 414c95eff1a08bc4e003d99d2d06421d22e1849d Mon Sep 17 00:00:00 2001 From: Alexander Claes Date: Sun, 18 Oct 2026 10:15:44 +0200 Subject: [PATCH] Make entire ticket cards draggable and click to edit titles --- README.md | 4 +-- src/main/resources/META-INF/resources/app.js | 29 ++++++++++++++++--- .../resources/META-INF/resources/index.html | 2 +- .../resources/META-INF/resources/styles.css | 3 ++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5a0d1bc..7d2b561 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ A learning project for a ticket board with TODO, DOING, and DONE columns. The ow ## Current features -- Create tickets in any column, edit titles inline in a textarea beside the actions button, and delete tickets. While editing, Enter adds a line, Ctrl/⌘ + Enter saves, and Escape cancels. Saved titles preserve line breaks on the card. -- Cards show the title, a three-dot actions button, and a small indicator when blocked. Hover over the actions button for 250 ms or click/tap it to open movement, blocking, deletion, and drag controls. Keyboard users can open it with Enter/Space or Arrow Down, Tab through actions, and close it with Escape. The drag control also supports left/right arrow keys. +- Create tickets in any column, click a card outside its actions menu to edit its title inline in a textarea beside the actions button, and delete tickets. While editing, Enter adds a line, Ctrl/⌘ + Enter saves, and Escape cancels. Saved titles preserve line breaks on the card. +- Cards show the title, a three-dot actions button, and a small indicator when blocked. Drag a card to another column to move it; dragging is disabled while editing or saving. Hover over the actions button for 250 ms or click/tap it to open movement, blocking, deletion, and drag controls. Menu clicks do not open the title editor. Keyboard users can open the menu with Enter/Space or Arrow Down, Tab through actions, and close it with Escape. The drag control also supports left/right arrow keys. - Add tickets with an explicit Add button or Enter. The actions panel contains a shortened UUID reference; the full identifier is retained in API requests and available in the reference tooltip. - Submit blocking requests, record or edit a blocking reason, and unblock tickets. - Refresh the board manually to load the current server state. diff --git a/src/main/resources/META-INF/resources/app.js b/src/main/resources/META-INF/resources/app.js index 3eb91f9..be2e45f 100644 --- a/src/main/resources/META-INF/resources/app.js +++ b/src/main/resources/META-INF/resources/app.js @@ -174,6 +174,7 @@ async function runCard(id, action, focusTarget = '.ticket-title') { updateRefresh(); clearDrag(); card.setAttribute('aria-busy', 'true'); + card.draggable = false; controls.forEach(control => { control.disabled = true; }); const message = card.querySelector('.ticket-feedback'); message.classList.remove('error', 'sr-only'); @@ -190,6 +191,7 @@ async function runCard(id, action, focusTarget = '.ticket-title') { updateRefresh(); if (card.isConnected) { card.removeAttribute('aria-busy'); + card.draggable = !editingTickets.has(id); controls.forEach((control, index) => { control.disabled = disabled[index]; }); } if (document.activeElement === document.body || card.contains(document.activeElement)) { @@ -246,6 +248,7 @@ function openInlineEditor(id, mode) { const card = cardFor(id); editingTickets.add(id); card.classList.add('editing'); + card.draggable = false; closeTicketMenus(); card.querySelectorAll('button').forEach(control => { control.disabled = true; }); card.querySelector('.ticket-feedback').textContent = ''; @@ -307,11 +310,24 @@ function ticketCard(ticket) { const id = String(ticket.id); const card = element('article', `ticket${ticket.blocked ? ' blocked' : ''}`); card.dataset.ticketId = id; + card.draggable = true; + let suppressClick = false; + card.addEventListener('pointerdown', event => { + card.draggable = !refreshing && !pendingTickets.has(id) && !editingTickets.has(id) + && (!event.target.closest('.ticket-menu') || !!event.target.closest('.drag-handle')); + }); + card.addEventListener('click', event => { + if (suppressClick || event.target.closest('.ticket-menu, .inline-editor')) return; + if (editingTickets.has(id)) { + card.querySelector('textarea[name="title"]')?.focus(); + return; + } + openInlineEditor(id, 'title'); + }); const header = element('div', 'ticket-header'); const heading = element('h3', 'ticket-heading'); const title = button(ticket.title, 'ticket-title', `Edit title of ticket ${id}: ${ticket.title}`); title.title = ticket.blocked ? `Blocked: ${ticket.blockedNote}` : 'Click to edit title'; - title.addEventListener('click', () => openInlineEditor(id, 'title')); heading.append(title); if (ticket.blocked) { const badge = element('span', 'blocked-indicator'); @@ -397,18 +413,23 @@ function ticketCard(ticket) { const destination = statuses[statuses.indexOf(ticket.status) + direction]; if (destination) moveTicket(id, destination); }); - handle.addEventListener('dragstart', event => { - if (refreshing || pendingTickets.has(id) || editingTickets.has(id)) { + card.addEventListener('dragstart', event => { + if (refreshing || pendingTickets.has(id) || editingTickets.has(id) || !card.draggable) { event.preventDefault(); return; } + suppressClick = true; + closeTicketMenus(); draggedTicketId = id; event.dataTransfer.setData('text/plain', id); event.dataTransfer.effectAllowed = 'move'; event.dataTransfer.setDragImage(card, card.offsetWidth / 2, 20); card.classList.add('dragging'); }); - handle.addEventListener('dragend', clearDrag); + card.addEventListener('dragend', () => { + clearDrag(); + setTimeout(() => { suppressClick = false; }, 0); + }); const remove = actionButton('Delete ticket', 'trash', 'quiet danger', `Delete ticket ${id}: ${ticket.title}`); remove.title = 'Delete ticket'; remove.addEventListener('click', () => { diff --git a/src/main/resources/META-INF/resources/index.html b/src/main/resources/META-INF/resources/index.html index a92e8f7..938092b 100644 --- a/src/main/resources/META-INF/resources/index.html +++ b/src/main/resources/META-INF/resources/index.html @@ -59,7 +59,7 @@

DONE 0

-

Click a title to edit. Enter adds a line; Ctrl/⌘ + Enter saves; Esc cancels. Hover over ⋯ briefly or click it for ticket actions, including moving and blocking.

+

Drag a card to move it, or click it to edit its title. Enter adds a line; Ctrl/⌘ + Enter saves; Esc cancels. Hover over ⋯ briefly or click it for ticket actions, including moving and blocking.

diff --git a/src/main/resources/META-INF/resources/styles.css b/src/main/resources/META-INF/resources/styles.css index 9e20df1..76d3ae7 100644 --- a/src/main/resources/META-INF/resources/styles.css +++ b/src/main/resources/META-INF/resources/styles.css @@ -175,6 +175,9 @@ h2 { font-size: .75rem; font-weight: 650; letter-spacing: .09em; margin: 0 0 18p border-radius: 10px; min-width: 0; box-shadow: 0 3px 8px var(--ticket-shadow); } .ticket:hover { border-color: var(--ticket-hover-border); } +.ticket[draggable="true"] { cursor: grab; } +.ticket[draggable="true"]:active { cursor: grabbing; } +.ticket[draggable="true"] .ticket-title { cursor: inherit; user-select: none; } .ticket.blocked { border-left: 3px solid var(--warning); } .ticket.dragging { opacity: .45; } .ticket-header { display: flex; align-items: flex-start; gap: 6px; }