| 1 | //! Ponos-bord in het hoofdpaneel: de tegel «Ponos» in de navigatierail, direct |
| 2 | //! onder Agents (Tim). Links alle groepen die je in Ponos ziet (eerst |
| 3 | //! «Mijn Taken», je persoonlijke groep), rechts het bord met de kolommen van |
| 4 | //! Ponos. Taken maken, bewerken, afronden en slepen tussen en binnen kolommen. |
| 5 | //! |
| 6 | //! Upstream-haken: `views/rail.rs` (tegel), `views/sidebar.rs` (`SidebarTab::Ponos`), |
| 7 | //! `views/shell.rs` (hoofdpaneel). Zie KVT-FORK.md. |
| 8 | |
| 9 | use std::collections::HashMap; |
| 10 | |
| 11 | use gpui_kit::component::input::{Input, InputState, Textarea, TextareaState}; |
| 12 | use gpui_kit::component::scroll::ScrollableElement as _; |
| 13 | use gpui_kit::component::{h_flex, v_flex}; |
| 14 | use gpui_kit::prelude::FluentBuilder as _; |
| 15 | use gpui_kit::*; |
| 16 | use kvt_sleutels::format::{iso_date_nl, parse_date_input}; |
| 17 | use kvt_sleutels::ponos::{ |
| 18 | MY_TASKS_GROUP, PonosGroup, PonosNavigation, PonosTask, STATUS_DONE, STATUSES, TaskInput, |
| 19 | apply_move, column, drop_position, group_url, name_from_email, |
| 20 | }; |
| 21 | use kvt_sleutels::{CardsClient, ClientError}; |
| 22 | |
| 23 | use super::modal::{primary_button, secondary_button}; |
| 24 | use super::tasks::{chip, field, label, muted, not_linked, ponos_error}; |
| 25 | use super::{Link, base_url, forget_token, is_demo, link, notice, open_external, token_and_client}; |
| 26 | use crate::app_state::AppHandle; |
| 27 | use crate::i18n::tr; |
| 28 | use crate::runtime; |
| 29 | use crate::theme::{self, ElevatedSurface as _}; |
| 30 | use crate::views::widgets::symbol; |
| 31 | |
| 32 | pub const KVT_BOARD_TAG: &str = "kvt-ponos-board"; |
| 33 | /// Laatst gekozen groep op het bord (alleen een id, in de lokale opslag). |
| 34 | const BOARD_GROUP_META_KEY: &str = "kvt.ponos.board_group"; |
| 35 | const TITLE_MAX: usize = 200; |
| 36 | const HEADER_HEIGHT: f32 = 60.; |
| 37 | const PAGE_PADDING: f32 = 20.; |
| 38 | const GROUPS_WIDTH: f32 = 240.; |
| 39 | const GROUP_ROW_HEIGHT: f32 = 36.; |
| 40 | const COLUMN_MIN_WIDTH: f32 = 220.; |
| 41 | const COLUMN_GAP: f32 = 12.; |
| 42 | const CARD_GAP: f32 = 8.; |
| 43 | const RADIUS: f32 = 10.; |
| 44 | const EDITOR_WIDTH: f32 = 560.; |
| 45 | const BACKDROP_OPACITY: f32 = 0.55; |
| 46 | |
| 47 | #[derive(Clone)] |
| 48 | enum Nav { |
| 49 | NotLinked, |
| 50 | Loading, |
| 51 | Loaded(PonosNavigation), |
| 52 | Failed(ClientError), |
| 53 | } |
| 54 | |
| 55 | #[derive(Clone)] |
| 56 | enum Tasks { |
| 57 | Loading, |
| 58 | Loaded(Vec<PonosTask>), |
| 59 | Failed(ClientError), |
| 60 | } |
| 61 | |
| 62 | #[derive(Clone)] |
| 63 | struct DraggedTask { |
| 64 | id: String, |
| 65 | title: String, |
| 66 | from_status: String, |
| 67 | } |
| 68 | |
| 69 | struct TaskGhost { |
| 70 | title: String, |
| 71 | } |
| 72 | |
| 73 | impl Render for TaskGhost { |
| 74 | fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement { |
| 75 | div() |
| 76 | .w(px(COLUMN_MIN_WIDTH)) |
| 77 | .px(px(12.)) |
| 78 | .py(px(10.)) |
| 79 | .rounded(px(8.)) |
| 80 | .flyout_surface() |
| 81 | .text_size(px(13.)) |
| 82 | .text_color(theme::text()) |
| 83 | .truncate() |
| 84 | .child(self.title.clone()) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | struct Editor { |
| 89 | /// `None`: nieuwe taak. |
| 90 | task: Option<PonosTask>, |
| 91 | status: String, |
| 92 | assignee: String, |
| 93 | target_group: Option<String>, |
| 94 | title: Entity<InputState>, |
| 95 | description: Entity<TextareaState>, |
| 96 | due: Entity<InputState>, |
| 97 | saving: bool, |
| 98 | error: Option<String>, |
| 99 | } |
| 100 | |
| 101 | pub struct PonosBoard { |
| 102 | nav: Nav, |
| 103 | group: Option<String>, |
| 104 | tasks: Tasks, |
| 105 | generation: u64, |
| 106 | editor: Option<Editor>, |
| 107 | /// Alleen `--demo`: verzonnen taken per groep. |
| 108 | demo: HashMap<String, Vec<PonosTask>>, |
| 109 | } |
| 110 | |
| 111 | /// Het bord als element van het hoofdpaneel (eenmalig aangemaakt). |
| 112 | pub fn board_view(cx: &mut App) -> AnyElement { |
| 113 | let existing = super::read(cx, |kvt| kvt.board.clone()).flatten(); |
| 114 | let board = match existing { |
| 115 | Some(board) => board, |
| 116 | None => { |
| 117 | let board = cx.new(PonosBoard::new); |
| 118 | if cx.has_global::<super::Kvt>() { |
| 119 | cx.global_mut::<super::Kvt>().board = Some(board.clone()); |
| 120 | } |
| 121 | board |
| 122 | } |
| 123 | }; |
| 124 | div() |
| 125 | .flex_1() |
| 126 | .min_w_0() |
| 127 | .h_full() |
| 128 | .child(board) |
| 129 | .into_any_element() |
| 130 | } |
| 131 | |
| 132 | /// De tegel is geopend: vers ophalen (bij de eerste keer laadt `new`). |
| 133 | pub fn board_opened(cx: &mut App) { |
| 134 | if let Some(board) = super::read(cx, |kvt| kvt.board.clone()).flatten() { |
| 135 | board.update(cx, |board, cx| board.reload(cx)); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /// Na «Taak maken in Ponos» vanuit een bericht. |
| 140 | pub(super) fn refresh_board_if_open(cx: &mut App) { |
| 141 | board_opened(cx); |
| 142 | } |
| 143 | |
| 144 | fn remembered_group(cx: &App) -> Option<String> { |
| 145 | let handle = cx.try_global::<AppHandle>()?; |
| 146 | handle |
| 147 | .0 |
| 148 | .read(cx) |
| 149 | .store |
| 150 | .meta(BOARD_GROUP_META_KEY) |
| 151 | .ok() |
| 152 | .flatten() |
| 153 | } |
| 154 | |
| 155 | fn remember_group(group: &str, cx: &App) { |
| 156 | if let Some(handle) = cx.try_global::<AppHandle>() { |
| 157 | let _ = handle |
| 158 | .0 |
| 159 | .read(cx) |
| 160 | .store |
| 161 | .set_meta(BOARD_GROUP_META_KEY, group); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /// Gekozen groep als die nog bestaat, anders de eerste (Mijn Taken). |
| 166 | fn pick_group(wanted: Option<&str>, navigation: &PonosNavigation) -> Option<String> { |
| 167 | wanted |
| 168 | .filter(|wanted| navigation.groups.iter().any(|group| group.id == *wanted)) |
| 169 | .map(str::to_owned) |
| 170 | .or_else(|| navigation.groups.first().map(|group| group.id.clone())) |
| 171 | } |
| 172 | |
| 173 | fn status_fallback(status: &str) -> String { |
| 174 | tr(match status { |
| 175 | "in_progress" => "kvt.board_status.in_progress", |
| 176 | STATUS_DONE => "kvt.board_status.done", |
| 177 | _ => "kvt.board_status.todo", |
| 178 | }) |
| 179 | } |
| 180 | |
| 181 | impl PonosBoard { |
| 182 | fn new(cx: &mut Context<Self>) -> Self { |
| 183 | let demo = if is_demo(cx) { |
| 184 | super::demo::board_tasks() |
| 185 | } else { |
| 186 | HashMap::new() |
| 187 | }; |
| 188 | let mut board = PonosBoard { |
| 189 | nav: Nav::Loading, |
| 190 | group: remembered_group(cx), |
| 191 | tasks: Tasks::Loading, |
| 192 | generation: 0, |
| 193 | editor: None, |
| 194 | demo, |
| 195 | }; |
| 196 | board.reload(cx); |
| 197 | board |
| 198 | } |
| 199 | |
| 200 | fn navigation(&self) -> Option<&PonosNavigation> { |
| 201 | match &self.nav { |
| 202 | Nav::Loaded(navigation) => Some(navigation), |
| 203 | _ => None, |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | fn current_group(&self) -> Option<&PonosGroup> { |
| 208 | let group = self.group.as_deref()?; |
| 209 | self.navigation()? |
| 210 | .groups |
| 211 | .iter() |
| 212 | .find(|candidate| candidate.id == group) |
| 213 | } |
| 214 | |
| 215 | fn user_email(&self) -> String { |
| 216 | self.navigation() |
| 217 | .map(|navigation| navigation.user_email.clone()) |
| 218 | .unwrap_or_default() |
| 219 | } |
| 220 | |
| 221 | fn status_label(&self, status: &str) -> String { |
| 222 | match self.navigation() { |
| 223 | Some(navigation) => navigation.status_label(status, || status_fallback(status)), |
| 224 | None => status_fallback(status), |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // --- laden ------------------------------------------------------------ |
| 229 | |
| 230 | fn reload(&mut self, cx: &mut Context<Self>) { |
| 231 | self.generation += 1; |
| 232 | if is_demo(cx) { |
| 233 | let navigation = super::demo::board_navigation(&self.demo); |
| 234 | self.group = pick_group(self.group.as_deref(), &navigation); |
| 235 | self.tasks = Tasks::Loaded(self.demo_tasks()); |
| 236 | self.nav = Nav::Loaded(navigation); |
| 237 | cx.notify(); |
| 238 | return; |
| 239 | } |
| 240 | let Some((token, client)) = token_and_client(cx) else { |
| 241 | self.nav = Nav::NotLinked; |
| 242 | cx.notify(); |
| 243 | return; |
| 244 | }; |
| 245 | if !matches!(self.nav, Nav::Loaded(_)) { |
| 246 | self.nav = Nav::Loading; |
| 247 | } |
| 248 | let generation = self.generation; |
| 249 | let wanted = self.group.clone(); |
| 250 | let loading = runtime::spawn(async move { |
| 251 | let navigation = client.ponos_navigation(&token).await?; |
| 252 | let group = pick_group(wanted.as_deref(), &navigation); |
| 253 | let tasks = match &group { |
| 254 | Some(group) => client.ponos_tasks(&token, group).await, |
| 255 | None => Ok(Vec::new()), |
| 256 | }; |
| 257 | Ok::<_, ClientError>((navigation, group, tasks)) |
| 258 | }); |
| 259 | cx.spawn(async move |this, cx| { |
| 260 | let result = loading.await.unwrap_or(Err(ClientError::Unavailable)); |
| 261 | cx.update(|cx| { |
| 262 | let unauthorized = matches!(&result, Err(ClientError::Unauthorized)) |
| 263 | || matches!(&result, Ok((_, _, Err(ClientError::Unauthorized)))); |
| 264 | if unauthorized { |
| 265 | forget_token(cx); |
| 266 | } |
| 267 | this.update(cx, |this, cx| { |
| 268 | if this.generation != generation { |
| 269 | return; |
| 270 | } |
| 271 | match result { |
| 272 | Ok((navigation, group, tasks)) => { |
| 273 | this.group = group; |
| 274 | this.tasks = match tasks { |
| 275 | Ok(tasks) => Tasks::Loaded(tasks), |
| 276 | Err(error) => Tasks::Failed(error), |
| 277 | }; |
| 278 | this.nav = Nav::Loaded(navigation); |
| 279 | } |
| 280 | Err(error) => this.nav = Nav::Failed(error), |
| 281 | } |
| 282 | cx.notify(); |
| 283 | }) |
| 284 | .ok(); |
| 285 | }); |
| 286 | }) |
| 287 | .detach(); |
| 288 | } |
| 289 | |
| 290 | fn select_group(&mut self, group: String, cx: &mut Context<Self>) { |
| 291 | if self.group.as_deref() == Some(group.as_str()) { |
| 292 | return; |
| 293 | } |
| 294 | remember_group(&group, cx); |
| 295 | self.group = Some(group); |
| 296 | self.tasks = Tasks::Loading; |
| 297 | self.editor = None; |
| 298 | self.reload(cx); |
| 299 | } |
| 300 | |
| 301 | // --- demo ------------------------------------------------------------- |
| 302 | |
| 303 | fn demo_tasks(&self) -> Vec<PonosTask> { |
| 304 | let Some(group) = self.group.as_deref() else { |
| 305 | return Vec::new(); |
| 306 | }; |
| 307 | if group == MY_TASKS_GROUP { |
| 308 | let mut mine: Vec<PonosTask> = self |
| 309 | .demo |
| 310 | .values() |
| 311 | .flatten() |
| 312 | .filter(|task| task.assignee_email == super::demo::BOARD_USER) |
| 313 | .cloned() |
| 314 | .collect(); |
| 315 | mine.sort_by(|a, b| a.id.cmp(&b.id)); |
| 316 | return mine; |
| 317 | } |
| 318 | self.demo.get(group).cloned().unwrap_or_default() |
| 319 | } |
| 320 | |
| 321 | fn demo_task_mut(&mut self, id: &str) -> Option<&mut PonosTask> { |
| 322 | self.demo.values_mut().flatten().find(|task| task.id == id) |
| 323 | } |
| 324 | |
| 325 | // --- acties ----------------------------------------------------------- |
| 326 | |
| 327 | /// Een schrijfactie bij Ponos; daarna altijd opnieuw laden. |
| 328 | fn submit<Fut>( |
| 329 | &mut self, |
| 330 | cx: &mut Context<Self>, |
| 331 | done: Option<String>, |
| 332 | job: impl FnOnce(String, CardsClient) -> Fut, |
| 333 | ) where |
| 334 | Fut: std::future::Future<Output = Result<(), ClientError>> + Send + 'static, |
| 335 | { |
| 336 | let Some((token, client)) = token_and_client(cx) else { |
| 337 | self.reload(cx); |
| 338 | return; |
| 339 | }; |
| 340 | let running = runtime::spawn(job(token, client)); |
| 341 | cx.spawn(async move |this, cx| { |
| 342 | let result = running.await.unwrap_or(Err(ClientError::Unavailable)); |
| 343 | cx.update(|cx| { |
| 344 | match &result { |
| 345 | Ok(()) => { |
| 346 | if let Some(done) = done { |
| 347 | notice(done, cx); |
| 348 | } |
| 349 | } |
| 350 | Err(error) => { |
| 351 | if *error == ClientError::Unauthorized { |
| 352 | forget_token(cx); |
| 353 | } |
| 354 | notice(ponos_error(error), cx); |
| 355 | } |
| 356 | } |
| 357 | this.update(cx, |this, cx| { |
| 358 | if result.is_ok() { |
| 359 | this.editor = None; |
| 360 | } else if let Some(editor) = this.editor.as_mut() { |
| 361 | editor.saving = false; |
| 362 | } |
| 363 | this.reload(cx); |
| 364 | }) |
| 365 | .ok(); |
| 366 | }); |
| 367 | }) |
| 368 | .detach(); |
| 369 | } |
| 370 | |
| 371 | fn drop_task( |
| 372 | &mut self, |
| 373 | dragged: &DraggedTask, |
| 374 | status: &'static str, |
| 375 | before: Option<usize>, |
| 376 | cx: &mut Context<Self>, |
| 377 | ) { |
| 378 | let Some(group) = self.group.clone() else { |
| 379 | return; |
| 380 | }; |
| 381 | let Tasks::Loaded(tasks) = &mut self.tasks else { |
| 382 | return; |
| 383 | }; |
| 384 | let position = drop_position(tasks, &dragged.id, status, before); |
| 385 | let unchanged = dragged.from_status == status |
| 386 | && column(tasks, status).position(|task| task.id == dragged.id) == Some(position); |
| 387 | if unchanged || !apply_move(tasks, &dragged.id, status, position) { |
| 388 | return; |
| 389 | } |
| 390 | cx.notify(); |
| 391 | let id = dragged.id.clone(); |
| 392 | if is_demo(cx) { |
| 393 | if let Some(task) = self.demo_task_mut(&id) { |
| 394 | task.status = status.to_owned(); |
| 395 | } |
| 396 | if group != MY_TASKS_GROUP |
| 397 | && let Some(list) = self.demo.get_mut(&group) |
| 398 | { |
| 399 | apply_move(list, &id, status, position); |
| 400 | } |
| 401 | return; |
| 402 | } |
| 403 | let virtual_group = group == MY_TASKS_GROUP; |
| 404 | let status_changed = dragged.from_status != status; |
| 405 | if virtual_group && !status_changed { |
| 406 | // «Mijn Taken» heeft geen eigen volgorde in Ponos. |
| 407 | return; |
| 408 | } |
| 409 | self.submit(cx, None, move |token, client| async move { |
| 410 | if virtual_group { |
| 411 | client.ponos_set_status(&token, &group, &id, status).await?; |
| 412 | } else { |
| 413 | client |
| 414 | .ponos_reorder_task(&token, &group, &id, status, position) |
| 415 | .await?; |
| 416 | } |
| 417 | Ok(()) |
| 418 | }); |
| 419 | } |
| 420 | |
| 421 | fn open_editor( |
| 422 | &mut self, |
| 423 | task: Option<PonosTask>, |
| 424 | status: &str, |
| 425 | window: &mut Window, |
| 426 | cx: &mut Context<Self>, |
| 427 | ) { |
| 428 | let (title_text, description_text, due_text) = match &task { |
| 429 | Some(task) => ( |
| 430 | task.title.clone(), |
| 431 | task.description.clone(), |
| 432 | iso_date_nl(&task.due_date).unwrap_or_default(), |
| 433 | ), |
| 434 | None => Default::default(), |
| 435 | }; |
| 436 | let title = cx.new(|cx| { |
| 437 | InputState::new(window, cx) |
| 438 | .placeholder(tr("kvt.ponos.title")) |
| 439 | .default_value(title_text) |
| 440 | }); |
| 441 | let description = cx.new(|cx| { |
| 442 | TextareaState::new(window, cx) |
| 443 | .auto_grow(4, 10) |
| 444 | .placeholder(tr("kvt.ponos.description")) |
| 445 | .default_value(description_text) |
| 446 | }); |
| 447 | let due = cx.new(|cx| { |
| 448 | InputState::new(window, cx) |
| 449 | .placeholder(tr("kvt.board.due_placeholder")) |
| 450 | .default_value(due_text) |
| 451 | }); |
| 452 | title.update(cx, |input, cx| input.focus(window, cx)); |
| 453 | let assignee = match &task { |
| 454 | Some(task) => task.assignee_email.clone(), |
| 455 | // Nieuw in «Mijn Taken» kan niet; elders standaard niemand. |
| 456 | None => String::new(), |
| 457 | }; |
| 458 | self.editor = Some(Editor { |
| 459 | status: task |
| 460 | .as_ref() |
| 461 | .map_or_else(|| status.to_owned(), |task| task.status.clone()), |
| 462 | assignee, |
| 463 | target_group: None, |
| 464 | task, |
| 465 | title, |
| 466 | description, |
| 467 | due, |
| 468 | saving: false, |
| 469 | error: None, |
| 470 | }); |
| 471 | cx.notify(); |
| 472 | } |
| 473 | |
| 474 | fn save_editor(&mut self, cx: &mut Context<Self>) { |
| 475 | let Some(group) = self.group.clone() else { |
| 476 | return; |
| 477 | }; |
| 478 | let Some(editor) = self.editor.as_mut() else { |
| 479 | return; |
| 480 | }; |
| 481 | if editor.saving { |
| 482 | return; |
| 483 | } |
| 484 | let title: String = editor |
| 485 | .title |
| 486 | .read(cx) |
| 487 | .value() |
| 488 | .trim() |
| 489 | .chars() |
| 490 | .take(TITLE_MAX) |
| 491 | .collect(); |
| 492 | let description = editor.description.read(cx).value().trim().to_owned(); |
| 493 | if title.is_empty() || description.is_empty() { |
| 494 | editor.error = Some(tr("kvt.ponos.fill_in")); |
| 495 | cx.notify(); |
| 496 | return; |
| 497 | } |
| 498 | let Some(due_date) = parse_date_input(&editor.due.read(cx).value()) else { |
| 499 | editor.error = Some(tr("kvt.board.bad_date")); |
| 500 | cx.notify(); |
| 501 | return; |
| 502 | }; |
| 503 | let input = TaskInput { |
| 504 | title, |
| 505 | description, |
| 506 | due_date, |
| 507 | assignee_email: editor.assignee.clone(), |
| 508 | target_group: editor.target_group.clone(), |
| 509 | }; |
| 510 | let status = editor.status.clone(); |
| 511 | let existing = editor.task.clone(); |
| 512 | editor.saving = true; |
| 513 | editor.error = None; |
| 514 | cx.notify(); |
| 515 | |
| 516 | if is_demo(cx) { |
| 517 | self.save_demo(&group, existing, input, status); |
| 518 | self.editor = None; |
| 519 | notice(tr("kvt.board.saved"), cx); |
| 520 | self.reload(cx); |
| 521 | return; |
| 522 | } |
| 523 | let done = tr(if existing.is_some() { |
| 524 | "kvt.board.saved" |
| 525 | } else { |
| 526 | "kvt.ponos.created" |
| 527 | }); |
| 528 | self.submit(cx, Some(done), move |token, client| async move { |
| 529 | match existing { |
| 530 | Some(task) => { |
| 531 | let saved = client |
| 532 | .ponos_update_task(&token, &group, &task.id, &input) |
| 533 | .await?; |
| 534 | if saved.status != status { |
| 535 | let home = input.target_group.as_deref().unwrap_or(&group); |
| 536 | client |
| 537 | .ponos_set_status(&token, home, &saved.id, &status) |
| 538 | .await?; |
| 539 | } |
| 540 | } |
| 541 | None => { |
| 542 | let created = client.ponos_create(&token, &group, &input).await?; |
| 543 | if created.status != status { |
| 544 | client |
| 545 | .ponos_set_status(&token, &group, &created.id, &status) |
| 546 | .await?; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | Ok(()) |
| 551 | }); |
| 552 | } |
| 553 | |
| 554 | fn save_demo( |
| 555 | &mut self, |
| 556 | group: &str, |
| 557 | existing: Option<PonosTask>, |
| 558 | input: TaskInput, |
| 559 | status: String, |
| 560 | ) { |
| 561 | match existing { |
| 562 | Some(task) => { |
| 563 | let home = task.group().to_owned(); |
| 564 | let Some(list) = self.demo.get_mut(&home) else { |
| 565 | return; |
| 566 | }; |
| 567 | let Some(index) = list.iter().position(|other| other.id == task.id) else { |
| 568 | return; |
| 569 | }; |
| 570 | let mut updated = list.remove(index); |
| 571 | updated.title = input.title; |
| 572 | updated.description = input.description; |
| 573 | updated.due_date = input.due_date; |
| 574 | updated.assignee_email = input.assignee_email; |
| 575 | let target = input.target_group.unwrap_or(home.clone()); |
| 576 | if target == home && updated.status == status { |
| 577 | list.insert(index, updated); |
| 578 | return; |
| 579 | } |
| 580 | updated.status = status; |
| 581 | updated.group_id = target.clone(); |
| 582 | updated.home_group_id = target.clone(); |
| 583 | self.demo.entry(target).or_default().push(updated); |
| 584 | } |
| 585 | None => { |
| 586 | let id = format!( |
| 587 | "demo-board-{}", |
| 588 | self.demo.values().map(Vec::len).sum::<usize>() + 1 |
| 589 | ); |
| 590 | let task = PonosTask { |
| 591 | id, |
| 592 | group_id: group.to_owned(), |
| 593 | home_group_id: group.to_owned(), |
| 594 | title: input.title, |
| 595 | status, |
| 596 | due_date: input.due_date, |
| 597 | description: input.description, |
| 598 | assignee_email: input.assignee_email, |
| 599 | ..super::demo::empty_task() |
| 600 | }; |
| 601 | self.demo.entry(group.to_owned()).or_default().push(task); |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | fn complete_from_editor(&mut self, cx: &mut Context<Self>) { |
| 607 | let Some(group) = self.group.clone() else { |
| 608 | return; |
| 609 | }; |
| 610 | let Some(task) = self.editor.as_ref().and_then(|editor| editor.task.clone()) else { |
| 611 | return; |
| 612 | }; |
| 613 | if is_demo(cx) { |
| 614 | if let Some(demo) = self.demo_task_mut(&task.id) { |
| 615 | demo.status = STATUS_DONE.to_owned(); |
| 616 | } |
| 617 | self.editor = None; |
| 618 | notice(tr("kvt.tasks.completed"), cx); |
| 619 | self.reload(cx); |
| 620 | return; |
| 621 | } |
| 622 | if let Some(editor) = self.editor.as_mut() { |
| 623 | editor.saving = true; |
| 624 | } |
| 625 | self.submit( |
| 626 | cx, |
| 627 | Some(tr("kvt.tasks.completed")), |
| 628 | move |token, client| async move { |
| 629 | client.ponos_complete_task(&token, &group, &task.id).await |
| 630 | }, |
| 631 | ); |
| 632 | } |
| 633 | |
| 634 | // --- weergave --------------------------------------------------------- |
| 635 | |
| 636 | fn groups_list(&self, cx: &mut Context<Self>) -> AnyElement { |
| 637 | let Some(navigation) = self.navigation() else { |
| 638 | return div().into_any_element(); |
| 639 | }; |
| 640 | v_flex() |
| 641 | .id("kvt-board-groups") |
| 642 | .w(px(GROUPS_WIDTH)) |
| 643 | .h_full() |
| 644 | .flex_none() |
| 645 | .p(px(8.)) |
| 646 | .gap(px(2.)) |
| 647 | .border_r_1() |
| 648 | .border_color(theme::border()) |
| 649 | .overflow_y_scrollbar() |
| 650 | .children(navigation.groups.iter().enumerate().map(|(index, group)| { |
| 651 | let selected = self.group.as_deref() == Some(group.id.as_str()); |
| 652 | let id = group.id.clone(); |
| 653 | h_flex() |
| 654 | .id(ElementId::Name(format!("kvt-board-group-{index}").into())) |
| 655 | .w_full() |
| 656 | .h(px(GROUP_ROW_HEIGHT)) |
| 657 | .flex_none() |
| 658 | .px(px(10.)) |
| 659 | .gap(px(8.)) |
| 660 | .items_center() |
| 661 | .rounded(px(6.)) |
| 662 | .cursor_pointer() |
| 663 | .text_size(px(13.)) |
| 664 | .map(|row| { |
| 665 | if selected { |
| 666 | row.bg(theme::selection()) |
| 667 | .text_color(theme::text_strong()) |
| 668 | .font_weight(FontWeight::SEMIBOLD) |
| 669 | } else { |
| 670 | row.text_color(theme::text()) |
| 671 | .hover(|row| row.bg(theme::row_hover())) |
| 672 | } |
| 673 | }) |
| 674 | .on_click(cx.listener(move |this, _, _, cx| this.select_group(id.clone(), cx))) |
| 675 | .child(symbol( |
| 676 | if group.is_virtual { "person" } else { "group" }, |
| 677 | 16., |
| 678 | if selected { |
| 679 | theme::accent_text() |
| 680 | } else { |
| 681 | theme::text_muted() |
| 682 | }, |
| 683 | )) |
| 684 | .child( |
| 685 | div() |
| 686 | .flex_1() |
| 687 | .min_w_0() |
| 688 | .truncate() |
| 689 | .child(group.name.clone()), |
| 690 | ) |
| 691 | .when(group.task_count > 0, |row| { |
| 692 | row.child( |
| 693 | div() |
| 694 | .flex_none() |
| 695 | .text_size(px(12.)) |
| 696 | .text_color(theme::text_muted()) |
| 697 | .child(group.task_count.to_string()), |
| 698 | ) |
| 699 | }) |
| 700 | })) |
| 701 | .into_any_element() |
| 702 | } |
| 703 | |
| 704 | fn header(&self, cx: &mut Context<Self>) -> Div { |
| 705 | let group = self.current_group(); |
| 706 | let title = group.map_or_else(|| tr("kvt.board.title"), |group| group.name.clone()); |
| 707 | let can_create = group.is_some_and(PonosGroup::accepts_new_tasks) |
| 708 | && matches!(self.tasks, Tasks::Loaded(_)); |
| 709 | let url = match self.group.as_deref() { |
| 710 | Some(group) => group_url(&base_url(), group), |
| 711 | None => format!("{}/ponos/", base_url()), |
| 712 | }; |
| 713 | h_flex() |
| 714 | .h(px(HEADER_HEIGHT)) |
| 715 | .flex_none() |
| 716 | .px(px(PAGE_PADDING)) |
| 717 | .gap(px(8.)) |
| 718 | .items_center() |
| 719 | .child( |
| 720 | div() |
| 721 | .flex_1() |
| 722 | .min_w_0() |
| 723 | .truncate() |
| 724 | .text_size(px(16.)) |
| 725 | .font_weight(FontWeight::BOLD) |
| 726 | .text_color(theme::text()) |
| 727 | .child(title), |
| 728 | ) |
| 729 | .when(can_create, |row| { |
| 730 | row.child( |
| 731 | primary_button("kvt-board-new", tr("kvt.board.new_task")).on_click( |
| 732 | cx.listener(|this, _, window, cx| { |
| 733 | this.open_editor(None, STATUSES[0], window, cx) |
| 734 | }), |
| 735 | ), |
| 736 | ) |
| 737 | }) |
| 738 | .child( |
| 739 | secondary_button("kvt-board-refresh", "refresh", tr("kvt.card.refresh")) |
| 740 | .on_click(cx.listener(|this, _, _, cx| this.reload(cx))), |
| 741 | ) |
| 742 | .child( |
| 743 | secondary_button("kvt-board-open", "open_in_new", tr("kvt.tasks.open_ponos")) |
| 744 | .on_click(move |_, _, cx| open_external(&url, cx)), |
| 745 | ) |
| 746 | } |
| 747 | |
| 748 | fn columns(&self, cx: &mut Context<Self>) -> AnyElement { |
| 749 | let tasks = match &self.tasks { |
| 750 | Tasks::Loading => { |
| 751 | return muted(tr("kvt.card.loading")) |
| 752 | .px(px(PAGE_PADDING)) |
| 753 | .into_any_element(); |
| 754 | } |
| 755 | Tasks::Failed(error) => { |
| 756 | return muted(ponos_error(error)) |
| 757 | .px(px(PAGE_PADDING)) |
| 758 | .into_any_element(); |
| 759 | } |
| 760 | Tasks::Loaded(tasks) => tasks, |
| 761 | }; |
| 762 | let group = self.current_group(); |
| 763 | let editable = group.is_some_and(PonosGroup::editable); |
| 764 | let can_create = group.is_some_and(PonosGroup::accepts_new_tasks); |
| 765 | let me = self.user_email(); |
| 766 | h_flex() |
| 767 | .id("kvt-board-columns") |
| 768 | .flex_1() |
| 769 | .min_h_0() |
| 770 | .w_full() |
| 771 | .px(px(PAGE_PADDING)) |
| 772 | .pb(px(PAGE_PADDING)) |
| 773 | .gap(px(COLUMN_GAP)) |
| 774 | .items_start() |
| 775 | .overflow_x_scrollbar() |
| 776 | .children( |
| 777 | STATUSES |
| 778 | .iter() |
| 779 | .map(|&status| self.column(tasks, status, editable, can_create, &me, cx)), |
| 780 | ) |
| 781 | .into_any_element() |
| 782 | } |
| 783 | |
| 784 | fn column( |
| 785 | &self, |
| 786 | tasks: &[PonosTask], |
| 787 | status: &'static str, |
| 788 | editable: bool, |
| 789 | can_create: bool, |
| 790 | me: &str, |
| 791 | cx: &mut Context<Self>, |
| 792 | ) -> AnyElement { |
| 793 | let cards: Vec<&PonosTask> = column(tasks, status).collect(); |
| 794 | let today = chrono::Local::now().format("%Y-%m-%d").to_string(); |
| 795 | let dot = match status { |
| 796 | "in_progress" => theme::accent(), |
| 797 | STATUS_DONE => theme::green(), |
| 798 | _ => theme::text_faint(), |
| 799 | }; |
| 800 | v_flex() |
| 801 | .id(ElementId::Name(format!("kvt-board-column-{status}").into())) |
| 802 | .debug_selector(move || format!("kvt-board/column/{status}")) |
| 803 | .flex_1() |
| 804 | .min_w(px(COLUMN_MIN_WIDTH)) |
| 805 | .h_full() |
| 806 | .p(px(10.)) |
| 807 | .gap(px(CARD_GAP)) |
| 808 | .rounded(px(RADIUS)) |
| 809 | .bg(theme::surface()) |
| 810 | .drag_over::<DraggedTask>(|style, _, _, _| style.bg(theme::drop_background())) |
| 811 | .on_drop(cx.listener(move |this, dragged: &DraggedTask, _, cx| { |
| 812 | this.drop_task(dragged, status, None, cx) |
| 813 | })) |
| 814 | .child( |
| 815 | h_flex() |
| 816 | .w_full() |
| 817 | .h(px(28.)) |
| 818 | .flex_none() |
| 819 | .gap(px(8.)) |
| 820 | .items_center() |
| 821 | .child(div().size(px(8.)).flex_none().rounded_full().bg(dot)) |
| 822 | .child( |
| 823 | div() |
| 824 | .flex_1() |
| 825 | .min_w_0() |
| 826 | .truncate() |
| 827 | .text_size(px(13.)) |
| 828 | .font_weight(FontWeight::SEMIBOLD) |
| 829 | .text_color(theme::text()) |
| 830 | .child(self.status_label(status)), |
| 831 | ) |
| 832 | .child( |
| 833 | div() |
| 834 | .text_size(px(12.)) |
| 835 | .text_color(theme::text_muted()) |
| 836 | .child(cards.len().to_string()), |
| 837 | ) |
| 838 | .when(can_create, |row| { |
| 839 | row.child( |
| 840 | div() |
| 841 | .id(ElementId::Name(format!("kvt-board-add-{status}").into())) |
| 842 | .size(px(24.)) |
| 843 | .flex_none() |
| 844 | .flex() |
| 845 | .items_center() |
| 846 | .justify_center() |
| 847 | .rounded_full() |
| 848 | .cursor_pointer() |
| 849 | .hover(|button| button.bg(theme::row_hover())) |
| 850 | .on_click(cx.listener(move |this, _, window, cx| { |
| 851 | this.open_editor(None, status, window, cx) |
| 852 | })) |
| 853 | .child(symbol("add", 16., theme::text_muted())), |
| 854 | ) |
| 855 | }), |
| 856 | ) |
| 857 | .child( |
| 858 | v_flex() |
| 859 | .id(ElementId::Name(format!("kvt-board-cards-{status}").into())) |
| 860 | .w_full() |
| 861 | .flex_1() |
| 862 | .min_h(px(80.)) |
| 863 | .gap(px(CARD_GAP)) |
| 864 | .overflow_y_scrollbar() |
| 865 | .when(cards.is_empty(), |list| { |
| 866 | list.child( |
| 867 | div() |
| 868 | .w_full() |
| 869 | .py(px(16.)) |
| 870 | .text_center() |
| 871 | .text_size(px(12.)) |
| 872 | .text_color(theme::text_faint()) |
| 873 | .child(tr("kvt.board.empty_column")), |
| 874 | ) |
| 875 | }) |
| 876 | .children(cards.iter().enumerate().map(|(index, task)| { |
| 877 | self.card(task, status, index, editable, me, &today, cx) |
| 878 | })), |
| 879 | ) |
| 880 | .into_any_element() |
| 881 | } |
| 882 | |
| 883 | #[allow(clippy::too_many_arguments)] |
| 884 | fn card( |
| 885 | &self, |
| 886 | task: &PonosTask, |
| 887 | status: &'static str, |
| 888 | index: usize, |
| 889 | editable: bool, |
| 890 | me: &str, |
| 891 | today: &str, |
| 892 | cx: &mut Context<Self>, |
| 893 | ) -> AnyElement { |
| 894 | let movable = editable && task.can_edit; |
| 895 | let overdue = |
| 896 | status != STATUS_DONE && !task.due_date.is_empty() && task.due_date.as_str() < today; |
| 897 | let due = iso_date_nl(&task.due_date); |
| 898 | let assignee = if task.assignee_email.is_empty() { |
| 899 | None |
| 900 | } else if task.assignee_email.eq_ignore_ascii_case(me) { |
| 901 | Some(tr("kvt.board.assignee_me")) |
| 902 | } else { |
| 903 | Some(name_from_email(&task.assignee_email)) |
| 904 | }; |
| 905 | let in_my_tasks = self.group.as_deref() == Some(MY_TASKS_GROUP); |
| 906 | let open = task.clone(); |
| 907 | let dragged = DraggedTask { |
| 908 | id: task.id.clone(), |
| 909 | title: task.title.clone(), |
| 910 | from_status: task.status.clone(), |
| 911 | }; |
| 912 | v_flex() |
| 913 | .id(ElementId::Name( |
| 914 | format!("kvt-board-card-{}", task.id).into(), |
| 915 | )) |
| 916 | .w_full() |
| 917 | .flex_none() |
| 918 | .px(px(12.)) |
| 919 | .py(px(10.)) |
| 920 | .gap(px(6.)) |
| 921 | .rounded(px(8.)) |
| 922 | .bg(theme::surface_raised()) |
| 923 | .cursor_pointer() |
| 924 | .hover(|card| card.bg(theme::popup_hover())) |
| 925 | .on_click(cx.listener(move |this, _, window, cx| { |
| 926 | this.open_editor(Some(open.clone()), &open.status, window, cx) |
| 927 | })) |
| 928 | .when(movable, |card| { |
| 929 | card.on_drag(dragged, |dragged, _, _, cx| { |
| 930 | let title = dragged.title.clone(); |
| 931 | cx.new(|_| TaskGhost { title }) |
| 932 | }) |
| 933 | .drag_over::<DraggedTask>(|style, _, _, _| style.bg(theme::drop_background())) |
| 934 | .on_drop(cx.listener( |
| 935 | move |this, dragged: &DraggedTask, _, cx| { |
| 936 | cx.stop_propagation(); |
| 937 | this.drop_task(dragged, status, Some(index), cx) |
| 938 | }, |
| 939 | )) |
| 940 | }) |
| 941 | .when(in_my_tasks && !task.home_group_name.is_empty(), |card| { |
| 942 | card.child( |
| 943 | div() |
| 944 | .truncate() |
| 945 | .text_size(px(11.)) |
| 946 | .text_color(theme::text_muted()) |
| 947 | .child(task.home_group_name.clone()), |
| 948 | ) |
| 949 | }) |
| 950 | .child( |
| 951 | div() |
| 952 | .text_size(px(13.)) |
| 953 | .line_height(px(18.)) |
| 954 | .text_color(if status == STATUS_DONE { |
| 955 | theme::text_muted() |
| 956 | } else { |
| 957 | theme::text() |
| 958 | }) |
| 959 | .when(status == STATUS_DONE, |text| text.line_through()) |
| 960 | .child(task.title.clone()), |
| 961 | ) |
| 962 | .child( |
| 963 | h_flex() |
| 964 | .w_full() |
| 965 | .flex_wrap() |
| 966 | .gap(px(8.)) |
| 967 | .items_center() |
| 968 | .text_size(px(11.)) |
| 969 | .text_color(theme::text_muted()) |
| 970 | .when(!task.category_label.is_empty(), |row| { |
| 971 | row.child( |
| 972 | div() |
| 973 | .px(px(6.)) |
| 974 | .py(px(1.)) |
| 975 | .rounded(px(4.)) |
| 976 | .bg(theme::selection()) |
| 977 | .text_color(theme::text_strong()) |
| 978 | .child(task.category_label.clone()), |
| 979 | ) |
| 980 | }) |
| 981 | .children(due.map(|due| { |
| 982 | h_flex() |
| 983 | .gap(px(3.)) |
| 984 | .items_center() |
| 985 | .text_color(if overdue { |
| 986 | theme::red_soft() |
| 987 | } else { |
| 988 | theme::text_muted() |
| 989 | }) |
| 990 | .child(symbol( |
| 991 | "event", |
| 992 | 12., |
| 993 | if overdue { |
| 994 | theme::red_soft() |
| 995 | } else { |
| 996 | theme::text_muted() |
| 997 | }, |
| 998 | )) |
| 999 | .child(due) |
| 1000 | })) |
| 1001 | .when(task.checklist_total > 0, |row| { |
| 1002 | row.child( |
| 1003 | h_flex() |
| 1004 | .gap(px(3.)) |
| 1005 | .items_center() |
| 1006 | .child(symbol("check", 12., theme::text_muted())) |
| 1007 | .child(format!("{}/{}", task.checklist_done, task.checklist_total)), |
| 1008 | ) |
| 1009 | }) |
| 1010 | .children(assignee.map(|assignee| { |
| 1011 | h_flex() |
| 1012 | .gap(px(3.)) |
| 1013 | .items_center() |
| 1014 | .child(symbol("person", 12., theme::text_muted())) |
| 1015 | .child(assignee) |
| 1016 | })), |
| 1017 | ) |
| 1018 | .into_any_element() |
| 1019 | } |
| 1020 | |
| 1021 | fn editor_layer(&self, cx: &mut Context<Self>) -> Option<AnyElement> { |
| 1022 | let editor = self.editor.as_ref()?; |
| 1023 | let navigation = self.navigation()?; |
| 1024 | let me = navigation.user_email.clone(); |
| 1025 | let existing = editor.task.clone(); |
| 1026 | let editable = existing.as_ref().is_none_or(|task| task.can_edit); |
| 1027 | let home = existing |
| 1028 | .as_ref() |
| 1029 | .map(|task| task.group().to_owned()) |
| 1030 | .or_else(|| self.group.clone()) |
| 1031 | .unwrap_or_default(); |
| 1032 | let target = editor.target_group.clone().unwrap_or_else(|| home.clone()); |
| 1033 | let title = tr(if existing.is_some() { |
| 1034 | "kvt.board.edit_task" |
| 1035 | } else { |
| 1036 | "kvt.ponos.dialog_title" |
| 1037 | }); |
| 1038 | let detail = existing |
| 1039 | .as_ref() |
| 1040 | .filter(|task| !task.home_group_name.is_empty()) |
| 1041 | .map(|task| task.home_group_name.clone()) |
| 1042 | .unwrap_or_default(); |
| 1043 | let url = existing.as_ref().map(|task| task.url(&base_url())); |
| 1044 | let move_groups: Vec<PonosGroup> = navigation |
| 1045 | .groups |
| 1046 | .iter() |
| 1047 | .filter(|group| !group.is_virtual && group.has_task_access) |
| 1048 | .cloned() |
| 1049 | .collect(); |
| 1050 | let other_assignee = (!editor.assignee.is_empty() |
| 1051 | && !editor.assignee.eq_ignore_ascii_case(&me)) |
| 1052 | .then(|| name_from_email(&editor.assignee)); |
| 1053 | let assignee_is_me = !me.is_empty() && editor.assignee.eq_ignore_ascii_case(&me); |
| 1054 | |
| 1055 | let status_chips = |
| 1056 | h_flex() |
| 1057 | .w_full() |
| 1058 | .flex_wrap() |
| 1059 | .gap(px(6.)) |
| 1060 | .children(STATUSES.iter().enumerate().map(|(index, &status)| { |
| 1061 | chip( |
| 1062 | format!("kvt-board-status-{index}").into(), |
| 1063 | self.status_label(status), |
| 1064 | editor.status == status, |
| 1065 | ) |
| 1066 | .on_click(cx.listener(move |this, _, _, cx| { |
| 1067 | if let Some(editor) = this.editor.as_mut() { |
| 1068 | editor.status = status.to_owned(); |
| 1069 | cx.notify(); |
| 1070 | } |
| 1071 | })) |
| 1072 | })); |
| 1073 | let assignee_chips = h_flex() |
| 1074 | .w_full() |
| 1075 | .flex_wrap() |
| 1076 | .gap(px(6.)) |
| 1077 | .child( |
| 1078 | chip( |
| 1079 | "kvt-board-assignee-none".into(), |
| 1080 | tr("kvt.board.assignee_none"), |
| 1081 | editor.assignee.is_empty(), |
| 1082 | ) |
| 1083 | .on_click(cx.listener(|this, _, _, cx| { |
| 1084 | if let Some(editor) = this.editor.as_mut() { |
| 1085 | editor.assignee.clear(); |
| 1086 | cx.notify(); |
| 1087 | } |
| 1088 | })), |
| 1089 | ) |
| 1090 | .when(!me.is_empty(), |row| { |
| 1091 | let me = me.clone(); |
| 1092 | row.child( |
| 1093 | chip( |
| 1094 | "kvt-board-assignee-me".into(), |
| 1095 | tr("kvt.board.assignee_me"), |
| 1096 | assignee_is_me, |
| 1097 | ) |
| 1098 | .on_click(cx.listener(move |this, _, _, cx| { |
| 1099 | if let Some(editor) = this.editor.as_mut() { |
| 1100 | editor.assignee = me.clone(); |
| 1101 | cx.notify(); |
| 1102 | } |
| 1103 | })), |
| 1104 | ) |
| 1105 | }) |
| 1106 | .children( |
| 1107 | other_assignee.map(|name| chip("kvt-board-assignee-other".into(), name, true)), |
| 1108 | ); |
| 1109 | let group_chips = |
| 1110 | (existing.is_some() && move_groups.len() > 1).then(|| { |
| 1111 | h_flex().w_full().flex_wrap().gap(px(6.)).children( |
| 1112 | move_groups.iter().enumerate().map(|(index, group)| { |
| 1113 | let id = group.id.clone(); |
| 1114 | let home = home.clone(); |
| 1115 | chip( |
| 1116 | format!("kvt-board-move-{index}").into(), |
| 1117 | group.name.clone(), |
| 1118 | group.id == target, |
| 1119 | ) |
| 1120 | .on_click(cx.listener(move |this, _, _, cx| { |
| 1121 | if let Some(editor) = this.editor.as_mut() { |
| 1122 | editor.target_group = (id != home).then(|| id.clone()); |
| 1123 | cx.notify(); |
| 1124 | } |
| 1125 | })) |
| 1126 | }), |
| 1127 | ) |
| 1128 | }); |
| 1129 | let can_complete = existing |
| 1130 | .as_ref() |
| 1131 | .is_some_and(|task| task.status != STATUS_DONE && task.can_edit); |
| 1132 | |
| 1133 | let panel = v_flex() |
| 1134 | .debug_selector(|| "kvt-board-editor".into()) |
| 1135 | .w(px(EDITOR_WIDTH)) |
| 1136 | .max_w(relative(1.)) |
| 1137 | .max_h(relative(0.92)) |
| 1138 | .m(px(32.)) |
| 1139 | .p(px(16.)) |
| 1140 | .gap(px(10.)) |
| 1141 | .rounded(px(RADIUS)) |
| 1142 | .dialog_surface() |
| 1143 | .text_color(theme::text()) |
| 1144 | .occlude() |
| 1145 | .child( |
| 1146 | h_flex() |
| 1147 | .w_full() |
| 1148 | .items_center() |
| 1149 | .gap(px(12.)) |
| 1150 | .child( |
| 1151 | v_flex() |
| 1152 | .flex_1() |
| 1153 | .min_w_0() |
| 1154 | .child( |
| 1155 | div() |
| 1156 | .text_size(px(15.)) |
| 1157 | .font_weight(FontWeight::SEMIBOLD) |
| 1158 | .child(title), |
| 1159 | ) |
| 1160 | .when(!detail.is_empty(), |column| { |
| 1161 | column.child( |
| 1162 | div() |
| 1163 | .truncate() |
| 1164 | .text_size(px(12.)) |
| 1165 | .text_color(theme::text_muted()) |
| 1166 | .child(detail), |
| 1167 | ) |
| 1168 | }), |
| 1169 | ) |
| 1170 | .child( |
| 1171 | div() |
| 1172 | .id("kvt-board-editor-close") |
| 1173 | .size(px(28.)) |
| 1174 | .flex_none() |
| 1175 | .flex() |
| 1176 | .items_center() |
| 1177 | .justify_center() |
| 1178 | .rounded_full() |
| 1179 | .cursor_pointer() |
| 1180 | .hover(|button| button.bg(theme::popup_hover())) |
| 1181 | .on_click(cx.listener(|this, _, _, cx| { |
| 1182 | this.editor = None; |
| 1183 | cx.notify(); |
| 1184 | })) |
| 1185 | .child(symbol("close", 16., theme::text_muted())), |
| 1186 | ), |
| 1187 | ) |
| 1188 | .child(label(tr("kvt.ponos.title"))) |
| 1189 | .child( |
| 1190 | field().child( |
| 1191 | div() |
| 1192 | .flex_1() |
| 1193 | .child(Input::new(&editor.title).appearance(false).bordered(false)), |
| 1194 | ), |
| 1195 | ) |
| 1196 | .child(label(tr("kvt.ponos.description"))) |
| 1197 | .child(Textarea::new(&editor.description)) |
| 1198 | .child(label(tr("kvt.board.status"))) |
| 1199 | .child(status_chips) |
| 1200 | .child(label(tr("kvt.board.due"))) |
| 1201 | .child( |
| 1202 | field().child( |
| 1203 | div() |
| 1204 | .flex_1() |
| 1205 | .child(Input::new(&editor.due).appearance(false).bordered(false)), |
| 1206 | ), |
| 1207 | ) |
| 1208 | .child(label(tr("kvt.board.assignee"))) |
| 1209 | .child(assignee_chips) |
| 1210 | .when_some(group_chips, |panel, chips| { |
| 1211 | panel.child(label(tr("kvt.ponos.group"))).child(chips) |
| 1212 | }) |
| 1213 | .children(editor.error.clone().map(|error| { |
| 1214 | div() |
| 1215 | .text_size(px(13.)) |
| 1216 | .text_color(theme::red_soft()) |
| 1217 | .child(error) |
| 1218 | })) |
| 1219 | .child( |
| 1220 | h_flex() |
| 1221 | .w_full() |
| 1222 | .gap(px(8.)) |
| 1223 | .items_center() |
| 1224 | .children(url.map(|url| { |
| 1225 | secondary_button( |
| 1226 | "kvt-board-editor-open", |
| 1227 | "open_in_new", |
| 1228 | tr("kvt.tasks.open_ponos"), |
| 1229 | ) |
| 1230 | .on_click(move |_, _, cx| open_external(&url, cx)) |
| 1231 | })) |
| 1232 | .child(div().flex_1()) |
| 1233 | .when(can_complete, |row| { |
| 1234 | row.child( |
| 1235 | secondary_button( |
| 1236 | "kvt-board-complete", |
| 1237 | "check_circle", |
| 1238 | tr("kvt.board.complete"), |
| 1239 | ) |
| 1240 | .on_click(cx.listener(|this, _, _, cx| this.complete_from_editor(cx))), |
| 1241 | ) |
| 1242 | }) |
| 1243 | .child( |
| 1244 | secondary_button("kvt-board-cancel", "close", tr("common.cancel")) |
| 1245 | .on_click(cx.listener(|this, _, _, cx| { |
| 1246 | this.editor = None; |
| 1247 | cx.notify(); |
| 1248 | })), |
| 1249 | ) |
| 1250 | .when(editable, |row| { |
| 1251 | row.child( |
| 1252 | primary_button( |
| 1253 | "kvt-board-save", |
| 1254 | tr(if editor.saving { |
| 1255 | "kvt.ponos.saving" |
| 1256 | } else { |
| 1257 | "kvt.board.save" |
| 1258 | }), |
| 1259 | ) |
| 1260 | .on_click(cx.listener(|this, _, _, cx| this.save_editor(cx))), |
| 1261 | ) |
| 1262 | }), |
| 1263 | ); |
| 1264 | Some( |
| 1265 | div() |
| 1266 | .id("kvt-board-editor-layer") |
| 1267 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { |
| 1268 | if event.keystroke.key == "escape" { |
| 1269 | cx.stop_propagation(); |
| 1270 | this.editor = None; |
| 1271 | cx.notify(); |
| 1272 | } |
| 1273 | })) |
| 1274 | .absolute() |
| 1275 | .top_0() |
| 1276 | .left_0() |
| 1277 | .size_full() |
| 1278 | .flex() |
| 1279 | .items_center() |
| 1280 | .justify_center() |
| 1281 | .child( |
| 1282 | div() |
| 1283 | .id("kvt-board-editor-backdrop") |
| 1284 | .absolute() |
| 1285 | .top_0() |
| 1286 | .left_0() |
| 1287 | .size_full() |
| 1288 | .bg(black().opacity(BACKDROP_OPACITY)) |
| 1289 | .occlude() |
| 1290 | .on_click(cx.listener(|this, _, _, cx| { |
| 1291 | this.editor = None; |
| 1292 | cx.notify(); |
| 1293 | })), |
| 1294 | ) |
| 1295 | .child(panel) |
| 1296 | .into_any_element(), |
| 1297 | ) |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | impl Render for PonosBoard { |
| 1302 | fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 1303 | let linked = matches!(link(cx), Link::Linked(_)); |
| 1304 | if !linked && !is_demo(cx) { |
| 1305 | // Ontkoppeld: na opnieuw koppelen vers laden, niets van de oude token tonen. |
| 1306 | self.nav = Nav::NotLinked; |
| 1307 | self.editor = None; |
| 1308 | } else if matches!(self.nav, Nav::NotLinked) { |
| 1309 | self.reload(cx); |
| 1310 | } |
| 1311 | let body = match (&self.nav, linked) { |
| 1312 | (_, false) => v_flex() |
| 1313 | .p(px(PAGE_PADDING)) |
| 1314 | .max_w(px(EDITOR_WIDTH)) |
| 1315 | .child(not_linked()) |
| 1316 | .into_any_element(), |
| 1317 | (Nav::NotLinked | Nav::Loading, _) => muted(tr("kvt.card.loading")) |
| 1318 | .px(px(PAGE_PADDING)) |
| 1319 | .into_any_element(), |
| 1320 | (Nav::Failed(error), _) => muted(ponos_error(error)) |
| 1321 | .px(px(PAGE_PADDING)) |
| 1322 | .into_any_element(), |
| 1323 | (Nav::Loaded(_), _) => h_flex() |
| 1324 | .flex_1() |
| 1325 | .min_h_0() |
| 1326 | .w_full() |
| 1327 | .child(self.groups_list(cx)) |
| 1328 | .child( |
| 1329 | v_flex() |
| 1330 | .flex_1() |
| 1331 | .min_w_0() |
| 1332 | .h_full() |
| 1333 | .child(self.header(cx)) |
| 1334 | .child(self.columns(cx)), |
| 1335 | ) |
| 1336 | .into_any_element(), |
| 1337 | }; |
| 1338 | let page_title = (!matches!(self.nav, Nav::Loaded(_)) || !linked).then(|| { |
| 1339 | h_flex() |
| 1340 | .h(px(HEADER_HEIGHT)) |
| 1341 | .flex_none() |
| 1342 | .px(px(PAGE_PADDING)) |
| 1343 | .items_center() |
| 1344 | .child( |
| 1345 | div() |
| 1346 | .text_size(px(16.)) |
| 1347 | .font_weight(FontWeight::BOLD) |
| 1348 | .text_color(theme::text()) |
| 1349 | .child(tr("kvt.board.title")), |
| 1350 | ) |
| 1351 | }); |
| 1352 | v_flex() |
| 1353 | .debug_selector(|| KVT_BOARD_TAG.into()) |
| 1354 | .relative() |
| 1355 | .size_full() |
| 1356 | .rounded(px(RADIUS)) |
| 1357 | .bg(theme::surface()) |
| 1358 | .overflow_hidden() |
| 1359 | .children(page_title) |
| 1360 | .child(body) |
| 1361 | .children(self.editor_layer(cx)) |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | #[cfg(test)] |
| 1366 | mod tests { |
| 1367 | use super::pick_group; |
| 1368 | use kvt_sleutels::ponos::{PonosGroup, PonosNavigation}; |
| 1369 | |
| 1370 | fn group(id: &str) -> PonosGroup { |
| 1371 | PonosGroup { |
| 1372 | id: id.to_owned(), |
| 1373 | name: id.to_owned(), |
| 1374 | is_virtual: false, |
| 1375 | can_create_tasks: true, |
| 1376 | has_task_access: true, |
| 1377 | task_count: 0, |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | #[test] |
| 1382 | fn remembered_group_wins_when_it_still_exists() { |
| 1383 | let navigation = PonosNavigation { |
| 1384 | groups: vec![group("__my_tasks__"), group("g1")], |
| 1385 | ..Default::default() |
| 1386 | }; |
| 1387 | assert_eq!(pick_group(Some("g1"), &navigation).as_deref(), Some("g1")); |
| 1388 | assert_eq!( |
| 1389 | pick_group(Some("weg"), &navigation).as_deref(), |
| 1390 | Some("__my_tasks__") |
| 1391 | ); |
| 1392 | assert_eq!(pick_group(None, &PonosNavigation::default()), None); |
| 1393 | } |
| 1394 | } |