From 9f8c3b79f954ce7b02fc467cd451d949bce6f9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 02:21:15 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=A9=20feat(web):=20a=20task=20shows=20?= =?UTF-8?q?its=20parts,=20and=20a=20part=20names=20its=20whole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 50 ++++ crates/izlek-core/src/detail.rs | 66 ++++- crates/izlek-core/src/mail.rs | 6 + crates/izlek-core/src/store/turso_store.rs | 106 +++++++- crates/izlek-core/tests/store.rs | 196 ++++++++++++++- crates/izlek-web/src/board.rs | 7 + crates/izlek-web/src/detail.rs | 272 ++++++++++++++++++++- crates/izlek-web/src/i18n.rs | 44 ++++ crates/izlek-web/src/logs.rs | 2 + crates/izlek-web/src/server.rs | 8 + crates/izlek-web/tests/http.rs | 203 +++++++++++++++ style/main.scss | 41 +++- 12 files changed, 983 insertions(+), 18 deletions(-) diff --git a/crates/izlek-core/src/board.rs b/crates/izlek-core/src/board.rs index ffa2d4f..74e53ef 100644 --- a/crates/izlek-core/src/board.rs +++ b/crates/izlek-core/src/board.rs @@ -37,6 +37,11 @@ pub struct TaskRow { pub deadline: Option, pub position: f64, pub done_at: Option, + /// The task this one is a subtask of. A row with a parent gets no card of + /// its own on the board — it is counted on its parent's instead — but it + /// is still read with the rest, because a key it owns can appear on + /// somebody else's card as a blocker. + pub parent_id: Option, } /// One card crossing from one column into another, as it was written. @@ -123,6 +128,10 @@ pub struct TaskCard { pub blocked_by: Vec, /// Keys of the tasks waiting on this one. pub blocks: Vec, + /// How many subtasks this card has, and how many of them are finished. + /// Both are zero for a card with none, which is what hides the chip. + pub subtask_total: u32, + pub subtask_done: u32, } impl TaskCard { @@ -130,6 +139,19 @@ impl TaskCard { self.done_at.is_some() } + /// The `2/5` the card wears, or nothing when the task has no parts. It is + /// also the only place the count appears when a move is refused, which is + /// why the refusal itself does not carry one. + pub fn subtask_label(&self) -> Option { + (self.subtask_total > 0) + .then(|| format!("{}/{}", self.subtask_done, self.subtask_total)) + } + + /// Whether finishing this card is currently refused. + pub fn holds_on_subtasks(&self) -> bool { + self.subtask_done < self.subtask_total + } + /// Blocked means something unfinished is in front of it. A finished task is /// never counted as blocked, whatever it still points at. pub fn is_blocked(&self) -> bool { @@ -306,13 +328,41 @@ pub fn assemble( } } + // A subtask is counted on its parent's card, never given one of its own. + let mut subtask_total: HashMap<&str, u32> = HashMap::new(); + let mut subtask_done: HashMap<&str, u32> = HashMap::new(); + for task in &tasks { + if let Some(parent) = task.parent_id.as_deref() { + *subtask_total.entry(parent).or_default() += 1; + if task.done_at.is_some() { + *subtask_done.entry(parent).or_default() += 1; + } + } + } + let subtask_total: HashMap = subtask_total + .into_iter() + .map(|(id, n)| (id.to_string(), n)) + .collect(); + let subtask_done: HashMap = subtask_done + .into_iter() + .map(|(id, n)| (id.to_string(), n)) + .collect(); + let mut cards: HashMap> = HashMap::new(); for task in tasks { + // Read with the rest so its key can appear as a blocker chip, but the + // board is a board of tasks: a subtask reaches its page through its + // parent's. + if task.parent_id.is_some() { + continue; + } let card = TaskCard { comment_count: counts.get(&task.id).copied().unwrap_or(0), assignees: people.remove(&task.id).unwrap_or_default(), blocked_by: blocked_by.remove(&task.id).unwrap_or_default(), blocks: blocks.remove(&task.id).unwrap_or_default(), + subtask_total: subtask_total.get(&task.id).copied().unwrap_or(0), + subtask_done: subtask_done.get(&task.id).copied().unwrap_or(0), id: task.id, task_key: task.task_key, title: task.title, diff --git a/crates/izlek-core/src/detail.rs b/crates/izlek-core/src/detail.rs index e2cad83..02b1dd6 100644 --- a/crates/izlek-core/src/detail.rs +++ b/crates/izlek-core/src/detail.rs @@ -99,6 +99,25 @@ impl FileLine { /// What deleting a task would take with it. The confirmation step says this /// out loud before the button fires. +/// One row in the subtask list on a task's page, and the "part of DZ-14" line +/// on a subtask's own page — the same shape both ways, because a subtask and +/// its parent are the same kind of thing. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct SubtaskLine { + pub id: String, + pub task_key: String, + pub title: String, + pub column_id: String, + pub done_at: Option, + pub assignees: Vec, +} + +impl SubtaskLine { + pub fn is_done(&self) -> bool { + self.done_at.is_some() + } +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct DeletionCost { pub task_key: String, @@ -108,6 +127,9 @@ pub struct DeletionCost { pub link_count: u32, /// Keys of the tasks that would have nothing in front of them afterwards. pub frees: Vec, + /// How many subtasks would go with it. A part has no meaning once the + /// whole is gone, so deleting a parent deletes them too. + pub subtask_count: u32, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -133,6 +155,10 @@ pub enum ActivityKind { Unassigned, Linked, Unlinked, + /// Filed under another task, and let out of it again. The detail is the + /// other task's key both ways. + Parented, + Unparented, Moved, Unblocked, Deleted, @@ -169,6 +195,8 @@ impl ActivityKind { pub fn as_str(&self) -> &str { match self { ActivityKind::Commented => "commented", + ActivityKind::Parented => "parented", + ActivityKind::Unparented => "unparented", ActivityKind::WorkspaceClaimed => "workspace_claimed", ActivityKind::Invited => "invited", ActivityKind::LinkResent => "link_resent", @@ -216,6 +244,8 @@ impl ActivityKind { "unassigned" => ActivityKind::Unassigned, "linked" => ActivityKind::Linked, "unlinked" => ActivityKind::Unlinked, + "parented" => ActivityKind::Parented, + "unparented" => ActivityKind::Unparented, "moved" => ActivityKind::Moved, "unblocked" => ActivityKind::Unblocked, "deleted" => ActivityKind::Deleted, @@ -272,6 +302,8 @@ impl ActivityEntry { ActivityKind::Unassigned => format!("unassigned {detail}"), ActivityKind::Linked => format!("linked {detail}"), ActivityKind::Unlinked => format!("unlinked {detail}"), + ActivityKind::Parented => format!("made this a part of {detail}"), + ActivityKind::Unparented => format!("released this from {detail}"), ActivityKind::Moved => format!("moved {detail}"), ActivityKind::Unblocked => format!("unblocked this task — {detail}"), ActivityKind::Deleted => "deleted this task".to_string(), @@ -412,6 +444,10 @@ pub struct TaskDetail { /// Files hung off this task, oldest first. pub files: Vec, pub activity: Vec, + /// The task this one is a part of, when it is one. + pub parent: Option, + /// The parts of this task, oldest first. Always empty for a subtask. + pub subtasks: Vec, } impl TaskDetail { @@ -483,7 +519,7 @@ pub use reads::{DetailReads, load}; mod reads { use async_trait::async_trait; - use super::{ActivityEntry, Comment, DependencyEdge, FileLine, TaskDetail, TaskFacts}; + use super::{ActivityEntry, Comment, DependencyEdge, FileLine, SubtaskLine, TaskDetail, TaskFacts}; use crate::board::{Column, Person}; use crate::store::Result; @@ -515,14 +551,21 @@ mod reads { async fn files_for_task(&self, task_id: &str) -> Result>; async fn activity_for_task(&self, task_id: &str) -> Result>; + + /// A task's parent and its subtasks in one read: `true` marks the + /// parent. One of the two is always empty — a subtask has a parent and + /// no children, a parent has children and no parent of its own — but + /// the query is the same either way, so it is one query either way. + async fn family_for_task(&self, task_id: &str) -> Result>; } - /// Loads one task detail in eight queries — the task, the board's columns, + /// Loads one task detail in nine queries — the task, the board's columns, /// its assignees, the workspace's writers, both directions of its - /// dependencies, its comments, its files and its activity. + /// dependencies, its comments, its files, its activity, and its family. /// - /// Eight, not eight-plus-one-per-comment: `a_task_detail_costs_eight_ - /// queries_whatever_it_carries` in `tests/store.rs` holds that line. + /// Nine, not nine-plus-one-per-comment or -per-subtask: `a_task_detail_ + /// costs_nine_queries_whatever_it_carries` in `tests/store.rs` holds that + /// line. pub async fn load( reads: &dyn DetailReads, workspace_id: &str, @@ -544,6 +587,17 @@ mod reads { let comments = reads.comments_for_task(task_id).await?; let files = reads.files_for_task(task_id).await?; let activity = reads.activity_for_task(task_id).await?; + let family = reads.family_for_task(task_id).await?; + + let mut parent = None; + let mut subtasks = Vec::new(); + for (is_parent, line) in family { + if is_parent { + parent = Some(line); + } else { + subtasks.push(line); + } + } let Some(column) = columns .iter() @@ -578,6 +632,8 @@ mod reads { comments, files, activity, + parent, + subtasks, })) } } diff --git a/crates/izlek-core/src/mail.rs b/crates/izlek-core/src/mail.rs index 6fa95bb..46d0273 100644 --- a/crates/izlek-core/src/mail.rs +++ b/crates/izlek-core/src/mail.rs @@ -671,6 +671,12 @@ impl Engine { ActivityKind::Retitled => format!("{} renamed it.", actor), ActivityKind::Linked => format!("{} linked {}.", actor, activity.detail), ActivityKind::Unlinked => format!("{} unlinked {}.", actor, activity.detail), + ActivityKind::Parented => { + format!("{} made it a part of {}.", actor, activity.detail) + } + ActivityKind::Unparented => { + format!("{} released it from {}.", actor, activity.detail) + } ActivityKind::Deleted => format!("{} deleted it.", actor), // Never a wired trigger — `activity_kind_for` never maps to // these — and account/admin kinds have no task to be mailed diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index ad986e5..0204913 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -24,7 +24,7 @@ use crate::Role; use crate::board::{BoardMeta, BoardReads, Column, Moved, Person, TaskRow, Transition}; use crate::detail::{ ActivityEntry, ActivityKind, Comment, DeletionCost, DependencyEdge, DetailReads, FileLine, - TaskFacts, + SubtaskLine, TaskFacts, }; use time::Date; use time::format_description::BorrowedFormatItem; @@ -1466,6 +1466,7 @@ impl Store for TursoStore { deadline: new.deadline, position, done_at: None, + parent_id: new.parent_id.map(str::to_string), }, activity_id, transition: Transition { @@ -1588,6 +1589,7 @@ impl Store for TursoStore { deadline: opt_day(&row, 4)?, position: row.get::(5).unwrap_or(0.0), done_at: opt_stamp(&row, 6)?, + parent_id: Some(parent_id.to_string()), }); } Ok(out) @@ -1628,6 +1630,24 @@ impl Store for TursoStore { } let stamp = stamp(at)?; + // A parent and its own part are already related, and the board would + // draw the relationship twice: once as a chip, once as the count. + { + let conn = self.conn.lock().await; + let mut rows = conn + .query( + "SELECT 1 FROM task WHERE (id = ?1 AND parent_id = ?2) \ + OR (id = ?2 AND parent_id = ?1) LIMIT 1", + params![blocked_task_id, blocking_task_id], + ) + .await + .map_err(backend)?; + let related = rows.next().await.map_err(backend)?.is_some(); + if related { + return Err(StoreError::Cycle); + } + } + let mut conn = self.tx_conn().await?; // IMMEDIATE: the reachability read and the insert that invalidates it // must not be interleaved with another writer's pair, or two adds each @@ -2196,6 +2216,15 @@ impl Store for TursoStore { params![task_id, stamp.clone()], ) .await?; + // The parts go with the whole, in the same write. A subtask that + // outlived its parent would be unreachable: the board does not + // show it, and the page that did is gone. + tx.execute( + "UPDATE task SET deleted_at = ?2, updated_at = ?2 \ + WHERE parent_id = ?1 AND deleted_at IS NULL", + params![task_id, stamp.clone()], + ) + .await?; let deleted_activity_id = Ulid::new().to_string(); tx.execute( "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \ @@ -2324,17 +2353,20 @@ impl Store for TursoStore { ON t.id = CASE WHEN d.blocked_task_id = ?1 \ THEN d.blocking_task_id ELSE d.blocked_task_id END \ WHERE (d.blocked_task_id = ?1 OR d.blocking_task_id = ?1) \ - AND d.cleared_at IS NULL AND t.deleted_at IS NULL)", + AND d.cleared_at IS NULL AND t.deleted_at IS NULL), \ + (SELECT COUNT(*) FROM task \ + WHERE parent_id = ?1 AND deleted_at IS NULL)", params![task_id], ) .await .map_err(backend)?; - let (comment_count, link_count) = match rows.next().await.map_err(backend)? { + let (comment_count, link_count, subtask_count) = match rows.next().await.map_err(backend)? { Some(row) => ( row.get::(0).map_err(backend)?.max(0) as u32, row.get::(1).map_err(backend)?.max(0) as u32, + row.get::(2).map_err(backend)?.max(0) as u32, ), - None => (0, 0), + None => (0, 0, 0), }; drop(rows); @@ -2366,6 +2398,7 @@ impl Store for TursoStore { comment_count, link_count, frees, + subtask_count, })) } @@ -3289,7 +3322,7 @@ impl DetailReads for TursoStore { let row = self .one_row( "SELECT t.id, t.task_key, t.title, t.column_id, t.deadline, t.position, \ - t.done_at, t.description, t.board_id, b.workspace_id \ + t.done_at, t.description, t.board_id, b.workspace_id, t.parent_id \ FROM task t JOIN board b ON b.id = t.board_id \ WHERE t.id = ?1 AND t.deleted_at IS NULL", params![task_id], @@ -3305,6 +3338,7 @@ impl DetailReads for TursoStore { deadline: opt_day(&row, 4)?, position: row.get::(5).map_err(backend)?, done_at: opt_stamp(&row, 6)?, + parent_id: opt_text(&row, 10)?, }, description: text(&row, 7)?, board_id: text(&row, 8)?, @@ -3486,6 +3520,65 @@ impl DetailReads for TursoStore { } Ok(out) } + + async fn family_for_task(&self, task_id: &str) -> Result> { + let conn = self.conn.lock().await; + // One query for both directions, and one for the assignees too: the + // LEFT JOIN repeats a task's row once per person it points at, and the + // fold below puts them back together. A task detail is not allowed to + // cost a query per subtask. + let mut rows = conn + .query( + "SELECT t.id, t.task_key, t.title, t.column_id, t.done_at, t.parent_id, \ + u.id, u.display_name, (u.photo IS NOT NULL) \ + FROM task t \ + LEFT JOIN task_assignee a ON a.task_id = t.id \ + LEFT JOIN user u ON u.id = a.user_id \ + WHERE t.deleted_at IS NULL AND ( \ + t.parent_id = ?1 \ + OR t.id = (SELECT parent_id FROM task WHERE id = ?1) \ + ) \ + ORDER BY t.created_at, u.display_name", + params![task_id], + ) + .await + .map_err(backend)?; + + let mut out: Vec<(bool, SubtaskLine)> = Vec::new(); + while let Some(row) = rows.next().await.map_err(backend)? { + let id = text(&row, 0)?; + // A row whose parent is the task we asked about is one of its + // parts; anything else this query can return is the parent. + let is_parent = opt_text(&row, 5)?.as_deref() != Some(task_id); + let person = match opt_text(&row, 6)? { + Some(user_id) => Some(Person { + id: user_id, + display_name: text(&row, 7)?, + has_photo: row.get::(8).map_err(backend)? != 0, + }), + None => None, + }; + match out.last_mut() { + Some((_, line)) if line.id == id => { + if let Some(person) = person { + line.assignees.push(person); + } + } + _ => out.push(( + is_parent, + SubtaskLine { + id, + task_key: text(&row, 1)?, + title: text(&row, 2)?, + column_id: text(&row, 3)?, + done_at: opt_stamp(&row, 4)?, + assignees: person.into_iter().collect(), + }, + )), + } + } + Ok(out) + } } #[async_trait] @@ -3534,7 +3627,7 @@ impl BoardReads for TursoStore { let conn = self.conn.lock().await; let mut rows = conn .query( - "SELECT id, task_key, title, column_id, deadline, position, done_at \ + "SELECT id, task_key, title, column_id, deadline, position, done_at, parent_id \ FROM task WHERE board_id = ?1 AND deleted_at IS NULL", params![board_id], ) @@ -3550,6 +3643,7 @@ impl BoardReads for TursoStore { deadline: opt_day(&row, 4)?, position: row.get::(5).map_err(backend)?, done_at: opt_stamp(&row, 6)?, + parent_id: opt_text(&row, 7)?, }); } Ok(out) diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index f36f449..bbeb1cb 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -404,6 +404,170 @@ async fn a_promoted_subtask_stops_holding_its_parent() { moved_to(&scratch.store, &workspace, &parent, "Backlog", "Done", &admin).await; } +#[tokio::test] +async fn the_board_counts_subtasks_instead_of_carding_them() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + let board = load(&scratch.store, &workspace).await.unwrap().unwrap(); + let cards: Vec<&izlek_core::board::TaskCard> = + board.columns.iter().flat_map(|c| &c.cards).collect(); + assert_eq!(cards.len(), 1, "the subtask took a card of its own"); + assert_eq!(cards[0].id, parent); + assert_eq!(cards[0].subtask_total, 1); + assert_eq!(cards[0].subtask_done, 0); + assert_eq!(cards[0].subtask_label().as_deref(), Some("0/1")); + assert!(cards[0].holds_on_subtasks()); + + moved_to(&scratch.store, &workspace, &child, "Backlog", "Done", &admin).await; + let board = load(&scratch.store, &workspace).await.unwrap().unwrap(); + let card = board + .columns + .iter() + .flat_map(|c| &c.cards) + .find(|card| card.id == parent) + .unwrap(); + assert_eq!(card.subtask_label().as_deref(), Some("1/1")); + assert!(!card.holds_on_subtasks()); +} + +#[tokio::test] +async fn a_card_with_no_parts_wears_no_chip() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + add_task(&scratch.store, &workspace, "Backlog", "Alone", None, &admin).await; + + let board = load(&scratch.store, &workspace).await.unwrap().unwrap(); + let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap(); + assert_eq!(card.subtask_label(), None); + assert!(!card.holds_on_subtasks()); +} + +#[tokio::test] +async fn a_subtask_blocking_a_card_still_names_itself_on_it() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (_parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + let other = add_task(&scratch.store, &workspace, "Backlog", "Waiting", None, &admin).await; + scratch + .store + .add_dependency(&other, &child, OffsetDateTime::now_utc()) + .await + .unwrap(); + + // The subtask has no card, but its key is real and the chip has to show + // it: dropping the row would leave the blocked card looking free. + let board = load(&scratch.store, &workspace).await.unwrap().unwrap(); + let waiting = board + .columns + .iter() + .flat_map(|c| &c.cards) + .find(|card| card.id == other) + .unwrap(); + assert_eq!(waiting.blocked_by.len(), 1); + assert!(waiting.is_blocked()); +} + +#[tokio::test] +async fn a_parent_and_its_own_part_are_not_linked_as_well() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + let now = OffsetDateTime::now_utc(); + + assert!(matches!( + scratch.store.add_dependency(&parent, &child, now).await, + Err(StoreError::Cycle) + )); + assert!(matches!( + scratch.store.add_dependency(&child, &parent, now).await, + Err(StoreError::Cycle) + )); +} + +#[tokio::test] +async fn a_task_detail_carries_its_family_both_ways() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + scratch.store.assign_task(&child, &admin).await.unwrap(); + + let whole = load_detail(&scratch.store, &workspace, &parent) + .await + .unwrap() + .unwrap(); + assert!(whole.parent.is_none()); + assert_eq!(whole.subtasks.len(), 1); + assert_eq!(whole.subtasks[0].id, child); + assert_eq!(whole.subtasks[0].assignees.len(), 1); + assert!(!whole.subtasks[0].is_done()); + + let part = load_detail(&scratch.store, &workspace, &child) + .await + .unwrap() + .unwrap(); + assert_eq!(part.parent.as_ref().unwrap().id, parent); + assert!( + part.subtasks.is_empty(), + "a subtask has no parts of its own" + ); +} + +#[tokio::test] +async fn deleting_a_parent_says_what_it_takes_and_takes_it() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + let cost = scratch + .store + .deletion_cost(&parent) + .await + .unwrap() + .expect("the parent is there to delete"); + assert_eq!(cost.subtask_count, 1); + + scratch + .store + .delete_task(&parent, &admin, OffsetDateTime::now_utc()) + .await + .unwrap(); + + // The part went with the whole, in the same write. A subtask that + // outlived its parent would be unreachable. + assert!( + load_detail(&scratch.store, &workspace, &child) + .await + .unwrap() + .is_none() + ); + let board = load(&scratch.store, &workspace).await.unwrap().unwrap(); + assert_eq!(board.columns.iter().flat_map(|c| &c.cards).count(), 0); +} + +#[tokio::test] +async fn deleting_a_subtask_leaves_its_parent_standing() { + let scratch = Scratch::open().await; + let (workspace, admin) = claim(&scratch.store).await; + let (parent, child) = a_parent_and_one_subtask(&scratch.store, &workspace, &admin).await; + + scratch + .store + .delete_task(&child, &admin, OffsetDateTime::now_utc()) + .await + .unwrap(); + + let whole = load_detail(&scratch.store, &workspace, &parent) + .await + .unwrap() + .unwrap(); + assert!(whole.subtasks.is_empty()); + let board = load(&scratch.store, &workspace).await.unwrap().unwrap(); + let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap(); + assert_eq!(card.subtask_label(), None); +} + #[tokio::test] async fn the_first_account_owns_the_workspace() { let scratch = Scratch::open().await; @@ -2553,6 +2717,14 @@ impl DetailReads for CountingDetail<'_> { self.tick(); self.inner.activity_for_task(task_id).await } + + async fn family_for_task( + &self, + task_id: &str, + ) -> Result, StoreError> { + self.tick(); + self.inner.family_for_task(task_id).await + } } #[tokio::test] @@ -2867,7 +3039,7 @@ async fn saving_a_task_records_only_what_changed() { } #[tokio::test] -async fn a_task_detail_costs_eight_queries_whatever_it_carries() { +async fn a_task_detail_costs_nine_queries_whatever_it_carries() { let (scratch, workspace, admin) = workspace_with_admin().await; let store = &scratch.store; let now = OffsetDateTime::now_utc(); @@ -2875,11 +3047,12 @@ async fn a_task_detail_costs_eight_queries_whatever_it_carries() { let bare = add_task(store, &workspace, "Backlog", "bare", None, &admin).await; let counted = CountingDetail::new(store); load_detail(&counted, &workspace, &bare).await.unwrap(); - assert_eq!(counted.count(), 8, "a task with nothing hung off it"); + assert_eq!(counted.count(), 9, "a task with nothing hung off it"); // Twenty comments, twenty activity lines, twenty people who could be - // assigned and twenty tasks on the other end of a dependency — the four - // things a naive detail query fans out on. + // assigned, twenty tasks on the other end of a dependency and twenty + // subtasks each with an assignee — the things a naive detail query fans + // out on. let heavy = add_task(store, &workspace, "Backlog", "heavy", None, &admin).await; for n in 0..20 { let person = store @@ -2910,6 +3083,10 @@ async fn a_task_detail_costs_eight_queries_whatever_it_carries() { let neighbour = add_task(store, &workspace, "Backlog", &format!("n{n}"), None, &admin).await; store.add_dependency(&neighbour, &heavy, now).await.unwrap(); + + let part = add_task(store, &workspace, "Backlog", &format!("p{n}"), None, &admin).await; + store.set_parent(&part, Some(&heavy)).await.unwrap(); + store.assign_task(&part, &person.id).await.unwrap(); } let counted = CountingDetail::new(store); @@ -2920,12 +3097,21 @@ async fn a_task_detail_costs_eight_queries_whatever_it_carries() { assert_eq!(detail.comments.len(), 20); assert_eq!(detail.assignees.len(), 20); assert_eq!(detail.blocks.len(), 20); + assert_eq!(detail.subtasks.len(), 20); + assert!(detail.parent.is_none()); + assert!( + detail + .subtasks + .iter() + .all(|part| part.assignees.len() == 1), + "a subtask row carries who holds it" + ); // Twenty comments (each its own Commented line), twenty moves, plus the // line create_task wrote. assert_eq!(detail.activity.len(), 41); assert_eq!( counted.count(), - 8, + 9, "the round trips a detail costs must not follow what it carries" ); } diff --git a/crates/izlek-web/src/board.rs b/crates/izlek-web/src/board.rs index 6c0da75..acecf4c 100644 --- a/crates/izlek-web/src/board.rs +++ b/crates/izlek-web/src/board.rs @@ -343,6 +343,8 @@ async fn render_card( None => t(lang, Key::NoDeadline).to_string(), }; let comments = card.comment_count; + let subtasks = card.subtask_label(); + let subtasks_open = card.holds_on_subtasks(); let mut assignees = Vec::new(); for person in card.assignees.iter() { assignees.push(crate::layout::avatar(cx, person, "").await?); @@ -377,6 +379,9 @@ async fn render_card( (deadline) + if let Some(parts) = subtasks.clone() { + (format!("{parts} \u{2630}")) + } if comments > 0 { (format!("{comments} \u{270e}")) }
@@ -620,6 +625,8 @@ mod sort_tests { comment_count: 0, blocked_by: Vec::new(), blocks: Vec::new(), + subtask_total: 0, + subtask_done: 0, } } diff --git a/crates/izlek-web/src/detail.rs b/crates/izlek-web/src/detail.rs index 990fa6c..4d9ae79 100644 --- a/crates/izlek-web/src/detail.rs +++ b/crates/izlek-web/src/detail.rs @@ -77,6 +77,10 @@ pub struct DetailSnapshot { /// shift into this, the same as `/logs` does. pub zone: UtcOffset, pub linkable: Vec, + /// Tasks this one could take in as parts: the board's other top-level + /// tasks that have no parts of their own. Empty when this task is itself + /// a part — subtasks go one level deep. + pub adoptable: Vec, pub may_write: bool, pub may_comment: bool, pub may_delete: bool, @@ -234,6 +238,21 @@ struct LinkForm { direction: Direction, } +#[derive(Deserialize)] +struct NewSubtaskForm { + parent_id: String, + title: String, +} + +#[derive(Deserialize)] +struct ParentForm { + task_id: String, + /// Empty means "let it out": the same form both ways, because parenting + /// and promoting are the same single write. + #[serde(default)] + parent_id: String, +} + #[derive(Deserialize)] struct CommentForm { task_id: String, @@ -272,6 +291,7 @@ async fn load_snapshot( // already on either end of a live link with this one. A cleared edge is // not a link any more, so its task comes back to the picker. let mut linkable = Vec::new(); + let mut adoptable = Vec::new(); if let Some(board) = store.board(&user.workspace_id).await? { let taken: Vec<&str> = detail .blocked_by @@ -280,7 +300,28 @@ async fn load_snapshot( .filter(|edge| edge.cleared_at.is_none()) .map(|edge| edge.task_id.as_str()) .collect(); - for task in store.tasks_for_board(&board.id).await? { + let tasks = store.tasks_for_board(&board.id).await?; + // Who already has parts, so the picker does not offer a task whose + // own children would become grandchildren. + let parents: Vec<&str> = tasks + .iter() + .filter_map(|task| task.parent_id.as_deref()) + .collect(); + for task in &tasks { + let is_self = task.id == detail.id; + if detail.parent.is_none() + && !is_self + && task.parent_id.is_none() + && !parents.contains(&task.id.as_str()) + { + adoptable.push(LinkTarget { + id: task.id.clone(), + task_key: task.task_key.clone(), + title: task.title.clone(), + }); + } + } + for task in tasks { if task.id == detail.id || taken.contains(&task.id.as_str()) { continue; } @@ -290,6 +331,7 @@ async fn load_snapshot( title: task.title, }); } + adoptable.sort_by(|a, b| a.id.cmp(&b.id)); // Sorted by id, not `task_key`: the key's tail is a random ULID // suffix now, not a counter, so only the id (a ULID itself) still // orders these by creation time. @@ -375,6 +417,7 @@ async fn load_snapshot( Ok(Ok(DetailSnapshot { detail, linkable, + adoptable, may_write, may_comment: user.role.can_comment(), may_delete: may_write, @@ -588,6 +631,104 @@ async fn unlink_tasks(cx: &Cx, Form(input): Form) -> Redirect { redirect(cx, None) } +/// Opens a new task already filed under this one. It starts in the board's +/// first column, the way a card dropped on the board's first column would. +#[route(POST "/api/create_subtask")] +async fn create_subtask(cx: &Cx, Form(input): Form) -> Redirect { + use izlek_core::store::NewTask; + + let (actor, parent) = match writer_and_task(cx, &input.parent_id).await { + Ok(pair) => pair, + Err(refusal) => return redirect(cx, Some(refusal)), + }; + let title = input.title.trim(); + if title.is_empty() { + return redirect(cx, Some(Refusal::EmptyTitle)); + } + let store = accounts(cx).store().clone(); + let columns = store.columns(&parent.board_id).await?; + let Some(first) = columns.iter().min_by_key(|column| column.position) else { + return redirect(cx, Some(Refusal::NotFound)); + }; + let created = match store + .create_task(NewTask { + board_id: &parent.board_id, + column_id: &first.id, + parent_id: Some(&input.parent_id), + title, + description: "", + deadline: None, + created_by: &actor.id, + }) + .await + { + Ok(created) => created, + Err(StoreError::NotNestable) => return redirect(cx, Some(Refusal::NotNestable)), + Err(error) => return Err(error.into()), + }; + mail(cx).after_activity(store.clone(), created.activity_id); + mail(cx).after(created.transition); + redirect(cx, None) +} + +/// Files a task under another one, or lets it out again — an empty +/// `parent_id` is the second. One handler, because it is one write. +#[route(POST "/api/set_parent")] +async fn set_parent(cx: &Cx, Form(input): Form) -> Redirect { + use izlek_core::detail::ActivityKind; + use time::OffsetDateTime; + + let (actor, task) = match writer_and_task(cx, &input.task_id).await { + Ok(pair) => pair, + Err(refusal) => return redirect(cx, Some(refusal)), + }; + let store = accounts(cx).store().clone(); + let wanted = input.parent_id.trim(); + + // Whichever end is not the task itself has to be a task this person may + // see, so the key the activity line names is one they already have. + let (parent_id, other_key) = if wanted.is_empty() { + let Some(had) = task.row.parent_id.clone() else { + return redirect(cx, None); + }; + match task_of(store.as_ref(), &actor, &had).await { + Ok(facts) => (None, facts.row.task_key), + Err(refusal) => return redirect(cx, Some(refusal)), + } + } else { + match task_of(store.as_ref(), &actor, wanted).await { + Ok(facts) => (Some(facts.row.id.clone()), facts.row.task_key), + Err(refusal) => return redirect(cx, Some(refusal)), + } + }; + + match store.set_parent(&input.task_id, parent_id.as_deref()).await { + Ok(()) => {} + Err(StoreError::NotNestable) => return redirect(cx, Some(Refusal::NotNestable)), + Err(StoreError::OtherBoard) => return redirect(cx, Some(Refusal::Forbidden)), + Err(StoreError::Cycle) => return redirect(cx, Some(Refusal::Cycle)), + Err(StoreError::NotFound) => return redirect(cx, Some(Refusal::NotFound)), + Err(error) => return Err(error.into()), + } + + let kind = if parent_id.is_some() { + ActivityKind::Parented + } else { + ActivityKind::Unparented + }; + let activity_id = store + .record_activity( + &input.task_id, + Some(&actor.id), + &kind, + &other_key, + OffsetDateTime::now_utc(), + ) + .await?; + mail(cx).after_activity(store, activity_id); + redirect(cx, None) +} + /// Writes a comment. The author is the session's user; there is no author /// field on the form. A Viewer is refused here, not merely shown no textarea. #[route(POST "/api/post_comment")] @@ -1231,6 +1372,88 @@ async fn link_picker(cx: &Cx, task_id: &str, linkable: &[LinkTarget], lang: Lang } } +/// One part on its parent's page: its key, its title, who holds it, and the +/// button that lets it out. The status is the column's name, read off the +/// board's columns the page already has. +async fn subtask_row( + cx: &Cx, + part: &izlek_core::detail::SubtaskLine, + columns: &[izlek_core::Column], + may_write: bool, + lang: Lang, +) -> Result { + let done = part.is_done(); + let status = columns + .iter() + .find(|column| column.id == part.column_id) + .map(|column| column.name.clone()) + .unwrap_or_default(); + let href = format!("/?task={}", part.id); + let release_title = t(lang, Key::ReleaseThisPart); + let mut faces = Vec::new(); + for person in &part.assignees { + faces.push(crate::layout::avatar(cx, person, "").await?); + } + view! { + cx => +
+ if done { (glyph::tick(cx).await?) } else { (glyph::lock(cx).await?) } + (part.task_key.clone()) + (part.title.clone()) +
+ (status) +
+ for face in faces { (face) } +
+ if may_write { + + } +
+ } +} + +/// Takes an existing task in as a part. The same shape as `link_picker`, and +/// absent for the same reason: with nothing to offer it shows nothing. +async fn adopt_picker(cx: &Cx, task_id: &str, adoptable: &[LinkTarget], lang: Lang) -> Result { + if adoptable.is_empty() { + return view! { cx => }; + } + let toggle = format!("adopt-{task_id}"); + let aria = t(lang, Key::MakeAPart); + view! { + cx => + + } +} + async fn dep_row( cx: &Cx, task_id: &str, @@ -1402,6 +1625,7 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab) today, zone, linkable, + adoptable, may_write, may_comment, may_delete, @@ -1413,6 +1637,7 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab) let lang = Lang::from_code(&me.language); let unassigned: Vec = detail.unassigned().cloned().collect(); + let done_parts = detail.subtasks.iter().filter(|part| part.is_done()).count(); let has_deps = !detail.blocked_by.is_empty() || !detail.blocks.is_empty(); let accept = (!allowed_file_types.is_empty()) .then(|| { @@ -1443,6 +1668,11 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab)
+ if let Some(parent) = detail.parent.clone() { + + (format!("{} {}", t(lang, Key::PartOf), parent.task_key)) + + } (detail.task_key.clone()) (title_control(cx, &detail, may_write, lang).await?)
@@ -1557,6 +1787,43 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab) if tab == Tab::Task { + if detail.parent.is_none() { +
+
+ (t(lang, Key::Subtasks)) + if !detail.subtasks.is_empty() { + (format!("{}/{}", done_parts, detail.subtasks.len())) + } +
+ if may_write { + (adopt_picker(cx, &detail.id, &adoptable, lang).await?) + } +
+ if may_write { +
+ + + +
+ } + (refused(cx, "create_subtask", lang).await?) + (refused(cx, "set_parent", lang).await?) + if detail.subtasks.is_empty() { +

(t(lang, Key::NoSubtasks))

+ } else { +
+ for part in &detail.subtasks { + (subtask_row(cx, part, &detail.columns, may_write, lang).await?) + } +
+ } +
+ } +
(t(lang, Key::Description)) (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) if cost.comment_count > 0 {
  • (if cost.comment_count == 1 { t(lang, Key::CommentGoesWithIt).to_string() } else { format!("{} {}", cost.comment_count, t(lang, Key::CommentsGoWithIt)) })
  • } + if cost.subtask_count > 0 { +
  • (if cost.subtask_count == 1 { t(lang, Key::SubtaskGoesWithIt).to_string() } else { format!("{} {}", cost.subtask_count, t(lang, Key::SubtasksGoWithIt)) })
  • + } if cost.link_count > 0 {
  • (if cost.link_count == 1 { t(lang, Key::DependencyStopsApplying).to_string() } else { format!("{} {}", cost.link_count, t(lang, Key::DependenciesStopApplying)) })
  • } diff --git a/crates/izlek-web/src/i18n.rs b/crates/izlek-web/src/i18n.rs index 129e425..e69efa4 100644 --- a/crates/izlek-web/src/i18n.rs +++ b/crates/izlek-web/src/i18n.rs @@ -283,6 +283,16 @@ pub enum Key { NoTasks, NoDescription, NoDependencies, + Subtasks, + SubtaskGoesWithIt, + SubtasksGoWithIt, + NoSubtasks, + NewSubtask, + AddSubtask, + PartOf, + MakeAPart, + ReleaseThisPart, + ExistingTask, DonePrefix, Clear, Today, @@ -822,6 +832,26 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (NoDescription, Tr) => "açıklama yok", (NoDependencies, En) => "no dependencies", (NoDependencies, Tr) => "bağımlılık yok", + (SubtaskGoesWithIt, En) => "its subtask goes with it", + (SubtaskGoesWithIt, Tr) => "alt görevi de silinir", + (SubtasksGoWithIt, En) => "subtasks go with it", + (SubtasksGoWithIt, Tr) => "alt görevi de silinir", + (Subtasks, En) => "Subtasks", + (Subtasks, Tr) => "Alt görevler", + (NoSubtasks, En) => "no subtasks", + (NoSubtasks, Tr) => "alt görev yok", + (NewSubtask, En) => "Subtask", + (NewSubtask, Tr) => "Alt görev", + (AddSubtask, En) => "Add", + (AddSubtask, Tr) => "Ekle", + (PartOf, En) => "Part of", + (PartOf, Tr) => "Şunun parçası:", + (MakeAPart, En) => "Take an existing task", + (MakeAPart, Tr) => "Var olan görevi al", + (ReleaseThisPart, En) => "Release this subtask", + (ReleaseThisPart, Tr) => "Bu alt görevi serbest bırak", + (ExistingTask, En) => "Take", + (ExistingTask, Tr) => "Al", (DonePrefix, En) => "done ", (DonePrefix, Tr) => "bitti ", (Clear, En) => "Clear", @@ -996,6 +1026,20 @@ pub fn linked_label(lang: Lang, detail: &str) -> String { } } +pub fn parented_label(lang: Lang, detail: &str) -> String { + match lang { + Lang::En => format!("made this a part of {detail}"), + Lang::Tr => format!("bunu {detail} görevinin parçası yaptı"), + } +} + +pub fn unparented_label(lang: Lang, detail: &str) -> String { + match lang { + Lang::En => format!("released this from {detail}"), + Lang::Tr => format!("bunu {detail} görevinden çıkardı"), + } +} + pub fn unlinked_label(lang: Lang, detail: &str) -> String { match lang { Lang::En => format!("unlinked {detail}"), diff --git a/crates/izlek-web/src/logs.rs b/crates/izlek-web/src/logs.rs index db9b991..4930d26 100644 --- a/crates/izlek-web/src/logs.rs +++ b/crates/izlek-web/src/logs.rs @@ -155,6 +155,8 @@ fn activity_sentence(kind: &izlek_core::detail::ActivityKind, detail: &str, lang ActivityKind::Unassigned => crate::i18n::unassigned_label(lang, detail), ActivityKind::Linked => crate::i18n::linked_label(lang, detail), ActivityKind::Unlinked => crate::i18n::unlinked_label(lang, detail), + ActivityKind::Parented => crate::i18n::parented_label(lang, detail), + ActivityKind::Unparented => crate::i18n::unparented_label(lang, detail), ActivityKind::Moved => crate::i18n::moved_label(lang, detail), ActivityKind::Unblocked => crate::i18n::unblocked_label(lang, detail), ActivityKind::Deleted => t(lang, Key::ActDeleted).to_string(), diff --git a/crates/izlek-web/src/server.rs b/crates/izlek-web/src/server.rs index cdfa1b9..5122afc 100644 --- a/crates/izlek-web/src/server.rs +++ b/crates/izlek-web/src/server.rs @@ -365,6 +365,9 @@ pub enum Refusal { /// carries it, and a number cannot survive the round trip through the /// address bar that a browser without script makes. SubtasksOpen, + /// Subtasks go one level deep: the task named as a parent is itself a + /// part, or the task being filed already has parts of its own. + NotNestable, /// No such task — or none this account may see. Deliberately one answer for /// both. NotFound, @@ -415,6 +418,7 @@ impl Refusal { Refusal::Cycle => "That link would put this task behind itself.".to_string(), Refusal::MovedAlready => "Somebody moved this card first.".to_string(), Refusal::SubtasksOpen => "Subtasks are still open.".to_string(), + Refusal::NotNestable => "Subtasks go one level deep.".to_string(), Refusal::NotFound => "No such task.".to_string(), Refusal::NoSuchMember => "No such member.".to_string(), Refusal::Unavailable => "Something went wrong.".to_string(), @@ -445,6 +449,7 @@ impl Refusal { Refusal::Cycle => "Bu bağlantı görevi kendi arkasına koyar.".to_string(), Refusal::MovedAlready => "Bu kartı başka biri zaten taşıdı.".to_string(), Refusal::SubtasksOpen => "Alt görevler hâlâ açık.".to_string(), + Refusal::NotNestable => "Alt görevler tek seviyedir.".to_string(), Refusal::NotFound => "Böyle bir görev yok.".to_string(), Refusal::NoSuchMember => "Böyle bir üye yok.".to_string(), Refusal::Unavailable => "Bir şeyler ters gitti.".to_string(), @@ -520,6 +525,7 @@ impl Refusal { "cycle" => Refusal::Cycle, "moved-already" => Refusal::MovedAlready, "subtasks-open" => Refusal::SubtasksOpen, + "not-nestable" => Refusal::NotNestable, "not-found" => Refusal::NotFound, "no-such-member" => Refusal::NoSuchMember, "unavailable" => Refusal::Unavailable, @@ -574,6 +580,7 @@ impl Refusal { Refusal::Cycle => "cycle", Refusal::MovedAlready => "moved-already", Refusal::SubtasksOpen => "subtasks-open", + Refusal::NotNestable => "not-nestable", Refusal::NotFound => "not-found", Refusal::NoSuchMember => "no-such-member", Refusal::Unavailable => "unavailable", @@ -852,6 +859,7 @@ mod refusal_message_tests { Refusal::Cycle, Refusal::MovedAlready, Refusal::SubtasksOpen, + Refusal::NotNestable, Refusal::NotFound, Refusal::NoSuchMember, Refusal::Unavailable, diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index a24842b..7166d93 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -1429,6 +1429,209 @@ async fn a_card_with_open_subtasks_is_refused_the_done_column() { ); } +#[tokio::test] +async fn a_subtask_is_opened_from_its_parents_page_and_shows_up_there() { + let app = App::open().await; + let admin = admin(&app).await; + let columns = columns_of(&app).await; + let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await; + + let made = app + .post( + "/api/create_subtask", + Some(&admin), + &[("parent_id", &parent), ("title", "Write the CSV writer")], + ) + .await; + assert_eq!(made.body, "null", "the subtask was refused: {}", made.body); + + // The parent's page lists it; the board does not card it. + let page = app.get(&format!("/?task={parent}"), Some(&admin)).await; + let page = String::from_utf8_lossy(&page.bytes); + assert!( + page.contains("Write the CSV writer"), + "the subtask is not on its parent's page" + ); + + let workspace_id = app.workspace_id().await; + let board = izlek_core::board::load(app.store.as_ref(), &workspace_id) + .await + .unwrap() + .unwrap(); + let cards: Vec<_> = board.columns.iter().flat_map(|c| &c.cards).collect(); + assert_eq!(cards.len(), 1, "the subtask took a card of its own"); + assert_eq!(cards[0].subtask_label().as_deref(), Some("0/1")); +} + +#[tokio::test] +async fn a_subtask_with_nothing_in_its_title_is_refused() { + let app = App::open().await; + let admin = admin(&app).await; + let columns = columns_of(&app).await; + let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await; + + // Posted the way a browser without script does, so the refusal has to + // survive the round trip through the address bar. + let empty = app + .post_without_script( + "/api/create_subtask", + Some(&admin), + &format!("http://izlek.sh/?task={parent}"), + &[("parent_id", &parent), ("title", " ")], + ) + .await; + assert!( + empty + .location + .as_deref() + .unwrap_or_default() + .contains("refusal=empty-title&on=create_subtask"), + "{:?}", + empty.location + ); +} + +#[tokio::test] +async fn taking_a_task_in_and_letting_it_out_are_the_same_form() { + let app = App::open().await; + let admin = admin(&app).await; + let columns = columns_of(&app).await; + let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await; + let loose = a_task(&app, &admin, &columns[1], "Write the CSV writer").await; + + let taken = app + .post( + "/api/set_parent", + Some(&admin), + &[("task_id", &loose), ("parent_id", &parent)], + ) + .await; + assert_eq!(taken.body, "null", "taking it in was refused: {}", taken.body); + let workspace_id = app.workspace_id().await; + let board = izlek_core::board::load(app.store.as_ref(), &workspace_id) + .await + .unwrap() + .unwrap(); + assert_eq!(board.columns.iter().flat_map(|c| &c.cards).count(), 1); + + // The subtask kept its column: being taken in is not a move. + let page = app.get(&format!("/?task={loose}"), Some(&admin)).await; + let page = String::from_utf8_lossy(&page.bytes); + assert!( + page.contains("Part of"), + "the part does not name its whole" + ); + + let released = app + .post( + "/api/set_parent", + Some(&admin), + &[("task_id", &loose), ("parent_id", "")], + ) + .await; + assert_eq!(released.body, "null", "letting it out was refused: {}", released.body); + let board = izlek_core::board::load(app.store.as_ref(), &workspace_id) + .await + .unwrap() + .unwrap(); + assert_eq!( + board.columns.iter().flat_map(|c| &c.cards).count(), + 2, + "the released task did not come back to the board" + ); +} + +#[tokio::test] +async fn a_second_level_of_subtask_is_refused_at_the_door() { + let app = App::open().await; + let admin = admin(&app).await; + let columns = columns_of(&app).await; + let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await; + let child = a_task(&app, &admin, &columns[0], "Write the CSV writer").await; + let loose = a_task(&app, &admin, &columns[0], "Loose").await; + app.store.set_parent(&child, Some(&parent)).await.unwrap(); + + let refused = app + .post_without_script( + "/api/create_subtask", + Some(&admin), + &format!("http://izlek.sh/?task={child}"), + &[("parent_id", &child), ("title", "Deeper")], + ) + .await; + assert!( + refused + .location + .as_deref() + .unwrap_or_default() + .contains("refusal=not-nestable&on=create_subtask"), + "{:?}", + refused.location + ); + + let also_refused = app + .post_without_script( + "/api/set_parent", + Some(&admin), + &format!("http://izlek.sh/?task={child}"), + &[("task_id", &loose), ("parent_id", &child)], + ) + .await; + assert!( + also_refused + .location + .as_deref() + .unwrap_or_default() + .contains("refusal=not-nestable&on=set_parent"), + "{:?}", + also_refused.location + ); +} + +#[tokio::test] +async fn a_viewer_may_not_open_or_move_a_subtask() { + let app = App::open().await; + let admin = admin(&app).await; + let watcher = invited(&app, &admin, "kay@izlek.sh", "Kay Watcher", Role::Viewer).await; + let columns = columns_of(&app).await; + let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await; + + let refused = app + .post_without_script( + "/api/create_subtask", + Some(&watcher), + &format!("http://izlek.sh/?task={parent}"), + &[("parent_id", &parent), ("title", "Not yours")], + ) + .await; + assert!( + refused + .location + .as_deref() + .unwrap_or_default() + .contains("refusal=forbidden"), + "{:?}", + refused.location + ); + + let also = app + .post_without_script( + "/api/set_parent", + Some(&watcher), + &format!("http://izlek.sh/?task={parent}"), + &[("task_id", &parent), ("parent_id", "")], + ) + .await; + assert!( + also.location + .as_deref() + .unwrap_or_default() + .contains("refusal=forbidden"), + "{:?}", + also.location + ); +} + #[tokio::test] async fn a_drop_decided_against_a_stale_board_is_refused() { let app = App::open().await; diff --git a/style/main.scss b/style/main.scss index ba6cd99..fd294b1 100644 --- a/style/main.scss +++ b/style/main.scss @@ -858,12 +858,17 @@ a { } } -.card-comments { +.card-comments, +.card-subtasks { font-family: var(--font-mono); font-size: 11px; color: var(--muted); } +/// Parts still open is the same warning the blocker chips carry: this card +/// cannot reach the done column yet. +.card-subtasks-open { color: var(--warn-ink); } + .avatars { display: flex; align-items: center; @@ -1441,6 +1446,18 @@ img.avatar { color: var(--muted-soft); } +// A subtask says whose part it is above its own key, so the page it opens on +// still names the work it belongs to. +.detail-parent { + display: block; + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted); + text-decoration: none; + + &:hover { color: var(--ink); } +} + .detail-title { margin: 0; font-size: 18px; @@ -1926,6 +1943,28 @@ img.avatar { font-size: 13px; } +// A finished part reads back the way a finished card does: still there, +// still legible, plainly no longer in the way. +.subtask-row-done { + .dep-key, + .dep-title, + .dep-note { color: var(--muted-soft); } + + .dep-title { text-decoration: line-through; } +} + +.subtask-new { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 8px; +} + +.subtask-new-box { + flex: 1; + min-width: 0; +} + .dep-row-waiting { background: var(--warn-tint-soft); border-color: var(--warn-border);