Sage on Ink is the default look for light and dark, listed first, and backgrounds and accents of one hue share a column (Ink and Sage, Anvil and Ember, Dusk and Ocean, Heather and Plum, Blush and Rose)
Browse files at this commit9b600b7da77301410fbc673f6f945d25df7cbbe4Parent: f708a8cAll checks have passed
Show checks
ci/buildSucceededDetails
- style
- Sage on Ink is the default look for light and dark, listed first, and backgrounds and accents of one hue share a column (Ink and Sage, Anvil and Ember, Dusk and Ocean, Heather and Plum, Blush and Rose)
- every action beside a page title is the same soft pill, links and reveals included
- the snippet form's files are a choice switch with a Files label, and the new repository mirror reveal starts on the controls' edge
- an export archive is one flat line on the sheet's edge ✨ feat: every list that can grow has one live search with Exact and Aa beside it, forgiving typos and case by default (audit logs, admin users, replication, explore, a profile's repositories, server settings, and the CI log's find)
- placeholders name what each tab searches
- replication, explore and admin users are paged
- the audit log folds runs of one action by one person whatever the target, opens each fold in place to show every entry, and counts folded lines per page
- a numbered pager always keeps Previous, Next and seven page slots in place
- Explore has Repositories and Organizations tabs
- an export can be deleted
- regenerating recovery codes asks for the password and a code
- new repository, import, import history, new organization and your snippets show your profile tabs with counts, the import source is a choice in its form, and Notifications, Needs you and Review requests share one rail 🐛 fix: Send the verification link again shows only when mail can be sent
- letter avatars are drawn in the page, so lists of people and organizations no longer wait on image requests
- the replication filter and search options sit on the field's line
- a removed accent or background moves to the default ✅ test: measure.ts treats a list search as a tools row
45 changed files +2109 -701
- crates/forge-core/migrations/0073_sage_ink_default.sql +21 -0
- crates/forge-core/src/model.rs +4 -4
- crates/forge-core/src/store/migrate.rs +1 -0
- crates/forge-core/src/store/ui_prefs.rs +7 -7
- crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs +11 -11
- crates/forge-web-base/src/accent.rs +13 -12
- crates/forge-web-base/src/accent_palette.rs +123 -123
- crates/forge-web-base/src/i18n/accents.rs +4 -0
- crates/forge-web/assets/nav.js +135 -24
- crates/forge-web/src/exporter.rs +15 -0
- crates/forge-web/src/pages/admin_replication.rs +139 -4
- crates/forge-web/src/pages/admin_server.rs +19 -17
- crates/forge-web/src/pages/admin_users.rs +39 -48
- crates/forge-web/src/pages/audit_log.rs +326 -131
- crates/forge-web/src/pages/avatars.rs +30 -7
- crates/forge-web/src/pages/ci_job.rs +2 -0
- crates/forge-web/src/pages/ci_runs.rs +2 -0
- crates/forge-web/src/pages/explore.rs +200 -87
- crates/forge-web/src/pages/import.rs +49 -29
- crates/forge-web/src/pages/issue_parts.rs +2 -2
- crates/forge-web/src/pages/issues_list.rs +2 -2
- crates/forge-web/src/pages/needs_you.rs +14 -10
- crates/forge-web/src/pages/new_repo.rs +4 -2
- crates/forge-web/src/pages/notifications.rs +39 -21
- crates/forge-web/src/pages/org_new.rs +4 -2
- crates/forge-web/src/pages/profile.rs +89 -28
- crates/forge-web/src/pages/pulls_list.rs +2 -2
- crates/forge-web/src/pages/register.rs +4 -0
- crates/forge-web/src/pages/review_requests.rs +17 -13
- crates/forge-web/src/pages/settings_appearance.rs +10 -9
- crates/forge-web/src/pages/settings_export.rs +28 -12
- crates/forge-web/src/pages/settings_profile.rs +1 -1
- crates/forge-web/src/pages/settings_security.rs +67 -29
- crates/forge-web/src/pages/snippets.rs +12 -1
- crates/forge-web/src/views/find.rs +212 -0
- crates/forge-web/src/views/mod.rs +25 -14
- crates/forge-web/src/views/repo_list.rs +38 -17
- crates/forge-web/src/views/review_thread.rs +2 -2
- docs/ui-language.md +29 -9
- scripts/audit/measure.ts +2 -2
- style/_import.scss +0 -8
- style/_min.scss +2 -2
- style/_min_settings.scss +9 -8
- style/_one.scss +301 -1
- style/_one_people.scss +54 -0
crates/forge-core/migrations/0073_sage_ink_default.sqladded+21 -0
| @@ -0,0 +1,21 @@ | |||
| 1 | +-- Sage on Ink becomes the look of a new account. An account that never chose its colours moves | ||
| 2 | +-- with the default; one that chose keeps its choice. The Fern and Graphite bases are gone, so an | ||
| 3 | +-- account that chose one moves to Ink. SQLite cannot change a column's default in place, so each | ||
| 4 | +-- column is replaced. | ||
| 5 | +ALTER TABLE users RENAME COLUMN accent TO accent_old; | ||
| 6 | +ALTER TABLE users RENAME COLUMN accent_dark TO accent_dark_old; | ||
| 7 | +ALTER TABLE users RENAME COLUMN base_light TO base_light_old; | ||
| 8 | +ALTER TABLE users RENAME COLUMN base_dark TO base_dark_old; | ||
| 9 | +ALTER TABLE users ADD COLUMN accent TEXT NOT NULL DEFAULT 'sage'; | ||
| 10 | +ALTER TABLE users ADD COLUMN accent_dark TEXT NOT NULL DEFAULT 'sage'; | ||
| 11 | +ALTER TABLE users ADD COLUMN base_light TEXT NOT NULL DEFAULT 'ink'; | ||
| 12 | +ALTER TABLE users ADD COLUMN base_dark TEXT NOT NULL DEFAULT 'ink'; | ||
| 13 | +UPDATE users SET accent = accent_old, accent_dark = accent_dark_old, | ||
| 14 | + base_light = CASE WHEN base_light_old IN ('fern', 'graphite') THEN 'ink' ELSE base_light_old END, | ||
| 15 | + base_dark = CASE WHEN base_dark_old IN ('fern', 'graphite') THEN 'ink' ELSE base_dark_old END | ||
| 16 | +WHERE NOT (accent_old = 'ember' AND accent_dark_old = 'ember' | ||
| 17 | + AND base_light_old = 'anvil' AND base_dark_old = 'anvil'); | ||
| 18 | +ALTER TABLE users DROP COLUMN accent_old; | ||
| 19 | +ALTER TABLE users DROP COLUMN accent_dark_old; | ||
| 20 | +ALTER TABLE users DROP COLUMN base_light_old; | ||
| 21 | +ALTER TABLE users DROP COLUMN base_dark_old; | ||
crates/forge-core/src/model.rsmodified+4 -4
| @@ -48,13 +48,13 @@ pub struct User { | |||
| 48 | /// Language code, e.g. "en"; "auto" uses the instance default. | 48 | /// Language code, e.g. "en"; "auto" uses the instance default. |
| 49 | pub language: String, | 49 | pub language: String, |
| 50 | /// Accent colour for the light theme: the id of a palette in forge-web's `accent_palette.rs`. | 50 | /// Accent colour for the light theme: the id of a palette in forge-web's `accent_palette.rs`. |
| 51 | - /// "ember" is the default. | 51 | + /// "sage" is the default. |
| 52 | pub accent: String, | 52 | pub accent: String, |
| 53 | - /// Accent colour for the dark theme, chosen separately from `accent`. "ember" is the default. | 53 | + /// Accent colour for the dark theme, chosen separately from `accent`. "sage" is the default. |
| 54 | pub accent_dark: String, | 54 | pub accent_dark: String, |
| 55 | - /// Base (neutral background, surface and text) set for the light theme. "anvil" is the default. | 55 | + /// Base (neutral background, surface and text) set for the light theme. "ink" is the default. |
| 56 | pub base_light: String, | 56 | pub base_light: String, |
| 57 | - /// Base set for the dark theme. "anvil" is the default. | 57 | + /// Base set for the dark theme. "ink" is the default. |
| 58 | pub base_dark: String, | 58 | pub base_dark: String, |
| 59 | /// Which side the main shell sidebar sits on: "left" (the default) or "right". | 59 | /// Which side the main shell sidebar sits on: "left" (the default) or "right". |
| 60 | pub sidebar_side: String, | 60 | pub sidebar_side: String, |
crates/forge-core/src/store/migrate.rsmodified+1 -0
| @@ -118,6 +118,7 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ | |||
| 118 | ), | 118 | ), |
| 119 | (71, include_str!("../../migrations/0071_ci_job_steps.sql")), | 119 | (71, include_str!("../../migrations/0071_ci_job_steps.sql")), |
| 120 | (72, include_str!("../../migrations/0072_ember_anvil_default.sql")), | 120 | (72, include_str!("../../migrations/0072_ember_anvil_default.sql")), |
| 121 | + (73, include_str!("../../migrations/0073_sage_ink_default.sql")), | ||
| 121 | ]; | 122 | ]; |
| 122 | 123 | ||
| 123 | /// The highest migration version this binary knows about. | 124 | /// The highest migration version this binary knows about. |
crates/forge-core/src/store/ui_prefs.rsmodified+7 -7
| @@ -15,11 +15,11 @@ pub const AUTO: &str = "auto"; | |||
| 15 | 15 | ||
| 16 | /// The accent colour a new user gets. It must match the default palette in forge-web's | 16 | /// The accent colour a new user gets. It must match the default palette in forge-web's |
| 17 | /// `accent_palette.rs`, which a test there checks. | 17 | /// `accent_palette.rs`, which a test there checks. |
| 18 | -pub const DEFAULT_ACCENT: &str = "ember"; | 18 | +pub const DEFAULT_ACCENT: &str = "sage"; |
| 19 | 19 | ||
| 20 | /// The base colour set a new user gets, for both themes. It must match the default base in | 20 | /// The base colour set a new user gets, for both themes. It must match the default base in |
| 21 | /// forge-web's `accent_palette.rs`, which a test there checks. | 21 | /// forge-web's `accent_palette.rs`, which a test there checks. |
| 22 | -pub const DEFAULT_BASE: &str = "anvil"; | 22 | +pub const DEFAULT_BASE: &str = "ink"; |
| 23 | 23 | ||
| 24 | /// The sidebar sides, in the order the settings page lists them. | 24 | /// The sidebar sides, in the order the settings page lists them. |
| 25 | pub const SIDEBAR_SIDES: &[&str] = &["left", "right"]; | 25 | pub const SIDEBAR_SIDES: &[&str] = &["left", "right"]; |
| @@ -263,7 +263,7 @@ mod tests { | |||
| 263 | assert_eq!(user.base_light, DEFAULT_BASE, "case colours default"); | 263 | assert_eq!(user.base_light, DEFAULT_BASE, "case colours default"); |
| 264 | assert_eq!(user.base_dark, DEFAULT_BASE, "case colours default"); | 264 | assert_eq!(user.base_dark, DEFAULT_BASE, "case colours default"); |
| 265 | store | 265 | store |
| 266 | - .set_colours(&user.id, "ocean", "rose", "graphite", "ink") | 266 | + .set_colours(&user.id, "ocean", "rose", "heather", "ink") |
| 267 | .await | 267 | .await |
| 268 | .unwrap(); | 268 | .unwrap(); |
| 269 | let stored = store.user_by_id(&user.id).await.unwrap().unwrap(); | 269 | let stored = store.user_by_id(&user.id).await.unwrap().unwrap(); |
| @@ -274,12 +274,12 @@ mod tests { | |||
| 274 | stored.base_light.as_str(), | 274 | stored.base_light.as_str(), |
| 275 | stored.base_dark.as_str() | 275 | stored.base_dark.as_str() |
| 276 | ), | 276 | ), |
| 277 | - ("ocean", "rose", "graphite", "ink"), | 277 | + ("ocean", "rose", "heather", "ink"), |
| 278 | "case colours persisted" | 278 | "case colours persisted" |
| 279 | ); | 279 | ); |
| 280 | assert!( | 280 | assert!( |
| 281 | store | 281 | store |
| 282 | - .set_colours(&user.id, "ocean", "Rose", "graphite", "ink") | 282 | + .set_colours(&user.id, "ocean", "Rose", "heather", "ink") |
| 283 | .await | 283 | .await |
| 284 | .is_err(), | 284 | .is_err(), |
| 285 | "case colours casing" | 285 | "case colours casing" |
| @@ -293,7 +293,7 @@ mod tests { | |||
| 293 | ); | 293 | ); |
| 294 | assert!( | 294 | assert!( |
| 295 | store | 295 | store |
| 296 | - .set_colours(&user.id, "ocean", "rose", "graphite", "") | 296 | + .set_colours(&user.id, "ocean", "rose", "heather", "") |
| 297 | .await | 297 | .await |
| 298 | .is_err(), | 298 | .is_err(), |
| 299 | "case colours empty" | 299 | "case colours empty" |
| @@ -306,7 +306,7 @@ mod tests { | |||
| 306 | still.base_light.as_str(), | 306 | still.base_light.as_str(), |
| 307 | still.base_dark.as_str() | 307 | still.base_dark.as_str() |
| 308 | ), | 308 | ), |
| 309 | - ("ocean", "rose", "graphite", "ink"), | 309 | + ("ocean", "rose", "heather", "ink"), |
| 310 | "case colours unchanged" | 310 | "case colours unchanged" |
| 311 | ); | 311 | ); |
| 312 | 312 | ||
crates/forge-e2e/tests/e2e/ui_prefs_e2e.rsmodified+11 -11
| @@ -230,7 +230,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | |||
| 230 | let session = login(&env.http, "tahinli", PW).await; | 230 | let session = login(&env.http, "tahinli", PW).await; |
| 231 | 231 | ||
| 232 | let page = env.http.get("/settings/appearance", Some(&session)).await; | 232 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 233 | - let defaults = ["ember", "ember", "anvil", "anvil"].map(str::to_owned); | 233 | + let defaults = ["sage", "sage", "ink", "ink"].map(str::to_owned); |
| 234 | assert_eq!(checked_colours(&page.body), defaults.clone().map(Some)); | 234 | assert_eq!(checked_colours(&page.body), defaults.clone().map(Some)); |
| 235 | assert_eq!(html_colours(&page.body), defaults.map(Some)); | 235 | assert_eq!(html_colours(&page.body), defaults.map(Some)); |
| 236 | let csrf = input_value(&page.body, "csrf"); | 236 | let csrf = input_value(&page.body, "csrf"); |
| @@ -267,14 +267,14 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | |||
| 267 | ("csrf", &csrf), | 267 | ("csrf", &csrf), |
| 268 | ("theme", "light"), | 268 | ("theme", "light"), |
| 269 | ("language", "en"), | 269 | ("language", "en"), |
| 270 | - ("base_dark", "graphite"), | 270 | + ("base_dark", "heather"), |
| 271 | ], | 271 | ], |
| 272 | Some(&session), | 272 | Some(&session), |
| 273 | ) | 273 | ) |
| 274 | .await; | 274 | .await; |
| 275 | assert_eq!(saved.status, 303, "save: {}", saved.body); | 275 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 276 | let page = env.http.get("/settings/appearance", Some(&session)).await; | 276 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 277 | - let chosen = ["ocean", "plum", "ink", "graphite"].map(str::to_owned); | 277 | + let chosen = ["ocean", "plum", "ink", "heather"].map(str::to_owned); |
| 278 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); | 278 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 279 | assert_eq!(html_colours(&page.body), chosen.map(Some)); | 279 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 280 | 280 | ||
| @@ -300,7 +300,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | |||
| 300 | assert_ne!(res.status, 303, "bad {field} {bad:?} must not save"); | 300 | assert_ne!(res.status, 303, "bad {field} {bad:?} must not save"); |
| 301 | } | 301 | } |
| 302 | let page = env.http.get("/settings/appearance", Some(&session)).await; | 302 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 303 | - let chosen = ["ocean", "plum", "ink", "graphite"].map(str::to_owned); | 303 | + let chosen = ["ocean", "plum", "ink", "heather"].map(str::to_owned); |
| 304 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); | 304 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 305 | assert_eq!(html_colours(&page.body), chosen.map(Some)); | 305 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 306 | 306 | ||
| @@ -315,7 +315,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | |||
| 315 | ("language", "tr"), | 315 | ("language", "tr"), |
| 316 | ("accent_light", "hue-200"), | 316 | ("accent_light", "hue-200"), |
| 317 | ("accent_dark", "rose"), | 317 | ("accent_dark", "rose"), |
| 318 | - ("base_light", "graphite"), | 318 | + ("base_light", "heather"), |
| 319 | ("base_dark", "dusk"), | 319 | ("base_dark", "dusk"), |
| 320 | ], | 320 | ], |
| 321 | Some(&session), | 321 | Some(&session), |
| @@ -324,9 +324,9 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | |||
| 324 | assert_eq!(saved.status, 303, "save: {}", saved.body); | 324 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 325 | let page = env.http.get("/settings/appearance", Some(&session)).await; | 325 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 326 | // The Custom radio carries the hue at the default vividness; the stored id stays `hue-200`. | 326 | // The Custom radio carries the hue at the default vividness; the stored id stays `hue-200`. |
| 327 | - let checked = ["hue-200-v50", "rose", "graphite", "dusk"].map(str::to_owned); | 327 | + let checked = ["hue-200-v50", "rose", "heather", "dusk"].map(str::to_owned); |
| 328 | assert_eq!(checked_colours(&page.body), checked.map(Some)); | 328 | assert_eq!(checked_colours(&page.body), checked.map(Some)); |
| 329 | - let chosen = ["hue-200", "rose", "graphite", "dusk"].map(str::to_owned); | 329 | + let chosen = ["hue-200", "rose", "heather", "dusk"].map(str::to_owned); |
| 330 | assert_eq!(html_colours(&page.body), chosen.map(Some)); | 330 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 331 | 331 | ||
| 332 | // The newest accents and backgrounds save and show the same way. | 332 | // The newest accents and backgrounds save and show the same way. |
| @@ -341,14 +341,14 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { | |||
| 341 | ("accent_light", "sage"), | 341 | ("accent_light", "sage"), |
| 342 | ("accent_dark", "ocean"), | 342 | ("accent_dark", "ocean"), |
| 343 | ("base_light", "ink"), | 343 | ("base_light", "ink"), |
| 344 | - ("base_dark", "graphite"), | 344 | + ("base_dark", "heather"), |
| 345 | ], | 345 | ], |
| 346 | Some(&session), | 346 | Some(&session), |
| 347 | ) | 347 | ) |
| 348 | .await; | 348 | .await; |
| 349 | assert_eq!(saved.status, 303, "save: {}", saved.body); | 349 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 350 | let page = env.http.get("/settings/appearance", Some(&session)).await; | 350 | let page = env.http.get("/settings/appearance", Some(&session)).await; |
| 351 | - let chosen = ["sage", "ocean", "ink", "graphite"].map(str::to_owned); | 351 | + let chosen = ["sage", "ocean", "ink", "heather"].map(str::to_owned); |
| 352 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); | 352 | assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); |
| 353 | assert_eq!(html_colours(&page.body), chosen.map(Some)); | 353 | assert_eq!(html_colours(&page.body), chosen.map(Some)); |
| 354 | } | 354 | } |
| @@ -370,7 +370,7 @@ async fn a_save_without_colour_fields_keeps_the_stored_colours() { | |||
| 370 | ("language", "en"), | 370 | ("language", "en"), |
| 371 | ("accent_light", "rose"), | 371 | ("accent_light", "rose"), |
| 372 | ("accent_dark", "ocean"), | 372 | ("accent_dark", "ocean"), |
| 373 | - ("base_light", "fern"), | 373 | + ("base_light", "blush"), |
| 374 | ("base_dark", "dusk"), | 374 | ("base_dark", "dusk"), |
| 375 | ], | 375 | ], |
| 376 | Some(&session), | 376 | Some(&session), |
| @@ -378,7 +378,7 @@ async fn a_save_without_colour_fields_keeps_the_stored_colours() { | |||
| 378 | .await; | 378 | .await; |
| 379 | assert_eq!(saved.status, 303, "save: {}", saved.body); | 379 | assert_eq!(saved.status, 303, "save: {}", saved.body); |
| 380 | let before = env.http.get("/settings/appearance", Some(&session)).await; | 380 | let before = env.http.get("/settings/appearance", Some(&session)).await; |
| 381 | - let stored = ["rose", "ocean", "fern", "dusk"].map(str::to_owned); | 381 | + let stored = ["rose", "ocean", "blush", "dusk"].map(str::to_owned); |
| 382 | assert_eq!(html_colours(&before.body), stored.clone().map(Some)); | 382 | assert_eq!(html_colours(&before.body), stored.clone().map(Some)); |
| 383 | 383 | ||
| 384 | let saved = env | 384 | let saved = env |
crates/forge-web-base/src/accent.rsmodified+13 -12
| @@ -310,11 +310,11 @@ mod tests { | |||
| 310 | fn the_presets_are_offered_in_picker_order_and_removed_ids_are_not() { | 310 | fn the_presets_are_offered_in_picker_order_and_removed_ids_are_not() { |
| 311 | assert_eq!( | 311 | assert_eq!( |
| 312 | ids().collect::<Vec<_>>(), | 312 | ids().collect::<Vec<_>>(), |
| 313 | - ["ember", "sage", "ocean", "plum", "rose"] | 313 | + ["sage", "ember", "ocean", "plum", "rose"] |
| 314 | ); | 314 | ); |
| 315 | assert_eq!( | 315 | assert_eq!( |
| 316 | base_ids().collect::<Vec<_>>(), | 316 | base_ids().collect::<Vec<_>>(), |
| 317 | - ["anvil", "fern", "graphite", "dusk", "ink"] | 317 | + ["ink", "anvil", "dusk", "heather", "blush"] |
| 318 | ); | 318 | ); |
| 319 | for id in [ | 319 | for id in [ |
| 320 | "ochre", | 320 | "ochre", |
| @@ -327,7 +327,7 @@ mod tests { | |||
| 327 | ] { | 327 | ] { |
| 328 | assert!(!is_offered(id), "{id}"); | 328 | assert!(!is_offered(id), "{id}"); |
| 329 | } | 329 | } |
| 330 | - for id in ["stone", "mist", "Fern", "dune", "slate-blue", "spark"] { | 330 | + for id in ["stone", "mist", "fern", "graphite", "dune", "slate-blue", "spark"] { |
| 331 | assert!(!is_offered_base(id), "{id}"); | 331 | assert!(!is_offered_base(id), "{id}"); |
| 332 | } | 332 | } |
| 333 | } | 333 | } |
| @@ -345,7 +345,8 @@ mod tests { | |||
| 345 | assert_eq!(resolve_base("ink").id, "ink"); | 345 | assert_eq!(resolve_base("ink").id, "ink"); |
| 346 | assert_eq!(resolve_base("removed-base").id, BASE_DEFAULT); | 346 | assert_eq!(resolve_base("removed-base").id, BASE_DEFAULT); |
| 347 | assert_eq!(base_id("mist"), BASE_DEFAULT); | 347 | assert_eq!(base_id("mist"), BASE_DEFAULT); |
| 348 | - assert_eq!(base_id("graphite"), "graphite"); | 348 | + assert_eq!(base_id("heather"), "heather"); |
| 349 | + assert_eq!(base_id("graphite"), BASE_DEFAULT); | ||
| 349 | } | 350 | } |
| 350 | 351 | ||
| 351 | #[test] | 352 | #[test] |
| @@ -383,7 +384,7 @@ mod tests { | |||
| 383 | assert_eq!(preset_accent_hue("plum"), Some(300)); | 384 | assert_eq!(preset_accent_hue("plum"), Some(300)); |
| 384 | assert_eq!(preset_accent_hue("fern"), None); | 385 | assert_eq!(preset_accent_hue("fern"), None); |
| 385 | assert_eq!(preset_accent_hue("hue-5"), None); | 386 | assert_eq!(preset_accent_hue("hue-5"), None); |
| 386 | - assert!(preset_base_hue("fern").is_some()); | 387 | + assert!(preset_base_hue("blush").is_some()); |
| 387 | assert!(preset_base_hue("dusk").is_some()); | 388 | assert!(preset_base_hue("dusk").is_some()); |
| 388 | assert_eq!(preset_base_hue("sage"), None); | 389 | assert_eq!(preset_base_hue("sage"), None); |
| 389 | } | 390 | } |
| @@ -397,10 +398,10 @@ mod tests { | |||
| 397 | accent_tokens(215, 50, false).accent | 398 | accent_tokens(215, 50, false).accent |
| 398 | ); | 399 | ); |
| 399 | assert_eq!(swatch("hue-215", true), accent_tokens(215, 50, true).accent); | 400 | assert_eq!(swatch("hue-215", true), accent_tokens(215, 50, true).accent); |
| 400 | - // A removed id falls back to the default, Ember. | 401 | + // A removed id falls back to the default. |
| 401 | - assert_eq!(swatch("terracotta", false), swatch("ember", false)); | 402 | + assert_eq!(swatch("terracotta", false), swatch(DEFAULT, false)); |
| 402 | - let (bg, text) = base_swatch("fern", false); | 403 | + let (bg, text) = base_swatch("blush", false); |
| 403 | - assert_eq!((bg.as_str(), text.as_str()), ("#F6F8F5", "#1E2420")); | 404 | + assert_eq!((bg.as_str(), text.as_str()), ("#F5EBEC", "#2B191C")); |
| 404 | let (bg, text) = base_swatch("hue-215", true); | 405 | let (bg, text) = base_swatch("hue-215", true); |
| 405 | assert_eq!(bg, base_tokens(215, 30, true).bg); | 406 | assert_eq!(bg, base_tokens(215, 30, true).bg); |
| 406 | assert_eq!(text, base_tokens(215, 30, true).text); | 407 | assert_eq!(text, base_tokens(215, 30, true).text); |
| @@ -408,10 +409,10 @@ mod tests { | |||
| 408 | 409 | ||
| 409 | #[test] | 410 | #[test] |
| 410 | fn the_custom_stylesheet_is_linked_only_when_a_hue_is_chosen() { | 411 | fn the_custom_stylesheet_is_linked_only_when_a_hue_is_chosen() { |
| 411 | - assert_eq!(custom_css_href("sage", "plum", "fern", "ink"), None); | 412 | + assert_eq!(custom_css_href("sage", "plum", "blush", "ink"), None); |
| 412 | assert_eq!( | 413 | assert_eq!( |
| 413 | - custom_css_href("hue-215", "plum", "fern", "hue-7").as_deref(), | 414 | + custom_css_href("hue-215", "plum", "blush", "hue-7").as_deref(), |
| 414 | - Some("/theme/custom.css?al=hue-215&ad=plum&bl=fern&bd=hue-7") | 415 | + Some("/theme/custom.css?al=hue-215&ad=plum&bl=blush&bd=hue-7") |
| 415 | ); | 416 | ); |
| 416 | assert_eq!( | 417 | assert_eq!( |
| 417 | custom_css_href("sage", "sage", "ink", "hue-0").as_deref(), | 418 | custom_css_href("sage", "sage", "ink", "hue-0").as_deref(), |
crates/forge-web-base/src/accent_palette.rsmodified+123 -123
| @@ -27,7 +27,7 @@ pub struct Palette { | |||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /// The palette used when none is stored, and for anonymous visitors. It must be `PALETTES[0]`. | 29 | /// The palette used when none is stored, and for anonymous visitors. It must be `PALETTES[0]`. |
| 30 | -pub const DEFAULT: &str = "ember"; | 30 | +pub const DEFAULT: &str = "sage"; |
| 31 | 31 | ||
| 32 | /// One token: the custom property it becomes and the field of `Tokens` that holds its value. | 32 | /// One token: the custom property it becomes and the field of `Tokens` that holds its value. |
| 33 | pub struct TokenVar { | 33 | pub struct TokenVar { |
| @@ -83,34 +83,6 @@ pub const TOKEN_VARS: &[TokenVar] = &[ | |||
| 83 | /// here: style/_heatmap.scss mixes them from `--accent`/`--accent-ink` and the base's surface, | 83 | /// here: style/_heatmap.scss mixes them from `--accent`/`--accent-ink` and the base's surface, |
| 84 | /// so they follow every accent and base. | 84 | /// so they follow every accent and base. |
| 85 | pub const PALETTES: &[Palette] = &[ | 85 | pub const PALETTES: &[Palette] = &[ |
| 86 | - // Ember: iron at working heat, a soft red-orange; copper in light. | ||
| 87 | - Palette { | ||
| 88 | - id: "ember", | ||
| 89 | - light: Tokens { | ||
| 90 | - accent: "#B44D1A", | ||
| 91 | - accent_ink: "#8F3A12", | ||
| 92 | - accent_soft: "#F8E9DF", | ||
| 93 | - accent_text: "#FFFFFF", | ||
| 94 | - focus: "#8F3A12", | ||
| 95 | - public_bg: "#F9E4D6", | ||
| 96 | - public_text: "#8F3A12", | ||
| 97 | - note: "#8F3A12", | ||
| 98 | - hunk_bg: "#FBF0E8", | ||
| 99 | - hunk_text: "#883611", | ||
| 100 | - }, | ||
| 101 | - dark: Tokens { | ||
| 102 | - accent: "#E8894A", | ||
| 103 | - accent_ink: "#FFB27A", | ||
| 104 | - accent_soft: "#3A2518", | ||
| 105 | - accent_text: "#1A0E06", | ||
| 106 | - focus: "#FFB27A", | ||
| 107 | - public_bg: "#3A2416", | ||
| 108 | - public_text: "#FFC69A", | ||
| 109 | - note: "#FFB27A", | ||
| 110 | - hunk_bg: "#24180F", | ||
| 111 | - hunk_text: "#F0A066", | ||
| 112 | - }, | ||
| 113 | - }, | ||
| 114 | // Sage: the original forge colour. | 86 | // Sage: the original forge colour. |
| 115 | Palette { | 87 | Palette { |
| 116 | id: "sage", | 88 | id: "sage", |
| @@ -141,6 +113,34 @@ pub const PALETTES: &[Palette] = &[ | |||
| 141 | hunk_text: "#B3C385", | 113 | hunk_text: "#B3C385", |
| 142 | }, | 114 | }, |
| 143 | }, | 115 | }, |
| 116 | + // Ember: iron at working heat, a soft red-orange; copper in light. | ||
| 117 | + Palette { | ||
| 118 | + id: "ember", | ||
| 119 | + light: Tokens { | ||
| 120 | + accent: "#B44D1A", | ||
| 121 | + accent_ink: "#8F3A12", | ||
| 122 | + accent_soft: "#F8E9DF", | ||
| 123 | + accent_text: "#FFFFFF", | ||
| 124 | + focus: "#8F3A12", | ||
| 125 | + public_bg: "#F9E4D6", | ||
| 126 | + public_text: "#8F3A12", | ||
| 127 | + note: "#8F3A12", | ||
| 128 | + hunk_bg: "#FBF0E8", | ||
| 129 | + hunk_text: "#883611", | ||
| 130 | + }, | ||
| 131 | + dark: Tokens { | ||
| 132 | + accent: "#E8894A", | ||
| 133 | + accent_ink: "#FFB27A", | ||
| 134 | + accent_soft: "#3A2518", | ||
| 135 | + accent_text: "#1A0E06", | ||
| 136 | + focus: "#FFB27A", | ||
| 137 | + public_bg: "#3A2416", | ||
| 138 | + public_text: "#FFC69A", | ||
| 139 | + note: "#FFB27A", | ||
| 140 | + hunk_bg: "#24180F", | ||
| 141 | + hunk_text: "#F0A066", | ||
| 142 | + }, | ||
| 143 | + }, | ||
| 144 | // Blue, clear and cool. | 144 | // Blue, clear and cool. |
| 145 | Palette { | 145 | Palette { |
| 146 | id: "ocean", | 146 | id: "ocean", |
| @@ -253,7 +253,7 @@ pub struct Base { | |||
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | /// The base used when none is stored, and for anonymous visitors. It must be `BASES[0]`. | 255 | /// The base used when none is stored, and for anonymous visitors. It must be `BASES[0]`. |
| 256 | -pub const BASE_DEFAULT: &str = "anvil"; | 256 | +pub const BASE_DEFAULT: &str = "ink"; |
| 257 | 257 | ||
| 258 | /// One base token: the custom property it becomes and the field of `BaseTokens` that holds its | 258 | /// One base token: the custom property it becomes and the field of `BaseTokens` that holds its |
| 259 | /// value. | 259 | /// value. |
| @@ -314,9 +314,42 @@ pub const BASE_TOKEN_VARS: &[BaseTokenVar] = &[ | |||
| 314 | }, | 314 | }, |
| 315 | ]; | 315 | ]; |
| 316 | 316 | ||
| 317 | -/// Every base on offer, in the order the picker lists them. `fern` is the original forge | 317 | +/// Every base on offer, in the order the picker lists them: the default first, then each in the |
| 318 | -/// neutral set. | 318 | +/// column of the accent of its hue (Anvil under Ember, Dusk under Ocean, Heather under Plum, Blush |
| 319 | +/// under Rose). Ink's faint olive tint sits with Sage. | ||
| 319 | pub const BASES: &[Base] = &[ | 320 | pub const BASES: &[Base] = &[ |
| 321 | + // Ink: crisp white in light, near-black in dark. | ||
| 322 | + Base { | ||
| 323 | + id: "ink", | ||
| 324 | + light: BaseTokens { | ||
| 325 | + bg: "#FCFCFB", | ||
| 326 | + surface: "#FFFFFF", | ||
| 327 | + surface_2: "#F2F2F0", | ||
| 328 | + text: "#111111", | ||
| 329 | + text_2: "#333333", | ||
| 330 | + muted: "#5F5F5C", | ||
| 331 | + border: "#E3E3E0", | ||
| 332 | + border_strong: "#C9C9C5", | ||
| 333 | + code_bg: "#F2F2F0", | ||
| 334 | + private_bg: "#F2F2F0", | ||
| 335 | + private_text: "#333333", | ||
| 336 | + ln_text: "#5F5F5C", | ||
| 337 | + }, | ||
| 338 | + dark: BaseTokens { | ||
| 339 | + bg: "#000000", | ||
| 340 | + surface: "#0B0B0B", | ||
| 341 | + surface_2: "#141414", | ||
| 342 | + text: "#F2F2F0", | ||
| 343 | + text_2: "#CFCFCC", | ||
| 344 | + muted: "#9C9C98", | ||
| 345 | + border: "#242424", | ||
| 346 | + border_strong: "#353535", | ||
| 347 | + code_bg: "#141414", | ||
| 348 | + private_bg: "#141414", | ||
| 349 | + private_text: "#CFCFCC", | ||
| 350 | + ln_text: "#9C9C98", | ||
| 351 | + }, | ||
| 352 | + }, | ||
| 320 | // Anvil: warm soot and cooled steel in dark, ash in light. | 353 | // Anvil: warm soot and cooled steel in dark, ash in light. |
| 321 | Base { | 354 | Base { |
| 322 | id: "anvil", | 355 | id: "anvil", |
| @@ -349,71 +382,6 @@ pub const BASES: &[Base] = &[ | |||
| 349 | ln_text: "#AAA69D", | 382 | ln_text: "#AAA69D", |
| 350 | }, | 383 | }, |
| 351 | }, | 384 | }, |
| 352 | - // Fern: the original forge neutrals, green-tinted in light and slate in dark. | ||
| 353 | - Base { | ||
| 354 | - id: "fern", | ||
| 355 | - light: BaseTokens { | ||
| 356 | - bg: "#F6F8F5", | ||
| 357 | - surface: "#FFFFFF", | ||
| 358 | - surface_2: "#EEF2EC", | ||
| 359 | - text: "#1E2420", | ||
| 360 | - text_2: "#3A433D", | ||
| 361 | - muted: "#667068", | ||
| 362 | - border: "#DDE3DB", | ||
| 363 | - border_strong: "#C5CFC3", | ||
| 364 | - code_bg: "#EEF2EC", | ||
| 365 | - private_bg: "#EEF2EC", | ||
| 366 | - private_text: "#3A433D", | ||
| 367 | - ln_text: "#646D65", | ||
| 368 | - }, | ||
| 369 | - // Dark is cool slate: a green-tinted near-black looked swampy. | ||
| 370 | - dark: BaseTokens { | ||
| 371 | - bg: "#131618", | ||
| 372 | - surface: "#191D20", | ||
| 373 | - surface_2: "#20252A", | ||
| 374 | - text: "#E3E8EA", | ||
| 375 | - text_2: "#C3CACD", | ||
| 376 | - muted: "#96A0A5", | ||
| 377 | - border: "#283035", | ||
| 378 | - border_strong: "#384146", | ||
| 379 | - code_bg: "#1C2125", | ||
| 380 | - private_bg: "#20252A", | ||
| 381 | - private_text: "#C3CACD", | ||
| 382 | - ln_text: "#8A959A", | ||
| 383 | - }, | ||
| 384 | - }, | ||
| 385 | - // Graphite: a cool neutral grey, flatter than the warmer neutrals. | ||
| 386 | - Base { | ||
| 387 | - id: "graphite", | ||
| 388 | - light: BaseTokens { | ||
| 389 | - bg: "#E9EAEC", | ||
| 390 | - surface: "#F9FAFB", | ||
| 391 | - surface_2: "#DCDEE2", | ||
| 392 | - text: "#17191C", | ||
| 393 | - text_2: "#33373D", | ||
| 394 | - muted: "#5C626B", | ||
| 395 | - border: "#CFD3D9", | ||
| 396 | - border_strong: "#B5BBC3", | ||
| 397 | - code_bg: "#DCDEE2", | ||
| 398 | - private_bg: "#DCDEE2", | ||
| 399 | - private_text: "#33373D", | ||
| 400 | - ln_text: "#545A63", | ||
| 401 | - }, | ||
| 402 | - dark: BaseTokens { | ||
| 403 | - bg: "#1A1B1E", | ||
| 404 | - surface: "#222428", | ||
| 405 | - surface_2: "#2B2D32", | ||
| 406 | - text: "#E6E8EB", | ||
| 407 | - text_2: "#C8CCD2", | ||
| 408 | - muted: "#9499A2", | ||
| 409 | - border: "#33363C", | ||
| 410 | - border_strong: "#44484F", | ||
| 411 | - code_bg: "#2B2D32", | ||
| 412 | - private_bg: "#2B2D32", | ||
| 413 | - private_text: "#C8CCD2", | ||
| 414 | - ln_text: "#9499A2", | ||
| 415 | - }, | ||
| 416 | - }, | ||
| 417 | // Dusk: cool blue-grey, a deeper blue-tinted neutral. | 385 | // Dusk: cool blue-grey, a deeper blue-tinted neutral. |
| 418 | Base { | 386 | Base { |
| 419 | id: "dusk", | 387 | id: "dusk", |
| @@ -446,36 +414,68 @@ pub const BASES: &[Base] = &[ | |||
| 446 | ln_text: "#8F9BB0", | 414 | ln_text: "#8F9BB0", |
| 447 | }, | 415 | }, |
| 448 | }, | 416 | }, |
| 449 | - // Ink: crisp white in light, near-black in dark. | 417 | + // Heather: violet-grey, Dusk turned to the hue of Plum. |
| 450 | Base { | 418 | Base { |
| 451 | - id: "ink", | 419 | + id: "heather", |
| 452 | light: BaseTokens { | 420 | light: BaseTokens { |
| 453 | - bg: "#FCFCFB", | 421 | + bg: "#EEECF4", |
| 454 | - surface: "#FFFFFF", | 422 | + surface: "#FAF9FD", |
| 455 | - surface_2: "#F2F2F0", | 423 | + surface_2: "#E4E0EC", |
| 456 | - text: "#111111", | 424 | + text: "#211B2B", |
| 457 | - text_2: "#333333", | 425 | + text_2: "#40384F", |
| 458 | - muted: "#5F5F5C", | 426 | + muted: "#665E77", |
| 459 | - border: "#E3E3E0", | 427 | + border: "#D6D1E1", |
| 460 | - border_strong: "#C9C9C5", | 428 | + border_strong: "#BDB6CB", |
| 461 | - code_bg: "#F2F2F0", | 429 | + code_bg: "#E4E0EC", |
| 462 | - private_bg: "#F2F2F0", | 430 | + private_bg: "#E4E0EC", |
| 463 | - private_text: "#333333", | 431 | + private_text: "#40384F", |
| 464 | - ln_text: "#5F5F5C", | 432 | + ln_text: "#605870", |
| 465 | }, | 433 | }, |
| 466 | dark: BaseTokens { | 434 | dark: BaseTokens { |
| 467 | - bg: "#000000", | 435 | + bg: "#110E18", |
| 468 | - surface: "#0B0B0B", | 436 | + surface: "#1B1625", |
| 469 | - surface_2: "#141414", | 437 | + surface_2: "#251F30", |
| 470 | - text: "#F2F2F0", | 438 | + text: "#E8E4F0", |
| 471 | - text_2: "#CFCFCC", | 439 | + text_2: "#CAC5D7", |
| 472 | - muted: "#9C9C98", | 440 | + muted: "#9D96AD", |
| 473 | - border: "#242424", | 441 | + border: "#2F293B", |
| 474 | - border_strong: "#353535", | 442 | + border_strong: "#3F384E", |
| 475 | - code_bg: "#141414", | 443 | + code_bg: "#251F30", |
| 476 | - private_bg: "#141414", | 444 | + private_bg: "#251F30", |
| 477 | - private_text: "#CFCFCC", | 445 | + private_text: "#CAC5D7", |
| 478 | - ln_text: "#9C9C98", | 446 | + ln_text: "#9D96AD", |
| 447 | + }, | ||
| 448 | + }, | ||
| 449 | + // Blush: rose-grey, Dusk turned to the hue of Rose. | ||
| 450 | + Base { | ||
| 451 | + id: "blush", | ||
| 452 | + light: BaseTokens { | ||
| 453 | + bg: "#F5EBEC", | ||
| 454 | + surface: "#FDF9F9", | ||
| 455 | + surface_2: "#EDDEE0", | ||
| 456 | + text: "#2B191C", | ||
| 457 | + text_2: "#4F3438", | ||
| 458 | + muted: "#77595E", | ||
| 459 | + border: "#E2CED1", | ||
| 460 | + border_strong: "#CCB2B6", | ||
| 461 | + code_bg: "#EDDEE0", | ||
| 462 | + private_bg: "#EDDEE0", | ||
| 463 | + private_text: "#4F3438", | ||
| 464 | + ln_text: "#715358", | ||
| 465 | + }, | ||
| 466 | + dark: BaseTokens { | ||
| 467 | + bg: "#180C0E", | ||
| 468 | + surface: "#251316", | ||
| 469 | + surface_2: "#301C20", | ||
| 470 | + text: "#F0E2E4", | ||
| 471 | + text_2: "#D8C2C5", | ||
| 472 | + muted: "#AE9296", | ||
| 473 | + border: "#3C2529", | ||
| 474 | + border_strong: "#4E3438", | ||
| 475 | + code_bg: "#301C20", | ||
| 476 | + private_bg: "#301C20", | ||
| 477 | + private_text: "#D8C2C5", | ||
| 478 | + ln_text: "#AE9296", | ||
| 479 | }, | 479 | }, |
| 480 | }, | 480 | }, |
| 481 | ]; | 481 | ]; |
crates/forge-web-base/src/i18n/accents.rsmodified+4 -0
| @@ -39,6 +39,10 @@ pub fn base_name(lang: Lang, id: &str) -> &'static str { | |||
| 39 | ("dusk", Lang::Tr) => "Alacakaranlık", | 39 | ("dusk", Lang::Tr) => "Alacakaranlık", |
| 40 | ("graphite", Lang::En) => "Graphite", | 40 | ("graphite", Lang::En) => "Graphite", |
| 41 | ("graphite", Lang::Tr) => "Grafit", | 41 | ("graphite", Lang::Tr) => "Grafit", |
| 42 | + ("heather", Lang::En) => "Heather", | ||
| 43 | + ("heather", Lang::Tr) => "Funda", | ||
| 44 | + ("blush", Lang::En) => "Blush", | ||
| 45 | + ("blush", Lang::Tr) => "Allık", | ||
| 42 | ("anvil", Lang::En) => "Anvil", | 46 | ("anvil", Lang::En) => "Anvil", |
| 43 | ("anvil", Lang::Tr) => "Örs", | 47 | ("anvil", Lang::Tr) => "Örs", |
| 44 | _ => "", | 48 | _ => "", |
crates/forge-web/assets/nav.jsmodified+135 -24
| @@ -1230,7 +1230,10 @@ | |||
| 1230 | dest.search = q ? '?' + q : ''; | 1230 | dest.search = q ? '?' + q : ''; |
| 1231 | // Enter in a live field on its own results page runs the search now and leaves the reader typing. | 1231 | // Enter in a live field on its own results page runs the search now and leaves the reader typing. |
| 1232 | var typing = document.activeElement; | 1232 | var typing = document.activeElement; |
| 1233 | - if (typing && typing.form === form && typing.hasAttribute('data-live-search') && url.pathname === location.pathname) { | 1233 | + // A filter or option ticked in a form that searches live refreshes in place too. |
| 1234 | + var liveForm = !!form.querySelector('[data-live-search]'); | ||
| 1235 | + if (typing && typing.form === form && url.pathname === location.pathname && | ||
| 1236 | + (typing.hasAttribute('data-live-search') || (liveForm && typing.hasAttribute('data-autosubmit')))) { | ||
| 1234 | clearTimeout(searchTimer); | 1237 | clearTimeout(searchTimer); |
| 1235 | searchTimer = null; | 1238 | searchTimer = null; |
| 1236 | if (dest.pathname + dest.search === shown) { pending.delete(form); return; } | 1239 | if (dest.pathname + dest.search === shown) { pending.delete(form); return; } |
| @@ -2292,6 +2295,8 @@ | |||
| 2292 | // through the same feed. All text is set with textContent, never as HTML. | 2295 | // through the same feed. All text is set with textContent, never as HTML. |
| 2293 | var logQuery = ''; // the search text survives a live swap of the page | 2296 | var logQuery = ''; // the search text survives a live swap of the page |
| 2294 | var LOG_MAX_MARKS = 2000; | 2297 | var LOG_MAX_MARKS = 2000; |
| 2298 | + var logExact = false; // the Exact and Aa options survive a live swap too | ||
| 2299 | + var logCase = false; | ||
| 2295 | 2300 | ||
| 2296 | function ansiState() { return { fg: null, bg: null, b: false, d: false, i: false, u: false, v: false }; } | 2301 | function ansiState() { return { fg: null, bg: null, b: false, d: false, i: false, u: false, v: false }; } |
| 2297 | 2302 | ||
| @@ -2504,36 +2509,126 @@ | |||
| 2504 | if (bar) { bar.classList.toggle('has-hits', !!text && !none); } | 2509 | if (bar) { bar.classList.toggle('has-hits', !!text && !none); } |
| 2505 | } | 2510 | } |
| 2506 | 2511 | ||
| 2507 | - // Highlights every match of `q` (case-insensitive) in the log and selects the one at `keep`. | 2512 | + // Slips a typed word may have, as views/find.rs counts them: none under four letters, one up to seven, two after. |
| 2513 | + function logSlips(len) { return len <= 3 ? 0 : (len <= 7 ? 1 : 2); } | ||
| 2514 | + | ||
| 2515 | + // Edits (insert, delete, change, swap two neighbours) between two words given as character arrays. | ||
| 2516 | + function logDistance(a, b) { | ||
| 2517 | + if (Math.abs(a.length - b.length) > 2) { return 99; } | ||
| 2518 | + var n = a.length, m = b.length, d = [], i, j; | ||
| 2519 | + for (i = 0; i <= n; i++) { d.push([i]); } | ||
| 2520 | + for (j = 1; j <= m; j++) { d[0][j] = j; } | ||
| 2521 | + for (i = 1; i <= n; i++) { | ||
| 2522 | + for (j = 1; j <= m; j++) { | ||
| 2523 | + var best = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)); | ||
| 2524 | + if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) { best = Math.min(best, d[i - 2][j - 2] + 1); } | ||
| 2525 | + d[i][j] = best; | ||
| 2526 | + } | ||
| 2527 | + } | ||
| 2528 | + return d[n][m]; | ||
| 2529 | + } | ||
| 2530 | + | ||
| 2531 | + // True when a typed word is close to a word of the line, or to the start of it as long as the word. | ||
| 2532 | + function logNear(word, token) { | ||
| 2533 | + var slips = logSlips(word.length); | ||
| 2534 | + if (!slips) { return false; } | ||
| 2535 | + if (logDistance(word, token) <= slips) { return true; } | ||
| 2536 | + return token.length > word.length && logDistance(word, token.slice(0, word.length)) <= slips; | ||
| 2537 | + } | ||
| 2538 | + | ||
| 2539 | + // Every place `part` occurs in `hay`, as [start, end) spans. | ||
| 2540 | + function logOccur(hay, part, out) { | ||
| 2541 | + var from = 0, at; | ||
| 2542 | + while (part && (at = hay.indexOf(part, from)) >= 0) { | ||
| 2543 | + out.push([at, at + part.length]); | ||
| 2544 | + from = at + part.length; | ||
| 2545 | + } | ||
| 2546 | + return out; | ||
| 2547 | + } | ||
| 2548 | + | ||
| 2549 | + // The spans of one line that match the search, or [] when it does not. Mirrors views/find.rs: the | ||
| 2550 | + // whole search as one piece; unless Exact, every typed word as typed (Aa) or, by default, every word | ||
| 2551 | + // in the line or close to one of its words (the near word is the span). | ||
| 2552 | + function logSpans(text, q, exact, cas) { | ||
| 2553 | + var hay = cas ? text : text.toLowerCase(); | ||
| 2554 | + var needle = cas ? q : q.toLowerCase(); | ||
| 2555 | + if (hay.indexOf(needle) >= 0) { return logOccur(hay, needle, []); } | ||
| 2556 | + if (exact) { return []; } | ||
| 2557 | + var words = needle.match(/[\p{L}\p{N}]+/gu) || []; | ||
| 2558 | + if (!words.length) { return []; } | ||
| 2559 | + // Word by word, each typed word must start one of the line's words (or, without Aa, be near | ||
| 2560 | + // one), so a short word such as "1" does not match every line with a 1 in it. | ||
| 2561 | + var spans = [], w, tokens, i, m, re, found, typed; | ||
| 2562 | + tokens = []; | ||
| 2563 | + re = /[\p{L}\p{N}]+/gu; | ||
| 2564 | + while ((m = re.exec(hay))) { tokens.push([m.index, m.index + m[0].length, m[0], Array.from(m[0])]); } | ||
| 2565 | + for (w = 0; w < words.length; w++) { | ||
| 2566 | + typed = Array.from(words[w]); | ||
| 2567 | + found = false; | ||
| 2568 | + for (i = 0; i < tokens.length; i++) { | ||
| 2569 | + if (tokens[i][2].indexOf(words[w]) === 0) { | ||
| 2570 | + spans.push([tokens[i][0], tokens[i][0] + words[w].length]); found = true; | ||
| 2571 | + } else if (!cas && logNear(typed, tokens[i][3])) { | ||
| 2572 | + spans.push([tokens[i][0], tokens[i][1]]); found = true; | ||
| 2573 | + } | ||
| 2574 | + } | ||
| 2575 | + if (!found) { return []; } | ||
| 2576 | + } | ||
| 2577 | + return spans; | ||
| 2578 | + } | ||
| 2579 | + | ||
| 2580 | + // Sorts spans and joins the ones that overlap, so one place is one mark. | ||
| 2581 | + function logMerge(spans) { | ||
| 2582 | + var sorted = spans.slice().sort(function (x, y) { return x[0] - y[0] || x[1] - y[1]; }); | ||
| 2583 | + var out = []; | ||
| 2584 | + for (var i = 0; i < sorted.length; i++) { | ||
| 2585 | + var last = out[out.length - 1]; | ||
| 2586 | + if (last && sorted[i][0] < last[1]) { last[1] = Math.max(last[1], sorted[i][1]); } | ||
| 2587 | + else { out.push([sorted[i][0], sorted[i][1]]); } | ||
| 2588 | + } | ||
| 2589 | + return out; | ||
| 2590 | + } | ||
| 2591 | + | ||
| 2592 | + // Wraps each span of a line's text in a mark, across the line's text nodes. | ||
| 2593 | + function logMark(el, spans) { | ||
| 2594 | + var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT); | ||
| 2595 | + var nodes = []; | ||
| 2596 | + while (walker.nextNode()) { nodes.push(walker.currentNode); } | ||
| 2597 | + var base = 0; | ||
| 2598 | + for (var k = 0; k < nodes.length; k++) { | ||
| 2599 | + var node = nodes[k]; | ||
| 2600 | + var end = base + node.data.length; | ||
| 2601 | + var cuts = []; | ||
| 2602 | + for (var s = 0; s < spans.length; s++) { | ||
| 2603 | + var a = Math.max(spans[s][0], base), b = Math.min(spans[s][1], end); | ||
| 2604 | + if (a < b) { cuts.push([a - base, b - base]); } | ||
| 2605 | + } | ||
| 2606 | + for (var c = cuts.length - 1; c >= 0; c--) { | ||
| 2607 | + var mid = node.splitText(cuts[c][0]); | ||
| 2608 | + mid.splitText(cuts[c][1] - cuts[c][0]); | ||
| 2609 | + var mark = document.createElement('mark'); | ||
| 2610 | + mark.className = 'lm'; | ||
| 2611 | + mid.parentNode.replaceChild(mark, mid); | ||
| 2612 | + mark.appendChild(mid); | ||
| 2613 | + } | ||
| 2614 | + base = end; | ||
| 2615 | + } | ||
| 2616 | + } | ||
| 2617 | + | ||
| 2618 | + // Highlights every match of `q` in the log and selects the one at `keep`. | ||
| 2508 | function logFind(pre, q, keep) { | 2619 | function logFind(pre, q, keep) { |
| 2509 | logClear(pre); | 2620 | logClear(pre); |
| 2510 | logCount('', false); | 2621 | logCount('', false); |
| 2622 | + q = Array.from(q.trim()).slice(0, 100).join(''); | ||
| 2511 | if (!q) { return; } | 2623 | if (!q) { return; } |
| 2512 | - var needle = q.toLowerCase(); | ||
| 2513 | var total = 0; | 2624 | var total = 0; |
| 2514 | var texts = pre.querySelectorAll('.lt'); | 2625 | var texts = pre.querySelectorAll('.lt'); |
| 2515 | for (var t = 0; t < texts.length && total < LOG_MAX_MARKS; t++) { | 2626 | for (var t = 0; t < texts.length && total < LOG_MAX_MARKS; t++) { |
| 2516 | - var walker = document.createTreeWalker(texts[t], NodeFilter.SHOW_TEXT); | 2627 | + var spans = logSpans(texts[t].textContent, q, logExact, logCase); |
| 2517 | - var nodes = []; | 2628 | + if (!spans.length) { continue; } |
| 2518 | - while (walker.nextNode()) { nodes.push(walker.currentNode); } | 2629 | + spans = logMerge(spans).slice(0, LOG_MAX_MARKS - total); |
| 2519 | - for (var k = 0; k < nodes.length && total < LOG_MAX_MARKS; k++) { | 2630 | + total += spans.length; |
| 2520 | - var node = nodes[k]; | 2631 | + logMark(texts[t], spans); |
| 2521 | - var lower = node.data.toLowerCase(); | ||
| 2522 | - var at = [], from = 0, idx; | ||
| 2523 | - while ((idx = lower.indexOf(needle, from)) >= 0 && total + at.length < LOG_MAX_MARKS) { | ||
| 2524 | - at.push(idx); | ||
| 2525 | - from = idx + needle.length; | ||
| 2526 | - } | ||
| 2527 | - for (var m = at.length - 1; m >= 0; m--) { | ||
| 2528 | - var mid = node.splitText(at[m]); | ||
| 2529 | - mid.splitText(needle.length); | ||
| 2530 | - var mark = document.createElement('mark'); | ||
| 2531 | - mark.className = 'lm'; | ||
| 2532 | - mid.parentNode.replaceChild(mark, mid); | ||
| 2533 | - mark.appendChild(mid); | ||
| 2534 | - } | ||
| 2535 | - total += at.length; | ||
| 2536 | - } | ||
| 2537 | } | 2632 | } |
| 2538 | var marks = pre.querySelectorAll('mark.lm'); | 2633 | var marks = pre.querySelectorAll('mark.lm'); |
| 2539 | if (!marks.length) { | 2634 | if (!marks.length) { |
| @@ -2572,6 +2667,10 @@ | |||
| 2572 | var pre = document.querySelector('[data-live-log]'); | 2667 | var pre = document.querySelector('[data-live-log]'); |
| 2573 | if (!pre || pre.getAttribute('data-ci')) { return; } | 2668 | if (!pre || pre.getAttribute('data-ci')) { return; } |
| 2574 | logInit(pre); | 2669 | logInit(pre); |
| 2670 | + var ex = document.querySelector('[data-log-exact]'); | ||
| 2671 | + if (ex) { ex.checked = logExact; } | ||
| 2672 | + var cs = document.querySelector('[data-log-case]'); | ||
| 2673 | + if (cs) { cs.checked = logCase; } | ||
| 2575 | var input = document.querySelector('[data-log-q]'); | 2674 | var input = document.querySelector('[data-log-q]'); |
| 2576 | if (input && logQuery) { input.value = logQuery; logFind(pre, logQuery, -1); } | 2675 | if (input && logQuery) { input.value = logQuery; logFind(pre, logQuery, -1); } |
| 2577 | if (location.hash && /^#L\d+$/.test(location.hash)) { logSelect(location.hash.slice(1), true); } | 2676 | if (location.hash && /^#L\d+$/.test(location.hash)) { logSelect(location.hash.slice(1), true); } |
| @@ -2586,6 +2685,18 @@ | |||
| 2586 | logFind(pre, logQuery, -1); | 2685 | logFind(pre, logQuery, -1); |
| 2587 | }); | 2686 | }); |
| 2588 | 2687 | ||
| 2688 | + // Exact and Aa re-run the search at once. | ||
| 2689 | + document.addEventListener('change', function (e) { | ||
| 2690 | + var box = e.target; | ||
| 2691 | + if (!box || !box.hasAttribute) { return; } | ||
| 2692 | + if (box.hasAttribute('data-log-exact')) { logExact = box.checked; } | ||
| 2693 | + else if (box.hasAttribute('data-log-case')) { logCase = box.checked; } | ||
| 2694 | + else { return; } | ||
| 2695 | + var pre = document.querySelector('[data-live-log]'); | ||
| 2696 | + if (!pre || !pre._ci) { return; } | ||
| 2697 | + logFind(pre, logQuery, -1); | ||
| 2698 | + }); | ||
| 2699 | + | ||
| 2589 | document.addEventListener('keydown', function (e) { | 2700 | document.addEventListener('keydown', function (e) { |
| 2590 | var input = e.target; | 2701 | var input = e.target; |
| 2591 | if (!input || !input.hasAttribute || !input.hasAttribute('data-log-q')) { return; } | 2702 | if (!input || !input.hasAttribute || !input.hasAttribute('data-log-q')) { return; } |
crates/forge-web/src/exporter.rsmodified+15 -0
| @@ -406,6 +406,21 @@ pub async fn sweep_expired(state: &AppState) { | |||
| 406 | } | 406 | } |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | +/// Deletes one export by hand, its archive and its row. A missing archive is not an error. | ||
| 410 | +pub async fn delete_one(state: &AppState, export: &DataExport) -> forge_core::Result<()> { | ||
| 411 | + match tokio::fs::remove_file(archive_path(state, &export.id)).await { | ||
| 412 | + Ok(()) => {} | ||
| 413 | + Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} | ||
| 414 | + Err(e) => { | ||
| 415 | + tracing::warn!(error = %e, "export: could not remove an archive"); | ||
| 416 | + return Err(e.into()); | ||
| 417 | + } | ||
| 418 | + } | ||
| 419 | + state.store.delete_export(&export.id).await?; | ||
| 420 | + bump(&export.user_id); | ||
| 421 | + Ok(()) | ||
| 422 | +} | ||
| 423 | + | ||
| 409 | /// Fails exports a restart cut short and removes expired ones. | 424 | /// Fails exports a restart cut short and removes expired ones. |
| 410 | pub async fn on_boot(state: &AppState) { | 425 | pub async fn on_boot(state: &AppState) { |
| 411 | if let Err(e) = state.store.fail_interrupted_exports().await { | 426 | if let Err(e) = state.store.fail_interrupted_exports().await { |
crates/forge-web/src/pages/admin_replication.rsmodified+139 -4
| @@ -27,14 +27,30 @@ use crate::i18n::{self, Lang}; | |||
| 27 | use crate::live::{Topic, stream_changes}; | 27 | use crate::live::{Topic, stream_changes}; |
| 28 | use crate::pages::admin_users::admin_only; | 28 | use crate::pages::admin_users::admin_only; |
| 29 | use crate::state::AppState; | 29 | use crate::state::AppState; |
| 30 | +use crate::pages::issues_list::list_href; | ||
| 31 | +use crate::pages::passkeys::s; | ||
| 32 | +use crate::views::find::{Finder, finder_field}; | ||
| 30 | use crate::views::parts::{SubPart, head, post_act}; | 33 | use crate::views::parts::{SubPart, head, post_act}; |
| 34 | +use crate::views::repo_list::{PageLink, pager, pager_links}; | ||
| 31 | use crate::views::{enc, rel_time_or_never, shell}; | 35 | use crate::views::{enc, rel_time_or_never, shell}; |
| 32 | 36 | ||
| 33 | #[query_params(error = bad_request)] | 37 | #[query_params(error = bad_request)] |
| 34 | pub(crate) struct NoticeQuery { | 38 | pub(crate) struct NoticeQuery { |
| 35 | notice: Option<String>, | 39 | notice: Option<String>, |
| 40 | + q: Option<String>, | ||
| 41 | + exact: Option<String>, | ||
| 42 | + case: Option<String>, | ||
| 43 | + /// The health to list: "ok", "lagging", "error", "never", or anything else for all. | ||
| 44 | + health: Option<String>, | ||
| 45 | + page: Option<String>, | ||
| 36 | } | 46 | } |
| 37 | 47 | ||
| 48 | +/// Repos per page of the list. | ||
| 49 | +const REPO_ROWS: usize = 10; | ||
| 50 | + | ||
| 51 | +/// The health filter's values, in the order the menu lists them. | ||
| 52 | +const HEALTH_KEYS: [&str; 4] = ["error", "lagging", "never", "ok"]; | ||
| 53 | + | ||
| 38 | /// How a subject reads on the page. | 54 | /// How a subject reads on the page. |
| 39 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 55 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 40 | enum Health { | 56 | enum Health { |
| @@ -64,6 +80,21 @@ impl Health { | |||
| 64 | } | 80 | } |
| 65 | } | 81 | } |
| 66 | 82 | ||
| 83 | + fn key(self) -> &'static str { | ||
| 84 | + match self { | ||
| 85 | + Health::Ok => "ok", | ||
| 86 | + Health::Lagging => "lagging", | ||
| 87 | + Health::Error => "error", | ||
| 88 | + Health::Never => "never", | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + fn from_key(key: &str) -> Option<Health> { | ||
| 93 | + [Health::Ok, Health::Lagging, Health::Error, Health::Never] | ||
| 94 | + .into_iter() | ||
| 95 | + .find(|h| h.key() == key) | ||
| 96 | + } | ||
| 97 | + | ||
| 67 | fn label(self, lang: Lang) -> &'static str { | 98 | fn label(self, lang: Lang) -> &'static str { |
| 68 | match self { | 99 | match self { |
| 69 | Health::Ok => g::t(lang, K::HealthOk), | 100 | Health::Ok => g::t(lang, K::HealthOk), |
| @@ -91,6 +122,7 @@ fn health(status: Option<&ReplicationStatus>, cutoff: &str) -> Health { | |||
| 91 | /// One line of the repos table, already formatted. | 122 | /// One line of the repos table, already formatted. |
| 92 | struct RepoRow { | 123 | struct RepoRow { |
| 93 | name: String, | 124 | name: String, |
| 125 | + kind: Health, | ||
| 94 | dot: &'static str, | 126 | dot: &'static str, |
| 95 | tone: &'static str, | 127 | tone: &'static str, |
| 96 | health: &'static str, | 128 | health: &'static str, |
| @@ -99,6 +131,20 @@ struct RepoRow { | |||
| 99 | error: String, | 131 | error: String, |
| 100 | } | 132 | } |
| 101 | 133 | ||
| 134 | +impl RepoRow { | ||
| 135 | + fn copy(&self) -> RepoRow { | ||
| 136 | + RepoRow { | ||
| 137 | + name: self.name.clone(), | ||
| 138 | + kind: self.kind, | ||
| 139 | + dot: self.dot, | ||
| 140 | + tone: self.tone, | ||
| 141 | + health: self.health, | ||
| 142 | + last_ok: self.last_ok.clone(), | ||
| 143 | + error: self.error.clone(), | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | +} | ||
| 147 | + | ||
| 102 | /// Everything the page shows, already formatted. | 148 | /// Everything the page shows, already formatted. |
| 103 | struct PageData { | 149 | struct PageData { |
| 104 | enabled: bool, | 150 | enabled: bool, |
| @@ -139,6 +185,7 @@ async fn page_data(state: &AppState, lang: Lang) -> forge_core::Result<PageData> | |||
| 139 | let h = health(status, &repo_cutoff); | 185 | let h = health(status, &repo_cutoff); |
| 140 | repos.push(RepoRow { | 186 | repos.push(RepoRow { |
| 141 | name, | 187 | name, |
| 188 | + kind: h, | ||
| 142 | dot: h.dot(), | 189 | dot: h.dot(), |
| 143 | tone: h.tone(), | 190 | tone: h.tone(), |
| 144 | health: h.label(lang), | 191 | health: h.label(lang), |
| @@ -154,6 +201,7 @@ async fn page_data(state: &AppState, lang: Lang) -> forge_core::Result<PageData> | |||
| 154 | let h = health(Some(status), &repo_cutoff); | 201 | let h = health(Some(status), &repo_cutoff); |
| 155 | repos.push(RepoRow { | 202 | repos.push(RepoRow { |
| 156 | name: g::deleted_repo_name(lang, &status.subject), | 203 | name: g::deleted_repo_name(lang, &status.subject), |
| 204 | + kind: h, | ||
| 157 | dot: h.dot(), | 205 | dot: h.dot(), |
| 158 | tone: h.tone(), | 206 | tone: h.tone(), |
| 159 | health: h.label(lang), | 207 | health: h.label(lang), |
| @@ -187,7 +235,20 @@ async fn replication_view( | |||
| 187 | csrf: String, | 235 | csrf: String, |
| 188 | data: PageData, | 236 | data: PageData, |
| 189 | notice: Option<String>, | 237 | notice: Option<String>, |
| 238 | + list: RepoList, | ||
| 190 | ) -> Result<impl View> { | 239 | ) -> Result<impl View> { |
| 240 | + let RepoList { | ||
| 241 | + finder, | ||
| 242 | + health, | ||
| 243 | + rows, | ||
| 244 | + page, | ||
| 245 | + pages, | ||
| 246 | + nav: (links, prev, next), | ||
| 247 | + } = list; | ||
| 248 | + let has_repos = !data.repos.is_empty(); | ||
| 249 | + let all_label = s(lang, "All", "Tümü"); | ||
| 250 | + let health_label = s(lang, "Health", "Durum"); | ||
| 251 | + let placeholder = s(lang, "Search repositories", "Depolarda ara"); | ||
| 191 | let sub = vec![SubPart::text(g::t(lang, K::ReplicationIntro))]; | 252 | let sub = vec![SubPart::text(g::t(lang, K::ReplicationIntro))]; |
| 192 | Ok(view! { | 253 | Ok(view! { |
| 193 | head(title: g::t(lang, K::Replication), sub: sub, | 254 | head(title: g::t(lang, K::Replication), sub: sub, |
| @@ -239,12 +300,29 @@ async fn replication_view( | |||
| 239 | } | 300 | } |
| 240 | <section class="sec"> | 301 | <section class="sec"> |
| 241 | <h2>(g::t(lang, K::Repos))</h2> | 302 | <h2>(g::t(lang, K::Repos))</h2> |
| 242 | - if data.repos.is_empty() { | 303 | + if !has_repos { |
| 243 | <p class="state">(g::t(lang, K::NoReposYet))</p> | 304 | <p class="state">(g::t(lang, K::NoReposYet))</p> |
| 244 | <p class="hint">(g::t(lang, K::ReposEmptyHint))</p> | 305 | <p class="hint">(g::t(lang, K::ReposEmptyHint))</p> |
| 245 | <p class="hint">(g::t(lang, K::ReplicationConfigHint))</p> | 306 | <p class="hint">(g::t(lang, K::ReplicationConfigHint))</p> |
| 246 | } else { | 307 | } else { |
| 247 | - for row in data.repos.into_iter() { | 308 | + <form class="sec-tools" method="get" action="/admin/replication" role="search"> |
| 309 | + finder_field(lang: lang, finder: finder, placeholder: placeholder, id: Some("replication-q")) | ||
| 310 | + <label class="find-filter"> | ||
| 311 | + (health_label) " " | ||
| 312 | + <select name="health" data-autosubmit="true"> | ||
| 313 | + <option value="" selected=(health.is_none())>(all_label)</option> | ||
| 314 | + for key in HEALTH_KEYS { | ||
| 315 | + if let Some(h) = Health::from_key(key) { | ||
| 316 | + <option value=(key) selected=(health == Some(h))>(h.label(lang))</option> | ||
| 317 | + } | ||
| 318 | + } | ||
| 319 | + </select> | ||
| 320 | + </label> | ||
| 321 | + </form> | ||
| 322 | + if rows.is_empty() { | ||
| 323 | + <p class="state">(s(lang, "No repository matches.", "Eşleşen depo yok."))</p> | ||
| 324 | + } | ||
| 325 | + for row in rows.into_iter() { | ||
| 248 | <div class="line" data-kb-row=""> | 326 | <div class="line" data-kb-row=""> |
| 249 | <span class="name">(row.name.as_str())</span> | 327 | <span class="name">(row.name.as_str())</span> |
| 250 | <span class="val"><span class=(row.dot) aria-hidden="true"></span> <span class=(row.tone)>(row.health)</span> " · " (g::t(lang, K::LastSuccess)) ": " rel_time_or_never(lang: lang, stamp: row.last_ok.as_deref())</span> | 328 | <span class="val"><span class=(row.dot) aria-hidden="true"></span> <span class=(row.tone)>(row.health)</span> " · " (g::t(lang, K::LastSuccess)) ": " rel_time_or_never(lang: lang, stamp: row.last_ok.as_deref())</span> |
| @@ -255,6 +333,7 @@ async fn replication_view( | |||
| 255 | } | 333 | } |
| 256 | } | 334 | } |
| 257 | </section> | 335 | </section> |
| 336 | + pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) | ||
| 258 | </div> | 337 | </div> |
| 259 | }) | 338 | }) |
| 260 | } | 339 | } |
| @@ -297,17 +376,73 @@ async fn replication_events(cx: &Cx) -> Result<Response> { | |||
| 297 | .await | 376 | .await |
| 298 | } | 377 | } |
| 299 | 378 | ||
| 379 | +/// One page of the repo list, after the search and the health filter. | ||
| 380 | +struct RepoList { | ||
| 381 | + finder: Finder, | ||
| 382 | + health: Option<Health>, | ||
| 383 | + rows: Vec<RepoRow>, | ||
| 384 | + page: u64, | ||
| 385 | + pages: u64, | ||
| 386 | + nav: (Vec<PageLink>, Option<String>, Option<String>), | ||
| 387 | +} | ||
| 388 | + | ||
| 389 | +/// Takes the repos that match the query out of `data`, a page of them. | ||
| 390 | +fn repo_list(data: &mut PageData, query: &NoticeQuery) -> RepoList { | ||
| 391 | + let finder = Finder::new( | ||
| 392 | + query.q.as_deref(), | ||
| 393 | + query.exact.as_deref(), | ||
| 394 | + query.case.as_deref(), | ||
| 395 | + ); | ||
| 396 | + let health = query.health.as_deref().and_then(Health::from_key); | ||
| 397 | + let matching: Vec<RepoRow> = data | ||
| 398 | + .repos | ||
| 399 | + .iter() | ||
| 400 | + .filter(|row| health.is_none_or(|h| row.kind == h)) | ||
| 401 | + .filter(|row| finder.matches_any(&[row.name.as_str(), row.error.as_str()])) | ||
| 402 | + .map(RepoRow::copy) | ||
| 403 | + .collect(); | ||
| 404 | + let pages = (matching.len() as u64).div_ceil(REPO_ROWS as u64).max(1); | ||
| 405 | + let page = query | ||
| 406 | + .page | ||
| 407 | + .as_deref() | ||
| 408 | + .and_then(|p| p.parse::<u64>().ok()) | ||
| 409 | + .unwrap_or(1) | ||
| 410 | + .clamp(1, pages); | ||
| 411 | + let rows = matching | ||
| 412 | + .into_iter() | ||
| 413 | + .skip((page - 1) as usize * REPO_ROWS) | ||
| 414 | + .take(REPO_ROWS) | ||
| 415 | + .collect(); | ||
| 416 | + let health_key = health.map_or("", Health::key); | ||
| 417 | + let nav = pager_links(page, pages, |n| { | ||
| 418 | + let number = n.to_string(); | ||
| 419 | + let mut params = finder.params(); | ||
| 420 | + params.push(("health", health_key)); | ||
| 421 | + params.push(("page", number.as_str())); | ||
| 422 | + list_href("/admin/replication", ¶ms) | ||
| 423 | + }); | ||
| 424 | + RepoList { | ||
| 425 | + finder, | ||
| 426 | + health, | ||
| 427 | + rows, | ||
| 428 | + page, | ||
| 429 | + pages, | ||
| 430 | + nav, | ||
| 431 | + } | ||
| 432 | +} | ||
| 433 | + | ||
| 300 | #[page("/admin/replication")] | 434 | #[page("/admin/replication")] |
| 301 | async fn replication_page(cx: &Cx) -> Result<impl View> { | 435 | async fn replication_page(cx: &Cx) -> Result<impl View> { |
| 302 | let viewer = admin_only(cx).await?; | 436 | let viewer = admin_only(cx).await?; |
| 303 | let query = query_params::<NoticeQuery>(cx)?; | 437 | let query = query_params::<NoticeQuery>(cx)?; |
| 304 | let lang = i18n::lang(cx, Some(&viewer.0)); | 438 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 305 | let state = app_context::<AppState>(cx); | 439 | let state = app_context::<AppState>(cx); |
| 306 | - let data = page_data(state, lang).await?; | 440 | + let mut data = page_data(state, lang).await?; |
| 441 | + let list = repo_list(&mut data, query); | ||
| 307 | let csrf = viewer.1.csrf_token.clone(); | 442 | let csrf = viewer.1.csrf_token.clone(); |
| 308 | let title = g::t(lang, K::Replication); | 443 | let title = g::t(lang, K::Replication); |
| 309 | Ok(view! { | 444 | Ok(view! { |
| 310 | - shell(title: title, viewer: Some(&viewer), replication_view(lang: lang, csrf: csrf, data: data, notice: query.notice.clone())) | 445 | + shell(title: title, viewer: Some(&viewer), replication_view(lang: lang, csrf: csrf, data: data, notice: query.notice.clone(), list: list)) |
| 311 | }) | 446 | }) |
| 312 | } | 447 | } |
| 313 | 448 | ||
crates/forge-web/src/pages/admin_server.rsmodified+19 -17
| @@ -38,6 +38,7 @@ use crate::pages::ci_runs::{changed_event, events_response}; | |||
| 38 | use crate::pages::passkeys::s; | 38 | use crate::pages::passkeys::s; |
| 39 | use crate::self_update; | 39 | use crate::self_update; |
| 40 | use crate::state::AppState; | 40 | use crate::state::AppState; |
| 41 | +use crate::views::find::{Finder, finder_field}; | ||
| 41 | use crate::views::parts::{RailItem, SubPart, confirm_act, head, rail}; | 42 | use crate::views::parts::{RailItem, SubPart, confirm_act, head, rail}; |
| 42 | use crate::views::{enc, shell}; | 43 | use crate::views::{enc, shell}; |
| 43 | 44 | ||
| @@ -48,6 +49,10 @@ pub(crate) struct ServerQuery { | |||
| 48 | cat: Option<String>, | 49 | cat: Option<String>, |
| 49 | /// The search text: when set, the page lists the matching settings from every category instead. | 50 | /// The search text: when set, the page lists the matching settings from every category instead. |
| 50 | q: Option<String>, | 51 | q: Option<String>, |
| 52 | + /// Set when the search asks for the text as typed, as one piece. | ||
| 53 | + exact: Option<String>, | ||
| 54 | + /// Set when the search keeps upper and lower case apart. | ||
| 55 | + case: Option<String>, | ||
| 51 | /// The older name for `cat`, still read so an old link opens the same category. | 56 | /// The older name for `cat`, still read so an old link opens the same category. |
| 52 | tab: Option<String>, | 57 | tab: Option<String>, |
| 53 | /// The boot id of the server that was asked to restart. | 58 | /// The boot id of the server that was asked to restart. |
| @@ -329,19 +334,15 @@ async fn rows_for(state: &AppState, lang: Lang, page: &SrvPage) -> forge_core::R | |||
| 329 | .collect()) | 334 | .collect()) |
| 330 | } | 335 | } |
| 331 | 336 | ||
| 332 | -/// The settings from every category whose key, label or help holds `needle` (already lowercase). | 337 | +/// The settings from every category whose key, label or help matches the search. |
| 333 | -async fn search_hits(state: &AppState, lang: Lang, needle: &str) -> forge_core::Result<Vec<Row>> { | 338 | +async fn search_hits(state: &AppState, lang: Lang, finder: &Finder) -> forge_core::Result<Vec<Row>> { |
| 334 | let overrides = state.store.server_overrides().await?; | 339 | let overrides = state.store.server_overrides().await?; |
| 335 | Ok(state | 340 | Ok(state |
| 336 | .settings | 341 | .settings |
| 337 | .views(&overrides) | 342 | .views(&overrides) |
| 338 | .iter() | 343 | .iter() |
| 339 | .map(|view| row(lang, view)) | 344 | .map(|view| row(lang, view)) |
| 340 | - .filter(|hit| { | 345 | + .filter(|hit| finder.matches_any(&[hit.key, hit.label, hit.help])) |
| 341 | - hit.key.contains(needle) | ||
| 342 | - || hit.label.to_lowercase().contains(needle) | ||
| 343 | - || hit.help.to_lowercase().contains(needle) | ||
| 344 | - }) | ||
| 345 | .collect()) | 346 | .collect()) |
| 346 | } | 347 | } |
| 347 | 348 | ||
| @@ -419,7 +420,7 @@ async fn server_view( | |||
| 419 | csrf: String, | 420 | csrf: String, |
| 420 | page: &'static SrvPage, | 421 | page: &'static SrvPage, |
| 421 | rows: Vec<Row>, | 422 | rows: Vec<Row>, |
| 422 | - q: String, | 423 | + finder: Finder, |
| 423 | search: Option<Vec<Row>>, | 424 | search: Option<Vec<Row>>, |
| 424 | notice: Option<String>, | 425 | notice: Option<String>, |
| 425 | restart: Restart, | 426 | restart: Restart, |
| @@ -472,10 +473,8 @@ async fn server_view( | |||
| 472 | } | 473 | } |
| 473 | <div class="work"> | 474 | <div class="work"> |
| 474 | rail(label: g::t(lang, K::ServerSettings), items: items, | 475 | rail(label: g::t(lang, K::ServerSettings), items: items, |
| 475 | - <form class="plain-search" method="get" action="/admin/server" role="search"> | 476 | + <form method="get" action="/admin/server" role="search"> |
| 476 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg> | 477 | + finder_field(lang: lang, finder: finder, placeholder: search_label, id: Some("server-search")) |
| 477 | - <label class="sr-only" for="server-search">(search_label)</label> | ||
| 478 | - <input id="server-search" type="search" name="q" value=(q.as_str()) placeholder=(search_label) data-live-search="" autocomplete="off"> | ||
| 479 | </form> | 478 | </form> |
| 480 | ) | 479 | ) |
| 481 | <div class="sheet srv-sheet"> | 480 | <div class="sheet srv-sheet"> |
| @@ -528,17 +527,20 @@ async fn server_page(cx: &Cx) -> Result<impl View> { | |||
| 528 | .or(query.tab.as_deref()) | 527 | .or(query.tab.as_deref()) |
| 529 | .and_then(page_by_slug) | 528 | .and_then(page_by_slug) |
| 530 | .unwrap_or(&PAGES[0]); | 529 | .unwrap_or(&PAGES[0]); |
| 531 | - let q = query.q.clone().unwrap_or_default(); | 530 | + let finder = Finder::new( |
| 532 | - let needle = q.trim().to_lowercase(); | 531 | + query.q.as_deref(), |
| 533 | - let (rows, search) = if needle.is_empty() { | 532 | + query.exact.as_deref(), |
| 533 | + query.case.as_deref(), | ||
| 534 | + ); | ||
| 535 | + let (rows, search) = if finder.is_empty() { | ||
| 534 | (rows_for(state, lang, page).await?, None) | 536 | (rows_for(state, lang, page).await?, None) |
| 535 | } else { | 537 | } else { |
| 536 | - (Vec::new(), Some(search_hits(state, lang, &needle).await?)) | 538 | + (Vec::new(), Some(search_hits(state, lang, &finder).await?)) |
| 537 | }; | 539 | }; |
| 538 | let csrf = viewer.1.csrf_token.clone(); | 540 | let csrf = viewer.1.csrf_token.clone(); |
| 539 | let title = g::t(lang, K::ServerSettings); | 541 | let title = g::t(lang, K::ServerSettings); |
| 540 | Ok(view! { | 542 | Ok(view! { |
| 541 | - shell(title: title, viewer: Some(&viewer), server_view(lang: lang, csrf: csrf, page: page, rows: rows, q: q, search: search, notice: query.notice.clone(), restart: restart_state(query.restarting.as_deref()))) | 543 | + shell(title: title, viewer: Some(&viewer), server_view(lang: lang, csrf: csrf, page: page, rows: rows, finder: finder, search: search, notice: query.notice.clone(), restart: restart_state(query.restarting.as_deref()))) |
| 542 | }) | 544 | }) |
| 543 | } | 545 | } |
| 544 | 546 | ||
crates/forge-web/src/pages/admin_users.rsmodified+39 -48
| @@ -23,15 +23,15 @@ use crate::live::{Topic, stream_changes}; | |||
| 23 | use crate::pages::passkeys::s; | 23 | use crate::pages::passkeys::s; |
| 24 | use crate::state::AppState; | 24 | use crate::state::AppState; |
| 25 | use crate::views::parts::{head, reveal}; | 25 | use crate::views::parts::{head, reveal}; |
| 26 | +use crate::pages::issues_list::list_href; | ||
| 27 | +use crate::views::find::{Finder, finder_field}; | ||
| 26 | use crate::views::repo_list::{pager, pager_links}; | 28 | use crate::views::repo_list::{pager, pager_links}; |
| 27 | use crate::views::{alert, enc, rel_time, shell, user_facing_message}; | 29 | use crate::views::{alert, enc, rel_time, shell, user_facing_message}; |
| 28 | 30 | ||
| 29 | const MIN_PASSWORD_CHARS: usize = 12; | 31 | const MIN_PASSWORD_CHARS: usize = 12; |
| 30 | const MAX_PASSWORD_BYTES: usize = 1024; | 32 | const MAX_PASSWORD_BYTES: usize = 1024; |
| 31 | /// Accounts per page of the list. | 33 | /// Accounts per page of the list. |
| 32 | -const PER_PAGE: u64 = 50; | 34 | +const PER_PAGE: u64 = 12; |
| 33 | -/// The longest search the list takes. | ||
| 34 | -const MAX_QUERY_CHARS: usize = 100; | ||
| 35 | 35 | ||
| 36 | #[derive(Deserialize)] | 36 | #[derive(Deserialize)] |
| 37 | struct CreateUserForm { | 37 | struct CreateUserForm { |
| @@ -59,6 +59,8 @@ struct DeleteForm { | |||
| 59 | #[query_params(error = bad_request)] | 59 | #[query_params(error = bad_request)] |
| 60 | struct UsersQuery { | 60 | struct UsersQuery { |
| 61 | q: Option<String>, | 61 | q: Option<String>, |
| 62 | + exact: Option<String>, | ||
| 63 | + case: Option<String>, | ||
| 62 | kind: Option<String>, | 64 | kind: Option<String>, |
| 63 | page: Option<String>, | 65 | page: Option<String>, |
| 64 | } | 66 | } |
| @@ -98,16 +100,13 @@ impl Kind { | |||
| 98 | } | 100 | } |
| 99 | } | 101 | } |
| 100 | 102 | ||
| 101 | -/// The search text, kind and page the query asks for, with the defaults filled in. | 103 | +/// The search, kind and page the query asks for, with the defaults filled in. |
| 102 | -fn listing_args(query: &UsersQuery) -> (String, Kind, u64) { | 104 | +fn listing_args(query: &UsersQuery) -> (Finder, Kind, u64) { |
| 103 | - let q: String = query | 105 | + let finder = Finder::new( |
| 104 | - .q | 106 | + query.q.as_deref(), |
| 105 | - .as_deref() | 107 | + query.exact.as_deref(), |
| 106 | - .unwrap_or("") | 108 | + query.case.as_deref(), |
| 107 | - .trim() | 109 | + ); |
| 108 | - .chars() | ||
| 109 | - .take(MAX_QUERY_CHARS) | ||
| 110 | - .collect(); | ||
| 111 | let kind = Kind::parse(query.kind.as_deref()); | 110 | let kind = Kind::parse(query.kind.as_deref()); |
| 112 | let page = query | 111 | let page = query |
| 113 | .page | 112 | .page |
| @@ -115,31 +114,21 @@ fn listing_args(query: &UsersQuery) -> (String, Kind, u64) { | |||
| 115 | .and_then(|p| p.parse::<u64>().ok()) | 114 | .and_then(|p| p.parse::<u64>().ok()) |
| 116 | .unwrap_or(1) | 115 | .unwrap_or(1) |
| 117 | .max(1); | 116 | .max(1); |
| 118 | - (q, kind, page) | 117 | + (finder, kind, page) |
| 119 | } | 118 | } |
| 120 | 119 | ||
| 121 | /// `/admin/users` with the search, the kind and the page. An empty search is left out. | 120 | /// `/admin/users` with the search, the kind and the page. An empty search is left out. |
| 122 | -fn users_href(q: &str, kind: Kind, page: u64) -> String { | 121 | +fn users_href(finder: &Finder, kind: Kind, page: u64) -> String { |
| 123 | - let mut href = String::from("/admin/users?"); | 122 | + let number = page.to_string(); |
| 124 | - if !q.is_empty() { | 123 | + let mut params = finder.params(); |
| 125 | - href.push_str("q="); | 124 | + params.push(("kind", kind.key())); |
| 126 | - href.push_str(&enc(q)); | 125 | + params.push(("page", number.as_str())); |
| 127 | - href.push('&'); | 126 | + list_href("/admin/users", ¶ms) |
| 128 | - } | ||
| 129 | - href.push_str(&format!("kind={}&page={page}", kind.key())); | ||
| 130 | - href | ||
| 131 | } | 127 | } |
| 132 | 128 | ||
| 133 | -/// Whether the account's name or email holds the lowercase search text. An empty search holds all. | 129 | +/// Whether the account's name or email matches the search. An empty search matches all. |
| 134 | -fn matches_search(user: &User, needle: &str) -> bool { | 130 | +fn matches_search(user: &User, finder: &Finder) -> bool { |
| 135 | - needle.is_empty() | 131 | + finder.matches_any(&[user.username.as_str(), user.email.as_deref().unwrap_or("")]) |
| 136 | - || user.username.to_lowercase().contains(needle) | ||
| 137 | - || user | ||
| 138 | |||
| 139 | - .as_deref() | ||
| 140 | - .unwrap_or("") | ||
| 141 | - .to_lowercase() | ||
| 142 | - .contains(needle) | ||
| 143 | } | 132 | } |
| 144 | 133 | ||
| 145 | /// The ghost account is reserved and never shown as a deletable user. | 134 | /// The ghost account is reserved and never shown as a deletable user. |
| @@ -182,15 +171,14 @@ async fn users_view( | |||
| 182 | lang: Lang, | 171 | lang: Lang, |
| 183 | csrf: &str, | 172 | csrf: &str, |
| 184 | users: Vec<User>, | 173 | users: Vec<User>, |
| 185 | - q: String, | 174 | + finder: Finder, |
| 186 | kind: Kind, | 175 | kind: Kind, |
| 187 | page: u64, | 176 | page: u64, |
| 188 | error: Option<String>, | 177 | error: Option<String>, |
| 189 | ) -> Result<impl View> { | 178 | ) -> Result<impl View> { |
| 190 | - let needle = q.to_lowercase(); | ||
| 191 | let matching: Vec<User> = users | 179 | let matching: Vec<User> = users |
| 192 | .into_iter() | 180 | .into_iter() |
| 193 | - .filter(|user| matches_search(user, &needle)) | 181 | + .filter(|user| matches_search(user, &finder)) |
| 194 | .collect(); | 182 | .collect(); |
| 195 | let all_count = matching.len(); | 183 | let all_count = matching.len(); |
| 196 | let org_count = matching.iter().filter(|user| user.is_org()).count(); | 184 | let org_count = matching.iter().filter(|user| user.is_org()).count(); |
| @@ -205,10 +193,15 @@ async fn users_view( | |||
| 205 | .take(PER_PAGE as usize) | 193 | .take(PER_PAGE as usize) |
| 206 | .map(|user| UserRow::new(lang, user)) | 194 | .map(|user| UserRow::new(lang, user)) |
| 207 | .collect(); | 195 | .collect(); |
| 208 | - let (links, prev, next) = pager_links(page, pages, |n| users_href(&q, kind, n)); | 196 | + let (links, prev, next) = pager_links(page, pages, |n| users_href(&finder, kind, n)); |
| 209 | let empty = rows.is_empty(); | 197 | let empty = rows.is_empty(); |
| 210 | let open = error.is_some(); | 198 | let open = error.is_some(); |
| 211 | - let search_label = s(lang, "Search users and organizations", "Kullanıcı ve kuruluşlarda ara"); | 199 | + // The field says what the current tab lists. |
| 200 | + let search_label = match kind { | ||
| 201 | + Kind::All => s(lang, "Search users and organizations", "Kullanıcı ve kuruluşlarda ara"), | ||
| 202 | + Kind::People => s(lang, "Search users", "Kullanıcılarda ara"), | ||
| 203 | + Kind::Organizations => s(lang, "Search organizations", "Kuruluşlarda ara"), | ||
| 204 | + }; | ||
| 212 | let filter_label = s(lang, "Filter", "Filtre"); | 205 | let filter_label = s(lang, "Filter", "Filtre"); |
| 213 | let all_label = format!("{} {}", s(lang, "All", "Tümü"), all_count); | 206 | let all_label = format!("{} {}", s(lang, "All", "Tümü"), all_count); |
| 214 | let people_label = format!( | 207 | let people_label = format!( |
| @@ -217,9 +210,9 @@ async fn users_view( | |||
| 217 | all_count - org_count | 210 | all_count - org_count |
| 218 | ); | 211 | ); |
| 219 | let orgs_label = format!("{} {}", og::t(lang, OG::Organizations), org_count); | 212 | let orgs_label = format!("{} {}", og::t(lang, OG::Organizations), org_count); |
| 220 | - let all_href = users_href(&q, Kind::All, 1); | 213 | + let all_href = users_href(&finder, Kind::All, 1); |
| 221 | - let people_href = users_href(&q, Kind::People, 1); | 214 | + let people_href = users_href(&finder, Kind::People, 1); |
| 222 | - let orgs_href = users_href(&q, Kind::Organizations, 1); | 215 | + let orgs_href = users_href(&finder, Kind::Organizations, 1); |
| 223 | Ok(view! { | 216 | Ok(view! { |
| 224 | head(title: g::t(lang, K::Users), | 217 | head(title: g::t(lang, K::Users), |
| 225 | reveal(label: g::t(lang, K::CreateUser), id: Some("create-user"), open: open, | 218 | reveal(label: g::t(lang, K::CreateUser), id: Some("create-user"), open: open, |
| @@ -256,10 +249,8 @@ async fn users_view( | |||
| 256 | </nav> | 249 | </nav> |
| 257 | <div class="sheet" data-live="/admin/users/events"> | 250 | <div class="sheet" data-live="/admin/users/events"> |
| 258 | <div class="sheet-tools"> | 251 | <div class="sheet-tools"> |
| 259 | - <form class="plain-search" method="get" action="/admin/users" role="search"> | 252 | + <form method="get" action="/admin/users" role="search"> |
| 260 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg> | 253 | + finder_field(lang: lang, finder: finder.clone(), placeholder: search_label, id: Some("user-search")) |
| 261 | - <label class="sr-only" for="user-search">(search_label)</label> | ||
| 262 | - <input id="user-search" type="search" name="q" value=(q.as_str()) placeholder=(search_label) data-live-search="" autocomplete="off"> | ||
| 263 | <input type="hidden" name="kind" value=(kind.key())> | 254 | <input type="hidden" name="kind" value=(kind.key())> |
| 264 | </form> | 255 | </form> |
| 265 | </div> | 256 | </div> |
| @@ -330,12 +321,12 @@ async fn users_events(cx: &Cx) -> Result<Response> { | |||
| 330 | async fn users_page(cx: &Cx) -> Result<impl View> { | 321 | async fn users_page(cx: &Cx) -> Result<impl View> { |
| 331 | let viewer = admin_only(cx).await?; | 322 | let viewer = admin_only(cx).await?; |
| 332 | let lang = i18n::lang(cx, Some(&viewer.0)); | 323 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 333 | - let (q, kind, page) = listing_args(query_params::<UsersQuery>(cx)?); | 324 | + let (finder, kind, page) = listing_args(query_params::<UsersQuery>(cx)?); |
| 334 | let users = app_context::<AppState>(cx).store.list_users().await?; | 325 | let users = app_context::<AppState>(cx).store.list_users().await?; |
| 335 | let csrf = viewer.1.csrf_token.clone(); | 326 | let csrf = viewer.1.csrf_token.clone(); |
| 336 | let title = g::t(lang, K::Users); | 327 | let title = g::t(lang, K::Users); |
| 337 | Ok(view! { | 328 | Ok(view! { |
| 338 | - shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), users: users, q: q, kind: kind, page: page, error: None)) | 329 | + shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), users: users, finder: finder, kind: kind, page: page, error: None)) |
| 339 | }) | 330 | }) |
| 340 | } | 331 | } |
| 341 | 332 | ||
| @@ -372,7 +363,7 @@ async fn users_create(cx: &Cx, Form(form): Form<CreateUserForm>) -> Result<impl | |||
| 372 | let csrf = viewer.1.csrf_token.clone(); | 363 | let csrf = viewer.1.csrf_token.clone(); |
| 373 | let title = g::t(lang, K::Users); | 364 | let title = g::t(lang, K::Users); |
| 374 | Ok(view! { | 365 | Ok(view! { |
| 375 | - shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), users: users, q: String::new(), kind: Kind::All, page: 1, error: Some(message))) | 366 | + shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), users: users, finder: Finder::default(), kind: Kind::All, page: 1, error: Some(message))) |
| 376 | }) | 367 | }) |
| 377 | } | 368 | } |
| 378 | } | 369 | } |
crates/forge-web/src/pages/audit_log.rsmodified+326 -131
| @@ -1,8 +1,9 @@ | |||
| 1 | //! Pages: the admin audit log (`/admin/audit`, instance admins only, 404 otherwise) and a user's | 1 | //! Pages: the admin audit log (`/admin/audit`, instance admins only, 404 otherwise) and a user's |
| 2 | //! own security log (`/settings/security/log`: entries the viewer acted in, or that targeted | 2 | //! own security log (`/settings/security/log`: entries the viewer acted in, or that targeted |
| 3 | -//! them). Both list newest first, a page of rows at a time, with numbered pages: 8 rows on the | 3 | +//! them). Both list newest first with a live search over every word of an entry (forgiving typos |
| 4 | -//! admin page (its filter bar takes the room) and 10 in the own log, sized to fit the window. | 4 | +//! unless Exact or Aa is on) and an action filter. Runs of the same action by the same actor fold |
| 5 | -//! Repeats in a row (same action, actor and target) fold into one row with a count. | 5 | +//! into one row with a count, which opens to show each entry. Pages count rows as shown, so a page |
| 6 | +//! is always full. | ||
| 6 | 7 | ||
| 7 | use forge_core::{AuditAction, AuditEntry, AuditFilter, Store}; | 8 | use forge_core::{AuditAction, AuditEntry, AuditFilter, Store}; |
| 8 | use topcoat::Result; | 9 | use topcoat::Result; |
| @@ -20,23 +21,29 @@ use crate::pages::issues_list::list_href; | |||
| 20 | use crate::pages::passkeys::s; | 21 | use crate::pages::passkeys::s; |
| 21 | use crate::pages::settings_security::{security_rail_for, security_sub}; | 22 | use crate::pages::settings_security::{security_rail_for, security_sub}; |
| 22 | use crate::state::AppState; | 23 | use crate::state::AppState; |
| 24 | +use crate::views::find::{Finder, finder_field}; | ||
| 23 | use crate::views::parts::{RailItem, SubPart, head, rail}; | 25 | use crate::views::parts::{RailItem, SubPart, head, rail}; |
| 24 | use crate::views::repo_list::{PageLink, pager, pager_links}; | 26 | use crate::views::repo_list::{PageLink, pager, pager_links}; |
| 25 | use crate::views::{rel_time, shell}; | 27 | use crate::views::{rel_time, shell}; |
| 26 | 28 | ||
| 27 | -/// Entries per page of the admin audit log, under its filter bar. | 29 | +/// Rows per page of either log. A folded run is one row. |
| 28 | -const ADMIN_PAGE_SIZE: usize = 8; | 30 | +const PAGE_ROWS: usize = 10; |
| 29 | 31 | ||
| 30 | -/// Entries per page of the own security log. | 32 | +/// The newest entries a search reads. Older ones are past any page a person pages to. |
| 31 | -const OWN_PAGE_SIZE: usize = 10; | 33 | +const SEARCH_CAP: u32 = 5000; |
| 32 | 34 | ||
| 33 | -/// Details shorter than this show in the row; longer ones move to the line's hover title. | 35 | +/// Details longer than this are cut in a row, with the whole text in its hover title. |
| 34 | const DETAILS_INLINE_CHARS: usize = 80; | 36 | const DETAILS_INLINE_CHARS: usize = 80; |
| 35 | 37 | ||
| 36 | #[query_params(error = bad_request)] | 38 | #[query_params(error = bad_request)] |
| 37 | pub(crate) struct AuditQuery { | 39 | pub(crate) struct AuditQuery { |
| 38 | action: Option<String>, | 40 | action: Option<String>, |
| 41 | + /// An exact actor username. No form sends it any more (the search covers actors); old links | ||
| 42 | + /// still filter by it. | ||
| 39 | actor: Option<String>, | 43 | actor: Option<String>, |
| 44 | + q: Option<String>, | ||
| 45 | + exact: Option<String>, | ||
| 46 | + case: Option<String>, | ||
| 40 | /// Old cursor links. Still accepted so old bookmarks load, and ignored. | 47 | /// Old cursor links. Still accepted so old bookmarks load, and ignored. |
| 41 | #[allow(dead_code)] | 48 | #[allow(dead_code)] |
| 42 | before: Option<String>, | 49 | before: Option<String>, |
| @@ -44,23 +51,81 @@ pub(crate) struct AuditQuery { | |||
| 44 | page: Option<String>, | 51 | page: Option<String>, |
| 45 | } | 52 | } |
| 46 | 53 | ||
| 47 | -/// One table row, already formatted for display. A row can stand for several entries in a row. | 54 | +/// One entry, already formatted for display. |
| 48 | struct RowView { | 55 | struct RowView { |
| 49 | when: String, | 56 | when: String, |
| 50 | actor: String, | 57 | actor: String, |
| 51 | - /// The action as words: "Ui prefs changed". | 58 | + /// The action as words: "Display preferences changed". |
| 52 | name: String, | 59 | name: String, |
| 53 | /// The raw action, for the hover title. | 60 | /// The raw action, for the hover title. |
| 54 | action: String, | 61 | action: String, |
| 55 | /// "kind: name", or the name alone, or empty when the entry has no target name. | 62 | /// "kind: name", or the name alone, or empty when the entry has no target name. |
| 56 | target: String, | 63 | target: String, |
| 57 | ip: String, | 64 | ip: String, |
| 58 | - /// The details when short enough to show in the row. Empty when they are long. | 65 | + /// The details as words, whole. |
| 59 | - details_inline: String, | 66 | + details: String, |
| 60 | - /// The details when too long for the row, for the line's hover title. Empty otherwise. | 67 | +} |
| 61 | - details_title: String, | 68 | + |
| 62 | - /// How many entries this row stands for. | 69 | +impl RowView { |
| 63 | - count: usize, | 70 | + /// Every word a search reads. |
| 71 | + fn text(&self) -> String { | ||
| 72 | + [ | ||
| 73 | + self.name.as_str(), | ||
| 74 | + self.action.as_str(), | ||
| 75 | + self.actor.as_str(), | ||
| 76 | + self.target.as_str(), | ||
| 77 | + self.ip.as_str(), | ||
| 78 | + self.details.as_str(), | ||
| 79 | + ] | ||
| 80 | + .join(" \u{1f} ") | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /// The details as shown in a row: cut when long. | ||
| 84 | + fn details_short(&self) -> String { | ||
| 85 | + if self.details.chars().count() <= DETAILS_INLINE_CHARS { | ||
| 86 | + self.details.clone() | ||
| 87 | + } else { | ||
| 88 | + let cut: String = self.details.chars().take(DETAILS_INLINE_CHARS).collect(); | ||
| 89 | + format!("{cut}\u{2026}") | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +/// A run of entries of one action by one actor, newest first. A run of one is a plain row. | ||
| 95 | +struct Group { | ||
| 96 | + /// The key the run folds on. | ||
| 97 | + key: (String, Option<String>, String), | ||
| 98 | + rows: Vec<RowView>, | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +impl Group { | ||
| 102 | + fn first(&self) -> &RowView { | ||
| 103 | + &self.rows[0] | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /// The target when every entry has the same one. | ||
| 107 | + fn shared_target(&self) -> Option<&str> { | ||
| 108 | + let first = self.first().target.as_str(); | ||
| 109 | + self.rows | ||
| 110 | + .iter() | ||
| 111 | + .all(|row| row.target == first) | ||
| 112 | + .then_some(first) | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /// The IP when every entry came from the same one. | ||
| 116 | + fn shared_ip(&self) -> Option<&str> { | ||
| 117 | + let first = self.first().ip.as_str(); | ||
| 118 | + self.rows.iter().all(|row| row.ip == first).then_some(first) | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /// The details when every entry has the same. | ||
| 122 | + fn shared_details(&self) -> Option<&str> { | ||
| 123 | + let first = self.first().details.as_str(); | ||
| 124 | + self.rows | ||
| 125 | + .iter() | ||
| 126 | + .all(|row| row.details == first) | ||
| 127 | + .then_some(first) | ||
| 128 | + } | ||
| 64 | } | 129 | } |
| 65 | 130 | ||
| 66 | /// "ci_secret_set" as "CI secret set": words, with the short names in capitals. | 131 | /// "ci_secret_set" as "CI secret set": words, with the short names in capitals. |
| @@ -164,11 +229,6 @@ fn row_view(entry: &AuditEntry, lang: Lang) -> RowView { | |||
| 164 | } else { | 229 | } else { |
| 165 | details_words(lang, &entry.data) | 230 | details_words(lang, &entry.data) |
| 166 | }; | 231 | }; |
| 167 | - let (details_inline, details_title) = if details.chars().count() < DETAILS_INLINE_CHARS { | ||
| 168 | - (details.clone(), String::new()) | ||
| 169 | - } else { | ||
| 170 | - (String::new(), details.clone()) | ||
| 171 | - }; | ||
| 172 | RowView { | 232 | RowView { |
| 173 | when: entry.at.clone(), | 233 | when: entry.at.clone(), |
| 174 | actor, | 234 | actor, |
| @@ -176,32 +236,33 @@ fn row_view(entry: &AuditEntry, lang: Lang) -> RowView { | |||
| 176 | action: entry.action.as_str().to_owned(), | 236 | action: entry.action.as_str().to_owned(), |
| 177 | target, | 237 | target, |
| 178 | ip: entry.ip.clone(), | 238 | ip: entry.ip.clone(), |
| 179 | - details_inline, | 239 | + details, |
| 180 | - details_title, | ||
| 181 | - count: 1, | ||
| 182 | } | 240 | } |
| 183 | } | 241 | } |
| 184 | 242 | ||
| 185 | -/// Rows for `entries` (newest first), with consecutive entries of the same action, actor and | 243 | +/// Groups for `entries` (newest first) that match the search: consecutive entries of the same |
| 186 | -/// target folded into one row. The row keeps the newest entry's time, IP and details. | 244 | +/// action by the same actor fold into one group, whatever their targets. |
| 187 | -fn fold_rows(entries: &[AuditEntry], lang: Lang) -> Vec<RowView> { | 245 | +fn fold_groups(entries: &[AuditEntry], lang: Lang, finder: &Finder) -> Vec<Group> { |
| 188 | - let mut rows: Vec<(&AuditEntry, RowView)> = Vec::new(); | 246 | + let mut groups: Vec<Group> = Vec::new(); |
| 189 | for entry in entries { | 247 | for entry in entries { |
| 190 | - if let Some((last, row)) = rows.last_mut() { | 248 | + let row = row_view(entry, lang); |
| 191 | - let same = last.action == entry.action | 249 | + if !finder.matches(&row.text()) { |
| 192 | - && last.actor_id == entry.actor_id | 250 | + continue; |
| 193 | - && last.actor_name == entry.actor_name | 251 | + } |
| 194 | - && last.target_kind == entry.target_kind | 252 | + let key = ( |
| 195 | - && last.target_id == entry.target_id | 253 | + entry.action.as_str().to_owned(), |
| 196 | - && last.target_name == entry.target_name; | 254 | + entry.actor_id.clone(), |
| 197 | - if same { | 255 | + entry.actor_name.clone(), |
| 198 | - row.count += 1; | 256 | + ); |
| 199 | - continue; | 257 | + match groups.last_mut() { |
| 200 | - } | 258 | + Some(group) if group.key == key => group.rows.push(row), |
| 259 | + _ => groups.push(Group { | ||
| 260 | + key, | ||
| 261 | + rows: vec![row], | ||
| 262 | + }), | ||
| 201 | } | 263 | } |
| 202 | - rows.push((entry, row_view(entry, lang))); | ||
| 203 | } | 264 | } |
| 204 | - rows.into_iter().map(|(_, row)| row).collect() | 265 | + groups |
| 205 | } | 266 | } |
| 206 | 267 | ||
| 207 | /// The page the query asks for, 1-based. Anything unreadable is page 1. | 268 | /// The page the query asks for, 1-based. Anything unreadable is page 1. |
| @@ -214,23 +275,21 @@ fn requested_page(query: &AuditQuery) -> u64 { | |||
| 214 | .max(1) | 275 | .max(1) |
| 215 | } | 276 | } |
| 216 | 277 | ||
| 217 | -/// One page of `size` entries, and the page that was asked for, clamped to the pages there are, | 278 | +/// The groups of one page, the page clamped to the pages there are, and the page count. |
| 218 | -/// with the page count. | 279 | +fn page_of(mut groups: Vec<Group>, page: u64) -> (Vec<Group>, u64, u64) { |
| 219 | -async fn fetch_page( | 280 | + let pages = (groups.len() as u64).div_ceil(PAGE_ROWS as u64).max(1); |
| 220 | - store: &Store, | ||
| 221 | - filter: &AuditFilter, | ||
| 222 | - page: u64, | ||
| 223 | - size: usize, | ||
| 224 | -) -> forge_core::Result<(Vec<AuditEntry>, u64, u64)> { | ||
| 225 | - let total = store.count_audit(filter).await?; | ||
| 226 | - let pages = total.div_ceil(size as u64).max(1); | ||
| 227 | let page = page.clamp(1, pages); | 281 | let page = page.clamp(1, pages); |
| 228 | - let offset = ((page - 1) * size as u64) as u32; | 282 | + let start = (page - 1) as usize * PAGE_ROWS; |
| 229 | - let entries = store.list_audit_page(filter, offset, size as u32).await?; | 283 | + let shown: Vec<Group> = groups.drain(..).skip(start).take(PAGE_ROWS).collect(); |
| 230 | - Ok((entries, page, pages)) | 284 | + (shown, page, pages) |
| 285 | +} | ||
| 286 | + | ||
| 287 | +/// The newest entries the filter selects, as many as a search reads. | ||
| 288 | +async fn fetch_entries(store: &Store, filter: &AuditFilter) -> forge_core::Result<Vec<AuditEntry>> { | ||
| 289 | + store.list_audit_page(filter, 0, SEARCH_CAP).await | ||
| 231 | } | 290 | } |
| 232 | 291 | ||
| 233 | -/// The numbered pager's entries and links for `page` of `pages`, under `href`'s params. | 292 | +/// The numbered pager's entries and links for `page` of `pages`, under `base` with `params`. |
| 234 | fn nav_for( | 293 | fn nav_for( |
| 235 | page: u64, | 294 | page: u64, |
| 236 | pages: u64, | 295 | pages: u64, |
| @@ -245,48 +304,181 @@ fn nav_for( | |||
| 245 | }) | 304 | }) |
| 246 | } | 305 | } |
| 247 | 306 | ||
| 307 | +/// The search and the action filter, in one GET form to `action`. | ||
| 248 | #[component] | 308 | #[component] |
| 249 | -async fn audit_table(lang: Lang, rows: Vec<RowView>, show_actor: bool) -> Result<impl View> { | 309 | +async fn log_tools( |
| 310 | + lang: Lang, | ||
| 311 | + form_action: &str, | ||
| 312 | + finder: Finder, | ||
| 313 | + action: String, | ||
| 314 | + actor: String, | ||
| 315 | +) -> Result<impl View> { | ||
| 316 | + let placeholder = s(lang, "Search the log", "Günlükte ara"); | ||
| 250 | Ok(view! { | 317 | Ok(view! { |
| 251 | - if rows.is_empty() { | 318 | + <div class="sheet-tools"> |
| 319 | + <form method="get" action=(form_action)> | ||
| 320 | + finder_field(lang: lang, finder: finder, placeholder: placeholder, id: Some("log-q")) | ||
| 321 | + <label class="find-filter"> | ||
| 322 | + (g::t(lang, K::ActionLabel)) " " | ||
| 323 | + <select name="action" data-autosubmit="true"> | ||
| 324 | + <option value="" selected=(action.is_empty())>(g::t(lang, K::AllActions))</option> | ||
| 325 | + for known in AuditAction::ALL.iter().copied() { | ||
| 326 | + <option value=(known.as_str()) selected=(known.as_str() == action.as_str())>(action_label(lang, known.as_str()))</option> | ||
| 327 | + } | ||
| 328 | + </select> | ||
| 329 | + </label> | ||
| 330 | + if !actor.is_empty() { | ||
| 331 | + <input type="hidden" name="actor" value=(actor.as_str())> | ||
| 332 | + } | ||
| 333 | + </form> | ||
| 334 | + </div> | ||
| 335 | + }) | ||
| 336 | +} | ||
| 337 | + | ||
| 338 | +/// The facts of one entry after its name: time, then whatever `show` asks for. | ||
| 339 | +#[component] | ||
| 340 | +async fn entry_facts( | ||
| 341 | + lang: Lang, | ||
| 342 | + row: RowView, | ||
| 343 | + show_actor: bool, | ||
| 344 | + show_target: bool, | ||
| 345 | + show_ip: bool, | ||
| 346 | + show_details: bool, | ||
| 347 | +) -> Result<impl View> { | ||
| 348 | + let details = row.details_short(); | ||
| 349 | + Ok(view! { | ||
| 350 | + rel_time(lang: lang, stamp: row.when.as_str()) | ||
| 351 | + if show_actor { | ||
| 352 | + " · " (row.actor.as_str()) | ||
| 353 | + } | ||
| 354 | + if show_target && !row.target.is_empty() { | ||
| 355 | + " · " (row.target.as_str()) | ||
| 356 | + } | ||
| 357 | + if show_ip && !row.ip.is_empty() { | ||
| 358 | + " · IP " (row.ip.as_str()) | ||
| 359 | + } | ||
| 360 | + if show_details && !details.is_empty() { | ||
| 361 | + " · " (details.as_str()) | ||
| 362 | + } | ||
| 363 | + }) | ||
| 364 | +} | ||
| 365 | + | ||
| 366 | +#[component] | ||
| 367 | +async fn audit_table(lang: Lang, groups: Vec<Group>, show_actor: bool) -> Result<impl View> { | ||
| 368 | + Ok(view! { | ||
| 369 | + if groups.is_empty() { | ||
| 252 | <p class="state">(g::t(lang, K::NoEntries))</p> | 370 | <p class="state">(g::t(lang, K::NoEntries))</p> |
| 253 | } else { | 371 | } else { |
| 254 | - for row in rows.into_iter() { | 372 | + for group in groups.into_iter() { |
| 255 | - let count = row.count.to_string(); | 373 | + if group.rows.len() == 1 { |
| 256 | - <div class="line" data-kb-row="" title=(row.details_title.as_str())> | 374 | + single_row(lang: lang, group: group, show_actor: show_actor) |
| 257 | - <span class="name" title=(row.action.as_str())>(row.name.as_str())</span> | 375 | + } else { |
| 258 | - if row.count > 1 { | 376 | + group_row(lang: lang, group: group, show_actor: show_actor) |
| 259 | - <span class="count">"×" (count.as_str())</span> | 377 | + } |
| 260 | - } | ||
| 261 | - <span class="val"> | ||
| 262 | - rel_time(lang: lang, stamp: row.when.as_str()) | ||
| 263 | - if show_actor { | ||
| 264 | - " · " (row.actor.as_str()) | ||
| 265 | - } | ||
| 266 | - if !row.target.is_empty() { | ||
| 267 | - " · " (row.target.as_str()) | ||
| 268 | - } | ||
| 269 | - if !row.ip.is_empty() { | ||
| 270 | - " · IP " (row.ip.as_str()) | ||
| 271 | - } | ||
| 272 | - if !row.details_inline.is_empty() { | ||
| 273 | - " · " (row.details_inline.as_str()) | ||
| 274 | - } | ||
| 275 | - </span> | ||
| 276 | - </div> | ||
| 277 | } | 378 | } |
| 278 | } | 379 | } |
| 279 | }) | 380 | }) |
| 280 | } | 381 | } |
| 281 | 382 | ||
| 383 | +/// One entry on its own line. | ||
| 384 | +#[component] | ||
| 385 | +async fn single_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<impl View> { | ||
| 386 | + let row = group.rows.remove(0); | ||
| 387 | + let title = row.details.clone(); | ||
| 388 | + let name = row.name.clone(); | ||
| 389 | + let action = row.action.clone(); | ||
| 390 | + Ok(view! { | ||
| 391 | + <div class="line" data-kb-row="" title=(title.as_str())> | ||
| 392 | + <span class="name" title=(action.as_str())>(name.as_str())</span> | ||
| 393 | + <span class="val">entry_facts(lang: lang, row: row, show_actor: show_actor, show_target: true, show_ip: true, show_details: true)</span> | ||
| 394 | + </div> | ||
| 395 | + }) | ||
| 396 | +} | ||
| 397 | + | ||
| 398 | +/// A run of entries: one row with the count and what they share, which opens to list each one | ||
| 399 | +/// with what differs. | ||
| 400 | +#[component] | ||
| 401 | +async fn group_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<impl View> { | ||
| 402 | + let count = group.rows.len().to_string(); | ||
| 403 | + let target = group.shared_target().map(str::to_owned); | ||
| 404 | + let ip = group.shared_ip().map(str::to_owned).filter(|ip| !ip.is_empty()); | ||
| 405 | + let details = group | ||
| 406 | + .shared_details() | ||
| 407 | + .map(str::to_owned) | ||
| 408 | + .filter(|d| !d.is_empty()); | ||
| 409 | + let mut seen: Vec<String> = group.rows.iter().map(|row| row.target.clone()).collect(); | ||
| 410 | + seen.sort_unstable(); | ||
| 411 | + seen.dedup(); | ||
| 412 | + let target_text = match target.as_deref() { | ||
| 413 | + Some(target) => target.to_owned(), | ||
| 414 | + None => format!("{} {}", seen.len(), s(lang, "targets", "hedef")), | ||
| 415 | + }; | ||
| 416 | + let show_target = target.is_none(); | ||
| 417 | + let show_ip = ip.is_none(); | ||
| 418 | + let show_details = details.is_none(); | ||
| 419 | + let ip = ip.unwrap_or_default(); | ||
| 420 | + let details = details.unwrap_or_default(); | ||
| 421 | + let name = group.first().name.clone(); | ||
| 422 | + let action = group.first().action.clone(); | ||
| 423 | + let when = group.first().when.clone(); | ||
| 424 | + let actor = group.first().actor.clone(); | ||
| 425 | + let rows = std::mem::take(&mut group.rows); | ||
| 426 | + Ok(view! { | ||
| 427 | + <details class="log-group"> | ||
| 428 | + <summary class="line" data-kb-row=""> | ||
| 429 | + <span class="name" title=(action.as_str())>(name.as_str())</span> | ||
| 430 | + <span class="count">"×" (count.as_str())</span> | ||
| 431 | + <span class="val"> | ||
| 432 | + rel_time(lang: lang, stamp: when.as_str()) | ||
| 433 | + if show_actor { | ||
| 434 | + " · " (actor.as_str()) | ||
| 435 | + } | ||
| 436 | + if !target_text.is_empty() { | ||
| 437 | + " · " (target_text.as_str()) | ||
| 438 | + } | ||
| 439 | + if !ip.is_empty() { | ||
| 440 | + " · IP " (ip.as_str()) | ||
| 441 | + } | ||
| 442 | + if !details.is_empty() { | ||
| 443 | + " · " (details.as_str()) | ||
| 444 | + } | ||
| 445 | + </span> | ||
| 446 | + </summary> | ||
| 447 | + <div class="log-items"> | ||
| 448 | + for row in rows.into_iter() { | ||
| 449 | + item_line(lang: lang, row: row, show_target: show_target, show_ip: show_ip, show_details: show_details) | ||
| 450 | + } | ||
| 451 | + </div> | ||
| 452 | + </details> | ||
| 453 | + }) | ||
| 454 | +} | ||
| 455 | + | ||
| 456 | +/// One entry inside an opened run: its time and what the run's row does not already say. | ||
| 457 | +#[component] | ||
| 458 | +async fn item_line( | ||
| 459 | + lang: Lang, | ||
| 460 | + row: RowView, | ||
| 461 | + show_target: bool, | ||
| 462 | + show_ip: bool, | ||
| 463 | + show_details: bool, | ||
| 464 | +) -> Result<impl View> { | ||
| 465 | + let title = row.details.clone(); | ||
| 466 | + Ok(view! { | ||
| 467 | + <div class="line" title=(title.as_str())> | ||
| 468 | + <span class="val">entry_facts(lang: lang, row: row, show_actor: false, show_target: show_target, show_ip: show_ip, show_details: show_details)</span> | ||
| 469 | + </div> | ||
| 470 | + }) | ||
| 471 | +} | ||
| 472 | + | ||
| 282 | #[component] | 473 | #[component] |
| 283 | async fn admin_audit_view( | 474 | async fn admin_audit_view( |
| 284 | lang: Lang, | 475 | lang: Lang, |
| 285 | live: String, | 476 | live: String, |
| 477 | + finder: Finder, | ||
| 286 | action: String, | 478 | action: String, |
| 287 | actor: String, | 479 | actor: String, |
| 288 | notice: Option<String>, | 480 | notice: Option<String>, |
| 289 | - rows: Vec<RowView>, | 481 | + groups: Vec<Group>, |
| 290 | page: u64, | 482 | page: u64, |
| 291 | pages: u64, | 483 | pages: u64, |
| 292 | nav: (Vec<PageLink>, Option<String>, Option<String>), | 484 | nav: (Vec<PageLink>, Option<String>, Option<String>), |
| @@ -296,28 +488,11 @@ async fn admin_audit_view( | |||
| 296 | Ok(view! { | 488 | Ok(view! { |
| 297 | head(title: g::t(lang, K::AuditLog), sub: sub) | 489 | head(title: g::t(lang, K::AuditLog), sub: sub) |
| 298 | <div class="sheet" data-live=(live.as_str())> | 490 | <div class="sheet" data-live=(live.as_str())> |
| 299 | - <div class="sheet-tools"> | 491 | + log_tools(lang: lang, form_action: "/admin/audit", finder: finder, action: action, actor: actor) |
| 300 | - <form method="get" action="/admin/audit"> | ||
| 301 | - <div class="plain-search"> | ||
| 302 | - <label class="sr-only" for="audit-actor">(g::t(lang, K::ActorUsername))</label> | ||
| 303 | - <input id="audit-actor" type="search" name="actor" value=(actor.as_str()) placeholder=(g::t(lang, K::ActorUsername)) data-live-search="" autocomplete="off"> | ||
| 304 | - <button type="submit" class="sr-only">(g::t(lang, K::Filter))</button> | ||
| 305 | - </div> | ||
| 306 | - <label> | ||
| 307 | - (g::t(lang, K::ActionLabel)) " " | ||
| 308 | - <select name="action" data-autosubmit="true"> | ||
| 309 | - <option value="" selected=(action.is_empty())>(g::t(lang, K::AllActions))</option> | ||
| 310 | - for known in AuditAction::ALL.iter().copied() { | ||
| 311 | - <option value=(known.as_str()) selected=(known.as_str() == action.as_str())>(action_label(lang, known.as_str()))</option> | ||
| 312 | - } | ||
| 313 | - </select> | ||
| 314 | - </label> | ||
| 315 | - </form> | ||
| 316 | - </div> | ||
| 317 | if let Some(message) = notice { | 492 | if let Some(message) = notice { |
| 318 | <p class="state" role="status">(message.as_str())</p> | 493 | <p class="state" role="status">(message.as_str())</p> |
| 319 | } | 494 | } |
| 320 | - audit_table(lang: lang, rows: rows, show_actor: true) | 495 | + audit_table(lang: lang, groups: groups, show_actor: true) |
| 321 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) | 496 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) |
| 322 | </div> | 497 | </div> |
| 323 | }) | 498 | }) |
| @@ -327,7 +502,9 @@ async fn admin_audit_view( | |||
| 327 | async fn own_log_view( | 502 | async fn own_log_view( |
| 328 | lang: Lang, | 503 | lang: Lang, |
| 329 | items: Vec<RailItem>, | 504 | items: Vec<RailItem>, |
| 330 | - rows: Vec<RowView>, | 505 | + finder: Finder, |
| 506 | + action: String, | ||
| 507 | + groups: Vec<Group>, | ||
| 331 | page: u64, | 508 | page: u64, |
| 332 | pages: u64, | 509 | pages: u64, |
| 333 | nav: (Vec<PageLink>, Option<String>, Option<String>), | 510 | nav: (Vec<PageLink>, Option<String>, Option<String>), |
| @@ -339,25 +516,41 @@ async fn own_log_view( | |||
| 339 | <div class="work"> | 516 | <div class="work"> |
| 340 | rail(label: i18n::t(lang, i18n::Key::Security), items: items) | 517 | rail(label: i18n::t(lang, i18n::Key::Security), items: items) |
| 341 | <div class="sheet"> | 518 | <div class="sheet"> |
| 342 | - <section class="sec"> | 519 | + log_tools(lang: lang, form_action: "/settings/security/log", finder: finder, action: action, actor: String::new()) |
| 343 | - <h2>(g::t(lang, K::SecurityLogTitle))</h2> | 520 | + audit_table(lang: lang, groups: groups, show_actor: false) |
| 344 | - <p class="hint">(g::t(lang, K::OwnLogIntro))</p> | ||
| 345 | - audit_table(lang: lang, rows: rows, show_actor: false) | ||
| 346 | - </section> | ||
| 347 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) | 521 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) |
| 348 | </div> | 522 | </div> |
| 349 | </div> | 523 | </div> |
| 350 | }) | 524 | }) |
| 351 | } | 525 | } |
| 352 | 526 | ||
| 527 | +/// The search, action and actor a query asks for, trimmed. | ||
| 528 | +fn query_parts(query: &AuditQuery) -> (Finder, String, String) { | ||
| 529 | + let finder = Finder::new( | ||
| 530 | + query.q.as_deref(), | ||
| 531 | + query.exact.as_deref(), | ||
| 532 | + query.case.as_deref(), | ||
| 533 | + ); | ||
| 534 | + let action = query.action.clone().unwrap_or_default().trim().to_owned(); | ||
| 535 | + let actor = query.actor.clone().unwrap_or_default().trim().to_owned(); | ||
| 536 | + (finder, action, actor) | ||
| 537 | +} | ||
| 538 | + | ||
| 539 | +/// The link params that keep the search and filters. | ||
| 540 | +fn keep_params<'a>(finder: &'a Finder, action: &'a str, actor: &'a str) -> Vec<(&'a str, &'a str)> { | ||
| 541 | + let mut params = finder.params(); | ||
| 542 | + params.push(("action", action)); | ||
| 543 | + params.push(("actor", actor)); | ||
| 544 | + params | ||
| 545 | +} | ||
| 546 | + | ||
| 353 | #[page("/admin/audit")] | 547 | #[page("/admin/audit")] |
| 354 | async fn admin_audit_page(cx: &Cx) -> Result<impl View> { | 548 | async fn admin_audit_page(cx: &Cx) -> Result<impl View> { |
| 355 | let viewer = admin_only(cx).await?; | 549 | let viewer = admin_only(cx).await?; |
| 356 | let lang = i18n::lang(cx, Some(&viewer.0)); | 550 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 357 | let query = query_params::<AuditQuery>(cx)?; | 551 | let query = query_params::<AuditQuery>(cx)?; |
| 358 | let store = &app_context::<AppState>(cx).store; | 552 | let store = &app_context::<AppState>(cx).store; |
| 359 | - let action = query.action.clone().unwrap_or_default().trim().to_owned(); | 553 | + let (finder, action, actor) = query_parts(query); |
| 360 | - let actor = query.actor.clone().unwrap_or_default().trim().to_owned(); | ||
| 361 | 554 | ||
| 362 | let mut filter = AuditFilter::default(); | 555 | let mut filter = AuditFilter::default(); |
| 363 | let mut notice: Option<String> = None; | 556 | let mut notice: Option<String> = None; |
| @@ -374,30 +567,26 @@ async fn admin_audit_page(cx: &Cx) -> Result<impl View> { | |||
| 374 | } | 567 | } |
| 375 | } | 568 | } |
| 376 | // An unknown action or actor matches nothing, so the notice explains the empty table. | 569 | // An unknown action or actor matches nothing, so the notice explains the empty table. |
| 377 | - let (entries, page, pages) = if notice.is_some() { | 570 | + let entries = if notice.is_some() { |
| 378 | - (Vec::new(), 1, 1) | 571 | + Vec::new() |
| 379 | } else { | 572 | } else { |
| 380 | - fetch_page(store, &filter, requested_page(&query), ADMIN_PAGE_SIZE).await? | 573 | + fetch_entries(store, &filter).await? |
| 381 | }; | 574 | }; |
| 382 | - | 575 | + let groups = fold_groups(&entries, lang, &finder); |
| 383 | - let rows = fold_rows(&entries, lang); | 576 | + let (groups, page, pages) = page_of(groups, requested_page(query)); |
| 384 | - let nav = nav_for( | 577 | + let params = keep_params(&finder, &action, &actor); |
| 385 | - page, | 578 | + let nav = nav_for(page, pages, "/admin/audit", ¶ms); |
| 386 | - pages, | ||
| 387 | - "/admin/audit", | ||
| 388 | - &[("action", action.as_str()), ("actor", actor.as_str())], | ||
| 389 | - ); | ||
| 390 | let live = list_href( | 579 | let live = list_href( |
| 391 | "/admin/audit/events", | 580 | "/admin/audit/events", |
| 392 | &[("action", action.as_str()), ("actor", actor.as_str())], | 581 | &[("action", action.as_str()), ("actor", actor.as_str())], |
| 393 | ); | 582 | ); |
| 394 | let title = g::t(lang, K::AuditLog); | 583 | let title = g::t(lang, K::AuditLog); |
| 395 | Ok(view! { | 584 | Ok(view! { |
| 396 | - shell(title: title, viewer: Some(&viewer), admin_audit_view(lang: lang, live: live, action: action, actor: actor, notice: notice, rows: rows, page: page, pages: pages, nav: nav)) | 585 | + shell(title: title, viewer: Some(&viewer), admin_audit_view(lang: lang, live: live, finder: finder.clone(), action: action.clone(), actor: actor.clone(), notice: notice, groups: groups, page: page, pages: pages, nav: nav)) |
| 397 | }) | 586 | }) |
| 398 | } | 587 | } |
| 399 | 588 | ||
| 400 | -/// The first page of entries the filter selects, as one string: the stream sends when it changes. | 589 | +/// The newest entries the filter selects, as one string: the stream sends when it changes. |
| 401 | /// An unknown action or actor selects nothing, as on the page. | 590 | /// An unknown action or actor selects nothing, as on the page. |
| 402 | async fn first_page_fingerprint(store: &Store, action: &str, actor: &str) -> Result<String> { | 591 | async fn first_page_fingerprint(store: &Store, action: &str, actor: &str) -> Result<String> { |
| 403 | let mut filter = AuditFilter::default(); | 592 | let mut filter = AuditFilter::default(); |
| @@ -413,7 +602,7 @@ async fn first_page_fingerprint(store: &Store, action: &str, actor: &str) -> Res | |||
| 413 | None => return Ok(String::new()), | 602 | None => return Ok(String::new()), |
| 414 | } | 603 | } |
| 415 | } | 604 | } |
| 416 | - let (entries, _, _) = fetch_page(store, &filter, 1, ADMIN_PAGE_SIZE).await?; | 605 | + let entries = store.list_audit_page(&filter, 0, PAGE_ROWS as u32).await?; |
| 417 | Ok(entries | 606 | Ok(entries |
| 418 | .iter() | 607 | .iter() |
| 419 | .map(|entry| entry.id.as_str()) | 608 | .map(|entry| entry.id.as_str()) |
| @@ -444,19 +633,24 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> { | |||
| 444 | let lang = i18n::lang(cx, Some(&viewer.0)); | 633 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 445 | let query = query_params::<AuditQuery>(cx)?; | 634 | let query = query_params::<AuditQuery>(cx)?; |
| 446 | let store = &app_context::<AppState>(cx).store; | 635 | let store = &app_context::<AppState>(cx).store; |
| 447 | - let filter = AuditFilter { | 636 | + let (finder, action, _) = query_parts(query); |
| 637 | + let mut filter = AuditFilter { | ||
| 448 | involving_user: Some(viewer.0.id.clone()), | 638 | involving_user: Some(viewer.0.id.clone()), |
| 449 | ..Default::default() | 639 | ..Default::default() |
| 450 | }; | 640 | }; |
| 451 | - let (entries, page, pages) = | 641 | + // An unknown action is ignored here: the menu only offers known ones. |
| 452 | - fetch_page(store, &filter, requested_page(&query), OWN_PAGE_SIZE).await?; | 642 | + if let Some(known) = AuditAction::parse(&action) { |
| 453 | - | 643 | + filter.action = Some(known); |
| 454 | - let rows = fold_rows(&entries, lang); | 644 | + } |
| 455 | - let nav = nav_for(page, pages, "/settings/security/log", &[]); | 645 | + let entries = fetch_entries(store, &filter).await?; |
| 646 | + let groups = fold_groups(&entries, lang, &finder); | ||
| 647 | + let (groups, page, pages) = page_of(groups, requested_page(query)); | ||
| 648 | + let params = keep_params(&finder, &action, ""); | ||
| 649 | + let nav = nav_for(page, pages, "/settings/security/log", ¶ms); | ||
| 456 | let items = security_rail_for(app_context::<AppState>(cx), lang, &viewer, "log").await?; | 650 | let items = security_rail_for(app_context::<AppState>(cx), lang, &viewer, "log").await?; |
| 457 | let title = g::t(lang, K::SecurityLogTitle); | 651 | let title = g::t(lang, K::SecurityLogTitle); |
| 458 | Ok(view! { | 652 | Ok(view! { |
| 459 | - shell(title: title, viewer: Some(&viewer), own_log_view(lang: lang, items: items, rows: rows, page: page, pages: pages, nav: nav)) | 653 | + shell(title: title, viewer: Some(&viewer), own_log_view(lang: lang, items: items, finder: finder.clone(), action: action.clone(), groups: groups, page: page, pages: pages, nav: nav)) |
| 460 | }) | 654 | }) |
| 461 | } | 655 | } |
| 462 | 656 | ||
| @@ -604,7 +798,8 @@ mod tests { | |||
| 604 | ) | 798 | ) |
| 605 | .await; | 799 | .await; |
| 606 | assert_eq!(status, 200); | 800 | assert_eq!(status, 200); |
| 607 | - assert_eq!(body.matches("login_success").count(), 1); | 801 | + // One row of the viewer's own sign-in (the action filter lists it once more). |
| 802 | + assert_eq!(body.matches("title=\"login_success\"").count(), 1); | ||
| 608 | assert!(body.contains("password_reset_by_admin")); | 803 | assert!(body.contains("password_reset_by_admin")); |
| 609 | 804 | ||
| 610 | // The own log needs a session. | 805 | // The own log needs a session. |
| @@ -618,6 +813,6 @@ mod tests { | |||
| 618 | let row = row_view(&entry, Lang::En); | 813 | let row = row_view(&entry, Lang::En); |
| 619 | assert_eq!(row.actor, "anonymous"); | 814 | assert_eq!(row.actor, "anonymous"); |
| 620 | assert_eq!(row.target, "mallory"); | 815 | assert_eq!(row.target, "mallory"); |
| 621 | - assert_eq!(row.details_inline, ""); | 816 | + assert_eq!(row.details, ""); |
| 622 | } | 817 | } |
| 623 | } | 818 | } |
crates/forge-web/src/pages/avatars.rsmodified+30 -7
| @@ -24,6 +24,9 @@ const PALETTE: [&str; 8] = [ | |||
| 24 | const CACHE_IMMUTABLE: &str = "public, max-age=31536000, immutable"; | 24 | const CACHE_IMMUTABLE: &str = "public, max-age=31536000, immutable"; |
| 25 | /// Without a matching `?v=`, the browser revalidates: the ETag gives a cheap 304. | 25 | /// Without a matching `?v=`, the browser revalidates: the ETag gives a cheap 304. |
| 26 | const CACHE_REVALIDATE: &str = "no-cache"; | 26 | const CACHE_REVALIDATE: &str = "no-cache"; |
| 27 | +/// The generated letter avatar is the same for a username until a photo is set, which changes the | ||
| 28 | +/// link: a page shows it from cache at once and checks it in the background. | ||
| 29 | +const CACHE_DEFAULT: &str = "public, max-age=3600, stale-while-revalidate=604800"; | ||
| 27 | const CSP: &str = "default-src 'none'"; | 30 | const CSP: &str = "default-src 'none'"; |
| 28 | 31 | ||
| 29 | #[query_params(error = bad_request)] | 32 | #[query_params(error = bad_request)] |
| @@ -31,9 +34,10 @@ struct AvatarQuery { | |||
| 31 | v: Option<String>, | 34 | v: Option<String>, |
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | -/// The generated default avatar: the first letter of the username on a palette color. | 37 | +/// The generated default avatar: the first letter of the username on a palette color picked by |
| 35 | -pub fn default_svg(username: &str, user_id: &str) -> String { | 38 | +/// the username, so a page can draw it inline without asking the server. |
| 36 | - let digest = Sha256::digest(user_id.as_bytes()); | 39 | +pub fn default_svg(username: &str) -> String { |
| 40 | + let digest = Sha256::digest(username.as_bytes()); | ||
| 37 | let color = PALETTE[usize::from(digest[0]) % PALETTE.len()]; | 41 | let color = PALETTE[usize::from(digest[0]) % PALETTE.len()]; |
| 38 | let letter = username | 42 | let letter = username |
| 39 | .chars() | 43 | .chars() |
| @@ -45,6 +49,22 @@ pub fn default_svg(username: &str, user_id: &str) -> String { | |||
| 45 | ) | 49 | ) |
| 46 | } | 50 | } |
| 47 | 51 | ||
| 52 | +/// The generated default avatar as a `data:` URL, for an `<img>` of an account known to have no | ||
| 53 | +/// photo: the page shows it at once, with no request. | ||
| 54 | +pub fn default_data_url(username: &str) -> String { | ||
| 55 | + let svg = default_svg(username); | ||
| 56 | + let mut out = String::with_capacity(svg.len() + 40); | ||
| 57 | + out.push_str("data:image/svg+xml,"); | ||
| 58 | + for byte in svg.bytes() { | ||
| 59 | + if byte.is_ascii_alphanumeric() || b" -_.~/=:;,'()".contains(&byte) { | ||
| 60 | + out.push(char::from(byte)); | ||
| 61 | + } else { | ||
| 62 | + out.push_str(&format!("%{byte:02X}")); | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + out | ||
| 66 | +} | ||
| 67 | + | ||
| 48 | fn xml_escape(text: &str) -> String { | 68 | fn xml_escape(text: &str) -> String { |
| 49 | let mut out = String::with_capacity(text.len()); | 69 | let mut out = String::with_capacity(text.len()); |
| 50 | for c in text.chars() { | 70 | for c in text.chars() { |
| @@ -97,10 +117,10 @@ async fn avatar(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec<u8>)> { | |||
| 97 | (png, "image/png", hash, cache) | 117 | (png, "image/png", hash, cache) |
| 98 | } | 118 | } |
| 99 | None => { | 119 | None => { |
| 100 | - let svg = default_svg(&user.username, &user.id).into_bytes(); | 120 | + let svg = default_svg(&user.username).into_bytes(); |
| 101 | let digest = Sha256::digest(&svg); | 121 | let digest = Sha256::digest(&svg); |
| 102 | let tag: String = digest.iter().take(8).map(|b| format!("{b:02x}")).collect(); | 122 | let tag: String = digest.iter().take(8).map(|b| format!("{b:02x}")).collect(); |
| 103 | - (svg, "image/svg+xml", tag, CACHE_REVALIDATE) | 123 | + (svg, "image/svg+xml", tag, CACHE_DEFAULT) |
| 104 | } | 124 | } |
| 105 | }; | 125 | }; |
| 106 | 126 | ||
| @@ -130,9 +150,12 @@ mod tests { | |||
| 130 | 150 | ||
| 131 | #[test] | 151 | #[test] |
| 132 | fn default_svg_escapes_the_letter_and_is_stable() { | 152 | fn default_svg_escapes_the_letter_and_is_stable() { |
| 133 | - let svg = super::default_svg("<", "user-1"); | 153 | + let svg = super::default_svg("<"); |
| 134 | assert!(svg.contains("><</text>"), "{svg}"); | 154 | assert!(svg.contains("><</text>"), "{svg}"); |
| 135 | - assert_eq!(svg, super::default_svg("<", "user-1")); | 155 | + assert_eq!(svg, super::default_svg("<")); |
| 156 | + let url = super::default_data_url("<"); | ||
| 157 | + assert!(url.starts_with("data:image/svg+xml,%3Csvg"), "{url}"); | ||
| 158 | + assert!(!url.contains('<') && !url.contains('#') && !url.contains('"'), "{url}"); | ||
| 136 | assert!(super::PALETTE.iter().any(|c| svg.contains(c))); | 159 | assert!(super::PALETTE.iter().any(|c| svg.contains(c))); |
| 137 | } | 160 | } |
| 138 | 161 | ||
crates/forge-web/src/pages/ci_job.rsmodified+2 -0
| @@ -479,6 +479,8 @@ async fn job_body( | |||
| 479 | <strong>(g::t(lang, K::Log))</strong> | 479 | <strong>(g::t(lang, K::Log))</strong> |
| 480 | <div class="ci-tl-tools"> | 480 | <div class="ci-tl-tools"> |
| 481 | <input type="search" class="ci-logsearch" data-log-q="true" placeholder=(g::t(lang, K::LogSearch)) aria-label=(g::t(lang, K::LogSearch)) autocomplete="off" spellcheck="false"> | 481 | <input type="search" class="ci-logsearch" data-log-q="true" placeholder=(g::t(lang, K::LogSearch)) aria-label=(g::t(lang, K::LogSearch)) autocomplete="off" spellcheck="false"> |
| 482 | + <label class="find-opt" title=(crate::pages::passkeys::s(lang, "Only the text as typed, as one piece", "Yalnızca yazılan metin, tek parça olarak"))><input type="checkbox" data-log-exact="true"><span>(crate::pages::passkeys::s(lang, "Exact", "Tam"))</span></label> | ||
| 483 | + <label class="find-opt" title=(crate::pages::passkeys::s(lang, "Keep upper and lower case apart", "Büyük ve küçük harfi ayırt et"))><input type="checkbox" data-log-case="true"><span>"Aa"</span></label> | ||
| 482 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> | 484 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> |
| 483 | <button type="button" class="act" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> | 485 | <button type="button" class="act" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> |
| 484 | <button type="button" class="act" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> | 486 | <button type="button" class="act" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> |
crates/forge-web/src/pages/ci_runs.rsmodified+2 -0
| @@ -2623,6 +2623,8 @@ async fn run_log( | |||
| 2623 | if let Some(log) = run.log.as_ref() { | 2623 | if let Some(log) = run.log.as_ref() { |
| 2624 | <div class="ci-tl-tools"> | 2624 | <div class="ci-tl-tools"> |
| 2625 | <input type="search" class="ci-logsearch" data-log-q="true" placeholder=(g::t(lang, K::LogSearch)) aria-label=(g::t(lang, K::LogSearch)) autocomplete="off" spellcheck="false"> | 2625 | <input type="search" class="ci-logsearch" data-log-q="true" placeholder=(g::t(lang, K::LogSearch)) aria-label=(g::t(lang, K::LogSearch)) autocomplete="off" spellcheck="false"> |
| 2626 | + <label class="find-opt" title=(crate::pages::passkeys::s(lang, "Only the text as typed, as one piece", "Yalnızca yazılan metin, tek parça olarak"))><input type="checkbox" data-log-exact="true"><span>(crate::pages::passkeys::s(lang, "Exact", "Tam"))</span></label> | ||
| 2627 | + <label class="find-opt" title=(crate::pages::passkeys::s(lang, "Keep upper and lower case apart", "Büyük ve küçük harfi ayırt et"))><input type="checkbox" data-log-case="true"><span>"Aa"</span></label> | ||
| 2626 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> | 2628 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> |
| 2627 | <button type="button" class="act" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> | 2629 | <button type="button" class="act" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> |
| 2628 | <button type="button" class="act" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> | 2630 | <button type="button" class="act" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> |
crates/forge-web/src/pages/explore.rsmodified+200 -87
| @@ -1,8 +1,10 @@ | |||
| 1 | //! Page: public repo listing at `/explore`. Only public repos are listed, even for their owners | 1 | //! Page: public repo listing at `/explore`. Only public repos are listed, even for their owners |
| 2 | -//! (private repos never appear here). A search box filters by name or description, three sort | 2 | +//! (private repos never appear here). A live search reads names and descriptions, forgiving typos |
| 3 | -//! orders are offered, and 30 repos are shown per page. `explore` is a reserved username, so this | 3 | +//! unless Exact or Aa is on; three sort orders are offered, and 12 repos are shown per page, so a |
| 4 | +//! page fits the window. `explore` is a reserved username, so this | ||
| 4 | //! route cannot collide with a profile. | 5 | //! route cannot collide with a profile. |
| 5 | 6 | ||
| 7 | +use forge_core::{Repo, User}; | ||
| 6 | use forge_core::store::RepoSort; | 8 | use forge_core::store::RepoSort; |
| 7 | use topcoat::Result; | 9 | use topcoat::Result; |
| 8 | use topcoat::context::{Cx, app_context}; | 10 | use topcoat::context::{Cx, app_context}; |
| @@ -19,11 +21,13 @@ use crate::views::parts::{SubPart, head}; | |||
| 19 | use crate::views::repo_list::{ | 21 | use crate::views::repo_list::{ |
| 20 | PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips, | 22 | PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips, |
| 21 | }; | 23 | }; |
| 22 | -use crate::views::{enc, now_unix, shell}; | 24 | +use crate::pages::issues_list::list_href; |
| 25 | +use crate::views::find::{Finder, finder_field}; | ||
| 26 | +use crate::views::{now_unix, shell}; | ||
| 23 | 27 | ||
| 24 | -const PER_PAGE: u64 = 30; | 28 | +const PER_PAGE: u64 = 12; |
| 25 | -/// Longest search text kept, in characters. | 29 | +/// The most public repos a search reads. |
| 26 | -const MAX_QUERY_CHARS: usize = 100; | 30 | +const SEARCH_CAP: u64 = 5000; |
| 27 | 31 | ||
| 28 | /// Sort keys in the order their links are shown, with the text key of each link. The first one is | 32 | /// Sort keys in the order their links are shown, with the text key of each link. The first one is |
| 29 | /// the default. | 33 | /// the default. |
| @@ -36,20 +40,61 @@ const SORTS: [(&str, K); 3] = [ | |||
| 36 | #[query_params(error = bad_request)] | 40 | #[query_params(error = bad_request)] |
| 37 | struct ExploreQuery { | 41 | struct ExploreQuery { |
| 38 | q: Option<String>, | 42 | q: Option<String>, |
| 43 | + exact: Option<String>, | ||
| 44 | + case: Option<String>, | ||
| 39 | sort: Option<String>, | 45 | sort: Option<String>, |
| 40 | page: Option<String>, | 46 | page: Option<String>, |
| 47 | + tab: Option<String>, | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +/// The Organizations tab's key in the query. | ||
| 51 | +const ORGS_TAB: &str = "organizations"; | ||
| 52 | + | ||
| 53 | +/// True when the query asks for the Organizations tab. | ||
| 54 | +fn orgs_tab(query: &ExploreQuery) -> bool { | ||
| 55 | + query.tab.as_deref() == Some(ORGS_TAB) | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +/// `/explore?tab=organizations` with the given search and page. | ||
| 59 | +fn orgs_href(finder: &Finder, page: u64) -> String { | ||
| 60 | + let number = page.to_string(); | ||
| 61 | + let mut params = finder.params(); | ||
| 62 | + params.push(("tab", ORGS_TAB)); | ||
| 63 | + params.push(("page", number.as_str())); | ||
| 64 | + list_href("/explore", ¶ms) | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +/// The organizations the search matches, by name, and how many there are: one page. | ||
| 68 | +async fn org_listing(state: &AppState, finder: &Finder, page: u64) -> Result<(Vec<User>, u64)> { | ||
| 69 | + let mut all: Vec<User> = state | ||
| 70 | + .store | ||
| 71 | + .list_orgs() | ||
| 72 | + .await? | ||
| 73 | + .into_iter() | ||
| 74 | + .filter(|org| { | ||
| 75 | + finder.matches_any(&[ | ||
| 76 | + org.username.as_str(), | ||
| 77 | + org.display_name.as_deref().unwrap_or(""), | ||
| 78 | + ]) | ||
| 79 | + }) | ||
| 80 | + .collect(); | ||
| 81 | + all.sort_by_key(|org| org.username.to_lowercase()); | ||
| 82 | + let total = all.len() as u64; | ||
| 83 | + let shown = all | ||
| 84 | + .into_iter() | ||
| 85 | + .skip(((page.max(1) - 1) * PER_PAGE) as usize) | ||
| 86 | + .take(PER_PAGE as usize) | ||
| 87 | + .collect(); | ||
| 88 | + Ok((shown, total)) | ||
| 41 | } | 89 | } |
| 42 | 90 | ||
| 43 | /// `/explore` with the given search, sort key and page. An empty search is left out. | 91 | /// `/explore` with the given search, sort key and page. An empty search is left out. |
| 44 | -fn explore_href(q: &str, sort: &str, page: u64) -> String { | 92 | +fn explore_href(finder: &Finder, sort: &str, page: u64) -> String { |
| 45 | - let mut href = String::from("/explore?"); | 93 | + let number = page.to_string(); |
| 46 | - if !q.is_empty() { | 94 | + let mut params = finder.params(); |
| 47 | - href.push_str("q="); | 95 | + params.push(("sort", sort)); |
| 48 | - href.push_str(&enc(q)); | 96 | + params.push(("page", number.as_str())); |
| 49 | - href.push('&'); | 97 | + list_href("/explore", ¶ms) |
| 50 | - } | ||
| 51 | - href.push_str(&format!("sort={sort}&page={page}")); | ||
| 52 | - href | ||
| 53 | } | 98 | } |
| 54 | 99 | ||
| 55 | /// Maps the `sort` query value to a key from `SORTS`; anything unknown means the default. | 100 | /// Maps the `sort` query value to a key from `SORTS`; anything unknown means the default. |
| @@ -61,16 +106,13 @@ fn sort_key(raw: Option<&str>) -> &'static str { | |||
| 61 | .unwrap_or(SORTS[0].0) | 106 | .unwrap_or(SORTS[0].0) |
| 62 | } | 107 | } |
| 63 | 108 | ||
| 64 | -/// The search text, sort key and page the query asks for, with the defaults filled in. | 109 | +/// The search, sort key and page the query asks for, with the defaults filled in. |
| 65 | -fn listing_args(query: &ExploreQuery) -> (String, &'static str, u64) { | 110 | +fn listing_args(query: &ExploreQuery) -> (Finder, &'static str, u64) { |
| 66 | - let q: String = query | 111 | + let finder = Finder::new( |
| 67 | - .q | 112 | + query.q.as_deref(), |
| 68 | - .as_deref() | 113 | + query.exact.as_deref(), |
| 69 | - .unwrap_or("") | 114 | + query.case.as_deref(), |
| 70 | - .trim() | 115 | + ); |
| 71 | - .chars() | ||
| 72 | - .take(MAX_QUERY_CHARS) | ||
| 73 | - .collect(); | ||
| 74 | let sort = sort_key(query.sort.as_deref()); | 116 | let sort = sort_key(query.sort.as_deref()); |
| 75 | let page = query | 117 | let page = query |
| 76 | .page | 118 | .page |
| @@ -78,28 +120,63 @@ fn listing_args(query: &ExploreQuery) -> (String, &'static str, u64) { | |||
| 78 | .and_then(|p| p.parse::<u64>().ok()) | 120 | .and_then(|p| p.parse::<u64>().ok()) |
| 79 | .unwrap_or(1) | 121 | .unwrap_or(1) |
| 80 | .max(1); | 122 | .max(1); |
| 81 | - (q, sort, page) | 123 | + (finder, sort, page) |
| 124 | +} | ||
| 125 | + | ||
| 126 | +/// The public repos the search matches, in the sort's order, and how many there are: one page. | ||
| 127 | +async fn listing( | ||
| 128 | + state: &AppState, | ||
| 129 | + finder: &Finder, | ||
| 130 | + sort: &'static str, | ||
| 131 | + page: u64, | ||
| 132 | +) -> Result<(Vec<(Repo, u64, String)>, u64)> { | ||
| 133 | + let sort_kind = match sort { | ||
| 134 | + "stars" => RepoSort::MostStars, | ||
| 135 | + "name" => RepoSort::Name, | ||
| 136 | + _ => RepoSort::RecentlyUpdated, | ||
| 137 | + }; | ||
| 138 | + let (all, _) = state | ||
| 139 | + .store | ||
| 140 | + .list_public_repos(None, sort_kind, 1, SEARCH_CAP) | ||
| 141 | + .await?; | ||
| 142 | + let matching: Vec<_> = all | ||
| 143 | + .into_iter() | ||
| 144 | + .filter(|(repo, _, _)| { | ||
| 145 | + let full = format!("{}/{}", repo.owner_name, repo.name); | ||
| 146 | + finder.matches_any(&[full.as_str(), repo.description.as_str()]) | ||
| 147 | + }) | ||
| 148 | + .collect(); | ||
| 149 | + let total = matching.len() as u64; | ||
| 150 | + let shown = matching | ||
| 151 | + .into_iter() | ||
| 152 | + .skip(((page.max(1) - 1) * PER_PAGE) as usize) | ||
| 153 | + .take(PER_PAGE as usize) | ||
| 154 | + .collect(); | ||
| 155 | + Ok((shown, total)) | ||
| 82 | } | 156 | } |
| 83 | 157 | ||
| 84 | #[page("/explore")] | 158 | #[page("/explore")] |
| 85 | async fn explore_page(cx: &Cx) -> Result<impl View> { | 159 | async fn explore_page(cx: &Cx) -> Result<impl View> { |
| 86 | let query = query_params::<ExploreQuery>(cx)?; | 160 | let query = query_params::<ExploreQuery>(cx)?; |
| 87 | - let (q, sort, page) = listing_args(query); | 161 | + let (finder, sort, page) = listing_args(query); |
| 88 | - let live = explore_href(&q, sort, page).replacen("/explore?", "/explore/events?", 1); | 162 | + let live = explore_href(&finder, sort, page).replacen("/explore?", "/explore/events?", 1); |
| 89 | let viewer = current_user(cx).await?; | 163 | let viewer = current_user(cx).await?; |
| 90 | let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u)); | 164 | let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u)); |
| 91 | let state = app_context::<AppState>(cx); | 165 | let state = app_context::<AppState>(cx); |
| 92 | - | 166 | + let on_orgs = orgs_tab(query); |
| 93 | - let sort_kind = match sort { | 167 | + let (listed, repo_total) = listing(state, &finder, sort, page).await?; |
| 94 | - "stars" => RepoSort::MostStars, | 168 | + let (org_page, org_total) = org_listing(state, &finder, page).await?; |
| 95 | - "name" => RepoSort::Name, | 169 | + let total = if on_orgs { org_total } else { repo_total }; |
| 96 | - _ => RepoSort::RecentlyUpdated, | 170 | + let (_, repos_all) = state |
| 97 | - }; | ||
| 98 | - let search = (!q.is_empty()).then_some(q.as_str()); | ||
| 99 | - let (listed, total) = state | ||
| 100 | .store | 171 | .store |
| 101 | - .list_public_repos(search, sort_kind, page, PER_PAGE) | 172 | + .list_public_repos(None, RepoSort::RecentlyUpdated, 1, 1) |
| 102 | .await?; | 173 | .await?; |
| 174 | + let orgs_all = state.store.list_orgs().await?.len() as u64; | ||
| 175 | + let live = if on_orgs { | ||
| 176 | + orgs_href(&finder, page).replacen("/explore?", "/explore/events?", 1) | ||
| 177 | + } else { | ||
| 178 | + live | ||
| 179 | + }; | ||
| 103 | 180 | ||
| 104 | let now = now_unix(); | 181 | let now = now_unix(); |
| 105 | let tz = viewer.as_ref().map_or("UTC", |(u, _)| u.timezone.as_str()); | 182 | let tz = viewer.as_ref().map_or("UTC", |(u, _)| u.timezone.as_str()); |
| @@ -107,30 +184,38 @@ async fn explore_page(cx: &Cx) -> Result<impl View> { | |||
| 107 | .into_iter() | 184 | .into_iter() |
| 108 | .map(|listed| RepoRow::new(lang, tz, now, listed)) | 185 | .map(|listed| RepoRow::new(lang, tz, now, listed)) |
| 109 | .collect(); | 186 | .collect(); |
| 110 | - let orgs: Vec<String> = state | 187 | + let mut orgs: Vec<(String, String)> = Vec::new(); |
| 111 | - .store | 188 | + for org in org_page { |
| 112 | - .list_orgs() | 189 | + let hash = state.store.avatar_hash(&org.id).await?; |
| 113 | - .await? | 190 | + let avatar = crate::views::avatar_url(&org.username, hash.as_deref()); |
| 114 | - .into_iter() | 191 | + orgs.push((org.username, avatar)); |
| 115 | - .map(|org| org.username) | 192 | + } |
| 116 | - .collect(); | ||
| 117 | let pages = total.div_ceil(PER_PAGE).max(1); | 193 | let pages = total.div_ceil(PER_PAGE).max(1); |
| 118 | let page = page.min(pages); | 194 | let page = page.min(pages); |
| 119 | let sort_links: Vec<SortLink> = SORTS | 195 | let sort_links: Vec<SortLink> = SORTS |
| 120 | .iter() | 196 | .iter() |
| 121 | .map(|(key, label)| SortLink { | 197 | .map(|(key, label)| SortLink { |
| 122 | label: g::t(lang, *label), | 198 | label: g::t(lang, *label), |
| 123 | - href: explore_href(&q, key, 1), | 199 | + href: explore_href(&finder, key, 1), |
| 124 | current: *key == sort, | 200 | current: *key == sort, |
| 125 | }) | 201 | }) |
| 126 | .collect(); | 202 | .collect(); |
| 127 | - let nav = pager_links(page, pages, |n| explore_href(&q, sort, n)); | 203 | + let nav = if on_orgs { |
| 204 | + pager_links(page, pages, |n| orgs_href(&finder, n)) | ||
| 205 | + } else { | ||
| 206 | + pager_links(page, pages, |n| explore_href(&finder, sort, n)) | ||
| 207 | + }; | ||
| 208 | + let tabs = vec![ | ||
| 209 | + (g::t(lang, K::Repositories), explore_href(&Finder::default(), sort, 1), repos_all, !on_orgs), | ||
| 210 | + (g::t(lang, K::Organizations), orgs_href(&Finder::default(), 1), orgs_all, on_orgs), | ||
| 211 | + ]; | ||
| 128 | let title = g::t(lang, K::Explore); | 212 | let title = g::t(lang, K::Explore); |
| 129 | 213 | ||
| 130 | Ok(view! { cx => | 214 | Ok(view! { cx => |
| 131 | shell(title: title, viewer: viewer.as_ref(), | 215 | shell(title: title, viewer: viewer.as_ref(), |
| 132 | - explore_body(q: q, sort: sort, sort_links: sort_links, rows: rows, | 216 | + explore_body(finder: finder, sort: sort, sort_links: sort_links, rows: rows, |
| 133 | - total: total, page: page, pages: pages, nav: nav, orgs: orgs, lang: lang, live: live)) | 217 | + total: total, page: page, pages: pages, nav: nav, orgs: orgs, lang: lang, live: live, |
| 218 | + on_orgs: on_orgs, tabs: tabs)) | ||
| 134 | }) | 219 | }) |
| 135 | } | 220 | } |
| 136 | 221 | ||
| @@ -140,12 +225,13 @@ async fn explore_page(cx: &Cx) -> Result<impl View> { | |||
| 140 | #[route(GET "/explore/events")] | 225 | #[route(GET "/explore/events")] |
| 141 | async fn explore_events(cx: &Cx) -> Result<Response> { | 226 | async fn explore_events(cx: &Cx) -> Result<Response> { |
| 142 | let query = query_params::<ExploreQuery>(cx)?; | 227 | let query = query_params::<ExploreQuery>(cx)?; |
| 143 | - let (q, sort, page) = listing_args(query); | 228 | + let (finder, sort, page) = listing_args(query); |
| 229 | + let on_orgs = orgs_tab(query); | ||
| 144 | let state = app_context::<AppState>(cx).clone(); | 230 | let state = app_context::<AppState>(cx).clone(); |
| 145 | stream_changes(cx, &state.live.clone(), &[Topic::Explore], move || { | 231 | stream_changes(cx, &state.live.clone(), &[Topic::Explore], move || { |
| 146 | let state = state.clone(); | 232 | let state = state.clone(); |
| 147 | - let q = q.clone(); | 233 | + let finder = finder.clone(); |
| 148 | - async move { explore_fingerprint(&state, &q, sort, page).await } | 234 | + async move { explore_fingerprint(&state, &finder, sort, page, on_orgs).await } |
| 149 | }) | 235 | }) |
| 150 | .await | 236 | .await |
| 151 | } | 237 | } |
| @@ -153,20 +239,18 @@ async fn explore_events(cx: &Cx) -> Result<Response> { | |||
| 153 | /// The state the explore listing shows: its total, each row with its stars, and the org names. | 239 | /// The state the explore listing shows: its total, each row with its stars, and the org names. |
| 154 | async fn explore_fingerprint( | 240 | async fn explore_fingerprint( |
| 155 | state: &AppState, | 241 | state: &AppState, |
| 156 | - q: &str, | 242 | + finder: &Finder, |
| 157 | sort: &'static str, | 243 | sort: &'static str, |
| 158 | page: u64, | 244 | page: u64, |
| 245 | + on_orgs: bool, | ||
| 159 | ) -> Result<String> { | 246 | ) -> Result<String> { |
| 160 | - let sort_kind = match sort { | 247 | + if on_orgs { |
| 161 | - "stars" => RepoSort::MostStars, | 248 | + let (orgs, total) = org_listing(state, finder, page).await?; |
| 162 | - "name" => RepoSort::Name, | 249 | + let mut lines = vec![total.to_string()]; |
| 163 | - _ => RepoSort::RecentlyUpdated, | 250 | + lines.extend(orgs.into_iter().map(|org| format!("org {}", org.username))); |
| 164 | - }; | 251 | + return Ok(lines.join("\n")); |
| 165 | - let search = (!q.is_empty()).then_some(q); | 252 | + } |
| 166 | - let (listed, total) = state | 253 | + let (listed, total) = listing(state, finder, sort, page).await?; |
| 167 | - .store | ||
| 168 | - .list_public_repos(search, sort_kind, page, PER_PAGE) | ||
| 169 | - .await?; | ||
| 170 | let mut lines = vec![total.to_string()]; | 254 | let mut lines = vec![total.to_string()]; |
| 171 | for (repo, stars, activity) in listed { | 255 | for (repo, stars, activity) in listed { |
| 172 | lines.push(format!( | 256 | lines.push(format!( |
| @@ -174,15 +258,12 @@ async fn explore_fingerprint( | |||
| 174 | repo.owner_name, repo.name, repo.description, repo.visibility, repo.default_branch | 258 | repo.owner_name, repo.name, repo.description, repo.visibility, repo.default_branch |
| 175 | )); | 259 | )); |
| 176 | } | 260 | } |
| 177 | - for org in state.store.list_orgs().await? { | ||
| 178 | - lines.push(format!("org {}", org.username)); | ||
| 179 | - } | ||
| 180 | Ok(lines.join("\n")) | 261 | Ok(lines.join("\n")) |
| 181 | } | 262 | } |
| 182 | 263 | ||
| 183 | #[component] | 264 | #[component] |
| 184 | async fn explore_body( | 265 | async fn explore_body( |
| 185 | - q: String, | 266 | + finder: Finder, |
| 186 | sort: &'static str, | 267 | sort: &'static str, |
| 187 | sort_links: Vec<SortLink>, | 268 | sort_links: Vec<SortLink>, |
| 188 | rows: Vec<RepoRow>, | 269 | rows: Vec<RepoRow>, |
| @@ -190,47 +271,79 @@ async fn explore_body( | |||
| 190 | page: u64, | 271 | page: u64, |
| 191 | pages: u64, | 272 | pages: u64, |
| 192 | nav: (Vec<PageLink>, Option<String>, Option<String>), | 273 | nav: (Vec<PageLink>, Option<String>, Option<String>), |
| 193 | - orgs: Vec<String>, | 274 | + orgs: Vec<(String, String)>, |
| 194 | lang: Lang, | 275 | lang: Lang, |
| 195 | live: String, | 276 | live: String, |
| 277 | + on_orgs: bool, | ||
| 278 | + tabs: Vec<(&'static str, String, u64, bool)>, | ||
| 196 | ) -> Result<impl View> { | 279 | ) -> Result<impl View> { |
| 197 | - let empty = rows.is_empty(); | 280 | + let empty = if on_orgs { orgs.is_empty() } else { rows.is_empty() }; |
| 198 | - let has_search = !q.is_empty(); | 281 | + let has_search = !finder.is_empty(); |
| 199 | - let has_orgs = !orgs.is_empty(); | ||
| 200 | let (links, prev, next) = nav; | 282 | let (links, prev, next) = nav; |
| 201 | - let clear_href = explore_href("", sort, 1); | 283 | + let clear_href = if on_orgs { |
| 284 | + orgs_href(&Finder::default(), 1) | ||
| 285 | + } else { | ||
| 286 | + explore_href(&Finder::default(), sort, 1) | ||
| 287 | + }; | ||
| 288 | + let placeholder = if on_orgs { | ||
| 289 | + crate::pages::passkeys::s(lang, "Search organizations", "Kuruluşlarda ara") | ||
| 290 | + } else { | ||
| 291 | + g::t(lang, K::SearchPublicRepos) | ||
| 292 | + }; | ||
| 293 | + let count_text = match (lang, total) { | ||
| 294 | + (Lang::Tr, n) => format!("{n} kuruluş"), | ||
| 295 | + (_, 1) => "1 organization".to_owned(), | ||
| 296 | + (_, n) => format!("{n} organizations"), | ||
| 297 | + }; | ||
| 298 | + let empty_text = if on_orgs { | ||
| 299 | + crate::pages::passkeys::s(lang, "No organization matches.", "Eşleşen kuruluş yok.") | ||
| 300 | + } else { | ||
| 301 | + g::t(lang, K::NoPublicReposMatch) | ||
| 302 | + }; | ||
| 202 | Ok(view! { | 303 | Ok(view! { |
| 203 | head(title: g::t(lang, K::Explore), sub: vec![SubPart::text(g::t(lang, K::PublicReposIntro))]) | 304 | head(title: g::t(lang, K::Explore), sub: vec![SubPart::text(g::t(lang, K::PublicReposIntro))]) |
| 305 | + <nav class="tabs" aria-label=(g::t(lang, K::Explore))> | ||
| 306 | + for (label, href, count, on) in tabs.into_iter() { | ||
| 307 | + <a href=(href) aria-current=(on.then_some("page"))>(label) " " <span class="tab-count">(count.to_string())</span></a> | ||
| 308 | + } | ||
| 309 | + </nav> | ||
| 204 | <div class="sheet" data-live=(live.as_str())> | 310 | <div class="sheet" data-live=(live.as_str())> |
| 205 | <div class="sheet-tools"> | 311 | <div class="sheet-tools"> |
| 206 | - <strong>(g::repo_count(lang, total))</strong> | 312 | + if on_orgs { |
| 207 | - <form method="get" action="/explore" class="plain-search" role="search"> | 313 | + <strong>(count_text.as_str())</strong> |
| 208 | - <input type="search" name="q" value=(q.as_str()) data-live-search="" | 314 | + } else { |
| 209 | - placeholder=(g::t(lang, K::SearchPublicRepos)) aria-label=(g::t(lang, K::SearchPublicRepos))> | 315 | + <strong>(g::repo_count(lang, total))</strong> |
| 210 | - <input type="hidden" name="sort" value=(sort)> | 316 | + } |
| 211 | - <button type="submit" class="act">(g::t(lang, K::Search))</button> | 317 | + <form method="get" action="/explore" role="search"> |
| 318 | + finder_field(lang: lang, finder: finder, placeholder: placeholder, id: Some("explore-q")) | ||
| 319 | + if on_orgs { | ||
| 320 | + <input type="hidden" name="tab" value=(ORGS_TAB)> | ||
| 321 | + } else { | ||
| 322 | + <input type="hidden" name="sort" value=(sort)> | ||
| 323 | + } | ||
| 212 | </form> | 324 | </form> |
| 213 | - sort_chips(links: sort_links, lang: lang) | 325 | + if !on_orgs { |
| 326 | + sort_chips(links: sort_links, lang: lang) | ||
| 327 | + } | ||
| 214 | </div> | 328 | </div> |
| 215 | if empty { | 329 | if empty { |
| 216 | - <p class="state">(g::t(lang, K::NoPublicReposMatch))</p> | 330 | + <p class="state">(empty_text)</p> |
| 217 | if has_search { | 331 | if has_search { |
| 218 | <div class="acts"> | 332 | <div class="acts"> |
| 219 | <a class="act" href=(clear_href.as_str())>(g::t(lang, K::ClearSearch))</a> | 333 | <a class="act" href=(clear_href.as_str())>(g::t(lang, K::ClearSearch))</a> |
| 220 | </div> | 334 | </div> |
| 221 | } | 335 | } |
| 336 | + } else if on_orgs { | ||
| 337 | + for (name, avatar) in orgs.into_iter() { | ||
| 338 | + <a class="line" href=(crate::views::user_href(&name)) data-kb-row=""> | ||
| 339 | + <img class="avatar avatar-sm" src=(avatar) alt="" width="24" height="24"> | ||
| 340 | + <span class="name">(name)</span> | ||
| 341 | + </a> | ||
| 342 | + } | ||
| 222 | } else { | 343 | } else { |
| 223 | repo_rows(rows: rows, lang: lang) | 344 | repo_rows(rows: rows, lang: lang) |
| 224 | } | 345 | } |
| 225 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) | 346 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) |
| 226 | - if has_orgs { | ||
| 227 | - <section class="sec"> | ||
| 228 | - <h2>(g::t(lang, K::Organizations))</h2> | ||
| 229 | - for org in orgs.iter() { | ||
| 230 | - <a class="line" href=(format!("/{}", org.as_str()))><span class="name">(org.as_str())</span></a> | ||
| 231 | - } | ||
| 232 | - </section> | ||
| 233 | - } | ||
| 234 | </div> | 347 | </div> |
| 235 | }) | 348 | }) |
| 236 | } | 349 | } |
crates/forge-web/src/pages/import.rsmodified+49 -29
| @@ -180,12 +180,15 @@ async fn source_tabs(lang: Lang, base: &str, active: Source) -> Result<impl View | |||
| 180 | let gitlab = format!("{base}?source=gitlab"); | 180 | let gitlab = format!("{base}?source=gitlab"); |
| 181 | let forgejo = format!("{base}?source=forgejo"); | 181 | let forgejo = format!("{base}?source=forgejo"); |
| 182 | Ok(view! { | 182 | Ok(view! { |
| 183 | - <nav class="tabs" aria-label=(g::t(lang, K::TabImport))> | 183 | + <div class="field"> |
| 184 | - <a href=(git.as_str()) aria-current=((active == Source::Git).then_some("page"))>(g::t(lang, K::SrcGit))</a> | 184 | + <span class="field-label">(crate::pages::passkeys::s(lang, "Source", "Kaynak"))</span> |
| 185 | - <a href=(github.as_str()) aria-current=((active == Source::GitHub).then_some("page"))>(g::t(lang, K::SrcGitHub))</a> | 185 | + <nav class="choice" aria-label=(g::t(lang, K::TabImport))> |
| 186 | - <a href=(gitlab.as_str()) aria-current=((active == Source::GitLab).then_some("page"))>(g::t(lang, K::SrcGitLab))</a> | 186 | + <a href=(git.as_str()) aria-current=((active == Source::Git).then_some("page"))>(g::t(lang, K::SrcGit))</a> |
| 187 | - <a href=(forgejo.as_str()) aria-current=((active == Source::Forgejo).then_some("page"))>(g::t(lang, K::SrcForgejo))</a> | 187 | + <a href=(github.as_str()) aria-current=((active == Source::GitHub).then_some("page"))>(g::t(lang, K::SrcGitHub))</a> |
| 188 | - </nav> | 188 | + <a href=(gitlab.as_str()) aria-current=((active == Source::GitLab).then_some("page"))>(g::t(lang, K::SrcGitLab))</a> |
| 189 | + <a href=(forgejo.as_str()) aria-current=((active == Source::Forgejo).then_some("page"))>(g::t(lang, K::SrcForgejo))</a> | ||
| 190 | + </nav> | ||
| 191 | + </div> | ||
| 189 | }) | 192 | }) |
| 190 | } | 193 | } |
| 191 | 194 | ||
| @@ -278,6 +281,7 @@ impl Draft { | |||
| 278 | #[component] | 281 | #[component] |
| 279 | async fn import_form( | 282 | async fn import_form( |
| 280 | lang: Lang, | 283 | lang: Lang, |
| 284 | + username: String, | ||
| 281 | csrf: &str, | 285 | csrf: &str, |
| 282 | draft: Draft, | 286 | draft: Draft, |
| 283 | error: Option<String>, | 287 | error: Option<String>, |
| @@ -317,24 +321,16 @@ async fn import_form( | |||
| 317 | let opts = draft.opts; | 321 | let opts = draft.opts; |
| 318 | Ok(view! { | 322 | Ok(view! { |
| 319 | head(title: g::t(lang, K::ImportTitle), sub: vec![SubPart::text(g::t(lang, K::ImportIntro))]) | 323 | head(title: g::t(lang, K::ImportTitle), sub: vec![SubPart::text(g::t(lang, K::ImportIntro))]) |
| 324 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "repositories".to_owned()) | ||
| 320 | newrepo_tabs(lang: lang, active: "import") | 325 | newrepo_tabs(lang: lang, active: "import") |
| 321 | - source_tabs(lang: lang, base: "/new/import", active: source) | ||
| 322 | <div class="sheet fit"> | 326 | <div class="sheet fit"> |
| 323 | - if !is_git { | ||
| 324 | - <section class="sec"> | ||
| 325 | - <h2>(g::t(lang, K::BulkLink))</h2> | ||
| 326 | - <p class="hint">(g::t(lang, K::BulkIntro))</p> | ||
| 327 | - <div class="acts"> | ||
| 328 | - <a class="act" href=(bulk_href.as_str())>(g::t(lang, K::BulkLinkButton))</a> | ||
| 329 | - </div> | ||
| 330 | - </section> | ||
| 331 | - } | ||
| 332 | <form method="post" action="/new/import" class="fields"> | 327 | <form method="post" action="/new/import" class="fields"> |
| 333 | if let Some(message) = error { | 328 | if let Some(message) = error { |
| 334 | alert(message: message.as_str()) | 329 | alert(message: message.as_str()) |
| 335 | } | 330 | } |
| 336 | csrf_field(token: csrf) | 331 | csrf_field(token: csrf) |
| 337 | <input type="hidden" name="source" value=(source_value)> | 332 | <input type="hidden" name="source" value=(source_value)> |
| 333 | + source_tabs(lang: lang, base: "/new/import", active: source) | ||
| 338 | if has_instance { | 334 | if has_instance { |
| 339 | <div class="field"> | 335 | <div class="field"> |
| 340 | <label for="import-instance">(instance_label)</label> | 336 | <label for="import-instance">(instance_label)</label> |
| @@ -379,6 +375,15 @@ async fn import_form( | |||
| 379 | visibility_pick(lang: lang, private: private) | 375 | visibility_pick(lang: lang, private: private) |
| 380 | <button type="submit" class="primary">(g::t(lang, K::StartImport))</button> | 376 | <button type="submit" class="primary">(g::t(lang, K::StartImport))</button> |
| 381 | </form> | 377 | </form> |
| 378 | + if !is_git { | ||
| 379 | + <section class="sec"> | ||
| 380 | + <h2>(g::t(lang, K::BulkLink))</h2> | ||
| 381 | + <p class="hint">(g::t(lang, K::BulkIntro))</p> | ||
| 382 | + <div class="acts"> | ||
| 383 | + <a class="act" href=(bulk_href.as_str())>(g::t(lang, K::BulkLinkButton))</a> | ||
| 384 | + </div> | ||
| 385 | + </section> | ||
| 386 | + } | ||
| 382 | </div> | 387 | </div> |
| 383 | }) | 388 | }) |
| 384 | } | 389 | } |
| @@ -390,6 +395,7 @@ const RECENT_IMPORTS: usize = 5; | |||
| 390 | #[component] | 395 | #[component] |
| 391 | async fn import_home( | 396 | async fn import_home( |
| 392 | lang: Lang, | 397 | lang: Lang, |
| 398 | + username: String, | ||
| 393 | csrf: String, | 399 | csrf: String, |
| 394 | draft: Draft, | 400 | draft: Draft, |
| 395 | owners: Vec<String>, | 401 | owners: Vec<String>, |
| @@ -397,7 +403,7 @@ async fn import_home( | |||
| 397 | more: bool, | 403 | more: bool, |
| 398 | ) -> Result<impl View> { | 404 | ) -> Result<impl View> { |
| 399 | Ok(view! { | 405 | Ok(view! { |
| 400 | - import_form(lang: lang, csrf: csrf.as_str(), draft: draft, error: None, owners: owners) | 406 | + import_form(lang: lang, username: username, csrf: csrf.as_str(), draft: draft, error: None, owners: owners) |
| 401 | recent_imports(lang: lang, jobs: jobs, more: more) | 407 | recent_imports(lang: lang, jobs: jobs, more: more) |
| 402 | }) | 408 | }) |
| 403 | } | 409 | } |
| @@ -406,13 +412,14 @@ async fn import_home( | |||
| 406 | #[component] | 412 | #[component] |
| 407 | async fn import_error_body( | 413 | async fn import_error_body( |
| 408 | lang: Lang, | 414 | lang: Lang, |
| 415 | + username: String, | ||
| 409 | csrf: String, | 416 | csrf: String, |
| 410 | draft: Draft, | 417 | draft: Draft, |
| 411 | error: String, | 418 | error: String, |
| 412 | owners: Vec<String>, | 419 | owners: Vec<String>, |
| 413 | ) -> Result<impl View> { | 420 | ) -> Result<impl View> { |
| 414 | Ok(view! { | 421 | Ok(view! { |
| 415 | - import_form(lang: lang, csrf: csrf.as_str(), draft: draft, error: Some(error), owners: owners) | 422 | + import_form(lang: lang, username: username, csrf: csrf.as_str(), draft: draft, error: Some(error), owners: owners) |
| 416 | }) | 423 | }) |
| 417 | } | 424 | } |
| 418 | 425 | ||
| @@ -431,7 +438,7 @@ async fn import_page(cx: &Cx) -> Result<impl View> { | |||
| 431 | jobs.truncate(RECENT_IMPORTS); | 438 | jobs.truncate(RECENT_IMPORTS); |
| 432 | Ok(view! { cx => | 439 | Ok(view! { cx => |
| 433 | shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer), | 440 | shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer), |
| 434 | - import_home(lang: lang, csrf: csrf, draft: Draft::fresh(source), owners: owners, jobs: jobs, more: more)) | 441 | + import_home(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: Draft::fresh(source), owners: owners, jobs: jobs, more: more)) |
| 435 | }) | 442 | }) |
| 436 | } | 443 | } |
| 437 | 444 | ||
| @@ -448,7 +455,7 @@ async fn import_submit(cx: &Cx, Form(form): Form<ImportForm>) -> Result<impl Vie | |||
| 448 | let draft = Draft::from_form(&form, source); | 455 | let draft = Draft::from_form(&form, source); |
| 449 | Ok(view! { cx => | 456 | Ok(view! { cx => |
| 450 | shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer), | 457 | shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer), |
| 451 | - import_error_body(lang: lang, csrf: csrf, draft: draft, error: message, owners: owners)) | 458 | + import_error_body(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: draft, error: message, owners: owners)) |
| 452 | }) | 459 | }) |
| 453 | } | 460 | } |
| 454 | } | 461 | } |
| @@ -593,6 +600,7 @@ async fn begin( | |||
| 593 | #[component] | 600 | #[component] |
| 594 | async fn bulk_form( | 601 | async fn bulk_form( |
| 595 | lang: Lang, | 602 | lang: Lang, |
| 603 | + username: String, | ||
| 596 | csrf: &str, | 604 | csrf: &str, |
| 597 | source: Source, | 605 | source: Source, |
| 598 | instance: &str, | 606 | instance: &str, |
| @@ -611,8 +619,8 @@ async fn bulk_form( | |||
| 611 | let owner_required = source != Source::Forgejo; | 619 | let owner_required = source != Source::Forgejo; |
| 612 | Ok(view! { | 620 | Ok(view! { |
| 613 | head(title: g::t(lang, K::BulkTitle), sub: vec![SubPart::text(g::t(lang, K::BulkIntro))]) | 621 | head(title: g::t(lang, K::BulkTitle), sub: vec![SubPart::text(g::t(lang, K::BulkIntro))]) |
| 622 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "repositories".to_owned()) | ||
| 614 | newrepo_tabs(lang: lang, active: "import") | 623 | newrepo_tabs(lang: lang, active: "import") |
| 615 | - source_tabs(lang: lang, base: "/new/import/bulk", active: source) | ||
| 616 | <div class="sheet fit"> | 624 | <div class="sheet fit"> |
| 617 | <form method="post" action="/new/import/bulk" class="fields"> | 625 | <form method="post" action="/new/import/bulk" class="fields"> |
| 618 | if let Some(message) = error { | 626 | if let Some(message) = error { |
| @@ -620,6 +628,7 @@ async fn bulk_form( | |||
| 620 | } | 628 | } |
| 621 | csrf_field(token: csrf) | 629 | csrf_field(token: csrf) |
| 622 | <input type="hidden" name="source" value=(source_value)> | 630 | <input type="hidden" name="source" value=(source_value)> |
| 631 | + source_tabs(lang: lang, base: "/new/import/bulk", active: source) | ||
| 623 | <input type="hidden" name="stage" value="list"> | 632 | <input type="hidden" name="stage" value="list"> |
| 624 | if has_instance { | 633 | if has_instance { |
| 625 | <div class="field"> | 634 | <div class="field"> |
| @@ -655,6 +664,7 @@ struct Listed { | |||
| 655 | #[component] | 664 | #[component] |
| 656 | async fn bulk_select( | 665 | async fn bulk_select( |
| 657 | lang: Lang, | 666 | lang: Lang, |
| 667 | + username: String, | ||
| 658 | csrf: &str, | 668 | csrf: &str, |
| 659 | form: BulkFormEcho, | 669 | form: BulkFormEcho, |
| 660 | repos: Vec<Listed>, | 670 | repos: Vec<Listed>, |
| @@ -671,6 +681,7 @@ async fn bulk_select( | |||
| 671 | }; | 681 | }; |
| 672 | Ok(view! { | 682 | Ok(view! { |
| 673 | head(title: g::t(lang, K::BulkSelectHeading)) | 683 | head(title: g::t(lang, K::BulkSelectHeading)) |
| 684 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "repositories".to_owned()) | ||
| 674 | newrepo_tabs(lang: lang, active: "import") | 685 | newrepo_tabs(lang: lang, active: "import") |
| 675 | <div class="sheet"> | 686 | <div class="sheet"> |
| 676 | <form method="post" action="/new/import/bulk" class="fields"> | 687 | <form method="post" action="/new/import/bulk" class="fields"> |
| @@ -753,7 +764,7 @@ async fn bulk_page(cx: &Cx) -> Result<impl View> { | |||
| 753 | let csrf = viewer.1.csrf_token.clone(); | 764 | let csrf = viewer.1.csrf_token.clone(); |
| 754 | Ok(view! { cx => | 765 | Ok(view! { cx => |
| 755 | shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer), | 766 | shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer), |
| 756 | - bulk_form(lang: lang, csrf: csrf.as_str(), source: source, instance: default_instance(source), owners: owners, error: query.error.clone().filter(|e| e.len() < 300))) | 767 | + bulk_form(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), source: source, instance: default_instance(source), owners: owners, error: query.error.clone().filter(|e| e.len() < 300))) |
| 757 | }) | 768 | }) |
| 758 | } | 769 | } |
| 759 | 770 | ||
| @@ -852,7 +863,7 @@ async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> { | |||
| 852 | }; | 863 | }; |
| 853 | Ok(view! { cx => | 864 | Ok(view! { cx => |
| 854 | shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer), | 865 | shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer), |
| 855 | - bulk_stage(lang: lang, csrf: csrf.as_str(), source: source, instance: instance.as_str(), owners: owners, error: error, picker: picker)) | 866 | + bulk_stage(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), source: source, instance: instance.as_str(), owners: owners, error: error, picker: picker)) |
| 856 | }) | 867 | }) |
| 857 | } | 868 | } |
| 858 | 869 | ||
| @@ -860,6 +871,7 @@ async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> { | |||
| 860 | #[component] | 871 | #[component] |
| 861 | async fn bulk_stage( | 872 | async fn bulk_stage( |
| 862 | lang: Lang, | 873 | lang: Lang, |
| 874 | + username: String, | ||
| 863 | csrf: &str, | 875 | csrf: &str, |
| 864 | source: Source, | 876 | source: Source, |
| 865 | instance: &str, | 877 | instance: &str, |
| @@ -869,9 +881,9 @@ async fn bulk_stage( | |||
| 869 | ) -> Result<impl View> { | 881 | ) -> Result<impl View> { |
| 870 | Ok(view! { | 882 | Ok(view! { |
| 871 | if let Some((echo, repos)) = picker { | 883 | if let Some((echo, repos)) = picker { |
| 872 | - bulk_select(lang: lang, csrf: csrf, form: echo, repos: repos, owners: owners) | 884 | + bulk_select(lang: lang, username: username, csrf: csrf, form: echo, repos: repos, owners: owners) |
| 873 | } else { | 885 | } else { |
| 874 | - bulk_form(lang: lang, csrf: csrf, source: source, instance: instance, owners: owners, error: error) | 886 | + bulk_form(lang: lang, username: username, csrf: csrf, source: source, instance: instance, owners: owners, error: error) |
| 875 | } | 887 | } |
| 876 | }) | 888 | }) |
| 877 | } | 889 | } |
| @@ -1075,6 +1087,7 @@ async fn recent_imports( | |||
| 1075 | #[component] | 1087 | #[component] |
| 1076 | async fn jobs_list( | 1088 | async fn jobs_list( |
| 1077 | lang: Lang, | 1089 | lang: Lang, |
| 1090 | + username: String, | ||
| 1078 | jobs: Vec<(ImportJob, Option<Repo>)>, | 1091 | jobs: Vec<(ImportJob, Option<Repo>)>, |
| 1079 | skipped: Option<String>, | 1092 | skipped: Option<String>, |
| 1080 | ) -> Result<impl View> { | 1093 | ) -> Result<impl View> { |
| @@ -1082,6 +1095,8 @@ async fn jobs_list( | |||
| 1082 | let retry = jobs.iter().any(|(job, _)| job.state == ImportState::Failed); | 1095 | let retry = jobs.iter().any(|(job, _)| job.state == ImportState::Failed); |
| 1083 | Ok(view! { | 1096 | Ok(view! { |
| 1084 | head(title: g::t(lang, K::JobsTitle), live: Some("/import/events")) | 1097 | head(title: g::t(lang, K::JobsTitle), live: Some("/import/events")) |
| 1098 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "repositories".to_owned()) | ||
| 1099 | + newrepo_tabs(lang: lang, active: "import") | ||
| 1085 | <div class="sheet"> | 1100 | <div class="sheet"> |
| 1086 | if retry { | 1101 | if retry { |
| 1087 | <div class="sheet-tools"> | 1102 | <div class="sheet-tools"> |
| @@ -1155,13 +1170,14 @@ async fn jobs_page(cx: &Cx) -> Result<impl View> { | |||
| 1155 | .filter(|s| !s.is_empty() && s.len() < 2000) | 1170 | .filter(|s| !s.is_empty() && s.len() < 2000) |
| 1156 | .map(|s| g::bulk_skipped(lang, &s)); | 1171 | .map(|s| g::bulk_skipped(lang, &s)); |
| 1157 | Ok(view! { cx => | 1172 | Ok(view! { cx => |
| 1158 | - shell(title: g::t(lang, K::JobsTitle), viewer: Some(&viewer), jobs_list(lang: lang, jobs: rows, skipped: skipped)) | 1173 | + shell(title: g::t(lang, K::JobsTitle), viewer: Some(&viewer), jobs_list(lang: lang, username: viewer.0.username.clone(), jobs: rows, skipped: skipped)) |
| 1159 | }) | 1174 | }) |
| 1160 | } | 1175 | } |
| 1161 | 1176 | ||
| 1162 | #[component] | 1177 | #[component] |
| 1163 | async fn job_view( | 1178 | async fn job_view( |
| 1164 | lang: Lang, | 1179 | lang: Lang, |
| 1180 | + username: String, | ||
| 1165 | csrf: &str, | 1181 | csrf: &str, |
| 1166 | job: ImportJob, | 1182 | job: ImportJob, |
| 1167 | repo: Option<Repo>, | 1183 | repo: Option<Repo>, |
| @@ -1194,6 +1210,8 @@ async fn job_view( | |||
| 1194 | }]; | 1210 | }]; |
| 1195 | Ok(view! { | 1211 | Ok(view! { |
| 1196 | head(title: job.source_ref.as_str(), sub: sub, live: live.as_deref()) | 1212 | head(title: job.source_ref.as_str(), sub: sub, live: live.as_deref()) |
| 1213 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "repositories".to_owned()) | ||
| 1214 | + newrepo_tabs(lang: lang, active: "import") | ||
| 1197 | <div class="sheet import-job" data-live-state=(state_word)> | 1215 | <div class="sheet import-job" data-live-state=(state_word)> |
| 1198 | <section class="sec"> | 1216 | <section class="sec"> |
| 1199 | if !stage.is_empty() { | 1217 | if !stage.is_empty() { |
| @@ -1271,7 +1289,7 @@ async fn job_page(cx: &Cx) -> Result<impl View> { | |||
| 1271 | let title = job.source_ref.clone(); | 1289 | let title = job.source_ref.clone(); |
| 1272 | Ok(view! { cx => | 1290 | Ok(view! { cx => |
| 1273 | shell(title: title.as_str(), viewer: Some(&viewer), | 1291 | shell(title: title.as_str(), viewer: Some(&viewer), |
| 1274 | - job_view(lang: lang, csrf: csrf.as_str(), job: job, repo: repo, log: log)) | 1292 | + job_view(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), job: job, repo: repo, log: log)) |
| 1275 | }) | 1293 | }) |
| 1276 | } | 1294 | } |
| 1277 | 1295 | ||
| @@ -1409,11 +1427,13 @@ fn source_label(raw: &str) -> &'static str { | |||
| 1409 | } | 1427 | } |
| 1410 | 1428 | ||
| 1411 | #[component] | 1429 | #[component] |
| 1412 | -async fn retry_list(lang: Lang, csrf: &str, rows: Vec<(ImportJob, Repo)>) -> Result<impl View> { | 1430 | +async fn retry_list(lang: Lang, username: String, csrf: &str, rows: Vec<(ImportJob, Repo)>) -> Result<impl View> { |
| 1413 | let count = rows.len(); | 1431 | let count = rows.len(); |
| 1414 | let empty = rows.is_empty(); | 1432 | let empty = rows.is_empty(); |
| 1415 | Ok(view! { | 1433 | Ok(view! { |
| 1416 | head(title: g::t(lang, K::RetryFailedTitle)) | 1434 | head(title: g::t(lang, K::RetryFailedTitle)) |
| 1435 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "repositories".to_owned()) | ||
| 1436 | + newrepo_tabs(lang: lang, active: "import") | ||
| 1417 | <div class="sheet"> | 1437 | <div class="sheet"> |
| 1418 | <form method="post" action="/import/retry" class="fields"> | 1438 | <form method="post" action="/import/retry" class="fields"> |
| 1419 | csrf_field(token: csrf) | 1439 | csrf_field(token: csrf) |
| @@ -1461,7 +1481,7 @@ async fn retry_page(cx: &Cx) -> Result<impl View> { | |||
| 1461 | let csrf = viewer.1.csrf_token.clone(); | 1481 | let csrf = viewer.1.csrf_token.clone(); |
| 1462 | Ok(view! { cx => | 1482 | Ok(view! { cx => |
| 1463 | shell(title: g::t(lang, K::RetryFailedTitle), viewer: Some(&viewer), | 1483 | shell(title: g::t(lang, K::RetryFailedTitle), viewer: Some(&viewer), |
| 1464 | - retry_list(lang: lang, csrf: csrf.as_str(), rows: rows)) | 1484 | + retry_list(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), rows: rows)) |
| 1465 | }) | 1485 | }) |
| 1466 | } | 1486 | } |
| 1467 | 1487 | ||
crates/forge-web/src/pages/issue_parts.rsmodified+2 -2
| @@ -28,7 +28,7 @@ use crate::state::AppState; | |||
| 28 | use crate::views::review_thread::{ThreadCtx, review_thread_in}; | 28 | use crate::views::review_thread::{ThreadCtx, review_thread_in}; |
| 29 | use crate::views::user_facing_message; | 29 | use crate::views::user_facing_message; |
| 30 | use crate::views::{ | 30 | use crate::views::{ |
| 31 | - alert, avatar_url, display_name, iso_time, now_unix, relative_time, repo_href, short_oid, | 31 | + alert, avatar_url, avatar_url_unknown, display_name, iso_time, now_unix, relative_time, repo_href, short_oid, |
| 32 | user_href, user_link, | 32 | user_href, user_link, |
| 33 | }; | 33 | }; |
| 34 | use crate::views::parts::{confirm_act, reveal}; | 34 | use crate::views::parts::{confirm_act, reveal}; |
| @@ -990,7 +990,7 @@ async fn review_entries( | |||
| 990 | anchor: format!("review-{}", review.id), | 990 | anchor: format!("review-{}", review.id), |
| 991 | author: display_name(lang, &review.author_name), | 991 | author: display_name(lang, &review.author_name), |
| 992 | login: review.author_name.clone(), | 992 | login: review.author_name.clone(), |
| 993 | - avatar: avatar_url(&review.author_name, None), | 993 | + avatar: avatar_url_unknown(&review.author_name), |
| 994 | when: When::new(lang, &stamp, tz, now), | 994 | when: When::new(lang, &stamp, tz, now), |
| 995 | verb, | 995 | verb, |
| 996 | dismissed, | 996 | dismissed, |
crates/forge-web/src/pages/issues_list.rsmodified+2 -2
| @@ -28,7 +28,7 @@ use crate::state::AppState; | |||
| 28 | use crate::templates::{self, Template}; | 28 | use crate::templates::{self, Template}; |
| 29 | use crate::views::parts::{RailItem, SubPart, rail}; | 29 | use crate::views::parts::{RailItem, SubPart, rail}; |
| 30 | use crate::views::{ | 30 | use crate::views::{ |
| 31 | - alert, avatar_url, csrf_field, enc, iso_time, now_unix, relative_time, repo_href, | 31 | + alert, avatar_url_unknown, csrf_field, enc, iso_time, now_unix, relative_time, repo_href, |
| 32 | shell, user_facing_message, user_link, | 32 | shell, user_facing_message, user_link, |
| 33 | }; | 33 | }; |
| 34 | use crate::webhooks::emit::{Sender, emit_issue}; | 34 | use crate::webhooks::emit::{Sender, emit_issue}; |
| @@ -349,7 +349,7 @@ fn row_view(row: RowCtx<'_>, item: &IssueListItem) -> RowView { | |||
| 349 | .iter() | 349 | .iter() |
| 350 | .map(|name| AssigneeView { | 350 | .map(|name| AssigneeView { |
| 351 | name: name.clone(), | 351 | name: name.clone(), |
| 352 | - avatar: avatar_url(name, None), | 352 | + avatar: avatar_url_unknown(name), |
| 353 | }) | 353 | }) |
| 354 | .collect(), | 354 | .collect(), |
| 355 | has_comments: comments > 0, | 355 | has_comments: comments > 0, |
crates/forge-web/src/pages/needs_you.rsmodified+14 -10
| @@ -410,6 +410,7 @@ async fn needs_you(cx: &Cx) -> Result<impl View> { | |||
| 410 | let empty = full.is_none() && sections.is_empty(); | 410 | let empty = full.is_none() && sections.is_empty(); |
| 411 | let back = full.as_ref().map(|_| ni::t(lang, K::BackToNeedsYou)); | 411 | let back = full.as_ref().map(|_| ni::t(lang, K::BackToNeedsYou)); |
| 412 | let heading = ni::t(lang, K::NeedsYou); | 412 | let heading = ni::t(lang, K::NeedsYou); |
| 413 | + let unread = state.store.unread_count(&user.id).await?; | ||
| 413 | let sub = vec![SubPart::text(s(lang, "Waiting on you", "Senden beklenenler"))]; | 414 | let sub = vec![SubPart::text(s(lang, "Waiting on you", "Senden beklenenler"))]; |
| 414 | Ok(view! { | 415 | Ok(view! { |
| 415 | shell(title: heading, viewer: Some(&viewer), | 416 | shell(title: heading, viewer: Some(&viewer), |
| @@ -418,16 +419,19 @@ async fn needs_you(cx: &Cx) -> Result<impl View> { | |||
| 418 | <a class="act" href="/needs-you">(back)</a> | 419 | <a class="act" href="/needs-you">(back)</a> |
| 419 | } | 420 | } |
| 420 | ) | 421 | ) |
| 421 | - <div class="sheet"> | 422 | + <div class="work"> |
| 422 | - if empty { | 423 | + crate::pages::notifications::inbox_rail(lang: lang, current: "needs", unread_count: unread) |
| 423 | - <p class="state">(ni::t(lang, K::AllClear))</p> | 424 | + <div class="sheet"> |
| 424 | - } | 425 | + if empty { |
| 425 | - for section in sections.into_iter() { | 426 | + <p class="state">(ni::t(lang, K::AllClear))</p> |
| 426 | - need_section(lang: lang, section: section) | 427 | + } |
| 427 | - } | 428 | + for section in sections.into_iter() { |
| 428 | - if let Some(section) = full { | 429 | + need_section(lang: lang, section: section) |
| 429 | - need_section(lang: lang, section: section) | 430 | + } |
| 430 | - } | 431 | + if let Some(section) = full { |
| 432 | + need_section(lang: lang, section: section) | ||
| 433 | + } | ||
| 434 | + </div> | ||
| 431 | </div> | 435 | </div> |
| 432 | ) | 436 | ) |
| 433 | }) | 437 | }) |
crates/forge-web/src/pages/new_repo.rsmodified+4 -2
| @@ -209,6 +209,7 @@ impl Draft { | |||
| 209 | #[component] | 209 | #[component] |
| 210 | async fn new_repo_form( | 210 | async fn new_repo_form( |
| 211 | lang: Lang, | 211 | lang: Lang, |
| 212 | + username: String, | ||
| 212 | csrf: &str, | 213 | csrf: &str, |
| 213 | draft: Draft, | 214 | draft: Draft, |
| 214 | error: Option<String>, | 215 | error: Option<String>, |
| @@ -235,6 +236,7 @@ async fn new_repo_form( | |||
| 235 | let draft_mirror_interval = draft.mirror_interval; | 236 | let draft_mirror_interval = draft.mirror_interval; |
| 236 | Ok(view! { | 237 | Ok(view! { |
| 237 | head(title: i18n::t(lang, Key::NewRepository)) | 238 | head(title: i18n::t(lang, Key::NewRepository)) |
| 239 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "repositories".to_owned()) | ||
| 238 | crate::pages::import::newrepo_tabs(lang: lang, active: "create") | 240 | crate::pages::import::newrepo_tabs(lang: lang, active: "create") |
| 239 | <div class="sheet fit"> | 241 | <div class="sheet fit"> |
| 240 | <form method="post" action="/new" class="fields"> | 242 | <form method="post" action="/new" class="fields"> |
| @@ -339,7 +341,7 @@ async fn new_repo_page(cx: &Cx) -> Result<impl View> { | |||
| 339 | } | 341 | } |
| 340 | let csrf = viewer.1.csrf_token.clone(); | 342 | let csrf = viewer.1.csrf_token.clone(); |
| 341 | Ok(view! { cx => | 343 | Ok(view! { cx => |
| 342 | - shell(title: i18n::t(lang, Key::NewRepository), viewer: Some(&viewer), new_repo_form(lang: lang, csrf: csrf.as_str(), draft: draft, error: None, owners: owners)) | 344 | + shell(title: i18n::t(lang, Key::NewRepository), viewer: Some(&viewer), new_repo_form(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), draft: draft, error: None, owners: owners)) |
| 343 | }) | 345 | }) |
| 344 | } | 346 | } |
| 345 | 347 | ||
| @@ -355,7 +357,7 @@ async fn new_repo_submit(cx: &Cx, Form(form): Form<NewRepoForm>) -> Result<impl | |||
| 355 | let csrf = viewer.1.csrf_token.clone(); | 357 | let csrf = viewer.1.csrf_token.clone(); |
| 356 | let draft = Draft::from_form(&form); | 358 | let draft = Draft::from_form(&form); |
| 357 | Ok(view! { cx => | 359 | Ok(view! { cx => |
| 358 | - shell(title: i18n::t(lang, Key::NewRepository), viewer: Some(&viewer), new_repo_form(lang: lang, csrf: csrf.as_str(), draft: draft, error: Some(message), owners: owners)) | 360 | + shell(title: i18n::t(lang, Key::NewRepository), viewer: Some(&viewer), new_repo_form(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), draft: draft, error: Some(message), owners: owners)) |
| 359 | }) | 361 | }) |
| 360 | } | 362 | } |
| 361 | } | 363 | } |
crates/forge-web/src/pages/notifications.rsmodified+39 -21
| @@ -1099,6 +1099,43 @@ fn back(cx: &Cx) -> String { | |||
| 1099 | return_path(cx).unwrap_or_else(|| "/notifications".to_owned()) | 1099 | return_path(cx).unwrap_or_else(|| "/notifications".to_owned()) |
| 1100 | } | 1100 | } |
| 1101 | 1101 | ||
| 1102 | +/// The inbox rail's places, the same on Notifications, Needs you and Review requests, so each | ||
| 1103 | +/// reaches the others: Unread with its count, All, Needs you, Review requests. `current` is the | ||
| 1104 | +/// key of the page showing it. | ||
| 1105 | +pub(crate) fn inbox_items(lang: Lang, current: &str, unread_count: u64) -> Vec<RailItem> { | ||
| 1106 | + let item = |key: &str, name: &str, val: String, href: &str| RailItem { | ||
| 1107 | + name: name.to_owned(), | ||
| 1108 | + val, | ||
| 1109 | + href: href.to_owned(), | ||
| 1110 | + current: key == current, | ||
| 1111 | + }; | ||
| 1112 | + vec![ | ||
| 1113 | + item("unread", g::t(lang, K::Unread), unread_count.to_string(), "/notifications"), | ||
| 1114 | + item("all", g::t(lang, K::AllTab), String::new(), "/notifications?all=1"), | ||
| 1115 | + item( | ||
| 1116 | + "needs", | ||
| 1117 | + crate::i18n::needs::t(lang, crate::i18n::needs::K::NeedsYou), | ||
| 1118 | + String::new(), | ||
| 1119 | + "/needs-you", | ||
| 1120 | + ), | ||
| 1121 | + item( | ||
| 1122 | + "reviews", | ||
| 1123 | + crate::i18n::authoring::t(lang, crate::i18n::authoring::K::ReviewRequestsTab), | ||
| 1124 | + String::new(), | ||
| 1125 | + "/review-requests", | ||
| 1126 | + ), | ||
| 1127 | + ] | ||
| 1128 | +} | ||
| 1129 | + | ||
| 1130 | +/// The inbox rail as Needs you and Review requests show it, beside their sheet. | ||
| 1131 | +#[component] | ||
| 1132 | +pub(crate) async fn inbox_rail(lang: Lang, current: &str, unread_count: u64) -> Result<impl View> { | ||
| 1133 | + let items = inbox_items(lang, current, unread_count); | ||
| 1134 | + Ok(view! { | ||
| 1135 | + rail(label: g::t(lang, K::NotificationFilter), items: items) | ||
| 1136 | + }) | ||
| 1137 | +} | ||
| 1138 | + | ||
| 1102 | /// The inbox page: the head with Mark all read, the filter rail (Unread, All, Reviews), then one | 1139 | /// The inbox page: the head with Mark all read, the filter rail (Unread, All, Reviews), then one |
| 1103 | /// sheet holding the transfers, the repo groups and the older-rows link. | 1140 | /// sheet holding the transfers, the repo groups and the older-rows link. |
| 1104 | #[component] | 1141 | #[component] |
| @@ -1118,29 +1155,10 @@ async fn inbox_list( | |||
| 1118 | } else { | 1155 | } else { |
| 1119 | g::t(lang, K::NoUnreadNotifications) | 1156 | g::t(lang, K::NoUnreadNotifications) |
| 1120 | }; | 1157 | }; |
| 1121 | - let filters = vec![ | 1158 | + let filters = inbox_items(lang, if all { "all" } else { "unread" }, unread_count); |
| 1122 | - RailItem { | ||
| 1123 | - name: g::t(lang, K::Unread).to_owned(), | ||
| 1124 | - val: unread_count.to_string(), | ||
| 1125 | - href: "/notifications".to_owned(), | ||
| 1126 | - current: !all, | ||
| 1127 | - }, | ||
| 1128 | - RailItem { | ||
| 1129 | - name: g::t(lang, K::AllTab).to_owned(), | ||
| 1130 | - val: String::new(), | ||
| 1131 | - href: "/notifications?all=1".to_owned(), | ||
| 1132 | - current: all, | ||
| 1133 | - }, | ||
| 1134 | - RailItem { | ||
| 1135 | - name: crate::i18n::authoring::t(lang, crate::i18n::authoring::K::ReviewRequestsTab) | ||
| 1136 | - .to_owned(), | ||
| 1137 | - val: String::new(), | ||
| 1138 | - href: "/review-requests".to_owned(), | ||
| 1139 | - current: false, | ||
| 1140 | - }, | ||
| 1141 | - ]; | ||
| 1142 | Ok(view! { | 1159 | Ok(view! { |
| 1143 | head(title: i18n::t(lang, Key::Notifications), | 1160 | head(title: i18n::t(lang, Key::Notifications), |
| 1161 | + sub: vec![crate::views::parts::SubPart::text(crate::pages::passkeys::s(lang, "What happened where you take part", "Katıldığın yerlerde olanlar"))], | ||
| 1144 | if !empty { | 1162 | if !empty { |
| 1145 | <form method="post" action="/notifications/mark_all_read" class="act-form"> | 1163 | <form method="post" action="/notifications/mark_all_read" class="act-form"> |
| 1146 | <input type="hidden" name="csrf" value=(csrf.as_str())> | 1164 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
crates/forge-web/src/pages/org_new.rsmodified+4 -2
| @@ -48,9 +48,11 @@ async fn new_org_form( | |||
| 48 | description: String, | 48 | description: String, |
| 49 | error: Option<String>, | 49 | error: Option<String>, |
| 50 | lang: Lang, | 50 | lang: Lang, |
| 51 | + username: String, | ||
| 51 | ) -> Result<impl View> { | 52 | ) -> Result<impl View> { |
| 52 | Ok(view! { | 53 | Ok(view! { |
| 53 | head(title: g::t(lang, K::NewOrganization), sub: vec![SubPart::text(g::t(lang, K::NewOrgIntro))]) | 54 | head(title: g::t(lang, K::NewOrganization), sub: vec![SubPart::text(g::t(lang, K::NewOrgIntro))]) |
| 55 | + crate::pages::profile::own_profile_tabs(lang: lang, username: username, current: "organizations".to_owned()) | ||
| 54 | <div class="sheet fit"> | 56 | <div class="sheet fit"> |
| 55 | if let Some(message) = error { | 57 | if let Some(message) = error { |
| 56 | alert(message: message.as_str()) | 58 | alert(message: message.as_str()) |
| @@ -82,7 +84,7 @@ async fn new_org_page(cx: &Cx) -> Result<impl View> { | |||
| 82 | let csrf = viewer.1.csrf_token.clone(); | 84 | let csrf = viewer.1.csrf_token.clone(); |
| 83 | Ok(view! { cx => | 85 | Ok(view! { cx => |
| 84 | shell(title: title, viewer: Some(&viewer), | 86 | shell(title: title, viewer: Some(&viewer), |
| 85 | - new_org_form(csrf: csrf, name: String::new(), description: String::new(), error: None, lang: lang)) | 87 | + new_org_form(csrf: csrf, name: String::new(), description: String::new(), error: None, lang: lang, username: viewer.0.username.clone())) |
| 86 | }) | 88 | }) |
| 87 | } | 89 | } |
| 88 | 90 | ||
| @@ -103,7 +105,7 @@ async fn new_org_submit(cx: &Cx, Form(form): Form<NewOrgForm>) -> Result<impl Vi | |||
| 103 | let description = form.description.clone(); | 105 | let description = form.description.clone(); |
| 104 | Ok(view! { cx => | 106 | Ok(view! { cx => |
| 105 | shell(title: title, viewer: Some(&viewer), | 107 | shell(title: title, viewer: Some(&viewer), |
| 106 | - new_org_form(csrf: csrf, name: name, description: description, error: Some(message), lang: lang)) | 108 | + new_org_form(csrf: csrf, name: name, description: description, error: Some(message), lang: lang, username: viewer.0.username.clone())) |
| 107 | }) | 109 | }) |
| 108 | } | 110 | } |
| 109 | } | 111 | } |
crates/forge-web/src/pages/profile.rsmodified+89 -28
| @@ -35,6 +35,7 @@ use crate::pages::repo_settings::{notice_banner_for, take_notice}; | |||
| 35 | use crate::pages::snippets::{ListRow, list_row, snippet_rows}; | 35 | use crate::pages::snippets::{ListRow, list_row, snippet_rows}; |
| 36 | use crate::render::markdown::render_markdown; | 36 | use crate::render::markdown::render_markdown; |
| 37 | use crate::state::AppState; | 37 | use crate::state::AppState; |
| 38 | +use crate::views::find::{Finder, finder_field}; | ||
| 38 | use crate::views::heatmap::{Calendar, DayDetail, contribution_calendar}; | 39 | use crate::views::heatmap::{Calendar, DayDetail, contribution_calendar}; |
| 39 | use crate::views::parts::{SubPart, head}; | 40 | use crate::views::parts::{SubPart, head}; |
| 40 | use crate::views::repo_list::{ | 41 | use crate::views::repo_list::{ |
| @@ -59,13 +60,17 @@ struct PinsMenu { | |||
| 59 | const POPULAR_COUNT: usize = 6; | 60 | const POPULAR_COUNT: usize = 6; |
| 60 | /// Members an organization's overview lists; a longer list links to the members page. | 61 | /// Members an organization's overview lists; a longer list links to the members page. |
| 61 | const ORG_MEMBERS_SHOWN: usize = 12; | 62 | const ORG_MEMBERS_SHOWN: usize = 12; |
| 62 | -/// Longest name filter kept, in characters. | 63 | +/// Repos the name filter reads at once. The filter runs in Rust, so it covers every repo in scope. |
| 63 | -const MAX_QUERY_CHARS: usize = 100; | 64 | +const SEARCH_CAP: u64 = 5000; |
| 64 | 65 | ||
| 65 | #[query_params(error = bad_request)] | 66 | #[query_params(error = bad_request)] |
| 66 | struct ProfileQuery { | 67 | struct ProfileQuery { |
| 67 | tab: Option<String>, | 68 | tab: Option<String>, |
| 68 | q: Option<String>, | 69 | q: Option<String>, |
| 70 | + /// Set when the filter asks for the text as typed, as one piece. | ||
| 71 | + exact: Option<String>, | ||
| 72 | + /// Set when the filter keeps upper and lower case apart. | ||
| 73 | + case: Option<String>, | ||
| 69 | sort: Option<String>, | 74 | sort: Option<String>, |
| 70 | page: Option<String>, | 75 | page: Option<String>, |
| 71 | /// A calendar day whose contributions to list under the calendar on the overview. | 76 | /// A calendar day whose contributions to list under the calendar on the overview. |
| @@ -124,14 +129,11 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 124 | } else { | 129 | } else { |
| 125 | tab | 130 | tab |
| 126 | }; | 131 | }; |
| 127 | - let q: String = query | 132 | + let finder = Finder::new( |
| 128 | - .q | 133 | + query.q.as_deref(), |
| 129 | - .as_deref() | 134 | + query.exact.as_deref(), |
| 130 | - .unwrap_or("") | 135 | + query.case.as_deref(), |
| 131 | - .trim() | 136 | + ); |
| 132 | - .chars() | ||
| 133 | - .take(MAX_QUERY_CHARS) | ||
| 134 | - .collect(); | ||
| 135 | let page = page_number(query.page.as_deref()); | 137 | let page = page_number(query.page.as_deref()); |
| 136 | let sort = sort_key(query.sort.as_deref()); | 138 | let sort = sort_key(query.sort.as_deref()); |
| 137 | 139 | ||
| @@ -263,14 +265,35 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 263 | "name" => RepoSort::Name, | 265 | "name" => RepoSort::Name, |
| 264 | _ => RepoSort::RecentlyUpdated, | 266 | _ => RepoSort::RecentlyUpdated, |
| 265 | }; | 267 | }; |
| 266 | - let search = (!q.is_empty()).then_some(q.as_str()); | 268 | + let (listed, total) = if finder.is_empty() { |
| 267 | - let (listed, total) = state | 269 | + state |
| 268 | - .store | 270 | + .store |
| 269 | - .list_visible_repos(scope, actor, search, sort_kind, page, PER_PAGE) | 271 | + .list_visible_repos(scope, actor, None, sort_kind, page, PER_PAGE) |
| 270 | - .await?; | 272 | + .await? |
| 273 | + } else { | ||
| 274 | + // The search reads each repo's name and description, so it runs here over every | ||
| 275 | + // repo in scope, then takes the one page asked for. | ||
| 276 | + let (all, _) = state | ||
| 277 | + .store | ||
| 278 | + .list_visible_repos(scope, actor, None, sort_kind, 1, SEARCH_CAP) | ||
| 279 | + .await?; | ||
| 280 | + let matching: Vec<_> = all | ||
| 281 | + .into_iter() | ||
| 282 | + .filter(|(repo, _, _)| { | ||
| 283 | + finder.matches_any(&[repo.name.as_str(), repo.description.as_str()]) | ||
| 284 | + }) | ||
| 285 | + .collect(); | ||
| 286 | + let total = matching.len() as u64; | ||
| 287 | + let shown = matching | ||
| 288 | + .into_iter() | ||
| 289 | + .skip(((page - 1) * PER_PAGE) as usize) | ||
| 290 | + .take(PER_PAGE as usize) | ||
| 291 | + .collect(); | ||
| 292 | + (shown, total) | ||
| 293 | + }; | ||
| 271 | let tz = actor.map_or("UTC", |u| u.timezone.as_str()); | 294 | let tz = actor.map_or("UTC", |u| u.timezone.as_str()); |
| 272 | let now = now_unix(); | 295 | let now = now_unix(); |
| 273 | - let empty = match (tab, q.is_empty()) { | 296 | + let empty = match (tab, finder.is_empty()) { |
| 274 | (_, false) => g::t(lang, K::NoReposMatch), | 297 | (_, false) => g::t(lang, K::NoReposMatch), |
| 275 | ("stars", true) => g::t(lang, K::NoVisibleStarred), | 298 | ("stars", true) => g::t(lang, K::NoVisibleStarred), |
| 276 | _ => g::t(lang, K::NoVisibleRepos), | 299 | _ => g::t(lang, K::NoVisibleRepos), |
| @@ -290,13 +313,13 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 290 | page, | 313 | page, |
| 291 | pages, | 314 | pages, |
| 292 | pager: pager_links(page, pages, |n| { | 315 | pager: pager_links(page, pages, |n| { |
| 293 | - profile_href(&user.username, tab, &q, sort, n) | 316 | + profile_href(&user.username, tab, &finder, sort, n) |
| 294 | }), | 317 | }), |
| 295 | sort_links: SORTS | 318 | sort_links: SORTS |
| 296 | .iter() | 319 | .iter() |
| 297 | .map(|(key, label)| SortLink { | 320 | .map(|(key, label)| SortLink { |
| 298 | label: g::t(lang, *label), | 321 | label: g::t(lang, *label), |
| 299 | - href: profile_href(&user.username, tab, &q, key, 1), | 322 | + href: profile_href(&user.username, tab, &finder, key, 1), |
| 300 | current: *key == sort, | 323 | current: *key == sort, |
| 301 | }) | 324 | }) |
| 302 | .collect(), | 325 | .collect(), |
| @@ -339,7 +362,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 339 | shell(title: title.as_str(), viewer: viewer.as_ref(), | 362 | shell(title: title.as_str(), viewer: viewer.as_ref(), |
| 340 | notice_banner_for(lang: lang, title: notice) | 363 | notice_banner_for(lang: lang, title: notice) |
| 341 | profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time, | 364 | profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time, |
| 342 | - org: org, lang: lang, tab: tab.to_owned(), q: q, sort: sort, repo_total: repo_total, | 365 | + org: org, lang: lang, tab: tab.to_owned(), finder: finder, sort: sort, repo_total: repo_total, |
| 343 | star_total: star_total, cards: cards, from_pins: from_pins, | 366 | star_total: star_total, cards: cards, from_pins: from_pins, |
| 344 | pins_menu_data: pins_menu_data, pins_error: pins_error, edit_profile: own, listing: listing, | 367 | pins_menu_data: pins_menu_data, pins_error: pins_error, edit_profile: own, listing: listing, |
| 345 | packages_on: packages_on, package_rows: package_rows, | 368 | packages_on: packages_on, package_rows: package_rows, |
| @@ -505,11 +528,15 @@ fn page_number(raw: Option<&str>) -> u64 { | |||
| 505 | 528 | ||
| 506 | /// The profile URL for a tab, with the name filter, a sort other than the default and the page | 529 | /// The profile URL for a tab, with the name filter, a sort other than the default and the page |
| 507 | /// when they are set. | 530 | /// when they are set. |
| 508 | -fn profile_href(name: &str, tab: &str, q: &str, sort: &str, page: u64) -> String { | 531 | +fn profile_href(name: &str, tab: &str, finder: &Finder, sort: &str, page: u64) -> String { |
| 509 | let mut href = format!("/{}?tab={tab}", enc(name)); | 532 | let mut href = format!("/{}?tab={tab}", enc(name)); |
| 510 | - if !q.is_empty() { | 533 | + if !finder.is_empty() { |
| 511 | - href.push_str("&q="); | 534 | + for (key, value) in finder.params() { |
| 512 | - href.push_str(&enc(q)); | 535 | + href.push('&'); |
| 536 | + href.push_str(key); | ||
| 537 | + href.push('='); | ||
| 538 | + href.push_str(&enc(value)); | ||
| 539 | + } | ||
| 513 | } | 540 | } |
| 514 | if sort != SORTS[0].0 { | 541 | if sort != SORTS[0].0 { |
| 515 | href.push_str("&sort="); | 542 | href.push_str("&sort="); |
| @@ -568,7 +595,7 @@ async fn profile_card( | |||
| 568 | org: Option<OrgSummary>, | 595 | org: Option<OrgSummary>, |
| 569 | lang: Lang, | 596 | lang: Lang, |
| 570 | tab: String, | 597 | tab: String, |
| 571 | - q: String, | 598 | + finder: Finder, |
| 572 | sort: &'static str, | 599 | sort: &'static str, |
| 573 | repo_total: u64, | 600 | repo_total: u64, |
| 574 | star_total: u64, | 601 | star_total: u64, |
| @@ -745,12 +772,10 @@ async fn profile_card( | |||
| 745 | <section class="sec"> | 772 | <section class="sec"> |
| 746 | <div class="sheet-tools"> | 773 | <div class="sheet-tools"> |
| 747 | <strong>(count_text.as_str())</strong> | 774 | <strong>(count_text.as_str())</strong> |
| 748 | - <form method="get" action=(base.as_str()) class="plain-search" role="search"> | 775 | + <form method="get" action=(base.as_str()) role="search"> |
| 749 | <input type="hidden" name="tab" value=(tab.as_str())> | 776 | <input type="hidden" name="tab" value=(tab.as_str())> |
| 750 | <input type="hidden" name="sort" value=(sort)> | 777 | <input type="hidden" name="sort" value=(sort)> |
| 751 | - <input type="search" name="q" value=(q.as_str()) data-live-search="" | 778 | + finder_field(lang: lang, finder: finder, placeholder: filter_label, id: Some("profile-q")) |
| 752 | - placeholder=(filter_label) aria-label=(filter_label)> | ||
| 753 | - <button type="submit" class="act">(g::t(lang, K::Search))</button> | ||
| 754 | </form> | 779 | </form> |
| 755 | sort_chips(links: sort_links, lang: lang) | 780 | sort_chips(links: sort_links, lang: lang) |
| 756 | </div> | 781 | </div> |
| @@ -836,6 +861,42 @@ async fn profile_card( | |||
| 836 | }) | 861 | }) |
| 837 | } | 862 | } |
| 838 | 863 | ||
| 864 | +/// The viewer's own profile tabs on a page that makes something of theirs (a repository, a | ||
| 865 | +/// snippet, an organization): the same tabs and counts as their profile, with `current` marked. | ||
| 866 | +#[component] | ||
| 867 | +pub async fn own_profile_tabs(lang: Lang, username: String, current: String) -> Result<impl View> { | ||
| 868 | + let items = crate::views::profile_items(lang, &username, false, true, false); | ||
| 869 | + let mut counts = Vec::new(); | ||
| 870 | + if let Some(state) = topcoat::context::try_app_context::<AppState>(__cx) | ||
| 871 | + && let Some(user) = state.store.user_by_username(&username).await? | ||
| 872 | + { | ||
| 873 | + let actor = Some(&user); | ||
| 874 | + let repos = state | ||
| 875 | + .store | ||
| 876 | + .count_visible_repos(RepoScope::OwnedBy(&user.id), actor) | ||
| 877 | + .await?; | ||
| 878 | + let stars = state | ||
| 879 | + .store | ||
| 880 | + .count_visible_repos(RepoScope::StarredBy(&user.id), actor) | ||
| 881 | + .await?; | ||
| 882 | + let snippets = state | ||
| 883 | + .store | ||
| 884 | + .list_owner_snippets(&user.id, Some(user.id.as_str())) | ||
| 885 | + .await? | ||
| 886 | + .len(); | ||
| 887 | + let packages = packages::package_rows(state, actor, &user).await?.len(); | ||
| 888 | + counts = vec![ | ||
| 889 | + ("repositories", repos.to_string()), | ||
| 890 | + ("snippets", snippets.to_string()), | ||
| 891 | + ("stars", stars.to_string()), | ||
| 892 | + ("packages", packages.to_string()), | ||
| 893 | + ]; | ||
| 894 | + } | ||
| 895 | + Ok(view! { | ||
| 896 | + profile_tabs(username: username, items: items, current: current, counts: counts) | ||
| 897 | + }) | ||
| 898 | +} | ||
| 899 | + | ||
| 839 | /// The profile tab bar: one link per item, the current tab marked, and a count after the label of | 900 | /// The profile tab bar: one link per item, the current tab marked, and a count after the label of |
| 840 | /// each tab that has one in `counts`, by the item's key. A person's, an organization's and an | 901 | /// each tab that has one in `counts`, by the item's key. A person's, an organization's and an |
| 841 | /// organization's member pages all render it. | 902 | /// organization's member pages all render it. |
crates/forge-web/src/pages/pulls_list.rsmodified+2 -2
| @@ -25,7 +25,7 @@ use crate::state::AppState; | |||
| 25 | use crate::pages::passkeys::s; | 25 | use crate::pages::passkeys::s; |
| 26 | use crate::views::parts::{RailItem, SubPart, rail}; | 26 | use crate::views::parts::{RailItem, SubPart, rail}; |
| 27 | use crate::views::{ | 27 | use crate::views::{ |
| 28 | - avatar_url, iso_time, now_unix, relative_time, repo_href, shell, user_link, | 28 | + avatar_url_unknown, iso_time, now_unix, relative_time, repo_href, shell, user_link, |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | path_param!(owner); | 31 | path_param!(owner); |
| @@ -136,7 +136,7 @@ fn row_view( | |||
| 136 | .iter() | 136 | .iter() |
| 137 | .map(|name| AssigneeView { | 137 | .map(|name| AssigneeView { |
| 138 | name: name.clone(), | 138 | name: name.clone(), |
| 139 | - avatar: avatar_url(name, None), | 139 | + avatar: avatar_url_unknown(name), |
| 140 | }) | 140 | }) |
| 141 | .collect(), | 141 | .collect(), |
| 142 | has_comments: comments > 0, | 142 | has_comments: comments > 0, |
crates/forge-web/src/pages/register.rsmodified+4 -0
| @@ -23,6 +23,7 @@ use crate::auth::{ | |||
| 23 | use crate::client_ip::client_ip; | 23 | use crate::client_ip::client_ip; |
| 24 | use crate::i18n::{self, Key, Lang, password_too_long, password_too_short, t}; | 24 | use crate::i18n::{self, Key, Lang, password_too_long, password_too_short, t}; |
| 25 | use crate::mail::account; | 25 | use crate::mail::account; |
| 26 | +use crate::pages::settings_security::mail_can_send; | ||
| 26 | use crate::state::AppState; | 27 | use crate::state::AppState; |
| 27 | use crate::throttle; | 28 | use crate::throttle; |
| 28 | use crate::views::parts::{SubPart, head}; | 29 | use crate::views::parts::{SubPart, head}; |
| @@ -425,6 +426,9 @@ async fn verify_submit(cx: &Cx, Form(form): Form<VerifyForm>) -> Result<impl Vie | |||
| 425 | async fn verify_resend(cx: &Cx, Form(form): Form<ResendForm>) -> Result<SeeOther> { | 426 | async fn verify_resend(cx: &Cx, Form(form): Form<ResendForm>) -> Result<SeeOther> { |
| 426 | let viewer = require_csrf(cx, &form.csrf).await?; | 427 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 427 | let state = app_context::<AppState>(cx); | 428 | let state = app_context::<AppState>(cx); |
| 429 | + if !mail_can_send(state).await { | ||
| 430 | + return Ok(see_other("/settings/security?saved=verify_wait")); | ||
| 431 | + } | ||
| 428 | if let Some(address) = viewer.0.email.clone() | 432 | if let Some(address) = viewer.0.email.clone() |
| 429 | && !state.store.email_is_verified(&viewer.0.id).await? | 433 | && !state.store.email_is_verified(&viewer.0.id).await? |
| 430 | && !account::send_verify(state, &viewer.0, &address).await? | 434 | && !account::send_verify(state, &viewer.0, &address).await? |
crates/forge-web/src/pages/review_requests.rsmodified+17 -13
| @@ -286,6 +286,7 @@ async fn review_requests(cx: &Cx) -> Result<impl View> { | |||
| 286 | } | 286 | } |
| 287 | let heading = ga::t(lang, AK::ReviewRequests); | 287 | let heading = ga::t(lang, AK::ReviewRequests); |
| 288 | let empty = rows.is_empty(); | 288 | let empty = rows.is_empty(); |
| 289 | + let unread = state.store.unread_count(&user.id).await?; | ||
| 289 | let sub = vec![SubPart::text(s( | 290 | let sub = vec![SubPart::text(s( |
| 290 | lang, | 291 | lang, |
| 291 | "Pull requests waiting for your review", | 292 | "Pull requests waiting for your review", |
| @@ -294,19 +295,22 @@ async fn review_requests(cx: &Cx) -> Result<impl View> { | |||
| 294 | Ok(view! { | 295 | Ok(view! { |
| 295 | shell(title: heading, viewer: Some(&viewer), | 296 | shell(title: heading, viewer: Some(&viewer), |
| 296 | head(title: heading, sub: sub, live: Some("/review-requests/events")) | 297 | head(title: heading, sub: sub, live: Some("/review-requests/events")) |
| 297 | - <div class="sheet"> | 298 | + <div class="work"> |
| 298 | - <div class="sec"> | 299 | + crate::pages::notifications::inbox_rail(lang: lang, current: "reviews", unread_count: unread) |
| 299 | - if empty { | 300 | + <div class="sheet"> |
| 300 | - <p class="state">(ga::t(lang, AK::NoReviewRequests))</p> | 301 | + <div class="sec"> |
| 301 | - } | 302 | + if empty { |
| 302 | - for row in rows.iter() { | 303 | + <p class="state">(ga::t(lang, AK::NoReviewRequests))</p> |
| 303 | - <a class="line" href=(row.1.as_str()) data-kb-row=""> | 304 | + } |
| 304 | - <span class="name">(row.2.as_str())</span> | 305 | + for row in rows.iter() { |
| 305 | - <span class="val">(row.0.as_str())</span> | 306 | + <a class="line" href=(row.1.as_str()) data-kb-row=""> |
| 306 | - <span class="val">(row.3.as_str())</span> | 307 | + <span class="name">(row.2.as_str())</span> |
| 307 | - <span class="val">rel_time(lang: lang, stamp: row.4.as_str())</span> | 308 | + <span class="val">(row.0.as_str())</span> |
| 308 | - </a> | 309 | + <span class="val">(row.3.as_str())</span> |
| 309 | - } | 310 | + <span class="val">rel_time(lang: lang, stamp: row.4.as_str())</span> |
| 311 | + </a> | ||
| 312 | + } | ||
| 313 | + </div> | ||
| 310 | </div> | 314 | </div> |
| 311 | </div> | 315 | </div> |
| 312 | ) | 316 | ) |
crates/forge-web/src/pages/settings_appearance.rsmodified+10 -9
| @@ -723,15 +723,15 @@ mod tests { | |||
| 723 | "accent: empty" | 723 | "accent: empty" |
| 724 | ); | 724 | ); |
| 725 | assert!( | 725 | assert!( |
| 726 | - base_choice(Lang::En, Some("ink"), "fern").is_ok(), | 726 | + base_choice(Lang::En, Some("ink"), "blush").is_ok(), |
| 727 | "base: offered" | 727 | "base: offered" |
| 728 | ); | 728 | ); |
| 729 | assert!( | 729 | assert!( |
| 730 | - base_choice(Lang::En, Some("neon"), "fern").is_err(), | 730 | + base_choice(Lang::En, Some("neon"), "blush").is_err(), |
| 731 | "base: unknown" | 731 | "base: unknown" |
| 732 | ); | 732 | ); |
| 733 | assert!( | 733 | assert!( |
| 734 | - base_choice(Lang::En, Some(""), "fern").is_err(), | 734 | + base_choice(Lang::En, Some(""), "blush").is_err(), |
| 735 | "base: empty" | 735 | "base: empty" |
| 736 | ); | 736 | ); |
| 737 | 737 | ||
| @@ -746,14 +746,14 @@ mod tests { | |||
| 746 | "accent upper case {id}" | 746 | "accent upper case {id}" |
| 747 | ); | 747 | ); |
| 748 | } | 748 | } |
| 749 | - for id in ["fern", "graphite", "dusk", "ink", "anvil", "hue-120"] { | 749 | + for id in ["blush", "heather", "dusk", "ink", "anvil", "hue-120"] { |
| 750 | assert_eq!( | 750 | assert_eq!( |
| 751 | - base_choice(Lang::Tr, Some(id), "fern").unwrap(), | 751 | + base_choice(Lang::Tr, Some(id), "blush").unwrap(), |
| 752 | id, | 752 | id, |
| 753 | "base {id}" | 753 | "base {id}" |
| 754 | ); | 754 | ); |
| 755 | assert!( | 755 | assert!( |
| 756 | - base_choice(Lang::Tr, Some(&id.to_uppercase()), "fern").is_err(), | 756 | + base_choice(Lang::Tr, Some(&id.to_uppercase()), "blush").is_err(), |
| 757 | "base upper case {id}" | 757 | "base upper case {id}" |
| 758 | ); | 758 | ); |
| 759 | } | 759 | } |
| @@ -777,7 +777,8 @@ mod tests { | |||
| 777 | for id in [ | 777 | for id in [ |
| 778 | "dune", | 778 | "dune", |
| 779 | "lilac", | 779 | "lilac", |
| 780 | - "blush", | 780 | + "fern", |
| 781 | + "graphite", | ||
| 781 | "pine", | 782 | "pine", |
| 782 | "slate-blue", | 783 | "slate-blue", |
| 783 | "spark", | 784 | "spark", |
| @@ -785,7 +786,7 @@ mod tests { | |||
| 785 | "hue-07", | 786 | "hue-07", |
| 786 | ] { | 787 | ] { |
| 787 | assert!( | 788 | assert!( |
| 788 | - base_choice(Lang::En, Some(id), "fern").is_err(), | 789 | + base_choice(Lang::En, Some(id), "blush").is_err(), |
| 789 | "base refused {id}" | 790 | "base refused {id}" |
| 790 | ); | 791 | ); |
| 791 | } | 792 | } |
| @@ -810,7 +811,7 @@ mod tests { | |||
| 810 | accent_err.to_string().contains("accent colour"), | 811 | accent_err.to_string().contains("accent colour"), |
| 811 | "{accent_err}" | 812 | "{accent_err}" |
| 812 | ); | 813 | ); |
| 813 | - let base_err = base_choice(Lang::En, Some("neon"), "fern").unwrap_err(); | 814 | + let base_err = base_choice(Lang::En, Some("neon"), "blush").unwrap_err(); |
| 814 | assert!(base_err.to_string().contains("background"), "{base_err}"); | 815 | assert!(base_err.to_string().contains("background"), "{base_err}"); |
| 815 | } | 816 | } |
| 816 | 817 | ||
crates/forge-web/src/pages/settings_export.rsmodified+28 -12
| @@ -26,7 +26,7 @@ use crate::i18n::migrate::{self as g, K}; | |||
| 26 | use crate::i18n::{self, Lang}; | 26 | use crate::i18n::{self, Lang}; |
| 27 | use crate::pages::ci_runs::{changed_event, events_response}; | 27 | use crate::pages::ci_runs::{changed_event, events_response}; |
| 28 | use crate::state::AppState; | 28 | use crate::state::AppState; |
| 29 | -use crate::views::parts::{SubPart, head}; | 29 | +use crate::views::parts::{SubPart, confirm_act, head}; |
| 30 | use crate::views::{alert, csrf_field, human_size, rel_time, shell}; | 30 | use crate::views::{alert, csrf_field, human_size, rel_time, shell}; |
| 31 | 31 | ||
| 32 | path_param!(export_id); | 32 | path_param!(export_id); |
| @@ -61,6 +61,10 @@ async fn export_view(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Result | |||
| 61 | ) | 61 | ) |
| 62 | }); | 62 | }); |
| 63 | let empty = exports.is_empty(); | 63 | let empty = exports.is_empty(); |
| 64 | + let deletes: Vec<String> = exports | ||
| 65 | + .iter() | ||
| 66 | + .map(|e| format!("/settings/export/{}/delete", e.id)) | ||
| 67 | + .collect(); | ||
| 64 | let ttl_note = g::export_ttl_note(lang, exporter::EXPORT_TTL_DAYS); | 68 | let ttl_note = g::export_ttl_note(lang, exporter::EXPORT_TTL_DAYS); |
| 65 | Ok(view! { | 69 | Ok(view! { |
| 66 | head(title: g::t(lang, K::ExportTitle), sub: vec![SubPart::text(g::t(lang, K::ExportIntro))], | 70 | head(title: g::t(lang, K::ExportTitle), sub: vec![SubPart::text(g::t(lang, K::ExportIntro))], |
| @@ -80,13 +84,14 @@ async fn export_view(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Result | |||
| 80 | if empty { | 84 | if empty { |
| 81 | <p class="state">(g::t(lang, K::ExportNone))</p> | 85 | <p class="state">(g::t(lang, K::ExportNone))</p> |
| 82 | } | 86 | } |
| 83 | - for export in exports.iter() { | 87 | + for (export, delete) in exports.iter().zip(deletes.iter()) { |
| 84 | <div class="export-row"> | 88 | <div class="export-row"> |
| 85 | <div class="line"> | 89 | <div class="line"> |
| 86 | <span class="name">(g::t(lang, K::ExportRequested)) " " rel_time(lang: lang, stamp: export.created_at.as_str())</span> | 90 | <span class="name">(g::t(lang, K::ExportRequested)) " " rel_time(lang: lang, stamp: export.created_at.as_str())</span> |
| 87 | <span class="val"> | 91 | <span class="val"> |
| 88 | if export.state == ExportState::Ready { | 92 | if export.state == ExportState::Ready { |
| 89 | - (g::t(lang, K::ExportReady)) | 93 | + (g::t(lang, K::ExportReady)) " · " (g::t(lang, K::ExportSize)) ": " (human_size(lang, u64::try_from(export.size).unwrap_or(0))) |
| 94 | + " · " (g::expires_label(lang)) " " rel_time(lang: lang, stamp: export.expires_at.as_str()) | ||
| 90 | } | 95 | } |
| 91 | if export.state == ExportState::Building { | 96 | if export.state == ExportState::Building { |
| 92 | (g::t(lang, K::ExportBuilding)) | 97 | (g::t(lang, K::ExportBuilding)) |
| @@ -95,16 +100,13 @@ async fn export_view(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Result | |||
| 95 | (g::t(lang, K::ExportFailed)) | 100 | (g::t(lang, K::ExportFailed)) |
| 96 | } | 101 | } |
| 97 | </span> | 102 | </span> |
| 98 | - </div> | 103 | + if export.state == ExportState::Ready { |
| 99 | - if export.state == ExportState::Ready { | ||
| 100 | - <p class="hint"> | ||
| 101 | - (g::t(lang, K::ExportSize)) ": " (human_size(lang, u64::try_from(export.size).unwrap_or(0))) | ||
| 102 | - " · " (g::expires_label(lang)) " " rel_time(lang: lang, stamp: export.expires_at.as_str()) | ||
| 103 | - </p> | ||
| 104 | - <div class="acts"> | ||
| 105 | <a class="act" href=(format!("/settings/export/{}/download", export.id))>(g::t(lang, K::ExportDownload))</a> | 104 | <a class="act" href=(format!("/settings/export/{}/download", export.id))>(g::t(lang, K::ExportDownload))</a> |
| 106 | - </div> | 105 | + } |
| 107 | - } | 106 | + if export.state != ExportState::Building { |
| 107 | + confirm_act(lang: lang, label: crate::pages::passkeys::s(lang, "Delete", "Sil"), action: delete.as_str(), csrf: csrf, note: Some(crate::pages::passkeys::s(lang, "The archive is deleted from the server.", "Arşiv sunucudan silinir.").to_owned())) | ||
| 108 | + } | ||
| 109 | + </div> | ||
| 108 | if export.state == ExportState::Building { | 110 | if export.state == ExportState::Building { |
| 109 | <progress class="import-progress export-progress"></progress> | 111 | <progress class="import-progress export-progress"></progress> |
| 110 | } | 112 | } |
| @@ -140,6 +142,20 @@ async fn export_request(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> | |||
| 140 | Err(see_other("/settings/export").into()) | 142 | Err(see_other("/settings/export").into()) |
| 141 | } | 143 | } |
| 142 | 144 | ||
| 145 | +/// Deletes one archive by hand. Only its owner, and not while it is still building. | ||
| 146 | +#[route(POST "/settings/export/{export_id}/delete")] | ||
| 147 | +async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | ||
| 148 | + let viewer = require_csrf(cx, &form.csrf).await?; | ||
| 149 | + let id = path_param::<ExportId>(cx).to_owned(); | ||
| 150 | + let state = app_context::<AppState>(cx); | ||
| 151 | + let export = match state.store.data_export(&id).await? { | ||
| 152 | + Some(e) if e.user_id == viewer.0.id && e.state != ExportState::Building => e, | ||
| 153 | + _ => return Err(not_found().into()), | ||
| 154 | + }; | ||
| 155 | + exporter::delete_one(state, &export).await?; | ||
| 156 | + Err(see_other("/settings/export").into()) | ||
| 157 | +} | ||
| 158 | + | ||
| 143 | /// The `changed` stream of the export page. It sends when the exports differ from what the page | 159 | /// The `changed` stream of the export page. It sends when the exports differ from what the page |
| 144 | /// shows, then on each change, and ends once nothing is building. | 160 | /// shows, then on each change, and ends once nothing is building. |
| 145 | #[route(GET "/settings/export/events")] | 161 | #[route(GET "/settings/export/events")] |
crates/forge-web/src/pages/settings_profile.rsmodified+1 -1
| @@ -994,7 +994,7 @@ pub(crate) mod tests { | |||
| 994 | ); | 994 | ); |
| 995 | let (_, _, body) = send(&fx.router, "GET", "/explore", true, None).await; | 995 | let (_, _, body) = send(&fx.router, "GET", "/explore", true, None).await; |
| 996 | assert!( | 996 | assert!( |
| 997 | - body.contains(r#"src="/avatars/tahinli?v=default""#), | 997 | + body.contains(r#"src="data:image/svg+xml,"#), |
| 998 | "remove: nav default {body}" | 998 | "remove: nav default {body}" |
| 999 | ); | 999 | ); |
| 1000 | // With no photo there is nothing to remove, so the menu leaves that item out. | 1000 | // With no photo there is nothing to remove, so the menu leaves that item out. |
crates/forge-web/src/pages/settings_security.rsmodified+67 -29
| @@ -29,7 +29,7 @@ use crate::pages::passkeys::{PasskeyPanel, build_panel, passkeys_panel, s}; | |||
| 29 | use crate::pages::settings_sessions::session_label; | 29 | use crate::pages::settings_sessions::session_label; |
| 30 | use crate::state::AppState; | 30 | use crate::state::AppState; |
| 31 | use crate::throttle::{self, LOGIN_USER_LIMIT, TWO_FACTOR_USER_LIMIT}; | 31 | use crate::throttle::{self, LOGIN_USER_LIMIT, TWO_FACTOR_USER_LIMIT}; |
| 32 | -use crate::views::parts::{RailItem, SubPart, confirm_act, head, post_act, rail, reveal}; | 32 | +use crate::views::parts::{RailItem, SubPart, confirm_act, head, post_act, rail}; |
| 33 | use crate::views::{added_status, alert, rel_time, shell, user_facing_message}; | 33 | use crate::views::{added_status, alert, rel_time, shell, user_facing_message}; |
| 34 | 34 | ||
| 35 | /// Shortest and longest new passwords, in characters. | 35 | /// Shortest and longest new passwords, in characters. |
| @@ -82,6 +82,8 @@ struct CodeForm { | |||
| 82 | #[serde(default)] | 82 | #[serde(default)] |
| 83 | csrf: String, | 83 | csrf: String, |
| 84 | #[serde(default)] | 84 | #[serde(default)] |
| 85 | + current_password: String, | ||
| 86 | + #[serde(default)] | ||
| 85 | code: String, | 87 | code: String, |
| 86 | } | 88 | } |
| 87 | 89 | ||
| @@ -171,6 +173,8 @@ struct SecurityPage { | |||
| 171 | email_status: String, | 173 | email_status: String, |
| 172 | /// When the latest verification mail went out, shown after the state as a live time. | 174 | /// When the latest verification mail went out, shown after the state as a live time. |
| 173 | email_sent: Option<String>, | 175 | email_sent: Option<String>, |
| 176 | + /// Whether this server can send mail at all. The resend link shows only when it can. | ||
| 177 | + mail_ready: bool, | ||
| 174 | notice: Option<&'static str>, | 178 | notice: Option<&'static str>, |
| 175 | password_error: Option<String>, | 179 | password_error: Option<String>, |
| 176 | email_error: Option<String>, | 180 | email_error: Option<String>, |
| @@ -296,6 +300,7 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result<impl View> { | |||
| 296 | stored_email, | 300 | stored_email, |
| 297 | email_status, | 301 | email_status, |
| 298 | email_sent, | 302 | email_sent, |
| 303 | + mail_ready, | ||
| 299 | notice, | 304 | notice, |
| 300 | password_error, | 305 | password_error, |
| 301 | email_error, | 306 | email_error, |
| @@ -323,7 +328,7 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result<impl View> { | |||
| 323 | let password_open = password_error.is_some(); | 328 | let password_open = password_error.is_some(); |
| 324 | let email_open = email_error.is_some(); | 329 | let email_open = email_error.is_some(); |
| 325 | let email_set = !email.is_empty(); | 330 | let email_set = !email.is_empty(); |
| 326 | - let show_resend = email_set && !email_verified; | 331 | + let show_resend = email_set && !email_verified && mail_ready; |
| 327 | let regenerate_error = two_factor_error | 332 | let regenerate_error = two_factor_error |
| 328 | .clone() | 333 | .clone() |
| 329 | .filter(|_| two_factor_panel == TwoFactorPanel::Regenerate); | 334 | .filter(|_| two_factor_panel == TwoFactorPanel::Regenerate); |
| @@ -444,46 +449,54 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result<impl View> { | |||
| 444 | if let Some(device) = two_factor { | 449 | if let Some(device) = two_factor { |
| 445 | <p class="state">(t(lang, Key::PillOn)) " · " (device.name.as_str())</p> | 450 | <p class="state">(t(lang, Key::PillOn)) " · " (device.name.as_str())</p> |
| 446 | <p class="hint">added_status(lang: lang, added: device.added.as_deref(), used: device.used.as_deref())</p> | 451 | <p class="hint">added_status(lang: lang, added: device.added.as_deref(), used: device.used.as_deref())</p> |
| 447 | - <p class="hint">(device.codes_line.as_str())</p> | 452 | + <div class="line"> |
| 453 | + <span class="name">(t(lang, Key::RecoveryCodes))</span> | ||
| 454 | + <span class="val">(device.codes_line.as_str())</span> | ||
| 455 | + </div> | ||
| 448 | if device.codes_low { | 456 | if device.codes_low { |
| 449 | <p class="hint topic-warn">(t(lang, Key::CodesRunningLow))</p> | 457 | <p class="hint topic-warn">(t(lang, Key::CodesRunningLow))</p> |
| 450 | } | 458 | } |
| 451 | - <div class="acts"> | 459 | + <details class="reveal" open=(regenerate_open)> |
| 452 | - reveal(label: t(lang, Key::RegenerateCodes), open: regenerate_open, | 460 | + <summary class="act">(s(lang, "Regenerate…", "Yeniden oluştur…"))</summary> |
| 461 | + <div class="opened"> | ||
| 453 | if let Some(message) = regenerate_error { | 462 | if let Some(message) = regenerate_error { |
| 454 | alert(message: message.as_str()) | 463 | alert(message: message.as_str()) |
| 455 | } | 464 | } |
| 456 | <form data-hard="true" method="post" action="/settings/security/2fa/recovery" class="fields"> | 465 | <form data-hard="true" method="post" action="/settings/security/2fa/recovery" class="fields"> |
| 457 | <input type="hidden" name="csrf" value=(csrf)> | 466 | <input type="hidden" name="csrf" value=(csrf)> |
| 458 | <p class="hint">(t(lang, Key::RegenerateCodesHint))</p> | 467 | <p class="hint">(t(lang, Key::RegenerateCodesHint))</p> |
| 468 | + <div class="field"> | ||
| 469 | + <label for="regenerate-password">(t(lang, Key::CurrentPassword))</label> | ||
| 470 | + <input id="regenerate-password" type="password" name="current_password" autocomplete="current-password" required=(true)> | ||
| 471 | + </div> | ||
| 459 | <div class="field"> | 472 | <div class="field"> |
| 460 | <label for="regenerate-code">(t(lang, Key::Code))</label> | 473 | <label for="regenerate-code">(t(lang, Key::Code))</label> |
| 461 | <input id="regenerate-code" type="text" name="code" autocomplete="one-time-code" required=(true)> | 474 | <input id="regenerate-code" type="text" name="code" autocomplete="one-time-code" required=(true)> |
| 462 | </div> | 475 | </div> |
| 463 | <button type="submit" class="primary">(t(lang, Key::RegenerateCodes))</button> | 476 | <button type="submit" class="primary">(t(lang, Key::RegenerateCodes))</button> |
| 464 | </form> | 477 | </form> |
| 465 | - ) | 478 | + </div> |
| 466 | - <details class="reveal" open=(disable_open)> | 479 | + </details> |
| 467 | - <summary class="act danger">(t(lang, Key::TurnOffTwoFactorButton))</summary> | 480 | + <details class="reveal" open=(disable_open)> |
| 468 | - <div class="opened"> | 481 | + <summary class="act danger">(t(lang, Key::TurnOffTwoFactorButton))</summary> |
| 469 | - if let Some(message) = disable_error { | 482 | + <div class="opened"> |
| 470 | - alert(message: message.as_str()) | 483 | + if let Some(message) = disable_error { |
| 471 | - } | 484 | + alert(message: message.as_str()) |
| 472 | - <form data-hard="true" method="post" action="/settings/security/2fa/disable" class="fields"> | 485 | + } |
| 473 | - <input type="hidden" name="csrf" value=(csrf)> | 486 | + <form data-hard="true" method="post" action="/settings/security/2fa/disable" class="fields"> |
| 474 | - <div class="field"> | 487 | + <input type="hidden" name="csrf" value=(csrf)> |
| 475 | - <label for="disable-password">(t(lang, Key::CurrentPassword))</label> | 488 | + <div class="field"> |
| 476 | - <input id="disable-password" type="password" name="current_password" autocomplete="current-password" required=(true)> | 489 | + <label for="disable-password">(t(lang, Key::CurrentPassword))</label> |
| 477 | - </div> | 490 | + <input id="disable-password" type="password" name="current_password" autocomplete="current-password" required=(true)> |
| 478 | - <div class="field"> | 491 | + </div> |
| 479 | - <label for="disable-code">(t(lang, Key::Code))</label> | 492 | + <div class="field"> |
| 480 | - <input id="disable-code" type="text" name="code" autocomplete="one-time-code" required=(true)> | 493 | + <label for="disable-code">(t(lang, Key::Code))</label> |
| 481 | - </div> | 494 | + <input id="disable-code" type="text" name="code" autocomplete="one-time-code" required=(true)> |
| 482 | - <button type="submit" class="act danger">(t(lang, Key::TurnOffTwoFactorButton))</button> | 495 | + </div> |
| 483 | - </form> | 496 | + <button type="submit" class="danger">(t(lang, Key::TurnOffTwoFactorButton))</button> |
| 484 | - </div> | 497 | + </form> |
| 485 | - </details> | 498 | + </div> |
| 486 | - </div> | 499 | + </details> |
| 487 | } else if pending_set { | 500 | } else if pending_set { |
| 488 | <p class="state">(t(lang, Key::SetupInProgress))</p> | 501 | <p class="state">(t(lang, Key::SetupInProgress))</p> |
| 489 | } else { | 502 | } else { |
| @@ -617,6 +630,22 @@ fn notice_for(lang: Lang, saved: Option<&str>) -> Option<&'static str> { | |||
| 617 | } | 630 | } |
| 618 | } | 631 | } |
| 619 | 632 | ||
| 633 | +/// Whether this server can send mail now. The log transport always can. SMTP can only when the | ||
| 634 | +/// stored settings are enabled and name a host and a sender. | ||
| 635 | +pub(crate) async fn mail_can_send(state: &AppState) -> bool { | ||
| 636 | + if state.config.mail.transport == forge_core::config::MailTransport::Log { | ||
| 637 | + return true; | ||
| 638 | + } | ||
| 639 | + match state.store.mail_settings().await { | ||
| 640 | + Ok(settings) => { | ||
| 641 | + settings.enabled | ||
| 642 | + && !settings.host.trim().is_empty() | ||
| 643 | + && !settings.from_addr.trim().is_empty() | ||
| 644 | + } | ||
| 645 | + Err(_) => false, | ||
| 646 | + } | ||
| 647 | +} | ||
| 648 | + | ||
| 620 | /// Builds the page data from the stored state and the message set for this render. | 649 | /// Builds the page data from the stored state and the message set for this render. |
| 621 | async fn build_page( | 650 | async fn build_page( |
| 622 | state: &AppState, | 651 | state: &AppState, |
| @@ -692,6 +721,7 @@ async fn build_page( | |||
| 692 | stored_email, | 721 | stored_email, |
| 693 | email_status, | 722 | email_status, |
| 694 | email_sent, | 723 | email_sent, |
| 724 | + mail_ready: mail_can_send(state).await, | ||
| 695 | email: shown | 725 | email: shown |
| 696 | .email_draft | 726 | .email_draft |
| 697 | .unwrap_or_else(|| viewer.0.email.clone().unwrap_or_default()), | 727 | .unwrap_or_else(|| viewer.0.email.clone().unwrap_or_default()), |
| @@ -1103,6 +1133,11 @@ async fn two_factor_recovery(cx: &Cx, Form(form): Form<CodeForm>) -> Result<impl | |||
| 1103 | two_factor_panel: TwoFactorPanel::Regenerate, | 1133 | two_factor_panel: TwoFactorPanel::Regenerate, |
| 1104 | ..Shown::default() | 1134 | ..Shown::default() |
| 1105 | }; | 1135 | }; |
| 1136 | + if let Err(refused) = require_password(lang, state, &viewer.0, &form.current_password).await? { | ||
| 1137 | + shown.two_factor_error = Some(refused.message.into()); | ||
| 1138 | + shown.throttled = refused.retry; | ||
| 1139 | + return respond(cx, viewer, shown).await; | ||
| 1140 | + } | ||
| 1106 | if let Some(retry) = second_factor_blocked(state, &user_id) { | 1141 | if let Some(retry) = second_factor_blocked(state, &user_id) { |
| 1107 | shown.two_factor_error = Some(t(lang, Key::ErrThrottled).into()); | 1142 | shown.two_factor_error = Some(t(lang, Key::ErrThrottled).into()); |
| 1108 | shown.throttled = Some(retry); | 1143 | shown.throttled = Some(retry); |
| @@ -1823,7 +1858,7 @@ mod tests { | |||
| 1823 | "only the turn-off panel should be open" | 1858 | "only the turn-off panel should be open" |
| 1824 | ); | 1859 | ); |
| 1825 | 1860 | ||
| 1826 | - let bad_code = format!("csrf={CSRF}&code=123456x"); | 1861 | + let bad_code = format!("csrf={CSRF}¤t_password={PASSWORD}&code=123456x"); |
| 1827 | let reply = send( | 1862 | let reply = send( |
| 1828 | &fx.router, | 1863 | &fx.router, |
| 1829 | "POST", | 1864 | "POST", |
| @@ -1843,7 +1878,10 @@ mod tests { | |||
| 1843 | "a refused code leaves the old codes" | 1878 | "a refused code leaves the old codes" |
| 1844 | ); | 1879 | ); |
| 1845 | 1880 | ||
| 1846 | - let good = format!("csrf={CSRF}&code={}", now_code(&shared)); | 1881 | + let good = format!( |
| 1882 | + "csrf={CSRF}¤t_password={PASSWORD}&code={}", | ||
| 1883 | + now_code(&shared) | ||
| 1884 | + ); | ||
| 1847 | let reply = send( | 1885 | let reply = send( |
| 1848 | &fx.router, | 1886 | &fx.router, |
| 1849 | "POST", | 1887 | "POST", |
crates/forge-web/src/pages/snippets.rsmodified+12 -1
| @@ -344,6 +344,7 @@ async fn snippet_files( | |||
| 344 | .collect(); | 344 | .collect(); |
| 345 | Ok(view! { | 345 | Ok(view! { |
| 346 | <div class="snippet-files"> | 346 | <div class="snippet-files"> |
| 347 | + <span class="snippet-files-label" aria-hidden="true">(g::t(lang, K::Files))</span> | ||
| 347 | <div class="snippet-tabbar"> | 348 | <div class="snippet-tabbar"> |
| 348 | <div class="snippet-tabs" role="group" aria-label=(g::t(lang, K::Files))> | 349 | <div class="snippet-tabs" role="group" aria-label=(g::t(lang, K::Files))> |
| 349 | for (number, label, checked) in tabs.into_iter() { | 350 | for (number, label, checked) in tabs.into_iter() { |
| @@ -474,6 +475,9 @@ async fn snippet_body( | |||
| 474 | confirm_act(lang: lang, label: g::t(lang, K::Delete), action: delete_action.as_str(), csrf: token.as_str()) | 475 | confirm_act(lang: lang, label: g::t(lang, K::Delete), action: delete_action.as_str(), csrf: token.as_str()) |
| 475 | } | 476 | } |
| 476 | ) | 477 | ) |
| 478 | + if is_owner { | ||
| 479 | + crate::pages::profile::own_profile_tabs(lang: lang, username: owner.to_owned(), current: "snippets".to_owned()) | ||
| 480 | + } | ||
| 477 | <div class="sheet" data-live=(live.as_deref())> | 481 | <div class="sheet" data-live=(live.as_deref())> |
| 478 | <section class="sec"> | 482 | <section class="sec"> |
| 479 | if !description.is_empty() { | 483 | if !description.is_empty() { |
| @@ -510,6 +514,7 @@ async fn revisions_body( | |||
| 510 | title: &str, | 514 | title: &str, |
| 511 | revisions: Vec<RevisionView>, | 515 | revisions: Vec<RevisionView>, |
| 512 | live: Option<String>, | 516 | live: Option<String>, |
| 517 | + owner_tabs: Option<String>, | ||
| 513 | ) -> Result<impl View> { | 518 | ) -> Result<impl View> { |
| 514 | let back = format!("/snippets/{snippet_id}"); | 519 | let back = format!("/snippets/{snippet_id}"); |
| 515 | let heading = g::revisions_of(lang, title); | 520 | let heading = g::revisions_of(lang, title); |
| @@ -517,6 +522,9 @@ async fn revisions_body( | |||
| 517 | head(title: heading.as_str(), | 522 | head(title: heading.as_str(), |
| 518 | <a class="button" href=(back)>(g::t(lang, K::BackToSnippet))</a> | 523 | <a class="button" href=(back)>(g::t(lang, K::BackToSnippet))</a> |
| 519 | ) | 524 | ) |
| 525 | + if let Some(owner) = owner_tabs { | ||
| 526 | + crate::pages::profile::own_profile_tabs(lang: lang, username: owner, current: "snippets".to_owned()) | ||
| 527 | + } | ||
| 520 | <div class="sheet" data-live=(live.as_deref())> | 528 | <div class="sheet" data-live=(live.as_deref())> |
| 521 | if revisions.is_empty() { | 529 | if revisions.is_empty() { |
| 522 | <p class="state">(g::t(lang, K::NoRevisions))</p> | 530 | <p class="state">(g::t(lang, K::NoRevisions))</p> |
| @@ -547,9 +555,11 @@ async fn snippet_form_page( | |||
| 547 | let title = draft.title.clone(); | 555 | let title = draft.title.clone(); |
| 548 | let description = draft.description.clone(); | 556 | let description = draft.description.clone(); |
| 549 | let visibility = draft.visibility.clone(); | 557 | let visibility = draft.visibility.clone(); |
| 558 | + let tab_user = viewer.0.username.clone(); | ||
| 550 | Ok(view! { | 559 | Ok(view! { |
| 551 | shell(title: heading, viewer: Some(viewer), | 560 | shell(title: heading, viewer: Some(viewer), |
| 552 | head(title: heading) | 561 | head(title: heading) |
| 562 | + crate::pages::profile::own_profile_tabs(lang: lang, username: tab_user, current: "snippets".to_owned()) | ||
| 553 | <div class="sheet"> | 563 | <div class="sheet"> |
| 554 | snippet_form(lang: lang, csrf: csrf.as_str(), action: action, | 564 | snippet_form(lang: lang, csrf: csrf.as_str(), action: action, |
| 555 | title: title.as_str(), description: description.as_str(), | 565 | title: title.as_str(), description: description.as_str(), |
| @@ -779,7 +789,8 @@ async fn snippet_revisions(cx: &Cx) -> Result<impl View> { | |||
| 779 | Ok(view! { | 789 | Ok(view! { |
| 780 | shell(title: snippet.title.as_str(), viewer: viewer.as_ref(), | 790 | shell(title: snippet.title.as_str(), viewer: viewer.as_ref(), |
| 781 | revisions_body(lang: lang, snippet_id: snippet.id.as_str(), title: snippet.title.as_str(), | 791 | revisions_body(lang: lang, snippet_id: snippet.id.as_str(), title: snippet.title.as_str(), |
| 782 | - revisions: rows, live: Some(item_live_url(snippet.id.as_str()))) | 792 | + revisions: rows, live: Some(item_live_url(snippet.id.as_str())), |
| 793 | + owner_tabs: viewer.as_ref().filter(|(user, _)| user.id == snippet.owner_id).map(|(user, _)| user.username.clone())) | ||
| 783 | ) | 794 | ) |
| 784 | }) | 795 | }) |
| 785 | } | 796 | } |
crates/forge-web/src/views/find.rsadded+212 -0
| @@ -0,0 +1,212 @@ | |||
| 1 | +//! Search in a list: one field, live as you type, with two options beside it. By default a search | ||
| 2 | +//! forgives typos and case: every word typed must be in the text, or close to one of its words | ||
| 3 | +//! (one slip in words of four to seven letters, two in longer ones), or the start of one. "Exact" asks for the typed | ||
| 4 | +//! text as it is, as one piece; "Match case" keeps upper and lower case apart and looks for each | ||
| 5 | +//! word as typed. | ||
| 6 | + | ||
| 7 | +use topcoat::Result; | ||
| 8 | +use topcoat::view::{View, component, view}; | ||
| 9 | + | ||
| 10 | +use crate::i18n::Lang; | ||
| 11 | +use crate::pages::passkeys::s; | ||
| 12 | + | ||
| 13 | +/// The longest search kept, in characters. | ||
| 14 | +pub const MAX_QUERY_CHARS: usize = 100; | ||
| 15 | + | ||
| 16 | +/// A search as typed, with its options. | ||
| 17 | +#[derive(Clone, Debug, Default)] | ||
| 18 | +pub struct Finder { | ||
| 19 | + /// The search as typed, trimmed. | ||
| 20 | + pub q: String, | ||
| 21 | + pub exact: bool, | ||
| 22 | + pub case: bool, | ||
| 23 | + /// The search folded for matching: lower case unless Match case is on. | ||
| 24 | + needle: String, | ||
| 25 | + words: Vec<Vec<char>>, | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +impl Finder { | ||
| 29 | + /// A search from the query's `q`, `exact` and `case` values. An option is on when its value is | ||
| 30 | + /// present and not empty. | ||
| 31 | + pub fn new(q: Option<&str>, exact: Option<&str>, case: Option<&str>) -> Finder { | ||
| 32 | + let q: String = q | ||
| 33 | + .unwrap_or("") | ||
| 34 | + .trim() | ||
| 35 | + .chars() | ||
| 36 | + .take(MAX_QUERY_CHARS) | ||
| 37 | + .collect(); | ||
| 38 | + let exact = exact.is_some_and(|v| !v.is_empty()); | ||
| 39 | + let case = case.is_some_and(|v| !v.is_empty()); | ||
| 40 | + let needle = if case { q.clone() } else { q.to_lowercase() }; | ||
| 41 | + let words = needle | ||
| 42 | + .split(|c: char| !c.is_alphanumeric()) | ||
| 43 | + .filter(|w| !w.is_empty()) | ||
| 44 | + .map(|w| w.chars().collect()) | ||
| 45 | + .collect(); | ||
| 46 | + Finder { | ||
| 47 | + q, | ||
| 48 | + exact, | ||
| 49 | + case, | ||
| 50 | + needle, | ||
| 51 | + words, | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /// True when nothing was typed: everything matches. | ||
| 56 | + pub fn is_empty(&self) -> bool { | ||
| 57 | + self.needle.is_empty() | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /// True when `text` matches the search. | ||
| 61 | + pub fn matches(&self, text: &str) -> bool { | ||
| 62 | + if self.is_empty() { | ||
| 63 | + return true; | ||
| 64 | + } | ||
| 65 | + let hay = if self.case { | ||
| 66 | + text.to_owned() | ||
| 67 | + } else { | ||
| 68 | + text.to_lowercase() | ||
| 69 | + }; | ||
| 70 | + if hay.contains(&self.needle) { | ||
| 71 | + return true; | ||
| 72 | + } | ||
| 73 | + if self.exact { | ||
| 74 | + return false; | ||
| 75 | + } | ||
| 76 | + // Word by word, each typed word must start one of the text's words, so a short word such | ||
| 77 | + // as "1" does not match every text with a 1 somewhere in it. Match case asks for the words | ||
| 78 | + // as typed, so a slip of case is not forgiven as a typo. | ||
| 79 | + let tokens: Vec<Vec<char>> = hay | ||
| 80 | + .split(|c: char| !c.is_alphanumeric()) | ||
| 81 | + .filter(|t| !t.is_empty()) | ||
| 82 | + .map(|t| t.chars().collect()) | ||
| 83 | + .collect(); | ||
| 84 | + !self.words.is_empty() | ||
| 85 | + && self.words.iter().all(|word| { | ||
| 86 | + tokens | ||
| 87 | + .iter() | ||
| 88 | + .any(|token| token.starts_with(word) || (!self.case && near(word, token))) | ||
| 89 | + }) | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /// True when any of `fields` matches, read as one text. | ||
| 93 | + pub fn matches_any(&self, fields: &[&str]) -> bool { | ||
| 94 | + self.is_empty() || self.matches(&fields.join(" \u{1f} ")) | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /// The query pairs that keep this search in a link: `q`, and each option that is on. | ||
| 98 | + pub fn params(&self) -> Vec<(&'static str, &str)> { | ||
| 99 | + let mut out = vec![("q", self.q.as_str())]; | ||
| 100 | + if self.exact { | ||
| 101 | + out.push(("exact", "1")); | ||
| 102 | + } | ||
| 103 | + if self.case { | ||
| 104 | + out.push(("case", "1")); | ||
| 105 | + } | ||
| 106 | + out | ||
| 107 | + } | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +/// How many slips a typed word of `len` letters may have. | ||
| 111 | +fn slips_for(len: usize) -> usize { | ||
| 112 | + match len { | ||
| 113 | + 0..=3 => 0, | ||
| 114 | + 4..=7 => 1, | ||
| 115 | + _ => 2, | ||
| 116 | + } | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +/// True when the typed `word` is close to `token`, or to the start of it as long as the word. | ||
| 120 | +fn near(word: &[char], token: &[char]) -> bool { | ||
| 121 | + let slips = slips_for(word.len()); | ||
| 122 | + if slips == 0 { | ||
| 123 | + return false; | ||
| 124 | + } | ||
| 125 | + if distance(word, token) <= slips { | ||
| 126 | + return true; | ||
| 127 | + } | ||
| 128 | + token.len() > word.len() && distance(word, &token[..word.len()]) <= slips | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +/// Edits (insert, delete, change, swap two neighbours) between two words. | ||
| 132 | +fn distance(a: &[char], b: &[char]) -> usize { | ||
| 133 | + if a.len().abs_diff(b.len()) > 2 { | ||
| 134 | + return usize::MAX; | ||
| 135 | + } | ||
| 136 | + let (n, m) = (a.len(), b.len()); | ||
| 137 | + let mut d = vec![vec![0usize; m + 1]; n + 1]; | ||
| 138 | + for (i, row) in d.iter_mut().enumerate() { | ||
| 139 | + row[0] = i; | ||
| 140 | + } | ||
| 141 | + for j in 0..=m { | ||
| 142 | + d[0][j] = j; | ||
| 143 | + } | ||
| 144 | + for i in 1..=n { | ||
| 145 | + for j in 1..=m { | ||
| 146 | + let cost = usize::from(a[i - 1] != b[j - 1]); | ||
| 147 | + let mut best = (d[i - 1][j] + 1) | ||
| 148 | + .min(d[i][j - 1] + 1) | ||
| 149 | + .min(d[i - 1][j - 1] + cost); | ||
| 150 | + if i > 1 && j > 1 && a[i - 1] == b[j - 2] && a[i - 2] == b[j - 1] { | ||
| 151 | + best = best.min(d[i - 2][j - 2] + 1); | ||
| 152 | + } | ||
| 153 | + d[i][j] = best; | ||
| 154 | + } | ||
| 155 | + } | ||
| 156 | + d[n][m] | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +/// The search field of a list, with its two options beside it, for inside a GET form. The field | ||
| 160 | +/// searches as you type; an option applies the moment it is ticked. | ||
| 161 | +#[component] | ||
| 162 | +pub async fn finder_field( | ||
| 163 | + lang: Lang, | ||
| 164 | + finder: Finder, | ||
| 165 | + placeholder: &str, | ||
| 166 | + #[default] id: Option<&str>, | ||
| 167 | +) -> Result<impl View> { | ||
| 168 | + let id = id.unwrap_or("find-q"); | ||
| 169 | + Ok(view! { | ||
| 170 | + <div class="list-find"> | ||
| 171 | + <div class="plain-search"> | ||
| 172 | + <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg> | ||
| 173 | + <label class="sr-only" for=(id)>(placeholder)</label> | ||
| 174 | + <input id=(id) type="search" name="q" value=(finder.q.as_str()) placeholder=(placeholder) data-live-search="" autocomplete="off"> | ||
| 175 | + </div> | ||
| 176 | + <label class="find-opt" title=(s(lang, "Only the text as typed, as one piece", "Yalnızca yazılan metin, tek parça olarak"))> | ||
| 177 | + <input type="checkbox" name="exact" value="1" checked=(finder.exact) data-autosubmit="true"> | ||
| 178 | + <span>(s(lang, "Exact", "Tam"))</span> | ||
| 179 | + </label> | ||
| 180 | + <label class="find-opt" title=(s(lang, "Keep upper and lower case apart", "Büyük ve küçük harfi ayırt et"))> | ||
| 181 | + <input type="checkbox" name="case" value="1" checked=(finder.case) data-autosubmit="true"> | ||
| 182 | + <span>"Aa"</span> | ||
| 183 | + </label> | ||
| 184 | + <button type="submit" class="sr-only">(s(lang, "Search", "Ara"))</button> | ||
| 185 | + </div> | ||
| 186 | + }) | ||
| 187 | +} | ||
| 188 | + | ||
| 189 | +#[cfg(test)] | ||
| 190 | +mod tests { | ||
| 191 | + use super::Finder; | ||
| 192 | + | ||
| 193 | + fn find(q: &str, exact: bool, case: bool) -> Finder { | ||
| 194 | + Finder::new(Some(q), exact.then_some("1"), case.then_some("1")) | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + #[test] | ||
| 198 | + fn forgives_typos_and_case_unless_asked() { | ||
| 199 | + let text = "Repository created · Hezarfen/hezarfen_landing"; | ||
| 200 | + assert!(find("", false, false).matches(text)); | ||
| 201 | + assert!(find("reposotory", false, false).matches(text)); | ||
| 202 | + assert!(find("landnig hezarfen", false, false).matches(text)); | ||
| 203 | + assert!(find("crea", false, false).matches(text)); | ||
| 204 | + assert!(!find("deleted", false, false).matches(text)); | ||
| 205 | + assert!(!find("reposotory", true, false).matches(text)); | ||
| 206 | + assert!(find("repository CREATED", true, false).matches(text)); | ||
| 207 | + assert!(!find("repository", false, true).matches(text)); | ||
| 208 | + assert!(find("Repository", false, true).matches(text)); | ||
| 209 | + assert!(!find("bulk 1", false, false).matches("tahinli/bulk-21")); | ||
| 210 | + assert!(find("bulk 1", false, false).matches("tahinli/bulk-12")); | ||
| 211 | + } | ||
| 212 | +} | ||
crates/forge-web/src/views/mod.rsmodified+25 -14
| @@ -4,6 +4,7 @@ | |||
| 4 | pub mod commit_line; | 4 | pub mod commit_line; |
| 5 | pub mod commit_status; | 5 | pub mod commit_status; |
| 6 | pub mod diff; | 6 | pub mod diff; |
| 7 | +pub mod find; | ||
| 7 | pub mod heatmap; | 8 | pub mod heatmap; |
| 8 | pub mod parts; | 9 | pub mod parts; |
| 9 | pub mod repo_list; | 10 | pub mod repo_list; |
| @@ -1218,9 +1219,19 @@ pub fn display_name(lang: Lang, username: &str) -> String { | |||
| 1218 | } | 1219 | } |
| 1219 | 1220 | ||
| 1220 | /// URL of a user's avatar. `hash` is the avatar's content hash (`?v=` makes the response | 1221 | /// URL of a user's avatar. `hash` is the avatar's content hash (`?v=` makes the response |
| 1221 | -/// immutable); `None` gives the generated default, which is cached for a short time only. | 1222 | +/// immutable); `None` means the account has no photo, and gives its letter avatar inline, so the |
| 1223 | +/// page shows it with no request. | ||
| 1222 | pub fn avatar_url(username: &str, hash: Option<&str>) -> String { | 1224 | pub fn avatar_url(username: &str, hash: Option<&str>) -> String { |
| 1223 | - format!("/avatars/{}?v={}", enc(username), hash.unwrap_or("default")) | 1225 | + match hash { |
| 1226 | + Some(hash) => format!("/avatars/{}?v={hash}", enc(username)), | ||
| 1227 | + None => crate::pages::avatars::default_data_url(username), | ||
| 1228 | + } | ||
| 1229 | +} | ||
| 1230 | + | ||
| 1231 | +/// URL of a user's avatar when the page does not know whether the account has a photo: the server | ||
| 1232 | +/// answers with the photo or the letter avatar. | ||
| 1233 | +pub fn avatar_url_unknown(username: &str) -> String { | ||
| 1234 | + format!("/avatars/{}?v=default", enc(username)) | ||
| 1224 | } | 1235 | } |
| 1225 | 1236 | ||
| 1226 | /// Public profile URL of a user: `/{username}`. | 1237 | /// Public profile URL of a user: `/{username}`. |
| @@ -2026,10 +2037,10 @@ mod shell_tests { | |||
| 2026 | 2037 | ||
| 2027 | // An anonymous page renders the default colours. | 2038 | // An anonymous page renders the default colours. |
| 2028 | let tag = html_tag(&html); | 2039 | let tag = html_tag(&html); |
| 2029 | - assert!(tag.contains("data-accent-light=\"ember\""), "{tag}"); | 2040 | + assert!(tag.contains("data-accent-light=\"sage\""), "{tag}"); |
| 2030 | - assert!(tag.contains("data-accent-dark=\"ember\""), "{tag}"); | 2041 | + assert!(tag.contains("data-accent-dark=\"sage\""), "{tag}"); |
| 2031 | - assert!(tag.contains("data-base-light=\"anvil\""), "{tag}"); | 2042 | + assert!(tag.contains("data-base-light=\"ink\""), "{tag}"); |
| 2032 | - assert!(tag.contains("data-base-dark=\"anvil\""), "{tag}"); | 2043 | + assert!(tag.contains("data-base-dark=\"ink\""), "{tag}"); |
| 2033 | } | 2044 | } |
| 2034 | 2045 | ||
| 2035 | /// The `<html …>` start tag of a page. | 2046 | /// The `<html …>` start tag of a page. |
| @@ -2101,10 +2112,10 @@ mod shell_tests { | |||
| 2101 | ["removed-palette", "removed-palette", "x", "x"], | 2112 | ["removed-palette", "removed-palette", "x", "x"], |
| 2102 | ) | 2113 | ) |
| 2103 | .await; | 2114 | .await; |
| 2104 | - assert!(removed.contains("data-accent-light=\"ember\""), "{removed}"); | 2115 | + assert!(removed.contains("data-accent-light=\"sage\""), "{removed}"); |
| 2105 | - assert!(removed.contains("data-accent-dark=\"ember\""), "{removed}"); | 2116 | + assert!(removed.contains("data-accent-dark=\"sage\""), "{removed}"); |
| 2106 | - assert!(removed.contains("data-base-light=\"anvil\""), "{removed}"); | 2117 | + assert!(removed.contains("data-base-light=\"ink\""), "{removed}"); |
| 2107 | - assert!(removed.contains("data-base-dark=\"anvil\""), "{removed}"); | 2118 | + assert!(removed.contains("data-base-dark=\"ink\""), "{removed}"); |
| 2108 | // A removed preset (`ochre`, `mist`) falls back too, and a hue passes through as itself. | 2119 | // A removed preset (`ochre`, `mist`) falls back too, and a hue passes through as itself. |
| 2109 | let retired = html_tag_for_colours( | 2120 | let retired = html_tag_for_colours( |
| 2110 | &router, | 2121 | &router, |
| @@ -2114,10 +2125,10 @@ mod shell_tests { | |||
| 2114 | ["ochre", "terracotta", "mist", "stone"], | 2125 | ["ochre", "terracotta", "mist", "stone"], |
| 2115 | ) | 2126 | ) |
| 2116 | .await; | 2127 | .await; |
| 2117 | - assert!(retired.contains("data-accent-light=\"ember\""), "{retired}"); | 2128 | + assert!(retired.contains("data-accent-light=\"sage\""), "{retired}"); |
| 2118 | - assert!(retired.contains("data-accent-dark=\"ember\""), "{retired}"); | 2129 | + assert!(retired.contains("data-accent-dark=\"sage\""), "{retired}"); |
| 2119 | - assert!(retired.contains("data-base-light=\"anvil\""), "{retired}"); | 2130 | + assert!(retired.contains("data-base-light=\"ink\""), "{retired}"); |
| 2120 | - assert!(retired.contains("data-base-dark=\"anvil\""), "{retired}"); | 2131 | + assert!(retired.contains("data-base-dark=\"ink\""), "{retired}"); |
| 2121 | let hued = html_tag_for_colours( | 2132 | let hued = html_tag_for_colours( |
| 2122 | &router, | 2133 | &router, |
| 2123 | &store, | 2134 | &store, |
crates/forge-web/src/views/repo_list.rsmodified+38 -17
| @@ -101,23 +101,36 @@ pub struct PageLink { | |||
| 101 | current: bool, | 101 | current: bool, |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | -/// The pages to show for `page` of `pages`: the first, the last and the neighbours of the | 104 | +/// How many page slots the numbered pager shows once there are more pages than that. |
| 105 | -/// current page, with `None` for a gap. A gap of a single page shows that page instead. | 105 | +const PAGE_SLOTS: u64 = 7; |
| 106 | + | ||
| 107 | +/// The pages to show for `page` of `pages`, with `None` for a gap. Past seven pages there are | ||
| 108 | +/// always seven slots (the first, the last, the current one's neighbours and the gaps), so moving | ||
| 109 | +/// between pages never moves Next or the numbers. | ||
| 106 | fn page_numbers(page: u64, pages: u64) -> Vec<Option<u64>> { | 110 | fn page_numbers(page: u64, pages: u64) -> Vec<Option<u64>> { |
| 107 | - let mut out = Vec::new(); | 111 | + if pages <= PAGE_SLOTS { |
| 108 | - let mut last = 0; | 112 | + return (1..=pages).map(Some).collect(); |
| 109 | - for n in 1..=pages { | 113 | + } |
| 110 | - let near = n == 1 || n == pages || n.abs_diff(page) <= 1; | 114 | + let page = page.clamp(1, pages); |
| 111 | - let fills_gap = (n == 2 && page == 4) || (n + 1 == pages && page + 3 == pages); | 115 | + if page <= 4 { |
| 112 | - if near || fills_gap { | 116 | + let mut out: Vec<Option<u64>> = (1..=5).map(Some).collect(); |
| 113 | - if n > last + 1 { | 117 | + out.extend([None, Some(pages)]); |
| 114 | - out.push(None); | 118 | + out |
| 115 | - } | 119 | + } else if page + 3 >= pages { |
| 116 | - out.push(Some(n)); | 120 | + let mut out = vec![Some(1), None]; |
| 117 | - last = n; | 121 | + out.extend((pages - 4..=pages).map(Some)); |
| 118 | - } | 122 | + out |
| 123 | + } else { | ||
| 124 | + vec![ | ||
| 125 | + Some(1), | ||
| 126 | + None, | ||
| 127 | + Some(page - 1), | ||
| 128 | + Some(page), | ||
| 129 | + Some(page + 1), | ||
| 130 | + None, | ||
| 131 | + Some(pages), | ||
| 132 | + ] | ||
| 119 | } | 133 | } |
| 120 | - out | ||
| 121 | } | 134 | } |
| 122 | 135 | ||
| 123 | /// The numbered pager with Previous and Next, from `pager_links`. Nothing is shown for a single | 136 | /// The numbered pager with Previous and Next, from `pager_links`. Nothing is shown for a single |
| @@ -138,6 +151,8 @@ pub async fn pager( | |||
| 138 | <nav class="pager pager-numbered" aria-label=(g::t(lang, K::Pages))> | 151 | <nav class="pager pager-numbered" aria-label=(g::t(lang, K::Pages))> |
| 139 | if let Some(href) = prev { | 152 | if let Some(href) = prev { |
| 140 | <a class="pager-step" href=(href.as_str()) rel="prev">(g::t(lang, K::Previous))</a> | 153 | <a class="pager-step" href=(href.as_str()) rel="prev">(g::t(lang, K::Previous))</a> |
| 154 | + } else { | ||
| 155 | + <span class="pager-step off" aria-disabled="true">(g::t(lang, K::Previous))</span> | ||
| 141 | } | 156 | } |
| 142 | for link in links.into_iter() { | 157 | for link in links.into_iter() { |
| 143 | if link.current { | 158 | if link.current { |
| @@ -152,6 +167,8 @@ pub async fn pager( | |||
| 152 | } | 167 | } |
| 153 | if let Some(href) = next { | 168 | if let Some(href) = next { |
| 154 | <a class="pager-step" href=(href.as_str()) rel="next">(g::t(lang, K::Next))</a> | 169 | <a class="pager-step" href=(href.as_str()) rel="next">(g::t(lang, K::Next))</a> |
| 170 | + } else { | ||
| 171 | + <span class="pager-step off" aria-disabled="true">(g::t(lang, K::Next))</span> | ||
| 155 | } | 172 | } |
| 156 | </nav> | 173 | </nav> |
| 157 | } | 174 | } |
| @@ -200,10 +217,14 @@ mod tests { | |||
| 200 | fn pages_are_compact_with_gaps() { | 217 | fn pages_are_compact_with_gaps() { |
| 201 | assert_eq!(shown(1, 1), "1"); | 218 | assert_eq!(shown(1, 1), "1"); |
| 202 | assert_eq!(shown(1, 3), "1 2 3"); | 219 | assert_eq!(shown(1, 3), "1 2 3"); |
| 220 | + assert_eq!(shown(1, 7), "1 2 3 4 5 6 7"); | ||
| 203 | assert_eq!(shown(5, 12), "1 ... 4 5 6 ... 12"); | 221 | assert_eq!(shown(5, 12), "1 ... 4 5 6 ... 12"); |
| 204 | - assert_eq!(shown(1, 12), "1 2 ... 12"); | 222 | + assert_eq!(shown(1, 12), "1 2 3 4 5 ... 12"); |
| 205 | - assert_eq!(shown(12, 12), "1 ... 11 12"); | 223 | + assert_eq!(shown(12, 12), "1 ... 8 9 10 11 12"); |
| 206 | assert_eq!(shown(4, 12), "1 2 3 4 5 ... 12"); | 224 | assert_eq!(shown(4, 12), "1 2 3 4 5 ... 12"); |
| 207 | assert_eq!(shown(9, 12), "1 ... 8 9 10 11 12"); | 225 | assert_eq!(shown(9, 12), "1 ... 8 9 10 11 12"); |
| 226 | + for page in 1..=54 { | ||
| 227 | + assert_eq!(page_numbers(page, 54).len(), 7, "page {page}"); | ||
| 228 | + } | ||
| 208 | } | 229 | } |
| 209 | } | 230 | } |
crates/forge-web/src/views/review_thread.rsmodified+2 -2
| @@ -16,7 +16,7 @@ use crate::i18n::pulls_review::{self as g, K}; | |||
| 16 | use crate::pages::issue_parts::When; | 16 | use crate::pages::issue_parts::When; |
| 17 | use crate::render::markdown::{LinkContext, render_markdown}; | 17 | use crate::render::markdown::{LinkContext, render_markdown}; |
| 18 | use crate::views::parts::{confirm_act, post_act, reveal}; | 18 | use crate::views::parts::{confirm_act, post_act, reveal}; |
| 19 | -use crate::views::{avatar_url, display_name, now_unix, user_href, user_link}; | 19 | +use crate::views::{avatar_url_unknown, display_name, now_unix, user_href, user_link}; |
| 20 | 20 | ||
| 21 | /// What the Apply control of a suggestion shows. A root without a state shows the diff only. | 21 | /// What the Apply control of a suggestion shows. A root without a state shows the diff only. |
| 22 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 22 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| @@ -149,7 +149,7 @@ fn comment_row( | |||
| 149 | let edited = ctx.edits.get(&comment.id).is_some_and(|count| *count > 0); | 149 | let edited = ctx.edits.get(&comment.id).is_some_and(|count| *count > 0); |
| 150 | let parts = body_parts(&comment, ctx, state); | 150 | let parts = body_parts(&comment, ctx, state); |
| 151 | CommentRow { | 151 | CommentRow { |
| 152 | - avatar: avatar_url(&comment.author_name, None), | 152 | + avatar: avatar_url_unknown(&comment.author_name), |
| 153 | author: display_name(lang, &comment.author_name), | 153 | author: display_name(lang, &comment.author_name), |
| 154 | login: comment.author_name.clone(), | 154 | login: comment.author_name.clone(), |
| 155 | when: When::new(lang, &comment.created_at, &ctx.tz, now), | 155 | when: When::new(lang, &comment.created_at, &ctx.tz, now), |
docs/ui-language.mdmodified+29 -9
| @@ -67,10 +67,15 @@ no `margin-left:auto`, no `justify-content:space-between`, no second column at t | |||
| 67 | 67 | ||
| 68 | - **Button**: `<button>` (soft), `<button class="primary">` (filled), `.small`. A head holds the page's | 68 | - **Button**: `<button>` (soft), `<button class="primary">` (filled), `.small`. A head holds the page's |
| 69 | main action as `.primary` and its others as soft. A form's submit is `.primary`, once, under its fields. | 69 | main action as `.primary` and its others as soft. A form's submit is `.primary`, once, under its fields. |
| 70 | - `a.button` for a link that acts like one. | 70 | + `a.button` for a link that acts like one. Every action beside a title is that soft pill (or the filled |
| 71 | + one), whatever it is made of: an `a.act`, a form's `button.act` or a reveal's `summary.act` in the head | ||
| 72 | + takes the pill's look, so no head shows a bare word beside a button. | ||
| 71 | - **Tool**: `.act`, a quiet word (14px, dim, radius 12). `.act.danger` for destructive. This is what goes in | 73 | - **Tool**: `.act`, a quiet word (14px, dim, radius 12). `.act.danger` for destructive. This is what goes in |
| 72 | tools rows, in rows and in `.acts`. | 74 | tools rows, in rows and in `.acts`. |
| 73 | - `reveal(label, id, open)`: a tool that opens its form in place. `open` when a form came back with an error. | 75 | - `reveal(label, id, open)`: a tool that opens its form in place. `open` when a form came back with an error. |
| 76 | + In a `.fields` form its word starts on the controls' edge. What should not be one click away | ||
| 77 | + (regenerating recovery codes, turning off two-factor) is a reveal whose form asks for the password | ||
| 78 | + and the code again, never a prominent button. | ||
| 74 | - `confirm_act(lang, label, action, csrf, fields, note)`: every destructive action. It always asks first, in | 79 | - `confirm_act(lang, label, action, csrf, fields, note)`: every destructive action. It always asks first, in |
| 75 | place, with a small filled danger button and "Keep it". There are no one-click deletes. | 80 | place, with a small filled danger button and "Keep it". There are no one-click deletes. |
| 76 | - `post_act(label, action, csrf, fields)`: a tool that posts at once, for what loses nothing. | 81 | - `post_act(label, action, csrf, fields)`: a tool that posts at once, for what loses nothing. |
| @@ -99,13 +104,21 @@ label. Errors are `alert` at the top of the form they belong to, which stays ope | |||
| 99 | 104 | ||
| 100 | ## Lists and search | 105 | ## Lists and search |
| 101 | 106 | ||
| 102 | -Every search bar is live: `data-live-search` on a real GET form's input in `.plain-search`. It sits in the | 107 | +Every list that can grow has a search, and every search is `finder_field` (`views/find.rs`): a live |
| 103 | -tools row or above the rail's list. Filters are the rail, or `.tabs` when there are only a few. Pagers | 108 | +`.plain-search` (results follow typing, no Enter) with two options beside it, Exact and Aa (match case), |
| 104 | -appear only when another page exists, as one `nav.pager` row (Newer, the page, Older) under the list, on | 109 | +which apply the moment they are ticked. By default a search forgives typos and case. Its placeholder |
| 105 | -the sheet's inset with a hairline above. A long log (the audit log) numbers its pages in the same row | 110 | +names what is searched ("Search users", "Search organizations", not one text for every tab). A category |
| 106 | -(`nav.pager.pager-numbered`), the current page held like a pressed tool. An empty list is `.state` with | 111 | +filter is a `.find-filter`: its word, then the small soft select, on the same line. Inside a topic the |
| 107 | -one line and its action as `.act`. A log reads as text: action words, then facts joined with " · ", never | 112 | +row is `form.sec-tools`. |
| 108 | -raw JSON; repeats in a row fold into one line with "×N". | 113 | + |
| 114 | +A list that can grow is paged, never endless: about one screen of rows. Pagers appear only when another | ||
| 115 | +page exists, as one `nav.pager` row under the list on the sheet's inset. A numbered pager always has | ||
| 116 | +Previous and Next and always seven page slots once there are more than seven pages, so nothing in the | ||
| 117 | +row moves when you change page; a step you cannot take stays in place, dimmed. An empty list is | ||
| 118 | +`.state` with one line and its action as `.act`. A log reads as text: action words, then facts joined | ||
| 119 | +with " · ", never raw JSON. Runs of the same action by the same person fold into one `details.log-group` | ||
| 120 | +line with "×N" and what they share; the line opens in place to list every entry with what differs, and | ||
| 121 | +a page counts folded lines, so a page of folds is as full as any other. | ||
| 109 | 122 | ||
| 110 | ## Menus | 123 | ## Menus |
| 111 | 124 | ||
| @@ -123,7 +136,8 @@ with a green hue, so results sit with whichever accent is chosen. Cancelled is g | |||
| 123 | is blue and deleted is rose. | 136 | is blue and deleted is rose. |
| 124 | 137 | ||
| 125 | A colour choice offers five presets and a Custom chip (its swatch and the word), on the same columns | 138 | A colour choice offers five presets and a Custom chip (its swatch and the word), on the same columns |
| 126 | -in every row. | 139 | +in every row. Backgrounds and accents of one hue share a column: Ink and Sage (the default for light |
| 140 | +and dark), Anvil and Ember, Dusk and Ocean, Heather and Plum, Blush and Rose. | ||
| 127 | 141 | ||
| 128 | ## Type | 142 | ## Type |
| 129 | 143 | ||
| @@ -158,3 +172,9 @@ Turkish page shows no English, an English page no Turkish. | |||
| 158 | - Every control has one focus ring: 2px in `--focus`, inside its own edge (`outline-offset: -2px`), so | 172 | - Every control has one focus ring: 2px in `--focus`, inside its own edge (`outline-offset: -2px`), so |
| 159 | no sheet, row or scrolling list cuts it. | 173 | no sheet, row or scrolling list cuts it. |
| 160 | - A tab's own pages sit in its rail: the Security log is a Security rail item, not a page of its own. | 174 | - A tab's own pages sit in its rail: the Security log is a Security rail item, not a page of its own. |
| 175 | +- No page is an orphan. A page that makes or shows something of yours (a new repository, an import, a | ||
| 176 | + snippet, a new organization) shows your profile tabs with the area it belongs to marked, and the inbox | ||
| 177 | + pages (Notifications, Needs you, Review requests) share one rail, so a mouse reaches every neighbour. | ||
| 178 | +- An action a server cannot carry out shows as unavailable: no "send again" when mail is not set up. | ||
| 179 | +- Avatars without an uploaded image are drawn in the page (a letter on a colour from the name), so a | ||
| 180 | + list of people or organizations never waits on image requests. | ||
scripts/audit/measure.tsmodified+2 -2
| @@ -147,8 +147,8 @@ const DESIGN = `(() => { | |||
| 147 | if (!CONTROLS.some(([h, r, fs]) => p.h === h && p.r === r && p.fs === fs)) bad.push('control shape ' + p.h + '/' + p.r + '/' + p.fs + ': ' + label); | 147 | if (!CONTROLS.some(([h, r, fs]) => p.h === h && p.r === r && p.fs === fs)) bad.push('control shape ' + p.h + '/' + p.r + '/' + p.fs + ': ' + label); |
| 148 | } | 148 | } |
| 149 | if (isText || tag === 'SELECT') { | 149 | if (isText || tag === 'SELECT') { |
| 150 | - // One height a place: 32 in a tools row, 36 in the top bar, 38 everywhere else. | 150 | + // One height a place: 32 in a tools row or a list's search, 36 in the top bar, 38 everywhere else. |
| 151 | - const want = e.closest('.sheet-tools') ? 32 : e.closest('.topbar, .pathbar, .top-search') ? 36 : 38; | 151 | + const want = e.closest('.sheet-tools, .sec-tools, .list-find, .find-filter') ? 32 : e.closest('.topbar, .pathbar, .top-search') ? 36 : 38; |
| 152 | if (p.h !== want) bad.push('field height ' + p.h + ' (want ' + want + '): ' + label); | 152 | if (p.h !== want) bad.push('field height ' + p.h + ' (want ' + want + '): ' + label); |
| 153 | if (p.b) bad.push('field border: ' + label); | 153 | if (p.b) bad.push('field border: ' + label); |
| 154 | if (none(p.bg) && !e.closest('.plain-search, .top-search')) bad.push('field without fill: ' + label); | 154 | if (none(p.bg) && !e.closest('.plain-search, .top-search')) bad.push('field without fill: ' + label); |
style/_import.scssmodified+0 -8
| @@ -72,14 +72,6 @@ | |||
| 72 | max-width: 960px; | 72 | max-width: 960px; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | -.export-row { | ||
| 76 | - display: flex; | ||
| 77 | - flex-wrap: wrap; | ||
| 78 | - align-items: center; | ||
| 79 | - gap: 8px 14px; | ||
| 80 | - | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | .export-progress { | 75 | .export-progress { |
| 84 | width: 120px; | 76 | width: 120px; |
| 85 | } | 77 | } |
style/_min.scssmodified+2 -2
| @@ -507,8 +507,8 @@ div.line { | |||
| 507 | } | 507 | } |
| 508 | 508 | ||
| 509 | // A tick or a radio always sits right before its own text, wherever the label is. | 509 | // A tick or a radio always sits right before its own text, wherever the label is. |
| 510 | -main label:not(.colour-choice, .choice > label):has(> input[type="checkbox"]), | 510 | +main label:not(.colour-choice, .find-opt, .choice > label):has(> input[type="checkbox"]), |
| 511 | -main label:not(.colour-choice, .choice > label):has(> input[type="radio"]) { | 511 | +main label:not(.colour-choice, .find-opt, .choice > label):has(> input[type="radio"]) { |
| 512 | display: flex; | 512 | display: flex; |
| 513 | flex-direction: row; | 513 | flex-direction: row; |
| 514 | align-items: flex-start; | 514 | align-items: flex-start; |
style/_min_settings.scssmodified+9 -8
| @@ -53,12 +53,11 @@ | |||
| 53 | } | 53 | } |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | -// Data export: one archive, its state beside its name, its link under it. | 56 | +// Data export: each archive is one flat line (when, state, Download, Delete); a building one adds its |
| 57 | +// progress and an error under the line. | ||
| 57 | .export-row { | 58 | .export-row { |
| 58 | - display: flex; | 59 | + display: block; |
| 59 | - flex-direction: column; | 60 | + margin: 0 -18px; |
| 60 | - gap: 6px; | ||
| 61 | - padding: 10px 0; | ||
| 62 | border-bottom: 1px solid var(--border); | 61 | border-bottom: 1px solid var(--border); |
| 63 | 62 | ||
| 64 | &:last-child { | 63 | &:last-child { |
| @@ -66,12 +65,14 @@ | |||
| 66 | } | 65 | } |
| 67 | 66 | ||
| 68 | > .line { | 67 | > .line { |
| 69 | - min-height: 0; | 68 | + padding-left: 18px; |
| 69 | + padding-right: 18px; | ||
| 70 | border-bottom: 0; | 70 | border-bottom: 0; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | - > .hint { | 73 | + > progress, |
| 74 | - margin: 0; | 74 | + > .alert { |
| 75 | + margin: 0 18px 10px; | ||
| 75 | } | 76 | } |
| 76 | } | 77 | } |
| 77 | 78 | ||
style/_one.scssmodified+301 -1
| @@ -3230,9 +3230,34 @@ nav.pager.pager-numbered { | |||
| 3230 | font-size: 14px; | 3230 | font-size: 14px; |
| 3231 | 3231 | ||
| 3232 | .pager-page, | 3232 | .pager-page, |
| 3233 | - .pager-step { | 3233 | + .pager-step, |
| 3234 | + .pager-gap { | ||
| 3235 | + display: inline-flex; | ||
| 3236 | + align-items: center; | ||
| 3237 | + justify-content: center; | ||
| 3238 | + box-sizing: border-box; | ||
| 3239 | + height: 30px; | ||
| 3240 | + margin: 0; | ||
| 3234 | color: var(--muted); | 3241 | color: var(--muted); |
| 3235 | font-weight: 500; | 3242 | font-weight: 500; |
| 3243 | + font-variant-numeric: tabular-nums; | ||
| 3244 | + } | ||
| 3245 | + | ||
| 3246 | + // Every number and gap is one width, and Previous and Next always hold their place (dimmed when | ||
| 3247 | + // there is nowhere to go), so moving between pages never moves a thing in the row. | ||
| 3248 | + .pager-page, | ||
| 3249 | + .pager-gap { | ||
| 3250 | + min-width: 40px; | ||
| 3251 | + padding: 0 4px; | ||
| 3252 | + } | ||
| 3253 | + | ||
| 3254 | + .pager-step { | ||
| 3255 | + padding: 0 10px; | ||
| 3256 | + } | ||
| 3257 | + | ||
| 3258 | + .pager-step.off { | ||
| 3259 | + opacity: 0.4; | ||
| 3260 | + cursor: default; | ||
| 3236 | } | 3261 | } |
| 3237 | 3262 | ||
| 3238 | > :first-child { | 3263 | > :first-child { |
| @@ -3273,3 +3298,278 @@ nav.pager.pager-numbered { | |||
| 3273 | outline-offset: -2px; | 3298 | outline-offset: -2px; |
| 3274 | box-shadow: none; | 3299 | box-shadow: none; |
| 3275 | } | 3300 | } |
| 3301 | + | ||
| 3302 | +// A list's search: one 32px soft field with its icon inside, then Exact and Aa as quiet options that | ||
| 3303 | +// hold like a pressed tool when on. The ring is the field's own, drawn inside its edge, so focusing or | ||
| 3304 | +// typing never moves or grows a thing in the row. | ||
| 3305 | +.list-find { | ||
| 3306 | + display: inline-flex; | ||
| 3307 | + flex-wrap: wrap; | ||
| 3308 | + align-items: center; | ||
| 3309 | + gap: 4px; | ||
| 3310 | + | ||
| 3311 | + &#{&} .plain-search { | ||
| 3312 | + display: inline-flex; | ||
| 3313 | + flex: none; | ||
| 3314 | + align-items: center; | ||
| 3315 | + gap: 8px; | ||
| 3316 | + box-sizing: border-box; | ||
| 3317 | + width: 280px; | ||
| 3318 | + height: 32px; | ||
| 3319 | + margin: 0; | ||
| 3320 | + padding: 0 12px; | ||
| 3321 | + border-radius: 16px; | ||
| 3322 | + background: var(--surface-2); | ||
| 3323 | + | ||
| 3324 | + &:focus-within { | ||
| 3325 | + outline: 2px solid var(--focus); | ||
| 3326 | + outline-offset: -2px; | ||
| 3327 | + } | ||
| 3328 | + | ||
| 3329 | + .ico { | ||
| 3330 | + flex: none; | ||
| 3331 | + width: 16px; | ||
| 3332 | + height: 16px; | ||
| 3333 | + fill: none; | ||
| 3334 | + stroke: var(--muted); | ||
| 3335 | + stroke-width: 2; | ||
| 3336 | + } | ||
| 3337 | + | ||
| 3338 | + input[type="search"] { | ||
| 3339 | + flex: 1; | ||
| 3340 | + width: auto; | ||
| 3341 | + min-width: 0; | ||
| 3342 | + height: 100%; | ||
| 3343 | + margin: 0; | ||
| 3344 | + padding: 0; | ||
| 3345 | + border: 0; | ||
| 3346 | + border-radius: 0; | ||
| 3347 | + outline: 0; | ||
| 3348 | + background: none; | ||
| 3349 | + box-shadow: none; | ||
| 3350 | + font-size: 14px; | ||
| 3351 | + } | ||
| 3352 | + | ||
| 3353 | + > button[type="submit"] { | ||
| 3354 | + display: none; | ||
| 3355 | + } | ||
| 3356 | + } | ||
| 3357 | +} | ||
| 3358 | + | ||
| 3359 | +.find-opt.find-opt { | ||
| 3360 | + position: relative; | ||
| 3361 | + display: inline-flex; | ||
| 3362 | + flex-direction: row; | ||
| 3363 | + align-items: center; | ||
| 3364 | + box-sizing: border-box; | ||
| 3365 | + height: 32px; | ||
| 3366 | + padding: 0 12px; | ||
| 3367 | + border-radius: 16px; | ||
| 3368 | + color: var(--muted); | ||
| 3369 | + cursor: pointer; | ||
| 3370 | + font-size: 14px; | ||
| 3371 | + font-weight: 500; | ||
| 3372 | + user-select: none; | ||
| 3373 | + | ||
| 3374 | + > input { | ||
| 3375 | + position: absolute; | ||
| 3376 | + width: 1px; | ||
| 3377 | + height: 1px; | ||
| 3378 | + margin: 0; | ||
| 3379 | + opacity: 0; | ||
| 3380 | + pointer-events: none; | ||
| 3381 | + } | ||
| 3382 | + | ||
| 3383 | + &:hover { | ||
| 3384 | + color: var(--text); | ||
| 3385 | + } | ||
| 3386 | + | ||
| 3387 | + &:has(> input:checked) { | ||
| 3388 | + background: var(--surface-2); | ||
| 3389 | + color: var(--text); | ||
| 3390 | + } | ||
| 3391 | + | ||
| 3392 | + &:has(> input:focus-visible) { | ||
| 3393 | + outline: 2px solid var(--focus); | ||
| 3394 | + outline-offset: -2px; | ||
| 3395 | + } | ||
| 3396 | +} | ||
| 3397 | + | ||
| 3398 | +@media (max-width: 640px) { | ||
| 3399 | + .list-find { | ||
| 3400 | + width: 100%; | ||
| 3401 | + } | ||
| 3402 | + | ||
| 3403 | + .list-find.list-find .plain-search { | ||
| 3404 | + flex: 1 1 auto; | ||
| 3405 | + width: auto; | ||
| 3406 | + } | ||
| 3407 | +} | ||
| 3408 | + | ||
| 3409 | +// A filter beside a list's search: its word, then the small soft select every tools row uses. | ||
| 3410 | +.find-filter.find-filter { | ||
| 3411 | + display: inline-flex; | ||
| 3412 | + flex-direction: row; | ||
| 3413 | + align-items: center; | ||
| 3414 | + gap: 8px; | ||
| 3415 | + margin-left: 8px; | ||
| 3416 | + color: var(--muted); | ||
| 3417 | + font-size: 14px; | ||
| 3418 | + font-weight: 500; | ||
| 3419 | + | ||
| 3420 | + select { | ||
| 3421 | + width: auto; | ||
| 3422 | + max-width: 220px; | ||
| 3423 | + height: 32px; | ||
| 3424 | + min-height: 0; | ||
| 3425 | + padding: 0 30px 0 14px; | ||
| 3426 | + border-radius: 16px; | ||
| 3427 | + font-size: 14px; | ||
| 3428 | + } | ||
| 3429 | +} | ||
| 3430 | + | ||
| 3431 | +// A list's search inside a topic: the same row as a sheet's tools, on the topic's edge. | ||
| 3432 | +.sec-tools { | ||
| 3433 | + display: flex; | ||
| 3434 | + flex-wrap: wrap; | ||
| 3435 | + align-items: center; | ||
| 3436 | + gap: 4px; | ||
| 3437 | + margin: 2px 0 6px; | ||
| 3438 | +} | ||
| 3439 | + | ||
| 3440 | +// A run of log entries folded into one row opens in place to list each entry, a step in from the | ||
| 3441 | +// row's edge, so a fold never hides what happened. | ||
| 3442 | +details.log-group { | ||
| 3443 | + border-bottom: 1px solid var(--border); | ||
| 3444 | + | ||
| 3445 | + &:last-child { | ||
| 3446 | + border-bottom: 0; | ||
| 3447 | + } | ||
| 3448 | + | ||
| 3449 | + > summary.line { | ||
| 3450 | + border-bottom: 0; | ||
| 3451 | + cursor: pointer; | ||
| 3452 | + list-style: none; | ||
| 3453 | + | ||
| 3454 | + &::-webkit-details-marker { | ||
| 3455 | + display: none; | ||
| 3456 | + } | ||
| 3457 | + | ||
| 3458 | + > .count::after { | ||
| 3459 | + content: ""; | ||
| 3460 | + display: inline-block; | ||
| 3461 | + width: 5px; | ||
| 3462 | + height: 5px; | ||
| 3463 | + margin-left: 6px; | ||
| 3464 | + border-right: 1.5px solid currentColor; | ||
| 3465 | + border-bottom: 1.5px solid currentColor; | ||
| 3466 | + transform: translateY(-2px) rotate(45deg); | ||
| 3467 | + } | ||
| 3468 | + } | ||
| 3469 | + | ||
| 3470 | + &[open] > summary.line > .count { | ||
| 3471 | + background: var(--text); | ||
| 3472 | + color: var(--bg); | ||
| 3473 | + | ||
| 3474 | + &::after { | ||
| 3475 | + transform: translateY(1px) rotate(-135deg); | ||
| 3476 | + } | ||
| 3477 | + } | ||
| 3478 | + | ||
| 3479 | + > .log-items { | ||
| 3480 | + margin: 0 18px 8px 30px; | ||
| 3481 | + border-left: 2px solid var(--border); | ||
| 3482 | + | ||
| 3483 | + > .line { | ||
| 3484 | + min-height: 34px; | ||
| 3485 | + padding: 4px 12px; | ||
| 3486 | + border-bottom: 0; | ||
| 3487 | + } | ||
| 3488 | + } | ||
| 3489 | +} | ||
| 3490 | + | ||
| 3491 | +// A reveal in a form of fields opens from the control column, its word on the controls' edge | ||
| 3492 | +// like the switches and the submit beside it. | ||
| 3493 | +.fields > details.reveal > summary.act { | ||
| 3494 | + margin-left: calc(var(--label-w, 130px) + 6px); | ||
| 3495 | +} | ||
| 3496 | + | ||
| 3497 | +@media (max-width: 700px) { | ||
| 3498 | + .fields > details.reveal > summary.act { | ||
| 3499 | + margin-left: -10px; | ||
| 3500 | + } | ||
| 3501 | +} | ||
| 3502 | + | ||
| 3503 | +// A page's own actions beside its title are all the same soft pill as Edit profile or Run | ||
| 3504 | +// workflow, whether the action is a link, a form's button or a reveal's word; a dangerous one | ||
| 3505 | +// keeps its red word on the pill. What opens from a reveal keeps its own kit. | ||
| 3506 | +.head-title > :is(a.act, button.act), | ||
| 3507 | +.head-title > form.act-form > button.act, | ||
| 3508 | +.head-title > details.reveal > summary.act { | ||
| 3509 | + display: inline-flex; | ||
| 3510 | + align-items: center; | ||
| 3511 | + box-sizing: border-box; | ||
| 3512 | + height: var(--control-h); | ||
| 3513 | + padding: 0 18px; | ||
| 3514 | + border: 0; | ||
| 3515 | + border-radius: 19px; | ||
| 3516 | + background: var(--surface-2); | ||
| 3517 | + color: var(--text); | ||
| 3518 | + font-size: 15px; | ||
| 3519 | + font-weight: 600; | ||
| 3520 | + line-height: 1; | ||
| 3521 | + text-decoration: none; | ||
| 3522 | + | ||
| 3523 | + &:hover { | ||
| 3524 | + background: color-mix(in oklab, var(--surface-2) 88%, var(--text)); | ||
| 3525 | + color: var(--text); | ||
| 3526 | + text-decoration: none; | ||
| 3527 | + } | ||
| 3528 | + | ||
| 3529 | + &.danger, | ||
| 3530 | + &.danger:hover { | ||
| 3531 | + color: var(--bad); | ||
| 3532 | + } | ||
| 3533 | +} | ||
| 3534 | + | ||
| 3535 | +// A choice whose options are places (an import's source) reads exactly like one of radios. | ||
| 3536 | +.choice.choice > a { | ||
| 3537 | + display: inline-flex; | ||
| 3538 | + align-items: center; | ||
| 3539 | + height: 32px; | ||
| 3540 | + padding: 0 16px; | ||
| 3541 | + border-radius: 16px; | ||
| 3542 | + color: var(--muted); | ||
| 3543 | + font-size: 14px; | ||
| 3544 | + font-weight: 500; | ||
| 3545 | + line-height: 1; | ||
| 3546 | + text-decoration: none; | ||
| 3547 | + white-space: nowrap; | ||
| 3548 | + | ||
| 3549 | + &:hover { | ||
| 3550 | + color: var(--text); | ||
| 3551 | + text-decoration: none; | ||
| 3552 | + } | ||
| 3553 | + | ||
| 3554 | + &[aria-current="page"] { | ||
| 3555 | + background: var(--surface); | ||
| 3556 | + box-shadow: 0 0 0 1px var(--border); | ||
| 3557 | + color: var(--text); | ||
| 3558 | + } | ||
| 3559 | + | ||
| 3560 | + &:focus-visible { | ||
| 3561 | + outline: 2px solid var(--focus); | ||
| 3562 | + outline-offset: -2px; | ||
| 3563 | + } | ||
| 3564 | +} | ||
| 3565 | + | ||
| 3566 | +// In a rail the search takes the rail's width, its options on the line under it. | ||
| 3567 | +.rail .list-find { | ||
| 3568 | + display: flex; | ||
| 3569 | + width: 100%; | ||
| 3570 | + | ||
| 3571 | + &.list-find .plain-search { | ||
| 3572 | + flex: 1 1 100%; | ||
| 3573 | + width: auto; | ||
| 3574 | + } | ||
| 3575 | +} | ||
style/_one_people.scssmodified+54 -0
| @@ -351,3 +351,57 @@ | |||
| 351 | } | 351 | } |
| 352 | } | 352 | } |
| 353 | } | 353 | } |
| 354 | + | ||
| 355 | +// The files row reads like every field: its word in the label column, then the files as one | ||
| 356 | +// choice switch in the kit's own look, Add file and the count beside it. | ||
| 357 | +.snippet-form > .snippet-files { | ||
| 358 | + padding-left: 0; | ||
| 359 | + | ||
| 360 | + > .snippet-files-label { | ||
| 361 | + order: 0; | ||
| 362 | + flex: 0 0 var(--label-w, 130px); | ||
| 363 | + margin-right: 8px; | ||
| 364 | + color: var(--text); | ||
| 365 | + font-size: 15px; | ||
| 366 | + font-weight: 500; | ||
| 367 | + } | ||
| 368 | + | ||
| 369 | + .snippet-tabs { | ||
| 370 | + gap: 0; | ||
| 371 | + padding: 3px; | ||
| 372 | + border-radius: 19px; | ||
| 373 | + background: var(--surface-2); | ||
| 374 | + } | ||
| 375 | + | ||
| 376 | + .snippet-tab { | ||
| 377 | + height: 32px; | ||
| 378 | + padding: 0 16px; | ||
| 379 | + border-radius: 16px; | ||
| 380 | + line-height: 1; | ||
| 381 | + font-family: inherit; | ||
| 382 | + font-size: 14px; | ||
| 383 | + font-weight: 500; | ||
| 384 | + } | ||
| 385 | + | ||
| 386 | + .snippet-tab-radio:checked + .snippet-tab { | ||
| 387 | + background: var(--surface); | ||
| 388 | + box-shadow: 0 0 0 1px var(--border); | ||
| 389 | + color: var(--text); | ||
| 390 | + font-weight: 500; | ||
| 391 | + } | ||
| 392 | + | ||
| 393 | + .snippet-tab-radio:focus-visible + .snippet-tab { | ||
| 394 | + outline: 2px solid var(--focus); | ||
| 395 | + outline-offset: 1px; | ||
| 396 | + } | ||
| 397 | +} | ||
| 398 | + | ||
| 399 | +@media (max-width: 700px) { | ||
| 400 | + .snippet-form > .snippet-files > .snippet-files-label { | ||
| 401 | + flex-basis: 100%; | ||
| 402 | + } | ||
| 403 | +} | ||
| 404 | + | ||
| 405 | +.snippet-form > .snippet-files > fieldset { | ||
| 406 | + margin-left: 0; | ||
| 407 | +} | ||