Task modal: fields, deadline, assignees, watch, subtasks, dependencies, comments, activity, delete
Browse files at this commit488d38e8e2eacd4ce04e76fc0e342e61c41cfa0cParent: 8b14dab- feat
- task modal: fields, deadline, assignees, watch, subtasks, dependencies, comments, activity, delete
16 changed files +2729 -17
- crates/iz-core/src/store/activity.rs +49 -0
- crates/iz-core/src/store/comments.rs +9 -6
- crates/iz-core/src/store/tasks.rs +72 -0
- crates/iz-web/assets/board.js +14 -1
- crates/iz-web/src/i18n/board.rs +4 -0
- crates/iz-web/src/i18n/mod.rs +1 -0
- crates/iz-web/src/i18n/task.rs +425 -0
- crates/iz-web/src/pages/board.rs +27 -5
- crates/iz-web/src/pages/mod.rs +1 -0
- crates/iz-web/src/pages/task.rs +1345 -0
- crates/iz-web/src/pages/tasks.rs +4 -4
- crates/iz-web/src/views/board.rs +5 -1
- crates/iz-web/src/views/mod.rs +1 -0
- crates/iz-web/src/views/task.rs +627 -0
- style/_task.scss +144 -0
- style/main.scss +1 -0
crates/iz-core/src/store/activity.rsmodified+49 -0
| @@ -120,6 +120,55 @@ impl Store { | ||
| 120 | 120 | .await |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | + /// One keyset page of a task's activity, newest first, for the task modal. `cursor` is the | |
| 124 | + /// `next_cursor` of the previous page. `limit` must be between [`PAGE_MIN`] and [`PAGE_MAX`]. | |
| 125 | + pub async fn list_task_page( | |
| 126 | + &self, | |
| 127 | + board_id: &str, | |
| 128 | + task_id: &str, | |
| 129 | + cursor: Option<&str>, | |
| 130 | + limit: usize, | |
| 131 | + ) -> Result<ActivityPage> { | |
| 132 | + if !(PAGE_MIN..=PAGE_MAX).contains(&limit) { | |
| 133 | + return Err(Error::Invalid(format!( | |
| 134 | + "page size must be {PAGE_MIN} to {PAGE_MAX}" | |
| 135 | + ))); | |
| 136 | + } | |
| 137 | + let (before_at, before_id) = match cursor { | |
| 138 | + None => (None, None), | |
| 139 | + Some(text) => { | |
| 140 | + let (at, id) = text | |
| 141 | + .split_once('~') | |
| 142 | + .ok_or_else(|| Error::Invalid("malformed activity cursor".into()))?; | |
| 143 | + (Some(at.to_owned()), Some(id.to_owned())) | |
| 144 | + } | |
| 145 | + }; | |
| 146 | + let conn = self.read_conn().await; | |
| 147 | + let items = fetch_all( | |
| 148 | + &conn, | |
| 149 | + &format!( | |
| 150 | + "SELECT {ACTIVITY_COLS} FROM activity a JOIN tasks t ON t.id = a.task_id \ | |
| 151 | + WHERE a.task_id = ?1 AND t.board_id = ?2 \ | |
| 152 | + AND (?3 IS NULL OR a.at < ?3 OR (a.at = ?3 AND a.id < ?4)) \ | |
| 153 | + ORDER BY a.at DESC, a.id DESC LIMIT ?5" | |
| 154 | + ), | |
| 155 | + ( | |
| 156 | + task_id.to_owned(), | |
| 157 | + board_id.to_owned(), | |
| 158 | + before_at, | |
| 159 | + before_id, | |
| 160 | + i64::try_from(limit).unwrap_or(i64::MAX), | |
| 161 | + ), | |
| 162 | + map_activity, | |
| 163 | + ) | |
| 164 | + .await?; | |
| 165 | + let next_cursor = match items.last() { | |
| 166 | + Some(last) if items.len() == limit => Some(format!("{}~{}", last.at, last.id)), | |
| 167 | + _ => None, | |
| 168 | + }; | |
| 169 | + Ok(ActivityPage { items, next_cursor }) | |
| 170 | + } | |
| 171 | + | |
| 123 | 172 | /// One page of recent activity, newest first. `cursor` is the `next_cursor` of the previous page. |
| 124 | 173 | /// `limit` must be between [`PAGE_MIN`] and [`PAGE_MAX`]. |
| 125 | 174 | pub async fn list_recent( |
crates/iz-core/src/store/comments.rsmodified+9 -6
| @@ -64,13 +64,14 @@ fn member_sub(actor: &Actor) -> Result<&str> { | ||
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | -/// Reads a live comment of `board_id` with its task id and author. Missing or foreign: `NotFound`. | |
| 67 | +/// Reads a live comment of a live task of `board_id` with its task id and author. A comment whose task | |
| 68 | +/// was deleted, or a comment of another board, is `NotFound`. | |
| 68 | 69 | async fn live_comment(conn: &Connection, board_id: &str, comment_id: &str) -> Result<Comment> { |
| 69 | 70 | fetch_opt( |
| 70 | 71 | conn, |
| 71 | 72 | "SELECT c.id, c.task_id, c.author, c.body, c.created_at, c.edited_at, c.deleted_at FROM comments c \ |
| 72 | 73 | JOIN tasks t ON t.id = c.task_id \ |
| 73 | - WHERE c.id = ?1 AND t.board_id = ?2 AND c.deleted_at IS NULL", | |
| 74 | + WHERE c.id = ?1 AND t.board_id = ?2 AND c.deleted_at IS NULL AND t.deleted_at IS NULL", | |
| 74 | 75 | (comment_id.to_owned(), board_id.to_owned()), |
| 75 | 76 | map_comment, |
| 76 | 77 | ) |
| @@ -196,16 +197,17 @@ impl Store { | ||
| 196 | 197 | finish(tx, outcome).await |
| 197 | 198 | } |
| 198 | 199 | |
| 199 | - /// Soft-deletes a comment. Its author (while a member) or any admin may do it (`authz`). | |
| 200 | + /// Soft-deletes a comment. Its author (while a member) or any admin may do it (`authz`). Returns the id | |
| 201 | + /// of the task the comment belonged to, so the caller can tell that task's viewers. | |
| 200 | 202 | pub async fn delete_comment( |
| 201 | 203 | &self, |
| 202 | 204 | board_id: &str, |
| 203 | 205 | comment_id: &str, |
| 204 | 206 | actor: &Actor, |
| 205 | - ) -> Result<()> { | |
| 207 | + ) -> Result<String> { | |
| 206 | 208 | let conn = self.inner.conn.lock().await; |
| 207 | 209 | let tx = conn.unchecked_transaction().await.map_err(db_err)?; |
| 208 | - let outcome: Result<()> = async { | |
| 210 | + let outcome: Result<String> = async { | |
| 209 | 211 | let current = live_comment(&tx, board_id, comment_id).await?; |
| 210 | 212 | authorize( |
| 211 | 213 | actor, |
| @@ -230,7 +232,8 @@ impl Store { | ||
| 230 | 232 | detail: serde_json::json!({ "comment": comment_id }), |
| 231 | 233 | }, |
| 232 | 234 | ) |
| 233 | - .await | |
| 235 | + .await?; | |
| 236 | + Ok(current.task_id) | |
| 234 | 237 | } |
| 235 | 238 | .await; |
| 236 | 239 | finish(tx, outcome).await |
crates/iz-core/src/store/tasks.rsmodified+72 -0
| @@ -1109,6 +1109,78 @@ impl Store { | ||
| 1109 | 1109 | finish(tx, outcome).await |
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | + /// Starts (`on`) or stops watching a live task for one member. Watching is the member's own choice, so | |
| 1113 | + /// `sub` is always the actor. Only a real change writes a `watch_changed` activity row. | |
| 1114 | + pub async fn set_watch( | |
| 1115 | + &self, | |
| 1116 | + board_id: &str, | |
| 1117 | + task_id: &str, | |
| 1118 | + sub: &str, | |
| 1119 | + on: bool, | |
| 1120 | + ) -> Result<()> { | |
| 1121 | + let conn = self.inner.conn.lock().await; | |
| 1122 | + let tx = conn.unchecked_transaction().await.map_err(db_err)?; | |
| 1123 | + let outcome: Result<()> = async { | |
| 1124 | + live_task(&tx, board_id, task_id).await?; | |
| 1125 | + let changed = if on { | |
| 1126 | + tx.execute( | |
| 1127 | + "INSERT INTO task_watchers (task_id, sub, created_at) VALUES (?1, ?2, ?3) \ | |
| 1128 | + ON CONFLICT(task_id, sub) DO NOTHING", | |
| 1129 | + (task_id.to_owned(), sub.to_owned(), now_stamp()), | |
| 1130 | + ) | |
| 1131 | + .await | |
| 1132 | + .map_err(db_err)? | |
| 1133 | + } else { | |
| 1134 | + tx.execute( | |
| 1135 | + "DELETE FROM task_watchers WHERE task_id = ?1 AND sub = ?2", | |
| 1136 | + (task_id.to_owned(), sub.to_owned()), | |
| 1137 | + ) | |
| 1138 | + .await | |
| 1139 | + .map_err(db_err)? | |
| 1140 | + }; | |
| 1141 | + if changed > 0 { | |
| 1142 | + log( | |
| 1143 | + &tx, | |
| 1144 | + task_id, | |
| 1145 | + sub, | |
| 1146 | + "watch_changed", | |
| 1147 | + None, | |
| 1148 | + serde_json::json!({ "on": on }), | |
| 1149 | + ) | |
| 1150 | + .await?; | |
| 1151 | + } | |
| 1152 | + Ok(()) | |
| 1153 | + } | |
| 1154 | + .await; | |
| 1155 | + finish(tx, outcome).await | |
| 1156 | + } | |
| 1157 | + | |
| 1158 | + /// Whether `sub` watches the task. | |
| 1159 | + pub async fn is_watching(&self, task_id: &str, sub: &str) -> Result<bool> { | |
| 1160 | + let conn = self.read_conn().await; | |
| 1161 | + let found = fetch_opt( | |
| 1162 | + &conn, | |
| 1163 | + "SELECT 1 FROM task_watchers WHERE task_id = ?1 AND sub = ?2", | |
| 1164 | + (task_id.to_owned(), sub.to_owned()), | |
| 1165 | + |row| col_int(row, 0), | |
| 1166 | + ) | |
| 1167 | + .await?; | |
| 1168 | + Ok(found.is_some()) | |
| 1169 | + } | |
| 1170 | + | |
| 1171 | + /// Every live task of the board, top-level and subtasks, by key. The task modal picks dependency | |
| 1172 | + /// partners and parents from this list; the store checks each choice again when it is written. | |
| 1173 | + pub async fn task_options(&self, board_id: &str) -> Result<Vec<Task>> { | |
| 1174 | + let conn = self.read_conn().await; | |
| 1175 | + fetch_all( | |
| 1176 | + &conn, | |
| 1177 | + &format!("SELECT {TASK_COLS} FROM tasks WHERE board_id = ?1 AND deleted_at IS NULL ORDER BY key"), | |
| 1178 | + (board_id.to_owned(),), | |
| 1179 | + map_task, | |
| 1180 | + ) | |
| 1181 | + .await | |
| 1182 | + } | |
| 1183 | + | |
| 1112 | 1184 | /// A cheap summary of everything the board page shows: counts and the newest change of the board's |
| 1113 | 1185 | /// tasks, assignments, links, comments, columns and projects. The live stream sends `changed` only |
| 1114 | 1186 | /// when this text changes, so it must change whenever any of those rows does. |
crates/iz-web/assets/board.jsmodified+14 -1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | * anything else puts it back and shows a toast with the server's translated message. |
| 11 | 11 | * - A drag that ends outside any column puts the card back where it was. |
| 12 | 12 | * |
| 13 | - * What it never does: decide anything about the move itself. The server checks the column, the | |
| 13 | + * It also closes the task modal on Escape (see below). What it never does: decide anything about the move itself. The server checks the column, the | |
| 14 | 14 | * subtasks, the role and the token; this script only shows the result. Dropping onto the card's own |
| 15 | 15 | * column is nothing to send, so it puts the card back. |
| 16 | 16 | * |
| @@ -20,6 +20,19 @@ | ||
| 20 | 20 | (function () { |
| 21 | 21 | "use strict"; |
| 22 | 22 | |
| 23 | + /** | |
| 24 | + * Escape closes the task modal. The modal's `data-close-href` is the board with its filters, so closing | |
| 25 | + * is the same navigation as the close link. The page is read on every key press, because a soft | |
| 26 | + * navigation (nav.js) can replace the modal without this script running again. | |
| 27 | + */ | |
| 28 | + document.addEventListener("keydown", (event) => { | |
| 29 | + if (event.key !== "Escape") return; | |
| 30 | + const dialog = document.querySelector("dialog[data-close-href]"); | |
| 31 | + if (dialog && dialog.open) { | |
| 32 | + window.location.assign(dialog.dataset.closeHref); | |
| 33 | + } | |
| 34 | + }); | |
| 35 | + | |
| 23 | 36 | const board = document.querySelector("[data-board-write]"); |
| 24 | 37 | if (!board || !window.fetch || !window.URLSearchParams) { |
| 25 | 38 | return; |
crates/iz-web/src/i18n/board.rsmodified+4 -0
| @@ -251,6 +251,10 @@ pub fn notice(lang: Lang, name: &str) -> Option<&'static str> { | ||
| 251 | 251 | match name { |
| 252 | 252 | "created" => Some(t(lang, K::NoticeCreated)), |
| 253 | 253 | "deleted" => Some(t(lang, K::NoticeDeleted)), |
| 254 | + "saved" => Some(crate::i18n::task::t( | |
| 255 | + lang, | |
| 256 | + crate::i18n::task::K::NoticeSaved, | |
| 257 | + )), | |
| 254 | 258 | _ => None, |
| 255 | 259 | } |
| 256 | 260 | } |
crates/iz-web/src/i18n/mod.rsmodified+1 -0
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | pub mod board; |
| 11 | 11 | pub mod shell; |
| 12 | +pub mod task; | |
| 12 | 13 | |
| 13 | 14 | use topcoat::context::Cx; |
| 14 | 15 | use topcoat::router::request::headers; |
crates/iz-web/src/i18n/task.rsadded+425 -0
| @@ -0,0 +1,425 @@ | ||
| 1 | +//! Strings of the task modal: its fields, its sections, the activity sentences and the message of every | |
| 2 | +//! refused write. Each key has an English and a Turkish text in [`t`]; the match is exhaustive, so a | |
| 3 | +//! missing translation does not compile. | |
| 4 | + | |
| 5 | +use super::Lang; | |
| 6 | + | |
| 7 | +/// One variant per phrase of the task modal. | |
| 8 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| 9 | +pub enum K { | |
| 10 | + /// The link that closes the modal. | |
| 11 | + Close, | |
| 12 | + /// The label of the title field. | |
| 13 | + Title, | |
| 14 | + /// The label of the description field. | |
| 15 | + Description, | |
| 16 | + /// The hint under the description: plain text, and which links are clickable. | |
| 17 | + DescriptionHint, | |
| 18 | + /// The label of the project field. | |
| 19 | + Project, | |
| 20 | + /// The label of the deadline day field. | |
| 21 | + Deadline, | |
| 22 | + /// The label of the meeting time field. | |
| 23 | + Meeting, | |
| 24 | + /// The hint under the meeting time: the viewer's zone. | |
| 25 | + MeetingHint, | |
| 26 | + /// The button that saves the fields. | |
| 27 | + Save, | |
| 28 | + /// The heading of the assignees section. | |
| 29 | + Assignees, | |
| 30 | + /// The label of the person picker. | |
| 31 | + AssignPick, | |
| 32 | + /// The button that assigns the picked person. | |
| 33 | + Assign, | |
| 34 | + /// The button that removes one assignee. | |
| 35 | + Remove, | |
| 36 | + /// The text when nobody is assigned. | |
| 37 | + NobodyAssigned, | |
| 38 | + /// The button that starts watching the task. | |
| 39 | + Watch, | |
| 40 | + /// The button that stops watching the task. | |
| 41 | + Unwatch, | |
| 42 | + /// The text while the viewer watches the task. | |
| 43 | + Watching, | |
| 44 | + /// The text while the viewer does not watch the task. | |
| 45 | + NotWatching, | |
| 46 | + /// The heading of the subtasks section. | |
| 47 | + Subtasks, | |
| 48 | + /// The text when the task has no subtasks. | |
| 49 | + NoSubtasks, | |
| 50 | + /// The label of the subtask title field. | |
| 51 | + SubtaskTitle, | |
| 52 | + /// The button that creates a subtask. | |
| 53 | + AddSubtask, | |
| 54 | + /// The heading of the parent section. | |
| 55 | + Parent, | |
| 56 | + /// The first entry of the parent picker: a top-level task. | |
| 57 | + NoParent, | |
| 58 | + /// The button that sets the parent. | |
| 59 | + SetParent, | |
| 60 | + /// The heading of the dependencies section. | |
| 61 | + Dependencies, | |
| 62 | + /// The label for tasks this one waits for. | |
| 63 | + BlockedBy, | |
| 64 | + /// The label for tasks waiting for this one. | |
| 65 | + Blocks, | |
| 66 | + /// The text when there are no dependencies. | |
| 67 | + NoLinks, | |
| 68 | + /// The label of the task picker for a dependency. | |
| 69 | + LinkWith, | |
| 70 | + /// The label of the direction picker for a dependency. | |
| 71 | + LinkDirection, | |
| 72 | + /// The direction "waits for". | |
| 73 | + DirBlockedBy, | |
| 74 | + /// The direction "is waited for by". | |
| 75 | + DirBlocks, | |
| 76 | + /// The button that adds a dependency. | |
| 77 | + AddLink, | |
| 78 | + /// The button that removes a dependency. | |
| 79 | + RemoveLink, | |
| 80 | + /// The heading of the comments section. | |
| 81 | + Comments, | |
| 82 | + /// The text when there are no comments. | |
| 83 | + NoComments, | |
| 84 | + /// The label of the comment field. | |
| 85 | + CommentBody, | |
| 86 | + /// The button that posts a comment. | |
| 87 | + PostComment, | |
| 88 | + /// The summary of a comment's editor. | |
| 89 | + EditComment, | |
| 90 | + /// The button that saves an edited comment. | |
| 91 | + SaveComment, | |
| 92 | + /// The button that deletes a comment. | |
| 93 | + DeleteComment, | |
| 94 | + /// The mark after a comment that was edited. | |
| 95 | + Edited, | |
| 96 | + /// The heading of the activity section. | |
| 97 | + Activity, | |
| 98 | + /// The text when there is no activity. | |
| 99 | + NoActivity, | |
| 100 | + /// The link to the next, older page of activity. | |
| 101 | + Older, | |
| 102 | + /// The link that opens the delete confirmation. | |
| 103 | + DeleteTask, | |
| 104 | + /// The question of the delete confirmation. | |
| 105 | + DeleteQuestion, | |
| 106 | + /// The consequence line of the delete confirmation. | |
| 107 | + DeleteConsequence, | |
| 108 | + /// The button that confirms the delete. | |
| 109 | + DeleteYes, | |
| 110 | + /// The notice after a change in the modal. | |
| 111 | + NoticeSaved, | |
| 112 | + /// Activity: the task was created. | |
| 113 | + ActCreated, | |
| 114 | + /// Activity: the task was edited. | |
| 115 | + ActEdited, | |
| 116 | + /// Activity: the task was moved. | |
| 117 | + ActMoved, | |
| 118 | + /// Activity: the task was deleted. | |
| 119 | + ActDeleted, | |
| 120 | + /// Activity: someone was assigned. | |
| 121 | + ActAssigned, | |
| 122 | + /// Activity: someone was unassigned. | |
| 123 | + ActUnassigned, | |
| 124 | + /// Activity: the project changed. | |
| 125 | + ActTagChanged, | |
| 126 | + /// Activity: the parent changed. | |
| 127 | + ActParentChanged, | |
| 128 | + /// Activity: a dependency was added. | |
| 129 | + ActLinkAdded, | |
| 130 | + /// Activity: a dependency was removed. | |
| 131 | + ActLinkRemoved, | |
| 132 | + /// Activity: the task was unblocked. | |
| 133 | + ActUnblocked, | |
| 134 | + /// Activity: the deadline was set. | |
| 135 | + ActDeadlineSet, | |
| 136 | + /// Activity: the deadline was cleared. | |
| 137 | + ActDeadlineCleared, | |
| 138 | + /// Activity: the meeting time was set. | |
| 139 | + ActClockSet, | |
| 140 | + /// Activity: the meeting time was cleared. | |
| 141 | + ActClockCleared, | |
| 142 | + /// Activity: watching changed. | |
| 143 | + ActWatchChanged, | |
| 144 | + /// Activity: a comment was added. | |
| 145 | + ActCommentAdded, | |
| 146 | + /// Activity: a comment was edited. | |
| 147 | + ActCommentEdited, | |
| 148 | + /// Activity: a comment was deleted. | |
| 149 | + ActCommentDeleted, | |
| 150 | + /// Activity: a file was added. | |
| 151 | + ActFileAdded, | |
| 152 | + /// Activity: a file was deleted. | |
| 153 | + ActFileDeleted, | |
| 154 | + /// Activity: a reminder was sent. | |
| 155 | + ActReminded, | |
| 156 | + /// Activity: an account changed. | |
| 157 | + ActAccountChanged, | |
| 158 | + /// Activity of a kind this build does not name. | |
| 159 | + ActOther, | |
| 160 | + /// Refused: the description is longer than the limit. | |
| 161 | + DescriptionTooLong, | |
| 162 | + /// Refused: the project does not exist on this board. | |
| 163 | + ErrProject, | |
| 164 | + /// Refused: the deadline is not a day. | |
| 165 | + ErrDeadline, | |
| 166 | + /// Refused: the meeting time is not a clock time. | |
| 167 | + ErrTime, | |
| 168 | + /// Refused: the meeting time needs a day, or does not exist in the viewer's zone. | |
| 169 | + ErrMeeting, | |
| 170 | + /// Refused: the person cannot be assigned. | |
| 171 | + ErrAssignee, | |
| 172 | + /// Refused: a task cannot depend on itself. | |
| 173 | + ErrSelf, | |
| 174 | + /// Refused: the dependency would close a cycle. | |
| 175 | + ErrCycle, | |
| 176 | + /// Refused: the parent is not a top-level task of this board, or the task is not a top-level task. | |
| 177 | + ErrParent, | |
| 178 | + /// Refused: the task has subtasks and so cannot become one. | |
| 179 | + ErrParentHasChildren, | |
| 180 | + /// Refused: the comment is empty or longer than the limit. | |
| 181 | + ErrComment, | |
| 182 | + /// Refused: the subtask title is empty or longer than the limit. | |
| 183 | + ErrSubtaskTitle, | |
| 184 | + /// Refused: the picked task is not on this board. | |
| 185 | + ErrOtherTask, | |
| 186 | + /// Refused: the picked direction is not one of the two. | |
| 187 | + ErrDirection, | |
| 188 | +} | |
| 189 | + | |
| 190 | +/// The text of `key` in `lang`. | |
| 191 | +pub fn t(lang: Lang, key: K) -> &'static str { | |
| 192 | + match (key, lang) { | |
| 193 | + (K::Close, Lang::En) => "Close", | |
| 194 | + (K::Close, Lang::Tr) => "Kapat", | |
| 195 | + (K::Title, Lang::En) => "Title", | |
| 196 | + (K::Title, Lang::Tr) => "Başlık", | |
| 197 | + (K::Description, Lang::En) => "Description", | |
| 198 | + (K::Description, Lang::Tr) => "Açıklama", | |
| 199 | + (K::DescriptionHint, Lang::En) => { | |
| 200 | + "Plain text. Addresses that start with http:// or https:// become links." | |
| 201 | + } | |
| 202 | + (K::DescriptionHint, Lang::Tr) => { | |
| 203 | + "Düz metin. http:// veya https:// ile başlayan adresler bağlantı olur." | |
| 204 | + } | |
| 205 | + (K::Project, Lang::En) => "Project", | |
| 206 | + (K::Project, Lang::Tr) => "Proje", | |
| 207 | + (K::Deadline, Lang::En) => "Deadline", | |
| 208 | + (K::Deadline, Lang::Tr) => "Son tarih", | |
| 209 | + (K::Meeting, Lang::En) => "Meeting time", | |
| 210 | + (K::Meeting, Lang::Tr) => "Toplantı saati", | |
| 211 | + (K::MeetingHint, Lang::En) => "Optional. In your time zone. Needs a deadline day.", | |
| 212 | + (K::MeetingHint, Lang::Tr) => { | |
| 213 | + "İsteğe bağlı. Sizin saat diliminizde. Bir son tarih gerekir." | |
| 214 | + } | |
| 215 | + (K::Save, Lang::En) => "Save", | |
| 216 | + (K::Save, Lang::Tr) => "Kaydet", | |
| 217 | + (K::Assignees, Lang::En) => "Assignees", | |
| 218 | + (K::Assignees, Lang::Tr) => "Atananlar", | |
| 219 | + (K::AssignPick, Lang::En) => "Person", | |
| 220 | + (K::AssignPick, Lang::Tr) => "Kişi", | |
| 221 | + (K::Assign, Lang::En) => "Assign", | |
| 222 | + (K::Assign, Lang::Tr) => "Ata", | |
| 223 | + (K::Remove, Lang::En) => "Remove", | |
| 224 | + (K::Remove, Lang::Tr) => "Çıkar", | |
| 225 | + (K::NobodyAssigned, Lang::En) => "Nobody is assigned.", | |
| 226 | + (K::NobodyAssigned, Lang::Tr) => "Kimse atanmadı.", | |
| 227 | + (K::Watch, Lang::En) => "Watch", | |
| 228 | + (K::Watch, Lang::Tr) => "İzle", | |
| 229 | + (K::Unwatch, Lang::En) => "Stop watching", | |
| 230 | + (K::Unwatch, Lang::Tr) => "İzlemeyi bırak", | |
| 231 | + (K::Watching, Lang::En) => "You are watching this task.", | |
| 232 | + (K::Watching, Lang::Tr) => "Bu görevi izliyorsunuz.", | |
| 233 | + (K::NotWatching, Lang::En) => "You are not watching this task.", | |
| 234 | + (K::NotWatching, Lang::Tr) => "Bu görevi izlemiyorsunuz.", | |
| 235 | + (K::Subtasks, Lang::En) => "Subtasks", | |
| 236 | + (K::Subtasks, Lang::Tr) => "Alt görevler", | |
| 237 | + (K::NoSubtasks, Lang::En) => "No subtasks.", | |
| 238 | + (K::NoSubtasks, Lang::Tr) => "Alt görev yok.", | |
| 239 | + (K::SubtaskTitle, Lang::En) => "New subtask", | |
| 240 | + (K::SubtaskTitle, Lang::Tr) => "Yeni alt görev", | |
| 241 | + (K::AddSubtask, Lang::En) => "Add subtask", | |
| 242 | + (K::AddSubtask, Lang::Tr) => "Alt görev ekle", | |
| 243 | + (K::Parent, Lang::En) => "Parent task", | |
| 244 | + (K::Parent, Lang::Tr) => "Üst görev", | |
| 245 | + (K::NoParent, Lang::En) => "None (top-level task)", | |
| 246 | + (K::NoParent, Lang::Tr) => "Yok (ana görev)", | |
| 247 | + (K::SetParent, Lang::En) => "Set parent", | |
| 248 | + (K::SetParent, Lang::Tr) => "Üst görevi ayarla", | |
| 249 | + (K::Dependencies, Lang::En) => "Dependencies", | |
| 250 | + (K::Dependencies, Lang::Tr) => "Bağımlılıklar", | |
| 251 | + (K::BlockedBy, Lang::En) => "Waits for", | |
| 252 | + (K::BlockedBy, Lang::Tr) => "Bekliyor", | |
| 253 | + (K::Blocks, Lang::En) => "Blocks", | |
| 254 | + (K::Blocks, Lang::Tr) => "Engelliyor", | |
| 255 | + (K::NoLinks, Lang::En) => "No dependencies.", | |
| 256 | + (K::NoLinks, Lang::Tr) => "Bağımlılık yok.", | |
| 257 | + (K::LinkWith, Lang::En) => "Task", | |
| 258 | + (K::LinkWith, Lang::Tr) => "Görev", | |
| 259 | + (K::LinkDirection, Lang::En) => "Direction", | |
| 260 | + (K::LinkDirection, Lang::Tr) => "Yön", | |
| 261 | + (K::DirBlockedBy, Lang::En) => "This task waits for the chosen task", | |
| 262 | + (K::DirBlockedBy, Lang::Tr) => "Bu görev seçilen görevi bekler", | |
| 263 | + (K::DirBlocks, Lang::En) => "This task blocks the chosen task", | |
| 264 | + (K::DirBlocks, Lang::Tr) => "Bu görev seçilen görevi engeller", | |
| 265 | + (K::AddLink, Lang::En) => "Add dependency", | |
| 266 | + (K::AddLink, Lang::Tr) => "Bağımlılık ekle", | |
| 267 | + (K::RemoveLink, Lang::En) => "Remove", | |
| 268 | + (K::RemoveLink, Lang::Tr) => "Kaldır", | |
| 269 | + (K::Comments, Lang::En) => "Comments", | |
| 270 | + (K::Comments, Lang::Tr) => "Yorumlar", | |
| 271 | + (K::NoComments, Lang::En) => "No comments yet.", | |
| 272 | + (K::NoComments, Lang::Tr) => "Henüz yorum yok.", | |
| 273 | + (K::CommentBody, Lang::En) => "Comment", | |
| 274 | + (K::CommentBody, Lang::Tr) => "Yorum", | |
| 275 | + (K::PostComment, Lang::En) => "Post comment", | |
| 276 | + (K::PostComment, Lang::Tr) => "Yorumu gönder", | |
| 277 | + (K::EditComment, Lang::En) => "Edit", | |
| 278 | + (K::EditComment, Lang::Tr) => "Düzenle", | |
| 279 | + (K::SaveComment, Lang::En) => "Save comment", | |
| 280 | + (K::SaveComment, Lang::Tr) => "Yorumu kaydet", | |
| 281 | + (K::DeleteComment, Lang::En) => "Delete comment", | |
| 282 | + (K::DeleteComment, Lang::Tr) => "Yorumu sil", | |
| 283 | + (K::Edited, Lang::En) => "edited", | |
| 284 | + (K::Edited, Lang::Tr) => "düzenlendi", | |
| 285 | + (K::Activity, Lang::En) => "Activity", | |
| 286 | + (K::Activity, Lang::Tr) => "Etkinlik", | |
| 287 | + (K::NoActivity, Lang::En) => "No activity yet.", | |
| 288 | + (K::NoActivity, Lang::Tr) => "Henüz etkinlik yok.", | |
| 289 | + (K::Older, Lang::En) => "Older activity", | |
| 290 | + (K::Older, Lang::Tr) => "Daha eski etkinlik", | |
| 291 | + (K::DeleteTask, Lang::En) => "Delete task", | |
| 292 | + (K::DeleteTask, Lang::Tr) => "Görevi sil", | |
| 293 | + (K::DeleteQuestion, Lang::En) => "Delete this task?", | |
| 294 | + (K::DeleteQuestion, Lang::Tr) => "Bu görev silinsin mi?", | |
| 295 | + (K::DeleteConsequence, Lang::En) => { | |
| 296 | + "Its subtasks and comments go with it. This cannot be undone." | |
| 297 | + } | |
| 298 | + (K::DeleteConsequence, Lang::Tr) => { | |
| 299 | + "Alt görevleri ve yorumları da silinir. Bu geri alınamaz." | |
| 300 | + } | |
| 301 | + (K::DeleteYes, Lang::En) => "Delete the task", | |
| 302 | + (K::DeleteYes, Lang::Tr) => "Görevi sil", | |
| 303 | + (K::NoticeSaved, Lang::En) => "Saved.", | |
| 304 | + (K::NoticeSaved, Lang::Tr) => "Kaydedildi.", | |
| 305 | + (K::ActCreated, Lang::En) => "created the task", | |
| 306 | + (K::ActCreated, Lang::Tr) => "görevi oluşturdu", | |
| 307 | + (K::ActEdited, Lang::En) => "edited the task", | |
| 308 | + (K::ActEdited, Lang::Tr) => "görevi düzenledi", | |
| 309 | + (K::ActMoved, Lang::En) => "moved the task", | |
| 310 | + (K::ActMoved, Lang::Tr) => "görevi taşıdı", | |
| 311 | + (K::ActDeleted, Lang::En) => "deleted the task", | |
| 312 | + (K::ActDeleted, Lang::Tr) => "görevi sildi", | |
| 313 | + (K::ActAssigned, Lang::En) => "assigned someone", | |
| 314 | + (K::ActAssigned, Lang::Tr) => "birini atadı", | |
| 315 | + (K::ActUnassigned, Lang::En) => "removed an assignee", | |
| 316 | + (K::ActUnassigned, Lang::Tr) => "bir atananı çıkardı", | |
| 317 | + (K::ActTagChanged, Lang::En) => "changed the project", | |
| 318 | + (K::ActTagChanged, Lang::Tr) => "projeyi değiştirdi", | |
| 319 | + (K::ActParentChanged, Lang::En) => "changed the parent task", | |
| 320 | + (K::ActParentChanged, Lang::Tr) => "üst görevi değiştirdi", | |
| 321 | + (K::ActLinkAdded, Lang::En) => "added a dependency", | |
| 322 | + (K::ActLinkAdded, Lang::Tr) => "bağımlılık ekledi", | |
| 323 | + (K::ActLinkRemoved, Lang::En) => "removed a dependency", | |
| 324 | + (K::ActLinkRemoved, Lang::Tr) => "bağımlılığı kaldırdı", | |
| 325 | + (K::ActUnblocked, Lang::En) => "was unblocked", | |
| 326 | + (K::ActUnblocked, Lang::Tr) => "engeli kalktı", | |
| 327 | + (K::ActDeadlineSet, Lang::En) => "set the deadline", | |
| 328 | + (K::ActDeadlineSet, Lang::Tr) => "son tarihi ayarladı", | |
| 329 | + (K::ActDeadlineCleared, Lang::En) => "cleared the deadline", | |
| 330 | + (K::ActDeadlineCleared, Lang::Tr) => "son tarihi kaldırdı", | |
| 331 | + (K::ActClockSet, Lang::En) => "set the meeting time", | |
| 332 | + (K::ActClockSet, Lang::Tr) => "toplantı saatini ayarladı", | |
| 333 | + (K::ActClockCleared, Lang::En) => "cleared the meeting time", | |
| 334 | + (K::ActClockCleared, Lang::Tr) => "toplantı saatini kaldırdı", | |
| 335 | + (K::ActWatchChanged, Lang::En) => "changed watching", | |
| 336 | + (K::ActWatchChanged, Lang::Tr) => "izleme durumunu değiştirdi", | |
| 337 | + (K::ActCommentAdded, Lang::En) => "commented", | |
| 338 | + (K::ActCommentAdded, Lang::Tr) => "yorum yaptı", | |
| 339 | + (K::ActCommentEdited, Lang::En) => "edited a comment", | |
| 340 | + (K::ActCommentEdited, Lang::Tr) => "bir yorumu düzenledi", | |
| 341 | + (K::ActCommentDeleted, Lang::En) => "deleted a comment", | |
| 342 | + (K::ActCommentDeleted, Lang::Tr) => "bir yorumu sildi", | |
| 343 | + (K::ActFileAdded, Lang::En) => "added a file", | |
| 344 | + (K::ActFileAdded, Lang::Tr) => "dosya ekledi", | |
| 345 | + (K::ActFileDeleted, Lang::En) => "deleted a file", | |
| 346 | + (K::ActFileDeleted, Lang::Tr) => "bir dosyayı sildi", | |
| 347 | + (K::ActReminded, Lang::En) => "was reminded", | |
| 348 | + (K::ActReminded, Lang::Tr) => "hatırlatıldı", | |
| 349 | + (K::ActAccountChanged, Lang::En) => "changed an account", | |
| 350 | + (K::ActAccountChanged, Lang::Tr) => "bir hesabı değiştirdi", | |
| 351 | + (K::ActOther, Lang::En) => "changed the task", | |
| 352 | + (K::ActOther, Lang::Tr) => "görevi değiştirdi", | |
| 353 | + (K::DescriptionTooLong, Lang::En) => "The description is longer than 20 000 characters.", | |
| 354 | + (K::DescriptionTooLong, Lang::Tr) => "Açıklama 20 000 karakterden uzun.", | |
| 355 | + (K::ErrProject, Lang::En) => "That project does not exist on this board.", | |
| 356 | + (K::ErrProject, Lang::Tr) => "Bu pano üzerinde böyle bir proje yok.", | |
| 357 | + (K::ErrDeadline, Lang::En) => "Use a deadline day such as 2026-10-28, or leave it empty.", | |
| 358 | + (K::ErrDeadline, Lang::Tr) => "2026-10-28 gibi bir gün yazın ya da boş bırakın.", | |
| 359 | + (K::ErrTime, Lang::En) => "Use a meeting time such as 09:30, or leave it empty.", | |
| 360 | + (K::ErrTime, Lang::Tr) => "09:30 gibi bir saat yazın ya da boş bırakın.", | |
| 361 | + (K::ErrMeeting, Lang::En) => { | |
| 362 | + "A meeting time needs a deadline day, and the time must exist in your time zone." | |
| 363 | + } | |
| 364 | + (K::ErrMeeting, Lang::Tr) => { | |
| 365 | + "Toplantı saati için bir son tarih gerekir ve saat sizin saat diliminizde olmalı." | |
| 366 | + } | |
| 367 | + (K::ErrAssignee, Lang::En) => "That person cannot be assigned.", | |
| 368 | + (K::ErrAssignee, Lang::Tr) => "Bu kişi atanamaz.", | |
| 369 | + (K::ErrSelf, Lang::En) => "A task cannot depend on itself.", | |
| 370 | + (K::ErrSelf, Lang::Tr) => "Bir görev kendisine bağımlı olamaz.", | |
| 371 | + (K::ErrCycle, Lang::En) => { | |
| 372 | + "This dependency would make a cycle of tasks waiting for each other." | |
| 373 | + } | |
| 374 | + (K::ErrCycle, Lang::Tr) => { | |
| 375 | + "Bu bağımlılık birbirini bekleyen görevlerden bir döngü oluşturur." | |
| 376 | + } | |
| 377 | + (K::ErrParent, Lang::En) => { | |
| 378 | + "A subtask must sit directly under a top-level task, and the parent must not be a subtask." | |
| 379 | + } | |
| 380 | + (K::ErrParent, Lang::Tr) => { | |
| 381 | + "Bir alt görev doğrudan bir ana göreve bağlanır ve üst görev de bir alt görev olamaz." | |
| 382 | + } | |
| 383 | + (K::ErrParentHasChildren, Lang::En) => "A task with subtasks cannot become a subtask.", | |
| 384 | + (K::ErrParentHasChildren, Lang::Tr) => "Alt görevi olan bir görev, alt görev yapılamaz.", | |
| 385 | + (K::ErrComment, Lang::En) => "Write a comment of 1 to 10 000 characters.", | |
| 386 | + (K::ErrComment, Lang::Tr) => "1 ile 10 000 karakter arasında bir yorum yazın.", | |
| 387 | + (K::ErrSubtaskTitle, Lang::En) => "Enter a subtask title of up to 200 characters.", | |
| 388 | + (K::ErrSubtaskTitle, Lang::Tr) => "En fazla 200 karakterlik bir alt görev başlığı girin.", | |
| 389 | + (K::ErrOtherTask, Lang::En) => "Pick a task from the list.", | |
| 390 | + (K::ErrOtherTask, Lang::Tr) => "Listeden bir görev seçin.", | |
| 391 | + (K::ErrDirection, Lang::En) => "Pick one of the two directions.", | |
| 392 | + (K::ErrDirection, Lang::Tr) => "İki yönden birini seçin.", | |
| 393 | + } | |
| 394 | +} | |
| 395 | + | |
| 396 | +/// The sentence of one activity row: the kind, in the viewer's language. | |
| 397 | +pub fn activity_kind(lang: Lang, kind: &str) -> &'static str { | |
| 398 | + let key = match kind { | |
| 399 | + "task_created" => K::ActCreated, | |
| 400 | + "task_edited" => K::ActEdited, | |
| 401 | + "task_moved" => K::ActMoved, | |
| 402 | + "task_deleted" => K::ActDeleted, | |
| 403 | + "assigned" => K::ActAssigned, | |
| 404 | + "unassigned" => K::ActUnassigned, | |
| 405 | + "tag_changed" => K::ActTagChanged, | |
| 406 | + "parent_changed" => K::ActParentChanged, | |
| 407 | + "link_added" => K::ActLinkAdded, | |
| 408 | + "link_removed" => K::ActLinkRemoved, | |
| 409 | + "unblocked" => K::ActUnblocked, | |
| 410 | + "deadline_set" => K::ActDeadlineSet, | |
| 411 | + "deadline_cleared" => K::ActDeadlineCleared, | |
| 412 | + "clock_set" => K::ActClockSet, | |
| 413 | + "clock_cleared" => K::ActClockCleared, | |
| 414 | + "watch_changed" => K::ActWatchChanged, | |
| 415 | + "comment_added" => K::ActCommentAdded, | |
| 416 | + "comment_edited" => K::ActCommentEdited, | |
| 417 | + "comment_deleted" => K::ActCommentDeleted, | |
| 418 | + "file_added" => K::ActFileAdded, | |
| 419 | + "file_deleted" => K::ActFileDeleted, | |
| 420 | + "reminded" => K::ActReminded, | |
| 421 | + "account_changed" => K::ActAccountChanged, | |
| 422 | + _ => K::ActOther, | |
| 423 | + }; | |
| 424 | + t(lang, key) | |
| 425 | +} |
crates/iz-web/src/pages/board.rsmodified+27 -5
| @@ -20,7 +20,7 @@ use topcoat::Result; | ||
| 20 | 20 | use topcoat::context::{Cx, app_context}; |
| 21 | 21 | use topcoat::router::error::not_found; |
| 22 | 22 | use topcoat::router::response::Response; |
| 23 | -use topcoat::router::route; | |
| 23 | +use topcoat::router::{StatusCode, route}; | |
| 24 | 24 | use topcoat::view::view; |
| 25 | 25 | |
| 26 | 26 | use crate::assets::BOARD_JS_HREF; |
| @@ -105,6 +105,8 @@ pub struct BoardPage { | ||
| 105 | 105 | pub alert: Option<K>, |
| 106 | 106 | /// The notice of the last write, shown above the board. |
| 107 | 107 | pub notice: Option<&'static str>, |
| 108 | + /// The task modal, when `?task=<key>` opened one (`pages/task.rs`). | |
| 109 | + pub modal: Option<crate::pages::task::TaskModal>, | |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | 112 | /// The board of this installation. The board is created at boot, so its absence is a missing page. |
| @@ -249,6 +251,7 @@ pub async fn load( | ||
| 249 | 251 | new_form: None, |
| 250 | 252 | alert: None, |
| 251 | 253 | notice: None, |
| 254 | + modal: None, | |
| 252 | 255 | }) |
| 253 | 256 | } |
| 254 | 257 | |
| @@ -297,13 +300,32 @@ async fn board_page(cx: &Cx) -> Result<Response> { | ||
| 297 | 300 | let lang = lang(cx, me.member.locale_override.as_deref()); |
| 298 | 301 | let query = uri_query(cx); |
| 299 | 302 | let mut page = load(&state.store, &me, lang, query.as_deref()).await?; |
| 300 | - let new_wanted = query_param(cx, "new").is_some_and(|v| v == "1"); | |
| 301 | - if new_wanted && page.can_write { | |
| 302 | - page.new_form = Some(blank_form(&page)); | |
| 303 | + let mut status = None; | |
| 304 | + match query_param(cx, "task").filter(|key| !key.is_empty()) { | |
| 305 | + Some(key) => { | |
| 306 | + let draft = crate::pages::task::Draft { | |
| 307 | + confirm: query_param(cx, "confirm").is_some_and(|v| v == "delete"), | |
| 308 | + before: query_param(cx, "before"), | |
| 309 | + ..Default::default() | |
| 310 | + }; | |
| 311 | + let found = | |
| 312 | + crate::pages::task::open(state, &me, &mut page, &key, query.as_deref(), draft) | |
| 313 | + .await?; | |
| 314 | + if !found { | |
| 315 | + page.alert = Some(K::TaskNotFound); | |
| 316 | + status = Some(StatusCode::NOT_FOUND); | |
| 317 | + } | |
| 318 | + } | |
| 319 | + None => { | |
| 320 | + let new_wanted = query_param(cx, "new").is_some_and(|v| v == "1"); | |
| 321 | + if new_wanted && page.can_write { | |
| 322 | + page.new_form = Some(blank_form(&page)); | |
| 323 | + } | |
| 324 | + } | |
| 303 | 325 | } |
| 304 | 326 | page.notice = |
| 305 | 327 | query_param(cx, "notice").and_then(|name| crate::i18n::board::notice(lang, &name)); |
| 306 | - render(cx, &page, None).await | |
| 328 | + render(cx, &page, status).await | |
| 307 | 329 | } |
| 308 | 330 | |
| 309 | 331 | /// The new-task form with the first column and the default project chosen. |
crates/iz-web/src/pages/mod.rsmodified+1 -0
| @@ -5,4 +5,5 @@ pub mod board; | ||
| 5 | 5 | pub mod not_found; |
| 6 | 6 | pub mod photo; |
| 7 | 7 | pub mod sign_in; |
| 8 | +pub mod task; | |
| 8 | 9 | pub mod tasks; |
crates/iz-web/src/pages/task.rsadded+1345 -0
| @@ -0,0 +1,1345 @@ | ||
| 1 | +//! The task modal (`docs/architecture.md` section 4, `docs/reference/old-inventory.md` 2.3): the card that | |
| 2 | +//! `GET /?task=<key>` opens over the board, and every write the modal makes. | |
| 3 | +//! | |
| 4 | +//! Reads: the modal loads one task of this board by its key. A key that is unknown, deleted or on another | |
| 5 | +//! board answers the board with a "not found" notice and `404`. A viewer sees the same content with no | |
| 6 | +//! write control. | |
| 7 | +//! | |
| 8 | +//! Writes: every write is a form that carries the CSRF token and a `next` path (the modal's own URL). The | |
| 9 | +//! gate is the same as the board's (`pages/tasks.rs`): a member with the write level, the token, then the | |
| 10 | +//! change. A refused change re-renders the board with the modal open, the message above the fields, and | |
| 11 | +//! the typed values kept, at `422`. An accepted change redirects (Post/Redirect/Get) to the modal of its | |
| 12 | +//! task, with a notice. Each write bumps the board topic and the task topic (`live.rs`). | |
| 13 | +//! | |
| 14 | +//! Comments are checked by their own id: the store loads the comment, checks that its task is live and on | |
| 15 | +//! this board, and only then asks `authz` whether this member may edit or delete it. A comment of a deleted | |
| 16 | +//! task is not found. | |
| 17 | + | |
| 18 | +use std::collections::{HashMap, HashSet}; | |
| 19 | +use std::result::Result as StdResult; | |
| 20 | + | |
| 21 | +use iz_core::authz::{Action, authorize}; | |
| 22 | +use iz_core::clock::{MeetingInput, resolve_meeting, timestamp_of}; | |
| 23 | +use iz_core::limits::{COMMENT_MAX, DESCRIPTION_MAX, TITLE_MAX}; | |
| 24 | +use iz_core::store::board::Tag; | |
| 25 | +use iz_core::store::members::Member; | |
| 26 | +use iz_core::store::tasks::{NewTask, Task, TaskDetail, TaskEdit}; | |
| 27 | +use iz_core::zones::{parse_zone, utc_to_local}; | |
| 28 | +use jiff::civil::Date; | |
| 29 | +use jiff::tz::TimeZone; | |
| 30 | +use serde::Deserialize; | |
| 31 | +use topcoat::Result; | |
| 32 | +use topcoat::context::{Cx, app_context}; | |
| 33 | +use topcoat::router::content::Form; | |
| 34 | +use topcoat::router::error::{forbidden, not_found, see_other}; | |
| 35 | +use topcoat::router::response::Response; | |
| 36 | +use topcoat::router::{StatusCode, path_param_segment, route}; | |
| 37 | + | |
| 38 | +use crate::auth::{CurrentMember, percent_encode, safe_next}; | |
| 39 | +use crate::i18n::board::{K as BK, t as bt}; | |
| 40 | +use crate::i18n::task::{K, activity_kind, t}; | |
| 41 | +use crate::i18n::{Lang, lang}; | |
| 42 | +use crate::live::Topic; | |
| 43 | +use crate::pages::board::{BoardPage, board_url, load, pairs, query_of, render, the_board}; | |
| 44 | +use crate::pages::tasks::{answer_stop, writer}; | |
| 45 | +use crate::state::AppState; | |
| 46 | + | |
| 47 | +/// Rows of activity per page in the modal. Reason: the feed is a summary; older rows are one click away. | |
| 48 | +const ACTIVITY_PAGE: usize = 20; | |
| 49 | + | |
| 50 | +/// The filters that the modal keeps in its own links, so the board behind it is the same one. | |
| 51 | +const FILTER_KEYS: [&str; 4] = ["tag", "assignee", "sort", "q"]; | |
| 52 | + | |
| 53 | +/// The fields of the edit form as typed, or as stored. A refused edit shows the typed values again. | |
| 54 | +#[derive(Clone, Debug, Default)] | |
| 55 | +pub struct EditValues { | |
| 56 | + /// The title. | |
| 57 | + pub title: String, | |
| 58 | + /// The description, as plain text. | |
| 59 | + pub description: String, | |
| 60 | + /// The project id. | |
| 61 | + pub tag: String, | |
| 62 | + /// The deadline day, `YYYY-MM-DD`, or empty. | |
| 63 | + pub deadline: String, | |
| 64 | + /// The meeting time in the viewer's zone, `HH:MM`, or empty. | |
| 65 | + pub time: String, | |
| 66 | +} | |
| 67 | + | |
| 68 | +/// One comment as the modal shows it, with the rights of the viewer over it. | |
| 69 | +pub struct CommentRow { | |
| 70 | + /// The comment id. | |
| 71 | + pub id: String, | |
| 72 | + /// The author's name. | |
| 73 | + pub author: String, | |
| 74 | + /// The body as stored (plain text). | |
| 75 | + pub body: String, | |
| 76 | + /// When it was written, in the viewer's zone, `YYYY-MM-DD HH:MM`. | |
| 77 | + pub when: String, | |
| 78 | + /// Whether it was edited after it was written. | |
| 79 | + pub edited: bool, | |
| 80 | + /// Whether the viewer may edit it (its author, while a member). | |
| 81 | + pub can_edit: bool, | |
| 82 | + /// Whether the viewer may delete it (its author, or an admin). | |
| 83 | + pub can_delete: bool, | |
| 84 | +} | |
| 85 | + | |
| 86 | +/// One row of the activity feed. | |
| 87 | +pub struct ActivityRow { | |
| 88 | + /// The sentence for the kind of event, in the viewer's language. | |
| 89 | + pub sentence: &'static str, | |
| 90 | + /// Who did it, by name (`-` for the system). | |
| 91 | + pub actor: String, | |
| 92 | + /// When, in the viewer's zone, `YYYY-MM-DD HH:MM`. | |
| 93 | + pub when: String, | |
| 94 | +} | |
| 95 | + | |
| 96 | +/// The task modal, as the board page shows it. | |
| 97 | +pub struct TaskModal { | |
| 98 | + /// The task with its tag, assignees, subtasks and links. | |
| 99 | + pub detail: TaskDetail, | |
| 100 | + /// Whether the viewer may change the task. | |
| 101 | + pub can_write: bool, | |
| 102 | + /// This modal's own URL: the board filters and `task=<key>`. Forms return here. | |
| 103 | + pub base: String, | |
| 104 | + /// The board with the same filters and no task: where the modal closes. | |
| 105 | + pub close: String, | |
| 106 | + /// The edit form's values: the stored ones, or the typed ones after a refusal. | |
| 107 | + pub edit: EditValues, | |
| 108 | + /// Enabled members who may be assigned and are not yet assigned here. | |
| 109 | + pub assignable: Vec<Member>, | |
| 110 | + /// Every other live task of the board, for the dependency and parent pickers. | |
| 111 | + pub options: Vec<Task>, | |
| 112 | + /// Whether the viewer watches the task. | |
| 113 | + pub watching: bool, | |
| 114 | + /// The live comments, oldest first. | |
| 115 | + pub comments: Vec<CommentRow>, | |
| 116 | + /// The newest page of the activity feed. | |
| 117 | + pub activity: Vec<ActivityRow>, | |
| 118 | + /// The URL of the next, older page of activity, when there is one. | |
| 119 | + pub older: Option<String>, | |
| 120 | + /// Whether the delete confirmation is open. | |
| 121 | + pub confirm_delete: bool, | |
| 122 | + /// The message of a refused write, shown above the fields. | |
| 123 | + pub error: Option<&'static str>, | |
| 124 | + /// The comment text typed in the composer, kept after a refusal. | |
| 125 | + pub comment_draft: String, | |
| 126 | +} | |
| 127 | + | |
| 128 | +/// What a re-rendered modal starts from: the message of a refusal, the typed values, and the view options. | |
| 129 | +#[derive(Default)] | |
| 130 | +pub struct Draft { | |
| 131 | + /// The refusal to show. | |
| 132 | + pub error: Option<&'static str>, | |
| 133 | + /// The typed edit values, when the edit was refused. | |
| 134 | + pub edit: Option<EditValues>, | |
| 135 | + /// The typed comment, when the comment was refused. | |
| 136 | + pub comment: Option<String>, | |
| 137 | + /// Whether the delete confirmation is open (`?confirm=delete`). | |
| 138 | + pub confirm: bool, | |
| 139 | + /// The cursor of the activity page to show (`?before=`). | |
| 140 | + pub before: Option<String>, | |
| 141 | +} | |
| 142 | + | |
| 143 | +/// The form of every modal write. Each field is optional on the wire; a missing one is empty. | |
| 144 | +#[derive(Deserialize, Default)] | |
| 145 | +pub struct ModalForm { | |
| 146 | + #[serde(default)] | |
| 147 | + csrf: String, | |
| 148 | + /// The modal URL the form was on. | |
| 149 | + #[serde(default)] | |
| 150 | + next: String, | |
| 151 | + #[serde(default)] | |
| 152 | + title: String, | |
| 153 | + #[serde(default)] | |
| 154 | + description: String, | |
| 155 | + /// The project id. | |
| 156 | + #[serde(default)] | |
| 157 | + tag: String, | |
| 158 | + #[serde(default)] | |
| 159 | + deadline: String, | |
| 160 | + /// The meeting time, `HH:MM`. | |
| 161 | + #[serde(default)] | |
| 162 | + time: String, | |
| 163 | + /// A comment body. | |
| 164 | + #[serde(default)] | |
| 165 | + body: String, | |
| 166 | + /// A member's id, for assign and unassign. | |
| 167 | + #[serde(default)] | |
| 168 | + sub: String, | |
| 169 | + /// `1` to watch, `0` to stop. | |
| 170 | + #[serde(default)] | |
| 171 | + on: String, | |
| 172 | + /// The parent task's id, or empty for none. | |
| 173 | + #[serde(default)] | |
| 174 | + parent: String, | |
| 175 | + /// The other task of a dependency. | |
| 176 | + #[serde(default)] | |
| 177 | + other: String, | |
| 178 | + /// `blocked_by` (this task waits for `other`) or `blocks` (`other` waits for this task). | |
| 179 | + #[serde(default)] | |
| 180 | + direction: String, | |
| 181 | +} | |
| 182 | + | |
| 183 | +/// The modal's URL for `key`: the board filters of `query` and `task=<key>`, plus `extra`. Filters that are | |
| 184 | +/// not in [`FILTER_KEYS`] are dropped, so a stale `confirm` or `before` never comes back. | |
| 185 | +pub fn modal_url(query: Option<&str>, key: &str, extra: &[(&str, &str)]) -> String { | |
| 186 | + let mut parts: Vec<String> = pairs(query.unwrap_or("")) | |
| 187 | + .into_iter() | |
| 188 | + .filter(|(name, _)| FILTER_KEYS.contains(&name.as_str())) | |
| 189 | + .map(|(name, value)| format!("{name}={}", percent_encode(&value))) | |
| 190 | + .collect(); | |
| 191 | + parts.push(format!("task={}", percent_encode(key))); | |
| 192 | + parts.extend( | |
| 193 | + extra | |
| 194 | + .iter() | |
| 195 | + .map(|(name, value)| format!("{name}={}", percent_encode(value))), | |
| 196 | + ); | |
| 197 | + format!("/?{}", parts.join("&")) | |
| 198 | +} | |
| 199 | + | |
| 200 | +/// The link to another task's modal from `close` (the board URL with the filters). | |
| 201 | +pub fn task_link(close: &str, key: &str) -> String { | |
| 202 | + let separator = if close.contains('?') { '&' } else { '?' }; | |
| 203 | + format!("{close}{separator}task={}", percent_encode(key)) | |
| 204 | +} | |
| 205 | + | |
| 206 | +/// The `task` value of a `next` path, when it names one. | |
| 207 | +fn task_of(next: &str) -> Option<String> { | |
| 208 | + pairs(query_of(safe_next(Some(next))).unwrap_or("")) | |
| 209 | + .into_iter() | |
| 210 | + .find(|(name, _)| name == "task") | |
| 211 | + .map(|(_, value)| value) | |
| 212 | + .filter(|value| !value.is_empty()) | |
| 213 | +} | |
| 214 | + | |
| 215 | +/// Maps a store error to the framework's answer: a missing or hidden thing is `404`, a refused right is | |
| 216 | +/// `403`, and anything else is a logged `500`. | |
| 217 | +pub fn core_err(error: iz_core::Error) -> topcoat::Error { | |
| 218 | + match error { | |
| 219 | + iz_core::Error::NotFound => not_found().into(), | |
| 220 | + iz_core::Error::Forbidden(_) => forbidden().into(), | |
| 221 | + other => other.into(), | |
| 222 | + } | |
| 223 | +} | |
| 224 | + | |
| 225 | +/// The zone of the signed-in member; UTC when the stored name does not parse. | |
| 226 | +fn zone_of(me: &CurrentMember) -> TimeZone { | |
| 227 | + parse_zone(&me.member.zoneinfo).unwrap_or(TimeZone::UTC) | |
| 228 | +} | |
| 229 | + | |
| 230 | +/// A stored UTC stamp in `zone` as `YYYY-MM-DD HH:MM`. Empty when the stamp does not parse. | |
| 231 | +fn local_text(stamp: &str, zone: &TimeZone) -> String { | |
| 232 | + match timestamp_of(stamp) { | |
| 233 | + Ok(at) => { | |
| 234 | + let local = utc_to_local(zone, at); | |
| 235 | + format!( | |
| 236 | + "{:04}-{:02}-{:02} {:02}:{:02}", | |
| 237 | + local.year(), | |
| 238 | + local.month(), | |
| 239 | + local.day(), | |
| 240 | + local.hour(), | |
| 241 | + local.minute() | |
| 242 | + ) | |
| 243 | + } | |
| 244 | + Err(_) => String::new(), | |
| 245 | + } | |
| 246 | +} | |
| 247 | + | |
| 248 | +/// A stored UTC stamp in `zone` as `HH:MM`, for the time field. | |
| 249 | +fn clock_text(stamp: &str, zone: &TimeZone) -> String { | |
| 250 | + match timestamp_of(stamp) { | |
| 251 | + Ok(at) => { | |
| 252 | + let local = utc_to_local(zone, at); | |
| 253 | + format!("{:02}:{:02}", local.hour(), local.minute()) | |
| 254 | + } | |
| 255 | + Err(_) => String::new(), | |
| 256 | + } | |
| 257 | +} | |
| 258 | + | |
| 259 | +/// Reads `HH:MM` (one or two digits per part). `None` for anything else, or an hour or minute out of range. | |
| 260 | +fn parse_clock(text: &str) -> Option<(u8, u8)> { | |
| 261 | + let (hour, minute) = text.trim().split_once(':')?; | |
| 262 | + if hour.is_empty() || hour.len() > 2 || minute.len() != 2 { | |
| 263 | + return None; | |
| 264 | + } | |
| 265 | + let hour: u8 = hour.parse().ok()?; | |
| 266 | + let minute: u8 = minute.parse().ok()?; | |
| 267 | + (hour < 24 && minute < 60).then_some((hour, minute)) | |
| 268 | +} | |
| 269 | + | |
| 270 | +/// Checks the edit form and turns it into the store's input. The first problem found is the message. The | |
| 271 | +/// deadline and the meeting time are resolved in the viewer's zone (`clock.rs`). | |
| 272 | +fn edit_input( | |
| 273 | + form: &ModalForm, | |
| 274 | + tags: &[Tag], | |
| 275 | + zone: &TimeZone, | |
| 276 | + language: Lang, | |
| 277 | +) -> StdResult<TaskEdit, &'static str> { | |
| 278 | + let title = form.title.trim(); | |
| 279 | + if title.is_empty() || title.chars().count() > TITLE_MAX { | |
| 280 | + return Err(bt(language, BK::TitleInvalid)); | |
| 281 | + } | |
| 282 | + if form.description.chars().count() > DESCRIPTION_MAX { | |
| 283 | + return Err(t(language, K::DescriptionTooLong)); | |
| 284 | + } | |
| 285 | + if !tags.iter().any(|tag| tag.id == form.tag) { | |
| 286 | + return Err(t(language, K::ErrProject)); | |
| 287 | + } | |
| 288 | + let day = match form.deadline.trim() { | |
| 289 | + "" => None, | |
| 290 | + text => Some( | |
| 291 | + text.parse::<Date>() | |
| 292 | + .map_err(|_| t(language, K::ErrDeadline))?, | |
| 293 | + ), | |
| 294 | + }; | |
| 295 | + let clock = match form.time.trim() { | |
| 296 | + "" => None, | |
| 297 | + text => Some(parse_clock(text).ok_or(t(language, K::ErrTime))?), | |
| 298 | + }; | |
| 299 | + let (hour, minute) = match clock { | |
| 300 | + Some((hour, minute)) => (Some(hour), Some(minute)), | |
| 301 | + None => (None, None), | |
| 302 | + }; | |
| 303 | + let (deadline, meeting_at) = resolve_meeting(MeetingInput { day, hour, minute }, zone) | |
| 304 | + .map_err(|_| t(language, K::ErrMeeting))?; | |
| 305 | + Ok(TaskEdit { | |
| 306 | + title: title.to_owned(), | |
| 307 | + description: form.description.clone(), | |
| 308 | + tag_id: form.tag.clone(), | |
| 309 | + deadline, | |
| 310 | + meeting_at, | |
| 311 | + }) | |
| 312 | +} | |
| 313 | + | |
| 314 | +/// The direction of a dependency as the stored pair: `(blocked, blocking)`. `None` for an unknown word. | |
| 315 | +fn link_pair<'a>(task: &'a str, other: &'a str, direction: &str) -> Option<(&'a str, &'a str)> { | |
| 316 | + match direction { | |
| 317 | + "blocked_by" => Some((task, other)), | |
| 318 | + "blocks" => Some((other, task)), | |
| 319 | + _ => None, | |
| 320 | + } | |
| 321 | +} | |
| 322 | + | |
| 323 | +/// Loads the modal of `key` into `page`. Returns `false` when the task does not exist on this board (or is | |
| 324 | +/// deleted); the page is then left as it was. | |
| 325 | +pub async fn open( | |
| 326 | + state: &AppState, | |
| 327 | + me: &CurrentMember, | |
| 328 | + page: &mut BoardPage, | |
| 329 | + key: &str, | |
| 330 | + query: Option<&str>, | |
| 331 | + draft: Draft, | |
| 332 | +) -> Result<bool> { | |
| 333 | + let store = &state.store; | |
| 334 | + let board = the_board(store).await?; | |
| 335 | + let detail = match store.task_detail(&board.id, key).await { | |
| 336 | + Ok(detail) => detail, | |
| 337 | + Err(iz_core::Error::NotFound) => return Ok(false), | |
| 338 | + Err(error) => return Err(core_err(error)), | |
| 339 | + }; | |
| 340 | + let task_id = detail.task.id.clone(); | |
| 341 | + let zone = page.zone.clone(); | |
| 342 | + let names: HashMap<String, String> = store | |
| 343 | + .list_members() | |
| 344 | + .await | |
| 345 | + .map_err(core_err)? | |
| 346 | + .into_iter() | |
| 347 | + .map(|member| (member.sub, member.name)) | |
| 348 | + .collect(); | |
| 349 | + let name_of = |sub: &str| names.get(sub).cloned().unwrap_or_else(|| "-".to_owned()); | |
| 350 | + let comments = store | |
| 351 | + .list_comments(&board.id, &task_id) | |
| 352 | + .await | |
| 353 | + .map_err(core_err)?; | |
| 354 | + let before = draft.before.filter(|cursor| cursor.contains('~')); | |
| 355 | + let feed = store | |
| 356 | + .list_task_page(&board.id, &task_id, before.as_deref(), ACTIVITY_PAGE) | |
| 357 | + .await | |
| 358 | + .map_err(core_err)?; | |
| 359 | + let watching = store | |
| 360 | + .is_watching(&task_id, &me.member.sub) | |
| 361 | + .await | |
| 362 | + .map_err(core_err)?; | |
| 363 | + let options: Vec<Task> = store | |
| 364 | + .task_options(&board.id) | |
| 365 | + .await | |
| 366 | + .map_err(core_err)? | |
| 367 | + .into_iter() | |
| 368 | + .filter(|other| other.id != task_id) | |
| 369 | + .collect(); | |
| 370 | + let assigned: HashSet<&str> = detail.assignees.iter().map(|a| a.sub.as_str()).collect(); | |
| 371 | + let assignable: Vec<Member> = page | |
| 372 | + .members | |
| 373 | + .iter() | |
| 374 | + .filter(|member| !assigned.contains(member.sub.as_str())) | |
| 375 | + .cloned() | |
| 376 | + .collect(); | |
| 377 | + let can_write = page.can_write; | |
| 378 | + let comment_rows: Vec<CommentRow> = comments | |
| 379 | + .into_iter() | |
| 380 | + .map(|comment| { | |
| 381 | + let author = comment.author.clone(); | |
| 382 | + CommentRow { | |
| 383 | + can_edit: can_write | |
| 384 | + && authorize( | |
| 385 | + &me.actor(), | |
| 386 | + &Action::EditComment { | |
| 387 | + author: author.clone(), | |
| 388 | + }, | |
| 389 | + ) | |
| 390 | + .is_ok(), | |
| 391 | + can_delete: can_write | |
| 392 | + && authorize( | |
| 393 | + &me.actor(), | |
| 394 | + &Action::DeleteComment { | |
| 395 | + author: author.clone(), | |
| 396 | + }, | |
| 397 | + ) | |
| 398 | + .is_ok(), | |
| 399 | + author: name_of(&author), | |
| 400 | + when: local_text(&comment.created_at, &zone), | |
| 401 | + edited: comment.edited_at.is_some(), | |
| 402 | + id: comment.id, | |
| 403 | + body: comment.body, | |
| 404 | + } | |
| 405 | + }) | |
| 406 | + .collect(); | |
| 407 | + let activity: Vec<ActivityRow> = feed | |
| 408 | + .items | |
| 409 | + .iter() | |
| 410 | + .map(|item| ActivityRow { | |
| 411 | + sentence: activity_kind(page.lang, &item.kind), | |
| 412 | + actor: item | |
| 413 | + .actor | |
| 414 | + .as_deref() | |
| 415 | + .map_or_else(|| "-".to_owned(), name_of), | |
| 416 | + when: local_text(&item.at, &zone), | |
| 417 | + }) | |
| 418 | + .collect(); | |
| 419 | + let base = modal_url(query, key, &[]); | |
| 420 | + let older = feed | |
| 421 | + .next_cursor | |
| 422 | + .map(|cursor| format!("{base}&before={}", percent_encode(&cursor))); | |
| 423 | + let stored = EditValues { | |
| 424 | + title: detail.task.title.clone(), | |
| 425 | + description: detail.task.description.clone(), | |
| 426 | + tag: detail.task.tag_id.clone(), | |
| 427 | + deadline: detail | |
| 428 | + .task | |
| 429 | + .deadline | |
| 430 | + .map(|day| day.to_string()) | |
| 431 | + .unwrap_or_default(), | |
| 432 | + time: detail | |
| 433 | + .task | |
| 434 | + .meeting_at | |
| 435 | + .as_deref() | |
| 436 | + .map(|stamp| clock_text(stamp, &zone)) | |
| 437 | + .unwrap_or_default(), | |
| 438 | + }; | |
| 439 | + let modal = TaskModal { | |
| 440 | + can_write, | |
| 441 | + close: board_url(&page.filters, &[]), | |
| 442 | + base, | |
| 443 | + edit: draft.edit.unwrap_or(stored), | |
| 444 | + assignable, | |
| 445 | + options, | |
| 446 | + watching, | |
| 447 | + comments: comment_rows, | |
| 448 | + activity, | |
| 449 | + older, | |
| 450 | + confirm_delete: draft.confirm && can_write, | |
| 451 | + error: draft.error, | |
| 452 | + comment_draft: draft.comment.unwrap_or_default(), | |
| 453 | + detail, | |
| 454 | + }; | |
| 455 | + page.modal = Some(modal); | |
| 456 | + Ok(true) | |
| 457 | +} | |
| 458 | + | |
| 459 | +/// A write that passed the gate and found its task on this board. | |
| 460 | +struct Begun { | |
| 461 | + me: CurrentMember, | |
| 462 | + lang: Lang, | |
| 463 | + board_id: String, | |
| 464 | + detail: TaskDetail, | |
| 465 | +} | |
| 466 | + | |
| 467 | +/// The gate of a write: the member with the write level and the CSRF token, then the board. A refusal of | |
| 468 | +/// the gate is answered as the board's writes answer theirs; the inner `Err` carries that answer. | |
| 469 | +async fn gate( | |
| 470 | + cx: &Cx, | |
| 471 | + csrf: &str, | |
| 472 | + next: &str, | |
| 473 | +) -> Result<StdResult<(CurrentMember, Lang, String), Response>> { | |
| 474 | + let state = app_context::<AppState>(cx); | |
| 475 | + let me = match writer(cx, csrf).await { | |
| 476 | + Ok(me) => me, | |
| 477 | + Err(stop) => { | |
| 478 | + return Ok(Err( | |
| 479 | + answer_stop(cx, stop, false, next, lang(cx, None)).await? | |
| 480 | + )); | |
| 481 | + } | |
| 482 | + }; | |
| 483 | + let language = lang(cx, me.member.locale_override.as_deref()); | |
| 484 | + let board = the_board(&state.store).await?; | |
| 485 | + Ok(Ok((me, language, board.id))) | |
| 486 | +} | |
| 487 | + | |
| 488 | +/// The gate of a write that names its task in the path. | |
| 489 | +async fn gate_task(cx: &Cx, form: &ModalForm, task_id: &str) -> Result<StdResult<Begun, Response>> { | |
| 490 | + let state = app_context::<AppState>(cx); | |
| 491 | + let (me, language, board_id) = match gate(cx, &form.csrf, &form.next).await? { | |
| 492 | + Ok(found) => found, | |
| 493 | + Err(response) => return Ok(Err(response)), | |
| 494 | + }; | |
| 495 | + let detail = state | |
| 496 | + .store | |
| 497 | + .task_detail(&board_id, task_id) | |
| 498 | + .await | |
| 499 | + .map_err(core_err)?; | |
| 500 | + Ok(Ok(Begun { | |
| 501 | + me, | |
| 502 | + lang: language, | |
| 503 | + board_id, | |
| 504 | + detail, | |
| 505 | + })) | |
| 506 | +} | |
| 507 | + | |
| 508 | +/// Re-renders the board with the modal of `key` open, the refusal above its fields, and `422`. When the | |
| 509 | +/// task is gone the board answers `404` with its "not found" notice. | |
| 510 | +async fn refuse( | |
| 511 | + cx: &Cx, | |
| 512 | + me: &CurrentMember, | |
| 513 | + language: Lang, | |
| 514 | + next: &str, | |
| 515 | + key: &str, | |
| 516 | + draft: Draft, | |
| 517 | +) -> Result<Response> { | |
| 518 | + let state = app_context::<AppState>(cx); | |
| 519 | + let query = query_of(safe_next(Some(next))); | |
| 520 | + let mut page = load(&state.store, me, language, query).await?; | |
| 521 | + let found = open(state, me, &mut page, key, query, draft).await?; | |
| 522 | + let status = if found { | |
| 523 | + StatusCode::UNPROCESSABLE_ENTITY | |
| 524 | + } else { | |
| 525 | + page.alert = Some(BK::TaskNotFound); | |
| 526 | + StatusCode::NOT_FOUND | |
| 527 | + }; | |
| 528 | + render(cx, &page, Some(status)).await | |
| 529 | +} | |
| 530 | + | |
| 531 | +/// A `Draft` that only shows a refusal. | |
| 532 | +fn refusal(message: &'static str) -> Draft { | |
| 533 | + Draft { | |
| 534 | + error: Some(message), | |
| 535 | + ..Draft::default() | |
| 536 | + } | |
| 537 | +} | |
| 538 | + | |
| 539 | +/// Tells every open view of the board and of the task that something changed. | |
| 540 | +fn bump(state: &AppState, board_id: &str, task_id: &str) { | |
| 541 | + state.live.bump(&Topic::Board(board_id.to_owned())); | |
| 542 | + state.live.bump(&Topic::Task(task_id.to_owned())); | |
| 543 | +} | |
| 544 | + | |
| 545 | +/// Answers a write that went through: the modal of `key` with the saved notice, or the board when there is | |
| 546 | +/// no task to return to. | |
| 547 | +fn back(next: &str, key: Option<&str>) -> Result<Response> { | |
| 548 | + let target = match key { | |
| 549 | + Some(key) => modal_url(query_of(safe_next(Some(next))), key, &[("notice", "saved")]), | |
| 550 | + None => "/".to_owned(), | |
| 551 | + }; | |
| 552 | + Err(see_other(target).into()) | |
| 553 | +} | |
| 554 | + | |
| 555 | +/// `POST /tasks/{id}/edit`: the title, description, project, deadline and meeting time. | |
| 556 | +#[route(POST "/tasks/{id}/edit")] | |
| 557 | +async fn edit_task(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 558 | + let state = app_context::<AppState>(cx); | |
| 559 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 560 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 561 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 562 | + Ok(begun) => begun, | |
| 563 | + Err(response) => return Ok(response), | |
| 564 | + }; | |
| 565 | + let key = begun.detail.task.key.clone(); | |
| 566 | + let zone = zone_of(&begun.me); | |
| 567 | + let tags = state.store.tags(&begun.board_id).await.map_err(core_err)?; | |
| 568 | + let typed = EditValues { | |
| 569 | + title: form.title.clone(), | |
| 570 | + description: form.description.clone(), | |
| 571 | + tag: form.tag.clone(), | |
| 572 | + deadline: form.deadline.clone(), | |
| 573 | + time: form.time.clone(), | |
| 574 | + }; | |
| 575 | + let edit = match edit_input(&form, &tags, &zone, begun.lang) { | |
| 576 | + Ok(edit) => edit, | |
| 577 | + Err(message) => { | |
| 578 | + let draft = Draft { | |
| 579 | + edit: Some(typed), | |
| 580 | + ..refusal(message) | |
| 581 | + }; | |
| 582 | + return refuse(cx, &begun.me, begun.lang, &form.next, &key, draft).await; | |
| 583 | + } | |
| 584 | + }; | |
| 585 | + match state | |
| 586 | + .store | |
| 587 | + .edit_task(&begun.board_id, &task_id, edit, &begun.me.member.sub) | |
| 588 | + .await | |
| 589 | + { | |
| 590 | + Ok(_) => { | |
| 591 | + bump(state, &begun.board_id, &task_id); | |
| 592 | + back(&form.next, Some(key.as_str())) | |
| 593 | + } | |
| 594 | + Err(iz_core::Error::Invalid(_)) => { | |
| 595 | + let draft = Draft { | |
| 596 | + edit: Some(typed), | |
| 597 | + ..refusal(bt(begun.lang, BK::InvalidForm)) | |
| 598 | + }; | |
| 599 | + refuse(cx, &begun.me, begun.lang, &form.next, &key, draft).await | |
| 600 | + } | |
| 601 | + Err(error) => Err(core_err(error)), | |
| 602 | + } | |
| 603 | +} | |
| 604 | + | |
| 605 | +/// `POST /tasks/{id}/assign`: adds one member. The store refuses anyone who is not an enabled admin or | |
| 606 | +/// member. | |
| 607 | +#[route(POST "/tasks/{id}/assign")] | |
| 608 | +async fn assign(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 609 | + let state = app_context::<AppState>(cx); | |
| 610 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 611 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 612 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 613 | + Ok(begun) => begun, | |
| 614 | + Err(response) => return Ok(response), | |
| 615 | + }; | |
| 616 | + let key = begun.detail.task.key.clone(); | |
| 617 | + let sub = form.sub.trim().to_owned(); | |
| 618 | + if sub.is_empty() { | |
| 619 | + return refuse( | |
| 620 | + cx, | |
| 621 | + &begun.me, | |
| 622 | + begun.lang, | |
| 623 | + &form.next, | |
| 624 | + &key, | |
| 625 | + refusal(t(begun.lang, K::ErrAssignee)), | |
| 626 | + ) | |
| 627 | + .await; | |
| 628 | + } | |
| 629 | + match state | |
| 630 | + .store | |
| 631 | + .assign(&begun.board_id, &task_id, &[sub], &begun.me.member.sub) | |
| 632 | + .await | |
| 633 | + { | |
| 634 | + Ok(()) => { | |
| 635 | + bump(state, &begun.board_id, &task_id); | |
| 636 | + back(&form.next, Some(key.as_str())) | |
| 637 | + } | |
| 638 | + Err(iz_core::Error::Invalid(_)) => { | |
| 639 | + refuse( | |
| 640 | + cx, | |
| 641 | + &begun.me, | |
| 642 | + begun.lang, | |
| 643 | + &form.next, | |
| 644 | + &key, | |
| 645 | + refusal(t(begun.lang, K::ErrAssignee)), | |
| 646 | + ) | |
| 647 | + .await | |
| 648 | + } | |
| 649 | + Err(error) => Err(core_err(error)), | |
| 650 | + } | |
| 651 | +} | |
| 652 | + | |
| 653 | +/// `POST /tasks/{id}/unassign`: removes one member. Removing someone who is not assigned changes nothing. | |
| 654 | +#[route(POST "/tasks/{id}/unassign")] | |
| 655 | +async fn unassign(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 656 | + let state = app_context::<AppState>(cx); | |
| 657 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 658 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 659 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 660 | + Ok(begun) => begun, | |
| 661 | + Err(response) => return Ok(response), | |
| 662 | + }; | |
| 663 | + let key = begun.detail.task.key.clone(); | |
| 664 | + state | |
| 665 | + .store | |
| 666 | + .unassign( | |
| 667 | + &begun.board_id, | |
| 668 | + &task_id, | |
| 669 | + &[form.sub.trim().to_owned()], | |
| 670 | + &begun.me.member.sub, | |
| 671 | + ) | |
| 672 | + .await | |
| 673 | + .map_err(core_err)?; | |
| 674 | + bump(state, &begun.board_id, &task_id); | |
| 675 | + back(&form.next, Some(key.as_str())) | |
| 676 | +} | |
| 677 | + | |
| 678 | +/// `POST /tasks/{id}/watch`: starts (`on=1`) or stops (`on=0`) watching the task, for the viewer. | |
| 679 | +#[route(POST "/tasks/{id}/watch")] | |
| 680 | +async fn watch(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 681 | + let state = app_context::<AppState>(cx); | |
| 682 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 683 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 684 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 685 | + Ok(begun) => begun, | |
| 686 | + Err(response) => return Ok(response), | |
| 687 | + }; | |
| 688 | + let key = begun.detail.task.key.clone(); | |
| 689 | + let on = match form.on.trim() { | |
| 690 | + "1" => true, | |
| 691 | + "0" => false, | |
| 692 | + _ => { | |
| 693 | + return refuse( | |
| 694 | + cx, | |
| 695 | + &begun.me, | |
| 696 | + begun.lang, | |
| 697 | + &form.next, | |
| 698 | + &key, | |
| 699 | + refusal(bt(begun.lang, BK::InvalidForm)), | |
| 700 | + ) | |
| 701 | + .await; | |
| 702 | + } | |
| 703 | + }; | |
| 704 | + state | |
| 705 | + .store | |
| 706 | + .set_watch(&begun.board_id, &task_id, &begun.me.member.sub, on) | |
| 707 | + .await | |
| 708 | + .map_err(core_err)?; | |
| 709 | + bump(state, &begun.board_id, &task_id); | |
| 710 | + back(&form.next, Some(key.as_str())) | |
| 711 | +} | |
| 712 | + | |
| 713 | +/// `POST /tasks/{id}/subtasks`: creates a subtask under this task, in its column and project. | |
| 714 | +#[route(POST "/tasks/{id}/subtasks")] | |
| 715 | +async fn add_subtask(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 716 | + let state = app_context::<AppState>(cx); | |
| 717 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 718 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 719 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 720 | + Ok(begun) => begun, | |
| 721 | + Err(response) => return Ok(response), | |
| 722 | + }; | |
| 723 | + let key = begun.detail.task.key.clone(); | |
| 724 | + let title = form.title.trim().to_owned(); | |
| 725 | + if title.is_empty() || title.chars().count() > TITLE_MAX { | |
| 726 | + let message = t(begun.lang, K::ErrSubtaskTitle); | |
| 727 | + return refuse( | |
| 728 | + cx, | |
| 729 | + &begun.me, | |
| 730 | + begun.lang, | |
| 731 | + &form.next, | |
| 732 | + &key, | |
| 733 | + refusal(message), | |
| 734 | + ) | |
| 735 | + .await; | |
| 736 | + } | |
| 737 | + if begun.detail.task.parent_id.is_some() { | |
| 738 | + let message = t(begun.lang, K::ErrParent); | |
| 739 | + return refuse( | |
| 740 | + cx, | |
| 741 | + &begun.me, | |
| 742 | + begun.lang, | |
| 743 | + &form.next, | |
| 744 | + &key, | |
| 745 | + refusal(message), | |
| 746 | + ) | |
| 747 | + .await; | |
| 748 | + } | |
| 749 | + let input = NewTask { | |
| 750 | + title, | |
| 751 | + description: String::new(), | |
| 752 | + column_id: begun.detail.task.column_id.clone(), | |
| 753 | + tag_id: begun.detail.task.tag_id.clone(), | |
| 754 | + deadline: None, | |
| 755 | + meeting_at: None, | |
| 756 | + assignees: Vec::new(), | |
| 757 | + parent_id: Some(task_id.clone()), | |
| 758 | + link: None, | |
| 759 | + }; | |
| 760 | + match state | |
| 761 | + .store | |
| 762 | + .create_task(&begun.board_id, input, &begun.me.member.sub) | |
| 763 | + .await | |
| 764 | + { | |
| 765 | + Ok(_) => { | |
| 766 | + bump(state, &begun.board_id, &task_id); | |
| 767 | + back(&form.next, Some(key.as_str())) | |
| 768 | + } | |
| 769 | + Err(iz_core::Error::Invalid(_)) => { | |
| 770 | + let message = t(begun.lang, K::ErrParent); | |
| 771 | + refuse( | |
| 772 | + cx, | |
| 773 | + &begun.me, | |
| 774 | + begun.lang, | |
| 775 | + &form.next, | |
| 776 | + &key, | |
| 777 | + refusal(message), | |
| 778 | + ) | |
| 779 | + .await | |
| 780 | + } | |
| 781 | + Err(error) => Err(core_err(error)), | |
| 782 | + } | |
| 783 | +} | |
| 784 | + | |
| 785 | +/// `POST /tasks/{id}/parent`: makes this task a subtask of `parent`, or a top-level task when `parent` is | |
| 786 | +/// empty. One level only; the store refuses the rest. | |
| 787 | +#[route(POST "/tasks/{id}/parent")] | |
| 788 | +async fn set_parent(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 789 | + let state = app_context::<AppState>(cx); | |
| 790 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 791 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 792 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 793 | + Ok(begun) => begun, | |
| 794 | + Err(response) => return Ok(response), | |
| 795 | + }; | |
| 796 | + let key = begun.detail.task.key.clone(); | |
| 797 | + let parent = form.parent.trim(); | |
| 798 | + let parent = (!parent.is_empty()).then_some(parent); | |
| 799 | + match state | |
| 800 | + .store | |
| 801 | + .set_parent(&begun.board_id, &task_id, parent, &begun.me.member.sub) | |
| 802 | + .await | |
| 803 | + { | |
| 804 | + Ok(()) => { | |
| 805 | + bump(state, &begun.board_id, &task_id); | |
| 806 | + back(&form.next, Some(key.as_str())) | |
| 807 | + } | |
| 808 | + Err(iz_core::Error::Conflict(_)) => { | |
| 809 | + let message = t(begun.lang, K::ErrParentHasChildren); | |
| 810 | + refuse( | |
| 811 | + cx, | |
| 812 | + &begun.me, | |
| 813 | + begun.lang, | |
| 814 | + &form.next, | |
| 815 | + &key, | |
| 816 | + refusal(message), | |
| 817 | + ) | |
| 818 | + .await | |
| 819 | + } | |
| 820 | + Err(iz_core::Error::Invalid(_)) => { | |
| 821 | + let message = t(begun.lang, K::ErrParent); | |
| 822 | + refuse( | |
| 823 | + cx, | |
| 824 | + &begun.me, | |
| 825 | + begun.lang, | |
| 826 | + &form.next, | |
| 827 | + &key, | |
| 828 | + refusal(message), | |
| 829 | + ) | |
| 830 | + .await | |
| 831 | + } | |
| 832 | + Err(error) => Err(core_err(error)), | |
| 833 | + } | |
| 834 | +} | |
| 835 | + | |
| 836 | +/// `POST /tasks/{id}/links`: adds a dependency with `other`. A cycle is refused with its own message. | |
| 837 | +#[route(POST "/tasks/{id}/links")] | |
| 838 | +async fn add_link(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 839 | + let state = app_context::<AppState>(cx); | |
| 840 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 841 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 842 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 843 | + Ok(begun) => begun, | |
| 844 | + Err(response) => return Ok(response), | |
| 845 | + }; | |
| 846 | + let key = begun.detail.task.key.clone(); | |
| 847 | + let other = form.other.trim().to_owned(); | |
| 848 | + if other.is_empty() { | |
| 849 | + let message = t(begun.lang, K::ErrOtherTask); | |
| 850 | + return refuse( | |
| 851 | + cx, | |
| 852 | + &begun.me, | |
| 853 | + begun.lang, | |
| 854 | + &form.next, | |
| 855 | + &key, | |
| 856 | + refusal(message), | |
| 857 | + ) | |
| 858 | + .await; | |
| 859 | + } | |
| 860 | + let Some((blocked, blocking)) = link_pair(&task_id, &other, form.direction.trim()) else { | |
| 861 | + let message = t(begun.lang, K::ErrDirection); | |
| 862 | + return refuse( | |
| 863 | + cx, | |
| 864 | + &begun.me, | |
| 865 | + begun.lang, | |
| 866 | + &form.next, | |
| 867 | + &key, | |
| 868 | + refusal(message), | |
| 869 | + ) | |
| 870 | + .await; | |
| 871 | + }; | |
| 872 | + match state | |
| 873 | + .store | |
| 874 | + .add_dependency(&begun.board_id, blocked, blocking, &begun.me.member.sub) | |
| 875 | + .await | |
| 876 | + { | |
| 877 | + Ok(()) => { | |
| 878 | + bump(state, &begun.board_id, &task_id); | |
| 879 | + state.live.bump(&Topic::Task(other.clone())); | |
| 880 | + back(&form.next, Some(key.as_str())) | |
| 881 | + } | |
| 882 | + Err(iz_core::Error::Conflict(_)) => { | |
| 883 | + let message = t(begun.lang, K::ErrCycle); | |
| 884 | + refuse( | |
| 885 | + cx, | |
| 886 | + &begun.me, | |
| 887 | + begun.lang, | |
| 888 | + &form.next, | |
| 889 | + &key, | |
| 890 | + refusal(message), | |
| 891 | + ) | |
| 892 | + .await | |
| 893 | + } | |
| 894 | + Err(iz_core::Error::Invalid(_)) => { | |
| 895 | + let message = t(begun.lang, K::ErrSelf); | |
| 896 | + refuse( | |
| 897 | + cx, | |
| 898 | + &begun.me, | |
| 899 | + begun.lang, | |
| 900 | + &form.next, | |
| 901 | + &key, | |
| 902 | + refusal(message), | |
| 903 | + ) | |
| 904 | + .await | |
| 905 | + } | |
| 906 | + Err(iz_core::Error::NotFound) => { | |
| 907 | + let message = t(begun.lang, K::ErrOtherTask); | |
| 908 | + refuse( | |
| 909 | + cx, | |
| 910 | + &begun.me, | |
| 911 | + begun.lang, | |
| 912 | + &form.next, | |
| 913 | + &key, | |
| 914 | + refusal(message), | |
| 915 | + ) | |
| 916 | + .await | |
| 917 | + } | |
| 918 | + Err(error) => Err(core_err(error)), | |
| 919 | + } | |
| 920 | +} | |
| 921 | + | |
| 922 | +/// `POST /tasks/{id}/links/remove`: clears a dependency (a soft clear: the history stays). | |
| 923 | +#[route(POST "/tasks/{id}/links/remove")] | |
| 924 | +async fn remove_link(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 925 | + let state = app_context::<AppState>(cx); | |
| 926 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 927 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 928 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 929 | + Ok(begun) => begun, | |
| 930 | + Err(response) => return Ok(response), | |
| 931 | + }; | |
| 932 | + let key = begun.detail.task.key.clone(); | |
| 933 | + let other = form.other.trim().to_owned(); | |
| 934 | + let Some((blocked, blocking)) = link_pair(&task_id, &other, form.direction.trim()) else { | |
| 935 | + let message = t(begun.lang, K::ErrDirection); | |
| 936 | + return refuse( | |
| 937 | + cx, | |
| 938 | + &begun.me, | |
| 939 | + begun.lang, | |
| 940 | + &form.next, | |
| 941 | + &key, | |
| 942 | + refusal(message), | |
| 943 | + ) | |
| 944 | + .await; | |
| 945 | + }; | |
| 946 | + match state | |
| 947 | + .store | |
| 948 | + .clear_dependency(&begun.board_id, blocked, blocking, &begun.me.member.sub) | |
| 949 | + .await | |
| 950 | + { | |
| 951 | + Ok(()) | Err(iz_core::Error::NotFound) => { | |
| 952 | + bump(state, &begun.board_id, &task_id); | |
| 953 | + state.live.bump(&Topic::Task(other.clone())); | |
| 954 | + back(&form.next, Some(key.as_str())) | |
| 955 | + } | |
| 956 | + Err(error) => Err(core_err(error)), | |
| 957 | + } | |
| 958 | +} | |
| 959 | + | |
| 960 | +/// `POST /tasks/{id}/comments`: posts a comment on the task. | |
| 961 | +#[route(POST "/tasks/{id}/comments")] | |
| 962 | +async fn add_comment(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 963 | + let state = app_context::<AppState>(cx); | |
| 964 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 965 | + let task_id = path_param_segment(cx, "id").to_owned(); | |
| 966 | + let begun = match gate_task(cx, &form, &task_id).await? { | |
| 967 | + Ok(begun) => begun, | |
| 968 | + Err(response) => return Ok(response), | |
| 969 | + }; | |
| 970 | + let key = begun.detail.task.key.clone(); | |
| 971 | + let body = form.body.trim().to_owned(); | |
| 972 | + if body.is_empty() || body.chars().count() > COMMENT_MAX { | |
| 973 | + let draft = Draft { | |
| 974 | + comment: Some(form.body.clone()), | |
| 975 | + ..refusal(t(begun.lang, K::ErrComment)) | |
| 976 | + }; | |
| 977 | + return refuse(cx, &begun.me, begun.lang, &form.next, &key, draft).await; | |
| 978 | + } | |
| 979 | + match state | |
| 980 | + .store | |
| 981 | + .add_comment(&begun.board_id, &task_id, &begun.me.member.sub, &body) | |
| 982 | + .await | |
| 983 | + { | |
| 984 | + Ok(_) => { | |
| 985 | + bump(state, &begun.board_id, &task_id); | |
| 986 | + back(&form.next, Some(key.as_str())) | |
| 987 | + } | |
| 988 | + Err(error) => Err(core_err(error)), | |
| 989 | + } | |
| 990 | +} | |
| 991 | + | |
| 992 | +/// `POST /comments/{id}/edit`: edits a comment. Only its author may, and only while a member. The comment | |
| 993 | +/// is checked by its own id (live, on this board, its task live), then by `authz`. | |
| 994 | +#[route(POST "/comments/{id}/edit")] | |
| 995 | +async fn edit_comment(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 996 | + let state = app_context::<AppState>(cx); | |
| 997 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 998 | + let comment_id = path_param_segment(cx, "id").to_owned(); | |
| 999 | + let (me, language, board_id) = match gate(cx, &form.csrf, &form.next).await? { | |
| 1000 | + Ok(found) => found, | |
| 1001 | + Err(response) => return Ok(response), | |
| 1002 | + }; | |
| 1003 | + let key = task_of(&form.next); | |
| 1004 | + let body = form.body.trim().to_owned(); | |
| 1005 | + if body.is_empty() || body.chars().count() > COMMENT_MAX { | |
| 1006 | + let Some(key) = key else { | |
| 1007 | + return Err(not_found().into()); | |
| 1008 | + }; | |
| 1009 | + let draft = Draft { | |
| 1010 | + comment: Some(form.body.clone()), | |
| 1011 | + ..refusal(t(language, K::ErrComment)) | |
| 1012 | + }; | |
| 1013 | + return refuse(cx, &me, language, &form.next, &key, draft).await; | |
| 1014 | + } | |
| 1015 | + match state | |
| 1016 | + .store | |
| 1017 | + .edit_comment(&board_id, &comment_id, &me.actor(), &body) | |
| 1018 | + .await | |
| 1019 | + { | |
| 1020 | + Ok(comment) => { | |
| 1021 | + bump(state, &board_id, &comment.task_id); | |
| 1022 | + back(&form.next, key.as_deref()) | |
| 1023 | + } | |
| 1024 | + Err(error) => Err(core_err(error)), | |
| 1025 | + } | |
| 1026 | +} | |
| 1027 | + | |
| 1028 | +/// `POST /comments/{id}/delete`: deletes a comment. Its author (while a member) or an admin may. | |
| 1029 | +#[route(POST "/comments/{id}/delete")] | |
| 1030 | +async fn delete_comment(cx: &Cx, form: Option<Form<ModalForm>>) -> Result<Response> { | |
| 1031 | + let state = app_context::<AppState>(cx); | |
| 1032 | + let form = form.map(|Form(form)| form).unwrap_or_default(); | |
| 1033 | + let comment_id = path_param_segment(cx, "id").to_owned(); | |
| 1034 | + let (me, _language, board_id) = match gate(cx, &form.csrf, &form.next).await? { | |
| 1035 | + Ok(found) => found, | |
| 1036 | + Err(response) => return Ok(response), | |
| 1037 | + }; | |
| 1038 | + let key = task_of(&form.next); | |
| 1039 | + match state | |
| 1040 | + .store | |
| 1041 | + .delete_comment(&board_id, &comment_id, &me.actor()) | |
| 1042 | + .await | |
| 1043 | + { | |
| 1044 | + Ok(task_id) => { | |
| 1045 | + bump(state, &board_id, &task_id); | |
| 1046 | + back(&form.next, key.as_deref()) | |
| 1047 | + } | |
| 1048 | + Err(error) => Err(core_err(error)), | |
| 1049 | + } | |
| 1050 | +} | |
| 1051 | + | |
| 1052 | +#[cfg(test)] | |
| 1053 | +mod tests { | |
| 1054 | + use super::*; | |
| 1055 | + | |
| 1056 | + #[test] | |
| 1057 | + fn modal_url_keeps_filters_and_drops_the_rest() { | |
| 1058 | + assert_eq!( | |
| 1059 | + modal_url(Some("tag=a b&confirm=delete&sort=title&q=x"), "IZ-4", &[]), | |
| 1060 | + "/?tag=a%20b&sort=title&q=x&task=IZ-4" | |
| 1061 | + ); | |
| 1062 | + assert_eq!( | |
| 1063 | + modal_url(None, "IZ-4", &[("before", "2026~01")]), | |
| 1064 | + "/?task=IZ-4&before=2026~01" | |
| 1065 | + ); | |
| 1066 | + } | |
| 1067 | + | |
| 1068 | + #[test] | |
| 1069 | + fn clock_text_is_hours_and_minutes() { | |
| 1070 | + assert_eq!(parse_clock("09:30"), Some((9, 30))); | |
| 1071 | + assert_eq!(parse_clock("9:30"), Some((9, 30))); | |
| 1072 | + assert_eq!(parse_clock("24:00"), None); | |
| 1073 | + assert_eq!(parse_clock("09:60"), None); | |
| 1074 | + assert_eq!(parse_clock("0930"), None); | |
| 1075 | + } | |
| 1076 | + | |
| 1077 | + #[test] | |
| 1078 | + fn a_dependency_names_its_blocked_and_blocking_side() { | |
| 1079 | + assert_eq!(link_pair("a", "b", "blocked_by"), Some(("a", "b"))); | |
| 1080 | + assert_eq!(link_pair("a", "b", "blocks"), Some(("b", "a"))); | |
| 1081 | + assert_eq!(link_pair("a", "b", "other"), None); | |
| 1082 | + } | |
| 1083 | + | |
| 1084 | + #[test] | |
| 1085 | + fn a_return_path_names_its_task_only_when_local() { | |
| 1086 | + assert_eq!(task_of("/?task=IZ-4&tag=x").as_deref(), Some("IZ-4")); | |
| 1087 | + assert_eq!(task_of("//evil.example/?task=IZ-4"), None); | |
| 1088 | + } | |
| 1089 | +} | |
| 1090 | + | |
| 1091 | +#[cfg(test)] | |
| 1092 | +mod render_tests { | |
| 1093 | + use http::header::{CONTENT_TYPE, COOKIE}; | |
| 1094 | + use iz_core::authz::Role; | |
| 1095 | + use iz_core::store::tasks::{NewTask, TaskEdit}; | |
| 1096 | + use topcoat::router::{Body, to_bytes}; | |
| 1097 | + | |
| 1098 | + use super::*; | |
| 1099 | + use crate::boot::{router, test_state}; | |
| 1100 | + use crate::pages::board::{cookie_of, one_card, sign_in_as}; | |
| 1101 | + use crate::state::AppState; | |
| 1102 | + | |
| 1103 | + const AUTHOR: &str = "01ADAAAAAAAAAAAAAAAAAAAAAA"; | |
| 1104 | + const OTHER: &str = "01BOAAAAAAAAAAAAAAAAAAAAAA"; | |
| 1105 | + const VIEWER: &str = "01VIAAAAAAAAAAAAAAAAAAAAAA"; | |
| 1106 | + | |
| 1107 | + /// Sends one request and returns its status and body as text. | |
| 1108 | + async fn send(state: &AppState, request: http::Request<Body>) -> (u16, String) { | |
| 1109 | + let response = router(state.clone()).handle(request).await; | |
| 1110 | + let status = response.status().as_u16(); | |
| 1111 | + let bytes = to_bytes(response.into_body(), 1024 * 1024) | |
| 1112 | + .await | |
| 1113 | + .expect("body"); | |
| 1114 | + (status, String::from_utf8_lossy(&bytes).into_owned()) | |
| 1115 | + } | |
| 1116 | + | |
| 1117 | + /// A form POST with the session's cookie. | |
| 1118 | + fn post(path: &str, token: &str, body: String) -> http::Request<Body> { | |
| 1119 | + http::Request::post(path) | |
| 1120 | + .header(CONTENT_TYPE, "application/x-www-form-urlencoded") | |
| 1121 | + .header(COOKIE, cookie_of(token)) | |
| 1122 | + .body(Body::from(body)) | |
| 1123 | + .expect("request") | |
| 1124 | + } | |
| 1125 | + | |
| 1126 | + /// A GET with the session's cookie. | |
| 1127 | + fn get(path: &str, token: &str) -> http::Request<Body> { | |
| 1128 | + http::Request::get(path) | |
| 1129 | + .header(COOKIE, cookie_of(token)) | |
| 1130 | + .body(Body::empty()) | |
| 1131 | + .expect("request") | |
| 1132 | + } | |
| 1133 | + | |
| 1134 | + /// The key of a task, read through the store. | |
| 1135 | + async fn key_of(state: &AppState, task_id: &str) -> String { | |
| 1136 | + let board = state.store.board().await.expect("board").expect("some"); | |
| 1137 | + state | |
| 1138 | + .store | |
| 1139 | + .task_detail(&board.id, task_id) | |
| 1140 | + .await | |
| 1141 | + .expect("detail") | |
| 1142 | + .task | |
| 1143 | + .key | |
| 1144 | + } | |
| 1145 | + | |
| 1146 | + /// The modal URL of a task, as a form carries it. | |
| 1147 | + fn next_of(key: &str) -> String { | |
| 1148 | + percent_encode(&modal_url(None, key, &[])) | |
| 1149 | + } | |
| 1150 | + | |
| 1151 | + /// A viewer's comment is refused with `403`, and nothing is stored. | |
| 1152 | + #[tokio::test] | |
| 1153 | + async fn a_viewer_cannot_comment() { | |
| 1154 | + let (_dir, state) = test_state().await; | |
| 1155 | + sign_in_as(&state, AUTHOR, Role::Member).await; | |
| 1156 | + let (task_id, _) = one_card(&state, "Milk", AUTHOR).await; | |
| 1157 | + let (token, csrf) = sign_in_as(&state, VIEWER, Role::Viewer).await; | |
| 1158 | + let key = key_of(&state, &task_id).await; | |
| 1159 | + let body = format!("csrf={csrf}&next={}&body=hello", next_of(&key)); | |
| 1160 | + let (status, _) = send( | |
| 1161 | + &state, | |
| 1162 | + post(&format!("/tasks/{task_id}/comments"), &token, body), | |
| 1163 | + ) | |
| 1164 | + .await; | |
| 1165 | + assert_eq!(status, 403); | |
| 1166 | + let board = state.store.board().await.expect("board").expect("some"); | |
| 1167 | + let comments = state | |
| 1168 | + .store | |
| 1169 | + .list_comments(&board.id, &task_id) | |
| 1170 | + .await | |
| 1171 | + .expect("comments"); | |
| 1172 | + assert!(comments.is_empty()); | |
| 1173 | + } | |
| 1174 | + | |
| 1175 | + /// Another member cannot edit someone else's comment: `403`, and the body stays as it was. | |
| 1176 | + #[tokio::test] | |
| 1177 | + async fn another_member_cannot_edit_a_comment() { | |
| 1178 | + let (_dir, state) = test_state().await; | |
| 1179 | + sign_in_as(&state, AUTHOR, Role::Member).await; | |
| 1180 | + sign_in_as(&state, OTHER, Role::Member).await; | |
| 1181 | + let (task_id, _) = one_card(&state, "Milk", AUTHOR).await; | |
| 1182 | + let board = state.store.board().await.expect("board").expect("some"); | |
| 1183 | + let comment = state | |
| 1184 | + .store | |
| 1185 | + .add_comment(&board.id, &task_id, AUTHOR, "mine") | |
| 1186 | + .await | |
| 1187 | + .expect("comment"); | |
| 1188 | + let (token, csrf) = sign_in_as(&state, OTHER, Role::Member).await; | |
| 1189 | + let key = key_of(&state, &task_id).await; | |
| 1190 | + let body = format!("csrf={csrf}&next={}&body=changed", next_of(&key)); | |
| 1191 | + let (status, _) = send( | |
| 1192 | + &state, | |
| 1193 | + post(&format!("/comments/{}/edit", comment.id), &token, body), | |
| 1194 | + ) | |
| 1195 | + .await; | |
| 1196 | + assert_eq!(status, 403); | |
| 1197 | + let comments = state | |
| 1198 | + .store | |
| 1199 | + .list_comments(&board.id, &task_id) | |
| 1200 | + .await | |
| 1201 | + .expect("comments"); | |
| 1202 | + assert_eq!(comments[0].body, "mine"); | |
| 1203 | + } | |
| 1204 | + | |
| 1205 | + /// A comment of a deleted task is not found, for edit and for delete. | |
| 1206 | + #[tokio::test] | |
| 1207 | + async fn a_comment_of_a_deleted_task_is_not_found() { | |
| 1208 | + let (_dir, state) = test_state().await; | |
| 1209 | + sign_in_as(&state, AUTHOR, Role::Member).await; | |
| 1210 | + let (task_id, _) = one_card(&state, "Milk", AUTHOR).await; | |
| 1211 | + let board = state.store.board().await.expect("board").expect("some"); | |
| 1212 | + let comment = state | |
| 1213 | + .store | |
| 1214 | + .add_comment(&board.id, &task_id, AUTHOR, "old") | |
| 1215 | + .await | |
| 1216 | + .expect("comment"); | |
| 1217 | + state | |
| 1218 | + .store | |
| 1219 | + .delete_task(&board.id, &task_id, AUTHOR) | |
| 1220 | + .await | |
| 1221 | + .expect("delete"); | |
| 1222 | + let (token, csrf) = sign_in_as(&state, AUTHOR, Role::Member).await; | |
| 1223 | + let body = format!("csrf={csrf}&next=%2F&body=again"); | |
| 1224 | + let (status, _) = send( | |
| 1225 | + &state, | |
| 1226 | + post(&format!("/comments/{}/edit", comment.id), &token, body), | |
| 1227 | + ) | |
| 1228 | + .await; | |
| 1229 | + assert_eq!(status, 404); | |
| 1230 | + let body = format!("csrf={csrf}&next=%2F"); | |
| 1231 | + let (status, _) = send( | |
| 1232 | + &state, | |
| 1233 | + post(&format!("/comments/{}/delete", comment.id), &token, body), | |
| 1234 | + ) | |
| 1235 | + .await; | |
| 1236 | + assert_eq!(status, 404); | |
| 1237 | + } | |
| 1238 | + | |
| 1239 | + /// A description with markup and a `javascript:` address reaches the page as text. Only the https | |
| 1240 | + /// address becomes a link. | |
| 1241 | + #[tokio::test] | |
| 1242 | + async fn a_description_is_plain_text_with_safe_links() { | |
| 1243 | + let (_dir, state) = test_state().await; | |
| 1244 | + let (token, _) = sign_in_as(&state, AUTHOR, Role::Member).await; | |
| 1245 | + let (task_id, _) = one_card(&state, "Milk", AUTHOR).await; | |
| 1246 | + let board = state.store.board().await.expect("board").expect("some"); | |
| 1247 | + let tags = state.store.tags(&board.id).await.expect("tags"); | |
| 1248 | + let description = "<img src=x onerror=alert(1)>\njavascript:alert(1) \ | |
| 1249 | + https://ok.example/a?b=1. <b>bold</b>"; | |
| 1250 | + state | |
| 1251 | + .store | |
| 1252 | + .edit_task( | |
| 1253 | + &board.id, | |
| 1254 | + &task_id, | |
| 1255 | + TaskEdit { | |
| 1256 | + title: "Milk".into(), | |
| 1257 | + description: description.into(), | |
| 1258 | + tag_id: tags[0].id.clone(), | |
| 1259 | + deadline: None, | |
| 1260 | + meeting_at: None, | |
| 1261 | + }, | |
| 1262 | + AUTHOR, | |
| 1263 | + ) | |
| 1264 | + .await | |
| 1265 | + .expect("edit"); | |
| 1266 | + let key = key_of(&state, &task_id).await; | |
| 1267 | + let (status, html) = send(&state, get(&format!("/?task={key}"), &token)).await; | |
| 1268 | + assert_eq!(status, 200); | |
| 1269 | + assert!( | |
| 1270 | + html.contains("<img src=x onerror=alert(1)>"), | |
| 1271 | + "not escaped" | |
| 1272 | + ); | |
| 1273 | + assert!(!html.contains("<img src=x"), "markup reached the page"); | |
| 1274 | + assert!(!html.contains("<b>bold</b>"), "markup reached the page"); | |
| 1275 | + assert!(!html.contains("href=\"javascript"), "javascript link"); | |
| 1276 | + assert!( | |
| 1277 | + html.contains("href=\"https://ok.example/a?b=1\""), | |
| 1278 | + "https address not linked" | |
| 1279 | + ); | |
| 1280 | + } | |
| 1281 | + | |
| 1282 | + /// A dependency that closes a cycle is refused with `422` and its translated message. | |
| 1283 | + #[tokio::test] | |
| 1284 | + async fn a_dependency_cycle_is_refused_with_a_message() { | |
| 1285 | + let (_dir, state) = test_state().await; | |
| 1286 | + let (token, csrf) = sign_in_as(&state, AUTHOR, Role::Member).await; | |
| 1287 | + let (first, column) = one_card(&state, "First", AUTHOR).await; | |
| 1288 | + let board = state.store.board().await.expect("board").expect("some"); | |
| 1289 | + let tags = state.store.tags(&board.id).await.expect("tags"); | |
| 1290 | + let second = state | |
| 1291 | + .store | |
| 1292 | + .create_task( | |
| 1293 | + &board.id, | |
| 1294 | + NewTask { | |
| 1295 | + title: "Second".into(), | |
| 1296 | + description: String::new(), | |
| 1297 | + column_id: column, | |
| 1298 | + tag_id: tags[0].id.clone(), | |
| 1299 | + deadline: None, | |
| 1300 | + meeting_at: None, | |
| 1301 | + assignees: Vec::new(), | |
| 1302 | + parent_id: None, | |
| 1303 | + link: None, | |
| 1304 | + }, | |
| 1305 | + AUTHOR, | |
| 1306 | + ) | |
| 1307 | + .await | |
| 1308 | + .expect("second task") | |
| 1309 | + .id; | |
| 1310 | + state | |
| 1311 | + .store | |
| 1312 | + .add_dependency(&board.id, &first, &second, AUTHOR) | |
| 1313 | + .await | |
| 1314 | + .expect("first link"); | |
| 1315 | + let key = key_of(&state, &second).await; | |
| 1316 | + let body = format!( | |
| 1317 | + "csrf={csrf}&next={}&other={first}&direction=blocked_by", | |
| 1318 | + next_of(&key) | |
| 1319 | + ); | |
| 1320 | + let (status, html) = send( | |
| 1321 | + &state, | |
| 1322 | + post(&format!("/tasks/{second}/links"), &token, body), | |
| 1323 | + ) | |
| 1324 | + .await; | |
| 1325 | + assert_eq!(status, 422); | |
| 1326 | + assert!( | |
| 1327 | + html.contains(t(Lang::En, K::ErrCycle)), | |
| 1328 | + "cycle message missing: {html}" | |
| 1329 | + ); | |
| 1330 | + } | |
| 1331 | + | |
| 1332 | + /// An unknown task key answers the board with its notice and `404`. | |
| 1333 | + #[tokio::test] | |
| 1334 | + async fn an_unknown_task_key_is_not_found() { | |
| 1335 | + let (_dir, state) = test_state().await; | |
| 1336 | + let (token, _) = sign_in_as(&state, AUTHOR, Role::Member).await; | |
| 1337 | + state.store.ensure_board("IZ").await.expect("board"); | |
| 1338 | + let (status, html) = send(&state, get("/?task=IZ-999", &token)).await; | |
| 1339 | + assert_eq!(status, 404); | |
| 1340 | + assert!(html.contains(crate::i18n::board::t( | |
| 1341 | + Lang::En, | |
| 1342 | + crate::i18n::board::K::TaskNotFound | |
| 1343 | + ))); | |
| 1344 | + } | |
| 1345 | +} |
crates/iz-web/src/pages/tasks.rsmodified+4 -4
| @@ -40,7 +40,7 @@ use crate::pages::board::{NewForm, load, query_of, render, the_board}; | ||
| 40 | 40 | use crate::state::AppState; |
| 41 | 41 | |
| 42 | 42 | /// A refused write: the status, the code a client reads, and the message a person reads. |
| 43 | -struct Refused { | |
| 43 | +pub(crate) struct Refused { | |
| 44 | 44 | status: StatusCode, |
| 45 | 45 | code: &'static str, |
| 46 | 46 | message: K, |
| @@ -56,7 +56,7 @@ fn refused(status: u16, code: &'static str, message: K) -> Refused { | ||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /// Why the gate of a write stopped it before any change. |
| 59 | -enum Stop { | |
| 59 | +pub(crate) enum Stop { | |
| 60 | 60 | /// No session: the browser goes to sign-in, a `fetch` gets `401`. |
| 61 | 61 | Anonymous, |
| 62 | 62 | /// The member may not write, or the token is wrong (`403`), or the member has no access (`404`). |
| @@ -156,7 +156,7 @@ fn parse_position(text: &str) -> StdResult<Option<usize>, ()> { | ||
| 156 | 156 | |
| 157 | 157 | /// The gate of every write: the member with the write level, and the CSRF token. The level is checked |
| 158 | 158 | /// first, so a viewer gets `403` whatever token they send. |
| 159 | -async fn writer(cx: &Cx, csrf: &str) -> StdResult<CurrentMember, Stop> { | |
| 159 | +pub(crate) async fn writer(cx: &Cx, csrf: &str) -> StdResult<CurrentMember, Stop> { | |
| 160 | 160 | match require_csrf(cx, Need::Member, csrf).await { |
| 161 | 161 | Ok(me) => Ok(me), |
| 162 | 162 | Err(error) if error.downcast_ref::<ForbiddenError>().is_some() => { |
| @@ -172,7 +172,7 @@ async fn writer(cx: &Cx, csrf: &str) -> StdResult<CurrentMember, Stop> { | ||
| 172 | 172 | |
| 173 | 173 | /// Answers a gate stop: sign-in for the anonymous, the refusal for the rest. Gate refusals are always |
| 174 | 174 | /// `403` or `404`, so they never need the board page. |
| 175 | -async fn answer_stop( | |
| 175 | +pub(crate) async fn answer_stop( | |
| 176 | 176 | cx: &Cx, |
| 177 | 177 | stop: Stop, |
| 178 | 178 | json: bool, |
crates/iz-web/src/views/board.rsmodified+5 -1
| @@ -15,6 +15,7 @@ use topcoat::view::{View, component, view}; | ||
| 15 | 15 | use crate::i18n::Lang; |
| 16 | 16 | use crate::i18n::board::{K, column_title, subtasks, t}; |
| 17 | 17 | use crate::pages::board::{BoardPage, Filters, NewForm, board_url}; |
| 18 | +use crate::views::task::task_modal; | |
| 18 | 19 | use crate::views::{alert, notice}; |
| 19 | 20 | |
| 20 | 21 | /// Number of palette tones a project chip can take. |
| @@ -36,7 +37,7 @@ pub fn tone(tags: &[Tag], tag_id: &str) -> usize { | ||
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | /// The value of an attribute that is present only when `on`. |
| 39 | -fn flag(on: bool) -> Option<&'static str> { | |
| 40 | +pub(crate) fn flag(on: bool) -> Option<&'static str> { | |
| 40 | 41 | on.then_some("") |
| 41 | 42 | } |
| 42 | 43 | |
| @@ -100,6 +101,9 @@ pub async fn board_content(page: &BoardPage) -> Result<impl View> { | ||
| 100 | 101 | } |
| 101 | 102 | </div> |
| 102 | 103 | </section> |
| 104 | + if let Some(modal) = page.modal.as_ref() { | |
| 105 | + task_modal(page: page, modal: modal) | |
| 106 | + } | |
| 103 | 107 | }) |
| 104 | 108 | } |
| 105 | 109 |
crates/iz-web/src/views/mod.rsmodified+1 -0
| @@ -9,6 +9,7 @@ use topcoat::router::response::{IntoResponse, Response}; | ||
| 9 | 9 | use topcoat::view::{Child, View, ViewExt, component, view}; |
| 10 | 10 | |
| 11 | 11 | pub mod board; |
| 12 | +pub mod task; | |
| 12 | 13 | |
| 13 | 14 | use crate::assets::{MAIN_CSS_HREF, NAV_JS_HREF, PAGES_JS_HREF}; |
| 14 | 15 | use crate::i18n::Lang; |
crates/iz-web/src/views/task.rsadded+627 -0
| @@ -0,0 +1,627 @@ | ||
| 1 | +//! The task modal's markup: the `<dialog>` over the board, its sections, and the plain-text renderer for | |
| 2 | +//! descriptions and comments. | |
| 3 | +//! | |
| 4 | +//! Text from users is never markup. [`segments`] splits a text into lines, text runs and links; only | |
| 5 | +//! addresses that start with `http://` or `https://` become links, with `rel="noopener noreferrer | |
| 6 | +//! nofollow"`. Everything else is escaped by `view!`, so `<img onerror=...>` and `javascript:` addresses | |
| 7 | +//! reach the page as plain characters. | |
| 8 | +//! | |
| 9 | +//! Forms carry the CSRF token and the modal's own URL as `next`. A viewer gets the same sections with no | |
| 10 | +//! form, so the read-only view and the write view differ only in controls. | |
| 11 | + | |
| 12 | +use topcoat::Result; | |
| 13 | +use topcoat::view::{View, component, view}; | |
| 14 | + | |
| 15 | +use crate::i18n::task::{K, t}; | |
| 16 | +use crate::pages::board::BoardPage; | |
| 17 | +use crate::pages::task::{TaskModal, task_link}; | |
| 18 | +use crate::views::alert; | |
| 19 | +use crate::views::board::flag; | |
| 20 | + | |
| 21 | +/// One piece of a plain-text body: a run of text, a link, or a line break. | |
| 22 | +pub struct Segment { | |
| 23 | + /// The text of the run, or the address of the link. Empty for a line break. | |
| 24 | + pub text: String, | |
| 25 | + /// Whether this piece is an address that becomes a link. | |
| 26 | + pub link: bool, | |
| 27 | + /// Whether this piece is a line break. | |
| 28 | + pub brk: bool, | |
| 29 | +} | |
| 30 | + | |
| 31 | +/// The text run `text` as a segment. | |
| 32 | +fn run(text: &str) -> Segment { | |
| 33 | + Segment { | |
| 34 | + text: text.to_owned(), | |
| 35 | + link: false, | |
| 36 | + brk: false, | |
| 37 | + } | |
| 38 | +} | |
| 39 | + | |
| 40 | +/// The first `http://` or `https://` address in `text` that is longer than its scheme, as its byte range. | |
| 41 | +/// Trailing sentence punctuation and brackets are not part of the address; whitespace and `<>"'` end it. | |
| 42 | +fn next_link(text: &str) -> Option<(usize, usize)> { | |
| 43 | + let lower = text.to_ascii_lowercase(); | |
| 44 | + let mut from = 0; | |
| 45 | + loop { | |
| 46 | + let (offset, scheme) = ["http://", "https://"] | |
| 47 | + .iter() | |
| 48 | + .filter_map(|scheme| lower[from..].find(scheme).map(|at| (at, *scheme))) | |
| 49 | + .min_by_key(|(at, _)| *at)?; | |
| 50 | + let start = from + offset; | |
| 51 | + let tail = &text[start..]; | |
| 52 | + let length = tail | |
| 53 | + .find(|c: char| c.is_whitespace() || matches!(c, '<' | '>' | '"' | '\'' | '`')) | |
| 54 | + .unwrap_or(tail.len()); | |
| 55 | + let mut end = start + length; | |
| 56 | + while end > start | |
| 57 | + && text[..end] | |
| 58 | + .chars() | |
| 59 | + .last() | |
| 60 | + .is_some_and(|c| matches!(c, '.' | ',' | ';' | ':' | '!' | '?' | ')' | ']' | '}')) | |
| 61 | + { | |
| 62 | + end -= 1; | |
| 63 | + } | |
| 64 | + if end - start > scheme.len() { | |
| 65 | + return Some((start, end)); | |
| 66 | + } | |
| 67 | + from = start + scheme.len(); | |
| 68 | + } | |
| 69 | +} | |
| 70 | + | |
| 71 | +/// Splits a plain-text body into segments: each line, its runs of text and its links, with a line break | |
| 72 | +/// between lines. A carriage return before a line feed is dropped. | |
| 73 | +pub fn segments(text: &str) -> Vec<Segment> { | |
| 74 | + let mut out = Vec::new(); | |
| 75 | + for (index, line) in text.split('\n').enumerate() { | |
| 76 | + if index > 0 { | |
| 77 | + out.push(Segment { | |
| 78 | + text: String::new(), | |
| 79 | + link: false, | |
| 80 | + brk: true, | |
| 81 | + }); | |
| 82 | + } | |
| 83 | + let mut rest = line.strip_suffix('\r').unwrap_or(line); | |
| 84 | + while let Some((start, end)) = next_link(rest) { | |
| 85 | + if start > 0 { | |
| 86 | + out.push(run(&rest[..start])); | |
| 87 | + } | |
| 88 | + out.push(Segment { | |
| 89 | + text: rest[start..end].to_owned(), | |
| 90 | + link: true, | |
| 91 | + brk: false, | |
| 92 | + }); | |
| 93 | + rest = &rest[end..]; | |
| 94 | + } | |
| 95 | + if !rest.is_empty() { | |
| 96 | + out.push(run(rest)); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + out | |
| 100 | +} | |
| 101 | + | |
| 102 | +/// A plain-text body as markup: escaped text, line breaks, and links for http and https addresses only. | |
| 103 | +#[component] | |
| 104 | +pub async fn rich_text(text: &str) -> Result<impl View> { | |
| 105 | + let pieces = segments(text); | |
| 106 | + Ok(view! { | |
| 107 | + <div class="rich-text"> | |
| 108 | + for piece in pieces.iter() { | |
| 109 | + if piece.brk { | |
| 110 | + <br> | |
| 111 | + } | |
| 112 | + if piece.link { | |
| 113 | + <a href=(piece.text.as_str()) rel="noopener noreferrer nofollow" target="_blank">(piece.text.as_str())</a> | |
| 114 | + } | |
| 115 | + if !piece.link && !piece.brk { | |
| 116 | + (piece.text.as_str()) | |
| 117 | + } | |
| 118 | + } | |
| 119 | + </div> | |
| 120 | + }) | |
| 121 | +} | |
| 122 | + | |
| 123 | +/// The modal: the `<dialog>` over the board. Escape and the close link return to the board with its | |
| 124 | +/// filters (`board.js` reads `data-close-href`). Without JavaScript the dialog is shown in place. | |
| 125 | +#[component] | |
| 126 | +pub async fn task_modal(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 127 | + let lang = page.lang; | |
| 128 | + let task = &modal.detail.task; | |
| 129 | + let key = task.key.as_str(); | |
| 130 | + let close = modal.close.as_str(); | |
| 131 | + Ok(view! { | |
| 132 | + <dialog class="task-dialog" open="" aria-labelledby="task-heading" data-close-href=(close)> | |
| 133 | + <header class="task-head"> | |
| 134 | + <p class="task-key">(key)</p> | |
| 135 | + <a class="button ghost" href=(close)>(t(lang, K::Close))</a> | |
| 136 | + </header> | |
| 137 | + if let Some(message) = modal.error { | |
| 138 | + alert(message: message) | |
| 139 | + } | |
| 140 | + <h2 id="task-heading" class="task-title">(task.title.as_str())</h2> | |
| 141 | + task_details(page: page, modal: modal) | |
| 142 | + task_people(page: page, modal: modal) | |
| 143 | + task_structure(page: page, modal: modal) | |
| 144 | + task_links(page: page, modal: modal) | |
| 145 | + task_comments(page: page, modal: modal) | |
| 146 | + task_activity(page: page, modal: modal) | |
| 147 | + task_delete(page: page, modal: modal) | |
| 148 | + </dialog> | |
| 149 | + }) | |
| 150 | +} | |
| 151 | + | |
| 152 | +/// The fields as read, and for a member the edit form folded under them. The form opens by itself after a | |
| 153 | +/// refusal, so the typed values stay in view. | |
| 154 | +#[component] | |
| 155 | +pub async fn task_details(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 156 | + let lang = page.lang; | |
| 157 | + let task = &modal.detail.task; | |
| 158 | + let deadline = task.deadline.map(|day| day.to_string()).unwrap_or_default(); | |
| 159 | + let deadline = if deadline.is_empty() { | |
| 160 | + "-".to_owned() | |
| 161 | + } else { | |
| 162 | + deadline | |
| 163 | + }; | |
| 164 | + let time = if modal.edit.time.is_empty() { | |
| 165 | + "-".to_owned() | |
| 166 | + } else { | |
| 167 | + modal.edit.time.clone() | |
| 168 | + }; | |
| 169 | + let project = modal.detail.tag.name.as_str(); | |
| 170 | + let id = task.id.as_str(); | |
| 171 | + let edit_action = format!("/tasks/{id}/edit"); | |
| 172 | + let csrf = page.viewer.csrf.as_str(); | |
| 173 | + let next = modal.base.as_str(); | |
| 174 | + let edit = &modal.edit; | |
| 175 | + Ok(view! { | |
| 176 | + <section class="task-section" aria-label=(t(lang, K::Description))> | |
| 177 | + <dl class="task-facts"> | |
| 178 | + <dt>(t(lang, K::Project))</dt> | |
| 179 | + <dd>(project)</dd> | |
| 180 | + <dt>(t(lang, K::Deadline))</dt> | |
| 181 | + <dd>(deadline.as_str())</dd> | |
| 182 | + <dt>(t(lang, K::Meeting))</dt> | |
| 183 | + <dd>(time.as_str())</dd> | |
| 184 | + </dl> | |
| 185 | + rich_text(text: task.description.as_str()) | |
| 186 | + if modal.can_write { | |
| 187 | + <details class="task-edit" open=(flag(modal.error.is_some()))> | |
| 188 | + <summary>(t(lang, K::EditComment))</summary> | |
| 189 | + <form class="task-form" method="post" action=(edit_action.as_str())> | |
| 190 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 191 | + <input type="hidden" name="next" value=(next)> | |
| 192 | + <div class="new-task-grid"> | |
| 193 | + <div class="field field-wide"> | |
| 194 | + <label for="tm-title">(t(lang, K::Title))</label> | |
| 195 | + <input id="tm-title" name="title" maxlength="200" required="" value=(edit.title.as_str())> | |
| 196 | + </div> | |
| 197 | + <div class="field"> | |
| 198 | + <label for="tm-tag">(t(lang, K::Project))</label> | |
| 199 | + <select id="tm-tag" name="tag"> | |
| 200 | + for tag in page.tags.iter() { | |
| 201 | + <option value=(tag.id.as_str()) selected=(flag(edit.tag == tag.id))>(tag.name.as_str())</option> | |
| 202 | + } | |
| 203 | + </select> | |
| 204 | + </div> | |
| 205 | + <div class="field"> | |
| 206 | + <label for="tm-deadline">(t(lang, K::Deadline))</label> | |
| 207 | + <input id="tm-deadline" type="date" name="deadline" value=(edit.deadline.as_str())> | |
| 208 | + </div> | |
| 209 | + <div class="field"> | |
| 210 | + <label for="tm-time">(t(lang, K::Meeting))</label> | |
| 211 | + <input id="tm-time" type="time" name="time" value=(edit.time.as_str())> | |
| 212 | + <p class="field-hint">(t(lang, K::MeetingHint))</p> | |
| 213 | + </div> | |
| 214 | + <div class="field field-wide"> | |
| 215 | + <label for="tm-description">(t(lang, K::Description))</label> | |
| 216 | + <textarea id="tm-description" name="description" maxlength="20000">(edit.description.as_str())</textarea> | |
| 217 | + <p class="field-hint">(t(lang, K::DescriptionHint))</p> | |
| 218 | + </div> | |
| 219 | + </div> | |
| 220 | + <button class="button primary" type="submit">(t(lang, K::Save))</button> | |
| 221 | + </form> | |
| 222 | + </details> | |
| 223 | + } | |
| 224 | + </section> | |
| 225 | + }) | |
| 226 | +} | |
| 227 | + | |
| 228 | +/// The assignees, with a remove control each, the picker for a new one, and the watch switch. | |
| 229 | +#[component] | |
| 230 | +pub async fn task_people(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 231 | + let lang = page.lang; | |
| 232 | + let id = modal.detail.task.id.as_str(); | |
| 233 | + let csrf = page.viewer.csrf.as_str(); | |
| 234 | + let next = modal.base.as_str(); | |
| 235 | + let assign_action = format!("/tasks/{id}/assign"); | |
| 236 | + let unassign_action = format!("/tasks/{id}/unassign"); | |
| 237 | + let watch_action = format!("/tasks/{id}/watch"); | |
| 238 | + let watch_on = if modal.watching { "0" } else { "1" }; | |
| 239 | + let watch_label = if modal.watching { | |
| 240 | + t(lang, K::Unwatch) | |
| 241 | + } else { | |
| 242 | + t(lang, K::Watch) | |
| 243 | + }; | |
| 244 | + let watch_text = if modal.watching { | |
| 245 | + t(lang, K::Watching) | |
| 246 | + } else { | |
| 247 | + t(lang, K::NotWatching) | |
| 248 | + }; | |
| 249 | + let assignees: Vec<(String, String)> = modal | |
| 250 | + .detail | |
| 251 | + .assignees | |
| 252 | + .iter() | |
| 253 | + .map(|a| (a.sub.clone(), a.name.clone())) | |
| 254 | + .collect(); | |
| 255 | + let picks: Vec<(String, String)> = modal | |
| 256 | + .assignable | |
| 257 | + .iter() | |
| 258 | + .map(|member| (member.sub.clone(), member.name.clone())) | |
| 259 | + .collect(); | |
| 260 | + Ok(view! { | |
| 261 | + <section class="task-section" aria-labelledby="task-people"> | |
| 262 | + <h3 id="task-people">(t(lang, K::Assignees))</h3> | |
| 263 | + if assignees.is_empty() { | |
| 264 | + <p class="muted">(t(lang, K::NobodyAssigned))</p> | |
| 265 | + } | |
| 266 | + <ul class="task-list"> | |
| 267 | + for (sub, name) in assignees.iter() { | |
| 268 | + <li class="task-row"> | |
| 269 | + <span>(name.as_str())</span> | |
| 270 | + if modal.can_write { | |
| 271 | + <form method="post" action=(unassign_action.as_str())> | |
| 272 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 273 | + <input type="hidden" name="next" value=(next)> | |
| 274 | + <input type="hidden" name="sub" value=(sub.as_str())> | |
| 275 | + <button class="button ghost" type="submit">(t(lang, K::Remove))</button> | |
| 276 | + </form> | |
| 277 | + } | |
| 278 | + </li> | |
| 279 | + } | |
| 280 | + </ul> | |
| 281 | + if modal.can_write && !picks.is_empty() { | |
| 282 | + <form class="task-inline" method="post" action=(assign_action.as_str())> | |
| 283 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 284 | + <input type="hidden" name="next" value=(next)> | |
| 285 | + <div class="field"> | |
| 286 | + <label for="assign-sub">(t(lang, K::AssignPick))</label> | |
| 287 | + <select id="assign-sub" name="sub"> | |
| 288 | + for (sub, name) in picks.iter() { | |
| 289 | + <option value=(sub.as_str())>(name.as_str())</option> | |
| 290 | + } | |
| 291 | + </select> | |
| 292 | + </div> | |
| 293 | + <button class="button" type="submit">(t(lang, K::Assign))</button> | |
| 294 | + </form> | |
| 295 | + } | |
| 296 | + <p class="muted">(watch_text)</p> | |
| 297 | + if modal.can_write { | |
| 298 | + <form class="task-inline" method="post" action=(watch_action.as_str())> | |
| 299 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 300 | + <input type="hidden" name="next" value=(next)> | |
| 301 | + <input type="hidden" name="on" value=(watch_on)> | |
| 302 | + <button class="button ghost" type="submit">(watch_label)</button> | |
| 303 | + </form> | |
| 304 | + } | |
| 305 | + </section> | |
| 306 | + }) | |
| 307 | +} | |
| 308 | + | |
| 309 | +/// The subtasks, the form that adds one, and the parent picker. | |
| 310 | +#[component] | |
| 311 | +pub async fn task_structure(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 312 | + let lang = page.lang; | |
| 313 | + let task = &modal.detail.task; | |
| 314 | + let id = task.id.as_str(); | |
| 315 | + let csrf = page.viewer.csrf.as_str(); | |
| 316 | + let next = modal.base.as_str(); | |
| 317 | + let subtask_action = format!("/tasks/{id}/subtasks"); | |
| 318 | + let parent_action = format!("/tasks/{id}/parent"); | |
| 319 | + let subtasks: Vec<(String, String)> = modal | |
| 320 | + .detail | |
| 321 | + .subtasks | |
| 322 | + .iter() | |
| 323 | + .map(|sub| { | |
| 324 | + ( | |
| 325 | + task_link(&modal.close, &sub.key), | |
| 326 | + format!("{} {}", sub.key, sub.title), | |
| 327 | + ) | |
| 328 | + }) | |
| 329 | + .collect(); | |
| 330 | + let parent_id = task.parent_id.clone().unwrap_or_default(); | |
| 331 | + let parents: Vec<(String, String, bool)> = modal | |
| 332 | + .options | |
| 333 | + .iter() | |
| 334 | + .filter(|other| other.parent_id.is_none()) | |
| 335 | + .map(|other| { | |
| 336 | + ( | |
| 337 | + other.id.clone(), | |
| 338 | + format!("{} {}", other.key, other.title), | |
| 339 | + other.id == parent_id, | |
| 340 | + ) | |
| 341 | + }) | |
| 342 | + .collect(); | |
| 343 | + let title_max = iz_core::limits::TITLE_MAX.to_string(); | |
| 344 | + Ok(view! { | |
| 345 | + <section class="task-section" aria-labelledby="task-subtasks"> | |
| 346 | + <h3 id="task-subtasks">(t(lang, K::Subtasks))</h3> | |
| 347 | + if subtasks.is_empty() { | |
| 348 | + <p class="muted">(t(lang, K::NoSubtasks))</p> | |
| 349 | + } | |
| 350 | + <ul class="task-list"> | |
| 351 | + for (link, label) in subtasks.iter() { | |
| 352 | + <li class="task-row"><a href=(link.as_str())>(label.as_str())</a></li> | |
| 353 | + } | |
| 354 | + </ul> | |
| 355 | + if modal.can_write && task.parent_id.is_none() { | |
| 356 | + <form class="task-inline" method="post" action=(subtask_action.as_str())> | |
| 357 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 358 | + <input type="hidden" name="next" value=(next)> | |
| 359 | + <div class="field field-wide"> | |
| 360 | + <label for="sub-title">(t(lang, K::SubtaskTitle))</label> | |
| 361 | + <input id="sub-title" name="title" maxlength=(title_max.as_str()) required=""> | |
| 362 | + </div> | |
| 363 | + <button class="button" type="submit">(t(lang, K::AddSubtask))</button> | |
| 364 | + </form> | |
| 365 | + } | |
| 366 | + if modal.can_write { | |
| 367 | + <form class="task-inline" method="post" action=(parent_action.as_str())> | |
| 368 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 369 | + <input type="hidden" name="next" value=(next)> | |
| 370 | + <div class="field"> | |
| 371 | + <label for="parent-pick">(t(lang, K::Parent))</label> | |
| 372 | + <select id="parent-pick" name="parent"> | |
| 373 | + <option value="" selected=(flag(task.parent_id.is_none()))>(t(lang, K::NoParent))</option> | |
| 374 | + for (parent, label, chosen) in parents.iter() { | |
| 375 | + <option value=(parent.as_str()) selected=(flag(*chosen))>(label.as_str())</option> | |
| 376 | + } | |
| 377 | + </select> | |
| 378 | + </div> | |
| 379 | + <button class="button" type="submit">(t(lang, K::SetParent))</button> | |
| 380 | + </form> | |
| 381 | + } | |
| 382 | + </section> | |
| 383 | + }) | |
| 384 | +} | |
| 385 | + | |
| 386 | +/// The dependencies in both directions, each with a remove control, and the form that adds one. | |
| 387 | +#[component] | |
| 388 | +pub async fn task_links(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 389 | + let lang = page.lang; | |
| 390 | + let id = modal.detail.task.id.as_str(); | |
| 391 | + let csrf = page.viewer.csrf.as_str(); | |
| 392 | + let next = modal.base.as_str(); | |
| 393 | + let remove_action = format!("/tasks/{id}/links/remove"); | |
| 394 | + let add_action = format!("/tasks/{id}/links"); | |
| 395 | + let waits: Vec<(String, String, String)> = modal | |
| 396 | + .detail | |
| 397 | + .blocked_by | |
| 398 | + .iter() | |
| 399 | + .map(|other| { | |
| 400 | + ( | |
| 401 | + other.id.clone(), | |
| 402 | + task_link(&modal.close, &other.key), | |
| 403 | + format!("{} {}", other.key, other.title), | |
| 404 | + ) | |
| 405 | + }) | |
| 406 | + .collect(); | |
| 407 | + let blocks: Vec<(String, String, String)> = modal | |
| 408 | + .detail | |
| 409 | + .blocks | |
| 410 | + .iter() | |
| 411 | + .map(|other| { | |
| 412 | + ( | |
| 413 | + other.id.clone(), | |
| 414 | + task_link(&modal.close, &other.key), | |
| 415 | + format!("{} {}", other.key, other.title), | |
| 416 | + ) | |
| 417 | + }) | |
| 418 | + .collect(); | |
| 419 | + let options: Vec<(String, String)> = modal | |
| 420 | + .options | |
| 421 | + .iter() | |
| 422 | + .map(|other| (other.id.clone(), format!("{} {}", other.key, other.title))) | |
| 423 | + .collect(); | |
| 424 | + let nothing = waits.is_empty() && blocks.is_empty(); | |
| 425 | + Ok(view! { | |
| 426 | + <section class="task-section" aria-labelledby="task-deps"> | |
| 427 | + <h3 id="task-deps">(t(lang, K::Dependencies))</h3> | |
| 428 | + if nothing { | |
| 429 | + <p class="muted">(t(lang, K::NoLinks))</p> | |
| 430 | + } | |
| 431 | + if !waits.is_empty() { | |
| 432 | + <h4>(t(lang, K::BlockedBy))</h4> | |
| 433 | + <ul class="task-list"> | |
| 434 | + for (other_id, link, label) in waits.iter() { | |
| 435 | + <li class="task-row"> | |
| 436 | + <a href=(link.as_str())>(label.as_str())</a> | |
| 437 | + if modal.can_write { | |
| 438 | + <form method="post" action=(remove_action.as_str())> | |
| 439 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 440 | + <input type="hidden" name="next" value=(next)> | |
| 441 | + <input type="hidden" name="other" value=(other_id.as_str())> | |
| 442 | + <input type="hidden" name="direction" value="blocked_by"> | |
| 443 | + <button class="button ghost" type="submit">(t(lang, K::RemoveLink))</button> | |
| 444 | + </form> | |
| 445 | + } | |
| 446 | + </li> | |
| 447 | + } | |
| 448 | + </ul> | |
| 449 | + } | |
| 450 | + if !blocks.is_empty() { | |
| 451 | + <h4>(t(lang, K::Blocks))</h4> | |
| 452 | + <ul class="task-list"> | |
| 453 | + for (other_id, link, label) in blocks.iter() { | |
| 454 | + <li class="task-row"> | |
| 455 | + <a href=(link.as_str())>(label.as_str())</a> | |
| 456 | + if modal.can_write { | |
| 457 | + <form method="post" action=(remove_action.as_str())> | |
| 458 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 459 | + <input type="hidden" name="next" value=(next)> | |
| 460 | + <input type="hidden" name="other" value=(other_id.as_str())> | |
| 461 | + <input type="hidden" name="direction" value="blocks"> | |
| 462 | + <button class="button ghost" type="submit">(t(lang, K::RemoveLink))</button> | |
| 463 | + </form> | |
| 464 | + } | |
| 465 | + </li> | |
| 466 | + } | |
| 467 | + </ul> | |
| 468 | + } | |
| 469 | + if modal.can_write && !options.is_empty() { | |
| 470 | + <form class="task-inline" method="post" action=(add_action.as_str())> | |
| 471 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 472 | + <input type="hidden" name="next" value=(next)> | |
| 473 | + <div class="field"> | |
| 474 | + <label for="link-other">(t(lang, K::LinkWith))</label> | |
| 475 | + <select id="link-other" name="other"> | |
| 476 | + for (other_id, label) in options.iter() { | |
| 477 | + <option value=(other_id.as_str())>(label.as_str())</option> | |
| 478 | + } | |
| 479 | + </select> | |
| 480 | + </div> | |
| 481 | + <div class="field"> | |
| 482 | + <label for="link-direction">(t(lang, K::LinkDirection))</label> | |
| 483 | + <select id="link-direction" name="direction"> | |
| 484 | + <option value="blocked_by">(t(lang, K::DirBlockedBy))</option> | |
| 485 | + <option value="blocks">(t(lang, K::DirBlocks))</option> | |
| 486 | + </select> | |
| 487 | + </div> | |
| 488 | + <button class="button" type="submit">(t(lang, K::AddLink))</button> | |
| 489 | + </form> | |
| 490 | + } | |
| 491 | + </section> | |
| 492 | + }) | |
| 493 | +} | |
| 494 | + | |
| 495 | +/// The comments, oldest first, with edit and delete for the ones the viewer may change, and the composer. | |
| 496 | +#[component] | |
| 497 | +pub async fn task_comments(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 498 | + let lang = page.lang; | |
| 499 | + let id = modal.detail.task.id.as_str(); | |
| 500 | + let csrf = page.viewer.csrf.as_str(); | |
| 501 | + let next = modal.base.as_str(); | |
| 502 | + let comment_action = format!("/tasks/{id}/comments"); | |
| 503 | + let actions: Vec<(String, String)> = modal | |
| 504 | + .comments | |
| 505 | + .iter() | |
| 506 | + .map(|c| { | |
| 507 | + ( | |
| 508 | + format!("/comments/{}/edit", c.id), | |
| 509 | + format!("/comments/{}/delete", c.id), | |
| 510 | + ) | |
| 511 | + }) | |
| 512 | + .collect(); | |
| 513 | + let limit = iz_core::limits::COMMENT_MAX.to_string(); | |
| 514 | + Ok(view! { | |
| 515 | + <section class="task-section" aria-labelledby="task-comments"> | |
| 516 | + <h3 id="task-comments">(t(lang, K::Comments))</h3> | |
| 517 | + if modal.comments.is_empty() { | |
| 518 | + <p class="muted">(t(lang, K::NoComments))</p> | |
| 519 | + } | |
| 520 | + <ol class="comment-list"> | |
| 521 | + for (c, (edit_action, delete_action)) in modal.comments.iter().zip(actions.iter()) { | |
| 522 | + <li class="comment"> | |
| 523 | + <p class="comment-meta"> | |
| 524 | + <strong>(c.author.as_str())</strong> | |
| 525 | + " " | |
| 526 | + <time>(c.when.as_str())</time> | |
| 527 | + if c.edited { | |
| 528 | + " " | |
| 529 | + <span>(t(lang, K::Edited))</span> | |
| 530 | + } | |
| 531 | + </p> | |
| 532 | + rich_text(text: c.body.as_str()) | |
| 533 | + if c.can_edit { | |
| 534 | + <details class="comment-edit"> | |
| 535 | + <summary>(t(lang, K::EditComment))</summary> | |
| 536 | + <form class="task-form" method="post" action=(edit_action.as_str())> | |
| 537 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 538 | + <input type="hidden" name="next" value=(next)> | |
| 539 | + <textarea name="body" maxlength=(limit.as_str()) required="">(c.body.as_str())</textarea> | |
| 540 | + <button class="button" type="submit">(t(lang, K::SaveComment))</button> | |
| 541 | + </form> | |
| 542 | + </details> | |
| 543 | + } | |
| 544 | + if c.can_delete { | |
| 545 | + <form method="post" action=(delete_action.as_str())> | |
| 546 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 547 | + <input type="hidden" name="next" value=(next)> | |
| 548 | + <button class="button ghost danger" type="submit">(t(lang, K::DeleteComment))</button> | |
| 549 | + </form> | |
| 550 | + } | |
| 551 | + </li> | |
| 552 | + } | |
| 553 | + </ol> | |
| 554 | + if modal.can_write { | |
| 555 | + <form class="task-form" method="post" action=(comment_action.as_str())> | |
| 556 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 557 | + <input type="hidden" name="next" value=(next)> | |
| 558 | + <div class="field field-wide"> | |
| 559 | + <label for="comment-body">(t(lang, K::CommentBody))</label> | |
| 560 | + <textarea id="comment-body" name="body" maxlength=(limit.as_str()) required="">(modal.comment_draft.as_str())</textarea> | |
| 561 | + </div> | |
| 562 | + <button class="button primary" type="submit">(t(lang, K::PostComment))</button> | |
| 563 | + </form> | |
| 564 | + } | |
| 565 | + </section> | |
| 566 | + }) | |
| 567 | +} | |
| 568 | + | |
| 569 | +/// The activity feed, newest first, with the link to the next older page. | |
| 570 | +#[component] | |
| 571 | +pub async fn task_activity(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 572 | + let lang = page.lang; | |
| 573 | + Ok(view! { | |
| 574 | + <section class="task-section" aria-labelledby="task-activity"> | |
| 575 | + <h3 id="task-activity">(t(lang, K::Activity))</h3> | |
| 576 | + if modal.activity.is_empty() { | |
| 577 | + <p class="muted">(t(lang, K::NoActivity))</p> | |
| 578 | + } | |
| 579 | + <ul class="activity-list"> | |
| 580 | + for row in modal.activity.iter() { | |
| 581 | + <li> | |
| 582 | + <time>(row.when.as_str())</time> | |
| 583 | + " " | |
| 584 | + <span>(row.actor.as_str())</span> | |
| 585 | + " " | |
| 586 | + (row.sentence) | |
| 587 | + </li> | |
| 588 | + } | |
| 589 | + </ul> | |
| 590 | + if let Some(older) = modal.older.as_ref() { | |
| 591 | + <p><a class="button ghost" href=(older.as_str())>(t(lang, K::Older))</a></p> | |
| 592 | + } | |
| 593 | + </section> | |
| 594 | + }) | |
| 595 | +} | |
| 596 | + | |
| 597 | +/// Deleting the task. The first step is a link to `?confirm=delete`; the confirmation form posts the | |
| 598 | +/// delete and returns to the board, without the task. | |
| 599 | +#[component] | |
| 600 | +pub async fn task_delete(page: &BoardPage, modal: &TaskModal) -> Result<impl View> { | |
| 601 | + let lang = page.lang; | |
| 602 | + let id = modal.detail.task.id.as_str(); | |
| 603 | + let csrf = page.viewer.csrf.as_str(); | |
| 604 | + let delete_action = format!("/tasks/{id}/delete"); | |
| 605 | + let confirm_url = format!("{}&confirm=delete", modal.base); | |
| 606 | + let close = modal.close.as_str(); | |
| 607 | + Ok(view! { | |
| 608 | + if modal.can_write { | |
| 609 | + <section class="task-section"> | |
| 610 | + if modal.confirm_delete { | |
| 611 | + <div class="card task-confirm"> | |
| 612 | + <h3>(t(lang, K::DeleteQuestion))</h3> | |
| 613 | + <p>(t(lang, K::DeleteConsequence))</p> | |
| 614 | + <form class="task-inline" method="post" action=(delete_action.as_str())> | |
| 615 | + <input type="hidden" name="csrf" value=(csrf)> | |
| 616 | + <input type="hidden" name="next" value=(close)> | |
| 617 | + <button class="button danger" type="submit">(t(lang, K::DeleteYes))</button> | |
| 618 | + <a class="button ghost" href=(modal.base.as_str())>(t(lang, K::Close))</a> | |
| 619 | + </form> | |
| 620 | + </div> | |
| 621 | + } else { | |
| 622 | + <a class="button ghost danger" href=(confirm_url.as_str())>(t(lang, K::DeleteTask))</a> | |
| 623 | + } | |
| 624 | + </section> | |
| 625 | + } | |
| 626 | + }) | |
| 627 | +} |
style/_task.scssadded+144 -0
| @@ -0,0 +1,144 @@ | ||
| 1 | +//! The task modal: a panel over the board that holds the task's fields, people, structure, dependencies, | |
| 2 | +//! comments and activity. Without JavaScript the dialog is shown in place, so the panel rules also apply | |
| 3 | +//! to a plain `<dialog open>`. | |
| 4 | + | |
| 5 | +.task-dialog { | |
| 6 | + position: fixed; | |
| 7 | + inset: 0 0 0 auto; | |
| 8 | + z-index: 20; | |
| 9 | + width: min(44rem, 100vw); | |
| 10 | + max-width: 100vw; | |
| 11 | + height: 100dvh; | |
| 12 | + max-height: 100dvh; | |
| 13 | + margin: 0; | |
| 14 | + padding: 1.25rem 1.5rem 3rem; | |
| 15 | + overflow-y: auto; | |
| 16 | + border: 0; | |
| 17 | + border-left: 1px solid var(--border); | |
| 18 | + background: var(--surface); | |
| 19 | + color: var(--text); | |
| 20 | + box-shadow: -8px 0 24px rgb(0 0 0 / 0.12); | |
| 21 | +} | |
| 22 | + | |
| 23 | +.task-head { | |
| 24 | + display: flex; | |
| 25 | + align-items: center; | |
| 26 | + justify-content: space-between; | |
| 27 | + gap: 0.75rem; | |
| 28 | +} | |
| 29 | + | |
| 30 | +.task-key { | |
| 31 | + margin: 0; | |
| 32 | + font-family: ui-monospace, monospace; | |
| 33 | + color: var(--muted); | |
| 34 | +} | |
| 35 | + | |
| 36 | +.task-title { | |
| 37 | + margin: 0.5rem 0 0.75rem; | |
| 38 | + overflow-wrap: anywhere; | |
| 39 | +} | |
| 40 | + | |
| 41 | +.task-section { | |
| 42 | + padding-block: 1rem; | |
| 43 | + border-top: 1px solid var(--border); | |
| 44 | + | |
| 45 | + h3 { | |
| 46 | + margin: 0 0 0.5rem; | |
| 47 | + font-size: 1rem; | |
| 48 | + } | |
| 49 | + | |
| 50 | + h4 { | |
| 51 | + margin: 0.75rem 0 0.25rem; | |
| 52 | + font-size: 0.9rem; | |
| 53 | + color: var(--muted); | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | |
| 57 | +.task-facts { | |
| 58 | + display: grid; | |
| 59 | + grid-template-columns: max-content 1fr; | |
| 60 | + gap: 0.25rem 1rem; | |
| 61 | + margin: 0 0 0.75rem; | |
| 62 | + | |
| 63 | + dt { | |
| 64 | + color: var(--muted); | |
| 65 | + } | |
| 66 | + | |
| 67 | + dd { | |
| 68 | + margin: 0; | |
| 69 | + } | |
| 70 | +} | |
| 71 | + | |
| 72 | +.task-list, | |
| 73 | +.comment-list, | |
| 74 | +.activity-list { | |
| 75 | + margin: 0; | |
| 76 | + padding: 0; | |
| 77 | + list-style: none; | |
| 78 | +} | |
| 79 | + | |
| 80 | +.task-row { | |
| 81 | + display: flex; | |
| 82 | + flex-wrap: wrap; | |
| 83 | + align-items: center; | |
| 84 | + justify-content: space-between; | |
| 85 | + gap: 0.5rem; | |
| 86 | + padding-block: 0.25rem; | |
| 87 | + overflow-wrap: anywhere; | |
| 88 | +} | |
| 89 | + | |
| 90 | +.task-inline { | |
| 91 | + display: flex; | |
| 92 | + flex-wrap: wrap; | |
| 93 | + align-items: flex-end; | |
| 94 | + gap: 0.5rem; | |
| 95 | + margin-block: 0.5rem; | |
| 96 | +} | |
| 97 | + | |
| 98 | +.task-form { | |
| 99 | + margin-block: 0.5rem; | |
| 100 | +} | |
| 101 | + | |
| 102 | +.task-edit { | |
| 103 | + margin-top: 0.75rem; | |
| 104 | + | |
| 105 | + summary { | |
| 106 | + cursor: pointer; | |
| 107 | + color: var(--accent); | |
| 108 | + } | |
| 109 | +} | |
| 110 | + | |
| 111 | +.rich-text { | |
| 112 | + overflow-wrap: anywhere; | |
| 113 | + white-space: normal; | |
| 114 | + line-height: 1.5; | |
| 115 | + | |
| 116 | + a { | |
| 117 | + color: var(--accent); | |
| 118 | + } | |
| 119 | +} | |
| 120 | + | |
| 121 | +.comment { | |
| 122 | + padding-block: 0.5rem; | |
| 123 | + border-top: 1px solid var(--border); | |
| 124 | +} | |
| 125 | + | |
| 126 | +.comment-meta { | |
| 127 | + margin: 0 0 0.25rem; | |
| 128 | + font-size: 0.85rem; | |
| 129 | + color: var(--muted); | |
| 130 | +} | |
| 131 | + | |
| 132 | +.comment-edit { | |
| 133 | + margin-top: 0.25rem; | |
| 134 | +} | |
| 135 | + | |
| 136 | +.activity-list li { | |
| 137 | + padding-block: 0.2rem; | |
| 138 | + font-size: 0.9rem; | |
| 139 | + overflow-wrap: anywhere; | |
| 140 | +} | |
| 141 | + | |
| 142 | +.task-confirm { | |
| 143 | + border-color: var(--danger); | |
| 144 | +} |
style/main.scssmodified+1 -0
| @@ -7,3 +7,4 @@ | ||
| 7 | 7 | @use "layout"; |
| 8 | 8 | @use "components"; |
| 9 | 9 | @use "board"; |
| 10 | +@use "task"; |