sprint-planner.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. /* global jQuery */
  2. /**
  3. * Main planning view (/sprints/{id}) — Section A: Arbeitstage grid.
  4. *
  5. * Behaviours:
  6. * - Day cells (per worker, per week) snap to 0.5 on blur, batch-saved via
  7. * PATCH /sprints/{id}/week-cells with 400 ms debounce.
  8. * - The Arbeitstage header row is derived from the weekday selection in
  9. * Sprint Settings — it's read-only here (Phase 12).
  10. * - RTB inputs snap to 0.05 on blur, saved via PATCH /sprints/{id}/workers/{sw_id}.
  11. * - Worker rows are sortable (jQuery UI). Drop posts to
  12. * POST /sprints/{id}/workers/reorder.
  13. *
  14. * All capacity values are recomputed client-side with the same formula as
  15. * `App\Services\CapacityCalculator` so the UI stays in sync without waiting
  16. * for the server response.
  17. */
  18. (function ($) {
  19. 'use strict';
  20. const $root = $('[data-sprint-root]');
  21. if ($root.length === 0) { return; }
  22. const sprintId = parseInt($root.data('sprint-id'), 10);
  23. const csrf = String($root.data('csrf') || '');
  24. const reserveFraction = Number($root.data('reserve-fraction') || 0);
  25. // Phase 15: the presentation view stamps data-beamer="1" on the root so
  26. // we can namespace its localStorage keys (don't clobber the user's
  27. // workflow on /sprints/{id}) and flip on vertical-header rotation if
  28. // the task table overflows after the first filter pass.
  29. const isBeamer = Number($root.data('beamer')) === 1;
  30. const keySuffix = isBeamer ? ':beamer' : '';
  31. // Phase 18: per-cell task-assignment status. The flag is rendered onto
  32. // the [data-task-section] element so both this view and present.php
  33. // light up identically. When false, the per-cell selectors and the
  34. // toolbar Status filter are simply absent from the DOM.
  35. const taskStatusEnabled =
  36. $root.find('[data-task-section]').attr('data-task-status-enabled') === '1';
  37. const STATUSES = ['zugewiesen', 'gestartet', 'abgeschlossen', 'abgebrochen'];
  38. // ---------------------------------------------------------------------
  39. // Capacity math — MUST match App\Services\CapacityCalculator
  40. // ---------------------------------------------------------------------
  41. function roundHalf(x) { return Math.round(x * 2) / 2; }
  42. function snap05(x) { return roundHalf(x); }
  43. function snap005(x) { return Math.round(x * 20) / 20; }
  44. function fmtDays(x) {
  45. const n = Number(x);
  46. if (Math.abs(n - Math.round(n)) < 1e-9) { return String(Math.round(n)); }
  47. return n.toFixed(1);
  48. }
  49. function fmtRtb(x) { return Number(x).toFixed(2); }
  50. function capacity(ressourcen, committedPrio1) {
  51. committedPrio1 = committedPrio1 || 0;
  52. const afterReserves = roundHalf(ressourcen * (1 - reserveFraction));
  53. const available = afterReserves - committedPrio1;
  54. return { ressourcen, afterReserves, committedPrio1, available };
  55. }
  56. // Sum of prio-1 task assignment cells per sprint worker, read from DOM.
  57. function committedPrio1FromDom() {
  58. const per = {};
  59. $root.find('tr[data-task-row]').each(function () {
  60. const $row = $(this);
  61. if (parseInt($row.attr('data-prio'), 10) !== 1) { return; }
  62. $row.find('[data-assign]').each(function () {
  63. const key = String($(this).data('sw-id'));
  64. const v = Number($(this).val());
  65. if (!Number.isNaN(v) && v > 0) {
  66. per[key] = (per[key] || 0) + v;
  67. }
  68. });
  69. });
  70. return per;
  71. }
  72. // ---------------------------------------------------------------------
  73. // HTTP helper — spec §7 envelopes
  74. // ---------------------------------------------------------------------
  75. function request(method, url, body) {
  76. const opts = {
  77. method,
  78. headers: {
  79. Accept: 'application/json',
  80. 'X-CSRF-Token': csrf,
  81. },
  82. credentials: 'same-origin',
  83. };
  84. if (body !== undefined) {
  85. opts.headers['Content-Type'] = 'application/json';
  86. opts.body = JSON.stringify(body);
  87. }
  88. return fetch(url, opts).then(async function (res) {
  89. let payload = null;
  90. try { payload = await res.json(); } catch (_) { /* ignore */ }
  91. if (!res.ok || !payload || payload.ok !== true) {
  92. const msg = (payload && payload.error && payload.error.message)
  93. ? payload.error.message
  94. : res.statusText || 'Request failed';
  95. const err = new Error(msg);
  96. err.status = res.status;
  97. err.payload = payload;
  98. throw err;
  99. }
  100. return payload.data;
  101. });
  102. }
  103. // ---------------------------------------------------------------------
  104. // Status line (shared with settings page styling)
  105. // ---------------------------------------------------------------------
  106. const $status = $root.find('[data-status]');
  107. let statusTimer = null;
  108. function flash(text, isError) {
  109. $status
  110. .text(text)
  111. .removeClass('text-green-700 text-red-700 bg-green-50 bg-red-50 border-green-200 border-red-200')
  112. .addClass(isError ? 'text-red-700 bg-red-50 border-red-200' : 'text-green-700 bg-green-50 border-green-200')
  113. .removeClass('opacity-0').addClass('opacity-100');
  114. clearTimeout(statusTimer);
  115. statusTimer = setTimeout(function () {
  116. $status.removeClass('opacity-100').addClass('opacity-0');
  117. }, 2500);
  118. }
  119. // ---------------------------------------------------------------------
  120. // Recompute worker row sum + capacity summary locally
  121. // ---------------------------------------------------------------------
  122. function recomputeRow(swId, commitMap) {
  123. const $row = $root.find('[data-sw-row][data-sw-id="' + swId + '"]');
  124. let sum = 0;
  125. $row.find('[data-day]').each(function () {
  126. const v = Number($(this).val());
  127. if (!Number.isNaN(v)) { sum += v; }
  128. });
  129. const committed = (commitMap || committedPrio1FromDom())[String(swId)] || 0;
  130. const cap = capacity(sum, committed);
  131. $row.find('[data-sum-days]').text(fmtDays(cap.ressourcen));
  132. $root.find('[data-cap-ressourcen][data-sw-id="' + swId + '"]').text(fmtDays(cap.ressourcen));
  133. $root.find('[data-cap-after-reserves][data-sw-id="' + swId + '"]').text(fmtDays(cap.afterReserves));
  134. const $avail = $root.find('[data-cap-available][data-sw-id="' + swId + '"]');
  135. $avail.text(fmtDays(cap.available));
  136. if (cap.available < 0) {
  137. $avail.removeClass('text-slate-900').addClass('text-red-700');
  138. } else {
  139. $avail.removeClass('text-red-700').addClass('text-slate-900');
  140. }
  141. }
  142. // Recompute every worker row (capacity summary) — called when a task-side
  143. // change might affect committed prio-1 values.
  144. function recomputeAllCapacity() {
  145. const commit = committedPrio1FromDom();
  146. $root.find('[data-sw-row]').each(function () {
  147. recomputeRow(parseInt($(this).data('sw-id'), 10), commit);
  148. });
  149. }
  150. // ---------------------------------------------------------------------
  151. // Pending-cell queue, debounced batch save
  152. // ---------------------------------------------------------------------
  153. // key = "swId:weekId" → { sw_id, week_id, days }
  154. const pendingCells = new Map();
  155. let cellDebounce = null;
  156. function queueCell(swId, weekId, days) {
  157. pendingCells.set(swId + ':' + weekId, {
  158. sprint_worker_id: swId,
  159. sprint_week_id: weekId,
  160. days: days,
  161. });
  162. clearTimeout(cellDebounce);
  163. cellDebounce = setTimeout(flushCells, 400);
  164. }
  165. function flushCells() {
  166. if (pendingCells.size === 0) { return; }
  167. const cells = Array.from(pendingCells.values());
  168. pendingCells.clear();
  169. request('PATCH', '/sprints/' + sprintId + '/week-cells', cells)
  170. .then(function (data) {
  171. if (data.applied === 0 && data.noop > 0) {
  172. flash('No changes');
  173. } else {
  174. flash('Saved ' + data.applied + (data.applied === 1 ? ' cell' : ' cells'));
  175. }
  176. // Trust the server's capacity numbers — same formula, but a
  177. // safety net if an input was tampered with.
  178. if (data.per_worker && typeof data.per_worker === 'object') {
  179. Object.keys(data.per_worker).forEach(function (swIdStr) {
  180. const c = data.per_worker[swIdStr];
  181. $root.find('[data-cap-ressourcen][data-sw-id="' + swIdStr + '"]').text(fmtDays(c.ressourcen));
  182. $root.find('[data-cap-after-reserves][data-sw-id="' + swIdStr + '"]').text(fmtDays(c.after_reserves));
  183. const $av = $root.find('[data-cap-available][data-sw-id="' + swIdStr + '"]');
  184. $av.text(fmtDays(c.available));
  185. if (c.available < 0) {
  186. $av.removeClass('text-slate-900').addClass('text-red-700');
  187. } else {
  188. $av.removeClass('text-red-700').addClass('text-slate-900');
  189. }
  190. $root.find('[data-sw-row][data-sw-id="' + swIdStr + '"] [data-sum-days]').text(fmtDays(c.ressourcen));
  191. });
  192. }
  193. })
  194. .catch(function (e) { flash(e.message, true); });
  195. }
  196. // ---------------------------------------------------------------------
  197. // Day cells
  198. // ---------------------------------------------------------------------
  199. $root.on('blur change', '[data-day]', function () {
  200. const $el = $(this);
  201. let v = Number($el.val());
  202. if (Number.isNaN(v)) { v = 0; }
  203. if (v < 0) { v = 0; }
  204. if (v > 5) { v = 5; }
  205. v = snap05(v);
  206. $el.val(fmtDays(v));
  207. const swId = parseInt($el.data('sw-id'), 10);
  208. const weekId = parseInt($el.data('week-id'), 10);
  209. queueCell(swId, weekId, v);
  210. recomputeRow(swId);
  211. });
  212. // ---------------------------------------------------------------------
  213. // Per-row RTB edit
  214. // ---------------------------------------------------------------------
  215. $root.on('blur change', '[data-rtb]', function () {
  216. const $el = $(this);
  217. let v = Number($el.val());
  218. if (Number.isNaN(v)) { v = 0; }
  219. if (v < 0) { v = 0; }
  220. if (v > 1) { v = 1; }
  221. v = snap005(v);
  222. $el.val(fmtRtb(v));
  223. const swId = parseInt($el.data('sw-id'), 10);
  224. request('PATCH', '/sprints/' + sprintId + '/workers/' + swId, { rtb: v })
  225. .then(function () { flash('Saved'); })
  226. .catch(function (e) { flash(e.message, true); });
  227. });
  228. // ---------------------------------------------------------------------
  229. // Worker row drag-reorder (admin only — tbody only exists with handles)
  230. // ---------------------------------------------------------------------
  231. const sortableAvailable = typeof $.fn.sortable === 'function';
  232. if (!sortableAvailable) {
  233. // jQuery UI didn't load (SRI mismatch, offline CDN, ad blocker).
  234. // Drag-reorder is unavailable but the rest of the page still works.
  235. // eslint-disable-next-line no-console
  236. console.warn('[sprint-planner] jQuery UI not loaded — drag reorder disabled.');
  237. }
  238. const $tbody = $root.find('[data-tbody]');
  239. if (sortableAvailable && $tbody.find('.handle').length > 0) {
  240. $tbody.sortable({
  241. handle: '.handle',
  242. items: 'tr[data-sw-row]',
  243. axis: 'y',
  244. helper: function (e, tr) {
  245. // Preserve the td widths so the row doesn't collapse while dragging.
  246. const $cells = tr.children();
  247. const $clone = tr.clone();
  248. $clone.children().each(function (i) { $(this).width($cells.eq(i).width()); });
  249. return $clone;
  250. },
  251. update: function () {
  252. const ordering = $tbody.find('tr[data-sw-row]').map(function (i, el) {
  253. return {
  254. sprint_worker_id: parseInt($(el).data('sw-id'), 10),
  255. sort_order: i + 1,
  256. };
  257. }).get();
  258. request('POST', '/sprints/' + sprintId + '/workers/reorder', ordering)
  259. .then(function (data) {
  260. if (data.moved) {
  261. // Column order in the task list below depends on
  262. // this ordering — simplest to re-render.
  263. window.location.reload();
  264. } else {
  265. flash('No changes');
  266. }
  267. })
  268. .catch(function (e) { flash(e.message, true); });
  269. },
  270. });
  271. }
  272. // =====================================================================
  273. // Task list — create/edit/delete/reorder + assignments + filter/sort
  274. // =====================================================================
  275. const $taskTbody = $root.find('[data-task-tbody]');
  276. const hasTaskUi = $taskTbody.length > 0;
  277. // --- Worker/owner helpers read from the DOM once ----------------------
  278. function sprintWorkerHeaders() {
  279. const out = [];
  280. $root.find('[data-task-table] thead th[data-sort-col^="sw-"]').each(function () {
  281. const col = String($(this).attr('data-sort-col'));
  282. out.push({
  283. id: parseInt(col.slice(3), 10),
  284. name: $(this).clone().children().remove().end().text().trim(),
  285. });
  286. });
  287. return out;
  288. }
  289. // The owner dropdown used to be a plain <select>, but Phase 10 replaced
  290. // it with a checkbox multi-filter. We now scrape the real source of
  291. // truth: the [data-owner-filter-opt] inputs, skipping the special
  292. // "__none__" entry. Empty list → new task rows get an empty dropdown,
  293. // which was the symptom the user hit after Phase 10 landed.
  294. function ownerChoices() {
  295. const out = [];
  296. $root.find('[data-owner-filter-opt]').each(function () {
  297. const v = String($(this).val());
  298. if (v === '' || v === '__none__') { return; }
  299. const id = parseInt(v, 10);
  300. if (!Number.isFinite(id)) { return; }
  301. const name = String($(this).closest('label').find('span').text()).trim();
  302. out.push({ id: id, name: name });
  303. });
  304. return out;
  305. }
  306. // --- Build a task row <tr> from an object ----------------------------
  307. function buildTaskRow(task, assignments) {
  308. assignments = assignments || {};
  309. const $tr = $('<tr>')
  310. .attr('data-task-row', '')
  311. .attr('data-task-id', task.id)
  312. .attr('data-prio', task.priority)
  313. .attr('data-owner', task.owner_worker_id || '')
  314. .attr('data-sort-order', task.sort_order);
  315. // handle
  316. $tr.append($('<td class="px-2 py-1"></td>').append(
  317. $('<span class="handle cursor-grab text-slate-400 select-none">').html('&#8801;')
  318. ));
  319. // title
  320. $tr.append(
  321. $('<td class="px-2 py-1 min-w-[14rem]"></td>').append(
  322. $('<input type="text" data-title class="w-full rounded border border-slate-200 px-2 py-1 focus:outline-none focus:ring-2 focus:ring-slate-400">')
  323. .val(task.title)
  324. )
  325. );
  326. // owner
  327. const $sel = $('<select data-owner-select class="w-full rounded border border-slate-200 px-2 py-1 bg-white focus:outline-none focus:ring-2 focus:ring-slate-400">');
  328. $sel.append('<option value="">—</option>');
  329. ownerChoices().forEach(function (o) {
  330. const $opt = $('<option>').val(o.id).text(o.name);
  331. if (Number(o.id) === Number(task.owner_worker_id)) { $opt.attr('selected', 'selected'); }
  332. $sel.append($opt);
  333. });
  334. $tr.append($('<td class="px-2 py-1" data-col="owner"></td>').append($sel));
  335. // priority
  336. const $prio = $('<select data-prio-select class="rounded border border-slate-200 px-2 py-1 bg-white font-mono focus:outline-none focus:ring-2 focus:ring-slate-400"><option value="1">1</option><option value="2">2</option></select>');
  337. $prio.val(String(task.priority));
  338. $tr.append($('<td class="px-2 py-1 text-center" data-col="prio"></td>').append($prio));
  339. // tot
  340. let tot = 0;
  341. Object.keys(assignments).forEach(function (k) { tot += Number(assignments[k]) || 0; });
  342. $tr.append($('<td class="px-2 py-1 text-center font-mono font-semibold" data-col="tot" data-task-tot>').text(fmtDays(tot)));
  343. // per-worker assignment cells
  344. sprintWorkerHeaders().forEach(function (sw) {
  345. const v = Number(assignments[sw.id] || 0);
  346. const $td = $('<td class="px-1 py-1 text-center"></td>')
  347. .attr('data-col', 'sw-' + sw.id)
  348. .attr('data-sort-value-sw-' + sw.id, v.toFixed(2));
  349. const $input = $('<input type="number" min="0" step="0.5" data-assign class="w-14 rounded border border-slate-200 px-1 py-1 text-center font-mono focus:outline-none focus:ring-2 focus:ring-slate-400">')
  350. .val(fmtDays(v))
  351. .attr('data-sw-id', sw.id);
  352. if (taskStatusEnabled) {
  353. // New tasks always start with the default status.
  354. const $cell = $('<span class="assign-cell assign-status-zugewiesen"></span>')
  355. .attr('data-assign-cell', '')
  356. .attr('data-sw-id', sw.id)
  357. .attr('data-status', 'zugewiesen');
  358. $cell.append($input);
  359. const $status = $('<select data-assign-status aria-label="Status" class="assign-status-select"></select>')
  360. .attr('data-sw-id', sw.id);
  361. STATUSES.forEach(function (s) {
  362. $('<option>').val(s).text(s).appendTo($status);
  363. });
  364. $status.val('zugewiesen');
  365. $cell.append($status);
  366. $td.append($cell);
  367. } else {
  368. $td.append($input);
  369. }
  370. $tr.append($td);
  371. });
  372. // delete
  373. $tr.append(
  374. $('<td class="px-1 py-1 text-right"></td>').append(
  375. $('<button type="button" data-delete-task class="text-sm text-red-600 hover:underline">').text('×')
  376. )
  377. );
  378. return $tr;
  379. }
  380. // --- Add task ---------------------------------------------------------
  381. $root.on('click', '[data-add-task]', function () {
  382. request('POST', '/sprints/' + sprintId + '/tasks', { title: '', priority: 1 })
  383. .then(function (data) {
  384. $root.find('[data-empty-tasks]').remove();
  385. const $row = buildTaskRow(data.task, data.assignments || {});
  386. $taskTbody.append($row);
  387. // Clear any active sort so the new row is actually visible at the end.
  388. clearSort();
  389. applyColumnVisibility();
  390. applyFilters();
  391. $row.find('[data-title]').trigger('focus').trigger('select');
  392. flash('Task added');
  393. })
  394. .catch(function (e) { flash(e.message, true); });
  395. });
  396. // --- Edit task fields (title / owner / prio) --------------------------
  397. const titleDebounce = {};
  398. $root.on('input', '[data-title]', function () {
  399. const $inp = $(this);
  400. const taskId = parseInt($inp.closest('tr').data('task-id'), 10);
  401. clearTimeout(titleDebounce[taskId]);
  402. titleDebounce[taskId] = setTimeout(function () {
  403. const title = String($inp.val()).trim();
  404. if (title === '') {
  405. flash('Title cannot be empty', true);
  406. return;
  407. }
  408. request('PATCH', '/tasks/' + taskId, { title: title })
  409. .then(function () { flash('Saved'); })
  410. .catch(function (e) { flash(e.message, true); });
  411. }, 400);
  412. });
  413. $root.on('change', '[data-owner-select]', function () {
  414. const $sel = $(this);
  415. const $row = $sel.closest('tr');
  416. const taskId = parseInt($row.data('task-id'), 10);
  417. const v = $sel.val();
  418. const owner = v === '' ? null : parseInt(String(v), 10);
  419. $row.attr('data-owner', owner === null ? '' : owner);
  420. request('PATCH', '/tasks/' + taskId, { owner_worker_id: owner })
  421. .then(function () { flash('Saved'); applyFilters(); })
  422. .catch(function (e) { flash(e.message, true); });
  423. });
  424. $root.on('change', '[data-prio-select]', function () {
  425. const $sel = $(this);
  426. const $row = $sel.closest('tr');
  427. const taskId = parseInt($row.data('task-id'), 10);
  428. const prio = parseInt(String($sel.val()), 10);
  429. $row.attr('data-prio', prio);
  430. request('PATCH', '/tasks/' + taskId, { priority: prio })
  431. .then(function (data) {
  432. flash('Saved');
  433. applyFilters();
  434. applyServerCapacity(data && data.per_worker);
  435. recomputeAllCapacity();
  436. })
  437. .catch(function (e) { flash(e.message, true); });
  438. });
  439. // --- Delete task ------------------------------------------------------
  440. $root.on('click', '[data-delete-task]', function () {
  441. const $row = $(this).closest('tr');
  442. const taskId = parseInt($row.data('task-id'), 10);
  443. const title = $row.find('[data-title]').val() || '(untitled)';
  444. if (!window.confirm('Delete task "' + title + '"?')) { return; }
  445. request('DELETE', '/tasks/' + taskId)
  446. .then(function (data) {
  447. $row.remove();
  448. applyServerCapacity(data && data.per_worker);
  449. recomputeAllCapacity();
  450. flash('Task deleted');
  451. if ($taskTbody.children('tr[data-task-row]').length === 0) {
  452. // Re-show the empty-state row (simpler than templating).
  453. window.location.reload();
  454. }
  455. })
  456. .catch(function (e) { flash(e.message, true); });
  457. });
  458. // --- Assignment cells (per task, per sprint worker) -------------------
  459. // Same shape as the Arbeitstage cell queue, but against /tasks/{id}/assignments.
  460. const pendingAssign = new Map(); // taskId -> Map<swId, days>
  461. const assignTimers = {};
  462. function queueAssign(taskId, swId, days) {
  463. if (!pendingAssign.has(taskId)) { pendingAssign.set(taskId, new Map()); }
  464. pendingAssign.get(taskId).set(swId, days);
  465. clearTimeout(assignTimers[taskId]);
  466. assignTimers[taskId] = setTimeout(function () { flushAssign(taskId); }, 400);
  467. }
  468. function flushAssign(taskId) {
  469. const m = pendingAssign.get(taskId);
  470. if (!m || m.size === 0) { return; }
  471. const cells = [];
  472. m.forEach(function (days, swId) {
  473. cells.push({ sprint_worker_id: swId, days: days });
  474. });
  475. pendingAssign.delete(taskId);
  476. request('PATCH', '/tasks/' + taskId + '/assignments', cells)
  477. .then(function (data) {
  478. if (data.applied === 0 && data.noop > 0) { flash('No changes'); }
  479. else { flash('Saved ' + data.applied + (data.applied === 1 ? ' cell' : ' cells')); }
  480. applyServerCapacity(data && data.per_worker);
  481. })
  482. .catch(function (e) { flash(e.message, true); });
  483. }
  484. $root.on('blur change', '[data-assign]', function () {
  485. const $el = $(this);
  486. let v = Number($el.val());
  487. if (Number.isNaN(v) || v < 0) { v = 0; }
  488. v = snap05(v);
  489. $el.val(fmtDays(v));
  490. $el.closest('td').attr('data-sort-value-sw-' + $el.data('sw-id'), v.toFixed(2));
  491. const taskId = parseInt($el.closest('tr').data('task-id'), 10);
  492. const swId = parseInt($el.data('sw-id'), 10);
  493. queueAssign(taskId, swId, v);
  494. // Row total
  495. let tot = 0;
  496. $el.closest('tr').find('[data-assign]').each(function () {
  497. const n = Number($(this).val());
  498. if (!Number.isNaN(n)) { tot += n; }
  499. });
  500. $el.closest('tr').find('[data-task-tot]').text(fmtDays(tot));
  501. // Available recompute (in case this is a prio-1 task)
  502. recomputeAllCapacity();
  503. });
  504. // --- Phase 18: per-cell status save pipeline -------------------------
  505. // Independent of the days pipeline: hits /tasks/{id}/assignments/status
  506. // (signed-in route, gated by app_settings.task_status_enabled). Same
  507. // debounce semantics + same audit weight (one row per changed cell).
  508. const pendingStatus = new Map(); // taskId -> Map<swId, status>
  509. const statusTimers = {};
  510. function queueStatus(taskId, swId, status) {
  511. if (!pendingStatus.has(taskId)) { pendingStatus.set(taskId, new Map()); }
  512. pendingStatus.get(taskId).set(swId, status);
  513. clearTimeout(statusTimers[taskId]);
  514. statusTimers[taskId] = setTimeout(function () { flushStatus(taskId); }, 400);
  515. }
  516. function flushStatus(taskId) {
  517. const m = pendingStatus.get(taskId);
  518. if (!m || m.size === 0) { return; }
  519. const cells = [];
  520. m.forEach(function (status, swId) {
  521. cells.push({ sprint_worker_id: swId, status: status });
  522. });
  523. pendingStatus.delete(taskId);
  524. request('PATCH', '/tasks/' + taskId + '/assignments/status', cells)
  525. .then(function (data) {
  526. if (data.applied === 0 && data.noop > 0) { flash('No changes'); }
  527. else { flash('Saved ' + data.applied + (data.applied === 1 ? ' status' : ' statuses')); }
  528. })
  529. .catch(function (e) { flash(e.message, true); });
  530. }
  531. function applyStatusClass($cell, next) {
  532. // Replace any existing assign-status-* with the new one. Keep the
  533. // class set deterministic (any unknown classes get scrubbed).
  534. STATUSES.forEach(function (s) { $cell.removeClass('assign-status-' + s); });
  535. $cell.addClass('assign-status-' + next);
  536. $cell.attr('data-status', next);
  537. }
  538. $root.on('change', '[data-assign-status]', function () {
  539. const $sel = $(this);
  540. const next = String($sel.val() || '');
  541. if (STATUSES.indexOf(next) === -1) { return; }
  542. const $cell = $sel.closest('[data-assign-cell]');
  543. applyStatusClass($cell, next);
  544. const taskId = parseInt($sel.closest('tr').data('task-id'), 10);
  545. const swId = parseInt($sel.data('sw-id'), 10);
  546. queueStatus(taskId, swId, next);
  547. // Re-evaluate the status filter immediately so the row hides /
  548. // shows without waiting for the server round-trip.
  549. applyFilters();
  550. });
  551. function applyServerCapacity(perWorker) {
  552. if (!perWorker || typeof perWorker !== 'object') { return; }
  553. Object.keys(perWorker).forEach(function (swIdStr) {
  554. const c = perWorker[swIdStr];
  555. $root.find('[data-cap-ressourcen][data-sw-id="' + swIdStr + '"]').text(fmtDays(c.ressourcen));
  556. $root.find('[data-cap-after-reserves][data-sw-id="' + swIdStr + '"]').text(fmtDays(c.after_reserves));
  557. const $av = $root.find('[data-cap-available][data-sw-id="' + swIdStr + '"]');
  558. $av.text(fmtDays(c.available));
  559. if (c.available < 0) {
  560. $av.removeClass('text-slate-900').addClass('text-red-700');
  561. } else {
  562. $av.removeClass('text-red-700').addClass('text-slate-900');
  563. }
  564. });
  565. }
  566. // --- Task reorder (drag) ----------------------------------------------
  567. if (sortableAvailable && hasTaskUi && $taskTbody.find('.handle').length > 0) {
  568. $taskTbody.sortable({
  569. handle: '.handle',
  570. items: 'tr[data-task-row]',
  571. axis: 'y',
  572. helper: function (e, tr) {
  573. const $cells = tr.children();
  574. const $clone = tr.clone();
  575. $clone.children().each(function (i) { $(this).width($cells.eq(i).width()); });
  576. return $clone;
  577. },
  578. start: function () {
  579. // Drag only makes sense when no sort is active.
  580. if (currentSort.col !== null) { clearSort(); }
  581. },
  582. update: function () {
  583. const ordering = $taskTbody.find('tr[data-task-row]').map(function (i, el) {
  584. return { task_id: parseInt($(el).data('task-id'), 10), sort_order: i + 1 };
  585. }).get();
  586. request('POST', '/sprints/' + sprintId + '/tasks/reorder', ordering)
  587. .then(function (data) {
  588. ordering.forEach(function (o) {
  589. $taskTbody.find('tr[data-task-id="' + o.task_id + '"]').attr('data-sort-order', o.sort_order);
  590. });
  591. flash(data.moved ? 'Order saved' : 'No changes');
  592. })
  593. .catch(function (e) { flash(e.message, true); });
  594. },
  595. });
  596. }
  597. // --- Multi-select owner filter (persisted in localStorage) -------------
  598. const ownerFilterKey = 'sp:' + sprintId + ':ownerFilter' + keySuffix;
  599. /** @type {Set<string>} */
  600. const ownerFilterSet = (function () {
  601. try {
  602. const raw = window.localStorage.getItem(ownerFilterKey);
  603. if (raw) {
  604. const arr = JSON.parse(raw);
  605. if (Array.isArray(arr)) { return new Set(arr.map(String)); }
  606. }
  607. } catch (_) { /* ignore */ }
  608. return new Set();
  609. })();
  610. function persistOwnerFilter() {
  611. try {
  612. window.localStorage.setItem(ownerFilterKey, JSON.stringify(Array.from(ownerFilterSet)));
  613. } catch (_) { /* ignore quota / private mode */ }
  614. }
  615. function updateOwnerFilterUi() {
  616. // Reflect state back into the checkboxes.
  617. $root.find('[data-owner-filter-opt]').each(function () {
  618. $(this).prop('checked', ownerFilterSet.has(String($(this).val())));
  619. });
  620. // Count label on the trigger.
  621. const n = ownerFilterSet.size;
  622. $root.find('[data-owner-filter-count]').text(n === 0 ? '' : '(' + n + ')');
  623. }
  624. $root.on('change', '[data-owner-filter-opt]', function () {
  625. const v = String($(this).val());
  626. if ($(this).is(':checked')) { ownerFilterSet.add(v); } else { ownerFilterSet.delete(v); }
  627. persistOwnerFilter();
  628. updateOwnerFilterUi();
  629. applyFilters();
  630. });
  631. $root.on('click', '[data-owner-filter-clear]', function () {
  632. ownerFilterSet.clear();
  633. persistOwnerFilter();
  634. updateOwnerFilterUi();
  635. applyFilters();
  636. });
  637. $root.on('click', '[data-owner-filter-trigger]', function (ev) {
  638. ev.stopPropagation();
  639. $root.find('[data-columns-dropdown]').addClass('hidden');
  640. $root.find('[data-owner-filter-dropdown]').toggleClass('hidden');
  641. });
  642. // --- Focus filter (single sprint worker, persisted) -------------------
  643. const focusKey = 'sp:' + sprintId + ':focusWorker' + keySuffix;
  644. let focusWorker = (function () {
  645. try {
  646. const raw = window.localStorage.getItem(focusKey);
  647. if (raw === null) { return ''; }
  648. return String(raw);
  649. } catch (_) { return ''; }
  650. })();
  651. function persistFocus() {
  652. try { window.localStorage.setItem(focusKey, String(focusWorker)); }
  653. catch (_) { /* ignore */ }
  654. }
  655. function updateFocusUi() {
  656. const $sel = $root.find('[data-focus-select]');
  657. if ($sel.length === 0) { return; }
  658. // If the stored worker is no longer a sprint member, fall back to "".
  659. if (focusWorker !== '' && $sel.find('option[value="' + focusWorker + '"]').length === 0) {
  660. focusWorker = '';
  661. persistFocus();
  662. }
  663. $sel.val(focusWorker);
  664. }
  665. // --- Phase 18: status filter (multi-select, persisted) ----------------
  666. const statusFilterKey = 'sp:' + sprintId + ':statusFilter' + keySuffix;
  667. /** @type {Set<string>} */
  668. const statusFilterSet = (function () {
  669. if (!taskStatusEnabled) { return new Set(); }
  670. try {
  671. const raw = window.localStorage.getItem(statusFilterKey);
  672. if (raw) {
  673. const arr = JSON.parse(raw);
  674. if (Array.isArray(arr)) { return new Set(arr.map(String)); }
  675. }
  676. } catch (_) { /* ignore */ }
  677. return new Set();
  678. })();
  679. function persistStatusFilter() {
  680. try {
  681. window.localStorage.setItem(statusFilterKey, JSON.stringify(Array.from(statusFilterSet)));
  682. } catch (_) { /* ignore quota / private mode */ }
  683. }
  684. function updateStatusFilterUi() {
  685. $root.find('[data-status-filter-opt]').each(function () {
  686. $(this).prop('checked', statusFilterSet.has(String($(this).val())));
  687. });
  688. const n = statusFilterSet.size;
  689. $root.find('[data-status-filter-count]').text(n === 0 ? '' : '(' + n + ')');
  690. }
  691. $root.on('change', '[data-status-filter-opt]', function () {
  692. const v = String($(this).val());
  693. if (STATUSES.indexOf(v) === -1) { return; }
  694. if ($(this).is(':checked')) { statusFilterSet.add(v); } else { statusFilterSet.delete(v); }
  695. persistStatusFilter();
  696. updateStatusFilterUi();
  697. applyFilters();
  698. });
  699. $root.on('click', '[data-status-filter-clear]', function () {
  700. statusFilterSet.clear();
  701. persistStatusFilter();
  702. updateStatusFilterUi();
  703. applyFilters();
  704. });
  705. $root.on('click', '[data-status-filter-trigger]', function (ev) {
  706. ev.stopPropagation();
  707. $root.find('[data-owner-filter-dropdown]').addClass('hidden');
  708. $root.find('[data-columns-dropdown]').addClass('hidden');
  709. $root.find('[data-status-filter-dropdown]').toggleClass('hidden');
  710. });
  711. // Predicate: row passes if at least one of its cells is in the picked
  712. // status set. The default 'zugewiesen' state matches only when there's
  713. // actual work assigned (days > 0) so picking it doesn't match every
  714. // task; the explicit states (gestartet/abgeschlossen/abgebrochen) match
  715. // regardless of days because a user only sets them deliberately.
  716. function rowMatchesStatusFilter($row) {
  717. if (statusFilterSet.size === 0) { return true; }
  718. let matched = false;
  719. $row.find('[data-assign-cell]').each(function () {
  720. const $cell = $(this);
  721. const status = String($cell.attr('data-status') || 'zugewiesen');
  722. if (!statusFilterSet.has(status)) { return; }
  723. if (status === 'zugewiesen') {
  724. const $inp = $cell.find('[data-assign]');
  725. const days = $inp.length
  726. ? (Number($inp.val()) || 0)
  727. : (Number($cell.find('.font-mono').text()) || 0);
  728. if (days > 0) { matched = true; return false; }
  729. return;
  730. }
  731. matched = true;
  732. return false;
  733. });
  734. return matched;
  735. }
  736. // --- Filters (search / prio / owner / focus / status) ----------------
  737. function applyFilters() {
  738. const q = String($root.find('[data-task-search]').val() || '').trim().toLowerCase();
  739. const prio = String($root.find('[data-prio-filter]').val() || '');
  740. const focus = String(focusWorker || '');
  741. let visibleCount = 0;
  742. $taskTbody.children('tr[data-task-row]').each(function () {
  743. const $row = $(this);
  744. const title = String($row.find('[data-title]').val() || $row.find('[data-title]').text() || '').toLowerCase();
  745. const rowPrio = String($row.attr('data-prio'));
  746. const rowOwner = String($row.attr('data-owner') || '');
  747. // The filter set treats "" (no owner) as the special "__none__" key.
  748. const ownerKey = rowOwner === '' ? '__none__' : rowOwner;
  749. let ok = true;
  750. if (q !== '' && !title.includes(q)) { ok = false; }
  751. if (prio !== '' && rowPrio !== prio) { ok = false; }
  752. if (ownerFilterSet.size > 0 && !ownerFilterSet.has(ownerKey)) { ok = false; }
  753. if (focus !== '') {
  754. // Zero-tolerance matches capacity math: treat 0 / 0.0 / empty
  755. // as "no assignment" (Number(v) > 0, not !== 0).
  756. const v = Number($row.find('[data-assign][data-sw-id="' + focus + '"]').val());
  757. if (!(v > 0)) { ok = false; }
  758. }
  759. if (ok && taskStatusEnabled && !rowMatchesStatusFilter($row)) { ok = false; }
  760. $row.toggle(ok);
  761. if (ok) { visibleCount++; }
  762. });
  763. const totalRows = $taskTbody.children('tr[data-task-row]').length;
  764. $root.find('[data-task-empty-filter]').toggle(totalRows > 0 && visibleCount === 0);
  765. applyFocusColumnVisibility();
  766. updateResetVisibility();
  767. }
  768. // Column auto-hide: when a focus worker is selected, any sw column that
  769. // is all-zero for the currently visible rows collapses. We tag cells
  770. // with `.focus-auto-hidden` rather than mutating `hiddenCols` so that
  771. // clearing Focus restores whatever the user picked in the Columns
  772. // dropdown.
  773. function applyFocusColumnVisibility() {
  774. // Always clear the transient class first — keeps the function
  775. // idempotent and correct when focus goes from set → "".
  776. $root.find('.focus-auto-hidden').removeClass('focus-auto-hidden');
  777. if (!focusWorker) { return; }
  778. // Walk every sw column. If no currently visible row has a > 0
  779. // assignment for that sw, hide every `[data-col="sw-{id}"]` cell.
  780. $root.find('[data-task-table] thead th[data-sort-col^="sw-"]').each(function () {
  781. const col = String($(this).attr('data-sort-col')); // e.g. "sw-42"
  782. const swId = col.slice(3);
  783. let anyNonZero = false;
  784. $taskTbody.children('tr[data-task-row]:visible').each(function () {
  785. const v = Number($(this).find('[data-assign][data-sw-id="' + swId + '"]').val());
  786. if (v > 0) { anyNonZero = true; return false; /* break */ }
  787. });
  788. if (!anyNonZero) {
  789. $root.find('[data-col="' + col + '"]').addClass('focus-auto-hidden');
  790. }
  791. });
  792. }
  793. let searchDebounce = null;
  794. $root.on('input', '[data-task-search]', function () {
  795. clearTimeout(searchDebounce);
  796. searchDebounce = setTimeout(applyFilters, 120);
  797. });
  798. $root.on('change', '[data-prio-filter]', applyFilters);
  799. $root.on('change', '[data-focus-select]', function () {
  800. focusWorker = String($(this).val() || '');
  801. persistFocus();
  802. applyFilters();
  803. });
  804. // --- Column visibility toggle (persisted in localStorage) --------------
  805. const columnsKey = 'sp:' + sprintId + ':hiddenCols' + keySuffix;
  806. /** @type {Set<string>} */
  807. const hiddenCols = (function () {
  808. try {
  809. const raw = window.localStorage.getItem(columnsKey);
  810. if (raw) {
  811. const arr = JSON.parse(raw);
  812. if (Array.isArray(arr)) { return new Set(arr.map(String)); }
  813. }
  814. // Phase 15: first-time-ever in beamer mode seeds the hidden set
  815. // with the non-discussion columns so the task table fits the
  816. // viewport at 1920×1080. User toggles from the Columns dropdown
  817. // persist from then on — we only seed when the key is missing.
  818. if (isBeamer) {
  819. const defaults = ['owner', 'prio', 'tot'];
  820. window.localStorage.setItem(columnsKey, JSON.stringify(defaults));
  821. return new Set(defaults);
  822. }
  823. } catch (_) { /* ignore */ }
  824. return new Set();
  825. })();
  826. function persistHiddenCols() {
  827. try {
  828. window.localStorage.setItem(columnsKey, JSON.stringify(Array.from(hiddenCols)));
  829. } catch (_) { /* ignore */ }
  830. }
  831. function applyColumnVisibility() {
  832. // Tailwind's .hidden is display:none; works on table cells.
  833. $root.find('[data-col]').each(function () {
  834. const col = String($(this).attr('data-col'));
  835. $(this).toggleClass('hidden', hiddenCols.has(col));
  836. });
  837. // Reflect state into the Columns dropdown checkboxes.
  838. $root.find('[data-column-opt]').each(function () {
  839. $(this).prop('checked', !hiddenCols.has(String($(this).val())));
  840. });
  841. }
  842. $root.on('change', '[data-column-opt]', function () {
  843. const v = String($(this).val());
  844. if ($(this).is(':checked')) { hiddenCols.delete(v); } else { hiddenCols.add(v); }
  845. persistHiddenCols();
  846. applyColumnVisibility();
  847. updateResetVisibility();
  848. });
  849. // --- Reset button (clears every filter + column-hide in one click) ----
  850. function filtersActive() {
  851. const q = String($root.find('[data-task-search]').val() || '').trim();
  852. const prio = String($root.find('[data-prio-filter]').val() || '');
  853. return q !== ''
  854. || prio !== ''
  855. || ownerFilterSet.size > 0
  856. || String(focusWorker || '') !== ''
  857. || hiddenCols.size > 0
  858. || (taskStatusEnabled && statusFilterSet.size > 0);
  859. }
  860. function updateResetVisibility() {
  861. $root.find('[data-reset-filters]').toggleClass('hidden', !filtersActive());
  862. }
  863. $root.on('click', '[data-reset-filters]', function () {
  864. $root.find('[data-task-search]').val('');
  865. $root.find('[data-prio-filter]').val('');
  866. ownerFilterSet.clear();
  867. persistOwnerFilter();
  868. focusWorker = '';
  869. persistFocus();
  870. hiddenCols.clear();
  871. persistHiddenCols();
  872. if (taskStatusEnabled) {
  873. statusFilterSet.clear();
  874. persistStatusFilter();
  875. }
  876. updateOwnerFilterUi();
  877. updateFocusUi();
  878. if (taskStatusEnabled) { updateStatusFilterUi(); }
  879. applyColumnVisibility();
  880. applyFilters();
  881. });
  882. $root.on('click', '[data-columns-trigger]', function (ev) {
  883. ev.stopPropagation();
  884. $root.find('[data-owner-filter-dropdown]').addClass('hidden');
  885. $root.find('[data-columns-dropdown]').toggleClass('hidden');
  886. });
  887. // Close either dropdown when clicking outside.
  888. $(document).on('click', function (ev) {
  889. if ($(ev.target).closest('[data-owner-filter-root]').length === 0) {
  890. $root.find('[data-owner-filter-dropdown]').addClass('hidden');
  891. }
  892. if ($(ev.target).closest('[data-columns-root]').length === 0) {
  893. $root.find('[data-columns-dropdown]').addClass('hidden');
  894. }
  895. if ($(ev.target).closest('[data-status-filter-root]').length === 0) {
  896. $root.find('[data-status-filter-dropdown]').addClass('hidden');
  897. }
  898. });
  899. // --- Column sort (client-side) ----------------------------------------
  900. const currentSort = { col: null, dir: null }; // dir: 'asc' | 'desc'
  901. function clearSort() {
  902. currentSort.col = null; currentSort.dir = null;
  903. $root.find('[data-sort-col]').each(function () {
  904. $(this).find('.sort-ind').text('↕').addClass('opacity-30').removeClass('opacity-100');
  905. });
  906. // Restore original order by data-sort-order
  907. const rows = $taskTbody.children('tr[data-task-row]').get();
  908. rows.sort(function (a, b) {
  909. return Number($(a).attr('data-sort-order')) - Number($(b).attr('data-sort-order'));
  910. });
  911. rows.forEach(function (el) { $taskTbody.append(el); });
  912. }
  913. function rowValueFor(col, $row) {
  914. if (col === 'title') {
  915. return String($row.find('[data-title]').val() || $row.find('[data-title]').text() || '').toLowerCase();
  916. }
  917. if (col === 'owner') {
  918. const id = String($row.attr('data-owner') || '');
  919. if (id === '') { return '\uFFFF'; } // sort empty last
  920. const opt = $row.find('[data-owner-select] option:selected');
  921. return String(opt.text() || '').toLowerCase();
  922. }
  923. if (col === 'prio') { return Number($row.attr('data-prio')); }
  924. if (col === 'tot') { return Number($row.find('[data-task-tot]').text()) || 0; }
  925. if (col.indexOf('sw-') === 0) {
  926. const swId = col.slice(3);
  927. return Number($row.find('[data-assign][data-sw-id="' + swId + '"]').val()) || 0;
  928. }
  929. return 0;
  930. }
  931. function applySort(col) {
  932. let dir;
  933. if (currentSort.col !== col) { dir = 'asc'; }
  934. else if (currentSort.dir === 'asc') { dir = 'desc'; }
  935. else { clearSort(); return; } // third click clears
  936. currentSort.col = col;
  937. currentSort.dir = dir;
  938. $root.find('[data-sort-col] .sort-ind').text('↕').addClass('opacity-30').removeClass('opacity-100');
  939. $root.find('[data-sort-col="' + col + '"] .sort-ind')
  940. .text(dir === 'asc' ? '↑' : '↓')
  941. .removeClass('opacity-30').addClass('opacity-100');
  942. const rows = $taskTbody.children('tr[data-task-row]').get();
  943. rows.sort(function (a, b) {
  944. const va = rowValueFor(col, $(a));
  945. const vb = rowValueFor(col, $(b));
  946. if (va < vb) { return dir === 'asc' ? -1 : 1; }
  947. if (va > vb) { return dir === 'asc' ? 1 : -1; }
  948. // Stable-ish tiebreak: fall back to data-sort-order
  949. return Number($(a).attr('data-sort-order')) - Number($(b).attr('data-sort-order'));
  950. });
  951. rows.forEach(function (el) { $taskTbody.append(el); });
  952. }
  953. $root.on('click', '[data-sort-col]', function () {
  954. applySort(String($(this).attr('data-sort-col')));
  955. });
  956. // =====================================================================
  957. // Boot
  958. // =====================================================================
  959. // Recompute once at boot in case the server-rendered sums drift from the
  960. // JS formula (e.g. after a stale reload).
  961. $root.find('[data-sw-row]').each(function () {
  962. recomputeRow(parseInt($(this).data('sw-id'), 10));
  963. });
  964. // Restore persisted task-list UI state BEFORE applyFilters so hidden
  965. // columns don't briefly flash in before being toggled off.
  966. updateOwnerFilterUi();
  967. updateFocusUi();
  968. if (taskStatusEnabled) { updateStatusFilterUi(); }
  969. applyColumnVisibility();
  970. applyFilters();
  971. // Reset button visibility is a function of every filter; applyFilters
  972. // already calls updateResetVisibility, but call it once more at boot
  973. // in case the tbody is empty (applyFilters short-circuits nothing,
  974. // but this is defensive).
  975. updateResetVisibility();
  976. // Phase 15: in beamer mode, if the rendered task table is wider than
  977. // its scroll container, rotate worker-column headers to vertical.
  978. // Measure once after the first applyFilters() run (inputs laid out,
  979. // hidden columns collapsed) and escalate a single step — horizontal
  980. // scroll is a fallback but never a spinlock.
  981. if (isBeamer && hasTaskUi) {
  982. const table = $root.find('[data-task-table]').get(0);
  983. const container = table ? table.parentElement : null;
  984. if (table && container && table.scrollWidth > container.clientWidth) {
  985. $root.addClass('beamer-vertical-headers');
  986. if (table.scrollWidth > container.clientWidth) {
  987. // eslint-disable-next-line no-console
  988. console.warn('[sprint-planner] beamer: table still overflows after vertical headers; horizontal scroll enabled.');
  989. }
  990. }
  991. }
  992. })(jQuery);