sprint-planner.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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. // Phase 18: when the feature is enabled the status attrs +
  350. // colour class go directly on the <td>. New rows always start
  351. // at the default status (no nested wrapper).
  352. if (taskStatusEnabled) {
  353. $td.addClass('assign-status-zugewiesen')
  354. .attr('data-assign-cell', '')
  355. .attr('data-status', 'zugewiesen')
  356. .attr('data-sw-id', sw.id);
  357. }
  358. $td.append(
  359. $('<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">')
  360. .val(fmtDays(v))
  361. .attr('data-sw-id', sw.id)
  362. );
  363. if (taskStatusEnabled) {
  364. const $status = $('<select data-assign-status aria-label="Status" class="assign-status-select"></select>')
  365. .attr('data-sw-id', sw.id);
  366. STATUSES.forEach(function (s) {
  367. $('<option>').val(s).text(s).appendTo($status);
  368. });
  369. $status.val('zugewiesen');
  370. $td.append($status);
  371. }
  372. $tr.append($td);
  373. });
  374. // delete
  375. $tr.append(
  376. $('<td class="px-1 py-1 text-right"></td>').append(
  377. $('<button type="button" data-delete-task class="text-sm text-red-600 hover:underline">').text('×')
  378. )
  379. );
  380. return $tr;
  381. }
  382. // --- Add task ---------------------------------------------------------
  383. $root.on('click', '[data-add-task]', function () {
  384. request('POST', '/sprints/' + sprintId + '/tasks', { title: '', priority: 1 })
  385. .then(function (data) {
  386. $root.find('[data-empty-tasks]').remove();
  387. const $row = buildTaskRow(data.task, data.assignments || {});
  388. $taskTbody.append($row);
  389. // Clear any active sort so the new row is actually visible at the end.
  390. clearSort();
  391. applyColumnVisibility();
  392. applyFilters();
  393. $row.find('[data-title]').trigger('focus').trigger('select');
  394. flash('Task added');
  395. })
  396. .catch(function (e) { flash(e.message, true); });
  397. });
  398. // --- Edit task fields (title / owner / prio) --------------------------
  399. const titleDebounce = {};
  400. $root.on('input', '[data-title]', function () {
  401. const $inp = $(this);
  402. const taskId = parseInt($inp.closest('tr').data('task-id'), 10);
  403. clearTimeout(titleDebounce[taskId]);
  404. titleDebounce[taskId] = setTimeout(function () {
  405. const title = String($inp.val()).trim();
  406. if (title === '') {
  407. flash('Title cannot be empty', true);
  408. return;
  409. }
  410. request('PATCH', '/tasks/' + taskId, { title: title })
  411. .then(function () { flash('Saved'); })
  412. .catch(function (e) { flash(e.message, true); });
  413. }, 400);
  414. });
  415. $root.on('change', '[data-owner-select]', function () {
  416. const $sel = $(this);
  417. const $row = $sel.closest('tr');
  418. const taskId = parseInt($row.data('task-id'), 10);
  419. const v = $sel.val();
  420. const owner = v === '' ? null : parseInt(String(v), 10);
  421. $row.attr('data-owner', owner === null ? '' : owner);
  422. request('PATCH', '/tasks/' + taskId, { owner_worker_id: owner })
  423. .then(function () { flash('Saved'); applyFilters(); })
  424. .catch(function (e) { flash(e.message, true); });
  425. });
  426. $root.on('change', '[data-prio-select]', function () {
  427. const $sel = $(this);
  428. const $row = $sel.closest('tr');
  429. const taskId = parseInt($row.data('task-id'), 10);
  430. const prio = parseInt(String($sel.val()), 10);
  431. $row.attr('data-prio', prio);
  432. request('PATCH', '/tasks/' + taskId, { priority: prio })
  433. .then(function (data) {
  434. flash('Saved');
  435. applyFilters();
  436. applyServerCapacity(data && data.per_worker);
  437. recomputeAllCapacity();
  438. })
  439. .catch(function (e) { flash(e.message, true); });
  440. });
  441. // --- Delete task ------------------------------------------------------
  442. $root.on('click', '[data-delete-task]', function () {
  443. const $row = $(this).closest('tr');
  444. const taskId = parseInt($row.data('task-id'), 10);
  445. const title = $row.find('[data-title]').val() || '(untitled)';
  446. if (!window.confirm('Delete task "' + title + '"?')) { return; }
  447. request('DELETE', '/tasks/' + taskId)
  448. .then(function (data) {
  449. $row.remove();
  450. applyServerCapacity(data && data.per_worker);
  451. recomputeAllCapacity();
  452. flash('Task deleted');
  453. if ($taskTbody.children('tr[data-task-row]').length === 0) {
  454. // Re-show the empty-state row (simpler than templating).
  455. window.location.reload();
  456. }
  457. })
  458. .catch(function (e) { flash(e.message, true); });
  459. });
  460. // --- Assignment cells (per task, per sprint worker) -------------------
  461. // Same shape as the Arbeitstage cell queue, but against /tasks/{id}/assignments.
  462. const pendingAssign = new Map(); // taskId -> Map<swId, days>
  463. const assignTimers = {};
  464. function queueAssign(taskId, swId, days) {
  465. if (!pendingAssign.has(taskId)) { pendingAssign.set(taskId, new Map()); }
  466. pendingAssign.get(taskId).set(swId, days);
  467. clearTimeout(assignTimers[taskId]);
  468. assignTimers[taskId] = setTimeout(function () { flushAssign(taskId); }, 400);
  469. }
  470. function flushAssign(taskId) {
  471. const m = pendingAssign.get(taskId);
  472. if (!m || m.size === 0) { return; }
  473. const cells = [];
  474. m.forEach(function (days, swId) {
  475. cells.push({ sprint_worker_id: swId, days: days });
  476. });
  477. pendingAssign.delete(taskId);
  478. request('PATCH', '/tasks/' + taskId + '/assignments', cells)
  479. .then(function (data) {
  480. if (data.applied === 0 && data.noop > 0) { flash('No changes'); }
  481. else { flash('Saved ' + data.applied + (data.applied === 1 ? ' cell' : ' cells')); }
  482. applyServerCapacity(data && data.per_worker);
  483. })
  484. .catch(function (e) { flash(e.message, true); });
  485. }
  486. $root.on('blur change', '[data-assign]', function () {
  487. const $el = $(this);
  488. let v = Number($el.val());
  489. if (Number.isNaN(v) || v < 0) { v = 0; }
  490. v = snap05(v);
  491. $el.val(fmtDays(v));
  492. $el.closest('td').attr('data-sort-value-sw-' + $el.data('sw-id'), v.toFixed(2));
  493. const taskId = parseInt($el.closest('tr').data('task-id'), 10);
  494. const swId = parseInt($el.data('sw-id'), 10);
  495. queueAssign(taskId, swId, v);
  496. // Row total
  497. let tot = 0;
  498. $el.closest('tr').find('[data-assign]').each(function () {
  499. const n = Number($(this).val());
  500. if (!Number.isNaN(n)) { tot += n; }
  501. });
  502. $el.closest('tr').find('[data-task-tot]').text(fmtDays(tot));
  503. // Available recompute (in case this is a prio-1 task)
  504. recomputeAllCapacity();
  505. });
  506. // --- Phase 18: per-cell status save pipeline -------------------------
  507. // Independent of the days pipeline: hits /tasks/{id}/assignments/status
  508. // (signed-in route, gated by app_settings.task_status_enabled). Same
  509. // debounce + audit semantics as the days pipeline (one row per changed
  510. // cell). Skipped entirely when the feature flag is off.
  511. const pendingStatus = new Map(); // taskId -> Map<swId, status>
  512. const statusTimers = {};
  513. function queueStatus(taskId, swId, status) {
  514. if (!pendingStatus.has(taskId)) { pendingStatus.set(taskId, new Map()); }
  515. pendingStatus.get(taskId).set(swId, status);
  516. clearTimeout(statusTimers[taskId]);
  517. statusTimers[taskId] = setTimeout(function () { flushStatus(taskId); }, 400);
  518. }
  519. function flushStatus(taskId) {
  520. const m = pendingStatus.get(taskId);
  521. if (!m || m.size === 0) { return; }
  522. const cells = [];
  523. m.forEach(function (status, swId) {
  524. cells.push({ sprint_worker_id: swId, status: status });
  525. });
  526. pendingStatus.delete(taskId);
  527. request('PATCH', '/tasks/' + taskId + '/assignments/status', cells)
  528. .then(function (data) {
  529. if (data.applied === 0 && data.noop > 0) { flash('No changes'); }
  530. else { flash('Saved ' + data.applied + (data.applied === 1 ? ' status' : ' statuses')); }
  531. })
  532. .catch(function (e) { flash(e.message, true); });
  533. }
  534. // Status change handler — only attach when the feature is on, and bail
  535. // defensively if the cell doesn't carry the data attributes we expect
  536. // (e.g. on a partially-rendered task row right after `+ Add task`).
  537. if (taskStatusEnabled) {
  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. if ($cell.length === 0) { return; }
  544. const $tr = $sel.closest('tr');
  545. const taskId = parseInt($tr.attr('data-task-id'), 10);
  546. const swId = parseInt($sel.attr('data-sw-id'), 10);
  547. if (!Number.isFinite(taskId) || !Number.isFinite(swId)) { return; }
  548. // Swap the cell's colour class + data-status. Done first so the
  549. // visual flip is instant; the server save is debounced.
  550. STATUSES.forEach(function (s) { $cell.removeClass('assign-status-' + s); });
  551. $cell.addClass('assign-status-' + next);
  552. $cell.attr('data-status', next);
  553. queueStatus(taskId, swId, next);
  554. applyFilters();
  555. });
  556. }
  557. function applyServerCapacity(perWorker) {
  558. if (!perWorker || typeof perWorker !== 'object') { return; }
  559. Object.keys(perWorker).forEach(function (swIdStr) {
  560. const c = perWorker[swIdStr];
  561. $root.find('[data-cap-ressourcen][data-sw-id="' + swIdStr + '"]').text(fmtDays(c.ressourcen));
  562. $root.find('[data-cap-after-reserves][data-sw-id="' + swIdStr + '"]').text(fmtDays(c.after_reserves));
  563. const $av = $root.find('[data-cap-available][data-sw-id="' + swIdStr + '"]');
  564. $av.text(fmtDays(c.available));
  565. if (c.available < 0) {
  566. $av.removeClass('text-slate-900').addClass('text-red-700');
  567. } else {
  568. $av.removeClass('text-red-700').addClass('text-slate-900');
  569. }
  570. });
  571. }
  572. // --- Task reorder (drag) ----------------------------------------------
  573. if (sortableAvailable && hasTaskUi && $taskTbody.find('.handle').length > 0) {
  574. $taskTbody.sortable({
  575. handle: '.handle',
  576. items: 'tr[data-task-row]',
  577. axis: 'y',
  578. helper: function (e, tr) {
  579. const $cells = tr.children();
  580. const $clone = tr.clone();
  581. $clone.children().each(function (i) { $(this).width($cells.eq(i).width()); });
  582. return $clone;
  583. },
  584. start: function () {
  585. // Drag only makes sense when no sort is active.
  586. if (currentSort.col !== null) { clearSort(); }
  587. },
  588. update: function () {
  589. const ordering = $taskTbody.find('tr[data-task-row]').map(function (i, el) {
  590. return { task_id: parseInt($(el).data('task-id'), 10), sort_order: i + 1 };
  591. }).get();
  592. request('POST', '/sprints/' + sprintId + '/tasks/reorder', ordering)
  593. .then(function (data) {
  594. ordering.forEach(function (o) {
  595. $taskTbody.find('tr[data-task-id="' + o.task_id + '"]').attr('data-sort-order', o.sort_order);
  596. });
  597. flash(data.moved ? 'Order saved' : 'No changes');
  598. })
  599. .catch(function (e) { flash(e.message, true); });
  600. },
  601. });
  602. }
  603. // --- Multi-select owner filter (persisted in localStorage) -------------
  604. const ownerFilterKey = 'sp:' + sprintId + ':ownerFilter' + keySuffix;
  605. /** @type {Set<string>} */
  606. const ownerFilterSet = (function () {
  607. try {
  608. const raw = window.localStorage.getItem(ownerFilterKey);
  609. if (raw) {
  610. const arr = JSON.parse(raw);
  611. if (Array.isArray(arr)) { return new Set(arr.map(String)); }
  612. }
  613. } catch (_) { /* ignore */ }
  614. return new Set();
  615. })();
  616. function persistOwnerFilter() {
  617. try {
  618. window.localStorage.setItem(ownerFilterKey, JSON.stringify(Array.from(ownerFilterSet)));
  619. } catch (_) { /* ignore quota / private mode */ }
  620. }
  621. function updateOwnerFilterUi() {
  622. // Reflect state back into the checkboxes.
  623. $root.find('[data-owner-filter-opt]').each(function () {
  624. $(this).prop('checked', ownerFilterSet.has(String($(this).val())));
  625. });
  626. // Count label on the trigger.
  627. const n = ownerFilterSet.size;
  628. $root.find('[data-owner-filter-count]').text(n === 0 ? '' : '(' + n + ')');
  629. }
  630. $root.on('change', '[data-owner-filter-opt]', function () {
  631. const v = String($(this).val());
  632. if ($(this).is(':checked')) { ownerFilterSet.add(v); } else { ownerFilterSet.delete(v); }
  633. persistOwnerFilter();
  634. updateOwnerFilterUi();
  635. applyFilters();
  636. });
  637. $root.on('click', '[data-owner-filter-clear]', function () {
  638. ownerFilterSet.clear();
  639. persistOwnerFilter();
  640. updateOwnerFilterUi();
  641. applyFilters();
  642. });
  643. $root.on('click', '[data-owner-filter-trigger]', function (ev) {
  644. ev.stopPropagation();
  645. $root.find('[data-columns-dropdown]').addClass('hidden');
  646. $root.find('[data-owner-filter-dropdown]').toggleClass('hidden');
  647. });
  648. // --- Focus filter (single sprint worker, persisted) -------------------
  649. const focusKey = 'sp:' + sprintId + ':focusWorker' + keySuffix;
  650. let focusWorker = (function () {
  651. try {
  652. const raw = window.localStorage.getItem(focusKey);
  653. if (raw === null) { return ''; }
  654. return String(raw);
  655. } catch (_) { return ''; }
  656. })();
  657. function persistFocus() {
  658. try { window.localStorage.setItem(focusKey, String(focusWorker)); }
  659. catch (_) { /* ignore */ }
  660. }
  661. function updateFocusUi() {
  662. const $sel = $root.find('[data-focus-select]');
  663. if ($sel.length === 0) { return; }
  664. // If the stored worker is no longer a sprint member, fall back to "".
  665. if (focusWorker !== '' && $sel.find('option[value="' + focusWorker + '"]').length === 0) {
  666. focusWorker = '';
  667. persistFocus();
  668. }
  669. $sel.val(focusWorker);
  670. }
  671. // --- Phase 18: status filter (multi-select, persisted) ----------------
  672. const statusFilterKey = 'sp:' + sprintId + ':statusFilter' + keySuffix;
  673. /** @type {Set<string>} */
  674. const statusFilterSet = (function () {
  675. if (!taskStatusEnabled) { return new Set(); }
  676. try {
  677. const raw = window.localStorage.getItem(statusFilterKey);
  678. if (raw) {
  679. const arr = JSON.parse(raw);
  680. if (Array.isArray(arr)) { return new Set(arr.map(String)); }
  681. }
  682. } catch (_) { /* ignore */ }
  683. return new Set();
  684. })();
  685. function persistStatusFilter() {
  686. try {
  687. window.localStorage.setItem(statusFilterKey, JSON.stringify(Array.from(statusFilterSet)));
  688. } catch (_) { /* ignore quota / private mode */ }
  689. }
  690. function updateStatusFilterUi() {
  691. $root.find('[data-status-filter-opt]').each(function () {
  692. $(this).prop('checked', statusFilterSet.has(String($(this).val())));
  693. });
  694. const n = statusFilterSet.size;
  695. $root.find('[data-status-filter-count]').text(n === 0 ? '' : '(' + n + ')');
  696. }
  697. $root.on('change', '[data-status-filter-opt]', function () {
  698. const v = String($(this).val());
  699. if (STATUSES.indexOf(v) === -1) { return; }
  700. if ($(this).is(':checked')) { statusFilterSet.add(v); } else { statusFilterSet.delete(v); }
  701. persistStatusFilter();
  702. updateStatusFilterUi();
  703. applyFilters();
  704. });
  705. $root.on('click', '[data-status-filter-clear]', function () {
  706. statusFilterSet.clear();
  707. persistStatusFilter();
  708. updateStatusFilterUi();
  709. applyFilters();
  710. });
  711. $root.on('click', '[data-status-filter-trigger]', function (ev) {
  712. ev.stopPropagation();
  713. $root.find('[data-owner-filter-dropdown]').addClass('hidden');
  714. $root.find('[data-columns-dropdown]').addClass('hidden');
  715. $root.find('[data-status-filter-dropdown]').toggleClass('hidden');
  716. });
  717. // Predicate: row passes if at least one of its cells is in the picked
  718. // status set. The default 'zugewiesen' state matches only when there's
  719. // actual work assigned (days > 0) so picking it doesn't match every
  720. // task; the explicit states (gestartet/abgeschlossen/abgebrochen) match
  721. // regardless of days because a user only sets them deliberately.
  722. function rowMatchesStatusFilter($row) {
  723. if (statusFilterSet.size === 0) { return true; }
  724. let matched = false;
  725. $row.find('[data-assign-cell]').each(function () {
  726. const $cell = $(this);
  727. const status = String($cell.attr('data-status') || 'zugewiesen');
  728. if (!statusFilterSet.has(status)) { return; }
  729. if (status === 'zugewiesen') {
  730. const $inp = $cell.find('[data-assign]');
  731. const days = $inp.length
  732. ? (Number($inp.val()) || 0)
  733. : (Number($cell.find('.font-mono').text()) || 0);
  734. if (days > 0) { matched = true; return false; }
  735. return;
  736. }
  737. matched = true;
  738. return false;
  739. });
  740. return matched;
  741. }
  742. // --- Filters (search / prio / owner / focus / status) ----------------
  743. function applyFilters() {
  744. const q = String($root.find('[data-task-search]').val() || '').trim().toLowerCase();
  745. const prio = String($root.find('[data-prio-filter]').val() || '');
  746. const focus = String(focusWorker || '');
  747. let visibleCount = 0;
  748. $taskTbody.children('tr[data-task-row]').each(function () {
  749. const $row = $(this);
  750. const title = String($row.find('[data-title]').val() || $row.find('[data-title]').text() || '').toLowerCase();
  751. const rowPrio = String($row.attr('data-prio'));
  752. const rowOwner = String($row.attr('data-owner') || '');
  753. // The filter set treats "" (no owner) as the special "__none__" key.
  754. const ownerKey = rowOwner === '' ? '__none__' : rowOwner;
  755. let ok = true;
  756. if (q !== '' && !title.includes(q)) { ok = false; }
  757. if (prio !== '' && rowPrio !== prio) { ok = false; }
  758. if (ownerFilterSet.size > 0 && !ownerFilterSet.has(ownerKey)) { ok = false; }
  759. if (focus !== '') {
  760. // Zero-tolerance matches capacity math: treat 0 / 0.0 / empty
  761. // as "no assignment" (Number(v) > 0, not !== 0).
  762. const v = Number($row.find('[data-assign][data-sw-id="' + focus + '"]').val());
  763. if (!(v > 0)) { ok = false; }
  764. }
  765. if (ok && taskStatusEnabled && !rowMatchesStatusFilter($row)) { ok = false; }
  766. $row.toggle(ok);
  767. if (ok) { visibleCount++; }
  768. });
  769. const totalRows = $taskTbody.children('tr[data-task-row]').length;
  770. $root.find('[data-task-empty-filter]').toggle(totalRows > 0 && visibleCount === 0);
  771. applyFocusColumnVisibility();
  772. updateResetVisibility();
  773. }
  774. // Column auto-hide: when a focus worker is selected, any sw column that
  775. // is all-zero for the currently visible rows collapses. We tag cells
  776. // with `.focus-auto-hidden` rather than mutating `hiddenCols` so that
  777. // clearing Focus restores whatever the user picked in the Columns
  778. // dropdown.
  779. function applyFocusColumnVisibility() {
  780. // Always clear the transient class first — keeps the function
  781. // idempotent and correct when focus goes from set → "".
  782. $root.find('.focus-auto-hidden').removeClass('focus-auto-hidden');
  783. if (!focusWorker) { return; }
  784. // Walk every sw column. If no currently visible row has a > 0
  785. // assignment for that sw, hide every `[data-col="sw-{id}"]` cell.
  786. $root.find('[data-task-table] thead th[data-sort-col^="sw-"]').each(function () {
  787. const col = String($(this).attr('data-sort-col')); // e.g. "sw-42"
  788. const swId = col.slice(3);
  789. let anyNonZero = false;
  790. $taskTbody.children('tr[data-task-row]:visible').each(function () {
  791. const v = Number($(this).find('[data-assign][data-sw-id="' + swId + '"]').val());
  792. if (v > 0) { anyNonZero = true; return false; /* break */ }
  793. });
  794. if (!anyNonZero) {
  795. $root.find('[data-col="' + col + '"]').addClass('focus-auto-hidden');
  796. }
  797. });
  798. }
  799. let searchDebounce = null;
  800. $root.on('input', '[data-task-search]', function () {
  801. clearTimeout(searchDebounce);
  802. searchDebounce = setTimeout(applyFilters, 120);
  803. });
  804. $root.on('change', '[data-prio-filter]', applyFilters);
  805. $root.on('change', '[data-focus-select]', function () {
  806. focusWorker = String($(this).val() || '');
  807. persistFocus();
  808. applyFilters();
  809. });
  810. // --- Column visibility toggle (persisted in localStorage) --------------
  811. const columnsKey = 'sp:' + sprintId + ':hiddenCols' + keySuffix;
  812. /** @type {Set<string>} */
  813. const hiddenCols = (function () {
  814. try {
  815. const raw = window.localStorage.getItem(columnsKey);
  816. if (raw) {
  817. const arr = JSON.parse(raw);
  818. if (Array.isArray(arr)) { return new Set(arr.map(String)); }
  819. }
  820. // Phase 15: first-time-ever in beamer mode seeds the hidden set
  821. // with the non-discussion columns so the task table fits the
  822. // viewport at 1920×1080. User toggles from the Columns dropdown
  823. // persist from then on — we only seed when the key is missing.
  824. if (isBeamer) {
  825. const defaults = ['owner', 'prio', 'tot'];
  826. window.localStorage.setItem(columnsKey, JSON.stringify(defaults));
  827. return new Set(defaults);
  828. }
  829. } catch (_) { /* ignore */ }
  830. return new Set();
  831. })();
  832. function persistHiddenCols() {
  833. try {
  834. window.localStorage.setItem(columnsKey, JSON.stringify(Array.from(hiddenCols)));
  835. } catch (_) { /* ignore */ }
  836. }
  837. function applyColumnVisibility() {
  838. // Tailwind's .hidden is display:none; works on table cells.
  839. $root.find('[data-col]').each(function () {
  840. const col = String($(this).attr('data-col'));
  841. $(this).toggleClass('hidden', hiddenCols.has(col));
  842. });
  843. // Reflect state into the Columns dropdown checkboxes.
  844. $root.find('[data-column-opt]').each(function () {
  845. $(this).prop('checked', !hiddenCols.has(String($(this).val())));
  846. });
  847. }
  848. $root.on('change', '[data-column-opt]', function () {
  849. const v = String($(this).val());
  850. if ($(this).is(':checked')) { hiddenCols.delete(v); } else { hiddenCols.add(v); }
  851. persistHiddenCols();
  852. applyColumnVisibility();
  853. updateResetVisibility();
  854. });
  855. // --- Reset button (clears every filter + column-hide in one click) ----
  856. function filtersActive() {
  857. const q = String($root.find('[data-task-search]').val() || '').trim();
  858. const prio = String($root.find('[data-prio-filter]').val() || '');
  859. return q !== ''
  860. || prio !== ''
  861. || ownerFilterSet.size > 0
  862. || String(focusWorker || '') !== ''
  863. || hiddenCols.size > 0
  864. || (taskStatusEnabled && statusFilterSet.size > 0);
  865. }
  866. function updateResetVisibility() {
  867. $root.find('[data-reset-filters]').toggleClass('hidden', !filtersActive());
  868. }
  869. $root.on('click', '[data-reset-filters]', function () {
  870. $root.find('[data-task-search]').val('');
  871. $root.find('[data-prio-filter]').val('');
  872. ownerFilterSet.clear();
  873. persistOwnerFilter();
  874. focusWorker = '';
  875. persistFocus();
  876. hiddenCols.clear();
  877. persistHiddenCols();
  878. if (taskStatusEnabled) {
  879. statusFilterSet.clear();
  880. persistStatusFilter();
  881. }
  882. updateOwnerFilterUi();
  883. updateFocusUi();
  884. if (taskStatusEnabled) { updateStatusFilterUi(); }
  885. applyColumnVisibility();
  886. applyFilters();
  887. });
  888. $root.on('click', '[data-columns-trigger]', function (ev) {
  889. ev.stopPropagation();
  890. $root.find('[data-owner-filter-dropdown]').addClass('hidden');
  891. $root.find('[data-columns-dropdown]').toggleClass('hidden');
  892. });
  893. // Close either dropdown when clicking outside.
  894. $(document).on('click', function (ev) {
  895. if ($(ev.target).closest('[data-owner-filter-root]').length === 0) {
  896. $root.find('[data-owner-filter-dropdown]').addClass('hidden');
  897. }
  898. if ($(ev.target).closest('[data-columns-root]').length === 0) {
  899. $root.find('[data-columns-dropdown]').addClass('hidden');
  900. }
  901. if ($(ev.target).closest('[data-status-filter-root]').length === 0) {
  902. $root.find('[data-status-filter-dropdown]').addClass('hidden');
  903. }
  904. });
  905. // --- Column sort (client-side) ----------------------------------------
  906. const currentSort = { col: null, dir: null }; // dir: 'asc' | 'desc'
  907. function clearSort() {
  908. currentSort.col = null; currentSort.dir = null;
  909. $root.find('[data-sort-col]').each(function () {
  910. $(this).find('.sort-ind').text('↕').addClass('opacity-30').removeClass('opacity-100');
  911. });
  912. // Restore original order by data-sort-order
  913. const rows = $taskTbody.children('tr[data-task-row]').get();
  914. rows.sort(function (a, b) {
  915. return Number($(a).attr('data-sort-order')) - Number($(b).attr('data-sort-order'));
  916. });
  917. rows.forEach(function (el) { $taskTbody.append(el); });
  918. }
  919. function rowValueFor(col, $row) {
  920. if (col === 'title') {
  921. return String($row.find('[data-title]').val() || $row.find('[data-title]').text() || '').toLowerCase();
  922. }
  923. if (col === 'owner') {
  924. const id = String($row.attr('data-owner') || '');
  925. if (id === '') { return '\uFFFF'; } // sort empty last
  926. const opt = $row.find('[data-owner-select] option:selected');
  927. return String(opt.text() || '').toLowerCase();
  928. }
  929. if (col === 'prio') { return Number($row.attr('data-prio')); }
  930. if (col === 'tot') { return Number($row.find('[data-task-tot]').text()) || 0; }
  931. if (col.indexOf('sw-') === 0) {
  932. const swId = col.slice(3);
  933. return Number($row.find('[data-assign][data-sw-id="' + swId + '"]').val()) || 0;
  934. }
  935. return 0;
  936. }
  937. function applySort(col) {
  938. let dir;
  939. if (currentSort.col !== col) { dir = 'asc'; }
  940. else if (currentSort.dir === 'asc') { dir = 'desc'; }
  941. else { clearSort(); return; } // third click clears
  942. currentSort.col = col;
  943. currentSort.dir = dir;
  944. $root.find('[data-sort-col] .sort-ind').text('↕').addClass('opacity-30').removeClass('opacity-100');
  945. $root.find('[data-sort-col="' + col + '"] .sort-ind')
  946. .text(dir === 'asc' ? '↑' : '↓')
  947. .removeClass('opacity-30').addClass('opacity-100');
  948. const rows = $taskTbody.children('tr[data-task-row]').get();
  949. rows.sort(function (a, b) {
  950. const va = rowValueFor(col, $(a));
  951. const vb = rowValueFor(col, $(b));
  952. if (va < vb) { return dir === 'asc' ? -1 : 1; }
  953. if (va > vb) { return dir === 'asc' ? 1 : -1; }
  954. // Stable-ish tiebreak: fall back to data-sort-order
  955. return Number($(a).attr('data-sort-order')) - Number($(b).attr('data-sort-order'));
  956. });
  957. rows.forEach(function (el) { $taskTbody.append(el); });
  958. }
  959. $root.on('click', '[data-sort-col]', function () {
  960. applySort(String($(this).attr('data-sort-col')));
  961. });
  962. // =====================================================================
  963. // Boot
  964. // =====================================================================
  965. // Recompute once at boot in case the server-rendered sums drift from the
  966. // JS formula (e.g. after a stale reload).
  967. $root.find('[data-sw-row]').each(function () {
  968. recomputeRow(parseInt($(this).data('sw-id'), 10));
  969. });
  970. // Restore persisted task-list UI state BEFORE applyFilters so hidden
  971. // columns don't briefly flash in before being toggled off.
  972. updateOwnerFilterUi();
  973. updateFocusUi();
  974. if (taskStatusEnabled) { updateStatusFilterUi(); }
  975. applyColumnVisibility();
  976. applyFilters();
  977. // Reset button visibility is a function of every filter; applyFilters
  978. // already calls updateResetVisibility, but call it once more at boot
  979. // in case the tbody is empty (applyFilters short-circuits nothing,
  980. // but this is defensive).
  981. updateResetVisibility();
  982. // Phase 15: in beamer mode, if the rendered task table is wider than
  983. // its scroll container, rotate worker-column headers to vertical.
  984. // Measure once after the first applyFilters() run (inputs laid out,
  985. // hidden columns collapsed) and escalate a single step — horizontal
  986. // scroll is a fallback but never a spinlock.
  987. if (isBeamer && hasTaskUi) {
  988. const table = $root.find('[data-task-table]').get(0);
  989. const container = table ? table.parentElement : null;
  990. if (table && container && table.scrollWidth > container.clientWidth) {
  991. $root.addClass('beamer-vertical-headers');
  992. if (table.scrollWidth > container.clientWidth) {
  993. // eslint-disable-next-line no-console
  994. console.warn('[sprint-planner] beamer: table still overflows after vertical headers; horizontal scroll enabled.');
  995. }
  996. }
  997. }
  998. })(jQuery);