show.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. /** @var \App\Domain\Sprint $sprint */
  3. /** @var \App\Domain\User $currentUser */
  4. /** @var string $csrfToken */
  5. /** @var list<\App\Domain\SprintWeek> $weeks */
  6. /** @var list<\App\Domain\SprintWorker> $sprintWorkers */
  7. /** @var array<int, array<int, float>> $grid sw_id => week_id => days */
  8. /** @var array<int, array{ressourcen:float, after_reserves:float, committed_prio1:float, available:float}> $capacity */
  9. /** @var list<\App\Domain\Task> $tasks */
  10. /** @var array<int, array<int, float>> $taskGrid task_id => sw_id => days */
  11. /** @var list<\App\Domain\Worker> $ownerChoices */
  12. use function App\Http\e;
  13. $tasks = $tasks ?? [];
  14. $taskGrid = $taskGrid ?? [];
  15. $ownerChoices = $ownerChoices ?? [];
  16. if (!function_exists('fmt_days')) {
  17. function fmt_days(float $x): string
  18. {
  19. // Show 0 as "0", whole numbers as integer, halves as x.5
  20. if (abs($x - round($x)) < 1e-9) {
  21. return (string) (int) round($x);
  22. }
  23. return number_format($x, 1);
  24. }
  25. }
  26. ?>
  27. <section class="space-y-6"
  28. data-sprint-root
  29. data-sprint-id="<?= (int) $sprint->id ?>"
  30. data-csrf="<?= e($csrfToken) ?>"
  31. data-reserve-fraction="<?= e(number_format($sprint->reserveFraction, 4, '.', '')) ?>">
  32. <header class="flex items-end justify-between gap-4">
  33. <div>
  34. <nav class="text-xs text-slate-500">
  35. <a href="/" class="hover:underline">Sprints</a> /
  36. </nav>
  37. <h1 class="text-2xl font-semibold tracking-tight"><?= e($sprint->name) ?></h1>
  38. <p class="text-slate-600 mt-1 text-sm">
  39. <?= e($sprint->startDate) ?> – <?= e($sprint->endDate) ?>
  40. · Reserve <?= e(number_format($sprint->reserveFraction * 100, 0)) ?>%
  41. <?php if ($sprint->isArchived): ?>
  42. · <span class="inline-block px-2 py-0.5 text-xs bg-slate-100 text-slate-600 rounded">archived</span>
  43. <?php endif; ?>
  44. </p>
  45. </div>
  46. <div class="flex items-center gap-3">
  47. <div data-status
  48. class="text-sm border rounded px-3 py-1 opacity-0 transition-opacity duration-200 border-slate-200 bg-slate-50 text-slate-700">
  49. </div>
  50. <?php if ($currentUser->isAdmin): ?>
  51. <a href="/sprints/<?= (int) $sprint->id ?>/settings"
  52. class="inline-flex items-center gap-2 rounded-md border border-slate-300 bg-white text-slate-700 px-3 py-2 text-sm hover:bg-slate-100">
  53. Settings
  54. </a>
  55. <?php endif; ?>
  56. </div>
  57. </header>
  58. <?php if ($sprintWorkers === [] || $weeks === []): ?>
  59. <div class="rounded-md border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900">
  60. <?php if ($weeks === []): ?>
  61. No weeks yet. <a href="/sprints/<?= (int) $sprint->id ?>/settings" class="underline">Open settings</a> to add some.
  62. <?php elseif ($sprintWorkers === []): ?>
  63. No workers on this sprint yet. <a href="/sprints/<?= (int) $sprint->id ?>/settings" class="underline">Open settings</a> to add some.
  64. <?php endif; ?>
  65. </div>
  66. <?php else: ?>
  67. <!-- Arbeitstage grid -->
  68. <section class="rounded-lg border bg-white overflow-x-auto">
  69. <table class="min-w-full text-sm" data-arbeitstage>
  70. <thead class="bg-slate-50 text-slate-600 text-xs uppercase tracking-wider">
  71. <tr>
  72. <th class="text-left px-3 py-2 font-semibold sticky left-0 bg-slate-50 z-10">&nbsp;</th>
  73. <?php foreach ($weeks as $w): ?>
  74. <th class="text-center px-2 py-2 font-semibold whitespace-nowrap">
  75. <div class="font-mono">KW<?= (int) $w->isoWeek ?></div>
  76. <div class="text-[10px] text-slate-500 font-normal"><?= e($w->startDate) ?></div>
  77. </th>
  78. <?php endforeach; ?>
  79. <th class="text-center px-2 py-2 font-semibold">Σ</th>
  80. <th class="text-center px-2 py-2 font-semibold">RTB</th>
  81. </tr>
  82. </thead>
  83. <tbody class="divide-y divide-slate-100" data-tbody>
  84. <!-- Arbeitstage (max working days) row -->
  85. <tr class="bg-slate-50">
  86. <th class="text-left px-3 py-2 font-semibold text-slate-700 sticky left-0 bg-slate-50">
  87. Arbeitstage
  88. </th>
  89. <?php $sumMax = 0.0; foreach ($weeks as $w): $sumMax += $w->maxWorkingDays; ?>
  90. <td class="px-1 py-1 text-center">
  91. <?php if ($currentUser->isAdmin): ?>
  92. <input type="number" min="0" max="5" step="0.5"
  93. value="<?= e(fmt_days($w->maxWorkingDays)) ?>"
  94. data-week-max data-week-id="<?= (int) $w->id ?>"
  95. class="w-14 rounded border border-slate-300 px-1 py-1 text-center font-mono focus:outline-none focus:ring-2 focus:ring-slate-400">
  96. <?php else: ?>
  97. <span class="font-mono"><?= e(fmt_days($w->maxWorkingDays)) ?></span>
  98. <?php endif; ?>
  99. </td>
  100. <?php endforeach; ?>
  101. <td class="px-2 py-1 text-center font-mono font-semibold" data-sum-max>
  102. <?= e(fmt_days($sumMax)) ?>
  103. </td>
  104. <td>&nbsp;</td>
  105. </tr>
  106. <!-- One row per sprint worker -->
  107. <?php foreach ($sprintWorkers as $sw): ?>
  108. <?php $rowDays = $grid[$sw->id] ?? []; $rowSum = array_sum($rowDays); ?>
  109. <tr data-sw-row data-sw-id="<?= (int) $sw->id ?>">
  110. <th class="text-left px-3 py-2 font-medium sticky left-0 bg-white z-10">
  111. <span class="flex items-center gap-2">
  112. <?php if ($currentUser->isAdmin): ?>
  113. <span class="handle cursor-grab text-slate-400 select-none">&#8801;</span>
  114. <?php endif; ?>
  115. <?= e($sw->workerName) ?>
  116. </span>
  117. </th>
  118. <?php foreach ($weeks as $w): $v = (float) ($rowDays[$w->id] ?? 0.0); ?>
  119. <td class="px-1 py-1 text-center">
  120. <?php if ($currentUser->isAdmin): ?>
  121. <input type="number" min="0" max="5" step="0.5"
  122. value="<?= e(fmt_days($v)) ?>"
  123. data-day data-sw-id="<?= (int) $sw->id ?>"
  124. data-week-id="<?= (int) $w->id ?>"
  125. 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">
  126. <?php else: ?>
  127. <span class="font-mono"><?= e(fmt_days($v)) ?></span>
  128. <?php endif; ?>
  129. </td>
  130. <?php endforeach; ?>
  131. <td class="px-2 py-1 text-center font-mono font-semibold"
  132. data-sum-days data-sw-id="<?= (int) $sw->id ?>">
  133. <?= e(fmt_days($rowSum)) ?>
  134. </td>
  135. <td class="px-1 py-1 text-center">
  136. <?php if ($currentUser->isAdmin): ?>
  137. <input type="number" min="0" max="1" step="0.05"
  138. value="<?= e(number_format($sw->rtb, 2, '.', '')) ?>"
  139. data-rtb data-sw-id="<?= (int) $sw->id ?>"
  140. class="w-16 rounded border border-slate-200 px-1 py-1 text-center font-mono focus:outline-none focus:ring-2 focus:ring-slate-400">
  141. <?php else: ?>
  142. <span class="font-mono"><?= e(number_format($sw->rtb, 2, '.', '')) ?></span>
  143. <?php endif; ?>
  144. </td>
  145. </tr>
  146. <?php endforeach; ?>
  147. </tbody>
  148. </table>
  149. </section>
  150. <!-- Capacity summary — one column per worker, aligned with task columns in Phase 6 -->
  151. <section class="rounded-lg border bg-white overflow-x-auto">
  152. <div class="px-4 py-2 border-b bg-slate-50 text-xs uppercase tracking-wider text-slate-600 font-semibold">
  153. Capacity
  154. </div>
  155. <table class="min-w-full text-sm">
  156. <thead>
  157. <tr class="bg-slate-50 text-slate-600 text-xs">
  158. <th class="text-left px-3 py-2 font-semibold sticky left-0 bg-slate-50 z-10">&nbsp;</th>
  159. <?php foreach ($sprintWorkers as $sw): ?>
  160. <th class="text-center px-2 py-2 font-semibold whitespace-nowrap">
  161. <?= e($sw->workerName) ?>
  162. </th>
  163. <?php endforeach; ?>
  164. </tr>
  165. </thead>
  166. <tbody class="divide-y divide-slate-100">
  167. <tr>
  168. <th class="text-left px-3 py-2 text-slate-700 font-medium sticky left-0 bg-white">Ressourcen</th>
  169. <?php foreach ($sprintWorkers as $sw): $c = $capacity[$sw->id] ?? null; ?>
  170. <td class="px-2 py-2 text-center font-mono"
  171. data-cap-ressourcen data-sw-id="<?= (int) $sw->id ?>">
  172. <?= e(fmt_days($c['ressourcen'] ?? 0.0)) ?>
  173. </td>
  174. <?php endforeach; ?>
  175. </tr>
  176. <tr>
  177. <th class="text-left px-3 py-2 text-slate-700 font-medium sticky left-0 bg-white">− Reserven</th>
  178. <?php foreach ($sprintWorkers as $sw): $c = $capacity[$sw->id] ?? null; ?>
  179. <td class="px-2 py-2 text-center font-mono text-slate-600"
  180. data-cap-after-reserves data-sw-id="<?= (int) $sw->id ?>">
  181. <?= e(fmt_days($c['after_reserves'] ?? 0.0)) ?>
  182. </td>
  183. <?php endforeach; ?>
  184. </tr>
  185. <tr>
  186. <th class="text-left px-3 py-2 text-slate-700 font-semibold sticky left-0 bg-white">Available</th>
  187. <?php foreach ($sprintWorkers as $sw): $c = $capacity[$sw->id] ?? null; $av = (float) ($c['available'] ?? 0.0); ?>
  188. <td class="px-2 py-2 text-center font-mono font-semibold <?= $av < 0 ? 'text-red-700' : 'text-slate-900' ?>"
  189. data-cap-available data-sw-id="<?= (int) $sw->id ?>">
  190. <?= e(fmt_days($av)) ?>
  191. </td>
  192. <?php endforeach; ?>
  193. </tr>
  194. </tbody>
  195. </table>
  196. </section>
  197. <p class="text-xs text-slate-500">
  198. Numeric inputs snap to 0.5 (days) or 0.05 (RTB) on blur. Edits save automatically
  199. with a 400&nbsp;ms debounce; Available turns red if a worker is overcommitted.
  200. </p>
  201. <!-- Section B: Task list -->
  202. <section class="rounded-lg border bg-white overflow-hidden"
  203. data-task-section>
  204. <div class="px-4 py-3 border-b bg-slate-50 flex flex-wrap items-center gap-2">
  205. <h2 class="text-sm font-semibold text-slate-700 uppercase tracking-wider">Tasks</h2>
  206. <!-- Toolbar -->
  207. <div class="ml-auto flex flex-wrap items-center gap-2">
  208. <input type="search" data-task-search placeholder="Search…"
  209. class="rounded border border-slate-300 px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-slate-400">
  210. <select data-prio-filter
  211. class="rounded border border-slate-300 px-2 py-1 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-slate-400">
  212. <option value="">All prios</option>
  213. <option value="1">Prio 1 only</option>
  214. <option value="2">Prio 2 only</option>
  215. </select>
  216. <select data-owner-filter
  217. class="rounded border border-slate-300 px-2 py-1 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-slate-400">
  218. <option value="">All owners</option>
  219. <option value="__none__">No owner</option>
  220. <?php foreach ($ownerChoices as $ow): ?>
  221. <option value="<?= (int) $ow->id ?>"><?= e($ow->name) ?></option>
  222. <?php endforeach; ?>
  223. </select>
  224. <?php if ($currentUser->isAdmin): ?>
  225. <button type="button" data-add-task
  226. class="rounded bg-slate-900 text-white px-3 py-1 text-sm font-medium hover:bg-slate-800">
  227. + Add task
  228. </button>
  229. <?php endif; ?>
  230. </div>
  231. </div>
  232. <div class="overflow-x-auto">
  233. <table class="min-w-full text-sm" data-task-table>
  234. <thead class="bg-slate-50 text-slate-600 text-xs uppercase tracking-wider">
  235. <tr>
  236. <th class="w-6 px-2 py-2"></th>
  237. <th class="text-left px-2 py-2 font-semibold cursor-pointer select-none"
  238. data-sort-col="title">Task <span class="sort-ind opacity-30">↕</span></th>
  239. <th class="text-left px-2 py-2 font-semibold cursor-pointer select-none"
  240. data-sort-col="owner">Owner <span class="sort-ind opacity-30">↕</span></th>
  241. <th class="text-center px-2 py-2 font-semibold cursor-pointer select-none"
  242. data-sort-col="prio">Prio <span class="sort-ind opacity-30">↕</span></th>
  243. <th class="text-center px-2 py-2 font-semibold cursor-pointer select-none"
  244. data-sort-col="tot">Tot <span class="sort-ind opacity-30">↕</span></th>
  245. <?php foreach ($sprintWorkers as $sw): ?>
  246. <th class="text-center px-2 py-2 font-semibold cursor-pointer select-none whitespace-nowrap"
  247. data-sort-col="sw-<?= (int) $sw->id ?>">
  248. <?= e($sw->workerName) ?>
  249. <span class="sort-ind opacity-30">↕</span>
  250. </th>
  251. <?php endforeach; ?>
  252. <th class="w-8 px-2 py-2"></th>
  253. </tr>
  254. </thead>
  255. <tbody class="divide-y divide-slate-100" data-task-tbody>
  256. <?php if ($tasks === []): ?>
  257. <tr data-empty-tasks>
  258. <td colspan="<?= 6 + count($sprintWorkers) ?>" class="px-3 py-8 text-center text-slate-500 text-sm">
  259. No tasks yet.
  260. <?php if ($currentUser->isAdmin): ?>
  261. Click <b>+ Add task</b> to start.
  262. <?php endif; ?>
  263. </td>
  264. </tr>
  265. <?php else: ?>
  266. <?php foreach ($tasks as $t): ?>
  267. <?php $assign = $taskGrid[$t->id] ?? []; $tot = array_sum($assign); ?>
  268. <tr data-task-row
  269. data-task-id="<?= (int) $t->id ?>"
  270. data-prio="<?= (int) $t->priority ?>"
  271. data-owner="<?= $t->ownerWorkerId !== null ? (int) $t->ownerWorkerId : '' ?>"
  272. data-sort-order="<?= (int) $t->sortOrder ?>">
  273. <td class="px-2 py-1">
  274. <?php if ($currentUser->isAdmin): ?>
  275. <span class="handle cursor-grab text-slate-400 select-none">&#8801;</span>
  276. <?php endif; ?>
  277. </td>
  278. <td class="px-2 py-1 min-w-[14rem]">
  279. <?php if ($currentUser->isAdmin): ?>
  280. <input type="text" data-title
  281. value="<?= e($t->title) ?>"
  282. class="w-full rounded border border-slate-200 px-2 py-1 focus:outline-none focus:ring-2 focus:ring-slate-400">
  283. <?php else: ?>
  284. <span><?= e($t->title) ?></span>
  285. <?php endif; ?>
  286. </td>
  287. <td class="px-2 py-1">
  288. <?php if ($currentUser->isAdmin): ?>
  289. <select data-owner-select
  290. class="w-full rounded border border-slate-200 px-2 py-1 bg-white focus:outline-none focus:ring-2 focus:ring-slate-400">
  291. <option value="">—</option>
  292. <?php foreach ($ownerChoices as $ow): ?>
  293. <option value="<?= (int) $ow->id ?>" <?= $t->ownerWorkerId === $ow->id ? 'selected' : '' ?>>
  294. <?= e($ow->name) ?>
  295. </option>
  296. <?php endforeach; ?>
  297. </select>
  298. <?php else: ?>
  299. <?php
  300. $ownerName = '—';
  301. foreach ($ownerChoices as $ow) {
  302. if ($ow->id === $t->ownerWorkerId) { $ownerName = $ow->name; break; }
  303. }
  304. echo e($ownerName);
  305. ?>
  306. <?php endif; ?>
  307. </td>
  308. <td class="px-2 py-1 text-center">
  309. <?php if ($currentUser->isAdmin): ?>
  310. <select data-prio-select
  311. class="rounded border border-slate-200 px-2 py-1 bg-white font-mono focus:outline-none focus:ring-2 focus:ring-slate-400">
  312. <option value="1" <?= $t->priority === 1 ? 'selected' : '' ?>>1</option>
  313. <option value="2" <?= $t->priority === 2 ? 'selected' : '' ?>>2</option>
  314. </select>
  315. <?php else: ?>
  316. <span class="font-mono"><?= (int) $t->priority ?></span>
  317. <?php endif; ?>
  318. </td>
  319. <td class="px-2 py-1 text-center font-mono font-semibold"
  320. data-task-tot>
  321. <?= e(fmt_days($tot)) ?>
  322. </td>
  323. <?php foreach ($sprintWorkers as $sw): $d = (float) ($assign[$sw->id] ?? 0.0); ?>
  324. <td class="px-1 py-1 text-center"
  325. data-sort-value-sw-<?= (int) $sw->id ?>="<?= e(number_format($d, 2, '.', '')) ?>">
  326. <?php if ($currentUser->isAdmin): ?>
  327. <input type="number" min="0" step="0.5"
  328. value="<?= e(fmt_days($d)) ?>"
  329. data-assign
  330. data-sw-id="<?= (int) $sw->id ?>"
  331. 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">
  332. <?php else: ?>
  333. <span class="font-mono"><?= e(fmt_days($d)) ?></span>
  334. <?php endif; ?>
  335. </td>
  336. <?php endforeach; ?>
  337. <td class="px-1 py-1 text-right">
  338. <?php if ($currentUser->isAdmin): ?>
  339. <button type="button" data-delete-task
  340. class="text-sm text-red-600 hover:underline">×</button>
  341. <?php endif; ?>
  342. </td>
  343. </tr>
  344. <?php endforeach; ?>
  345. <?php endif; ?>
  346. </tbody>
  347. </table>
  348. </div>
  349. <div data-task-empty-filter class="hidden p-4 text-center text-slate-500 text-sm">
  350. No tasks match the current filters.
  351. </div>
  352. </section>
  353. <?php endif; ?>
  354. </section>
  355. <script src="/assets/js/sprint-planner.js" defer></script>