The task modal crosses over
Browse files at this commitc7a137218c50137da911da615b56a7102b10c0c1Parent: 6106c34- feat
- the task modal crosses over
1 changed file +1030 -1
- crates/izlek-topcoat/src/detail.rs +1030 -1
crates/izlek-topcoat/src/detail.rsmodified+1030 -1
| @@ -1 +1,1030 @@ | ||
| 1 | -//! Lands in the page-port fan-out. | |
| 1 | +//! The task detail modal, ported from `izlek-web/src/detail.rs`'s TaskDetail | |
| 2 | +//! artboard. | |
| 3 | +//! | |
| 4 | +//! Leptos rendered this once and patched it in the browser from a resource; | |
| 5 | +//! topcoat has no browser bundle at all, so every one of the ten calls below | |
| 6 | +//! answers a plain form post with a 303 back to the page it came from — | |
| 7 | +//! [`crate::server::carry_refusal_on_redirect`] carries the refusal (if any) | |
| 8 | +//! onto that redirect's query the same way `crate::auth`'s calls do — and the | |
| 9 | +//! page it lands on reads the fresh task straight off the store. There is no | |
| 10 | +//! resource to refetch and no action to hold a pending state: a reload *is* | |
| 11 | +//! the refresh. | |
| 12 | +//! | |
| 13 | +//! Every mutating call still checks the task belongs to the asker's workspace | |
| 14 | +//! before it does anything — a task id in a form is an authorization | |
| 15 | +//! question, not a validation one — and every mail-rule wiring point | |
| 16 | +//! (`after_activity`/`after_freeing`) from the leptos version is carried over | |
| 17 | +//! unchanged. | |
| 18 | + | |
| 19 | +use izlek_core::board::Person; | |
| 20 | +use izlek_core::detail::{Comment, DeletionCost, DependencyEdge, TaskDetail, TaskFacts, moment_label}; | |
| 21 | +use izlek_core::store::{Store, StoreError, User}; | |
| 22 | +use serde::{Deserialize, Serialize}; | |
| 23 | +use time::Date; | |
| 24 | +use topcoat::Result; | |
| 25 | +use topcoat::context::Cx; | |
| 26 | +use topcoat::router::content::{Form, Json}; | |
| 27 | +use topcoat::router::request::headers; | |
| 28 | +use topcoat::router::{HeaderName, StatusCode, header, route}; | |
| 29 | +use topcoat::view::{class, view}; | |
| 30 | + | |
| 31 | +use crate::server::{Refusal, accounts, mail, refusal_of, require_user, require_writer}; | |
| 32 | + | |
| 33 | +/// A task this board could be linked to: enough to name it in the picker and | |
| 34 | +/// nothing more. | |
| 35 | +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 36 | +pub struct LinkTarget { | |
| 37 | + pub id: String, | |
| 38 | + pub task_key: String, | |
| 39 | + pub title: String, | |
| 40 | +} | |
| 41 | + | |
| 42 | +/// The person the current browser is signed in as, wired the same as | |
| 43 | +/// `izlek-web/src/auth.rs`'s `Me` so [`fetch_task`]'s answer keeps its shape. | |
| 44 | +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 45 | +pub struct Me { | |
| 46 | + pub id: String, | |
| 47 | + pub display_name: String, | |
| 48 | + pub email: String, | |
| 49 | + pub role: izlek_core::Role, | |
| 50 | +} | |
| 51 | + | |
| 52 | +impl From<&User> for Me { | |
| 53 | + fn from(user: &User) -> Self { | |
| 54 | + Me { | |
| 55 | + id: user.id.clone(), | |
| 56 | + display_name: user.display_name.clone(), | |
| 57 | + email: user.email.clone(), | |
| 58 | + role: user.role, | |
| 59 | + } | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +/// One task detail's worth of state — the [`fetch_task`] answer. | |
| 64 | +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 65 | +pub struct DetailSnapshot { | |
| 66 | + pub detail: TaskDetail, | |
| 67 | + pub me: Me, | |
| 68 | + pub today: Date, | |
| 69 | + pub linkable: Vec<LinkTarget>, | |
| 70 | + pub may_write: bool, | |
| 71 | + pub may_comment: bool, | |
| 72 | + pub may_delete: bool, | |
| 73 | + pub allowed_file_types: Vec<String>, | |
| 74 | + pub attachment_limit_mb: u64, | |
| 75 | +} | |
| 76 | + | |
| 77 | +/// Which way round a dependency runs, as it travels in a form. | |
| 78 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 79 | +#[serde(rename_all = "snake_case")] | |
| 80 | +pub enum Direction { | |
| 81 | + BlockedBy, | |
| 82 | + Blocks, | |
| 83 | +} | |
| 84 | + | |
| 85 | +/// Which task is `blocked` and which is `blocking`, from the task the modal | |
| 86 | +/// is open on, the other task it names, and which way the form said the link | |
| 87 | +/// runs. | |
| 88 | +fn resolve_direction(task_id: &str, other_id: &str, direction: Direction) -> (String, String) { | |
| 89 | + match direction { | |
| 90 | + Direction::BlockedBy => (task_id.to_string(), other_id.to_string()), | |
| 91 | + Direction::Blocks => (other_id.to_string(), task_id.to_string()), | |
| 92 | + } | |
| 93 | +} | |
| 94 | + | |
| 95 | +#[cfg(test)] | |
| 96 | +mod resolve_direction_tests { | |
| 97 | + use super::{Direction, resolve_direction}; | |
| 98 | + | |
| 99 | + #[test] | |
| 100 | + fn blocked_by_puts_this_task_first() { | |
| 101 | + assert_eq!( | |
| 102 | + resolve_direction("this", "other", Direction::BlockedBy), | |
| 103 | + ("this".to_string(), "other".to_string()) | |
| 104 | + ); | |
| 105 | + } | |
| 106 | + | |
| 107 | + #[test] | |
| 108 | + fn blocks_puts_the_other_task_first() { | |
| 109 | + assert_eq!( | |
| 110 | + resolve_direction("this", "other", Direction::Blocks), | |
| 111 | + ("other".to_string(), "this".to_string()) | |
| 112 | + ); | |
| 113 | + } | |
| 114 | +} | |
| 115 | + | |
| 116 | +// -- guards ------------------------------------------------------------- | |
| 117 | + | |
| 118 | +/// The task, if this person's workspace is the one holding it. A task in | |
| 119 | +/// another workspace is not found rather than forbidden: the answer says | |
| 120 | +/// nothing about whether the id is real. | |
| 121 | +async fn task_of(store: &dyn Store, user: &User, task_id: &str) -> std::result::Result<TaskFacts, Refusal> { | |
| 122 | + match store.task(task_id).await { | |
| 123 | + Ok(Some(facts)) if facts.workspace_id == user.workspace_id => Ok(facts), | |
| 124 | + Ok(_) => Err(Refusal::NotFound), | |
| 125 | + Err(error) => { | |
| 126 | + eprintln!("store error: {error}"); | |
| 127 | + Err(Refusal::Unavailable) | |
| 128 | + } | |
| 129 | + } | |
| 130 | +} | |
| 131 | + | |
| 132 | +/// The writer behind this request and the task they named. | |
| 133 | +async fn writer_and_task(cx: &Cx, task_id: &str) -> std::result::Result<(User, TaskFacts), Refusal> { | |
| 134 | + let user = require_writer(cx).await?; | |
| 135 | + let store = accounts(cx).store().clone(); | |
| 136 | + let facts = task_of(store.as_ref(), &user, task_id).await?; | |
| 137 | + Ok((user, facts)) | |
| 138 | +} | |
| 139 | + | |
| 140 | +/// A 303 back to wherever the form was posted from, carrying `refusal` as the | |
| 141 | +/// body for `carry_refusal_on_redirect` to read — the same shape `auth.rs` | |
| 142 | +/// uses for every one of its mutating calls. | |
| 143 | +type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json<Option<Refusal>>)>; | |
| 144 | + | |
| 145 | +fn back_to(cx: &Cx) -> String { | |
| 146 | + headers(cx) | |
| 147 | + .get(header::REFERER) | |
| 148 | + .and_then(|value| value.to_str().ok()) | |
| 149 | + .unwrap_or("/") | |
| 150 | + .to_string() | |
| 151 | +} | |
| 152 | + | |
| 153 | +fn redirect(cx: &Cx, refusal: Option<Refusal>) -> Redirect { | |
| 154 | + Ok((StatusCode::SEE_OTHER, [(header::LOCATION, back_to(cx))], Json(refusal))) | |
| 155 | +} | |
| 156 | + | |
| 157 | +// -- the ten calls -------------------------------------------------------- | |
| 158 | + | |
| 159 | +#[derive(Deserialize)] | |
| 160 | +struct TaskIdForm { | |
| 161 | + task_id: String, | |
| 162 | +} | |
| 163 | + | |
| 164 | +#[derive(Deserialize)] | |
| 165 | +struct SaveTaskForm { | |
| 166 | + task_id: String, | |
| 167 | + #[serde(default)] | |
| 168 | + title: Option<String>, | |
| 169 | + #[serde(default)] | |
| 170 | + description: Option<String>, | |
| 171 | + #[serde(default)] | |
| 172 | + deadline: Option<String>, | |
| 173 | +} | |
| 174 | + | |
| 175 | +#[derive(Deserialize)] | |
| 176 | +struct PersonForm { | |
| 177 | + task_id: String, | |
| 178 | + user_id: String, | |
| 179 | +} | |
| 180 | + | |
| 181 | +#[derive(Deserialize)] | |
| 182 | +struct LinkForm { | |
| 183 | + task_id: String, | |
| 184 | + other_id: String, | |
| 185 | + direction: Direction, | |
| 186 | +} | |
| 187 | + | |
| 188 | +#[derive(Deserialize)] | |
| 189 | +struct CommentForm { | |
| 190 | + task_id: String, | |
| 191 | + body: String, | |
| 192 | +} | |
| 193 | + | |
| 194 | +#[derive(Deserialize)] | |
| 195 | +struct FileIdForm { | |
| 196 | + file_id: String, | |
| 197 | +} | |
| 198 | + | |
| 199 | +/// Everything one task detail shows. A Viewer may read it; what they may not | |
| 200 | +/// do is refused in the calls below, not merely hidden from them here. | |
| 201 | +/// | |
| 202 | +/// Shared by the route and [`task_modal`], which calls it directly rather | |
| 203 | +/// than going back through its own HTTP endpoint — the same shape `pages.rs` | |
| 204 | +/// reads the store straight through for its own screens. | |
| 205 | +async fn load_snapshot(cx: &Cx, task_id: &str) -> Result<std::result::Result<DetailSnapshot, Refusal>> { | |
| 206 | + use izlek_core::detail::load; | |
| 207 | + use time::OffsetDateTime; | |
| 208 | + | |
| 209 | + let user = match require_user(cx).await { | |
| 210 | + Ok(user) => user, | |
| 211 | + Err(refusal) => return Ok(Err(refusal)), | |
| 212 | + }; | |
| 213 | + let store = accounts(cx).store().clone(); | |
| 214 | + | |
| 215 | + let Some(detail) = load(store.as_ref(), &user.workspace_id, task_id).await? else { | |
| 216 | + return Ok(Err(Refusal::NotFound)); | |
| 217 | + }; | |
| 218 | + | |
| 219 | + // What the picker may offer: this board's other tasks, minus the ones | |
| 220 | + // already on either end of a live link with this one. A cleared edge is | |
| 221 | + // not a link any more, so its task comes back to the picker. | |
| 222 | + let mut linkable = Vec::new(); | |
| 223 | + if let Some(board) = store.board(&user.workspace_id).await? { | |
| 224 | + let taken: Vec<&str> = detail | |
| 225 | + .blocked_by | |
| 226 | + .iter() | |
| 227 | + .chain(detail.blocks.iter()) | |
| 228 | + .filter(|edge| edge.cleared_at.is_none()) | |
| 229 | + .map(|edge| edge.task_id.as_str()) | |
| 230 | + .collect(); | |
| 231 | + for task in store.tasks_for_board(&board.id).await? { | |
| 232 | + if task.id == detail.id || taken.contains(&task.id.as_str()) { | |
| 233 | + continue; | |
| 234 | + } | |
| 235 | + linkable.push(LinkTarget { | |
| 236 | + id: task.id, | |
| 237 | + task_key: task.task_key, | |
| 238 | + title: task.title, | |
| 239 | + }); | |
| 240 | + } | |
| 241 | + linkable.sort_by(|a, b| a.task_key.cmp(&b.task_key)); | |
| 242 | + } | |
| 243 | + | |
| 244 | + let may_write = user.role.can_write_tasks(); | |
| 245 | + | |
| 246 | + const MB: u64 = 1024 * 1024; | |
| 247 | + let workspace = store.workspace().await?; | |
| 248 | + let allowed_file_types = workspace | |
| 249 | + .as_ref() | |
| 250 | + .map(|workspace| workspace.allowed_file_types.clone()) | |
| 251 | + .unwrap_or_default(); | |
| 252 | + let attachment_limit_mb = workspace.map(|workspace| workspace.attachment_limit_bytes / MB).unwrap_or(0); | |
| 253 | + | |
| 254 | + Ok(Ok(DetailSnapshot { | |
| 255 | + detail, | |
| 256 | + linkable, | |
| 257 | + may_write, | |
| 258 | + may_comment: user.role.can_comment(), | |
| 259 | + may_delete: may_write, | |
| 260 | + allowed_file_types, | |
| 261 | + attachment_limit_mb, | |
| 262 | + me: Me::from(&user), | |
| 263 | + today: OffsetDateTime::now_utc().date(), | |
| 264 | + })) | |
| 265 | +} | |
| 266 | + | |
| 267 | +#[route(POST "/api/fetch_task")] | |
| 268 | +async fn fetch_task(cx: &Cx, Form(input): Form<TaskIdForm>) -> Result<Json<std::result::Result<DetailSnapshot, Refusal>>> { | |
| 269 | + Ok(Json(load_snapshot(cx, &input.task_id).await?)) | |
| 270 | +} | |
| 271 | + | |
| 272 | +/// Saves the title, the description and the deadline. Status is not here: the | |
| 273 | +/// column a task sits in is changed by moving it, a call `board.rs` owns. | |
| 274 | +#[route(POST "/api/save_task")] | |
| 275 | +async fn save_task(cx: &Cx, Form(input): Form<SaveTaskForm>) -> Redirect { | |
| 276 | + use time::OffsetDateTime; | |
| 277 | + use time::macros::format_description; | |
| 278 | + | |
| 279 | + let (user, facts) = match writer_and_task(cx, &input.task_id).await { | |
| 280 | + Ok(pair) => pair, | |
| 281 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 282 | + }; | |
| 283 | + | |
| 284 | + let title = match input.title { | |
| 285 | + Some(given) => { | |
| 286 | + let trimmed = given.trim().to_string(); | |
| 287 | + if trimmed.is_empty() { | |
| 288 | + return redirect(cx, Some(Refusal::EmptyTitle)); | |
| 289 | + } | |
| 290 | + trimmed | |
| 291 | + } | |
| 292 | + None => facts.row.title.clone(), | |
| 293 | + }; | |
| 294 | + let description = match &input.description { | |
| 295 | + Some(given) => given.trim().to_string(), | |
| 296 | + None => facts.description.clone(), | |
| 297 | + }; | |
| 298 | + let deadline = match input.deadline.as_deref() { | |
| 299 | + None => facts.row.deadline, | |
| 300 | + Some(raw) => match raw.trim() { | |
| 301 | + "" => None, | |
| 302 | + day => match Date::parse(day, format_description!("[year]-[month]-[day]")) { | |
| 303 | + Ok(day) => Some(day), | |
| 304 | + Err(_) => return redirect(cx, Some(Refusal::BadDeadline)), | |
| 305 | + }, | |
| 306 | + }, | |
| 307 | + }; | |
| 308 | + | |
| 309 | + let store = accounts(cx).store().clone(); | |
| 310 | + let activity_ids = store | |
| 311 | + .save_task(&input.task_id, &title, &description, deadline, &user.id, OffsetDateTime::now_utc()) | |
| 312 | + .await?; | |
| 313 | + for activity_id in activity_ids { | |
| 314 | + mail(cx).after_activity(store.clone(), activity_id); | |
| 315 | + } | |
| 316 | + redirect(cx, None) | |
| 317 | +} | |
| 318 | + | |
| 319 | +/// Puts someone on a task. A Viewer can neither do this nor be the target. | |
| 320 | +#[route(POST "/api/assign")] | |
| 321 | +async fn assign(cx: &Cx, Form(input): Form<PersonForm>) -> Redirect { | |
| 322 | + use izlek_core::detail::ActivityKind; | |
| 323 | + use time::OffsetDateTime; | |
| 324 | + | |
| 325 | + let (actor, _) = match writer_and_task(cx, &input.task_id).await { | |
| 326 | + Ok(pair) => pair, | |
| 327 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 328 | + }; | |
| 329 | + let store = accounts(cx).store().clone(); | |
| 330 | + | |
| 331 | + let Some(person) = store.user(&input.user_id).await? else { | |
| 332 | + return redirect(cx, Some(Refusal::NotFound)); | |
| 333 | + }; | |
| 334 | + if person.workspace_id != actor.workspace_id { | |
| 335 | + return redirect(cx, Some(Refusal::NotFound)); | |
| 336 | + } | |
| 337 | + if !person.role.can_be_assigned() { | |
| 338 | + return redirect(cx, Some(Refusal::Forbidden)); | |
| 339 | + } | |
| 340 | + | |
| 341 | + store.assign_task(&input.task_id, &person.id).await?; | |
| 342 | + let activity_id = store | |
| 343 | + .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Assigned, &person.display_name, OffsetDateTime::now_utc()) | |
| 344 | + .await?; | |
| 345 | + mail(cx).after_activity(store, activity_id); | |
| 346 | + redirect(cx, None) | |
| 347 | +} | |
| 348 | + | |
| 349 | +#[route(POST "/api/unassign")] | |
| 350 | +async fn unassign(cx: &Cx, Form(input): Form<PersonForm>) -> Redirect { | |
| 351 | + use izlek_core::detail::ActivityKind; | |
| 352 | + use time::OffsetDateTime; | |
| 353 | + | |
| 354 | + let (actor, _) = match writer_and_task(cx, &input.task_id).await { | |
| 355 | + Ok(pair) => pair, | |
| 356 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 357 | + }; | |
| 358 | + let store = accounts(cx).store().clone(); | |
| 359 | + | |
| 360 | + let Some(person) = store.user(&input.user_id).await? else { | |
| 361 | + return redirect(cx, Some(Refusal::NotFound)); | |
| 362 | + }; | |
| 363 | + if person.workspace_id != actor.workspace_id { | |
| 364 | + return redirect(cx, Some(Refusal::NotFound)); | |
| 365 | + } | |
| 366 | + store.unassign_task(&input.task_id, &person.id).await?; | |
| 367 | + let activity_id = store | |
| 368 | + .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Unassigned, &person.display_name, OffsetDateTime::now_utc()) | |
| 369 | + .await?; | |
| 370 | + mail(cx).after_activity(store, activity_id); | |
| 371 | + redirect(cx, None) | |
| 372 | +} | |
| 373 | + | |
| 374 | +/// Links two tasks. Both ends are checked against the asker's workspace, and | |
| 375 | +/// a link that would close a circle is refused by the store, inside the | |
| 376 | +/// transaction that would have written it. | |
| 377 | +#[route(POST "/api/link_tasks")] | |
| 378 | +async fn link_tasks(cx: &Cx, Form(input): Form<LinkForm>) -> Redirect { | |
| 379 | + use izlek_core::detail::ActivityKind; | |
| 380 | + use time::OffsetDateTime; | |
| 381 | + | |
| 382 | + let (actor, _) = match writer_and_task(cx, &input.task_id).await { | |
| 383 | + Ok(pair) => pair, | |
| 384 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 385 | + }; | |
| 386 | + let store = accounts(cx).store().clone(); | |
| 387 | + let other = match task_of(store.as_ref(), &actor, &input.other_id).await { | |
| 388 | + Ok(facts) => facts, | |
| 389 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 390 | + }; | |
| 391 | + | |
| 392 | + let (blocked, blocking) = resolve_direction(&input.task_id, &input.other_id, input.direction); | |
| 393 | + let now = OffsetDateTime::now_utc(); | |
| 394 | + match store.add_dependency(&blocked, &blocking, now).await { | |
| 395 | + Ok(()) => {} | |
| 396 | + Err(StoreError::Cycle) => return redirect(cx, Some(Refusal::Cycle)), | |
| 397 | + Err(error) => return Err(error.into()), | |
| 398 | + } | |
| 399 | + let activity_id = store | |
| 400 | + .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Linked, &other.row.task_key, now) | |
| 401 | + .await?; | |
| 402 | + mail(cx).after_activity(store, activity_id); | |
| 403 | + redirect(cx, None) | |
| 404 | +} | |
| 405 | + | |
| 406 | +/// Clears a link. The row stays, marked cleared, so the history — and the | |
| 407 | +/// rules engine — still has something to read. | |
| 408 | +#[route(POST "/api/unlink_tasks")] | |
| 409 | +async fn unlink_tasks(cx: &Cx, Form(input): Form<LinkForm>) -> Redirect { | |
| 410 | + use izlek_core::detail::ActivityKind; | |
| 411 | + use time::OffsetDateTime; | |
| 412 | + | |
| 413 | + let (actor, _) = match writer_and_task(cx, &input.task_id).await { | |
| 414 | + Ok(pair) => pair, | |
| 415 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 416 | + }; | |
| 417 | + let store = accounts(cx).store().clone(); | |
| 418 | + let other = match task_of(store.as_ref(), &actor, &input.other_id).await { | |
| 419 | + Ok(facts) => facts, | |
| 420 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 421 | + }; | |
| 422 | + | |
| 423 | + let (blocked, blocking) = resolve_direction(&input.task_id, &input.other_id, input.direction); | |
| 424 | + let now = OffsetDateTime::now_utc(); | |
| 425 | + store.clear_dependency(&blocked, &blocking, now).await?; | |
| 426 | + let activity_id = store | |
| 427 | + .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Unlinked, &other.row.task_key, now) | |
| 428 | + .await?; | |
| 429 | + mail(cx).after_activity(store, activity_id); | |
| 430 | + redirect(cx, None) | |
| 431 | +} | |
| 432 | + | |
| 433 | +/// Writes a comment. The author is the session's user; there is no author | |
| 434 | +/// field on the form. A Viewer is refused here, not merely shown no textarea. | |
| 435 | +#[route(POST "/api/post_comment")] | |
| 436 | +async fn post_comment(cx: &Cx, Form(input): Form<CommentForm>) -> Redirect { | |
| 437 | + use time::OffsetDateTime; | |
| 438 | + | |
| 439 | + let user = match require_user(cx).await { | |
| 440 | + Ok(user) => user, | |
| 441 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 442 | + }; | |
| 443 | + if !user.role.can_comment() { | |
| 444 | + return redirect(cx, Some(Refusal::Forbidden)); | |
| 445 | + } | |
| 446 | + let store = accounts(cx).store().clone(); | |
| 447 | + if let Err(refusal) = task_of(store.as_ref(), &user, &input.task_id).await { | |
| 448 | + return redirect(cx, Some(refusal)); | |
| 449 | + } | |
| 450 | + let body = input.body.trim(); | |
| 451 | + if body.is_empty() { | |
| 452 | + return redirect(cx, Some(Refusal::EmptyComment)); | |
| 453 | + } | |
| 454 | + | |
| 455 | + let written = store.add_comment(&input.task_id, &user.id, body, OffsetDateTime::now_utc()).await?; | |
| 456 | + mail(cx).after_activity(store, written.activity_id); | |
| 457 | + redirect(cx, None) | |
| 458 | +} | |
| 459 | + | |
| 460 | +/// What a delete would take with it, for the confirmation step. Reads only. | |
| 461 | +#[route(POST "/api/what_delete_costs")] | |
| 462 | +async fn what_delete_costs(cx: &Cx, Form(input): Form<TaskIdForm>) -> Result<Json<std::result::Result<DeletionCost, Refusal>>> { | |
| 463 | + if let Err(refusal) = writer_and_task(cx, &input.task_id).await { | |
| 464 | + return Ok(Json(Err(refusal))); | |
| 465 | + } | |
| 466 | + match accounts(cx).store().deletion_cost(&input.task_id).await? { | |
| 467 | + Some(cost) => Ok(Json(Ok(cost))), | |
| 468 | + None => Ok(Json(Err(Refusal::NotFound))), | |
| 469 | + } | |
| 470 | +} | |
| 471 | + | |
| 472 | +/// Deletes a task. A writer may: the delete is soft, so a mistake is | |
| 473 | +/// recoverable by hand. Whatever was waiting only on it becomes unblocked, | |
| 474 | +/// the store records that as an event, and the unblocked rules fire on it. | |
| 475 | +#[route(POST "/api/delete_task")] | |
| 476 | +async fn delete_task(cx: &Cx, Form(input): Form<TaskIdForm>) -> Redirect { | |
| 477 | + use time::OffsetDateTime; | |
| 478 | + | |
| 479 | + let (user, _) = match writer_and_task(cx, &input.task_id).await { | |
| 480 | + Ok(pair) => pair, | |
| 481 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 482 | + }; | |
| 483 | + let store = accounts(cx).store().clone(); | |
| 484 | + let deletion = store.delete_task(&input.task_id, &user.id, OffsetDateTime::now_utc()).await?; | |
| 485 | + // A blocker being deleted unblocks whatever was waiting only on it, which | |
| 486 | + // is the same news as the blocker finishing. The freeing is committed; | |
| 487 | + // the send is a separate step, off the request. | |
| 488 | + if let Some(freeing) = deletion.event { | |
| 489 | + mail(cx).after_freeing(freeing, deletion.freed); | |
| 490 | + } | |
| 491 | + mail(cx).after_activity(store, deletion.activity_id); | |
| 492 | + redirect(cx, None) | |
| 493 | +} | |
| 494 | + | |
| 495 | +/// Deletes an attachment's row and its bytes. A hard delete, unlike | |
| 496 | +/// [`delete_task`]'s soft one — a file is a blob on disk, not a fact worth an | |
| 497 | +/// audit trail. Only the person who put it there, or an admin, may take it | |
| 498 | +/// away. | |
| 499 | +#[route(POST "/api/delete_file")] | |
| 500 | +async fn delete_file(cx: &Cx, Form(input): Form<FileIdForm>) -> Redirect { | |
| 501 | + let user = match require_user(cx).await { | |
| 502 | + Ok(user) => user, | |
| 503 | + Err(refusal) => return redirect(cx, Some(refusal)), | |
| 504 | + }; | |
| 505 | + let store = accounts(cx).store().clone(); | |
| 506 | + let Some(attachment) = store.attachment(&input.file_id).await? else { | |
| 507 | + return redirect(cx, Some(Refusal::NotFound)); | |
| 508 | + }; | |
| 509 | + if let Err(refusal) = task_of(store.as_ref(), &user, &attachment.task_id).await { | |
| 510 | + return redirect(cx, Some(refusal)); | |
| 511 | + } | |
| 512 | + if user.id != attachment.uploaded_by && !user.role.can_administer() { | |
| 513 | + return redirect(cx, Some(Refusal::Forbidden)); | |
| 514 | + } | |
| 515 | + | |
| 516 | + store.delete_attachment(&input.file_id).await?; | |
| 517 | + redirect(cx, None) | |
| 518 | +} | |
| 519 | + | |
| 520 | +// -- the screen ------------------------------------------------------------- | |
| 521 | +// | |
| 522 | +// Wasm-escapes from the leptos version, each simplified to a plain form post | |
| 523 | +// rather than ported to a runtime signal (noted at each site below): | |
| 524 | +// | |
| 525 | +// - StatusControl's `on:change` auto-submit (dyn_into the `<select>`, call | |
| 526 | +// `request_submit()`) is dropped; the "Move" button is always shown rather | |
| 527 | +// than only when script is not running. | |
| 528 | +// - The modal scrim's click-to-close and the window `Escape` listener are | |
| 529 | +// dropped; the X glyph and the footer "Close" button (plain links/buttons, | |
| 530 | +// no script) are the only ways to close. | |
| 531 | +// - DeadlineControl's hand-built calendar grid (`js_sys::Date` for "today", | |
| 532 | +// month navigation, per-day buttons) is replaced with a native | |
| 533 | +// `<input type="date">` inside the same CSS-only edit-toggle popover — | |
| 534 | +// the toggle itself needed no script in the leptos version either. | |
| 535 | +// - The file input's `on:change` auto-submit is dropped; an explicit | |
| 536 | +// "Upload" submit button is added next to the file picker. | |
| 537 | +// - The two-step delete confirmation (an `ask` action fetching the cost, | |
| 538 | +// then a second click) is collapsed into one eager read: the cost is | |
| 539 | +// computed while the screen renders, and a native `<details>` disclosure — | |
| 540 | +// no script — holds the confirmation and the real delete button. | |
| 541 | + | |
| 542 | +/// A person as a circle. Ported from `izlek-web/src/board.rs`'s `Avatar`; that | |
| 543 | +/// component has not crossed over into this crate yet, so this is a private | |
| 544 | +/// copy rather than a shared one. | |
| 545 | +async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { | |
| 546 | + let initials = person.initials(); | |
| 547 | + let tone = person.id.bytes().fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32)) % 5; | |
| 548 | + view! { | |
| 549 | + cx => | |
| 550 | + <span class=(class!("avatar", format!("avatar-tone-{tone}"), extra)) title=(person.display_name.clone())> | |
| 551 | + (initials) | |
| 552 | + </span> | |
| 553 | + } | |
| 554 | +} | |
| 555 | + | |
| 556 | +async fn refused(cx: &Cx, call: &str) -> Result { | |
| 557 | + match refusal_of(cx, call) { | |
| 558 | + Some(refusal) => view! { cx => <p class="modal-problem">(refusal.message())</p> }, | |
| 559 | + None => view! { cx => }, | |
| 560 | + } | |
| 561 | +} | |
| 562 | + | |
| 563 | +async fn title_control(cx: &Cx, task: &TaskDetail, may_write: bool) -> Result { | |
| 564 | + if !may_write { | |
| 565 | + return view! { cx => <h2 class="detail-title">(task.title.clone())</h2> }; | |
| 566 | + } | |
| 567 | + let toggle = format!("rename-{}", task.id); | |
| 568 | + view! { | |
| 569 | + cx => | |
| 570 | + <div class="edit"> | |
| 571 | + <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label="Rename this task"> | |
| 572 | + <h2 class="detail-title edit-view"> | |
| 573 | + <label class="edit-hit" for=(toggle.clone())>(task.title.clone())</label> | |
| 574 | + </h2> | |
| 575 | + <form class="edit-form title-form" method="post" action="/api/save_task"> | |
| 576 | + <input type="hidden" name="task_id" value=(task.id.clone())> | |
| 577 | + <input class="title-input" type="text" name="title" value=(task.title.clone()) autocomplete="off" required=""> | |
| 578 | + <button class="edit-save" type="submit">"Save"</button> | |
| 579 | + <label class="edit-cancel" for=(toggle)>"Cancel"</label> | |
| 580 | + </form> | |
| 581 | + (refused(cx, "save_task").await?) | |
| 582 | + </div> | |
| 583 | + } | |
| 584 | +} | |
| 585 | + | |
| 586 | +async fn description_control(cx: &Cx, task: &TaskDetail, may_write: bool) -> Result { | |
| 587 | + let empty = task.description.trim().is_empty(); | |
| 588 | + let prose = if empty { "No description yet.".to_string() } else { task.description.clone() }; | |
| 589 | + | |
| 590 | + if !may_write { | |
| 591 | + return view! { cx => <p class=(class!("detail-prose", "detail-prose-empty" if empty))>(prose)</p> }; | |
| 592 | + } | |
| 593 | + let toggle = format!("describe-{}", task.id); | |
| 594 | + view! { | |
| 595 | + cx => | |
| 596 | + <div class="edit"> | |
| 597 | + <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label="Edit the description"> | |
| 598 | + <label class=(class!("detail-prose", "edit-view", "edit-hit", "detail-prose-empty" if empty)) for=(toggle.clone())> | |
| 599 | + (prose) | |
| 600 | + </label> | |
| 601 | + <form class="edit-form describe-form" method="post" action="/api/save_task"> | |
| 602 | + <input type="hidden" name="task_id" value=(task.id.clone())> | |
| 603 | + <textarea class="detail-textarea" name="description" rows="5">(task.description.clone())</textarea> | |
| 604 | + <div class="edit-row"> | |
| 605 | + <button class="edit-save" type="submit">"Save"</button> | |
| 606 | + <label class="edit-cancel" for=(toggle)>"Cancel"</label> | |
| 607 | + </div> | |
| 608 | + </form> | |
| 609 | + (refused(cx, "save_task").await?) | |
| 610 | + </div> | |
| 611 | + } | |
| 612 | +} | |
| 613 | + | |
| 614 | +async fn deadline_control(cx: &Cx, task: &TaskDetail, today: Date, may_write: bool) -> Result { | |
| 615 | + let overdue = task.is_overdue(today); | |
| 616 | + let label = task.deadline_label(today); | |
| 617 | + if !may_write { | |
| 618 | + return view! { | |
| 619 | + cx => | |
| 620 | + <span class=(class!("field-box", "detail-overdue" if overdue))> | |
| 621 | + <span class="field-text">(label)</span> | |
| 622 | + </span> | |
| 623 | + }; | |
| 624 | + } | |
| 625 | + let toggle = format!("deadline-{}", task.id); | |
| 626 | + let input_value = task.deadline_input(); | |
| 627 | + view! { | |
| 628 | + cx => | |
| 629 | + <div class="edit edit-pop"> | |
| 630 | + <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label="Change the deadline"> | |
| 631 | + <label class=(class!("field-box", "edit-view", "edit-hit", "detail-overdue" if overdue)) for=(toggle.clone())> | |
| 632 | + <span class="field-text">(label)</span> | |
| 633 | + </label> | |
| 634 | + <div class="edit-form pop-panel datepick-panel"> | |
| 635 | + <form class="pop-form" method="post" action="/api/save_task"> | |
| 636 | + <input type="hidden" name="task_id" value=(task.id.clone())> | |
| 637 | + <input class="field-input" type="date" name="deadline" value=(input_value)> | |
| 638 | + <div class="edit-row"> | |
| 639 | + <button class="edit-save" type="submit">"Save"</button> | |
| 640 | + <label class="edit-cancel" for=(toggle)>"Cancel"</label> | |
| 641 | + </div> | |
| 642 | + </form> | |
| 643 | + (refused(cx, "save_task").await?) | |
| 644 | + </div> | |
| 645 | + </div> | |
| 646 | + } | |
| 647 | +} | |
| 648 | + | |
| 649 | +async fn assignee_chip(cx: &Cx, task_id: &str, person: &Person, may_write: bool) -> Result { | |
| 650 | + let remove_title = format!("Take {} off this task", person.display_name); | |
| 651 | + view! { | |
| 652 | + cx => | |
| 653 | + <span class="assignee-chip" title=(person.display_name.clone())> | |
| 654 | + (avatar(cx, person, "avatar-sm").await?) | |
| 655 | + <span class="assignee-name">(person.display_name.clone())</span> | |
| 656 | + if may_write { | |
| 657 | + <form class="assignee-drop" method="post" action="/api/unassign"> | |
| 658 | + <input type="hidden" name="task_id" value=(task_id.to_string())> | |
| 659 | + <input type="hidden" name="user_id" value=(person.id.clone())> | |
| 660 | + <button class="assignee-remove" type="submit" title=(remove_title)>"×"</button> | |
| 661 | + </form> | |
| 662 | + } | |
| 663 | + </span> | |
| 664 | + } | |
| 665 | +} | |
| 666 | + | |
| 667 | +async fn assignee_picker(cx: &Cx, task_id: &str, people: &[Person]) -> Result { | |
| 668 | + if people.is_empty() { | |
| 669 | + return view! { cx => }; | |
| 670 | + } | |
| 671 | + let toggle = format!("assign-{task_id}"); | |
| 672 | + view! { | |
| 673 | + cx => | |
| 674 | + <div class="edit edit-pop assignee-pop"> | |
| 675 | + <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label="Put someone on this task"> | |
| 676 | + <label class="assignee-add edit-view edit-hit" for=(toggle.clone())>"+"</label> | |
| 677 | + <div class="edit-form pop-panel"> | |
| 678 | + <div class="pop-list"> | |
| 679 | + for person in people { | |
| 680 | + <form class="pop-row-form" method="post" action="/api/assign"> | |
| 681 | + <input type="hidden" name="task_id" value=(task_id.to_string())> | |
| 682 | + <input type="hidden" name="user_id" value=(person.id.clone())> | |
| 683 | + <button class="pop-row" type="submit"> | |
| 684 | + (avatar(cx, person, "avatar-sm").await?) | |
| 685 | + <span class="pop-row-name">(person.display_name.clone())</span> | |
| 686 | + </button> | |
| 687 | + </form> | |
| 688 | + } | |
| 689 | + </div> | |
| 690 | + (refused(cx, "assign").await?) | |
| 691 | + </div> | |
| 692 | + </div> | |
| 693 | + } | |
| 694 | +} | |
| 695 | + | |
| 696 | +async fn link_picker(cx: &Cx, task_id: &str, linkable: &[LinkTarget]) -> Result { | |
| 697 | + if linkable.is_empty() { | |
| 698 | + return view! { cx => }; | |
| 699 | + } | |
| 700 | + let toggle = format!("link-{task_id}"); | |
| 701 | + view! { | |
| 702 | + cx => | |
| 703 | + <div class="edit edit-pop link-pop"> | |
| 704 | + <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label="Link another task"> | |
| 705 | + <label class="dep-chip edit-view edit-hit" for=(toggle.clone())> | |
| 706 | + <span class="dep-chip-text">"Link a task"</span> | |
| 707 | + </label> | |
| 708 | + <div class="edit-form pop-panel pop-panel-wide"> | |
| 709 | + <form class="pop-form" method="post" action="/api/link_tasks"> | |
| 710 | + <input type="hidden" name="task_id" value=(task_id.to_string())> | |
| 711 | + <div class="pop-list pop-list-scroll"> | |
| 712 | + for target in linkable { | |
| 713 | + <label class="pick-row"> | |
| 714 | + <input type="radio" name="other_id" value=(target.id.clone()) required=""> | |
| 715 | + <span class="dep-key">(target.task_key.clone())</span> | |
| 716 | + <span class="pick-title">(target.title.clone())</span> | |
| 717 | + </label> | |
| 718 | + } | |
| 719 | + </div> | |
| 720 | + <fieldset class="pick-direction"> | |
| 721 | + <legend class="detail-label">"DIRECTION"</legend> | |
| 722 | + <label class="pick-row"> | |
| 723 | + <input type="radio" name="direction" value="blocked_by" checked=""> | |
| 724 | + <span class="pick-title">"blocks this task"</span> | |
| 725 | + </label> | |
| 726 | + <label class="pick-row"> | |
| 727 | + <input type="radio" name="direction" value="blocks"> | |
| 728 | + <span class="pick-title">"waits on this task"</span> | |
| 729 | + </label> | |
| 730 | + </fieldset> | |
| 731 | + <div class="edit-row"> | |
| 732 | + <button class="edit-save" type="submit">"Link"</button> | |
| 733 | + <label class="edit-cancel" for=(toggle)>"Cancel"</label> | |
| 734 | + </div> | |
| 735 | + </form> | |
| 736 | + (refused(cx, "link_tasks").await?) | |
| 737 | + </div> | |
| 738 | + </div> | |
| 739 | + } | |
| 740 | +} | |
| 741 | + | |
| 742 | +async fn dep_row(cx: &Cx, task_id: &str, edge: &DependencyEdge, direction: Direction, may_write: bool) -> Result { | |
| 743 | + let cleared = edge.is_cleared(); | |
| 744 | + let note = match direction { | |
| 745 | + Direction::BlockedBy => edge.blocked_by_label(), | |
| 746 | + Direction::Blocks => edge.blocks_label(), | |
| 747 | + }; | |
| 748 | + let waiting = matches!(direction, Direction::BlockedBy) && !cleared; | |
| 749 | + let wire = match direction { | |
| 750 | + Direction::BlockedBy => "blocked_by", | |
| 751 | + Direction::Blocks => "blocks", | |
| 752 | + }; | |
| 753 | + let tag = match direction { | |
| 754 | + Direction::BlockedBy => "BLOCKED BY", | |
| 755 | + Direction::Blocks => "BLOCKS", | |
| 756 | + }; | |
| 757 | + view! { | |
| 758 | + cx => | |
| 759 | + <div class=(class!("dep-row", "dep-row-waiting" if waiting))> | |
| 760 | + <span class="dep-tag">(tag)</span> | |
| 761 | + <span class="dep-key">(edge.task_key.clone())</span> | |
| 762 | + <span class="dep-title">(edge.title.clone())</span> | |
| 763 | + <div class="spacer"></div> | |
| 764 | + <span class="dep-note">(note)</span> | |
| 765 | + if may_write { | |
| 766 | + <form class="dep-unlink-form" method="post" action="/api/unlink_tasks"> | |
| 767 | + <input type="hidden" name="task_id" value=(task_id.to_string())> | |
| 768 | + <input type="hidden" name="other_id" value=(edge.task_id.clone())> | |
| 769 | + <input type="hidden" name="direction" value=(wire)> | |
| 770 | + <button class="dep-unlink" type="submit" title="Remove this link">"×"</button> | |
| 771 | + </form> | |
| 772 | + } | |
| 773 | + </div> | |
| 774 | + } | |
| 775 | +} | |
| 776 | + | |
| 777 | +async fn file_chip(cx: &Cx, file: &izlek_core::detail::FileLine, me: &Me, may_write: bool) -> Result { | |
| 778 | + let _ = may_write; | |
| 779 | + let may_drop = me.id == file.uploaded_by || me.role.can_administer(); | |
| 780 | + let on_comment = file.comment_id.is_some(); | |
| 781 | + view! { | |
| 782 | + cx => | |
| 783 | + <span class="file-chip"> | |
| 784 | + <a class="file-chip-name" href=(format!("/files/{}", file.id))>(file.name.clone())</a> | |
| 785 | + <span class="file-chip-size">(file.size_label())</span> | |
| 786 | + if on_comment { | |
| 787 | + <span class="file-chip-note">"on a comment"</span> | |
| 788 | + } | |
| 789 | + if may_drop { | |
| 790 | + <form class="file-chip-drop-form" method="post" action="/api/delete_file"> | |
| 791 | + <input type="hidden" name="file_id" value=(file.id.clone())> | |
| 792 | + <button class="file-chip-drop" type="submit" title="Remove this file">"×"</button> | |
| 793 | + </form> | |
| 794 | + } | |
| 795 | + </span> | |
| 796 | + } | |
| 797 | +} | |
| 798 | + | |
| 799 | +async fn comment_row(cx: &Cx, comment: &Comment) -> Result { | |
| 800 | + view! { | |
| 801 | + cx => | |
| 802 | + <div class="comment"> | |
| 803 | + (avatar(cx, &comment.author, "avatar-lg").await?) | |
| 804 | + <div class="comment-said"> | |
| 805 | + <div class="comment-head"> | |
| 806 | + <span class="comment-who">(comment.author.display_name.clone())</span> | |
| 807 | + <span class="comment-when">(moment_label(comment.at))</span> | |
| 808 | + </div> | |
| 809 | + <div class="comment-body">(comment.body.clone())</div> | |
| 810 | + </div> | |
| 811 | + </div> | |
| 812 | + } | |
| 813 | +} | |
| 814 | + | |
| 815 | +/// The task modal's markup: title, description, assignees, deadline, | |
| 816 | +/// dependencies, files, comments, activity and delete, exactly as the | |
| 817 | +/// artboard draws them. Wiring `?task=<id>` on the board page is a later | |
| 818 | +/// integration slice — this only renders the fragment. | |
| 819 | +pub async fn task_modal(cx: &Cx, task_id: &str) -> Result { | |
| 820 | + let snapshot = match load_snapshot(cx, task_id).await? { | |
| 821 | + Ok(snapshot) => snapshot, | |
| 822 | + Err(refusal) => { | |
| 823 | + return view! { cx => <div class="modal-scrim"><div class="modal"><p class="modal-note">(refusal.message())</p></div></div> }; | |
| 824 | + } | |
| 825 | + }; | |
| 826 | + let DetailSnapshot { | |
| 827 | + detail, | |
| 828 | + me, | |
| 829 | + today, | |
| 830 | + linkable, | |
| 831 | + may_write, | |
| 832 | + may_comment, | |
| 833 | + may_delete, | |
| 834 | + allowed_file_types, | |
| 835 | + attachment_limit_mb: _, | |
| 836 | + } = snapshot; | |
| 837 | + | |
| 838 | + let unassigned: Vec<Person> = detail.unassigned().cloned().collect(); | |
| 839 | + let has_deps = !detail.blocked_by.is_empty() || !detail.blocks.is_empty(); | |
| 840 | + let accept = (!allowed_file_types.is_empty()) | |
| 841 | + .then(|| allowed_file_types.iter().map(|kind| format!(".{kind}")).collect::<Vec<_>>().join(",")) | |
| 842 | + .unwrap_or_default(); | |
| 843 | + | |
| 844 | + // The delete confirmation is computed eagerly rather than fetched on | |
| 845 | + // demand: there is no script here to hold the intermediate "did they | |
| 846 | + // click delete yet" state, so the cost is already known by the time the | |
| 847 | + // disclosure opens. | |
| 848 | + let cost = if may_delete { accounts(cx).store().deletion_cost(&detail.id).await? } else { None }; | |
| 849 | + | |
| 850 | + view! { | |
| 851 | + cx => | |
| 852 | + <div class="modal-scrim"> | |
| 853 | + <div class="modal" tabindex="-1"> | |
| 854 | + <header class="detail-head"> | |
| 855 | + <div class="detail-headline"> | |
| 856 | + <span class="detail-key">(detail.task_key.clone())</span> | |
| 857 | + (title_control(cx, &detail, may_write).await?) | |
| 858 | + </div> | |
| 859 | + <a class="detail-close" href="/" aria-label="Close this task">"×"</a> | |
| 860 | + </header> | |
| 861 | + | |
| 862 | + <div class="detail-fields"> | |
| 863 | + <div class="detail-field"> | |
| 864 | + <span class="detail-label">"STATUS"</span> | |
| 865 | + if may_write { | |
| 866 | + <form class="status-form" method="post" action="/api/move_card"> | |
| 867 | + <input type="hidden" name="task_id" value=(detail.id.clone())> | |
| 868 | + <input type="hidden" name="from_column_id" value=(detail.column.id.clone())> | |
| 869 | + <span class=(class!("status-dot", "status-dot-done" if detail.column.is_done))></span> | |
| 870 | + <select class="status-select" name="to_column_id"> | |
| 871 | + for column in &detail.columns { | |
| 872 | + <option value=(column.id.clone()) selected=(column.id == detail.column.id)>(column.name.clone())</option> | |
| 873 | + } | |
| 874 | + </select> | |
| 875 | + <button class="status-go" type="submit">"Move"</button> | |
| 876 | + </form> | |
| 877 | + } else { | |
| 878 | + <span class="field-box"> | |
| 879 | + <span class="status-dot"></span> | |
| 880 | + <span class="field-text">(detail.column.name.clone())</span> | |
| 881 | + </span> | |
| 882 | + } | |
| 883 | + (refused(cx, "move_card").await?) | |
| 884 | + </div> | |
| 885 | + <div class="detail-field"> | |
| 886 | + <span class="detail-label">(format!("ASSIGNEES — {}", detail.assignees.len()))</span> | |
| 887 | + <div class="detail-assignees"> | |
| 888 | + for person in &detail.assignees { | |
| 889 | + (assignee_chip(cx, &detail.id, person, may_write).await?) | |
| 890 | + } | |
| 891 | + <div class="spacer"></div> | |
| 892 | + if may_write { | |
| 893 | + (assignee_picker(cx, &detail.id, &unassigned).await?) | |
| 894 | + } | |
| 895 | + </div> | |
| 896 | + </div> | |
| 897 | + <div class="detail-field"> | |
| 898 | + <span class="detail-label">"DEADLINE"</span> | |
| 899 | + (deadline_control(cx, &detail, today, may_write).await?) | |
| 900 | + </div> | |
| 901 | + </div> | |
| 902 | + | |
| 903 | + <section class="detail-block"> | |
| 904 | + <span class="detail-label">"DESCRIPTION"</span> | |
| 905 | + (description_control(cx, &detail, may_write).await?) | |
| 906 | + </section> | |
| 907 | + | |
| 908 | + <section class="detail-block"> | |
| 909 | + <div class="detail-block-head"> | |
| 910 | + <span class="detail-label">"DEPENDENCIES"</span> | |
| 911 | + <div class="spacer"></div> | |
| 912 | + if may_write { | |
| 913 | + (link_picker(cx, &detail.id, &linkable).await?) | |
| 914 | + } | |
| 915 | + </div> | |
| 916 | + if has_deps { | |
| 917 | + <div class="dep-list"> | |
| 918 | + for edge in &detail.blocked_by { | |
| 919 | + (dep_row(cx, &detail.id, edge, Direction::BlockedBy, may_write).await?) | |
| 920 | + } | |
| 921 | + for edge in &detail.blocks { | |
| 922 | + (dep_row(cx, &detail.id, edge, Direction::Blocks, may_write).await?) | |
| 923 | + } | |
| 924 | + </div> | |
| 925 | + } else { | |
| 926 | + <p class="detail-quiet">"Nothing blocks this task."</p> | |
| 927 | + } | |
| 928 | + </section> | |
| 929 | + | |
| 930 | + <section class="detail-block"> | |
| 931 | + <div class="detail-block-head"> | |
| 932 | + <span class="detail-label">"FILES"</span> | |
| 933 | + <span class="detail-count">(detail.files.len())</span> | |
| 934 | + </div> | |
| 935 | + if detail.files.is_empty() { | |
| 936 | + <p class="detail-quiet">"No files yet."</p> | |
| 937 | + } else { | |
| 938 | + <div class="file-list"> | |
| 939 | + for file in &detail.files { | |
| 940 | + (file_chip(cx, file, &me, may_write).await?) | |
| 941 | + } | |
| 942 | + </div> | |
| 943 | + } | |
| 944 | + (refused(cx, "delete_file").await?) | |
| 945 | + if may_comment { | |
| 946 | + <form class="file-upload" method="post" action="/files" enctype="multipart/form-data"> | |
| 947 | + <input type="hidden" name="task_id" value=(detail.id.clone())> | |
| 948 | + <input class="field-input" type="file" name="file" accept=(accept) required=""> | |
| 949 | + <button class="file-upload-submit" type="submit">"Attach"</button> | |
| 950 | + </form> | |
| 951 | + (refused(cx, "upload_file").await?) | |
| 952 | + } | |
| 953 | + </section> | |
| 954 | + | |
| 955 | + <section class="detail-block"> | |
| 956 | + <div class="detail-block-head"> | |
| 957 | + <span class="detail-label">"COMMENTS"</span> | |
| 958 | + <span class="detail-count">(detail.comments.len())</span> | |
| 959 | + </div> | |
| 960 | + <div class="comment-list"> | |
| 961 | + for entry in &detail.comments { | |
| 962 | + (comment_row(cx, entry).await?) | |
| 963 | + } | |
| 964 | + if may_comment { | |
| 965 | + <form class="comment-composer" method="post" action="/api/post_comment"> | |
| 966 | + <input type="hidden" name="task_id" value=(detail.id.clone())> | |
| 967 | + <textarea class="detail-textarea comment-input" name="body" rows="3" placeholder="Write a comment…" required=""></textarea> | |
| 968 | + <div class="comment-row"> | |
| 969 | + <div class="spacer"></div> | |
| 970 | + <button class="comment-post" type="submit">"Comment"</button> | |
| 971 | + </div> | |
| 972 | + </form> | |
| 973 | + (refused(cx, "post_comment").await?) | |
| 974 | + } | |
| 975 | + </div> | |
| 976 | + </section> | |
| 977 | + | |
| 978 | + <section class="detail-block"> | |
| 979 | + <span class="detail-label">"ACTIVITY"</span> | |
| 980 | + <div class="activity-list"> | |
| 981 | + for entry in &detail.activity { | |
| 982 | + <div class="activity-line"> | |
| 983 | + <span class="activity-stamp">(entry.moment())</span> | |
| 984 | + <strong class="activity-who">(entry.actor.as_ref().map(|person| person.display_name.clone()).unwrap_or_else(|| "Izlek".to_string()))</strong> | |
| 985 | + <span class="activity-what">(entry.sentence())</span> | |
| 986 | + </div> | |
| 987 | + } | |
| 988 | + </div> | |
| 989 | + </section> | |
| 990 | + | |
| 991 | + (refused(cx, "delete_task").await?) | |
| 992 | + | |
| 993 | + <footer class="detail-foot"> | |
| 994 | + if may_delete { | |
| 995 | + match cost { | |
| 996 | + Some(cost) => { | |
| 997 | + let freed = cost.frees.join(", "); | |
| 998 | + <details class="confirm-details"> | |
| 999 | + <summary class="detail-delete">"Delete task"</summary> | |
| 1000 | + <div class="confirm"> | |
| 1001 | + <div class="confirm-title">(format!("Delete {} — {}?", cost.task_key, cost.title))</div> | |
| 1002 | + <ul class="confirm-list"> | |
| 1003 | + if cost.comment_count > 0 { | |
| 1004 | + <li>(if cost.comment_count == 1 { "1 comment goes with it".to_string() } else { format!("{} comments go with it", cost.comment_count) })</li> | |
| 1005 | + } | |
| 1006 | + if cost.link_count > 0 { | |
| 1007 | + <li>(if cost.link_count == 1 { "1 dependency stops applying".to_string() } else { format!("{} dependencies stop applying", cost.link_count) })</li> | |
| 1008 | + } | |
| 1009 | + if !freed.is_empty() { | |
| 1010 | + <li>(format!("{freed} stops being blocked"))</li> | |
| 1011 | + } | |
| 1012 | + </ul> | |
| 1013 | + <div class="confirm-note">"The task keeps its record in the database, but nothing in Izlek brings it back."</div> | |
| 1014 | + <form class="detail-delete-form" method="post" action="/api/delete_task"> | |
| 1015 | + <input type="hidden" name="task_id" value=(detail.id.clone())> | |
| 1016 | + <button class="detail-delete detail-delete-sure" type="submit">(format!("Delete {}", cost.task_key))</button> | |
| 1017 | + </form> | |
| 1018 | + </div> | |
| 1019 | + </details> | |
| 1020 | + }, | |
| 1021 | + None => <p class="detail-quiet">"This task cannot be deleted."</p>, | |
| 1022 | + } | |
| 1023 | + } | |
| 1024 | + <div class="spacer"></div> | |
| 1025 | + <a class="detail-cancel" href="/">"Close"</a> | |
| 1026 | + </footer> | |
| 1027 | + </div> | |
| 1028 | + </div> | |
| 1029 | + } | |
| 1030 | +} |