| 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 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
use quasi_router::layout::{Notice, Tone}; |
| 37 |
use quasi_router::{ |
| 38 |
Act, Action, Node, Outcome, RegionKind, Request, Response, RouteError, Router, Screen, Slot, |
| 39 |
}; |
| 40 |
|
| 41 |
use super::Panels; |
| 42 |
|
| 43 |
|
| 44 |
const BODY: &str = "loose-files"; |
| 45 |
|
| 46 |
|
| 47 |
const BACK: &str = "/"; |
| 48 |
|
| 49 |
|
| 50 |
const BLAST: &str = |
| 51 |
"Tags, analysis results, and history for these samples will be permanently deleted. Purge?"; |
| 52 |
|
| 53 |
|
| 54 |
pub fn routes(router: Router<Panels<'_>>) -> Router<Panels<'_>> { |
| 55 |
router |
| 56 |
.get("/library/loose-files", screen) |
| 57 |
.post("/library/loose-files/dismiss", dismiss) |
| 58 |
.post("/library/loose-files/locate", locate) |
| 59 |
.post("/library/loose-files/purge", purge) |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
fn screen(state: &Panels<'_>, _request: Request) -> Result<Response, RouteError> { |
| 64 |
let missing = state.integrity.missing(); |
| 65 |
if missing == 0 { |
| 66 |
return Err(RouteError::not_found("nothing is missing")); |
| 67 |
} |
| 68 |
|
| 69 |
let body = Slot::new(BODY, RegionKind::Pane) |
| 70 |
.with(Node::page("Loose-files mode warning")) |
| 71 |
.with(Node::Notice { |
| 72 |
kind: Notice::Banner, |
| 73 |
tone: Tone::Warning, |
| 74 |
text: format!( |
| 75 |
"{missing} sample{} in this vault {} missing source {}.", |
| 76 |
if missing == 1 { "" } else { "s" }, |
| 77 |
if missing == 1 { "has a" } else { "have" }, |
| 78 |
if missing == 1 { "file" } else { "files" }, |
| 79 |
), |
| 80 |
}) |
| 81 |
.with(Node::text( |
| 82 |
"The original files may have been moved or deleted. These samples cannot be played or exported until the files are restored.", |
| 83 |
)) |
| 84 |
.with(Node::Act( |
| 85 |
Act::new("Locate missing files", Action::post("/library/loose-files/locate")), |
| 86 |
)) |
| 87 |
.with(Node::Act( |
| 88 |
Act::new("Purge", Action::post("/library/loose-files/purge")) |
| 89 |
.tone(Tone::Danger) |
| 90 |
.confirm(BLAST), |
| 91 |
)) |
| 92 |
.with(Node::Act( |
| 93 |
Act::new("Cancel", Action::post("/library/loose-files/dismiss")).key("esc"), |
| 94 |
)); |
| 95 |
|
| 96 |
Ok(Response::from(Outcome::Over( |
| 97 |
Screen::sidebar_content("Loose-files mode warning").with(body), |
| 98 |
))) |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
fn dismiss(state: &Panels<'_>, _request: Request) -> Result<Response, RouteError> { |
| 103 |
state.integrity.dismiss(); |
| 104 |
Ok(Response::from(Outcome::Goto(Action::get(BACK)))) |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
fn locate(state: &Panels<'_>, _request: Request) -> Result<Response, RouteError> { |
| 114 |
state.integrity.locate(); |
| 115 |
Ok(Response::from(Outcome::Goto(Action::get(BACK)))) |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
fn purge(state: &Panels<'_>, _request: Request) -> Result<Response, RouteError> { |
| 120 |
let missing = state.integrity.missing(); |
| 121 |
if missing == 0 { |
| 122 |
return Err(RouteError::not_found("nothing is missing")); |
| 123 |
} |
| 124 |
state.integrity.purge(); |
| 125 |
Ok(Response::from(Outcome::Goto(Action::get(BACK))) |
| 126 |
.toast(Tone::Warning, format!("Purging {missing} samples."))) |
| 127 |
} |
| 128 |
|