forge
Explore
Log in

Don't you dare go Hollow

A task shows its parts, and a part names its whole

Browse files at this commit

9f8c3b79f954ce7b02fc467cd451d949bce6f9daAhmet Kaan GümüşParent: 08a79b8
  • feat
    • a task shows its parts, and a part names its whole
Show full message
🧩 feat(web): a task shows its parts, and a part names its whole

The board keeps being a board of tasks. A subtask is read with the rest
but never carded: the filter is in `assemble`, not in the query, because
a subtask's key can appear on somebody else's card as a blocker and a
query-side filter would drop that chip silently, leaving a blocked card
looking free. The parent wears `2/5` instead, in the same family as the
comment chip, and turns warning-coloured while parts are open — the card
carries the count the refusal deliberately does not.

The detail page grows a Subtasks block: a row per part with its key,
title, status and who holds it, a field to open a new one, and a picker
that takes an existing task in. Each row's cross lets that part back
out. A subtask's own page names its whole above its key. Both directions
are `/api/set_parent` with one field — filing under and letting out are
the same single write, so they are the same form.

The family costs one query, so a detail is nine round trips rather than
eight, and the budget test now hangs twenty assigned subtasks off the
heavy case to hold that line.

Deleting a parent takes its parts with it, in the same write, and the
confirmation says so before the button fires: a subtask that outlived
its parent would be unreachable — off the board by design, and the page
that showed it is gone. A parent and its own part can no longer be
linked as a dependency either; the relationship already exists, and the
board would draw it twice.
crates/izlek-core/src/board.rsmodified+50 -0
@@ -37,6 +37,11 @@ pub struct TaskRow {
3737 pub deadline: Option<Date>,
3838 pub position: f64,
3939 pub done_at: Option<OffsetDateTime>,
40+ /// The task this one is a subtask of. A row with a parent gets no card of
41+ /// its own on the board — it is counted on its parent's instead — but it
42+ /// is still read with the rest, because a key it owns can appear on
43+ /// somebody else's card as a blocker.
44+ pub parent_id: Option<String>,
4045 }
4146
4247 /// One card crossing from one column into another, as it was written.
@@ -123,6 +128,10 @@ pub struct TaskCard {
123128 pub blocked_by: Vec<String>,
124129 /// Keys of the tasks waiting on this one.
125130 pub blocks: Vec<String>,
131+ /// How many subtasks this card has, and how many of them are finished.
132+ /// Both are zero for a card with none, which is what hides the chip.
133+ pub subtask_total: u32,
134+ pub subtask_done: u32,
126135 }
127136
128137 impl TaskCard {
@@ -130,6 +139,19 @@ impl TaskCard {
130139 self.done_at.is_some()
131140 }
132141
142+ /// The `2/5` the card wears, or nothing when the task has no parts. It is
143+ /// also the only place the count appears when a move is refused, which is
144+ /// why the refusal itself does not carry one.
145+ pub fn subtask_label(&self) -> Option<String> {
146+ (self.subtask_total > 0)
147+ .then(|| format!("{}/{}", self.subtask_done, self.subtask_total))
148+ }
149+
150+ /// Whether finishing this card is currently refused.
151+ pub fn holds_on_subtasks(&self) -> bool {
152+ self.subtask_done < self.subtask_total
153+ }
154+
133155 /// Blocked means something unfinished is in front of it. A finished task is
134156 /// never counted as blocked, whatever it still points at.
135157 pub fn is_blocked(&self) -> bool {
@@ -306,13 +328,41 @@ pub fn assemble(
306328 }
307329 }
308330
331+ // A subtask is counted on its parent's card, never given one of its own.
332+ let mut subtask_total: HashMap<&str, u32> = HashMap::new();
333+ let mut subtask_done: HashMap<&str, u32> = HashMap::new();
334+ for task in &tasks {
335+ if let Some(parent) = task.parent_id.as_deref() {
336+ *subtask_total.entry(parent).or_default() += 1;
337+ if task.done_at.is_some() {
338+ *subtask_done.entry(parent).or_default() += 1;
339+ }
340+ }
341+ }
342+ let subtask_total: HashMap<String, u32> = subtask_total
343+ .into_iter()
344+ .map(|(id, n)| (id.to_string(), n))
345+ .collect();
346+ let subtask_done: HashMap<String, u32> = subtask_done
347+ .into_iter()
348+ .map(|(id, n)| (id.to_string(), n))
349+ .collect();
350+
309351 let mut cards: HashMap<String, Vec<TaskCard>> = HashMap::new();
310352 for task in tasks {
353+ // Read with the rest so its key can appear as a blocker chip, but the
354+ // board is a board of tasks: a subtask reaches its page through its
355+ // parent's.
356+ if task.parent_id.is_some() {
357+ continue;
358+ }
311359 let card = TaskCard {
312360 comment_count: counts.get(&task.id).copied().unwrap_or(0),
313361 assignees: people.remove(&task.id).unwrap_or_default(),
314362 blocked_by: blocked_by.remove(&task.id).unwrap_or_default(),
315363 blocks: blocks.remove(&task.id).unwrap_or_default(),
364+ subtask_total: subtask_total.get(&task.id).copied().unwrap_or(0),
365+ subtask_done: subtask_done.get(&task.id).copied().unwrap_or(0),
316366 id: task.id,
317367 task_key: task.task_key,
318368 title: task.title,
crates/izlek-core/src/detail.rsmodified+61 -5
@@ -99,6 +99,25 @@ impl FileLine {
9999
100100 /// What deleting a task would take with it. The confirmation step says this
101101 /// out loud before the button fires.
102+/// One row in the subtask list on a task's page, and the "part of DZ-14" line
103+/// on a subtask's own page — the same shape both ways, because a subtask and
104+/// its parent are the same kind of thing.
105+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
106+pub struct SubtaskLine {
107+ pub id: String,
108+ pub task_key: String,
109+ pub title: String,
110+ pub column_id: String,
111+ pub done_at: Option<OffsetDateTime>,
112+ pub assignees: Vec<Person>,
113+}
114+
115+impl SubtaskLine {
116+ pub fn is_done(&self) -> bool {
117+ self.done_at.is_some()
118+ }
119+}
120+
102121 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
103122 pub struct DeletionCost {
104123 pub task_key: String,
@@ -108,6 +127,9 @@ pub struct DeletionCost {
108127 pub link_count: u32,
109128 /// Keys of the tasks that would have nothing in front of them afterwards.
110129 pub frees: Vec<String>,
130+ /// How many subtasks would go with it. A part has no meaning once the
131+ /// whole is gone, so deleting a parent deletes them too.
132+ pub subtask_count: u32,
111133 }
112134
113135 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -133,6 +155,10 @@ pub enum ActivityKind {
133155 Unassigned,
134156 Linked,
135157 Unlinked,
158+ /// Filed under another task, and let out of it again. The detail is the
159+ /// other task's key both ways.
160+ Parented,
161+ Unparented,
136162 Moved,
137163 Unblocked,
138164 Deleted,
@@ -169,6 +195,8 @@ impl ActivityKind {
169195 pub fn as_str(&self) -> &str {
170196 match self {
171197 ActivityKind::Commented => "commented",
198+ ActivityKind::Parented => "parented",
199+ ActivityKind::Unparented => "unparented",
172200 ActivityKind::WorkspaceClaimed => "workspace_claimed",
173201 ActivityKind::Invited => "invited",
174202 ActivityKind::LinkResent => "link_resent",
@@ -216,6 +244,8 @@ impl ActivityKind {
216244 "unassigned" => ActivityKind::Unassigned,
217245 "linked" => ActivityKind::Linked,
218246 "unlinked" => ActivityKind::Unlinked,
247+ "parented" => ActivityKind::Parented,
248+ "unparented" => ActivityKind::Unparented,
219249 "moved" => ActivityKind::Moved,
220250 "unblocked" => ActivityKind::Unblocked,
221251 "deleted" => ActivityKind::Deleted,
@@ -272,6 +302,8 @@ impl ActivityEntry {
272302 ActivityKind::Unassigned => format!("unassigned {detail}"),
273303 ActivityKind::Linked => format!("linked {detail}"),
274304 ActivityKind::Unlinked => format!("unlinked {detail}"),
305+ ActivityKind::Parented => format!("made this a part of {detail}"),
306+ ActivityKind::Unparented => format!("released this from {detail}"),
275307 ActivityKind::Moved => format!("moved {detail}"),
276308 ActivityKind::Unblocked => format!("unblocked this task — {detail}"),
277309 ActivityKind::Deleted => "deleted this task".to_string(),
@@ -412,6 +444,10 @@ pub struct TaskDetail {
412444 /// Files hung off this task, oldest first.
413445 pub files: Vec<FileLine>,
414446 pub activity: Vec<ActivityEntry>,
447+ /// The task this one is a part of, when it is one.
448+ pub parent: Option<SubtaskLine>,
449+ /// The parts of this task, oldest first. Always empty for a subtask.
450+ pub subtasks: Vec<SubtaskLine>,
415451 }
416452
417453 impl TaskDetail {
@@ -483,7 +519,7 @@ pub use reads::{DetailReads, load};
483519 mod reads {
484520 use async_trait::async_trait;
485521
486- use super::{ActivityEntry, Comment, DependencyEdge, FileLine, TaskDetail, TaskFacts};
522+ use super::{ActivityEntry, Comment, DependencyEdge, FileLine, SubtaskLine, TaskDetail, TaskFacts};
487523 use crate::board::{Column, Person};
488524 use crate::store::Result;
489525
@@ -515,14 +551,21 @@ mod reads {
515551 async fn files_for_task(&self, task_id: &str) -> Result<Vec<FileLine>>;
516552
517553 async fn activity_for_task(&self, task_id: &str) -> Result<Vec<ActivityEntry>>;
554+
555+ /// A task's parent and its subtasks in one read: `true` marks the
556+ /// parent. One of the two is always empty — a subtask has a parent and
557+ /// no children, a parent has children and no parent of its own — but
558+ /// the query is the same either way, so it is one query either way.
559+ async fn family_for_task(&self, task_id: &str) -> Result<Vec<(bool, SubtaskLine)>>;
518560 }
519561
520- /// Loads one task detail in eight queries — the task, the board's columns,
562+ /// Loads one task detail in nine queries — the task, the board's columns,
521563 /// its assignees, the workspace's writers, both directions of its
522- /// dependencies, its comments, its files and its activity.
564+ /// dependencies, its comments, its files, its activity, and its family.
523565 ///
524- /// Eight, not eight-plus-one-per-comment: `a_task_detail_costs_eight_
525- /// queries_whatever_it_carries` in `tests/store.rs` holds that line.
566+ /// Nine, not nine-plus-one-per-comment or -per-subtask: `a_task_detail_
567+ /// costs_nine_queries_whatever_it_carries` in `tests/store.rs` holds that
568+ /// line.
526569 pub async fn load(
527570 reads: &dyn DetailReads,
528571 workspace_id: &str,
@@ -544,6 +587,17 @@ mod reads {
544587 let comments = reads.comments_for_task(task_id).await?;
545588 let files = reads.files_for_task(task_id).await?;
546589 let activity = reads.activity_for_task(task_id).await?;
590+ let family = reads.family_for_task(task_id).await?;
591+
592+ let mut parent = None;
593+ let mut subtasks = Vec::new();
594+ for (is_parent, line) in family {
595+ if is_parent {
596+ parent = Some(line);
597+ } else {
598+ subtasks.push(line);
599+ }
600+ }
547601
548602 let Some(column) = columns
549603 .iter()
@@ -578,6 +632,8 @@ mod reads {
578632 comments,
579633 files,
580634 activity,
635+ parent,
636+ subtasks,
581637 }))
582638 }
583639 }
crates/izlek-core/src/mail.rsmodified+6 -0
@@ -671,6 +671,12 @@ impl Engine {
671671 ActivityKind::Retitled => format!("{} renamed it.", actor),
672672 ActivityKind::Linked => format!("{} linked {}.", actor, activity.detail),
673673 ActivityKind::Unlinked => format!("{} unlinked {}.", actor, activity.detail),
674+ ActivityKind::Parented => {
675+ format!("{} made it a part of {}.", actor, activity.detail)
676+ }
677+ ActivityKind::Unparented => {
678+ format!("{} released it from {}.", actor, activity.detail)
679+ }
674680 ActivityKind::Deleted => format!("{} deleted it.", actor),
675681 // Never a wired trigger — `activity_kind_for` never maps to
676682 // these — and account/admin kinds have no task to be mailed
crates/izlek-core/src/store/turso_store.rsmodified+100 -6
@@ -24,7 +24,7 @@ use crate::Role;
2424 use crate::board::{BoardMeta, BoardReads, Column, Moved, Person, TaskRow, Transition};
2525 use crate::detail::{
2626 ActivityEntry, ActivityKind, Comment, DeletionCost, DependencyEdge, DetailReads, FileLine,
27- TaskFacts,
27+ SubtaskLine, TaskFacts,
2828 };
2929 use time::Date;
3030 use time::format_description::BorrowedFormatItem;
@@ -1466,6 +1466,7 @@ impl Store for TursoStore {
14661466 deadline: new.deadline,
14671467 position,
14681468 done_at: None,
1469+ parent_id: new.parent_id.map(str::to_string),
14691470 },
14701471 activity_id,
14711472 transition: Transition {
@@ -1588,6 +1589,7 @@ impl Store for TursoStore {
15881589 deadline: opt_day(&row, 4)?,
15891590 position: row.get::<f64>(5).unwrap_or(0.0),
15901591 done_at: opt_stamp(&row, 6)?,
1592+ parent_id: Some(parent_id.to_string()),
15911593 });
15921594 }
15931595 Ok(out)
@@ -1628,6 +1630,24 @@ impl Store for TursoStore {
16281630 }
16291631 let stamp = stamp(at)?;
16301632
1633+ // A parent and its own part are already related, and the board would
1634+ // draw the relationship twice: once as a chip, once as the count.
1635+ {
1636+ let conn = self.conn.lock().await;
1637+ let mut rows = conn
1638+ .query(
1639+ "SELECT 1 FROM task WHERE (id = ?1 AND parent_id = ?2) \
1640+ OR (id = ?2 AND parent_id = ?1) LIMIT 1",
1641+ params![blocked_task_id, blocking_task_id],
1642+ )
1643+ .await
1644+ .map_err(backend)?;
1645+ let related = rows.next().await.map_err(backend)?.is_some();
1646+ if related {
1647+ return Err(StoreError::Cycle);
1648+ }
1649+ }
1650+
16311651 let mut conn = self.tx_conn().await?;
16321652 // IMMEDIATE: the reachability read and the insert that invalidates it
16331653 // must not be interleaved with another writer's pair, or two adds each
@@ -2196,6 +2216,15 @@ impl Store for TursoStore {
21962216 params![task_id, stamp.clone()],
21972217 )
21982218 .await?;
2219+ // The parts go with the whole, in the same write. A subtask that
2220+ // outlived its parent would be unreachable: the board does not
2221+ // show it, and the page that did is gone.
2222+ tx.execute(
2223+ "UPDATE task SET deleted_at = ?2, updated_at = ?2 \
2224+ WHERE parent_id = ?1 AND deleted_at IS NULL",
2225+ params![task_id, stamp.clone()],
2226+ )
2227+ .await?;
21992228 let deleted_activity_id = Ulid::new().to_string();
22002229 tx.execute(
22012230 "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \
@@ -2324,17 +2353,20 @@ impl Store for TursoStore {
23242353 ON t.id = CASE WHEN d.blocked_task_id = ?1 \
23252354 THEN d.blocking_task_id ELSE d.blocked_task_id END \
23262355 WHERE (d.blocked_task_id = ?1 OR d.blocking_task_id = ?1) \
2327- AND d.cleared_at IS NULL AND t.deleted_at IS NULL)",
2356+ AND d.cleared_at IS NULL AND t.deleted_at IS NULL), \
2357+ (SELECT COUNT(*) FROM task \
2358+ WHERE parent_id = ?1 AND deleted_at IS NULL)",
23282359 params![task_id],
23292360 )
23302361 .await
23312362 .map_err(backend)?;
2332- let (comment_count, link_count) = match rows.next().await.map_err(backend)? {
2363+ let (comment_count, link_count, subtask_count) = match rows.next().await.map_err(backend)? {
23332364 Some(row) => (
23342365 row.get::<i64>(0).map_err(backend)?.max(0) as u32,
23352366 row.get::<i64>(1).map_err(backend)?.max(0) as u32,
2367+ row.get::<i64>(2).map_err(backend)?.max(0) as u32,
23362368 ),
2337- None => (0, 0),
2369+ None => (0, 0, 0),
23382370 };
23392371 drop(rows);
23402372
@@ -2366,6 +2398,7 @@ impl Store for TursoStore {
23662398 comment_count,
23672399 link_count,
23682400 frees,
2401+ subtask_count,
23692402 }))
23702403 }
23712404
@@ -3289,7 +3322,7 @@ impl DetailReads for TursoStore {
32893322 let row = self
32903323 .one_row(
32913324 "SELECT t.id, t.task_key, t.title, t.column_id, t.deadline, t.position, \
3292- t.done_at, t.description, t.board_id, b.workspace_id \
3325+ t.done_at, t.description, t.board_id, b.workspace_id, t.parent_id \
32933326 FROM task t JOIN board b ON b.id = t.board_id \
32943327 WHERE t.id = ?1 AND t.deleted_at IS NULL",
32953328 params![task_id],
@@ -3305,6 +3338,7 @@ impl DetailReads for TursoStore {
33053338 deadline: opt_day(&row, 4)?,
33063339 position: row.get::<f64>(5).map_err(backend)?,
33073340 done_at: opt_stamp(&row, 6)?,
3341+ parent_id: opt_text(&row, 10)?,
33083342 },
33093343 description: text(&row, 7)?,
33103344 board_id: text(&row, 8)?,
@@ -3486,6 +3520,65 @@ impl DetailReads for TursoStore {
34863520 }
34873521 Ok(out)
34883522 }
3523+
3524+ async fn family_for_task(&self, task_id: &str) -> Result<Vec<(bool, SubtaskLine)>> {
3525+ let conn = self.conn.lock().await;
3526+ // One query for both directions, and one for the assignees too: the
3527+ // LEFT JOIN repeats a task's row once per person it points at, and the
3528+ // fold below puts them back together. A task detail is not allowed to
3529+ // cost a query per subtask.
3530+ let mut rows = conn
3531+ .query(
3532+ "SELECT t.id, t.task_key, t.title, t.column_id, t.done_at, t.parent_id, \
3533+ u.id, u.display_name, (u.photo IS NOT NULL) \
3534+ FROM task t \
3535+ LEFT JOIN task_assignee a ON a.task_id = t.id \
3536+ LEFT JOIN user u ON u.id = a.user_id \
3537+ WHERE t.deleted_at IS NULL AND ( \
3538+ t.parent_id = ?1 \
3539+ OR t.id = (SELECT parent_id FROM task WHERE id = ?1) \
3540+ ) \
3541+ ORDER BY t.created_at, u.display_name",
3542+ params![task_id],
3543+ )
3544+ .await
3545+ .map_err(backend)?;
3546+
3547+ let mut out: Vec<(bool, SubtaskLine)> = Vec::new();
3548+ while let Some(row) = rows.next().await.map_err(backend)? {
3549+ let id = text(&row, 0)?;
3550+ // A row whose parent is the task we asked about is one of its
3551+ // parts; anything else this query can return is the parent.
3552+ let is_parent = opt_text(&row, 5)?.as_deref() != Some(task_id);
3553+ let person = match opt_text(&row, 6)? {
3554+ Some(user_id) => Some(Person {
3555+ id: user_id,
3556+ display_name: text(&row, 7)?,
3557+ has_photo: row.get::<i64>(8).map_err(backend)? != 0,
3558+ }),
3559+ None => None,
3560+ };
3561+ match out.last_mut() {
3562+ Some((_, line)) if line.id == id => {
3563+ if let Some(person) = person {
3564+ line.assignees.push(person);
3565+ }
3566+ }
3567+ _ => out.push((
3568+ is_parent,
3569+ SubtaskLine {
3570+ id,
3571+ task_key: text(&row, 1)?,
3572+ title: text(&row, 2)?,
3573+ column_id: text(&row, 3)?,
3574+ done_at: opt_stamp(&row, 4)?,
3575+ assignees: person.into_iter().collect(),
3576+ },
3577+ )),
3578+ }
3579+ }
3580+ Ok(out)
3581+ }
34893582 }
34903583
34913584 #[async_trait]
@@ -3534,7 +3627,7 @@ impl BoardReads for TursoStore {
35343627 let conn = self.conn.lock().await;
35353628 let mut rows = conn
35363629 .query(
3537- "SELECT id, task_key, title, column_id, deadline, position, done_at \
3630+ "SELECT id, task_key, title, column_id, deadline, position, done_at, parent_id \
35383631 FROM task WHERE board_id = ?1 AND deleted_at IS NULL",
35393632 params![board_id],
35403633 )
@@ -3550,6 +3643,7 @@ impl BoardReads for TursoStore {
35503643 deadline: opt_day(&row, 4)?,
35513644 position: row.get::<f64>(5).map_err(backend)?,
35523645 done_at: opt_stamp(&row, 6)?,
3646+ parent_id: opt_text(&row, 7)?,
35533647 });
35543648 }
35553649 Ok(out)
crates/izlek-core/tests/store.rsmodified+191 -5
@@ -404,6 +404,170 @@ async fn a_promoted_subtask_stops_holding_its_parent() {
404404 moved_to(&scratch.store, &workspace, &parent, "Backlog", "Done", &admin).await;
405405 }
406406
407+#[tokio::test]
408+async fn the_board_counts_subtasks_instead_of_carding_them() {
409+ let scratch = Scratch::open().await;
410+ let (workspace, admin) = claim(&scratch.store).await;
411+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
412+
413+ let board = load(&scratch.store, &workspace).await.unwrap().unwrap();
414+ let cards: Vec<&izlek_core::board::TaskCard> =
415+ board.columns.iter().flat_map(|c| &c.cards).collect();
416+ assert_eq!(cards.len(), 1, "the subtask took a card of its own");
417+ assert_eq!(cards[0].id, parent);
418+ assert_eq!(cards[0].subtask_total, 1);
419+ assert_eq!(cards[0].subtask_done, 0);
420+ assert_eq!(cards[0].subtask_label().as_deref(), Some("0/1"));
421+ assert!(cards[0].holds_on_subtasks());
422+
423+ moved_to(&scratch.store, &workspace, &child, "Backlog", "Done", &admin).await;
424+ let board = load(&scratch.store, &workspace).await.unwrap().unwrap();
425+ let card = board
426+ .columns
427+ .iter()
428+ .flat_map(|c| &c.cards)
429+ .find(|card| card.id == parent)
430+ .unwrap();
431+ assert_eq!(card.subtask_label().as_deref(), Some("1/1"));
432+ assert!(!card.holds_on_subtasks());
433+}
434+
435+#[tokio::test]
436+async fn a_card_with_no_parts_wears_no_chip() {
437+ let scratch = Scratch::open().await;
438+ let (workspace, admin) = claim(&scratch.store).await;
439+ add_task(&scratch.store, &workspace, "Backlog", "Alone", None, &admin).await;
440+
441+ let board = load(&scratch.store, &workspace).await.unwrap().unwrap();
442+ let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap();
443+ assert_eq!(card.subtask_label(), None);
444+ assert!(!card.holds_on_subtasks());
445+}
446+
447+#[tokio::test]
448+async fn a_subtask_blocking_a_card_still_names_itself_on_it() {
449+ let scratch = Scratch::open().await;
450+ let (workspace, admin) = claim(&scratch.store).await;
451+ let (_parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
452+ let other = add_task(&scratch.store, &workspace, "Backlog", "Waiting", None, &admin).await;
453+ scratch
454+ .store
455+ .add_dependency(&other, &child, OffsetDateTime::now_utc())
456+ .await
457+ .unwrap();
458+
459+ // The subtask has no card, but its key is real and the chip has to show
460+ // it: dropping the row would leave the blocked card looking free.
461+ let board = load(&scratch.store, &workspace).await.unwrap().unwrap();
462+ let waiting = board
463+ .columns
464+ .iter()
465+ .flat_map(|c| &c.cards)
466+ .find(|card| card.id == other)
467+ .unwrap();
468+ assert_eq!(waiting.blocked_by.len(), 1);
469+ assert!(waiting.is_blocked());
470+}
471+
472+#[tokio::test]
473+async fn a_parent_and_its_own_part_are_not_linked_as_well() {
474+ let scratch = Scratch::open().await;
475+ let (workspace, admin) = claim(&scratch.store).await;
476+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
477+ let now = OffsetDateTime::now_utc();
478+
479+ assert!(matches!(
480+ scratch.store.add_dependency(&parent, &child, now).await,
481+ Err(StoreError::Cycle)
482+ ));
483+ assert!(matches!(
484+ scratch.store.add_dependency(&child, &parent, now).await,
485+ Err(StoreError::Cycle)
486+ ));
487+}
488+
489+#[tokio::test]
490+async fn a_task_detail_carries_its_family_both_ways() {
491+ let scratch = Scratch::open().await;
492+ let (workspace, admin) = claim(&scratch.store).await;
493+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
494+ scratch.store.assign_task(&child, &admin).await.unwrap();
495+
496+ let whole = load_detail(&scratch.store, &workspace, &parent)
497+ .await
498+ .unwrap()
499+ .unwrap();
500+ assert!(whole.parent.is_none());
501+ assert_eq!(whole.subtasks.len(), 1);
502+ assert_eq!(whole.subtasks[0].id, child);
503+ assert_eq!(whole.subtasks[0].assignees.len(), 1);
504+ assert!(!whole.subtasks[0].is_done());
505+
506+ let part = load_detail(&scratch.store, &workspace, &child)
507+ .await
508+ .unwrap()
509+ .unwrap();
510+ assert_eq!(part.parent.as_ref().unwrap().id, parent);
511+ assert!(
512+ part.subtasks.is_empty(),
513+ "a subtask has no parts of its own"
514+ );
515+}
516+
517+#[tokio::test]
518+async fn deleting_a_parent_says_what_it_takes_and_takes_it() {
519+ let scratch = Scratch::open().await;
520+ let (workspace, admin) = claim(&scratch.store).await;
521+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
522+
523+ let cost = scratch
524+ .store
525+ .deletion_cost(&parent)
526+ .await
527+ .unwrap()
528+ .expect("the parent is there to delete");
529+ assert_eq!(cost.subtask_count, 1);
530+
531+ scratch
532+ .store
533+ .delete_task(&parent, &admin, OffsetDateTime::now_utc())
534+ .await
535+ .unwrap();
536+
537+ // The part went with the whole, in the same write. A subtask that
538+ // outlived its parent would be unreachable.
539+ assert!(
540+ load_detail(&scratch.store, &workspace, &child)
541+ .await
542+ .unwrap()
543+ .is_none()
544+ );
545+ let board = load(&scratch.store, &workspace).await.unwrap().unwrap();
546+ assert_eq!(board.columns.iter().flat_map(|c| &c.cards).count(), 0);
547+}
548+
549+#[tokio::test]
550+async fn deleting_a_subtask_leaves_its_parent_standing() {
551+ let scratch = Scratch::open().await;
552+ let (workspace, admin) = claim(&scratch.store).await;
553+ let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await;
554+
555+ scratch
556+ .store
557+ .delete_task(&child, &admin, OffsetDateTime::now_utc())
558+ .await
559+ .unwrap();
560+
561+ let whole = load_detail(&scratch.store, &workspace, &parent)
562+ .await
563+ .unwrap()
564+ .unwrap();
565+ assert!(whole.subtasks.is_empty());
566+ let board = load(&scratch.store, &workspace).await.unwrap().unwrap();
567+ let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap();
568+ assert_eq!(card.subtask_label(), None);
569+}
570+
407571 #[tokio::test]
408572 async fn the_first_account_owns_the_workspace() {
409573 let scratch = Scratch::open().await;
@@ -2553,6 +2717,14 @@ impl DetailReads for CountingDetail<'_> {
25532717 self.tick();
25542718 self.inner.activity_for_task(task_id).await
25552719 }
2720+
2721+ async fn family_for_task(
2722+ &self,
2723+ task_id: &str,
2724+ ) -> Result<Vec<(bool, izlek_core::detail::SubtaskLine)>, StoreError> {
2725+ self.tick();
2726+ self.inner.family_for_task(task_id).await
2727+ }
25562728 }
25572729
25582730 #[tokio::test]
@@ -2867,7 +3039,7 @@ async fn saving_a_task_records_only_what_changed() {
28673039 }
28683040
28693041 #[tokio::test]
2870-async fn a_task_detail_costs_eight_queries_whatever_it_carries() {
3042+async fn a_task_detail_costs_nine_queries_whatever_it_carries() {
28713043 let (scratch, workspace, admin) = workspace_with_admin().await;
28723044 let store = &scratch.store;
28733045 let now = OffsetDateTime::now_utc();
@@ -2875,11 +3047,12 @@ async fn a_task_detail_costs_eight_queries_whatever_it_carries() {
28753047 let bare = add_task(store, &workspace, "Backlog", "bare", None, &admin).await;
28763048 let counted = CountingDetail::new(store);
28773049 load_detail(&counted, &workspace, &bare).await.unwrap();
2878- assert_eq!(counted.count(), 8, "a task with nothing hung off it");
3050+ assert_eq!(counted.count(), 9, "a task with nothing hung off it");
28793051
28803052 // Twenty comments, twenty activity lines, twenty people who could be
2881- // assigned and twenty tasks on the other end of a dependency — the four
2882- // things a naive detail query fans out on.
3053+ // assigned, twenty tasks on the other end of a dependency and twenty
3054+ // subtasks each with an assignee — the things a naive detail query fans
3055+ // out on.
28833056 let heavy = add_task(store, &workspace, "Backlog", "heavy", None, &admin).await;
28843057 for n in 0..20 {
28853058 let person = store
@@ -2910,6 +3083,10 @@ async fn a_task_detail_costs_eight_queries_whatever_it_carries() {
29103083 let neighbour =
29113084 add_task(store, &workspace, "Backlog", &format!("n{n}"), None, &admin).await;
29123085 store.add_dependency(&neighbour, &heavy, now).await.unwrap();
3086+
3087+ let part = add_task(store, &workspace, "Backlog", &format!("p{n}"), None, &admin).await;
3088+ store.set_parent(&part, Some(&heavy)).await.unwrap();
3089+ store.assign_task(&part, &person.id).await.unwrap();
29133090 }
29143091
29153092 let counted = CountingDetail::new(store);
@@ -2920,12 +3097,21 @@ async fn a_task_detail_costs_eight_queries_whatever_it_carries() {
29203097 assert_eq!(detail.comments.len(), 20);
29213098 assert_eq!(detail.assignees.len(), 20);
29223099 assert_eq!(detail.blocks.len(), 20);
3100+ assert_eq!(detail.subtasks.len(), 20);
3101+ assert!(detail.parent.is_none());
3102+ assert!(
3103+ detail
3104+ .subtasks
3105+ .iter()
3106+ .all(|part| part.assignees.len() == 1),
3107+ "a subtask row carries who holds it"
3108+ );
29233109 // Twenty comments (each its own Commented line), twenty moves, plus the
29243110 // line create_task wrote.
29253111 assert_eq!(detail.activity.len(), 41);
29263112 assert_eq!(
29273113 counted.count(),
2928- 8,
3114+ 9,
29293115 "the round trips a detail costs must not follow what it carries"
29303116 );
29313117 }
crates/izlek-web/src/board.rsmodified+7 -0
@@ -343,6 +343,8 @@ async fn render_card(
343343 None => t(lang, Key::NoDeadline).to_string(),
344344 };
345345 let comments = card.comment_count;
346+ let subtasks = card.subtask_label();
347+ let subtasks_open = card.holds_on_subtasks();
346348 let mut assignees = Vec::new();
347349 for person in card.assignees.iter() {
348350 assignees.push(crate::layout::avatar(cx, person, "").await?);
@@ -377,6 +379,9 @@ async fn render_card(
377379 <span class="card-deadline" class:card-deadline-overdue=(overdue) class:card-deadline-none=(!dated)>
378380 (deadline)
379381 </span>
382+ if let Some(parts) = subtasks.clone() {
383+ <span class="card-subtasks" class:card-subtasks-open=(subtasks_open)>(format!("{parts} \u{2630}"))</span>
384+ }
380385 if comments > 0 { <span class="card-comments">(format!("{comments} \u{270e}"))</span> }
381386 <div class="spacer"></div>
382387 <div class="avatars">
@@ -620,6 +625,8 @@ mod sort_tests {
620625 comment_count: 0,
621626 blocked_by: Vec::new(),
622627 blocks: Vec::new(),
628+ subtask_total: 0,
629+ subtask_done: 0,
623630 }
624631 }
625632
crates/izlek-web/src/detail.rsmodified+271 -1
@@ -77,6 +77,10 @@ pub struct DetailSnapshot {
7777 /// shift into this, the same as `/logs` does.
7878 pub zone: UtcOffset,
7979 pub linkable: Vec<LinkTarget>,
80+ /// Tasks this one could take in as parts: the board's other top-level
81+ /// tasks that have no parts of their own. Empty when this task is itself
82+ /// a part — subtasks go one level deep.
83+ pub adoptable: Vec<LinkTarget>,
8084 pub may_write: bool,
8185 pub may_comment: bool,
8286 pub may_delete: bool,
@@ -234,6 +238,21 @@ struct LinkForm {
234238 direction: Direction,
235239 }
236240
241+#[derive(Deserialize)]
242+struct NewSubtaskForm {
243+ parent_id: String,
244+ title: String,
245+}
246+
247+#[derive(Deserialize)]
248+struct ParentForm {
249+ task_id: String,
250+ /// Empty means "let it out": the same form both ways, because parenting
251+ /// and promoting are the same single write.
252+ #[serde(default)]
253+ parent_id: String,
254+}
255+
237256 #[derive(Deserialize)]
238257 struct CommentForm {
239258 task_id: String,
@@ -272,6 +291,7 @@ async fn load_snapshot(
272291 // already on either end of a live link with this one. A cleared edge is
273292 // not a link any more, so its task comes back to the picker.
274293 let mut linkable = Vec::new();
294+ let mut adoptable = Vec::new();
275295 if let Some(board) = store.board(&user.workspace_id).await? {
276296 let taken: Vec<&str> = detail
277297 .blocked_by
@@ -280,7 +300,28 @@ async fn load_snapshot(
280300 .filter(|edge| edge.cleared_at.is_none())
281301 .map(|edge| edge.task_id.as_str())
282302 .collect();
283- for task in store.tasks_for_board(&board.id).await? {
303+ let tasks = store.tasks_for_board(&board.id).await?;
304+ // Who already has parts, so the picker does not offer a task whose
305+ // own children would become grandchildren.
306+ let parents: Vec<&str> = tasks
307+ .iter()
308+ .filter_map(|task| task.parent_id.as_deref())
309+ .collect();
310+ for task in &tasks {
311+ let is_self = task.id == detail.id;
312+ if detail.parent.is_none()
313+ && !is_self
314+ && task.parent_id.is_none()
315+ && !parents.contains(&task.id.as_str())
316+ {
317+ adoptable.push(LinkTarget {
318+ id: task.id.clone(),
319+ task_key: task.task_key.clone(),
320+ title: task.title.clone(),
321+ });
322+ }
323+ }
324+ for task in tasks {
284325 if task.id == detail.id || taken.contains(&task.id.as_str()) {
285326 continue;
286327 }
@@ -290,6 +331,7 @@ async fn load_snapshot(
290331 title: task.title,
291332 });
292333 }
334+ adoptable.sort_by(|a, b| a.id.cmp(&b.id));
293335 // Sorted by id, not `task_key`: the key's tail is a random ULID
294336 // suffix now, not a counter, so only the id (a ULID itself) still
295337 // orders these by creation time.
@@ -375,6 +417,7 @@ async fn load_snapshot(
375417 Ok(Ok(DetailSnapshot {
376418 detail,
377419 linkable,
420+ adoptable,
378421 may_write,
379422 may_comment: user.role.can_comment(),
380423 may_delete: may_write,
@@ -588,6 +631,104 @@ async fn unlink_tasks(cx: &Cx, Form(input): Form<LinkForm>) -> Redirect {
588631 redirect(cx, None)
589632 }
590633
634+/// Opens a new task already filed under this one. It starts in the board's
635+/// first column, the way a card dropped on the board's first column would.
636+#[route(POST "/api/create_subtask")]
637+async fn create_subtask(cx: &Cx, Form(input): Form<NewSubtaskForm>) -> Redirect {
638+ use izlek_core::store::NewTask;
639+
640+ let (actor, parent) = match writer_and_task(cx, &input.parent_id).await {
641+ Ok(pair) => pair,
642+ Err(refusal) => return redirect(cx, Some(refusal)),
643+ };
644+ let title = input.title.trim();
645+ if title.is_empty() {
646+ return redirect(cx, Some(Refusal::EmptyTitle));
647+ }
648+ let store = accounts(cx).store().clone();
649+ let columns = store.columns(&parent.board_id).await?;
650+ let Some(first) = columns.iter().min_by_key(|column| column.position) else {
651+ return redirect(cx, Some(Refusal::NotFound));
652+ };
653+ let created = match store
654+ .create_task(NewTask {
655+ board_id: &parent.board_id,
656+ column_id: &first.id,
657+ parent_id: Some(&input.parent_id),
658+ title,
659+ description: "",
660+ deadline: None,
661+ created_by: &actor.id,
662+ })
663+ .await
664+ {
665+ Ok(created) => created,
666+ Err(StoreError::NotNestable) => return redirect(cx, Some(Refusal::NotNestable)),
667+ Err(error) => return Err(error.into()),
668+ };
669+ mail(cx).after_activity(store.clone(), created.activity_id);
670+ mail(cx).after(created.transition);
671+ redirect(cx, None)
672+}
673+
674+/// Files a task under another one, or lets it out again — an empty
675+/// `parent_id` is the second. One handler, because it is one write.
676+#[route(POST "/api/set_parent")]
677+async fn set_parent(cx: &Cx, Form(input): Form<ParentForm>) -> Redirect {
678+ use izlek_core::detail::ActivityKind;
679+ use time::OffsetDateTime;
680+
681+ let (actor, task) = match writer_and_task(cx, &input.task_id).await {
682+ Ok(pair) => pair,
683+ Err(refusal) => return redirect(cx, Some(refusal)),
684+ };
685+ let store = accounts(cx).store().clone();
686+ let wanted = input.parent_id.trim();
687+
688+ // Whichever end is not the task itself has to be a task this person may
689+ // see, so the key the activity line names is one they already have.
690+ let (parent_id, other_key) = if wanted.is_empty() {
691+ let Some(had) = task.row.parent_id.clone() else {
692+ return redirect(cx, None);
693+ };
694+ match task_of(store.as_ref(), &actor, &had).await {
695+ Ok(facts) => (None, facts.row.task_key),
696+ Err(refusal) => return redirect(cx, Some(refusal)),
697+ }
698+ } else {
699+ match task_of(store.as_ref(), &actor, wanted).await {
700+ Ok(facts) => (Some(facts.row.id.clone()), facts.row.task_key),
701+ Err(refusal) => return redirect(cx, Some(refusal)),
702+ }
703+ };
704+
705+ match store.set_parent(&input.task_id, parent_id.as_deref()).await {
706+ Ok(()) => {}
707+ Err(StoreError::NotNestable) => return redirect(cx, Some(Refusal::NotNestable)),
708+ Err(StoreError::OtherBoard) => return redirect(cx, Some(Refusal::Forbidden)),
709+ Err(StoreError::Cycle) => return redirect(cx, Some(Refusal::Cycle)),
710+ Err(StoreError::NotFound) => return redirect(cx, Some(Refusal::NotFound)),
711+ Err(error) => return Err(error.into()),
712+ }
713+
714+ let kind = if parent_id.is_some() {
715+ ActivityKind::Parented
716+ } else {
717+ ActivityKind::Unparented
718+ };
719+ let activity_id = store
720+ .record_activity(
721+ &input.task_id,
722+ Some(&actor.id),
723+ &kind,
724+ &other_key,
725+ OffsetDateTime::now_utc(),
726+ )
727+ .await?;
728+ mail(cx).after_activity(store, activity_id);
729+ redirect(cx, None)
730+}
731+
591732 /// Writes a comment. The author is the session's user; there is no author
592733 /// field on the form. A Viewer is refused here, not merely shown no textarea.
593734 #[route(POST "/api/post_comment")]
@@ -1231,6 +1372,88 @@ async fn link_picker(cx: &Cx, task_id: &str, linkable: &[LinkTarget], lang: Lang
12311372 }
12321373 }
12331374
1375+/// One part on its parent's page: its key, its title, who holds it, and the
1376+/// button that lets it out. The status is the column's name, read off the
1377+/// board's columns the page already has.
1378+async fn subtask_row(
1379+ cx: &Cx,
1380+ part: &izlek_core::detail::SubtaskLine,
1381+ columns: &[izlek_core::Column],
1382+ may_write: bool,
1383+ lang: Lang,
1384+) -> Result {
1385+ let done = part.is_done();
1386+ let status = columns
1387+ .iter()
1388+ .find(|column| column.id == part.column_id)
1389+ .map(|column| column.name.clone())
1390+ .unwrap_or_default();
1391+ let href = format!("/?task={}", part.id);
1392+ let release_title = t(lang, Key::ReleaseThisPart);
1393+ let mut faces = Vec::new();
1394+ for person in &part.assignees {
1395+ faces.push(crate::layout::avatar(cx, person, "").await?);
1396+ }
1397+ view! {
1398+ cx =>
1399+ <div class=(class!("dep-row", "subtask-row-done" if done))>
1400+ if done { (glyph::tick(cx).await?) } else { (glyph::lock(cx).await?) }
1401+ <a class="dep-key" href=(href.clone())>(part.task_key.clone())</a>
1402+ <a class="dep-title" href=(href)>(part.title.clone())</a>
1403+ <div class="spacer"></div>
1404+ <span class="dep-note">(status)</span>
1405+ <div class="avatars">
1406+ for face in faces { (face) }
1407+ </div>
1408+ if may_write {
1409+ <form class="dep-unlink-form" method="post" action="/api/set_parent">
1410+ <input type="hidden" name="task_id" value=(part.id.clone())>
1411+ <input type="hidden" name="parent_id" value="">
1412+ <button class="dep-unlink" type="submit" title=(release_title)>(glyph::cross(cx).await?)</button>
1413+ </form>
1414+ }
1415+ </div>
1416+ }
1417+}
1418+
1419+/// Takes an existing task in as a part. The same shape as `link_picker`, and
1420+/// absent for the same reason: with nothing to offer it shows nothing.
1421+async fn adopt_picker(cx: &Cx, task_id: &str, adoptable: &[LinkTarget], lang: Lang) -> Result {
1422+ if adoptable.is_empty() {
1423+ return view! { cx => };
1424+ }
1425+ let toggle = format!("adopt-{task_id}");
1426+ let aria = t(lang, Key::MakeAPart);
1427+ view! {
1428+ cx =>
1429+ <div class="edit edit-pop link-pop">
1430+ <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label=(aria)>
1431+ <label class="dep-chip edit-view edit-hit" for=(toggle.clone())>
1432+ (glyph::plus(cx).await?)
1433+ <span class="dep-chip-text">(t(lang, Key::MakeAPart))</span>
1434+ </label>
1435+ <div class="edit-form pop-panel pop-panel-wide">
1436+ <form class="pop-form" method="post" action="/api/set_parent">
1437+ <input type="hidden" name="parent_id" value=(task_id.to_string())>
1438+ <div class="pop-list pop-list-scroll">
1439+ for target in adoptable {
1440+ <label class="pick-row">
1441+ <input type="radio" name="task_id" value=(target.id.clone()) required="">
1442+ <span class="dep-key">(target.task_key.clone())</span>
1443+ <span class="pick-title">(target.title.clone())</span>
1444+ </label>
1445+ }
1446+ </div>
1447+ <div class="edit-row">
1448+ <button class="edit-save" type="submit">(t(lang, Key::ExistingTask))</button>
1449+ <label class="edit-cancel" for=(toggle)>(t(lang, Key::Cancel))</label>
1450+ </div>
1451+ </form>
1452+ </div>
1453+ </div>
1454+ }
1455+}
1456+
12341457 async fn dep_row(
12351458 cx: &Cx,
12361459 task_id: &str,
@@ -1402,6 +1625,7 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab)
14021625 today,
14031626 zone,
14041627 linkable,
1628+ adoptable,
14051629 may_write,
14061630 may_comment,
14071631 may_delete,
@@ -1413,6 +1637,7 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab)
14131637 let lang = Lang::from_code(&me.language);
14141638
14151639 let unassigned: Vec<Person> = detail.unassigned().cloned().collect();
1640+ let done_parts = detail.subtasks.iter().filter(|part| part.is_done()).count();
14161641 let has_deps = !detail.blocked_by.is_empty() || !detail.blocks.is_empty();
14171642 let accept = (!allowed_file_types.is_empty())
14181643 .then(|| {
@@ -1443,6 +1668,11 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab)
14431668 <div class="detail-mast">
14441669 <header class="detail-head">
14451670 <div class="detail-headline">
1671+ if let Some(parent) = detail.parent.clone() {
1672+ <a class="detail-parent" href=(format!("/?task={}", parent.id))>
1673+ (format!("{} {}", t(lang, Key::PartOf), parent.task_key))
1674+ </a>
1675+ }
14461676 <span class="detail-key">(detail.task_key.clone())</span>
14471677 (title_control(cx, &detail, may_write, lang).await?)
14481678 </div>
@@ -1557,6 +1787,43 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab)
15571787 if tab == Tab::Task {
15581788
15591789
1790+ if detail.parent.is_none() {
1791+ <section class="detail-block">
1792+ <div class="detail-block-head">
1793+ <span class="detail-label">(t(lang, Key::Subtasks))</span>
1794+ if !detail.subtasks.is_empty() {
1795+ <span class="detail-count">(format!("{}/{}", done_parts, detail.subtasks.len()))</span>
1796+ }
1797+ <div class="spacer"></div>
1798+ if may_write {
1799+ (adopt_picker(cx, &detail.id, &adoptable, lang).await?)
1800+ }
1801+ </div>
1802+ if may_write {
1803+ <form class="subtask-new" method="post" action="/api/create_subtask">
1804+ <input type="hidden" name="parent_id" value=(detail.id.clone())>
1805+ <label class="field-box subtask-new-box">
1806+ (glyph::plus(cx).await?)
1807+ <input class="field-input" type="text" name="title"
1808+ placeholder=(t(lang, Key::NewSubtask)) required="" maxlength="200">
1809+ </label>
1810+ <button class="edit-save" type="submit">(t(lang, Key::AddSubtask))</button>
1811+ </form>
1812+ }
1813+ (refused(cx, "create_subtask", lang).await?)
1814+ (refused(cx, "set_parent", lang).await?)
1815+ if detail.subtasks.is_empty() {
1816+ <p class="detail-prose detail-prose-empty">(t(lang, Key::NoSubtasks))</p>
1817+ } else {
1818+ <div class="dep-list">
1819+ for part in &detail.subtasks {
1820+ (subtask_row(cx, part, &detail.columns, may_write, lang).await?)
1821+ }
1822+ </div>
1823+ }
1824+ </section>
1825+ }
1826+
15601827 <section class="detail-block">
15611828 <span class="detail-label">(t(lang, Key::Description))</span>
15621829 (description_control(cx, &detail, may_write, lang).await?)
@@ -1683,6 +1950,9 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab)
16831950 if cost.comment_count > 0 {
16841951 <li>(if cost.comment_count == 1 { t(lang, Key::CommentGoesWithIt).to_string() } else { format!("{} {}", cost.comment_count, t(lang, Key::CommentsGoWithIt)) })</li>
16851952 }
1953+ if cost.subtask_count > 0 {
1954+ <li>(if cost.subtask_count == 1 { t(lang, Key::SubtaskGoesWithIt).to_string() } else { format!("{} {}", cost.subtask_count, t(lang, Key::SubtasksGoWithIt)) })</li>
1955+ }
16861956 if cost.link_count > 0 {
16871957 <li>(if cost.link_count == 1 { t(lang, Key::DependencyStopsApplying).to_string() } else { format!("{} {}", cost.link_count, t(lang, Key::DependenciesStopApplying)) })</li>
16881958 }
crates/izlek-web/src/i18n.rsmodified+44 -0
@@ -283,6 +283,16 @@ pub enum Key {
283283 NoTasks,
284284 NoDescription,
285285 NoDependencies,
286+ Subtasks,
287+ SubtaskGoesWithIt,
288+ SubtasksGoWithIt,
289+ NoSubtasks,
290+ NewSubtask,
291+ AddSubtask,
292+ PartOf,
293+ MakeAPart,
294+ ReleaseThisPart,
295+ ExistingTask,
286296 DonePrefix,
287297 Clear,
288298 Today,
@@ -822,6 +832,26 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
822832 (NoDescription, Tr) => "açıklama yok",
823833 (NoDependencies, En) => "no dependencies",
824834 (NoDependencies, Tr) => "bağımlılık yok",
835+ (SubtaskGoesWithIt, En) => "its subtask goes with it",
836+ (SubtaskGoesWithIt, Tr) => "alt görevi de silinir",
837+ (SubtasksGoWithIt, En) => "subtasks go with it",
838+ (SubtasksGoWithIt, Tr) => "alt görevi de silinir",
839+ (Subtasks, En) => "Subtasks",
840+ (Subtasks, Tr) => "Alt görevler",
841+ (NoSubtasks, En) => "no subtasks",
842+ (NoSubtasks, Tr) => "alt görev yok",
843+ (NewSubtask, En) => "Subtask",
844+ (NewSubtask, Tr) => "Alt görev",
845+ (AddSubtask, En) => "Add",
846+ (AddSubtask, Tr) => "Ekle",
847+ (PartOf, En) => "Part of",
848+ (PartOf, Tr) => "Şunun parçası:",
849+ (MakeAPart, En) => "Take an existing task",
850+ (MakeAPart, Tr) => "Var olan görevi al",
851+ (ReleaseThisPart, En) => "Release this subtask",
852+ (ReleaseThisPart, Tr) => "Bu alt görevi serbest bırak",
853+ (ExistingTask, En) => "Take",
854+ (ExistingTask, Tr) => "Al",
825855 (DonePrefix, En) => "done ",
826856 (DonePrefix, Tr) => "bitti ",
827857 (Clear, En) => "Clear",
@@ -996,6 +1026,20 @@ pub fn linked_label(lang: Lang, detail: &str) -> String {
9961026 }
9971027 }
9981028
1029+pub fn parented_label(lang: Lang, detail: &str) -> String {
1030+ match lang {
1031+ Lang::En => format!("made this a part of {detail}"),
1032+ Lang::Tr => format!("bunu {detail} görevinin parçası yaptı"),
1033+ }
1034+}
1035+
1036+pub fn unparented_label(lang: Lang, detail: &str) -> String {
1037+ match lang {
1038+ Lang::En => format!("released this from {detail}"),
1039+ Lang::Tr => format!("bunu {detail} görevinden çıkardı"),
1040+ }
1041+}
1042+
9991043 pub fn unlinked_label(lang: Lang, detail: &str) -> String {
10001044 match lang {
10011045 Lang::En => format!("unlinked {detail}"),
crates/izlek-web/src/logs.rsmodified+2 -0
@@ -155,6 +155,8 @@ fn activity_sentence(kind: &izlek_core::detail::ActivityKind, detail: &str, lang
155155 ActivityKind::Unassigned => crate::i18n::unassigned_label(lang, detail),
156156 ActivityKind::Linked => crate::i18n::linked_label(lang, detail),
157157 ActivityKind::Unlinked => crate::i18n::unlinked_label(lang, detail),
158+ ActivityKind::Parented => crate::i18n::parented_label(lang, detail),
159+ ActivityKind::Unparented => crate::i18n::unparented_label(lang, detail),
158160 ActivityKind::Moved => crate::i18n::moved_label(lang, detail),
159161 ActivityKind::Unblocked => crate::i18n::unblocked_label(lang, detail),
160162 ActivityKind::Deleted => t(lang, Key::ActDeleted).to_string(),
crates/izlek-web/src/server.rsmodified+8 -0
@@ -365,6 +365,9 @@ pub enum Refusal {
365365 /// carries it, and a number cannot survive the round trip through the
366366 /// address bar that a browser without script makes.
367367 SubtasksOpen,
368+ /// Subtasks go one level deep: the task named as a parent is itself a
369+ /// part, or the task being filed already has parts of its own.
370+ NotNestable,
368371 /// No such task — or none this account may see. Deliberately one answer for
369372 /// both.
370373 NotFound,
@@ -415,6 +418,7 @@ impl Refusal {
415418 Refusal::Cycle => "That link would put this task behind itself.".to_string(),
416419 Refusal::MovedAlready => "Somebody moved this card first.".to_string(),
417420 Refusal::SubtasksOpen => "Subtasks are still open.".to_string(),
421+ Refusal::NotNestable => "Subtasks go one level deep.".to_string(),
418422 Refusal::NotFound => "No such task.".to_string(),
419423 Refusal::NoSuchMember => "No such member.".to_string(),
420424 Refusal::Unavailable => "Something went wrong.".to_string(),
@@ -445,6 +449,7 @@ impl Refusal {
445449 Refusal::Cycle => "Bu bağlantı görevi kendi arkasına koyar.".to_string(),
446450 Refusal::MovedAlready => "Bu kartı başka biri zaten taşıdı.".to_string(),
447451 Refusal::SubtasksOpen => "Alt görevler hâlâ açık.".to_string(),
452+ Refusal::NotNestable => "Alt görevler tek seviyedir.".to_string(),
448453 Refusal::NotFound => "Böyle bir görev yok.".to_string(),
449454 Refusal::NoSuchMember => "Böyle bir üye yok.".to_string(),
450455 Refusal::Unavailable => "Bir şeyler ters gitti.".to_string(),
@@ -520,6 +525,7 @@ impl Refusal {
520525 "cycle" => Refusal::Cycle,
521526 "moved-already" => Refusal::MovedAlready,
522527 "subtasks-open" => Refusal::SubtasksOpen,
528+ "not-nestable" => Refusal::NotNestable,
523529 "not-found" => Refusal::NotFound,
524530 "no-such-member" => Refusal::NoSuchMember,
525531 "unavailable" => Refusal::Unavailable,
@@ -574,6 +580,7 @@ impl Refusal {
574580 Refusal::Cycle => "cycle",
575581 Refusal::MovedAlready => "moved-already",
576582 Refusal::SubtasksOpen => "subtasks-open",
583+ Refusal::NotNestable => "not-nestable",
577584 Refusal::NotFound => "not-found",
578585 Refusal::NoSuchMember => "no-such-member",
579586 Refusal::Unavailable => "unavailable",
@@ -852,6 +859,7 @@ mod refusal_message_tests {
852859 Refusal::Cycle,
853860 Refusal::MovedAlready,
854861 Refusal::SubtasksOpen,
862+ Refusal::NotNestable,
855863 Refusal::NotFound,
856864 Refusal::NoSuchMember,
857865 Refusal::Unavailable,
crates/izlek-web/tests/http.rsmodified+203 -0
@@ -1429,6 +1429,209 @@ async fn a_card_with_open_subtasks_is_refused_the_done_column() {
14291429 );
14301430 }
14311431
1432+#[tokio::test]
1433+async fn a_subtask_is_opened_from_its_parents_page_and_shows_up_there() {
1434+ let app = App::open().await;
1435+ let admin = admin(&app).await;
1436+ let columns = columns_of(&app).await;
1437+ let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await;
1438+
1439+ let made = app
1440+ .post(
1441+ "/api/create_subtask",
1442+ Some(&admin),
1443+ &[("parent_id", &parent), ("title", "Write the CSV writer")],
1444+ )
1445+ .await;
1446+ assert_eq!(made.body, "null", "the subtask was refused: {}", made.body);
1447+
1448+ // The parent's page lists it; the board does not card it.
1449+ let page = app.get(&format!("/?task={parent}"), Some(&admin)).await;
1450+ let page = String::from_utf8_lossy(&page.bytes);
1451+ assert!(
1452+ page.contains("Write the CSV writer"),
1453+ "the subtask is not on its parent's page"
1454+ );
1455+
1456+ let workspace_id = app.workspace_id().await;
1457+ let board = izlek_core::board::load(app.store.as_ref(), &workspace_id)
1458+ .await
1459+ .unwrap()
1460+ .unwrap();
1461+ let cards: Vec<_> = board.columns.iter().flat_map(|c| &c.cards).collect();
1462+ assert_eq!(cards.len(), 1, "the subtask took a card of its own");
1463+ assert_eq!(cards[0].subtask_label().as_deref(), Some("0/1"));
1464+}
1465+
1466+#[tokio::test]
1467+async fn a_subtask_with_nothing_in_its_title_is_refused() {
1468+ let app = App::open().await;
1469+ let admin = admin(&app).await;
1470+ let columns = columns_of(&app).await;
1471+ let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await;
1472+
1473+ // Posted the way a browser without script does, so the refusal has to
1474+ // survive the round trip through the address bar.
1475+ let empty = app
1476+ .post_without_script(
1477+ "/api/create_subtask",
1478+ Some(&admin),
1479+ &format!("http://izlek.sh/?task={parent}"),
1480+ &[("parent_id", &parent), ("title", " ")],
1481+ )
1482+ .await;
1483+ assert!(
1484+ empty
1485+ .location
1486+ .as_deref()
1487+ .unwrap_or_default()
1488+ .contains("refusal=empty-title&on=create_subtask"),
1489+ "{:?}",
1490+ empty.location
1491+ );
1492+}
1493+
1494+#[tokio::test]
1495+async fn taking_a_task_in_and_letting_it_out_are_the_same_form() {
1496+ let app = App::open().await;
1497+ let admin = admin(&app).await;
1498+ let columns = columns_of(&app).await;
1499+ let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await;
1500+ let loose = a_task(&app, &admin, &columns[1], "Write the CSV writer").await;
1501+
1502+ let taken = app
1503+ .post(
1504+ "/api/set_parent",
1505+ Some(&admin),
1506+ &[("task_id", &loose), ("parent_id", &parent)],
1507+ )
1508+ .await;
1509+ assert_eq!(taken.body, "null", "taking it in was refused: {}", taken.body);
1510+ let workspace_id = app.workspace_id().await;
1511+ let board = izlek_core::board::load(app.store.as_ref(), &workspace_id)
1512+ .await
1513+ .unwrap()
1514+ .unwrap();
1515+ assert_eq!(board.columns.iter().flat_map(|c| &c.cards).count(), 1);
1516+
1517+ // The subtask kept its column: being taken in is not a move.
1518+ let page = app.get(&format!("/?task={loose}"), Some(&admin)).await;
1519+ let page = String::from_utf8_lossy(&page.bytes);
1520+ assert!(
1521+ page.contains("Part of"),
1522+ "the part does not name its whole"
1523+ );
1524+
1525+ let released = app
1526+ .post(
1527+ "/api/set_parent",
1528+ Some(&admin),
1529+ &[("task_id", &loose), ("parent_id", "")],
1530+ )
1531+ .await;
1532+ assert_eq!(released.body, "null", "letting it out was refused: {}", released.body);
1533+ let board = izlek_core::board::load(app.store.as_ref(), &workspace_id)
1534+ .await
1535+ .unwrap()
1536+ .unwrap();
1537+ assert_eq!(
1538+ board.columns.iter().flat_map(|c| &c.cards).count(),
1539+ 2,
1540+ "the released task did not come back to the board"
1541+ );
1542+}
1543+
1544+#[tokio::test]
1545+async fn a_second_level_of_subtask_is_refused_at_the_door() {
1546+ let app = App::open().await;
1547+ let admin = admin(&app).await;
1548+ let columns = columns_of(&app).await;
1549+ let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await;
1550+ let child = a_task(&app, &admin, &columns[0], "Write the CSV writer").await;
1551+ let loose = a_task(&app, &admin, &columns[0], "Loose").await;
1552+ app.store.set_parent(&child, Some(&parent)).await.unwrap();
1553+
1554+ let refused = app
1555+ .post_without_script(
1556+ "/api/create_subtask",
1557+ Some(&admin),
1558+ &format!("http://izlek.sh/?task={child}"),
1559+ &[("parent_id", &child), ("title", "Deeper")],
1560+ )
1561+ .await;
1562+ assert!(
1563+ refused
1564+ .location
1565+ .as_deref()
1566+ .unwrap_or_default()
1567+ .contains("refusal=not-nestable&on=create_subtask"),
1568+ "{:?}",
1569+ refused.location
1570+ );
1571+
1572+ let also_refused = app
1573+ .post_without_script(
1574+ "/api/set_parent",
1575+ Some(&admin),
1576+ &format!("http://izlek.sh/?task={child}"),
1577+ &[("task_id", &loose), ("parent_id", &child)],
1578+ )
1579+ .await;
1580+ assert!(
1581+ also_refused
1582+ .location
1583+ .as_deref()
1584+ .unwrap_or_default()
1585+ .contains("refusal=not-nestable&on=set_parent"),
1586+ "{:?}",
1587+ also_refused.location
1588+ );
1589+}
1590+
1591+#[tokio::test]
1592+async fn a_viewer_may_not_open_or_move_a_subtask() {
1593+ let app = App::open().await;
1594+ let admin = admin(&app).await;
1595+ let watcher = invited(&app, &admin, "kay@izlek.sh", "Kay Watcher", Role::Viewer).await;
1596+ let columns = columns_of(&app).await;
1597+ let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await;
1598+
1599+ let refused = app
1600+ .post_without_script(
1601+ "/api/create_subtask",
1602+ Some(&watcher),
1603+ &format!("http://izlek.sh/?task={parent}"),
1604+ &[("parent_id", &parent), ("title", "Not yours")],
1605+ )
1606+ .await;
1607+ assert!(
1608+ refused
1609+ .location
1610+ .as_deref()
1611+ .unwrap_or_default()
1612+ .contains("refusal=forbidden"),
1613+ "{:?}",
1614+ refused.location
1615+ );
1616+
1617+ let also = app
1618+ .post_without_script(
1619+ "/api/set_parent",
1620+ Some(&watcher),
1621+ &format!("http://izlek.sh/?task={parent}"),
1622+ &[("task_id", &parent), ("parent_id", "")],
1623+ )
1624+ .await;
1625+ assert!(
1626+ also.location
1627+ .as_deref()
1628+ .unwrap_or_default()
1629+ .contains("refusal=forbidden"),
1630+ "{:?}",
1631+ also.location
1632+ );
1633+}
1634+
14321635 #[tokio::test]
14331636 async fn a_drop_decided_against_a_stale_board_is_refused() {
14341637 let app = App::open().await;
style/main.scssmodified+40 -1
@@ -858,12 +858,17 @@ a {
858858 }
859859 }
860860
861-.card-comments {
861+.card-comments,
862+.card-subtasks {
862863 font-family: var(--font-mono);
863864 font-size: 11px;
864865 color: var(--muted);
865866 }
866867
868+/// Parts still open is the same warning the blocker chips carry: this card
869+/// cannot reach the done column yet.
870+.card-subtasks-open { color: var(--warn-ink); }
871+
867872 .avatars {
868873 display: flex;
869874 align-items: center;
@@ -1441,6 +1446,18 @@ img.avatar {
14411446 color: var(--muted-soft);
14421447 }
14431448
1449+// A subtask says whose part it is above its own key, so the page it opens on
1450+// still names the work it belongs to.
1451+.detail-parent {
1452+ display: block;
1453+ font-family: var(--font-mono);
1454+ font-size: 11px;
1455+ color: var(--muted);
1456+ text-decoration: none;
1457+
1458+ &:hover { color: var(--ink); }
1459+}
1460+
14441461 .detail-title {
14451462 margin: 0;
14461463 font-size: 18px;
@@ -1926,6 +1943,28 @@ img.avatar {
19261943 font-size: 13px;
19271944 }
19281945
1946+// A finished part reads back the way a finished card does: still there,
1947+// still legible, plainly no longer in the way.
1948+.subtask-row-done {
1949+ .dep-key,
1950+ .dep-title,
1951+ .dep-note { color: var(--muted-soft); }
1952+
1953+ .dep-title { text-decoration: line-through; }
1954+}
1955+
1956+.subtask-new {
1957+ display: flex;
1958+ align-items: center;
1959+ gap: 8px;
1960+ margin-bottom: 8px;
1961+}
1962+
1963+.subtask-new-box {
1964+ flex: 1;
1965+ min-width: 0;
1966+}
1967+
19291968 .dep-row-waiting {
19301969 background: var(--warn-tint-soft);
19311970 border-color: var(--warn-border);