Files
Spark fbe58bbf16 feat(today): focus du jour — le rituel des 3 cartes (issue #5)
Table today_picks; POST /api/today/pin (max 3, idempotent) et
/unpin; page /today (picks en direct, candidates de l'encours,
reprises d'hier, récap du jour depuis le journal); bouton 📌 sur
les cartes (délégation capture dans today.js, fragments live
compris); sections dédiées dans le briefing du matin.
2026-10-11 13:55:03 -04:00

49 lines
2.2 KiB
JavaScript

/**
* Kanbante — Focus of the day (issue #5): pin/unpin from /today and,
* via a delegated handler, the 📌 button on board cards.
*/
(function () {
var csrf = (document.querySelector('meta[name="csrf-token"]') || {}).content || '';
function post(url, repo, number) {
var data = new FormData();
data.append('repo_full_name', repo);
data.append('issue_number', number);
data.append('csrf_token', csrf);
return fetch(url, { method: 'POST', body: data }).then(function (r) {
return r.json().catch(function () { return {}; }).then(function (body) {
if (!r.ok || body.ok === false) throw new Error(body.error || ('HTTP ' + r.status));
return body;
});
});
}
// Capture phase: a 📌 click on a board card must be swallowed
// before board.js sees it (it would open the detail drawer).
document.addEventListener('click', function (e) {
var pinBtn = e.target.closest('[data-pin]');
var unpinBtn = e.target.closest('[data-unpin]');
var cardPin = e.target.closest('.pin-btn');
if (pinBtn) {
post('/api/today/pin', pinBtn.getAttribute('data-repo'), pinBtn.getAttribute('data-number'))
.then(function () { location.reload(); })
.catch(function (err) { alert(err.message); });
} else if (unpinBtn) {
post('/api/today/unpin', unpinBtn.getAttribute('data-repo'), unpinBtn.getAttribute('data-number'))
.then(function () { location.reload(); })
.catch(function (err) { alert(err.message); });
} else if (cardPin) {
// Board card 📌: never open the detail drawer for this click.
e.stopPropagation();
e.preventDefault();
var card = cardPin.closest('.kanban-card');
post('/api/today/pin', card.getAttribute('data-repo'), card.getAttribute('data-issue'))
.then(function () {
cardPin.textContent = '📌✓';
cardPin.title = 'Épinglée au Focus du jour (/today)';
})
.catch(function (err) { alert(err.message); });
}
}, true);
})();