| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#![allow(clippy::needless_pass_by_value)] |
| 31 |
|
| 32 |
use std::collections::HashMap; |
| 33 |
|
| 34 |
use chrono::{Duration, NaiveDate}; |
| 35 |
use goingson_core::weekly_review::{ |
| 36 |
self, EventSummary, ProjectHealth, TimelineDayData, WeeklyReviewData, |
| 37 |
}; |
| 38 |
use goingson_core::{LinkedTaskRef, Task, TaskId}; |
| 39 |
use makeover_layout::Tone; |
| 40 |
use quasi_declare::declare; |
| 41 |
use quasi_router::screen::{Figure, Tag}; |
| 42 |
use quasi_router::{Action, Response, RouteError, Router}; |
| 43 |
|
| 44 |
use crate::commands::{focus_blockers, gather_weekly_review}; |
| 45 |
use crate::state::{AppState, DESKTOP_USER_ID}; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
type FocusBlockers = HashMap<TaskId, Vec<LinkedTaskRef>>; |
| 52 |
|
| 53 |
#[cfg(test)] |
| 54 |
mod tests; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
const FOCUS_SLOTS: usize = 3; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
const WEEKDAYS: [&str; 7] = [ |
| 70 |
"Monday", |
| 71 |
"Tuesday", |
| 72 |
"Wednesday", |
| 73 |
"Thursday", |
| 74 |
"Friday", |
| 75 |
"Saturday", |
| 76 |
"Sunday", |
| 77 |
]; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
fn week_of(request: &quasi_router::Request) -> NaiveDate { |
| 87 |
request |
| 88 |
.carried |
| 89 |
.get("week") |
| 90 |
.and_then(weekly_review::parse_week_start) |
| 91 |
.unwrap_or_else(weekly_review::current_week_start) |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
fn in_week(action: Action, week: NaiveDate) -> Action { |
| 96 |
action.carrying("week", week.to_string()) |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
fn load(state: &AppState, week: NaiveDate) -> Result<WeeklyReviewData, RouteError> { |
| 101 |
gather_weekly_review(state, week).map_err(|error| RouteError::internal(error.to_string())) |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
fn health_tone(status: &str) -> makeover_layout::Tone { |
| 110 |
match status { |
| 111 |
"healthy" => makeover_layout::Tone::Success, |
| 112 |
"warning" => makeover_layout::Tone::Warning, |
| 113 |
"danger" => makeover_layout::Tone::Danger, |
| 114 |
_ => makeover_layout::Tone::Neutral, |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
fn prompt_answer(notes: &str, marker: &str, until: Option<&str>) -> String { |
| 126 |
let Some(start) = notes.find(marker) else { |
| 127 |
return String::new(); |
| 128 |
}; |
| 129 |
let rest = ¬es[start + marker.len()..]; |
| 130 |
let end = until.and_then(|next| rest.find(next)).unwrap_or(rest.len()); |
| 131 |
rest[..end].trim().to_owned() |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
fn waiting_mark(task: &Task, waits: &FocusBlockers) -> Option<Tag> { |
| 149 |
if task.graph.in_cycle { |
| 150 |
return Some(Tag::badge("Cycle").tone(Tone::Danger)); |
| 151 |
} |
| 152 |
let blockers = waits.get(&task.id)?; |
| 153 |
let first = blockers.first()?; |
| 154 |
let label = if blockers.len() > 1 { |
| 155 |
format!("after {} +{}", first.title, blockers.len() - 1) |
| 156 |
} else { |
| 157 |
format!("after {}", first.title) |
| 158 |
}; |
| 159 |
Some(Tag::badge(label).tone(Tone::Warning)) |
| 160 |
} |
| 161 |
|
| 162 |
declare! { |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
shape task_row(task: &Task) -> Row; |
| 169 |
|
| 170 |
row &task.title { |
| 171 |
for project in task.project_name.iter() { |
| 172 |
meta project; |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
struct Place { |
| 179 |
|
| 180 |
number: usize, |
| 181 |
|
| 182 |
task: Option<Task>, |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
fn filled(place: &Place) -> bool { |
| 187 |
place.task.is_some() |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
struct Weekday { |
| 192 |
|
| 193 |
index: usize, |
| 194 |
name: &'static str, |
| 195 |
off: bool, |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
struct Review { |
| 200 |
data: WeeklyReviewData, |
| 201 |
week: NaiveDate, |
| 202 |
waits: FocusBlockers, |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
places: Vec<Place>, |
| 211 |
days: Vec<Weekday>, |
| 212 |
|
| 213 |
went_well: String, |
| 214 |
improve: String, |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
fn read(state: &AppState, week: NaiveDate) -> Result<Review, RouteError> { |
| 219 |
let data = load(state, week)?; |
| 220 |
let waits = focus_blockers(state, &data.available_for_focus) |
| 221 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 222 |
|
| 223 |
let taken = data.focused_tasks.len(); |
| 224 |
let places = (0..FOCUS_SLOTS.max(taken)) |
| 225 |
.map(|index| Place { |
| 226 |
number: index + 1, |
| 227 |
task: data.focused_tasks.get(index).cloned(), |
| 228 |
}) |
| 229 |
.collect(); |
| 230 |
|
| 231 |
let days = WEEKDAYS |
| 232 |
.iter() |
| 233 |
.enumerate() |
| 234 |
.map(|(index, name)| Weekday { |
| 235 |
index, |
| 236 |
name, |
| 237 |
off: data |
| 238 |
.vacation_days |
| 239 |
.contains(&u8::try_from(index).unwrap_or(0)), |
| 240 |
}) |
| 241 |
.collect(); |
| 242 |
|
| 243 |
Ok(Review { |
| 244 |
went_well: prompt_answer( |
| 245 |
&data.notes, |
| 246 |
"What went well:", |
| 247 |
Some("What could be improved:"), |
| 248 |
), |
| 249 |
improve: prompt_answer(&data.notes, "What could be improved:", None), |
| 250 |
data, |
| 251 |
week, |
| 252 |
waits, |
| 253 |
places, |
| 254 |
days, |
| 255 |
}) |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
fn day_counts(day: &TimelineDayData) -> String { |
| 271 |
let mut counts = Vec::new(); |
| 272 |
if day.completed_count > 0 { |
| 273 |
counts.push(format!("{} done", day.completed_count)); |
| 274 |
} |
| 275 |
if day.event_count > 0 { |
| 276 |
counts.push(format!("{} events", day.event_count)); |
| 277 |
} |
| 278 |
if day.overdue_count > 0 { |
| 279 |
counts.push(format!("{} overdue", day.overdue_count)); |
| 280 |
} |
| 281 |
if !day.is_past && day.due_count > 0 { |
| 282 |
counts.push(format!("{} due", day.due_count)); |
| 283 |
} |
| 284 |
counts.join(", ") |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
fn busy(day: &TimelineDayData) -> bool { |
| 289 |
!day_counts(day).is_empty() |
| 290 |
} |
| 291 |
|
| 292 |
declare! { |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
shape timeline(review: &Review) -> Vec<Node>; |
| 313 |
|
| 314 |
section "Week at a Glance"; |
| 315 |
|
| 316 |
list { |
| 317 |
for day in review.data.timeline_days.iter() { |
| 318 |
row "{day.day_name} {day.day_number}" { |
| 319 |
token Tag::badge("Today").tone(Tone::Info) when day.is_today; |
| 320 |
token Tag::badge("Day off") when day.is_vacation; |
| 321 |
meta day_counts(day) when busy(day); |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
declare! { |
| 328 |
|
| 329 |
shape event_row(event: &EventSummary) -> Row; |
| 330 |
|
| 331 |
row &event.title { |
| 332 |
meta &event.formatted_time; |
| 333 |
|
| 334 |
for project in event.project_name.iter() { |
| 335 |
token Tag::badge(project); |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
fn no_events(review: &Review) -> bool { |
| 342 |
review |
| 343 |
.data |
| 344 |
.timeline_days |
| 345 |
.iter() |
| 346 |
.all(|day| day.events.is_empty()) |
| 347 |
} |
| 348 |
|
| 349 |
declare! { |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
shape week_events(review: &Review) -> Vec<Node>; |
| 357 |
|
| 358 |
section "Week's Events" unless no_events(review); |
| 359 |
|
| 360 |
for day in review.data.timeline_days.iter() { |
| 361 |
subsection "{day.day_name} {day.day_number}" unless day.events.is_empty(); |
| 362 |
|
| 363 |
list { |
| 364 |
for event in day.events.iter() { |
| 365 |
include event_row(event); |
| 366 |
} |
| 367 |
} unless day.events.is_empty(); |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
declare! { |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
shape accomplished(review: &Review) -> Vec<Node>; |
| 391 |
|
| 392 |
section "Accomplished"; |
| 393 |
|
| 394 |
stats [] { |
| 395 |
figure Figure::new(review.data.tasks_completed_count.to_string(), "Tasks Completed") |
| 396 |
.tone(Tone::Success); |
| 397 |
figure Figure::new(review.data.events_occurred_count.to_string(), "Events Attended"); |
| 398 |
} |
| 399 |
|
| 400 |
empty "Nothing completed this week" when review.data.tasks_completed.is_empty(); |
| 401 |
|
| 402 |
list { |
| 403 |
for task in review.data.tasks_completed.iter() { |
| 404 |
include task_row(task); |
| 405 |
} |
| 406 |
} unless review.data.tasks_completed.is_empty(); |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
fn overdue_tone(review: &Review) -> Tone { |
| 411 |
if review.data.tasks_overdue_count > 0 { |
| 412 |
Tone::Danger |
| 413 |
} else { |
| 414 |
Tone::Neutral |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
fn slipped(review: &Review) -> bool { |
| 420 |
!review.data.tasks_overdue.is_empty() || !review.data.carried_over_tasks.is_empty() |
| 421 |
} |
| 422 |
|
| 423 |
declare! { |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
shape needs_attention(review: &Review) -> Vec<Node>; |
| 436 |
|
| 437 |
section "Needs Attention"; |
| 438 |
|
| 439 |
stats [] { |
| 440 |
figure Figure::new(review.data.tasks_overdue_count.to_string(), "Overdue") |
| 441 |
.tone(overdue_tone(review)); |
| 442 |
figure Figure::new(review.data.carried_over_count.to_string(), "Carried Over") |
| 443 |
.tone(Tone::Info); |
| 444 |
} |
| 445 |
|
| 446 |
list { |
| 447 |
for task in review.data.tasks_overdue.iter() { |
| 448 |
row &task.title { |
| 449 |
meta project_and_due(task); |
| 450 |
token Tag::badge("Overdue").tone(Tone::Danger); |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
for task in review.data.carried_over_tasks.iter() { |
| 455 |
row &task.title { |
| 456 |
for project in task.project_name.iter() { |
| 457 |
meta project; |
| 458 |
} |
| 459 |
token Tag::badge("Carried over"); |
| 460 |
} |
| 461 |
} |
| 462 |
} when slipped(review); |
| 463 |
} |
| 464 |
|
| 465 |
declare! { |
| 466 |
|
| 467 |
shape due_this_week(review: &Review) -> Vec<Node>; |
| 468 |
|
| 469 |
section "Due This Week"; |
| 470 |
|
| 471 |
empty "No tasks due this week" when review.data.tasks_due_next_week.is_empty(); |
| 472 |
|
| 473 |
list { |
| 474 |
for task in review.data.tasks_due_next_week.iter() { |
| 475 |
row &task.title { |
| 476 |
meta project_and_due(task); |
| 477 |
} |
| 478 |
} |
| 479 |
} unless review.data.tasks_due_next_week.is_empty(); |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
fn project_and_due(task: &Task) -> String { |
| 488 |
[task.project_name.clone(), Some(task.due_formatted())] |
| 489 |
.into_iter() |
| 490 |
.flatten() |
| 491 |
.collect::<Vec<_>>() |
| 492 |
.join(" · ") |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
fn any_focused(review: &Review) -> bool { |
| 497 |
!review.data.focused_tasks.is_empty() |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
fn offers_suggestions(review: &Review) -> bool { |
| 507 |
review.data.focused_tasks.len() < FOCUS_SLOTS && !review.data.available_for_focus.is_empty() |
| 508 |
} |
| 509 |
|
| 510 |
declare! { |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
shape focus(review: &Review) -> Vec<Node>; |
| 543 |
|
| 544 |
section "This Week's Focus"; |
| 545 |
|
| 546 |
for place in review.places.iter() { |
| 547 |
region "weekly-focus-{place.number}" as Group { |
| 548 |
named "Priority {place.number}"; |
| 549 |
|
| 550 |
empty "Open" unless filled(place); |
| 551 |
|
| 552 |
list { |
| 553 |
for task in place.task.iter() { |
| 554 |
include focused_row(review, task); |
| 555 |
} |
| 556 |
} when filled(place); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
act "Clear all focus" to doing in_week( |
| 561 |
Action::post("/weekly-review/focus/clear"), |
| 562 |
review.week |
| 563 |
) when any_focused(review); |
| 564 |
|
| 565 |
subsection "Suggested" when offers_suggestions(review); |
| 566 |
|
| 567 |
list { |
| 568 |
for task in review.data.available_for_focus.iter() { |
| 569 |
include suggested_row(review, task); |
| 570 |
} |
| 571 |
} when offers_suggestions(review); |
| 572 |
} |
| 573 |
|
| 574 |
declare! { |
| 575 |
|
| 576 |
shape focused_row(review: &Review, task: &Task) -> Row; |
| 577 |
|
| 578 |
row &task.title { |
| 579 |
for project in task.project_name.iter() { |
| 580 |
meta project; |
| 581 |
} |
| 582 |
|
| 583 |
act "Remove" to doing in_week( |
| 584 |
Action::post("/weekly-review/focus/{task.id}").with("focus", "false"), |
| 585 |
review.week |
| 586 |
); |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
declare! { |
| 591 |
|
| 592 |
shape suggested_row(review: &Review, task: &Task) -> Row; |
| 593 |
|
| 594 |
row &task.title { |
| 595 |
for project in task.project_name.iter() { |
| 596 |
meta project; |
| 597 |
} |
| 598 |
|
| 599 |
for mark in waiting_mark(task, &review.waits).into_iter() { |
| 600 |
token mark; |
| 601 |
} |
| 602 |
|
| 603 |
act "Focus" to doing in_week( |
| 604 |
Action::post("/weekly-review/focus/{task.id}").with("focus", "true"), |
| 605 |
review.week |
| 606 |
); |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
fn project_counts(project: &ProjectHealth) -> String { |
| 612 |
format!( |
| 613 |
"{} active, {} total", |
| 614 |
project.active_count, project.total_count |
| 615 |
) |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
fn project_overdue(project: &ProjectHealth) -> bool { |
| 620 |
project.overdue_count > 0 |
| 621 |
} |
| 622 |
|
| 623 |
declare! { |
| 624 |
|
| 625 |
shape projects_health(review: &Review) -> Vec<Node>; |
| 626 |
|
| 627 |
section "Projects Health" unless review.data.project_health.is_empty(); |
| 628 |
|
| 629 |
list { |
| 630 |
for project in review.data.project_health.iter() { |
| 631 |
row &project.name { |
| 632 |
meta project_counts(project); |
| 633 |
token Tag::badge(&project.status).tone(health_tone(&project.status)); |
| 634 |
token Tag::badge("{project.overdue_count} overdue").tone(Tone::Danger) |
| 635 |
when project_overdue(project); |
| 636 |
} |
| 637 |
} |
| 638 |
} unless review.data.project_health.is_empty(); |
| 639 |
} |
| 640 |
|
| 641 |
declare! { |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
shape days_off(review: &Review) -> Vec<Node>; |
| 659 |
|
| 660 |
section "Days Off"; |
| 661 |
|
| 662 |
for day in review.days.iter() { |
| 663 |
chip day.name to doing in_week( |
| 664 |
Action::post("/weekly-review/vacation/{day.index}"), |
| 665 |
review.week |
| 666 |
) { |
| 667 |
latched day.off; |
| 668 |
} |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
fn reflection_submit(review: &Review) -> &'static str { |
| 674 |
if review.data.is_completed { |
| 675 |
"Save notes" |
| 676 |
} else { |
| 677 |
"Complete review" |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
declare! { |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
shape reflection(review: &Review) -> Vec<Node>; |
| 703 |
|
| 704 |
section "Reflection"; |
| 705 |
|
| 706 |
form doing in_week(Action::post("/weekly-review/complete"), review.week) { |
| 707 |
submit reflection_submit(review); |
| 708 |
|
| 709 |
field Textarea "went-well" "What went well?" { |
| 710 |
placeholder "Completed the budget ahead of schedule..."; |
| 711 |
value &review.went_well; |
| 712 |
} |
| 713 |
|
| 714 |
field Textarea "improve" "What could be improved?" { |
| 715 |
placeholder "Need to block more focus time..."; |
| 716 |
value &review.improve; |
| 717 |
} |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
fn last_week(review: &Review) -> NaiveDate { |
| 723 |
review.week - Duration::days(7) |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
fn next_week(review: &Review) -> NaiveDate { |
| 728 |
review.week + Duration::days(7) |
| 729 |
} |
| 730 |
|
| 731 |
declare! { |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
shape screen(review: &Review) -> Screen; |
| 743 |
|
| 744 |
screen sidebar_content "Weekly Review" { |
| 745 |
at_place super::shell::WEEK; |
| 746 |
|
| 747 |
region "review-band" as Band { |
| 748 |
page &review.data.week_display; |
| 749 |
|
| 750 |
act "Previous week" |
| 751 |
to doing in_week(Action::get("/weekly-review"), last_week(review)); |
| 752 |
act "Next week" |
| 753 |
to doing in_week(Action::get("/weekly-review"), next_week(review)); |
| 754 |
} |
| 755 |
|
| 756 |
region "weekly-review" as Pane { |
| 757 |
banner Tone::Info "This week is already reviewed. Your notes stay editable." |
| 758 |
when review.data.is_completed; |
| 759 |
|
| 760 |
extend timeline(review); |
| 761 |
extend week_events(review); |
| 762 |
extend accomplished(review); |
| 763 |
extend needs_attention(review); |
| 764 |
extend due_this_week(review); |
| 765 |
extend focus(review); |
| 766 |
extend projects_health(review); |
| 767 |
extend days_off(review); |
| 768 |
extend reflection(review); |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
fn wrote(state: &AppState, week: NaiveDate) -> Result<Response, RouteError> { |
| 780 |
Ok(screen(&read(state, week)?).into()) |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
fn review(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 785 |
wrote(state, week_of(&request)) |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
fn set_focus(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 799 |
let raw = request |
| 800 |
.captures |
| 801 |
.get("id") |
| 802 |
.ok_or_else(|| RouteError::not_found("no task id"))?; |
| 803 |
let id = goingson_core::TaskId::from( |
| 804 |
uuid::Uuid::parse_str(raw).map_err(|_| RouteError::not_found("not a task id"))?, |
| 805 |
); |
| 806 |
let on = request.payload.get("focus") == Some("true"); |
| 807 |
state |
| 808 |
.tasks |
| 809 |
.set_focus(id, DESKTOP_USER_ID, on) |
| 810 |
.map_err(|error| RouteError::internal(error.to_string()))? |
| 811 |
.ok_or_else(|| RouteError::not_found("no such task"))?; |
| 812 |
wrote(state, week_of(&request)) |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
fn clear_focus(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 817 |
state |
| 818 |
.tasks |
| 819 |
.clear_all_focus(DESKTOP_USER_ID) |
| 820 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 821 |
wrote(state, week_of(&request)) |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
fn toggle_vacation( |
| 834 |
state: &AppState, |
| 835 |
request: quasi_router::Request, |
| 836 |
) -> Result<Response, RouteError> { |
| 837 |
let week = week_of(&request); |
| 838 |
let day: u8 = request |
| 839 |
.captures |
| 840 |
.get("day") |
| 841 |
.and_then(|raw| raw.parse().ok()) |
| 842 |
.filter(|day| usize::from(*day) < WEEKDAYS.len()) |
| 843 |
.ok_or_else(|| RouteError::not_found("not a weekday"))?; |
| 844 |
|
| 845 |
let mut days = load(state, week)?.vacation_days; |
| 846 |
if let Some(at) = days.iter().position(|held| *held == day) { |
| 847 |
days.remove(at); |
| 848 |
} else { |
| 849 |
days.push(day); |
| 850 |
} |
| 851 |
crate::commands::weekly_review::set_vacation_week(state, week, &days) |
| 852 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 853 |
wrote(state, week) |
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
fn complete(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 866 |
let week = week_of(&request); |
| 867 |
let went_well = request.payload.get("went-well").unwrap_or_default().trim(); |
| 868 |
let improve = request.payload.get("improve").unwrap_or_default().trim(); |
| 869 |
|
| 870 |
let mut notes = String::new(); |
| 871 |
if !went_well.is_empty() { |
| 872 |
notes.push_str("What went well:\n"); |
| 873 |
notes.push_str(went_well); |
| 874 |
notes.push_str("\n\n"); |
| 875 |
} |
| 876 |
if !improve.is_empty() { |
| 877 |
notes.push_str("What could be improved:\n"); |
| 878 |
notes.push_str(improve); |
| 879 |
} |
| 880 |
|
| 881 |
state |
| 882 |
.weekly_reviews |
| 883 |
.upsert(DESKTOP_USER_ID, week, notes.trim()) |
| 884 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 885 |
Ok(wrote(state, week)?.toast(makeover_layout::Tone::Success, "Week reviewed")) |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
#[must_use] |
| 890 |
pub fn routes(router: Router<AppState>) -> Router<AppState> { |
| 891 |
router |
| 892 |
.get("/weekly-review", review) |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
.post("/weekly-review/focus/clear", clear_focus) |
| 898 |
.post("/weekly-review/focus/{id}", set_focus) |
| 899 |
.post("/weekly-review/vacation/{day}", toggle_vacation) |
| 900 |
.post("/weekly-review/complete", complete) |
| 901 |
} |
| 902 |
|