The interface becomes a choice, saved like a theme
Browse files at this commit86d9d52789b5294e506cb3bc68fc36769088b9d1Parent: 14f757d- feat
- the interface becomes a choice, saved like a theme
9 changed files +92 -10
- crates/izlek-core/migrations/0017_ui_preference.sql +3 -0
- crates/izlek-core/src/store/mod.rs +3 -0
- crates/izlek-core/src/store/turso_store.rs +6 -3
- crates/izlek-core/tests/store.rs +6 -4
- crates/izlek-web/src/i18n.rs +3 -0
- crates/izlek-web/src/layout.rs +4 -1
- crates/izlek-web/src/server.rs +6 -0
- crates/izlek-web/src/settings.rs +18 -2
- crates/izlek-web/tests/http.rs +43 -0
crates/izlek-core/migrations/0017_ui_preference.sqladded+3 -0
| @@ -0,0 +1,3 @@ | ||
| 1 | +-- Which interface this person uses. Display-only, as the preferences before | |
| 2 | +-- it: no stored data depends on it. | |
| 3 | +ALTER TABLE user ADD COLUMN ui TEXT NOT NULL DEFAULT 'instrument'; |
crates/izlek-core/src/store/mod.rsmodified+3 -0
| @@ -150,6 +150,8 @@ pub struct User { | ||
| 150 | 150 | pub theme: String, |
| 151 | 151 | /// Display-only, as [`Self::timezone`]. |
| 152 | 152 | pub language: String, |
| 153 | + /// Display-only, as [`Self::timezone`]. | |
| 154 | + pub ui: String, | |
| 153 | 155 | } |
| 154 | 156 | |
| 155 | 157 | impl User { |
| @@ -596,6 +598,7 @@ pub trait Store: BoardReads + DetailReads + 'static { | ||
| 596 | 598 | timezone: &str, |
| 597 | 599 | theme: &str, |
| 598 | 600 | language: &str, |
| 601 | + ui: &str, | |
| 599 | 602 | ) -> Result<()>; |
| 600 | 603 | |
| 601 | 604 | async fn set_role(&self, user_id: &str, role: Role) -> Result<()>; |
crates/izlek-core/src/store/turso_store.rsmodified+6 -3
| @@ -69,6 +69,7 @@ const MIGRATIONS: &[(i64, &str)] = &[ | ||
| 69 | 69 | 16, |
| 70 | 70 | include_str!("../../migrations/0016_display_preferences.sql"), |
| 71 | 71 | ), |
| 72 | + (17, include_str!("../../migrations/0017_ui_preference.sql")), | |
| 72 | 73 | ]; |
| 73 | 74 | |
| 74 | 75 | /// The board a fresh workspace gets, and its columns. `Done` is the column |
| @@ -583,11 +584,12 @@ fn user_from(row: &Row) -> Result<User> { | ||
| 583 | 584 | timezone: text(row, 10)?, |
| 584 | 585 | theme: text(row, 11)?, |
| 585 | 586 | language: text(row, 12)?, |
| 587 | + ui: text(row, 13)?, | |
| 586 | 588 | }) |
| 587 | 589 | } |
| 588 | 590 | |
| 589 | 591 | const USER_COLUMNS: &str = "id, workspace_id, email, display_name, role, password_hash, \ |
| 590 | - photo_path, created_at, last_signed_in_at, invited_by, timezone, theme, language"; | |
| 592 | + photo_path, created_at, last_signed_in_at, invited_by, timezone, theme, language, ui"; | |
| 591 | 593 | |
| 592 | 594 | fn signin_link_from(row: &Row) -> Result<SigninLink> { |
| 593 | 595 | Ok(SigninLink { |
| @@ -997,12 +999,13 @@ impl Store for TursoStore { | ||
| 997 | 999 | timezone: &str, |
| 998 | 1000 | theme: &str, |
| 999 | 1001 | language: &str, |
| 1002 | + ui: &str, | |
| 1000 | 1003 | ) -> Result<()> { |
| 1001 | 1004 | let conn = self.conn.lock().await; |
| 1002 | 1005 | let n = conn |
| 1003 | 1006 | .execute( |
| 1004 | - "UPDATE user SET timezone = ?1, theme = ?2, language = ?3 WHERE id = ?4", | |
| 1005 | - params![timezone, theme, language, user_id], | |
| 1007 | + "UPDATE user SET timezone = ?1, theme = ?2, language = ?3, ui = ?4 WHERE id = ?5", | |
| 1008 | + params![timezone, theme, language, ui, user_id], | |
| 1006 | 1009 | ) |
| 1007 | 1010 | .await |
| 1008 | 1011 | .map_err(backend)?; |
crates/izlek-core/tests/store.rsmodified+6 -4
| @@ -236,14 +236,14 @@ async fn migrations_apply_once_and_survive_reopen() { | ||
| 236 | 236 | let path = dir.join("izlek.db").to_string_lossy().into_owned(); |
| 237 | 237 | |
| 238 | 238 | let first = TursoStore::open(&path).await.unwrap(); |
| 239 | - assert_eq!(first.schema_version().await.unwrap(), 16); | |
| 239 | + assert_eq!(first.schema_version().await.unwrap(), 17); | |
| 240 | 240 | claim(&first).await; |
| 241 | 241 | drop(first); |
| 242 | 242 | |
| 243 | 243 | // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and |
| 244 | 244 | // must not lose what the first open wrote. |
| 245 | 245 | let second = TursoStore::open(&path).await.unwrap(); |
| 246 | - assert_eq!(second.schema_version().await.unwrap(), 16); | |
| 246 | + assert_eq!(second.schema_version().await.unwrap(), 17); | |
| 247 | 247 | assert_eq!(second.workspace().await.unwrap().unwrap().name, "Izlek"); |
| 248 | 248 | drop(second); |
| 249 | 249 | let _ = std::fs::remove_dir_all(&dir); |
| @@ -260,7 +260,7 @@ async fn migration_0013_rebuilds_mail_rule_without_losing_its_ledger() { | ||
| 260 | 260 | a_pre_0013_store_with_a_rule_send_and_decision().await; |
| 261 | 261 | |
| 262 | 262 | let store = TursoStore::open(path.to_str().unwrap()).await.unwrap(); |
| 263 | - assert_eq!(store.schema_version().await.unwrap(), 16); | |
| 263 | + assert_eq!(store.schema_version().await.unwrap(), 17); | |
| 264 | 264 | assert_eq!(store.board(&workspace).await.unwrap().unwrap().id, board); |
| 265 | 265 | |
| 266 | 266 | let rules = store.mail_rules(&board).await.unwrap(); |
| @@ -864,9 +864,10 @@ async fn display_preferences_default_and_persist_across_reopen() { | ||
| 864 | 864 | assert_eq!(admin.timezone, "UTC"); |
| 865 | 865 | assert_eq!(admin.theme, "light"); |
| 866 | 866 | assert_eq!(admin.language, "en"); |
| 867 | + assert_eq!(admin.ui, "instrument"); | |
| 867 | 868 | |
| 868 | 869 | store |
| 869 | - .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr") | |
| 870 | + .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr", "ledger") | |
| 870 | 871 | .await |
| 871 | 872 | .unwrap(); |
| 872 | 873 | drop(store); |
| @@ -876,6 +877,7 @@ async fn display_preferences_default_and_persist_across_reopen() { | ||
| 876 | 877 | assert_eq!(admin.timezone, "Europe/Istanbul"); |
| 877 | 878 | assert_eq!(admin.theme, "dark"); |
| 878 | 879 | assert_eq!(admin.language, "tr"); |
| 880 | + assert_eq!(admin.ui, "ledger"); | |
| 879 | 881 | |
| 880 | 882 | drop(reopened); |
| 881 | 883 | let _ = std::fs::remove_dir_all(&dir); |
crates/izlek-web/src/i18n.rsmodified+3 -0
| @@ -107,6 +107,7 @@ pub enum Key { | ||
| 107 | 107 | ThemeLabel, |
| 108 | 108 | LightOption, |
| 109 | 109 | DarkOption, |
| 110 | + UiLabel, | |
| 110 | 111 | LanguageLabel, |
| 111 | 112 | Saved, |
| 112 | 113 | SignOut, |
| @@ -438,6 +439,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 438 | 439 | (TimezoneLabel, Tr) => "SAAT DİLİMİ", |
| 439 | 440 | (ThemeLabel, En) => "THEME", |
| 440 | 441 | (ThemeLabel, Tr) => "TEMA", |
| 442 | + (UiLabel, En) => "INTERFACE", | |
| 443 | + (UiLabel, Tr) => "ARAYÜZ", | |
| 441 | 444 | (LightOption, En) => "Light", |
| 442 | 445 | (LightOption, Tr) => "Açık", |
| 443 | 446 | (DarkOption, En) => "Dark", |
crates/izlek-web/src/layout.rsmodified+4 -1
| @@ -109,6 +109,8 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | ||
| 109 | 109 | if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \ |
| 110 | 110 | if (root.hasAttribute('data-theme')) { document.documentElement.setAttribute('data-theme', root.getAttribute('data-theme')); } \ |
| 111 | 111 | else { document.documentElement.removeAttribute('data-theme'); } \ |
| 112 | + if (root.hasAttribute('data-ui')) { document.documentElement.setAttribute('data-ui', root.getAttribute('data-ui')); } \ | |
| 113 | + else { document.documentElement.removeAttribute('data-ui'); } \ | |
| 112 | 114 | if (url) { history.replaceState(null, '', url); } \ |
| 113 | 115 | window.scrollTo(fresh ? 0 : x, fresh ? 0 : y); \ |
| 114 | 116 | wire(); \ |
| @@ -286,6 +288,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result { | ||
| 286 | 288 | Err(_) => None, |
| 287 | 289 | }; |
| 288 | 290 | let dark = asking.is_some_and(|user| user.theme == "dark"); |
| 291 | + let ui = asking.map_or("instrument", |user| user.ui.as_str()); | |
| 289 | 292 | let lang = asking.map_or(Lang::En, |user| Lang::from_code(&user.language)); |
| 290 | 293 | |
| 291 | 294 | let content = match slot { |
| @@ -301,7 +304,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result { | ||
| 301 | 304 | |
| 302 | 305 | view! { |
| 303 | 306 | <!DOCTYPE html> |
| 304 | - <html lang=(lang.code()) data-theme=(dark.then_some("dark"))> | |
| 307 | + <html lang=(lang.code()) data-theme=(dark.then_some("dark")) data-ui=(ui)> | |
| 305 | 308 | <head> |
| 306 | 309 | <meta charset="utf-8"> |
| 307 | 310 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
crates/izlek-web/src/server.rsmodified+6 -0
| @@ -311,6 +311,8 @@ pub enum Refusal { | ||
| 311 | 311 | BadZone, |
| 312 | 312 | /// The theme field was not one of the values the form offers. |
| 313 | 313 | BadTheme, |
| 314 | + /// The ui field was not one of the values the form offers. | |
| 315 | + BadUi, | |
| 314 | 316 | /// The language field was not one of the values the form offers. |
| 315 | 317 | BadLanguage, |
| 316 | 318 | /// The email field did not look like an address. |
| @@ -367,6 +369,7 @@ impl Refusal { | ||
| 367 | 369 | } |
| 368 | 370 | Refusal::BadZone => "That is not a timezone.".to_string(), |
| 369 | 371 | Refusal::BadTheme => "That is not a theme.".to_string(), |
| 372 | + Refusal::BadUi => "That is not an interface.".to_string(), | |
| 370 | 373 | Refusal::BadLanguage => "That is not a language.".to_string(), |
| 371 | 374 | Refusal::BadEmail => "That is not an address.".to_string(), |
| 372 | 375 | Refusal::BadFileType => { |
| @@ -418,6 +421,7 @@ impl Refusal { | ||
| 418 | 421 | } |
| 419 | 422 | Refusal::BadZone => "Bu bir saat dilimi değil.".to_string(), |
| 420 | 423 | Refusal::BadTheme => "Bu bir tema değil.".to_string(), |
| 424 | + Refusal::BadUi => "Bu bir arayüz değil.".to_string(), | |
| 421 | 425 | Refusal::BadLanguage => "Bu bir dil değil.".to_string(), |
| 422 | 426 | Refusal::BadEmail => "Bu bir adres değil.".to_string(), |
| 423 | 427 | Refusal::BadFileType => { |
| @@ -463,6 +467,7 @@ impl Refusal { | ||
| 463 | 467 | "bad-limit" => Refusal::BadLimit, |
| 464 | 468 | "bad-zone" => Refusal::BadZone, |
| 465 | 469 | "bad-theme" => Refusal::BadTheme, |
| 470 | + "bad-ui" => Refusal::BadUi, | |
| 466 | 471 | "bad-language" => Refusal::BadLanguage, |
| 467 | 472 | "bad-email" => Refusal::BadEmail, |
| 468 | 473 | "bad-file-type" => Refusal::BadFileType, |
| @@ -515,6 +520,7 @@ impl Refusal { | ||
| 515 | 520 | Refusal::BadLimit => "bad-limit", |
| 516 | 521 | Refusal::BadZone => "bad-zone", |
| 517 | 522 | Refusal::BadTheme => "bad-theme", |
| 523 | + Refusal::BadUi => "bad-ui", | |
| 518 | 524 | Refusal::BadLanguage => "bad-language", |
| 519 | 525 | Refusal::BadEmail => "bad-email", |
| 520 | 526 | Refusal::BadFileType => "bad-file-type", |
crates/izlek-web/src/settings.rsmodified+18 -2
| @@ -446,7 +446,7 @@ async fn send_test_mail(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec<u8>)> { | ||
| 446 | 446 | struct SaveProfileForm { |
| 447 | 447 | display_name: String, |
| 448 | 448 | /// Absent on a form that never got the field — kept as it was, same as |
| 449 | - /// `timezone`/`theme`/`language` below. | |
| 449 | + /// `timezone`/`theme`/`language`/`ui` below. | |
| 450 | 450 | #[serde(default)] |
| 451 | 451 | email: Option<String>, |
| 452 | 452 | #[serde(default)] |
| @@ -455,11 +455,16 @@ struct SaveProfileForm { | ||
| 455 | 455 | theme: Option<String>, |
| 456 | 456 | #[serde(default)] |
| 457 | 457 | language: Option<String>, |
| 458 | + #[serde(default)] | |
| 459 | + ui: Option<String>, | |
| 458 | 460 | } |
| 459 | 461 | |
| 460 | 462 | /// The values the theme field offers. |
| 461 | 463 | const THEME_OPTIONS: [&str; 2] = ["light", "dark"]; |
| 462 | 464 | |
| 465 | +/// The values the ui field offers. | |
| 466 | +const UI_OPTIONS: [&str; 2] = ["instrument", "ledger"]; | |
| 467 | + | |
| 463 | 468 | /// The values the language field offers. |
| 464 | 469 | const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"]; |
| 465 | 470 | |
| @@ -502,6 +507,10 @@ async fn save_profile(cx: &Cx, Form(input): Form<SaveProfileForm>) -> Result<(St | ||
| 502 | 507 | if !THEME_OPTIONS.contains(&theme.as_str()) { |
| 503 | 508 | return Ok(saved_or_refused("save_profile", Some(Refusal::BadTheme))); |
| 504 | 509 | } |
| 510 | + let ui = input.ui.unwrap_or_else(|| user.ui.clone()); | |
| 511 | + if !UI_OPTIONS.contains(&ui.as_str()) { | |
| 512 | + return Ok(saved_or_refused("save_profile", Some(Refusal::BadUi))); | |
| 513 | + } | |
| 505 | 514 | let language = input.language.unwrap_or_else(|| user.language.clone()); |
| 506 | 515 | if !LANGUAGE_OPTIONS.contains(&language.as_str()) { |
| 507 | 516 | return Ok(saved_or_refused("save_profile", Some(Refusal::BadLanguage))); |
| @@ -521,7 +530,7 @@ async fn save_profile(cx: &Cx, Form(input): Form<SaveProfileForm>) -> Result<(St | ||
| 521 | 530 | let outcome = store |
| 522 | 531 | .set_profile(&user.id, &display_name, user.photo_path.as_deref()) |
| 523 | 532 | .await |
| 524 | - .and(store.set_preferences(&user.id, &timezone, &theme, &language).await) | |
| 533 | + .and(store.set_preferences(&user.id, &timezone, &theme, &language, &ui).await) | |
| 525 | 534 | .and(store.set_email(&user.id, &user.workspace_id, &email).await); |
| 526 | 535 | let refusal = match outcome { |
| 527 | 536 | Ok(()) => None, |
| @@ -832,6 +841,13 @@ async fn settings_page(cx: &Cx) -> Result { | ||
| 832 | 841 | <option value="dark" selected=(user.theme == "dark")>(t(lang, Key::DarkOption))</option> |
| 833 | 842 | </select> |
| 834 | 843 | </label> |
| 844 | + <label class="field"> | |
| 845 | + <span class="field-label">(t(lang, Key::UiLabel))</span> | |
| 846 | + <select class="field-input" name="ui"> | |
| 847 | + <option value="instrument" selected=(user.ui == "instrument")>"Instrument"</option> | |
| 848 | + <option value="ledger" selected=(user.ui == "ledger")>"Ledger"</option> | |
| 849 | + </select> | |
| 850 | + </label> | |
| 835 | 851 | <label class="field"> |
| 836 | 852 | <span class="field-label">(t(lang, Key::LanguageLabel))</span> |
| 837 | 853 | <select class="field-input" name="language"> |
crates/izlek-web/tests/http.rsmodified+43 -0
| @@ -2818,6 +2818,49 @@ async fn an_unlisted_theme_is_refused() { | ||
| 2818 | 2818 | assert!(location.contains("refusal=bad-theme&on=save_profile"), "{location}"); |
| 2819 | 2819 | } |
| 2820 | 2820 | |
| 2821 | +#[tokio::test] | |
| 2822 | +async fn the_ledger_ui_is_saved_and_marks_the_page() { | |
| 2823 | + let app = App::open().await; | |
| 2824 | + let admin_cookie = admin(&app).await; | |
| 2825 | + | |
| 2826 | + let saved = app | |
| 2827 | + .post( | |
| 2828 | + "/api/save_profile", | |
| 2829 | + Some(&admin_cookie), | |
| 2830 | + &[("display_name", "Ada Lovelace"), ("ui", "ledger")], | |
| 2831 | + ) | |
| 2832 | + .await; | |
| 2833 | + assert!( | |
| 2834 | + !saved.location.as_deref().unwrap_or_default().contains("refusal="), | |
| 2835 | + "{:?}", | |
| 2836 | + saved.location | |
| 2837 | + ); | |
| 2838 | + | |
| 2839 | + let page = app.get("/settings", Some(&admin_cookie)).await; | |
| 2840 | + let html = String::from_utf8_lossy(&page.bytes); | |
| 2841 | + assert!(html.contains(r#"data-ui="ledger""#), "{html}"); | |
| 2842 | +} | |
| 2843 | + | |
| 2844 | +#[tokio::test] | |
| 2845 | +async fn an_unlisted_ui_is_refused() { | |
| 2846 | + let app = App::open().await; | |
| 2847 | + let admin_cookie = admin(&app).await; | |
| 2848 | + | |
| 2849 | + let answer = app | |
| 2850 | + .post( | |
| 2851 | + "/api/save_profile", | |
| 2852 | + Some(&admin_cookie), | |
| 2853 | + &[("display_name", "Ada Lovelace"), ("ui", "neon")], | |
| 2854 | + ) | |
| 2855 | + .await; | |
| 2856 | + let location = answer.location.as_deref().unwrap_or_default(); | |
| 2857 | + assert!(location.contains("refusal=bad-ui&on=save_profile"), "{location}"); | |
| 2858 | + | |
| 2859 | + let page = app.get("/settings", Some(&admin_cookie)).await; | |
| 2860 | + let html = String::from_utf8_lossy(&page.bytes); | |
| 2861 | + assert!(html.contains(r#"data-ui="instrument""#), "{html}"); | |
| 2862 | +} | |
| 2863 | + | |
| 2821 | 2864 | /// Creating a task files its own Created activity, but the column it lands |
| 2822 | 2865 | /// in also fires a `Transition` the way a drop does — a `StatusBecomes` rule |
| 2823 | 2866 | /// armed on that column must owe mail on creation, not only on a later move. |