The sidebar and dashboard are gone: / opens your profile, which holds the contribution calendar and tabs for Repositories (with New repository), Snippets, Stars, Packages and Organizations (with New organization), and a sidebar stays only on section pages
Browse files at this commitc812504a9bcc48c0950d1f69f878aeaff146e97fParent: 2596bea- feat
- the sidebar and dashboard are gone: / opens your profile, which holds the contribution calendar and tabs for Repositories (with New repository), Snippets, Stars, Packages and Organizations (with New organization), and a sidebar stays only on section pages
- the profile corner is a floating panel, bottom left by default, that can be dragged anywhere and reset with a double click
- organizations get a real profile with New repository, Members, Teams and Settings, and their settings take a display name and an avatar
- failed bulk imports can be retried from a checklist with a token
- a signed-in user's tree width, panel position, diff view and banner dismissal are stored in the database (migration 0069)
- fix
- a form the server refuses keeps its address, so a live refresh no longer lands on a 405 page after a wrong repo transfer
- the Recent imports card matches the import form's width and no longer touches it
- deleting a repo returns to the owner's Repositories tab with its notice
50 changed files +1708 -1357
- crates/forge-core/migrations/0069_user_prefs.sql +11 -0
- crates/forge-core/src/store/migrate.rs +1 -0
- crates/forge-core/src/store/mod.rs +1 -0
- crates/forge-core/src/store/snippets.rs +40 -13
- crates/forge-core/src/store/user_delete.rs +1 -0
- crates/forge-core/src/store/user_prefs.rs +55 -0
- crates/forge-web/assets/nav.js +179 -28
- crates/forge-web/src/boot.rs +1 -0
- crates/forge-web/src/i18n/migrate.rs +15 -0
- crates/forge-web/src/i18n/misc.rs +0 -40
- crates/forge-web/src/i18n/orgs.rs +26 -18
- crates/forge-web/src/importer/mod.rs +1 -0
- crates/forge-web/src/importer/tests.rs +60 -1
- crates/forge-web/src/live.rs +1 -1
- crates/forge-web/src/pages/banner.rs +24 -9
- crates/forge-web/src/pages/commit.rs +2 -1
- crates/forge-web/src/pages/compare.rs +2 -1
- crates/forge-web/src/pages/dashboard.rs +0 -401
- crates/forge-web/src/pages/home.rs +47 -0
- crates/forge-web/src/pages/import.rs +191 -13
- crates/forge-web/src/pages/mod.rs +3 -1
- crates/forge-web/src/pages/new_repo.rs +18 -2
- crates/forge-web/src/pages/notifications.rs +5 -5
- crates/forge-web/src/pages/org_ctx.rs +2 -0
- crates/forge-web/src/pages/org_settings.rs +189 -47
- crates/forge-web/src/pages/palette.rs +2 -4
- crates/forge-web/src/pages/profile.rs +228 -17
- crates/forge-web/src/pages/profile_calendar.rs +92 -0
- crates/forge-web/src/pages/pull_files.rs +1 -1
- crates/forge-web/src/pages/repo.rs +1 -1
- crates/forge-web/src/pages/repo_settings.rs +7 -6
- crates/forge-web/src/pages/settings_profile.rs +10 -4
- crates/forge-web/src/pages/setup.rs +4 -4
- crates/forge-web/src/pages/shell_events.rs +8 -10
- crates/forge-web/src/pages/snippets.rs +35 -22
- crates/forge-web/src/pages/user_prefs.rs +158 -0
- crates/forge-web/src/post_update.rs +2 -2
- crates/forge-web/src/test_support.rs +2 -1
- crates/forge-web/src/views/diff.rs +45 -21
- crates/forge-web/src/views/heatmap.rs +10 -8
- crates/forge-web/src/views/mod.rs +74 -200
- crates/forge-web/src/views/repo_list.rs +8 -1
- crates/forge-web/tests/e2e/browse_e2e.rs +3 -11
- crates/forge-web/tests/e2e/orgs_ui_e2e.rs +5 -2
- crates/forge-web/tests/e2e/repo_settings_e2e.rs +10 -10
- style/_dashboard.scss +0 -273
- style/_heatmap.scss +1 -1
- style/_import.scss +6 -0
- style/_shell.scss +101 -176
- style/main.scss +20 -1
crates/forge-core/migrations/0069_user_prefs.sqladded+11 -0
| @@ -0,0 +1,11 @@ | |||
| 1 | +-- Account preferences that do not fit a column of `users`: the tree width, the profile corner's | ||
| 2 | +-- position and similar. One row per user and key; the web layer decides the keys and values, and | ||
| 3 | +-- a value of "" never reaches here (it deletes the row). Applied by store/migrate.rs. | ||
| 4 | + | ||
| 5 | +CREATE TABLE user_prefs ( | ||
| 6 | + user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
| 7 | + key TEXT NOT NULL, | ||
| 8 | + value TEXT NOT NULL, | ||
| 9 | + updated_at TEXT NOT NULL, | ||
| 10 | + PRIMARY KEY (user_id, key) | ||
| 11 | +); | ||
crates/forge-core/src/store/migrate.rsmodified+1 -0
| @@ -108,6 +108,7 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ | |||
| 108 | (66, include_str!("../../migrations/0066_session_ip.sql")), | 108 | (66, include_str!("../../migrations/0066_session_ip.sql")), |
| 109 | (67, include_str!("../../migrations/0067_coauthored_commits.sql")), | 109 | (67, include_str!("../../migrations/0067_coauthored_commits.sql")), |
| 110 | (68, include_str!("../../migrations/0068_ci_jobs_runner.sql")), | 110 | (68, include_str!("../../migrations/0068_ci_jobs_runner.sql")), |
| 111 | + (69, include_str!("../../migrations/0069_user_prefs.sql")), | ||
| 111 | ]; | 112 | ]; |
| 112 | 113 | ||
| 113 | /// The highest migration version this binary knows about. | 114 | /// The highest migration version this binary knows about. |
crates/forge-core/src/store/mod.rsmodified+1 -0
| @@ -48,6 +48,7 @@ pub mod suspension; | |||
| 48 | pub mod transfers; | 48 | pub mod transfers; |
| 49 | pub mod ui_prefs; | 49 | pub mod ui_prefs; |
| 50 | pub mod user_delete; | 50 | pub mod user_delete; |
| 51 | +pub mod user_prefs; | ||
| 51 | pub mod web_push; | 52 | pub mod web_push; |
| 52 | pub mod webhooks; | 53 | pub mod webhooks; |
| 53 | pub mod wiki; | 54 | pub mod wiki; |
crates/forge-core/src/store/snippets.rsmodified+40 -13
| @@ -202,6 +202,20 @@ fn map_snippet(row: &turso::Row) -> Result<Snippet> { | |||
| 202 | }) | 202 | }) |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | +/// One row of the summary queries: id, owner name, title, visibility, update stamp, file count. | ||
| 206 | +fn summary_row(row: &turso::Row) -> Result<SnippetSummary> { | ||
| 207 | + let visibility = col_text(row, 3)?; | ||
| 208 | + Ok(SnippetSummary { | ||
| 209 | + id: col_text(row, 0)?, | ||
| 210 | + owner_name: col_text(row, 1)?, | ||
| 211 | + title: col_text(row, 2)?, | ||
| 212 | + visibility: SnippetVisibility::parse(&visibility) | ||
| 213 | + .ok_or_else(|| Error::Database(format!("unknown snippet visibility {visibility}")))?, | ||
| 214 | + updated_at: col_text(row, 4)?, | ||
| 215 | + file_count: u64::try_from(col_int(row, 5)?).unwrap_or(0), | ||
| 216 | + }) | ||
| 217 | +} | ||
| 218 | + | ||
| 205 | fn map_file(row: &turso::Row) -> Result<SnippetFile> { | 219 | fn map_file(row: &turso::Row) -> Result<SnippetFile> { |
| 206 | Ok(SnippetFile { | 220 | Ok(SnippetFile { |
| 207 | name: col_text(row, 0)?, | 221 | name: col_text(row, 0)?, |
| @@ -411,19 +425,32 @@ impl Store { | |||
| 411 | WHERE s.visibility = 'public' OR s.owner_id = ?1 \ | 425 | WHERE s.visibility = 'public' OR s.owner_id = ?1 \ |
| 412 | ORDER BY s.updated_at DESC, s.id DESC LIMIT ?2", | 426 | ORDER BY s.updated_at DESC, s.id DESC LIMIT ?2", |
| 413 | (viewer_id.unwrap_or("").to_string(), LIST_LIMIT), | 427 | (viewer_id.unwrap_or("").to_string(), LIST_LIMIT), |
| 414 | - |row| { | 428 | + summary_row, |
| 415 | - let visibility = col_text(row, 3)?; | 429 | + ) |
| 416 | - Ok(SnippetSummary { | 430 | + .await |
| 417 | - id: col_text(row, 0)?, | 431 | + } |
| 418 | - owner_name: col_text(row, 1)?, | 432 | + |
| 419 | - title: col_text(row, 2)?, | 433 | + /// The snippets `owner_id` owns that the viewer can list: their public ones, and all of them |
| 420 | - visibility: SnippetVisibility::parse(&visibility).ok_or_else(|| { | 434 | + /// when the viewer is the owner. Unlisted ones are left out, as on `list_snippets`. Newest first. |
| 421 | - Error::Database(format!("unknown snippet visibility {visibility}")) | 435 | + pub async fn list_owner_snippets( |
| 422 | - })?, | 436 | + &self, |
| 423 | - updated_at: col_text(row, 4)?, | 437 | + owner_id: &str, |
| 424 | - file_count: u64::try_from(col_int(row, 5)?).unwrap_or(0), | 438 | + viewer_id: Option<&str>, |
| 425 | - }) | 439 | + ) -> Result<Vec<SnippetSummary>> { |
| 426 | - }, | 440 | + let conn = self.read_conn().await; |
| 441 | + fetch_all( | ||
| 442 | + &conn, | ||
| 443 | + "SELECT s.id, u.username, s.title, s.visibility, s.updated_at, \ | ||
| 444 | + (SELECT COUNT(*) FROM snippet_files f WHERE f.snippet_id = s.id) \ | ||
| 445 | + FROM snippets s JOIN users u ON u.id = s.owner_id \ | ||
| 446 | + WHERE s.owner_id = ?1 AND (s.visibility = 'public' OR s.owner_id = ?2) \ | ||
| 447 | + ORDER BY s.updated_at DESC, s.id DESC LIMIT ?3", | ||
| 448 | + ( | ||
| 449 | + owner_id.to_string(), | ||
| 450 | + viewer_id.unwrap_or("").to_string(), | ||
| 451 | + LIST_LIMIT, | ||
| 452 | + ), | ||
| 453 | + summary_row, | ||
| 427 | ) | 454 | ) |
| 428 | .await | 455 | .await |
| 429 | } | 456 | } |
crates/forge-core/src/store/user_delete.rsmodified+1 -0
| @@ -138,6 +138,7 @@ const REMOVED: &[(&str, &str, &str)] = &[ | |||
| 138 | ), | 138 | ), |
| 139 | ("admin notifications", "admin_notifications", "user_id"), | 139 | ("admin notifications", "admin_notifications", "user_id"), |
| 140 | ("reactions", "reactions", "user_id"), | 140 | ("reactions", "reactions", "user_id"), |
| 141 | + ("preferences", "user_prefs", "user_id"), | ||
| 141 | ("review requests", "review_requests", "reviewer_id"), | 142 | ("review requests", "review_requests", "reviewer_id"), |
| 142 | ]; | 143 | ]; |
| 143 | 144 | ||
crates/forge-core/src/store/user_prefs.rsadded+55 -0
| @@ -0,0 +1,55 @@ | |||
| 1 | +//! Account preferences that are not columns of `users`: one text value per user and key, in | ||
| 2 | +//! `user_prefs` (migration 0069). The web layer decides which keys exist and what each value may | ||
| 3 | +//! be; this store only keeps the rows. Rows go with the user (ON DELETE CASCADE). | ||
| 4 | + | ||
| 5 | +use std::collections::HashMap; | ||
| 6 | + | ||
| 7 | +use super::{Store, col_text, db_err, fetch_all}; | ||
| 8 | +use crate::error::Result; | ||
| 9 | +use crate::time::now_stamp; | ||
| 10 | + | ||
| 11 | +impl Store { | ||
| 12 | + /// All of a user's preferences as `key -> value`. | ||
| 13 | + pub async fn user_prefs(&self, user_id: &str) -> Result<HashMap<String, String>> { | ||
| 14 | + let conn = self.read_conn().await; | ||
| 15 | + let rows = fetch_all( | ||
| 16 | + &conn, | ||
| 17 | + "SELECT key, value FROM user_prefs WHERE user_id = ?1", | ||
| 18 | + (user_id.to_string(),), | ||
| 19 | + |row| Ok((col_text(row, 0)?, col_text(row, 1)?)), | ||
| 20 | + ) | ||
| 21 | + .await?; | ||
| 22 | + Ok(rows.into_iter().collect()) | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /// Stores `value` under `key` for the user, replacing an earlier value. | ||
| 26 | + pub async fn set_user_pref(&self, user_id: &str, key: &str, value: &str) -> Result<()> { | ||
| 27 | + let conn = self.inner.conn.lock().await; | ||
| 28 | + conn.execute( | ||
| 29 | + "INSERT INTO user_prefs (user_id, key, value, updated_at) VALUES (?1, ?2, ?3, ?4) \ | ||
| 30 | + ON CONFLICT (user_id, key) DO UPDATE SET \ | ||
| 31 | + value = excluded.value, updated_at = excluded.updated_at", | ||
| 32 | + ( | ||
| 33 | + user_id.to_string(), | ||
| 34 | + key.to_string(), | ||
| 35 | + value.to_string(), | ||
| 36 | + now_stamp(), | ||
| 37 | + ), | ||
| 38 | + ) | ||
| 39 | + .await | ||
| 40 | + .map_err(db_err)?; | ||
| 41 | + Ok(()) | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /// Removes one preference. A key the user never set is not an error. | ||
| 45 | + pub async fn delete_user_pref(&self, user_id: &str, key: &str) -> Result<()> { | ||
| 46 | + let conn = self.inner.conn.lock().await; | ||
| 47 | + conn.execute( | ||
| 48 | + "DELETE FROM user_prefs WHERE user_id = ?1 AND key = ?2", | ||
| 49 | + (user_id.to_string(), key.to_string()), | ||
| 50 | + ) | ||
| 51 | + .await | ||
| 52 | + .map_err(db_err)?; | ||
| 53 | + Ok(()) | ||
| 54 | + } | ||
| 55 | +} | ||
crates/forge-web/assets/nav.jsmodified+179 -28
| @@ -17,6 +17,7 @@ | |||
| 17 | var inFlight = 0; // requests on the wire, drives aria-busy | 17 | var inFlight = 0; // requests on the wire, drives aria-busy |
| 18 | var pending = new WeakSet(); // forms with a request on the wire: a second submit is ignored | 18 | var pending = new WeakSet(); // forms with a request on the wire: a second submit is ignored |
| 19 | var queued = new WeakSet(); // forms that changed while pending: submitted again once it completes | 19 | var queued = new WeakSet(); // forms that changed while pending: submitted again once it completes |
| 20 | + var heldForm = false; // a rejected form is on screen; see load() | ||
| 20 | var shown = location.pathname + location.search; | 21 | var shown = location.pathname + location.search; |
| 21 | var GET_INIT = { headers: { accept: 'text/html' } }; | 22 | var GET_INIT = { headers: { accept: 'text/html' } }; |
| 22 | 23 | ||
| @@ -427,6 +428,12 @@ | |||
| 427 | } | 428 | } |
| 428 | var dest = new URL(res.url.href); | 429 | var dest = new URL(res.url.href); |
| 429 | dest.hash = o.dest.hash; | 430 | dest.hash = o.dest.hash; |
| 431 | + // A form the server refused comes back as a page under the POST's URL, which may have no GET. | ||
| 432 | + // The address stays on the page the form was sent from, and live refreshes wait, because one | ||
| 433 | + // would replace the error with a fresh page. The next navigation ends the wait. | ||
| 434 | + var refused = o.post && !res.redirected; | ||
| 435 | + if (refused) { dest = new URL(location.href); } | ||
| 436 | + if (o.how !== 'live') { heldForm = refused; } | ||
| 430 | // A live refresh that lands on another path (a revoked session sent to the login page) is a | 437 | // A live refresh that lands on another path (a revoked session sent to the login page) is a |
| 431 | // navigation: it gets a history entry, so the address bar shows where the page now is. | 438 | // navigation: it gets a history entry, so the address bar shows where the page now is. |
| 432 | var how = o.how === 'live' && res.url.pathname !== o.target.pathname ? 'nav' : o.how; | 439 | var how = o.how === 'live' && res.url.pathname !== o.target.pathname ? 'nav' : o.how; |
| @@ -564,8 +571,8 @@ | |||
| 564 | 571 | ||
| 565 | // Every page holds one stream to /-/shell/events (`/-/alive` for a page from before a deploy, and for | 572 | // Every page holds one stream to /-/shell/events (`/-/alive` for a page from before a deploy, and for |
| 566 | // an anonymous visitor the same alive events). Its error means the server, or the proxy in front of | 573 | // an anonymous visitor the same alive events). Its error means the server, or the proxy in front of |
| 567 | - // it, is down; its open means it is back. Signed-in viewers also get `unread` (the inbox count), | 574 | + // it, is down; its open means it is back. Signed-in viewers also get `unread` (the inbox count) and |
| 568 | - // `activity` (the live strip and ring) and `side` (the sidebar's repo list) on the same connection. | 575 | + // `activity` (the live strip and ring) on the same connection. |
| 569 | // A `theme` event carries the signed-in user's appearance as `name=value` pairs joined by `;` | 576 | // A `theme` event carries the signed-in user's appearance as `name=value` pairs joined by `;` |
| 570 | // (the `<html>` attributes). An empty value removes the attribute. Only data-* names are applied. | 577 | // (the `<html>` attributes). An empty value removes the attribute. Only data-* names are applied. |
| 571 | function applyAppearance(data) { | 578 | function applyAppearance(data) { |
| @@ -613,9 +620,7 @@ | |||
| 613 | // The inbox count changed (see `unreadChanged` above). | 620 | // The inbox count changed (see `unreadChanged` above). |
| 614 | unread: unreadChanged, | 621 | unread: unreadChanged, |
| 615 | // The viewer's activity changed: the strip, ring and chips are fetched again. | 622 | // The viewer's activity changed: the strip, ring and chips are fetched again. |
| 616 | - activity: function () { refreshActivity(); }, | 623 | + activity: function () { refreshActivity(); } |
| 617 | - // The sidebar's repo list changed (the sidebar is re-rendered with the page). | ||
| 618 | - side: sideChanged | ||
| 619 | }); | 624 | }); |
| 620 | document.addEventListener('visibilitychange', function () { wake(false); }); | 625 | document.addEventListener('visibilitychange', function () { wake(false); }); |
| 621 | document.addEventListener('resume', function () { wake(true); }); | 626 | document.addEventListener('resume', function () { wake(true); }); |
| @@ -643,11 +648,11 @@ | |||
| 643 | } | 648 | } |
| 644 | 649 | ||
| 645 | // Dropdown menus: the <details> that float over the page (avatar menu, branch selector, clone | 650 | // Dropdown menus: the <details> that float over the page (avatar menu, branch selector, clone |
| 646 | - // popover, phone menu, profile corner). Inline disclosures are not listed: a click outside leaves them open. | 651 | + // popover, section menu, profile corner). Inline disclosures are not listed: a click outside leaves them open. |
| 647 | var DROPDOWN = 'details.menu, details.ref-select, details.clone, details.nav-toggle, details.corner, details.strip-runs'; | 652 | var DROPDOWN = 'details.menu, details.ref-select, details.clone, details.nav-toggle, details.corner, details.strip-runs'; |
| 648 | 653 | ||
| 649 | - // Closes every open dropdown that does not contain `from` (pass null to close them all). The corner | 654 | + // Closes every open dropdown that does not contain `from` (pass null to close them all). A click |
| 650 | - // sits inside the phone menu, so a click in the corner keeps the phone menu open too. | 655 | + // inside the floating corner keeps its own menu open. |
| 651 | function closeDropdowns(from) { | 656 | function closeDropdowns(from) { |
| 652 | document.querySelectorAll(DROPDOWN).forEach(function (d) { | 657 | document.querySelectorAll(DROPDOWN).forEach(function (d) { |
| 653 | if (d.open && !(from && d.contains(from))) { d.open = false; } | 658 | if (d.open && !(from && d.contains(from))) { d.open = false; } |
| @@ -706,6 +711,138 @@ | |||
| 706 | closeDropdowns(e.target && e.target.nodeType === 1 ? e.target : null); | 711 | closeDropdowns(e.target && e.target.nodeType === 1 ? e.target : null); |
| 707 | }, false); | 712 | }, false); |
| 708 | 713 | ||
| 714 | + // The profile corner can be dragged anywhere on the window. A press records its start; it becomes a | ||
| 715 | + // drag after CORNER_SLOP px of movement, and then the panel follows the pointer, clamped to the | ||
| 716 | + // window. The released position is kept as fractions of the free space, so it holds at any size. | ||
| 717 | + var CORNER_SLOP = 5; | ||
| 718 | + var cornerPress = null; // { el, id, x, y, left, top, dragging } from a press to its release | ||
| 719 | + var cornerSwallow = false; // the click that ends a drag must not open the menu or the bell | ||
| 720 | + | ||
| 721 | + function parseCorner(text) { | ||
| 722 | + var parts = String(text || '').split(','); | ||
| 723 | + if (parts.length !== 2) { return null; } | ||
| 724 | + var x = parseFloat(parts[0]), y = parseFloat(parts[1]); | ||
| 725 | + if (!isFinite(x) || !isFinite(y)) { return null; } | ||
| 726 | + return [Math.min(1, Math.max(0, x)), Math.min(1, Math.max(0, y))]; | ||
| 727 | + } | ||
| 728 | + // [x, y] fractions of the stored position, or null for the default corner. Kept current by drags and resets. | ||
| 729 | + var cornerSaved = parseCorner(document.body.dataset.cornerPos); | ||
| 730 | + | ||
| 731 | + // Registered before the bell's click listener below, so it runs first and stops the click that | ||
| 732 | + // follows a drag once. | ||
| 733 | + window.addEventListener('click', function (e) { | ||
| 734 | + if (!cornerSwallow) { return; } | ||
| 735 | + cornerSwallow = false; | ||
| 736 | + e.preventDefault(); | ||
| 737 | + e.stopImmediatePropagation(); | ||
| 738 | + }, true); | ||
| 739 | + | ||
| 740 | + function cornerEl() { return document.querySelector('.corner-float'); } | ||
| 741 | + | ||
| 742 | + // The menu opens down when the panel is in the top half of the window, and anchors to the right | ||
| 743 | + // edge when the panel is in the right half. The default corner (no attribute) opens up, as before. | ||
| 744 | + function cornerDirection(el, left, top, w, h) { | ||
| 745 | + if (top + h / 2 < window.innerHeight / 2) { el.setAttribute('data-open', 'down'); } else { el.removeAttribute('data-open'); } | ||
| 746 | + if (left + w / 2 > window.innerWidth / 2) { el.setAttribute('data-side', 'right'); } else { el.removeAttribute('data-side'); } | ||
| 747 | + } | ||
| 748 | + | ||
| 749 | + // Places the panel at (left, top) in px, clamped so the whole panel stays in the window. | ||
| 750 | + function cornerPlace(el, left, top) { | ||
| 751 | + var w = el.offsetWidth, h = el.offsetHeight; | ||
| 752 | + left = Math.max(0, Math.min(left, window.innerWidth - w)); | ||
| 753 | + top = Math.max(0, Math.min(top, window.innerHeight - h)); | ||
| 754 | + el.style.left = left + 'px'; | ||
| 755 | + el.style.top = top + 'px'; | ||
| 756 | + el.style.right = 'auto'; | ||
| 757 | + el.style.bottom = 'auto'; | ||
| 758 | + cornerDirection(el, left, top, w, h); | ||
| 759 | + } | ||
| 760 | + | ||
| 761 | + // Puts the panel where the stored position says, or in the default corner. It does nothing while a | ||
| 762 | + // drag runs, so a re-render or a resize does not pull the panel from under the pointer. | ||
| 763 | + function cornerApply() { | ||
| 764 | + var el = cornerEl(); | ||
| 765 | + if (!el || (cornerPress && cornerPress.dragging)) { return; } | ||
| 766 | + if (cornerSaved) { | ||
| 767 | + cornerPlace(el, cornerSaved[0] * (window.innerWidth - el.offsetWidth), cornerSaved[1] * (window.innerHeight - el.offsetHeight)); | ||
| 768 | + return; | ||
| 769 | + } | ||
| 770 | + el.style.left = ''; | ||
| 771 | + el.style.top = ''; | ||
| 772 | + el.style.right = ''; | ||
| 773 | + el.style.bottom = ''; | ||
| 774 | + var r = el.getBoundingClientRect(); | ||
| 775 | + cornerDirection(el, r.left, r.top, el.offsetWidth, el.offsetHeight); | ||
| 776 | + } | ||
| 777 | + | ||
| 778 | + // Saves one account preference through /-/prefs, signed in only (the CSRF token comes from the | ||
| 779 | + // panel). Saves go one after another, and `read` gives the value at the moment of sending, so the | ||
| 780 | + // last one sent holds the newest value. A failure is ignored: the next load shows what the server has. | ||
| 781 | + var prefsChain = Promise.resolve(); | ||
| 782 | + function prefSave(key, read) { | ||
| 783 | + prefsChain = prefsChain.then(function () { | ||
| 784 | + var el = document.querySelector('.corner-float[data-prefs-csrf]'); | ||
| 785 | + var body = new URLSearchParams({ csrf: el ? el.getAttribute('data-prefs-csrf') : '', key: key, value: read() }); | ||
| 786 | + return fetch('/-/prefs', { method: 'POST', credentials: 'same-origin', body: body }); | ||
| 787 | + }).catch(function () { }); | ||
| 788 | + } | ||
| 789 | + | ||
| 790 | + document.addEventListener('pointerdown', function (e) { | ||
| 791 | + cornerSwallow = false; | ||
| 792 | + var el = e.target && e.target.closest ? e.target.closest('.corner-float') : null; | ||
| 793 | + if (!el || e.button !== 0) { cornerPress = null; return; } | ||
| 794 | + var r = el.getBoundingClientRect(); | ||
| 795 | + cornerPress = { el: el, id: e.pointerId, x: e.clientX, y: e.clientY, left: r.left, top: r.top, dragging: false }; | ||
| 796 | + }); | ||
| 797 | + | ||
| 798 | + document.addEventListener('pointermove', function (e) { | ||
| 799 | + var p = cornerPress; | ||
| 800 | + if (!p || e.pointerId !== p.id) { return; } | ||
| 801 | + if (!p.dragging) { | ||
| 802 | + if (Math.hypot(e.clientX - p.x, e.clientY - p.y) < CORNER_SLOP) { return; } | ||
| 803 | + p.dragging = true; | ||
| 804 | + try { p.el.setPointerCapture(p.id); } catch (err) { } | ||
| 805 | + p.el.classList.add('dragging'); | ||
| 806 | + } | ||
| 807 | + cornerPlace(p.el, p.left + e.clientX - p.x, p.top + e.clientY - p.y); | ||
| 808 | + }); | ||
| 809 | + | ||
| 810 | + function cornerEnd(e) { | ||
| 811 | + var p = cornerPress; | ||
| 812 | + if (!p || e.pointerId !== p.id) { return; } | ||
| 813 | + cornerPress = null; | ||
| 814 | + if (!p.dragging) { return; } | ||
| 815 | + p.el.classList.remove('dragging'); | ||
| 816 | + if (e.type === 'pointercancel') { cornerApply(); return; } | ||
| 817 | + cornerSwallow = true; | ||
| 818 | + // A swap that replaced the panel during the drag leaves the new one to the stored position. | ||
| 819 | + if (!p.el.isConnected) { cornerApply(); return; } | ||
| 820 | + var room = { x: window.innerWidth - p.el.offsetWidth, y: window.innerHeight - p.el.offsetHeight }; | ||
| 821 | + var x = room.x > 0 ? Math.round(10000 * (parseFloat(p.el.style.left) || 0) / room.x) / 10000 : 0; | ||
| 822 | + var y = room.y > 0 ? Math.round(10000 * (parseFloat(p.el.style.top) || 0) / room.y) / 10000 : 0; | ||
| 823 | + x = Math.min(1, Math.max(0, x)); | ||
| 824 | + y = Math.min(1, Math.max(0, y)); | ||
| 825 | + cornerSaved = [x, y]; | ||
| 826 | + prefSave('corner_pos', function () { return x + ',' + y; }); | ||
| 827 | + } | ||
| 828 | + document.addEventListener('pointerup', cornerEnd); | ||
| 829 | + document.addEventListener('pointercancel', cornerEnd); | ||
| 830 | + | ||
| 831 | + // A double click on the panel, not on a link or a button, returns it to the default corner. | ||
| 832 | + document.addEventListener('dblclick', function (e) { | ||
| 833 | + var target = e.target; | ||
| 834 | + if (!target || !target.closest || target.closest('a, button, input, select, textarea, summary, label, [role="button"]')) { return; } | ||
| 835 | + var el = target.closest('.corner-float'); | ||
| 836 | + if (!el) { return; } | ||
| 837 | + cornerSaved = null; | ||
| 838 | + prefSave('corner_pos', function () { return ''; }); | ||
| 839 | + cornerApply(); | ||
| 840 | + }); | ||
| 841 | + | ||
| 842 | + document.addEventListener('forge:swapped', cornerApply); | ||
| 843 | + window.addEventListener('resize', cornerApply); | ||
| 844 | + cornerApply(); | ||
| 845 | + | ||
| 709 | // The bell beside the profile corner opens a popover of the newest notifications instead of going | 846 | // The bell beside the profile corner opens a popover of the newest notifications instead of going |
| 710 | // to the inbox. A plain click toggles it; with a modifier or a middle click the link's own | 847 | // to the inbox. A plain click toggles it; with a modifier or a middle click the link's own |
| 711 | // behaviour stays. The Popover API light-dismisses it and Escape closes it. Its list is fetched | 848 | // behaviour stays. The Popover API light-dismisses it and Escape closes it. Its list is fetched |
| @@ -718,12 +855,20 @@ | |||
| 718 | 855 | ||
| 719 | // Under the bell, opening upward: the popover's bottom sits 6px above the bell's top, and its left | 856 | // Under the bell, opening upward: the popover's bottom sits 6px above the bell's top, and its left |
| 720 | // edge follows the bell but stays inside the viewport. | 857 | // edge follows the bell but stays inside the viewport. |
| 858 | + // When the panel sits in the top half (data-open="down" on it), the popover opens below the bell. | ||
| 721 | function placePeek(bell, pop) { | 859 | function placePeek(bell, pop) { |
| 722 | if (!bell) { return; } | 860 | if (!bell) { return; } |
| 723 | var r = bell.getBoundingClientRect(); | 861 | var r = bell.getBoundingClientRect(); |
| 724 | var left = Math.max(8, Math.min(r.left, window.innerWidth - pop.offsetWidth - 8)); | 862 | var left = Math.max(8, Math.min(r.left, window.innerWidth - pop.offsetWidth - 8)); |
| 725 | pop.style.left = left + 'px'; | 863 | pop.style.left = left + 'px'; |
| 726 | - pop.style.bottom = (window.innerHeight - r.top + 6) + 'px'; | 864 | + var corner = bell.closest('.corner-float'); |
| 865 | + if (corner && corner.getAttribute('data-open') === 'down') { | ||
| 866 | + pop.style.top = (r.bottom + 6) + 'px'; | ||
| 867 | + pop.style.bottom = 'auto'; | ||
| 868 | + } else { | ||
| 869 | + pop.style.top = 'auto'; | ||
| 870 | + pop.style.bottom = (window.innerHeight - r.top + 6) + 'px'; | ||
| 871 | + } | ||
| 727 | } | 872 | } |
| 728 | 873 | ||
| 729 | // Fills the popover's list with the server's fragment. A reader who closed it meanwhile, or a newer | 874 | // Fills the popover's list with the server's fragment. A reader who closed it meanwhile, or a newer |
| @@ -793,7 +938,7 @@ | |||
| 793 | } | 938 | } |
| 794 | }, true); | 939 | }, true); |
| 795 | 940 | ||
| 796 | - // A page swap replaces the sidebar; an open popover goes with the page it was opened on. | 941 | + // A page swap re-renders the page and its corner; an open popover goes with the page it was opened on. |
| 797 | document.addEventListener('forge:swapped', function () { | 942 | document.addEventListener('forge:swapped', function () { |
| 798 | document.querySelectorAll('.bell-pop').forEach(function (pop) { | 943 | document.querySelectorAll('.bell-pop').forEach(function (pop) { |
| 799 | try { pop.hidePopover(); } catch (err) { } | 944 | try { pop.hidePopover(); } catch (err) { } |
| @@ -803,17 +948,33 @@ | |||
| 803 | // Repo home resize: a drag on the separator between the file tree and the README sets the tree's | 948 | // Repo home resize: a drag on the separator between the file tree and the README sets the tree's |
| 804 | // width, the --tree-w property of the .repo-home grid. The width is kept in localStorage and applied | 949 | // width, the --tree-w property of the .repo-home grid. The width is kept in localStorage and applied |
| 805 | // to each repo home on load and after every swap. The README takes the rest of the row. | 950 | // to each repo home on load and after every swap. The README takes the rest of the row. |
| 806 | - var TREE_KEY = 'forge-tree-w'; | 951 | + var TREE_KEY = 'forge-tree-w'; // signed-out visitors keep the width in localStorage |
| 952 | + // Signed in, the width is the account's tree_width preference. The variable starts from the page's | ||
| 953 | + // data-tree-w and follows every change, so a swap never reads back an older value. | ||
| 954 | + var signedIn = document.body.dataset.signedIn === 'true'; | ||
| 955 | + var treeAccount = parseFloat(document.body.dataset.treeW) || 0; | ||
| 956 | + var treeTimer = null; | ||
| 807 | var TREE_MIN = 220; // px, the narrowest the tree goes | 957 | var TREE_MIN = 220; // px, the narrowest the tree goes |
| 808 | var README_MIN = 360; // px, room the drag always leaves for the README | 958 | var README_MIN = 360; // px, room the drag always leaves for the README |
| 809 | var TREE_STEP = 16; // px per arrow key; Shift moves 64px | 959 | var TREE_STEP = 16; // px per arrow key; Shift moves 64px |
| 810 | var treeDrag = null; // { grid, id, x, w, moved } while a pointer drag runs | 960 | var treeDrag = null; // { grid, id, x, w, moved } while a pointer drag runs |
| 811 | 961 | ||
| 812 | function treeLoad() { | 962 | function treeLoad() { |
| 963 | + if (signedIn) { return treeAccount; } | ||
| 813 | try { return parseFloat(localStorage.getItem(TREE_KEY)) || 0; } catch (err) { return 0; } | 964 | try { return parseFloat(localStorage.getItem(TREE_KEY)) || 0; } catch (err) { return 0; } |
| 814 | } | 965 | } |
| 815 | 966 | ||
| 816 | function treeStore(px) { | 967 | function treeStore(px) { |
| 968 | + if (signedIn) { | ||
| 969 | + treeAccount = px ? Math.round(px) : 0; | ||
| 970 | + // One save once the changes settle, not one per step of a drag or a key repeat. | ||
| 971 | + clearTimeout(treeTimer); | ||
| 972 | + treeTimer = setTimeout(function () { | ||
| 973 | + treeTimer = null; | ||
| 974 | + prefSave('tree_width', function () { return treeAccount ? String(treeAccount) : ''; }); | ||
| 975 | + }, 300); | ||
| 976 | + return; | ||
| 977 | + } | ||
| 817 | try { | 978 | try { |
| 818 | if (px) { localStorage.setItem(TREE_KEY, String(Math.round(px))); } else { localStorage.removeItem(TREE_KEY); } | 979 | if (px) { localStorage.setItem(TREE_KEY, String(Math.round(px))); } else { localStorage.removeItem(TREE_KEY); } |
| 819 | } catch (err) { } | 980 | } catch (err) { } |
| @@ -1812,8 +1973,8 @@ | |||
| 1812 | // Live unread count. The profile corner (data-unread-stream) is re-rendered by every swap, so it is | 1973 | // Live unread count. The profile corner (data-unread-stream) is re-rendered by every swap, so it is |
| 1813 | // looked up on each update. The count arrives as an `unread` event of the shell stream (see | 1974 | // looked up on each update. The count arrives as an `unread` event of the shell stream (see |
| 1814 | // `/-/shell/events`, opened with the alive handlers above), which the server pushes on each change; | 1975 | // `/-/shell/events`, opened with the alive handlers above), which the server pushes on each change; |
| 1815 | - // nothing polls. Each `unread` event also refreshes the activity (below). The count shows twice: as | 1976 | + // nothing polls. Each `unread` event also refreshes the activity (below). The count shows on the |
| 1816 | - // a dot on the menu toggle (has-dot), and next to Notifications in the sidebar and the phone menu. | 1977 | + // bell of the floating profile corner. |
| 1817 | 1978 | ||
| 1818 | // Shows the count in one link the way the server renders it: a span with the number, or no span at zero. | 1979 | // Shows the count in one link the way the server renders it: a span with the number, or no span at zero. |
| 1819 | function setCount(el, cls, n) { | 1980 | function setCount(el, cls, n) { |
| @@ -1831,12 +1992,9 @@ | |||
| 1831 | } | 1992 | } |
| 1832 | 1993 | ||
| 1833 | function setUnread(n) { | 1994 | function setUnread(n) { |
| 1834 | - // The menu toggle carries a dot while anything is unread. | 1995 | + // The bell of the profile corner, `.bell-count` as the server renders it. |
| 1835 | - var toggles = document.querySelectorAll('details.nav-toggle > summary'); | 1996 | + var bells = document.querySelectorAll('.corner-bell'); |
| 1836 | - for (var t = 0; t < toggles.length; t++) { toggles[t].classList.toggle('has-dot', n > 0); } | 1997 | + for (var i = 0; i < bells.length; i++) { setCount(bells[i], 'bell-count', n); } |
| 1837 | - // The sidebar's Notifications link (the sidebar and the phone menu hold one each), `.count` as the server renders it. | ||
| 1838 | - var links = document.querySelectorAll('nav.side-links a[href="/notifications"]'); | ||
| 1839 | - for (var i = 0; i < links.length; i++) { setCount(links[i], 'count', n); } | ||
| 1840 | } | 1998 | } |
| 1841 | 1999 | ||
| 1842 | // An `unread` event: the count, then the activity is fetched again. | 2000 | // An `unread` event: the count, then the activity is fetched again. |
| @@ -2574,15 +2732,6 @@ | |||
| 2574 | return es; | 2732 | return es; |
| 2575 | } | 2733 | } |
| 2576 | 2734 | ||
| 2577 | - // A `side` event of the shell stream: the sidebar's repo list changed. The page is re-rendered with | ||
| 2578 | - // it, as a `changed` event of a data-live stream would, but at most once a second (a code view or a | ||
| 2579 | - // live-now page re-renders at once). | ||
| 2580 | - function sideChanged() { | ||
| 2581 | - if (document.querySelector('[data-live-code], [data-live-now]')) { refreshLive(true); return; } | ||
| 2582 | - if (liveTimer) { return; } | ||
| 2583 | - liveTimer = setTimeout(function () { liveTimer = null; refreshLive(true); }, 1000); | ||
| 2584 | - } | ||
| 2585 | - | ||
| 2586 | // Closes the streams the page no longer names and opens the ones it newly names. | 2735 | // Closes the streams the page no longer names and opens the ones it newly names. |
| 2587 | function syncLive() { | 2736 | function syncLive() { |
| 2588 | var want = liveWanted(); | 2737 | var want = liveWanted(); |
| @@ -2642,6 +2791,8 @@ | |||
| 2642 | // A one-time secret (a token, recovery codes) is on screen only in the response that made it: a | 2791 | // A one-time secret (a token, recovery codes) is on screen only in the response that made it: a |
| 2643 | // re-render would take it away. The page is refreshed at the next navigation instead. | 2792 | // re-render would take it away. The page is refreshed at the next navigation instead. |
| 2644 | if (document.querySelector('[data-once]')) { return; } | 2793 | if (document.querySelector('[data-once]')) { return; } |
| 2794 | + // A rejected form is on screen: a re-render would replace its error. See load(). | ||
| 2795 | + if (heldForm) { return; } | ||
| 2645 | if (userBusy > 0 || liveBusy || selecting()) { liveDirty = true; if (force) { liveForced = true; } return; } | 2796 | if (userBusy > 0 || liveBusy || selecting()) { liveDirty = true; if (force) { liveForced = true; } return; } |
| 2646 | liveDirty = false; | 2797 | liveDirty = false; |
| 2647 | liveForced = false; | 2798 | liveForced = false; |
crates/forge-web/src/boot.rsmodified+1 -0
| @@ -172,6 +172,7 @@ pub async fn serve( | |||
| 172 | .layer(crate::pages::settings_live::AccountWriteLayer) | 172 | .layer(crate::pages::settings_live::AccountWriteLayer) |
| 173 | .cookies() | 173 | .cookies() |
| 174 | .layer(crate::pages::settings_profile::avatar_body_limit()) | 174 | .layer(crate::pages::settings_profile::avatar_body_limit()) |
| 175 | + .layer(crate::pages::settings_profile::org_avatar_body_limit()) | ||
| 175 | .layer(crate::pages::repo_ctx::RepoMovedLayer) | 176 | .layer(crate::pages::repo_ctx::RepoMovedLayer) |
| 176 | .layer(crate::pages::pull_live::PullWriteLayer) | 177 | .layer(crate::pages::pull_live::PullWriteLayer) |
| 177 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) | 178 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) |
crates/forge-web/src/i18n/migrate.rsmodified+15 -0
| @@ -67,6 +67,10 @@ pub enum K { | |||
| 67 | JobProgress, | 67 | JobProgress, |
| 68 | JobNoLog, | 68 | JobNoLog, |
| 69 | JobStarted, | 69 | JobStarted, |
| 70 | + RetryFailedTitle, | ||
| 71 | + RetrySelected, | ||
| 72 | + RetryNone, | ||
| 73 | + RetryTokenHelp, | ||
| 70 | StageGit, | 74 | StageGit, |
| 71 | StageLabels, | 75 | StageLabels, |
| 72 | StageMilestones, | 76 | StageMilestones, |
| @@ -155,6 +159,10 @@ const ALL: &[K] = &[ | |||
| 155 | K::JobProgress, | 159 | K::JobProgress, |
| 156 | K::JobNoLog, | 160 | K::JobNoLog, |
| 157 | K::JobStarted, | 161 | K::JobStarted, |
| 162 | + K::RetryFailedTitle, | ||
| 163 | + K::RetrySelected, | ||
| 164 | + K::RetryNone, | ||
| 165 | + K::RetryTokenHelp, | ||
| 158 | K::StageGit, | 166 | K::StageGit, |
| 159 | K::StageLabels, | 167 | K::StageLabels, |
| 160 | K::StageMilestones, | 168 | K::StageMilestones, |
| @@ -278,6 +286,13 @@ fn pair(key: K) -> (&'static str, &'static str) { | |||
| 278 | K::JobProgress => ("Progress", "İlerleme"), | 286 | K::JobProgress => ("Progress", "İlerleme"), |
| 279 | K::JobNoLog => ("Nothing yet.", "Henüz bir şey yok."), | 287 | K::JobNoLog => ("Nothing yet.", "Henüz bir şey yok."), |
| 280 | K::JobStarted => ("Started", "Başladı"), | 288 | K::JobStarted => ("Started", "Başladı"), |
| 289 | + K::RetryFailedTitle => ("Retry failed imports", "Başarısız içe aktarmaları yeniden dene"), | ||
| 290 | + K::RetrySelected => ("Retry selected", "Seçilenleri yeniden dene"), | ||
| 291 | + K::RetryNone => ("No failed imports", "Başarısız içe aktarma yok"), | ||
| 292 | + K::RetryTokenHelp => ( | ||
| 293 | + "Used for every import you select, then discarded. Retry imports from another account or provider separately with their own token. What was already imported is skipped.", | ||
| 294 | + "Seçtiğiniz her içe aktarma için kullanılır, sonra silinir. Başka bir hesap veya sağlayıcıdan gelen içe aktarmaları kendi belirteçleriyle ayrı olarak yeniden deneyin. Daha önce içe aktarılanlar atlanır.", | ||
| 295 | + ), | ||
| 281 | K::StageGit => ("Git data", "Git verisi"), | 296 | K::StageGit => ("Git data", "Git verisi"), |
| 282 | K::StageLabels => ("Labels", "Etiketler"), | 297 | K::StageLabels => ("Labels", "Etiketler"), |
| 283 | K::StageMilestones => ("Milestones", "Kilometre taşları"), | 298 | K::StageMilestones => ("Milestones", "Kilometre taşları"), |
crates/forge-web/src/i18n/misc.rsmodified+0 -40
| @@ -158,12 +158,6 @@ pub enum K { | |||
| 158 | WedLabel, | 158 | WedLabel, |
| 159 | FriLabel, | 159 | FriLabel, |
| 160 | NoContributionsDay, | 160 | NoContributionsDay, |
| 161 | - // Dashboard greeting and "Needs your attention" column. | ||
| 162 | - GoodMorning, | ||
| 163 | - GoodAfternoon, | ||
| 164 | - GoodEvening, | ||
| 165 | - NeedsAttention, | ||
| 166 | - NothingNeedsYou, | ||
| 167 | ViewAllNotifications, | 161 | ViewAllNotifications, |
| 168 | // Shell chrome (`views::mod`): breadcrumb landmark, theme picker, ref selector. | 162 | // Shell chrome (`views::mod`): breadcrumb landmark, theme picker, ref selector. |
| 169 | BreadcrumbNav, | 163 | BreadcrumbNav, |
| @@ -323,11 +317,6 @@ const ALL: &[K] = &[ | |||
| 323 | K::WedLabel, | 317 | K::WedLabel, |
| 324 | K::FriLabel, | 318 | K::FriLabel, |
| 325 | K::NoContributionsDay, | 319 | K::NoContributionsDay, |
| 326 | - K::GoodMorning, | ||
| 327 | - K::GoodAfternoon, | ||
| 328 | - K::GoodEvening, | ||
| 329 | - K::NeedsAttention, | ||
| 330 | - K::NothingNeedsYou, | ||
| 331 | K::ViewAllNotifications, | 320 | K::ViewAllNotifications, |
| 332 | K::BreadcrumbNav, | 321 | K::BreadcrumbNav, |
| 333 | K::ApplyTheme, | 322 | K::ApplyTheme, |
| @@ -644,16 +633,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 644 | (FriLabel, Tr) => "Cum", | 633 | (FriLabel, Tr) => "Cum", |
| 645 | (NoContributionsDay, En) => "No contributions on this day.", | 634 | (NoContributionsDay, En) => "No contributions on this day.", |
| 646 | (NoContributionsDay, Tr) => "Bu günde katkı yok.", | 635 | (NoContributionsDay, Tr) => "Bu günde katkı yok.", |
| 647 | - (GoodMorning, En) => "Good morning", | ||
| 648 | - (GoodMorning, Tr) => "Günaydın", | ||
| 649 | - (GoodAfternoon, En) => "Good afternoon", | ||
| 650 | - (GoodAfternoon, Tr) => "İyi günler", | ||
| 651 | - (GoodEvening, En) => "Good evening", | ||
| 652 | - (GoodEvening, Tr) => "İyi akşamlar", | ||
| 653 | - (NeedsAttention, En) => "Needs your attention", | ||
| 654 | - (NeedsAttention, Tr) => "Dikkatinizi bekleyenler", | ||
| 655 | - (NothingNeedsYou, En) => "Nothing needs you right now.", | ||
| 656 | - (NothingNeedsYou, Tr) => "Şu an dikkatinizi bekleyen bir şey yok.", | ||
| 657 | (ViewAllNotifications, En) => "View all notifications", | 636 | (ViewAllNotifications, En) => "View all notifications", |
| 658 | (ViewAllNotifications, Tr) => "Tüm bildirimleri gör", | 637 | (ViewAllNotifications, Tr) => "Tüm bildirimleri gör", |
| 659 | (BreadcrumbNav, En) => "Path", | 638 | (BreadcrumbNav, En) => "Path", |
| @@ -994,25 +973,6 @@ pub fn git_init_failed(lang: Lang, error: impl Display) -> String { | |||
| 994 | 973 | ||
| 995 | /// Upper-cases the first character. Turkish verbs here start with a plain letter, so the | 974 | /// Upper-cases the first character. Turkish verbs here start with a plain letter, so the |
| 996 | /// default mapping is right. | 975 | /// default mapping is right. |
| 997 | -/// "Good morning, Ahmet" for an hour before noon, "Good afternoon" before 18:00 and "Good | ||
| 998 | -/// evening" otherwise. `hour` is 0-23 in UTC. | ||
| 999 | -pub fn greeting(lang: Lang, hour: u8, name: &str) -> String { | ||
| 1000 | - let phrase = match hour { | ||
| 1001 | - 0..12 => K::GoodMorning, | ||
| 1002 | - 12..18 => K::GoodAfternoon, | ||
| 1003 | - _ => K::GoodEvening, | ||
| 1004 | - }; | ||
| 1005 | - format!("{}, {name}", t(lang, phrase)) | ||
| 1006 | -} | ||
| 1007 | - | ||
| 1008 | -/// `1 repository` / `3 repositories`, and `3 depo` in Turkish. | ||
| 1009 | -pub fn repositories_count(lang: Lang, n: u64) -> String { | ||
| 1010 | - match lang { | ||
| 1011 | - Lang::En => format!("{n} repositor{}", if n == 1 { "y" } else { "ies" }), | ||
| 1012 | - Lang::Tr => format!("{n} depo"), | ||
| 1013 | - } | ||
| 1014 | -} | ||
| 1015 | - | ||
| 1016 | fn capitalize(text: &str) -> String { | 976 | fn capitalize(text: &str) -> String { |
| 1017 | let mut chars = text.chars(); | 977 | let mut chars = text.chars(); |
| 1018 | match chars.next() { | 978 | match chars.next() { |
crates/forge-web/src/i18n/orgs.rsmodified+26 -18
| @@ -1,5 +1,5 @@ | |||
| 1 | //! Strings for the organization pages (`/org/...`), org creation, and the org-related parts of the | 1 | //! Strings for the organization pages (`/org/...`), org creation, and the org-related parts of the |
| 2 | -//! profile, explore and dashboard pages. | 2 | +//! profile, explore and landing pages. |
| 3 | 3 | ||
| 4 | use super::Lang; | 4 | use super::Lang; |
| 5 | 5 | ||
| @@ -33,6 +33,8 @@ pub enum K { | |||
| 33 | NoticeHasRepos, | 33 | NoticeHasRepos, |
| 34 | NoticeConfirmName, | 34 | NoticeConfirmName, |
| 35 | NoticeDescriptionLength, | 35 | NoticeDescriptionLength, |
| 36 | + NoticeInvalidDisplayName, | ||
| 37 | + NoticeAvatarInvalid, | ||
| 36 | // Shared labels. | 38 | // Shared labels. |
| 37 | Save, | 39 | Save, |
| 38 | Remove, | 40 | Remove, |
| @@ -49,6 +51,7 @@ pub enum K { | |||
| 49 | // Organization settings. | 51 | // Organization settings. |
| 50 | Settings, | 52 | Settings, |
| 51 | Description, | 53 | Description, |
| 54 | + DisplayNameLabel, | ||
| 52 | DefaultRoleLabel, | 55 | DefaultRoleLabel, |
| 53 | DefaultRoleHelp, | 56 | DefaultRoleHelp, |
| 54 | MembersCanCreate, | 57 | MembersCanCreate, |
| @@ -107,6 +110,7 @@ pub enum K { | |||
| 107 | // Profile. | 110 | // Profile. |
| 108 | LocalTime, | 111 | LocalTime, |
| 109 | NoMembers, | 112 | NoMembers, |
| 113 | + NoOrganizations, | ||
| 110 | NoVisibleRepos, | 114 | NoVisibleRepos, |
| 111 | NoVisibleStarred, | 115 | NoVisibleStarred, |
| 112 | Pinned, | 116 | Pinned, |
| @@ -117,19 +121,16 @@ pub enum K { | |||
| 117 | PinsTooMany, | 121 | PinsTooMany, |
| 118 | NoPinnableRepos, | 122 | NoPinnableRepos, |
| 119 | TabOverview, | 123 | TabOverview, |
| 124 | + Overview, | ||
| 120 | TabStars, | 125 | TabStars, |
| 121 | FilterRepos, | 126 | FilterRepos, |
| 122 | NoReposMatch, | 127 | NoReposMatch, |
| 123 | ClearSearch, | 128 | ClearSearch, |
| 124 | - // Dashboard and landing. | 129 | + // Landing. |
| 125 | - Dashboard, | ||
| 126 | Home, | 130 | Home, |
| 127 | LandingTagline, | 131 | LandingTagline, |
| 128 | LogIn, | 132 | LogIn, |
| 129 | SetUpForge, | 133 | SetUpForge, |
| 130 | - YourRepositories, | ||
| 131 | - RecentRepositories, | ||
| 132 | - NoReposYet, | ||
| 133 | } | 134 | } |
| 134 | 135 | ||
| 135 | pub fn t(lang: Lang, key: K) -> &'static str { | 136 | pub fn t(lang: Lang, key: K) -> &'static str { |
| @@ -190,6 +191,14 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 190 | (NoticeConfirmName, Tr) => "Kuruluşu silmek için adını tam olarak yazın.", | 191 | (NoticeConfirmName, Tr) => "Kuruluşu silmek için adını tam olarak yazın.", |
| 191 | (NoticeDescriptionLength, En) => "The description is longer than 2000 characters.", | 192 | (NoticeDescriptionLength, En) => "The description is longer than 2000 characters.", |
| 192 | (NoticeDescriptionLength, Tr) => "Açıklama 2000 karakterden uzun.", | 193 | (NoticeDescriptionLength, Tr) => "Açıklama 2000 karakterden uzun.", |
| 194 | + (NoticeInvalidDisplayName, En) => "That display name can't be used.", | ||
| 195 | + (NoticeInvalidDisplayName, Tr) => "Bu görünen ad kullanılamıyor.", | ||
| 196 | + (NoticeAvatarInvalid, En) => { | ||
| 197 | + "That image can't be used. Try a PNG, JPEG, WebP or GIF up to 5 MiB." | ||
| 198 | + } | ||
| 199 | + (NoticeAvatarInvalid, Tr) => { | ||
| 200 | + "Bu görsel kullanılamıyor. PNG, JPEG, WebP ya da GIF, en fazla 5 MiB deneyin." | ||
| 201 | + } | ||
| 193 | (Save, En) => "Save", | 202 | (Save, En) => "Save", |
| 194 | (Save, Tr) => "Kaydet", | 203 | (Save, Tr) => "Kaydet", |
| 195 | (Remove, En) => "Remove", | 204 | (Remove, En) => "Remove", |
| @@ -220,6 +229,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 220 | (Settings, Tr) => "Ayarlar", | 229 | (Settings, Tr) => "Ayarlar", |
| 221 | (Description, En) => "Description", | 230 | (Description, En) => "Description", |
| 222 | (Description, Tr) => "Açıklama", | 231 | (Description, Tr) => "Açıklama", |
| 232 | + (DisplayNameLabel, En) => "Display name", | ||
| 233 | + (DisplayNameLabel, Tr) => "Görünen ad", | ||
| 223 | (DefaultRoleLabel, En) => "Default role on the organization's repositories", | 234 | (DefaultRoleLabel, En) => "Default role on the organization's repositories", |
| 224 | (DefaultRoleLabel, Tr) => "Kuruluş depolarında varsayılan rol", | 235 | (DefaultRoleLabel, Tr) => "Kuruluş depolarında varsayılan rol", |
| 225 | (DefaultRoleHelp, En) => { | 236 | (DefaultRoleHelp, En) => { |
| @@ -342,6 +353,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 342 | (LocalTime, Tr) => "Yerel saat: ", | 353 | (LocalTime, Tr) => "Yerel saat: ", |
| 343 | (NoMembers, En) => "No members.", | 354 | (NoMembers, En) => "No members.", |
| 344 | (NoMembers, Tr) => "Üye yok.", | 355 | (NoMembers, Tr) => "Üye yok.", |
| 356 | + (NoOrganizations, En) => "You are not in any organization yet.", | ||
| 357 | + (NoOrganizations, Tr) => "Henüz hiçbir kuruluşta değilsiniz.", | ||
| 345 | (NoVisibleRepos, En) => "No visible repositories.", | 358 | (NoVisibleRepos, En) => "No visible repositories.", |
| 346 | (NoVisibleRepos, Tr) => "Görünür depo yok.", | 359 | (NoVisibleRepos, Tr) => "Görünür depo yok.", |
| 347 | (NoVisibleStarred, En) => "No visible starred repositories.", | 360 | (NoVisibleStarred, En) => "No visible starred repositories.", |
| @@ -362,6 +375,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 362 | (NoPinnableRepos, Tr) => "Henüz sabitlenecek depo yok.", | 375 | (NoPinnableRepos, Tr) => "Henüz sabitlenecek depo yok.", |
| 363 | (TabOverview, En) => "Overview", | 376 | (TabOverview, En) => "Overview", |
| 364 | (TabOverview, Tr) => "Genel bakış", | 377 | (TabOverview, Tr) => "Genel bakış", |
| 378 | + (Overview, En) => "Overview", | ||
| 379 | + (Overview, Tr) => "Genel bakış", | ||
| 365 | (TabStars, En) => "Stars", | 380 | (TabStars, En) => "Stars", |
| 366 | (TabStars, Tr) => "Yıldızlar", | 381 | (TabStars, Tr) => "Yıldızlar", |
| 367 | (FilterRepos, En) => "Find a repository", | 382 | (FilterRepos, En) => "Find a repository", |
| @@ -370,8 +385,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 370 | (NoReposMatch, Tr) => "Aramayla eşleşen depo yok.", | 385 | (NoReposMatch, Tr) => "Aramayla eşleşen depo yok.", |
| 371 | (ClearSearch, En) => "Clear search", | 386 | (ClearSearch, En) => "Clear search", |
| 372 | (ClearSearch, Tr) => "Aramayı temizle", | 387 | (ClearSearch, Tr) => "Aramayı temizle", |
| 373 | - (Dashboard, En) => "Dashboard", | ||
| 374 | - (Dashboard, Tr) => "Pano", | ||
| 375 | (Home, En) => "Home", | 388 | (Home, En) => "Home", |
| 376 | (Home, Tr) => "Ana sayfa", | 389 | (Home, Tr) => "Ana sayfa", |
| 377 | (LandingTagline, En) => "Self-hosted git repositories with a small, fast web interface.", | 390 | (LandingTagline, En) => "Self-hosted git repositories with a small, fast web interface.", |
| @@ -382,12 +395,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 382 | (LogIn, Tr) => "Giriş yap", | 395 | (LogIn, Tr) => "Giriş yap", |
| 383 | (SetUpForge, En) => "Set up forge", | 396 | (SetUpForge, En) => "Set up forge", |
| 384 | (SetUpForge, Tr) => "forge'u kur", | 397 | (SetUpForge, Tr) => "forge'u kur", |
| 385 | - (YourRepositories, En) => "Your repositories", | ||
| 386 | - (YourRepositories, Tr) => "Depolarınız", | ||
| 387 | - (RecentRepositories, En) => "Recent repositories", | ||
| 388 | - (RecentRepositories, Tr) => "Son depolar", | ||
| 389 | - (NoReposYet, En) => "You have no repositories yet.", | ||
| 390 | - (NoReposYet, Tr) => "Henüz deponuz yok.", | ||
| 391 | } | 398 | } |
| 392 | } | 399 | } |
| 393 | 400 | ||
| @@ -531,6 +538,8 @@ mod tests { | |||
| 531 | K::NoticeHasRepos, | 538 | K::NoticeHasRepos, |
| 532 | K::NoticeConfirmName, | 539 | K::NoticeConfirmName, |
| 533 | K::NoticeDescriptionLength, | 540 | K::NoticeDescriptionLength, |
| 541 | + K::NoticeInvalidDisplayName, | ||
| 542 | + K::NoticeAvatarInvalid, | ||
| 534 | K::Save, | 543 | K::Save, |
| 535 | K::Remove, | 544 | K::Remove, |
| 536 | K::Username, | 545 | K::Username, |
| @@ -544,6 +553,7 @@ mod tests { | |||
| 544 | K::CreateOrg, | 553 | K::CreateOrg, |
| 545 | K::Settings, | 554 | K::Settings, |
| 546 | K::Description, | 555 | K::Description, |
| 556 | + K::DisplayNameLabel, | ||
| 547 | K::DefaultRoleLabel, | 557 | K::DefaultRoleLabel, |
| 548 | K::DefaultRoleHelp, | 558 | K::DefaultRoleHelp, |
| 549 | K::MembersCanCreate, | 559 | K::MembersCanCreate, |
| @@ -597,6 +607,7 @@ mod tests { | |||
| 597 | K::NoPublicReposMatch, | 607 | K::NoPublicReposMatch, |
| 598 | K::LocalTime, | 608 | K::LocalTime, |
| 599 | K::NoMembers, | 609 | K::NoMembers, |
| 610 | + K::NoOrganizations, | ||
| 600 | K::NoVisibleRepos, | 611 | K::NoVisibleRepos, |
| 601 | K::NoVisibleStarred, | 612 | K::NoVisibleStarred, |
| 602 | K::Pinned, | 613 | K::Pinned, |
| @@ -607,18 +618,15 @@ mod tests { | |||
| 607 | K::PinsTooMany, | 618 | K::PinsTooMany, |
| 608 | K::NoPinnableRepos, | 619 | K::NoPinnableRepos, |
| 609 | K::TabOverview, | 620 | K::TabOverview, |
| 621 | + K::Overview, | ||
| 610 | K::TabStars, | 622 | K::TabStars, |
| 611 | K::FilterRepos, | 623 | K::FilterRepos, |
| 612 | K::NoReposMatch, | 624 | K::NoReposMatch, |
| 613 | K::ClearSearch, | 625 | K::ClearSearch, |
| 614 | - K::Dashboard, | ||
| 615 | K::Home, | 626 | K::Home, |
| 616 | K::LandingTagline, | 627 | K::LandingTagline, |
| 617 | K::LogIn, | 628 | K::LogIn, |
| 618 | K::SetUpForge, | 629 | K::SetUpForge, |
| 619 | - K::YourRepositories, | ||
| 620 | - K::RecentRepositories, | ||
| 621 | - K::NoReposYet, | ||
| 622 | ]; | 630 | ]; |
| 623 | 631 | ||
| 624 | #[test] | 632 | #[test] |
crates/forge-web/src/importer/mod.rsmodified+1 -0
| @@ -359,6 +359,7 @@ async fn run_production(state: &AppState, job: &ImportJob, spec: &JobSpec) { | |||
| 359 | } | 359 | } |
| 360 | 360 | ||
| 361 | async fn fail(state: &AppState, rep: &Reporter, message: &str) { | 361 | async fn fail(state: &AppState, rep: &Reporter, message: &str) { |
| 362 | + tracing::warn!(job = %rep.job_id, %message, "import failed"); | ||
| 362 | rep.log("error", message).await; | 363 | rep.log("error", message).await; |
| 363 | if let Err(e) = state | 364 | if let Err(e) = state |
| 364 | .store | 365 | .store |
crates/forge-web/src/importer/tests.rsmodified+60 -1
| @@ -8,6 +8,8 @@ use std::sync::Mutex; | |||
| 8 | use forge_core::issues::IssueFilter; | 8 | use forge_core::issues::IssueFilter; |
| 9 | use forge_core::store::imports::{ImportJob, ImportState}; | 9 | use forge_core::store::imports::{ImportJob, ImportState}; |
| 10 | use forge_core::{IssueState, Visibility}; | 10 | use forge_core::{IssueState, Visibility}; |
| 11 | +use topcoat::router::request::Request; | ||
| 12 | +use topcoat::router::{Body, to_bytes}; | ||
| 11 | 13 | ||
| 12 | use super::api::{ | 14 | use super::api::{ |
| 13 | ApiError, ApiResult, AssetStream, ExtAsset, ExtComment, ExtIssue, ExtLabel, ExtMilestone, | 15 | ApiError, ApiResult, AssetStream, ExtAsset, ExtComment, ExtIssue, ExtLabel, ExtMilestone, |
| @@ -16,8 +18,9 @@ use super::api::{ | |||
| 16 | use super::{ | 18 | use super::{ |
| 17 | ImportOptions, JobSpec, Source, Transport, asset_name, origin_note, run_job, with_note, | 19 | ImportOptions, JobSpec, Source, Transport, asset_name, origin_note, run_job, with_note, |
| 18 | }; | 20 | }; |
| 21 | +use crate::auth::SESSION_COOKIE; | ||
| 19 | use crate::state::AppState; | 22 | use crate::state::AppState; |
| 20 | -use crate::test_support::test_state; | 23 | +use crate::test_support::{app_router, create_session, test_state}; |
| 21 | 24 | ||
| 22 | const TOKEN: &str = "ghp_supersecret_token_value"; | 25 | const TOKEN: &str = "ghp_supersecret_token_value"; |
| 23 | 26 | ||
| @@ -495,6 +498,62 @@ async fn the_token_is_never_written_to_the_database() { | |||
| 495 | ); | 498 | ); |
| 496 | } | 499 | } |
| 497 | 500 | ||
| 501 | +#[tokio::test] | ||
| 502 | +async fn retry_submit_leaves_another_users_failed_job_alone() { | ||
| 503 | + let fx = fixture().await; | ||
| 504 | + let other = fx | ||
| 505 | + .state | ||
| 506 | + .store | ||
| 507 | + .create_user("mallory", None, "unused", false) | ||
| 508 | + .await | ||
| 509 | + .unwrap(); | ||
| 510 | + let job = new_job(&fx, Source::GitHub).await; | ||
| 511 | + fx.state | ||
| 512 | + .store | ||
| 513 | + .set_import_state(&job.id, ImportState::Failed, Some("rate limit")) | ||
| 514 | + .await | ||
| 515 | + .unwrap(); | ||
| 516 | + create_session(&fx.state.store, &other.id, "retry-other-session", "retry-csrf").await; | ||
| 517 | + | ||
| 518 | + let router = app_router(fx.state.clone()); | ||
| 519 | + let cookie = format!("__Host-{SESSION_COOKIE}=retry-other-session"); | ||
| 520 | + | ||
| 521 | + // The static /import/retry is not taken for /import/{job_id}: mallory sees her own empty list. | ||
| 522 | + let page = router | ||
| 523 | + .handle( | ||
| 524 | + Request::builder() | ||
| 525 | + .method("GET") | ||
| 526 | + .uri("/import/retry") | ||
| 527 | + .header("cookie", cookie.as_str()) | ||
| 528 | + .body(Body::empty()) | ||
| 529 | + .unwrap(), | ||
| 530 | + ) | ||
| 531 | + .await; | ||
| 532 | + assert_eq!(page.status().as_u16(), 200); | ||
| 533 | + let bytes = to_bytes(page.into_body(), usize::MAX).await.unwrap(); | ||
| 534 | + assert!(String::from_utf8_lossy(&bytes).contains("No failed imports")); | ||
| 535 | + | ||
| 536 | + // The form names the owner's job, and mallory is signed in: the page redirects, nothing starts. | ||
| 537 | + let form = format!("csrf=retry-csrf&token=&sel_0={}", job.id); | ||
| 538 | + let res = router | ||
| 539 | + .handle( | ||
| 540 | + Request::builder() | ||
| 541 | + .method("POST") | ||
| 542 | + .uri("/import/retry") | ||
| 543 | + .header("cookie", cookie.as_str()) | ||
| 544 | + .header("content-type", "application/x-www-form-urlencoded") | ||
| 545 | + .body(Body::from(form)) | ||
| 546 | + .unwrap(), | ||
| 547 | + ) | ||
| 548 | + .await; | ||
| 549 | + assert_eq!(res.status().as_u16(), 303); | ||
| 550 | + let _ = to_bytes(res.into_body(), usize::MAX).await.unwrap(); | ||
| 551 | + | ||
| 552 | + let after = fx.state.store.import_job(&job.id).await.unwrap().unwrap(); | ||
| 553 | + assert_eq!(after.state, ImportState::Failed); | ||
| 554 | + assert_eq!(after.error.as_deref(), Some("rate limit")); | ||
| 555 | +} | ||
| 556 | + | ||
| 498 | #[test] | 557 | #[test] |
| 499 | fn the_origin_note_escapes_the_mention_and_cleans_the_name() { | 558 | fn the_origin_note_escapes_the_mention_and_cleans_the_name() { |
| 500 | let note = origin_note( | 559 | let note = origin_note( |
crates/forge-web/src/live.rsmodified+1 -1
| @@ -59,7 +59,7 @@ pub enum Topic { | |||
| 59 | /// home page shows its newest version). The header's counts follow [`Topic::RepoIssues`] and | 59 | /// home page shows its newest version). The header's counts follow [`Topic::RepoIssues`] and |
| 60 | /// [`Topic::PullList`] as well. | 60 | /// [`Topic::PullList`] as well. |
| 61 | Repo(String), | 61 | Repo(String), |
| 62 | - /// A user's repo listing, pins, contribution calendar and the signed-in sidebar's repo list. | 62 | + /// A user's repo listing, pins and contribution calendar. |
| 63 | /// Keyed by user id (an organization is a user too). | 63 | /// Keyed by user id (an organization is a user too). |
| 64 | User(String), | 64 | User(String), |
| 65 | /// A user's inbox: a notification was added, read or marked read. Keyed by user id. | 65 | /// A user's inbox: a notification was added, read or marked read. Keyed by user id. |
crates/forge-web/src/pages/banner.rsmodified+24 -9
| @@ -1,26 +1,32 @@ | |||
| 1 | //! The site announcement banner. The admin sets it in the server settings (`banner.*`, live), and | 1 | //! The site announcement banner. The admin sets it in the server settings (`banner.*`, live), and |
| 2 | //! the shell shows it under the header on every page. A visitor dismisses it with | 2 | //! the shell shows it under the header on every page. A visitor dismisses it with |
| 3 | -//! `POST /-/banner/dismiss`, which stores the hash of the message in the `forge_banner` cookie, so a | 3 | +//! `POST /-/banner/dismiss`, which stores the hash of the message so a changed message shows again: |
| 4 | -//! changed message shows again. | 4 | +//! in the `forge_banner` cookie for a signed-out visitor, and as the `banner_dismissed` account |
| 5 | +//! preference for a signed-in user. | ||
| 5 | 6 | ||
| 7 | +use std::collections::HashMap; | ||
| 6 | use std::time::Duration; | 8 | use std::time::Duration; |
| 7 | 9 | ||
| 8 | use forge_core::config::BannerConfig; | 10 | use forge_core::config::BannerConfig; |
| 9 | use forge_core::token::hash_token; | 11 | use forge_core::token::hash_token; |
| 10 | use serde::Deserialize; | 12 | use serde::Deserialize; |
| 11 | use topcoat::Result; | 13 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, try_app_context}; | 14 | +use topcoat::context::{Cx, app_context, try_app_context}; |
| 13 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; | 15 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; |
| 14 | use topcoat::router::content::Form; | 16 | use topcoat::router::content::Form; |
| 15 | use topcoat::router::error::{SeeOther, see_other}; | 17 | use topcoat::router::error::{SeeOther, see_other}; |
| 16 | use topcoat::router::route; | 18 | use topcoat::router::route; |
| 17 | 19 | ||
| 20 | +use crate::auth::current_user; | ||
| 18 | use crate::pages::theme_cookie::safe_back; | 21 | use crate::pages::theme_cookie::safe_back; |
| 19 | use crate::state::AppState; | 22 | use crate::state::AppState; |
| 20 | 23 | ||
| 21 | /// Name of the dismissal cookie. | 24 | /// Name of the dismissal cookie. |
| 22 | pub const BANNER_COOKIE: &str = "forge_banner"; | 25 | pub const BANNER_COOKIE: &str = "forge_banner"; |
| 23 | 26 | ||
| 27 | +/// Account preference key holding the dismissed hash of a signed-in user. | ||
| 28 | +pub const BANNER_PREF: &str = "banner_dismissed"; | ||
| 29 | + | ||
| 24 | const BANNER_COOKIE_TTL: Duration = Duration::from_secs(365 * 24 * 60 * 60); | 30 | const BANNER_COOKIE_TTL: Duration = Duration::from_secs(365 * 24 * 60 * 60); |
| 25 | 31 | ||
| 26 | /// What the shell draws. | 32 | /// What the shell draws. |
| @@ -39,7 +45,7 @@ pub fn banner_hash(message: &str, level: &str) -> String { | |||
| 39 | } | 45 | } |
| 40 | 46 | ||
| 41 | /// The banner to show at `now`, or `None` when it is off, expired or dismissed (`dismissed` is the | 47 | /// The banner to show at `now`, or `None` when it is off, expired or dismissed (`dismissed` is the |
| 42 | -/// cookie value). | 48 | +/// stored hash). |
| 43 | pub fn view_for(config: &BannerConfig, now: i64, dismissed: Option<&str>) -> Option<BannerView> { | 49 | pub fn view_for(config: &BannerConfig, now: i64, dismissed: Option<&str>) -> Option<BannerView> { |
| 44 | if !config.active_at(now) { | 50 | if !config.active_at(now) { |
| 45 | return None; | 51 | return None; |
| @@ -57,15 +63,19 @@ pub fn view_for(config: &BannerConfig, now: i64, dismissed: Option<&str>) -> Opt | |||
| 57 | }) | 63 | }) |
| 58 | } | 64 | } |
| 59 | 65 | ||
| 60 | -/// The banner for this request, read from the live settings and the cookie. | 66 | +/// The banner for this request, read from the live settings. `prefs` is a signed-in viewer's |
| 61 | -pub fn current(cx: &Cx) -> Option<BannerView> { | 67 | +/// account preferences; without them the dismissal comes from the cookie. |
| 68 | +pub fn current(cx: &Cx, prefs: Option<&HashMap<String, String>>) -> Option<BannerView> { | ||
| 62 | let state = try_app_context::<AppState>(cx)?; | 69 | let state = try_app_context::<AppState>(cx)?; |
| 63 | let live = state.live(); | 70 | let live = state.live(); |
| 64 | if live.banner.message.trim().is_empty() { | 71 | if live.banner.message.trim().is_empty() { |
| 65 | return None; | 72 | return None; |
| 66 | } | 73 | } |
| 67 | - let cookie = cookies(cx).get(BANNER_COOKIE).map(|c| c.value().to_owned()); | 74 | + let dismissed = match prefs { |
| 68 | - view_for(&live.banner, crate::views::now_unix(), cookie.as_deref()) | 75 | + Some(prefs) => prefs.get(BANNER_PREF).cloned(), |
| 76 | + None => cookies(cx).get(BANNER_COOKIE).map(|c| c.value().to_owned()), | ||
| 77 | + }; | ||
| 78 | + view_for(&live.banner, crate::views::now_unix(), dismissed.as_deref()) | ||
| 69 | } | 79 | } |
| 70 | 80 | ||
| 71 | #[derive(Deserialize)] | 81 | #[derive(Deserialize)] |
| @@ -79,7 +89,12 @@ struct DismissForm { | |||
| 79 | #[route(POST "/-/banner/dismiss")] | 89 | #[route(POST "/-/banner/dismiss")] |
| 80 | async fn dismiss(cx: &Cx, Form(form): Form<DismissForm>) -> Result<SeeOther> { | 90 | async fn dismiss(cx: &Cx, Form(form): Form<DismissForm>) -> Result<SeeOther> { |
| 81 | let hash_ok = form.hash.len() == 16 && form.hash.bytes().all(|b| b.is_ascii_hexdigit()); | 91 | let hash_ok = form.hash.len() == 16 && form.hash.bytes().all(|b| b.is_ascii_hexdigit()); |
| 82 | - if hash_ok { | 92 | + if hash_ok && let Some((user, _)) = current_user(cx).await? { |
| 93 | + app_context::<AppState>(cx) | ||
| 94 | + .store | ||
| 95 | + .set_user_pref(&user.id, BANNER_PREF, &form.hash) | ||
| 96 | + .await?; | ||
| 97 | + } else if hash_ok { | ||
| 83 | let max_age = | 98 | let max_age = |
| 84 | time::Duration::seconds(i64::try_from(BANNER_COOKIE_TTL.as_secs()).unwrap_or(i64::MAX)); | 99 | time::Duration::seconds(i64::try_from(BANNER_COOKIE_TTL.as_secs()).unwrap_or(i64::MAX)); |
| 85 | cookies(cx).add( | 100 | cookies(cx).add( |
crates/forge-web/src/pages/commit.rsmodified+2 -1
| @@ -134,7 +134,8 @@ async fn commit_page(cx: &Cx) -> Result<impl View> { | |||
| 134 | ctx.repo.owner_name, ctx.repo.name, info.oid | 134 | ctx.repo.owner_name, ctx.repo.name, info.oid |
| 135 | ), | 135 | ), |
| 136 | )), | 136 | )), |
| 137 | - ); | 137 | + ) |
| 138 | + .await?; | ||
| 138 | let diff = | 139 | let diff = |
| 139 | history::commit_diff_ws(&state.git, &ctx.path, &info.oid, LIMITS, opts.ignore_ws).await?; | 140 | history::commit_diff_ws(&state.git, &ctx.path, &info.oid, LIMITS, opts.ignore_ws).await?; |
| 140 | 141 | ||
crates/forge-web/src/pages/compare.rsmodified+2 -1
| @@ -269,7 +269,8 @@ async fn compare_view( | |||
| 269 | format!("{compare_path}.patch"), | 269 | format!("{compare_path}.patch"), |
| 270 | format!("{compare_path}.diff"), | 270 | format!("{compare_path}.diff"), |
| 271 | )), | 271 | )), |
| 272 | - ); | 272 | + ) |
| 273 | + .await?; | ||
| 273 | // The page may be a failed POST re-shown; the toolbar still links to the comparison itself. | 274 | // The page may be a failed POST re-shown; the toolbar still links to the comparison itself. |
| 274 | opts.path = compare_path; | 275 | opts.path = compare_path; |
| 275 | let diff = if show_diff { | 276 | let diff = if show_diff { |
crates/forge-web/src/pages/dashboard.rsdeleted+0 -401
| @@ -1,401 +0,0 @@ | |||
| 1 | -//! Page: home. Landing page for visitors; repo dashboard for signed-in users. | ||
| 2 | -//! | ||
| 3 | -//! The dashboard is a greeting, the contribution calendar, then two columns: the user's | ||
| 4 | -//! repositories and the unread inbox rows that need them. | ||
| 5 | - | ||
| 6 | -use std::time::Duration; | ||
| 7 | - | ||
| 8 | -use forge_core::store::RepoSort; | ||
| 9 | -use forge_core::store::repo_listing::RepoScope; | ||
| 10 | -use forge_core::time::stamp_from_unix; | ||
| 11 | -use forge_core::{Notification, Repo, Visibility}; | ||
| 12 | -use jiff::{Timestamp, civil}; | ||
| 13 | -use topcoat::Result; | ||
| 14 | -use topcoat::context::{Cx, app_context}; | ||
| 15 | -use topcoat::router::content::sse::Event; | ||
| 16 | -use topcoat::router::response::Response; | ||
| 17 | -use topcoat::router::{Body, StatusCode, page, query_params, route}; | ||
| 18 | -use topcoat::view::{View, component, view}; | ||
| 19 | - | ||
| 20 | -use crate::auth::{current_user, percent_encode}; | ||
| 21 | -use crate::i18n::misc::{self as m, K as MK}; | ||
| 22 | -use crate::i18n::orgs::{self as g, K}; | ||
| 23 | -use crate::i18n::{self, Lang}; | ||
| 24 | -use crate::live::{Topic, named_changes, stream_changes}; | ||
| 25 | -use crate::pages::issue_parts::stamp_unix; | ||
| 26 | -use crate::pages::repo_settings::{notice_banner_for, take_notice}; | ||
| 27 | -use crate::state::AppState; | ||
| 28 | -use crate::views::heatmap::{self, Calendar, DayDetail, contribution_calendar}; | ||
| 29 | -use crate::views::{SIDE_REPOS, display_name, empty_state, now_unix, relative_time, shell}; | ||
| 30 | - | ||
| 31 | -/// How far back the calendar reads contributions: 53 weeks plus the days of the current week. | ||
| 32 | -const CALENDAR_DAYS: u64 = 371; | ||
| 33 | - | ||
| 34 | -/// The `since` stamp for the calendar. One extra day covers the viewer's local day, which can | ||
| 35 | -/// start before the UTC day that `CALENDAR_DAYS` reaches back to. | ||
| 36 | -fn calendar_since() -> String { | ||
| 37 | - forge_core::time::stamp_ago(Duration::from_secs((CALENDAR_DAYS + 1) * 86_400)) | ||
| 38 | -} | ||
| 39 | - | ||
| 40 | -/// The `day` query: a calendar day whose contributions to list under the calendar. | ||
| 41 | -#[query_params(error = bad_request)] | ||
| 42 | -struct DayQuery { | ||
| 43 | - day: Option<String>, | ||
| 44 | -} | ||
| 45 | - | ||
| 46 | -/// Unread inbox rows in the "Needs your attention" column. | ||
| 47 | -const ATTENTION_ROWS: u32 = 5; | ||
| 48 | - | ||
| 49 | -/// What the signed-in dashboard shows, loaded once per page view. | ||
| 50 | -struct Dashboard { | ||
| 51 | - name: String, | ||
| 52 | - hour: u8, | ||
| 53 | - repos: Vec<Repo>, | ||
| 54 | - calendar: Calendar, | ||
| 55 | - selected: Option<DayDetail>, | ||
| 56 | - attention: Vec<AttentionRow>, | ||
| 57 | -} | ||
| 58 | - | ||
| 59 | -/// One unread inbox row, with its strings ready for the view. | ||
| 60 | -struct AttentionRow { | ||
| 61 | - href: String, | ||
| 62 | - reference: String, | ||
| 63 | - title: String, | ||
| 64 | - kind: &'static str, | ||
| 65 | - /// The item's update stamp, for the `<time>` that shows `relative`. | ||
| 66 | - updated: String, | ||
| 67 | - relative: String, | ||
| 68 | -} | ||
| 69 | - | ||
| 70 | -#[page("/")] | ||
| 71 | -async fn home(cx: &Cx) -> Result<impl View> { | ||
| 72 | - let state = app_context::<AppState>(cx); | ||
| 73 | - let viewer = current_user(cx).await?; | ||
| 74 | - let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u)); | ||
| 75 | - let query = query_params::<DayQuery>(cx)?; | ||
| 76 | - let dash = match &viewer { | ||
| 77 | - Some((user, _)) => Some(load_dashboard(state, user, lang, query.day.as_deref()).await?), | ||
| 78 | - None => None, | ||
| 79 | - }; | ||
| 80 | - let has_users = viewer.is_none() && state.store.user_count().await? > 0; | ||
| 81 | - let title = if viewer.is_some() { | ||
| 82 | - g::t(lang, K::Dashboard) | ||
| 83 | - } else { | ||
| 84 | - g::t(lang, K::Home) | ||
| 85 | - }; | ||
| 86 | - let notice = take_notice(cx); | ||
| 87 | - Ok(view! { | ||
| 88 | - shell(title: title, viewer: viewer.as_ref(), | ||
| 89 | - notice_banner_for(lang: lang, title: notice) | ||
| 90 | - if let Some(dash) = dash { | ||
| 91 | - dashboard(dash: dash, lang: lang) | ||
| 92 | - } else { | ||
| 93 | - landing(has_users: has_users, lang: lang) | ||
| 94 | - }) | ||
| 95 | - }) | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -/// The dashboard's change stream for the viewer. It follows the viewer's own user topic (repo | ||
| 99 | -/// listing and contribution calendar, both moved by the viewer's pushes and repo changes) and | ||
| 100 | -/// their inbox. The viewer comes from the session only. | ||
| 101 | -#[route(GET "/dashboard/events")] | ||
| 102 | -async fn dashboard_events(cx: &Cx) -> Result<Response> { | ||
| 103 | - let Some((user, _)) = current_user(cx).await? else { | ||
| 104 | - let mut res = Response::new(Body::empty()); | ||
| 105 | - *res.status_mut() = StatusCode::UNAUTHORIZED; | ||
| 106 | - return Ok(res); | ||
| 107 | - }; | ||
| 108 | - let state = app_context::<AppState>(cx).clone(); | ||
| 109 | - let topics = [Topic::User(user.id.clone()), Topic::Inbox(user.id.clone())]; | ||
| 110 | - stream_changes(cx, &state.live.clone(), &topics, move || { | ||
| 111 | - let state = state.clone(); | ||
| 112 | - let user = user.clone(); | ||
| 113 | - async move { dashboard_fingerprint(&state, &user).await } | ||
| 114 | - }) | ||
| 115 | - .await | ||
| 116 | -} | ||
| 117 | - | ||
| 118 | -/// The signed-in sidebar's change stream: the viewer's freshest repos and their total. It follows | ||
| 119 | -/// the viewer's user topic only, and the viewer comes from the session, never from the URL. | ||
| 120 | -#[route(GET "/-/side/events")] | ||
| 121 | -async fn side_events(cx: &Cx) -> Result<Response> { | ||
| 122 | - let Some((user, _)) = current_user(cx).await? else { | ||
| 123 | - let mut res = Response::new(Body::empty()); | ||
| 124 | - *res.status_mut() = StatusCode::UNAUTHORIZED; | ||
| 125 | - return Ok(res); | ||
| 126 | - }; | ||
| 127 | - let state = app_context::<AppState>(cx).clone(); | ||
| 128 | - let topics = [Topic::User(user.id.clone())]; | ||
| 129 | - stream_changes(cx, &state.live.clone(), &topics, move || { | ||
| 130 | - let state = state.clone(); | ||
| 131 | - let user = user.clone(); | ||
| 132 | - async move { side_fingerprint(&state, &user).await } | ||
| 133 | - }) | ||
| 134 | - .await | ||
| 135 | -} | ||
| 136 | - | ||
| 137 | -/// The sidebar's change events for `user`, each named `name` (`changed` on `/-/side/events`). | ||
| 138 | -pub(crate) async fn side_changes( | ||
| 139 | - state: &AppState, | ||
| 140 | - user: &forge_core::User, | ||
| 141 | - name: &'static str, | ||
| 142 | -) -> topcoat::Result<impl futures_util::Stream<Item = topcoat::Result<Event>> + Send + 'static> { | ||
| 143 | - let topics = vec![Topic::User(user.id.clone())]; | ||
| 144 | - let (state_for_read, user) = (state.clone(), user.clone()); | ||
| 145 | - named_changes(&state.live, topics, Vec::new(), name, move || { | ||
| 146 | - let state = state_for_read.clone(); | ||
| 147 | - let user = user.clone(); | ||
| 148 | - async move { side_fingerprint(&state, &user).await } | ||
| 149 | - }) | ||
| 150 | - .await | ||
| 151 | -} | ||
| 152 | - | ||
| 153 | -/// The sidebar's repo list as it shows: the names in order, and the total. | ||
| 154 | -async fn side_fingerprint(state: &AppState, user: &forge_core::User) -> Result<String> { | ||
| 155 | - let (listed, total) = state | ||
| 156 | - .store | ||
| 157 | - .list_visible_repos( | ||
| 158 | - RepoScope::OwnedBy(&user.id), | ||
| 159 | - Some(user), | ||
| 160 | - None, | ||
| 161 | - RepoSort::RecentlyUpdated, | ||
| 162 | - 1, | ||
| 163 | - SIDE_REPOS, | ||
| 164 | - ) | ||
| 165 | - .await?; | ||
| 166 | - let mut lines = vec![format!("total {total}")]; | ||
| 167 | - lines.extend(listed.iter().map(|(repo, _, _)| repo.name.clone())); | ||
| 168 | - Ok(lines.join("\n")) | ||
| 169 | -} | ||
| 170 | - | ||
| 171 | -/// The state the dashboard shows: the repo list, the calendar counts and the attention rows. | ||
| 172 | -async fn dashboard_fingerprint(state: &AppState, user: &forge_core::User) -> Result<String> { | ||
| 173 | - let mut lines = Vec::new(); | ||
| 174 | - for repo in state.store.list_repos_by_owner(&user.id).await? { | ||
| 175 | - lines.push(format!( | ||
| 176 | - "repo {} {:?} {}", | ||
| 177 | - repo.name, repo.visibility, repo.description | ||
| 178 | - )); | ||
| 179 | - } | ||
| 180 | - let since = calendar_since(); | ||
| 181 | - for (day, count) in state | ||
| 182 | - .store | ||
| 183 | - .contribution_counts(&user.id, &since, &user.timezone) | ||
| 184 | - .await? | ||
| 185 | - { | ||
| 186 | - lines.push(format!("day {day} {count}")); | ||
| 187 | - } | ||
| 188 | - for note in state | ||
| 189 | - .store | ||
| 190 | - .list_notifications(&user.id, true, None, ATTENTION_ROWS) | ||
| 191 | - .await? | ||
| 192 | - { | ||
| 193 | - lines.push(format!( | ||
| 194 | - "note {} {} {} {}", | ||
| 195 | - note.id, note.updated_at, note.title, note.issue_state | ||
| 196 | - )); | ||
| 197 | - } | ||
| 198 | - Ok(lines.join("\n")) | ||
| 199 | -} | ||
| 200 | - | ||
| 201 | -/// The day the `day` query asks for: a strict `YYYY-MM-DD` date from the calendar's first day to | ||
| 202 | -/// today. Anything else (malformed, a future day, or before the calendar) is ignored. | ||
| 203 | -fn selected_day( | ||
| 204 | - day: Option<&str>, | ||
| 205 | - first: (i64, i64, i64), | ||
| 206 | - today: (i64, i64, i64), | ||
| 207 | -) -> Option<civil::Date> { | ||
| 208 | - let text = day?; | ||
| 209 | - let date: civil::Date = text.parse().ok()?; | ||
| 210 | - // The parser takes more forms than the calendar link uses, so the date must print back as sent. | ||
| 211 | - if date.to_string() != text { | ||
| 212 | - return None; | ||
| 213 | - } | ||
| 214 | - let ymd = ( | ||
| 215 | - i64::from(date.year()), | ||
| 216 | - i64::from(date.month()), | ||
| 217 | - i64::from(date.day()), | ||
| 218 | - ); | ||
| 219 | - (first..=today).contains(&ymd).then_some(date) | ||
| 220 | -} | ||
| 221 | - | ||
| 222 | -/// The contributions the user made on their local day `date`, newest first. | ||
| 223 | -async fn day_detail( | ||
| 224 | - state: &AppState, | ||
| 225 | - user: &forge_core::User, | ||
| 226 | - date: civil::Date, | ||
| 227 | -) -> Result<Option<DayDetail>> { | ||
| 228 | - let Some((start, end)) = forge_core::tz::day_span(date, &user.timezone) else { | ||
| 229 | - return Ok(None); | ||
| 230 | - }; | ||
| 231 | - let (Some(from), Some(to)) = (stamp_from_unix(start), stamp_from_unix(end)) else { | ||
| 232 | - return Ok(None); | ||
| 233 | - }; | ||
| 234 | - let items = state | ||
| 235 | - .store | ||
| 236 | - .contributions_between(&user.id, &from, &to) | ||
| 237 | - .await?; | ||
| 238 | - Ok(Some(DayDetail { | ||
| 239 | - date: ( | ||
| 240 | - i64::from(date.year()), | ||
| 241 | - i64::from(date.month()), | ||
| 242 | - i64::from(date.day()), | ||
| 243 | - ), | ||
| 244 | - items, | ||
| 245 | - })) | ||
| 246 | -} | ||
| 247 | - | ||
| 248 | -/// Reads the dashboard data for a signed-in user. `day` is the raw `day` query value. | ||
| 249 | -async fn load_dashboard( | ||
| 250 | - state: &AppState, | ||
| 251 | - user: &forge_core::User, | ||
| 252 | - lang: Lang, | ||
| 253 | - day: Option<&str>, | ||
| 254 | -) -> Result<Dashboard> { | ||
| 255 | - let repos = state.store.list_repos_by_owner(&user.id).await?; | ||
| 256 | - let local_now = forge_core::tz::local_datetime(Timestamp::now(), &user.timezone); | ||
| 257 | - let today = ( | ||
| 258 | - i64::from(local_now.year()), | ||
| 259 | - i64::from(local_now.month()), | ||
| 260 | - i64::from(local_now.day()), | ||
| 261 | - ); | ||
| 262 | - let counts = state | ||
| 263 | - .store | ||
| 264 | - .contribution_counts(&user.id, &calendar_since(), &user.timezone) | ||
| 265 | - .await?; | ||
| 266 | - let calendar = heatmap::build(&counts, today); | ||
| 267 | - let selected = match selected_day(day, calendar.first_day, today) { | ||
| 268 | - Some(date) => day_detail(state, user, date).await?, | ||
| 269 | - None => None, | ||
| 270 | - }; | ||
| 271 | - let now_secs = now_unix(); | ||
| 272 | - let attention = state | ||
| 273 | - .store | ||
| 274 | - .list_notifications(&user.id, true, None, ATTENTION_ROWS) | ||
| 275 | - .await? | ||
| 276 | - .iter() | ||
| 277 | - .map(|note| attention_row(lang, note, now_secs)) | ||
| 278 | - .collect(); | ||
| 279 | - Ok(Dashboard { | ||
| 280 | - name: display_name(lang, &user.username), | ||
| 281 | - hour: u8::try_from(local_now.hour()).unwrap_or_default(), | ||
| 282 | - repos, | ||
| 283 | - calendar, | ||
| 284 | - selected, | ||
| 285 | - attention, | ||
| 286 | - }) | ||
| 287 | -} | ||
| 288 | - | ||
| 289 | -#[component] | ||
| 290 | -async fn landing(has_users: bool, lang: Lang) -> Result<impl View> { | ||
| 291 | - Ok(view! { | ||
| 292 | - <section class="hero"> | ||
| 293 | - <h1>"forge"</h1> | ||
| 294 | - <p class="muted">(g::t(lang, K::LandingTagline))</p> | ||
| 295 | - <div class="actions"> | ||
| 296 | - <a class="button primary" href="/login">(g::t(lang, K::LogIn))</a> | ||
| 297 | - if !has_users { | ||
| 298 | - <a class="button" href="/setup">(g::t(lang, K::SetUpForge))</a> | ||
| 299 | - } | ||
| 300 | - </div> | ||
| 301 | - </section> | ||
| 302 | - }) | ||
| 303 | -} | ||
| 304 | - | ||
| 305 | -#[component] | ||
| 306 | -async fn dashboard(dash: Dashboard, lang: Lang) -> Result<impl View> { | ||
| 307 | - let empty = dash.repos.is_empty(); | ||
| 308 | - let count = m::repositories_count(lang, dash.repos.len() as u64); | ||
| 309 | - let greeting = m::greeting(lang, dash.hour, &dash.name); | ||
| 310 | - let attention_empty = dash.attention.is_empty(); | ||
| 311 | - Ok(view! { | ||
| 312 | - <div data-live="/dashboard/events"> | ||
| 313 | - <h1 class="greet">(greeting)</h1> | ||
| 314 | - contribution_calendar(calendar: dash.calendar, selected: dash.selected, lang: lang) | ||
| 315 | - <div class="dash-cols"> | ||
| 316 | - <section class="dash-repos" aria-labelledby="repos-h"> | ||
| 317 | - <div class="sec-head"> | ||
| 318 | - <h2 id="repos-h">(g::t(lang, K::YourRepositories))</h2> | ||
| 319 | - <span class="small">(count)</span> | ||
| 320 | - <a class="button primary" href="/new">(g::t(lang, K::NewRepository))</a> | ||
| 321 | - </div> | ||
| 322 | - if empty { | ||
| 323 | - empty_state(title: g::t(lang, K::NoReposYet), | ||
| 324 | - <a class="button primary" href="/new">(g::t(lang, K::NewRepository))</a> | ||
| 325 | - <a class="button" href="/new/import">(crate::i18n::migrate::t(lang, crate::i18n::migrate::K::ImportTitle))</a>) | ||
| 326 | - } else { | ||
| 327 | - <div class="table-wrap"> | ||
| 328 | - <table class="table"> | ||
| 329 | - <thead> | ||
| 330 | - <tr> | ||
| 331 | - <th scope="col">(g::t(lang, K::Name))</th> | ||
| 332 | - <th scope="col" class="dash-desc">(g::t(lang, K::Description))</th> | ||
| 333 | - </tr> | ||
| 334 | - </thead> | ||
| 335 | - <tbody> | ||
| 336 | - for repo in dash.repos.into_iter() { | ||
| 337 | - <tr> | ||
| 338 | - <td> | ||
| 339 | - <a class="repo-name" href=(format!("/{}/{}", repo.owner_name, repo.name))> | ||
| 340 | - (format!("{}/{}", repo.owner_name, repo.name)) | ||
| 341 | - </a> | ||
| 342 | - if repo.visibility == Visibility::Private { | ||
| 343 | - <span class=(badge_class(repo.visibility))>(i18n::visibility_label(lang, repo.visibility))</span> | ||
| 344 | - } | ||
| 345 | - </td> | ||
| 346 | - <td class="muted dash-desc">(repo.description)</td> | ||
| 347 | - </tr> | ||
| 348 | - } | ||
| 349 | - </tbody> | ||
| 350 | - </table> | ||
| 351 | - </div> | ||
| 352 | - } | ||
| 353 | - </section> | ||
| 354 | - <section class="dash-attention" aria-labelledby="attn-h"> | ||
| 355 | - <div class="sec-head"> | ||
| 356 | - <h2 id="attn-h">(m::t(lang, MK::NeedsAttention))</h2> | ||
| 357 | - </div> | ||
| 358 | - if attention_empty { | ||
| 359 | - empty_state(title: m::t(lang, MK::NothingNeedsYou)) | ||
| 360 | - } else { | ||
| 361 | - <ul class="attn"> | ||
| 362 | - for item in dash.attention.into_iter() { | ||
| 363 | - <li> | ||
| 364 | - <a href=(item.href.as_str())><span class="mono">(item.reference.as_str())</span>" "(item.title.as_str())</a> | ||
| 365 | - <span class="sub">(item.kind) " · " <time data-rel="true" datetime=(item.updated.as_str())>(item.relative.as_str())</time></span> | ||
| 366 | - </li> | ||
| 367 | - } | ||
| 368 | - </ul> | ||
| 369 | - } | ||
| 370 | - <p class="small"><a href="/notifications">(m::t(lang, MK::ViewAllNotifications))</a></p> | ||
| 371 | - </section> | ||
| 372 | - </div> | ||
| 373 | - </div> | ||
| 374 | - }) | ||
| 375 | -} | ||
| 376 | - | ||
| 377 | -/// The row for an unread inbox entry on the dashboard. | ||
| 378 | -fn attention_row(lang: Lang, note: &Notification, now: i64) -> AttentionRow { | ||
| 379 | - let kind = match (note.is_pull, note.issue_state.as_str()) { | ||
| 380 | - (false, "open") => m::t(lang, MK::KindOpenIssue), | ||
| 381 | - (false, _) => m::t(lang, MK::KindClosedIssue), | ||
| 382 | - (true, "open") => m::t(lang, MK::KindOpenPull), | ||
| 383 | - (true, _) => m::t(lang, MK::KindClosedPull), | ||
| 384 | - }; | ||
| 385 | - AttentionRow { | ||
| 386 | - href: format!("/notifications/{}/open", percent_encode(¬e.id)), | ||
| 387 | - reference: format!("{}/{} #{}", note.repo_owner, note.repo_name, note.number), | ||
| 388 | - title: note.title.clone(), | ||
| 389 | - kind, | ||
| 390 | - updated: note.updated_at.clone(), | ||
| 391 | - relative: relative_time(lang, stamp_unix(¬e.updated_at), now), | ||
| 392 | - } | ||
| 393 | -} | ||
| 394 | - | ||
| 395 | -/// CSS class for a visibility badge. | ||
| 396 | -pub fn badge_class(visibility: Visibility) -> &'static str { | ||
| 397 | - match visibility { | ||
| 398 | - Visibility::Public => "badge public", | ||
| 399 | - Visibility::Private => "badge private", | ||
| 400 | - } | ||
| 401 | -} | ||
crates/forge-web/src/pages/home.rsadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +//! Page: home. The landing page for visitors. A signed-in viewer is sent to their own profile. | ||
| 2 | + | ||
| 3 | +use topcoat::Result; | ||
| 4 | +use topcoat::context::{Cx, app_context}; | ||
| 5 | +use topcoat::router::error::see_other; | ||
| 6 | +use topcoat::router::page; | ||
| 7 | +use topcoat::view::{View, component, view}; | ||
| 8 | + | ||
| 9 | +use crate::auth::current_user; | ||
| 10 | +use crate::i18n::orgs::{self as g, K}; | ||
| 11 | +use crate::i18n::{self, Lang}; | ||
| 12 | +use crate::pages::repo_settings::{notice_banner_for, take_notice}; | ||
| 13 | +use crate::state::AppState; | ||
| 14 | +use crate::views::{enc, shell}; | ||
| 15 | + | ||
| 16 | +#[page("/")] | ||
| 17 | +async fn home(cx: &Cx) -> Result<impl View> { | ||
| 18 | + let state = app_context::<AppState>(cx); | ||
| 19 | + if let Some((user, _)) = current_user(cx).await? { | ||
| 20 | + return Err(see_other(format!("/{}", enc(&user.username))).into()); | ||
| 21 | + } | ||
| 22 | + let lang = i18n::lang(cx, None); | ||
| 23 | + let has_users = state.store.user_count().await? > 0; | ||
| 24 | + let notice = take_notice(cx); | ||
| 25 | + Ok(view! { | ||
| 26 | + shell(title: g::t(lang, K::Home), viewer: None, | ||
| 27 | + notice_banner_for(lang: lang, title: notice) | ||
| 28 | + landing(has_users: has_users, lang: lang) | ||
| 29 | + ) | ||
| 30 | + }) | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +#[component] | ||
| 34 | +async fn landing(has_users: bool, lang: Lang) -> Result<impl View> { | ||
| 35 | + Ok(view! { | ||
| 36 | + <section class="hero"> | ||
| 37 | + <h1>"forge"</h1> | ||
| 38 | + <p class="muted">(g::t(lang, K::LandingTagline))</p> | ||
| 39 | + <div class="actions"> | ||
| 40 | + <a class="button primary" href="/login">(g::t(lang, K::LogIn))</a> | ||
| 41 | + if !has_users { | ||
| 42 | + <a class="button" href="/setup">(g::t(lang, K::SetUpForge))</a> | ||
| 43 | + } | ||
| 44 | + </div> | ||
| 45 | + </section> | ||
| 46 | + }) | ||
| 47 | +} | ||
crates/forge-web/src/pages/import.rsmodified+191 -13
| @@ -949,6 +949,13 @@ async fn run_bulk( | |||
| 949 | } else { | 949 | } else { |
| 950 | Visibility::Private | 950 | Visibility::Private |
| 951 | }; | 951 | }; |
| 952 | + let failed: Vec<ImportJob> = state | ||
| 953 | + .store | ||
| 954 | + .list_import_jobs(&viewer.id, 200) | ||
| 955 | + .await? | ||
| 956 | + .into_iter() | ||
| 957 | + .filter(|job| job.state == ImportState::Failed) | ||
| 958 | + .collect(); | ||
| 952 | let mut skipped: Vec<String> = Vec::new(); | 959 | let mut skipped: Vec<String> = Vec::new(); |
| 953 | for (_, full_name) in picked { | 960 | for (_, full_name) in picked { |
| 954 | let Some((remote, inst)) = parse_remote(source, full_name, instance) else { | 961 | let Some((remote, inst)) = parse_remote(source, full_name, instance) else { |
| @@ -963,6 +970,19 @@ async fn run_bulk( | |||
| 963 | options, | 970 | options, |
| 964 | }; | 971 | }; |
| 965 | let name = default_name(&remote); | 972 | let name = default_name(&remote); |
| 973 | + // The repository from a failed import of this source is there already: retry that import | ||
| 974 | + // instead of refusing the name as taken. | ||
| 975 | + if let Some(repo) = state | ||
| 976 | + .store | ||
| 977 | + .repo_by_owner_and_name(&target.username, &name) | ||
| 978 | + .await? | ||
| 979 | + && let Some(job) = failed.iter().find(|job| { | ||
| 980 | + job.repo_id.as_deref() == Some(repo.id.as_str()) && job.source == source.as_str() | ||
| 981 | + }) | ||
| 982 | + { | ||
| 983 | + retry_job(state, job.clone(), &form.token).await?; | ||
| 984 | + continue; | ||
| 985 | + } | ||
| 966 | // A name already taken, or any refusal, skips that one; the list page says which and why. | 986 | // A name already taken, or any refusal, skips that one; the list page says which and why. |
| 967 | if let Err(message) = begin(cx, viewer, &target, &name, "", visibility, spec).await? { | 987 | if let Err(message) = begin(cx, viewer, &target, &name, "", visibility, spec).await? { |
| 968 | tracing::info!(repo = %remote, %message, "bulk import: skipped a repository"); | 988 | tracing::info!(repo = %remote, %message, "bulk import: skipped a repository"); |
| @@ -1061,13 +1081,24 @@ async fn recent_imports( | |||
| 1061 | more: bool, | 1081 | more: bool, |
| 1062 | ) -> Result<impl View> { | 1082 | ) -> Result<impl View> { |
| 1063 | let empty = jobs.is_empty(); | 1083 | let empty = jobs.is_empty(); |
| 1084 | + let retry = jobs.iter().any(|(job, _)| job.state == ImportState::Failed); | ||
| 1064 | Ok(view! { | 1085 | Ok(view! { |
| 1065 | if !empty { | 1086 | if !empty { |
| 1066 | <section class="card import-recent"> | 1087 | <section class="card import-recent"> |
| 1067 | <h2>(g::t(lang, K::RecentImports))</h2> | 1088 | <h2>(g::t(lang, K::RecentImports))</h2> |
| 1068 | job_rows(lang: lang, jobs: jobs) | 1089 | job_rows(lang: lang, jobs: jobs) |
| 1069 | - if more { | 1090 | + if more || retry { |
| 1070 | - <p class="small"><a href="/import">(g::t(lang, K::ViewAll))</a></p> | 1091 | + <p class="small"> |
| 1092 | + if more { | ||
| 1093 | + <a href="/import">(g::t(lang, K::ViewAll))</a> | ||
| 1094 | + } | ||
| 1095 | + if more && retry { | ||
| 1096 | + " · " | ||
| 1097 | + } | ||
| 1098 | + if retry { | ||
| 1099 | + <a href="/import/retry">(g::t(lang, K::RetryFailedTitle))</a> | ||
| 1100 | + } | ||
| 1101 | + </p> | ||
| 1071 | } | 1102 | } |
| 1072 | </section> | 1103 | </section> |
| 1073 | } | 1104 | } |
| @@ -1081,10 +1112,14 @@ async fn jobs_list( | |||
| 1081 | skipped: Option<String>, | 1112 | skipped: Option<String>, |
| 1082 | ) -> Result<impl View> { | 1113 | ) -> Result<impl View> { |
| 1083 | let empty = jobs.is_empty(); | 1114 | let empty = jobs.is_empty(); |
| 1115 | + let retry = jobs.iter().any(|(job, _)| job.state == ImportState::Failed); | ||
| 1084 | Ok(view! { | 1116 | Ok(view! { |
| 1085 | newrepo_tabs(lang: lang, active: "import") | 1117 | newrepo_tabs(lang: lang, active: "import") |
| 1086 | <section class="page-head" data-live="/import/events"> | 1118 | <section class="page-head" data-live="/import/events"> |
| 1087 | <h1>(g::t(lang, K::JobsTitle))</h1> | 1119 | <h1>(g::t(lang, K::JobsTitle))</h1> |
| 1120 | + if retry { | ||
| 1121 | + <a class="button" href="/import/retry">(g::t(lang, K::RetryFailedTitle))</a> | ||
| 1122 | + } | ||
| 1088 | </section> | 1123 | </section> |
| 1089 | if let Some(message) = skipped { | 1124 | if let Some(message) = skipped { |
| 1090 | alert(message: message.as_str()) | 1125 | alert(message: message.as_str()) |
| @@ -1308,25 +1343,23 @@ struct RetryForm { | |||
| 1308 | token: String, | 1343 | token: String, |
| 1309 | } | 1344 | } |
| 1310 | 1345 | ||
| 1311 | -#[route(POST "/import/{job_id}/retry")] | 1346 | +/// Re-queues a failed import and starts it again; what was imported before is skipped. `Ok(false)` |
| 1312 | -async fn job_retry(cx: &Cx, Form(form): Form<RetryForm>) -> Result<SeeOther> { | 1347 | +/// when nothing was started: the job is not failed, its source or remote does not parse, or its |
| 1313 | - let viewer = require_csrf(cx, &form.csrf).await?; | 1348 | +/// repository already has an import running. |
| 1314 | - let state = app_context::<AppState>(cx); | 1349 | +async fn retry_job(state: &AppState, job: ImportJob, token: &str) -> Result<bool> { |
| 1315 | - let job = owned_job(cx, &viewer.0).await?; | ||
| 1316 | - let href = format!("/import/{}", job.id); | ||
| 1317 | if job.state != ImportState::Failed { | 1350 | if job.state != ImportState::Failed { |
| 1318 | - return Err(see_other(href).into()); | 1351 | + return Ok(false); |
| 1319 | } | 1352 | } |
| 1320 | let Some(source) = Source::parse(&job.source) else { | 1353 | let Some(source) = Source::parse(&job.source) else { |
| 1321 | - return Err(see_other(href).into()); | 1354 | + return Ok(false); |
| 1322 | }; | 1355 | }; |
| 1323 | let Some((remote, instance)) = parse_remote(source, &job.source_ref, "") else { | 1356 | let Some((remote, instance)) = parse_remote(source, &job.source_ref, "") else { |
| 1324 | - return Err(see_other(href).into()); | 1357 | + return Ok(false); |
| 1325 | }; | 1358 | }; |
| 1326 | if let Some(repo_id) = &job.repo_id | 1359 | if let Some(repo_id) = &job.repo_id |
| 1327 | && state.store.active_import_for_repo(repo_id).await?.is_some() | 1360 | && state.store.active_import_for_repo(repo_id).await?.is_some() |
| 1328 | { | 1361 | { |
| 1329 | - return Err(see_other(href).into()); | 1362 | + return Ok(false); |
| 1330 | } | 1363 | } |
| 1331 | let options: ImportOptions = serde_json::from_str(&job.options).unwrap_or_default(); | 1364 | let options: ImportOptions = serde_json::from_str(&job.options).unwrap_or_default(); |
| 1332 | state | 1365 | state |
| @@ -1345,10 +1378,155 @@ async fn job_retry(cx: &Cx, Form(form): Form<RetryForm>) -> Result<SeeOther> { | |||
| 1345 | source, | 1378 | source, |
| 1346 | remote, | 1379 | remote, |
| 1347 | instance, | 1380 | instance, |
| 1348 | - token: token_of(&form.token), | 1381 | + token: token_of(token), |
| 1349 | git_user: String::new(), | 1382 | git_user: String::new(), |
| 1350 | options, | 1383 | options, |
| 1351 | }; | 1384 | }; |
| 1352 | importer::spawn_job(state.clone(), job, spec); | 1385 | importer::spawn_job(state.clone(), job, spec); |
| 1386 | + Ok(true) | ||
| 1387 | +} | ||
| 1388 | + | ||
| 1389 | +#[route(POST "/import/{job_id}/retry")] | ||
| 1390 | +async fn job_retry(cx: &Cx, Form(form): Form<RetryForm>) -> Result<SeeOther> { | ||
| 1391 | + let viewer = require_csrf(cx, &form.csrf).await?; | ||
| 1392 | + let state = app_context::<AppState>(cx); | ||
| 1393 | + let job = owned_job(cx, &viewer.0).await?; | ||
| 1394 | + let href = format!("/import/{}", job.id); | ||
| 1395 | + retry_job(state, job, &form.token).await?; | ||
| 1353 | Err(see_other(href).into()) | 1396 | Err(see_other(href).into()) |
| 1354 | } | 1397 | } |
| 1398 | + | ||
| 1399 | +// ---- retry several failed imports ---- | ||
| 1400 | + | ||
| 1401 | +/// The viewer's failed imports whose repository still exists and is readable, with the repository, | ||
| 1402 | +/// and no import running on it. Newest first. | ||
| 1403 | +async fn retry_candidates(state: &AppState, viewer: &User) -> Result<Vec<(ImportJob, Repo)>> { | ||
| 1404 | + let mut rows = Vec::new(); | ||
| 1405 | + for job in state.store.list_import_jobs(&viewer.id, 200).await? { | ||
| 1406 | + if job.state != ImportState::Failed { | ||
| 1407 | + continue; | ||
| 1408 | + } | ||
| 1409 | + let Some(repo) = job_repo(state, Some(viewer), &job).await? else { | ||
| 1410 | + continue; | ||
| 1411 | + }; | ||
| 1412 | + if state.store.active_import_for_repo(&repo.id).await?.is_some() { | ||
| 1413 | + continue; | ||
| 1414 | + } | ||
| 1415 | + rows.push((job, repo)); | ||
| 1416 | + } | ||
| 1417 | + Ok(rows) | ||
| 1418 | +} | ||
| 1419 | + | ||
| 1420 | +/// The provider's name for a job's source, as the source tabs show it. | ||
| 1421 | +fn source_label(raw: &str) -> &'static str { | ||
| 1422 | + Source::parse(raw).map_or("", Source::label) | ||
| 1423 | +} | ||
| 1424 | + | ||
| 1425 | +#[component] | ||
| 1426 | +async fn retry_list(lang: Lang, csrf: &str, rows: Vec<(ImportJob, Repo)>) -> Result<impl View> { | ||
| 1427 | + let count = rows.len(); | ||
| 1428 | + let empty = rows.is_empty(); | ||
| 1429 | + Ok(view! { | ||
| 1430 | + newrepo_tabs(lang: lang, active: "import") | ||
| 1431 | + <form method="post" action="/import/retry" class="newrepo-form"> | ||
| 1432 | + csrf_field(token: csrf) | ||
| 1433 | + <header class="newrepo-head"> | ||
| 1434 | + <h1>(g::t(lang, K::RetryFailedTitle))</h1> | ||
| 1435 | + <div class="newrepo-head-actions"> | ||
| 1436 | + if !empty { | ||
| 1437 | + <button type="submit" class="primary">(g::t(lang, K::RetrySelected))</button> | ||
| 1438 | + } | ||
| 1439 | + </div> | ||
| 1440 | + </header> | ||
| 1441 | + if empty { | ||
| 1442 | + empty_state(title: g::t(lang, K::RetryNone)) | ||
| 1443 | + } else { | ||
| 1444 | + <div class="newrepo-card"> | ||
| 1445 | + <label> | ||
| 1446 | + <span>(g::t(lang, K::TokenOptional))</span> | ||
| 1447 | + <input type="password" name="token" autocomplete="new-password" maxlength="1024"> | ||
| 1448 | + </label> | ||
| 1449 | + <p class="muted small">(g::t(lang, K::RetryTokenHelp))</p> | ||
| 1450 | + </div> | ||
| 1451 | + <div class="newrepo-card import-pick"> | ||
| 1452 | + <label class="import-pick-row import-pick-all"> | ||
| 1453 | + <input type="checkbox" data-select-all=".import-pick-list"> | ||
| 1454 | + <span class="import-pick-main"> | ||
| 1455 | + <span class="import-pick-title">(g::t(lang, K::BulkSelectAll))</span> | ||
| 1456 | + </span> | ||
| 1457 | + <span class="muted small">(count)</span> | ||
| 1458 | + </label> | ||
| 1459 | + <ul class="import-pick-list"> | ||
| 1460 | + for (i, (job, repo)) in rows.iter().enumerate() { | ||
| 1461 | + <li> | ||
| 1462 | + <label class="import-pick-row"> | ||
| 1463 | + <input type="checkbox" name=(format!("sel_{i}")) value=(job.id.as_str())> | ||
| 1464 | + <span class="import-pick-main"> | ||
| 1465 | + <span class="import-pick-title"> | ||
| 1466 | + <span class="import-pick-name">(format!("{}/{}", repo.owner_name, repo.name))</span> | ||
| 1467 | + <span class="badge">(source_label(&job.source))</span> | ||
| 1468 | + </span> | ||
| 1469 | + <span class="muted small import-pick-desc">(job.source_ref.as_str())</span> | ||
| 1470 | + if let Some(message) = job.error.as_ref() { | ||
| 1471 | + <span class="muted small import-pick-desc">(message.as_str())</span> | ||
| 1472 | + } | ||
| 1473 | + </span> | ||
| 1474 | + </label> | ||
| 1475 | + </li> | ||
| 1476 | + } | ||
| 1477 | + </ul> | ||
| 1478 | + </div> | ||
| 1479 | + } | ||
| 1480 | + </form> | ||
| 1481 | + }) | ||
| 1482 | +} | ||
| 1483 | + | ||
| 1484 | +#[page("/import/retry")] | ||
| 1485 | +async fn retry_page(cx: &Cx) -> Result<impl View> { | ||
| 1486 | + let viewer = require_user(cx).await?; | ||
| 1487 | + let lang = i18n::lang(cx, Some(&viewer.0)); | ||
| 1488 | + let state = app_context::<AppState>(cx); | ||
| 1489 | + let rows = retry_candidates(state, &viewer.0).await?; | ||
| 1490 | + let csrf = viewer.1.csrf_token.clone(); | ||
| 1491 | + Ok(view! { cx => | ||
| 1492 | + shell(title: g::t(lang, K::RetryFailedTitle), viewer: Some(&viewer), | ||
| 1493 | + retry_list(lang: lang, csrf: csrf.as_str(), rows: rows)) | ||
| 1494 | + }) | ||
| 1495 | +} | ||
| 1496 | + | ||
| 1497 | +#[derive(Deserialize)] | ||
| 1498 | +struct RetrySelectedForm { | ||
| 1499 | + #[serde(default)] | ||
| 1500 | + csrf: String, | ||
| 1501 | + #[serde(default)] | ||
| 1502 | + token: String, | ||
| 1503 | + /// The ticked jobs arrive as `sel_0`, `sel_1`, ... with the job id as the value. | ||
| 1504 | + #[serde(flatten)] | ||
| 1505 | + extra: HashMap<String, String>, | ||
| 1506 | +} | ||
| 1507 | + | ||
| 1508 | +#[route(POST "/import/retry")] | ||
| 1509 | +async fn retry_submit(cx: &Cx, Form(form): Form<RetrySelectedForm>) -> Result<SeeOther> { | ||
| 1510 | + let viewer = require_csrf(cx, &form.csrf).await?; | ||
| 1511 | + let state = app_context::<AppState>(cx); | ||
| 1512 | + let mut picked: Vec<(usize, &String)> = form | ||
| 1513 | + .extra | ||
| 1514 | + .iter() | ||
| 1515 | + .filter_map(|(k, v)| Some((k.strip_prefix("sel_")?.parse::<usize>().ok()?, v))) | ||
| 1516 | + .collect(); | ||
| 1517 | + picked.sort_by_key(|(i, _)| *i); | ||
| 1518 | + if picked.is_empty() { | ||
| 1519 | + return Err(see_other("/import/retry").into()); | ||
| 1520 | + } | ||
| 1521 | + for (_, id) in picked { | ||
| 1522 | + // Only the viewer's own jobs; anything else is skipped without a word. | ||
| 1523 | + let Some(job) = state.store.import_job(id).await? else { | ||
| 1524 | + continue; | ||
| 1525 | + }; | ||
| 1526 | + if job.user_id != viewer.0.id { | ||
| 1527 | + continue; | ||
| 1528 | + } | ||
| 1529 | + retry_job(state, job, &form.token).await?; | ||
| 1530 | + } | ||
| 1531 | + Err(see_other("/import").into()) | ||
| 1532 | +} | ||
crates/forge-web/src/pages/mod.rsmodified+3 -1
| @@ -36,7 +36,6 @@ pub mod code_search; | |||
| 36 | pub mod commit; | 36 | pub mod commit; |
| 37 | pub mod commits; | 37 | pub mod commits; |
| 38 | pub mod compare; | 38 | pub mod compare; |
| 39 | -pub mod dashboard; | ||
| 40 | pub mod discussion_actions; | 39 | pub mod discussion_actions; |
| 41 | pub mod discussion_live; | 40 | pub mod discussion_live; |
| 42 | #[cfg(test)] | 41 | #[cfg(test)] |
| @@ -49,6 +48,7 @@ pub mod explore; | |||
| 49 | pub mod finder; | 48 | pub mod finder; |
| 50 | pub mod forgot; | 49 | pub mod forgot; |
| 51 | pub mod fork; | 50 | pub mod fork; |
| 51 | +pub mod home; | ||
| 52 | pub mod import; | 52 | pub mod import; |
| 53 | #[cfg(test)] | 53 | #[cfg(test)] |
| 54 | mod import_tests; | 54 | mod import_tests; |
| @@ -85,6 +85,7 @@ pub mod passkeys; | |||
| 85 | #[cfg(test)] | 85 | #[cfg(test)] |
| 86 | mod passkeys_tests; | 86 | mod passkeys_tests; |
| 87 | pub mod profile; | 87 | pub mod profile; |
| 88 | +pub mod profile_calendar; | ||
| 88 | pub mod profile_pins; | 89 | pub mod profile_pins; |
| 89 | pub mod pull_branch; | 90 | pub mod pull_branch; |
| 90 | pub mod pull_files; | 91 | pub mod pull_files; |
| @@ -142,5 +143,6 @@ pub mod snippets_live; | |||
| 142 | pub mod star; | 143 | pub mod star; |
| 143 | pub mod theme_cookie; | 144 | pub mod theme_cookie; |
| 144 | pub mod tree; | 145 | pub mod tree; |
| 146 | +pub mod user_prefs; | ||
| 145 | pub mod wiki; | 147 | pub mod wiki; |
| 146 | pub mod wiki_live; | 148 | pub mod wiki_live; |
crates/forge-web/src/pages/new_repo.rsmodified+18 -2
| @@ -10,7 +10,10 @@ use topcoat::Result; | |||
| 10 | use topcoat::context::{Cx, app_context}; | 10 | use topcoat::context::{Cx, app_context}; |
| 11 | use topcoat::router::content::Form; | 11 | use topcoat::router::content::Form; |
| 12 | use topcoat::router::error::see_other; | 12 | use topcoat::router::error::see_other; |
| 13 | -use topcoat::router::page; | 13 | +// Named by the `#[query_params]` attribute below, which the unused-import lint does not see. |
| 14 | +#[allow(unused_imports)] | ||
| 15 | +use topcoat::router::error::bad_request; | ||
| 16 | +use topcoat::router::{page, query_params}; | ||
| 14 | use topcoat::view::{View, component, view}; | 17 | use topcoat::view::{View, component, view}; |
| 15 | 18 | ||
| 16 | use crate::audit::{self, Actor, Target}; | 19 | use crate::audit::{self, Actor, Target}; |
| @@ -301,14 +304,27 @@ pub(crate) async fn owner_choices(state: &AppState, viewer: &User) -> Result<Vec | |||
| 301 | Ok(names) | 304 | Ok(names) |
| 302 | } | 305 | } |
| 303 | 306 | ||
| 307 | +/// `/new?owner=acme` preselects that owner. An owner the viewer cannot pick is ignored. | ||
| 308 | +#[query_params(error = bad_request)] | ||
| 309 | +struct NewRepoQuery { | ||
| 310 | + owner: Option<String>, | ||
| 311 | +} | ||
| 312 | + | ||
| 304 | #[page("/new")] | 313 | #[page("/new")] |
| 305 | async fn new_repo_page(cx: &Cx) -> Result<impl View> { | 314 | async fn new_repo_page(cx: &Cx) -> Result<impl View> { |
| 306 | let viewer = require_user(cx).await?; | 315 | let viewer = require_user(cx).await?; |
| 307 | let lang = i18n::lang(cx, Some(&viewer.0)); | 316 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 317 | + let wanted = query_params::<NewRepoQuery>(cx)?.owner.clone(); | ||
| 308 | let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?; | 318 | let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?; |
| 319 | + let mut draft = Draft::fresh(); | ||
| 320 | + if let Some(wanted) = wanted.as_deref() | ||
| 321 | + && let Some(owner) = owners.iter().find(|name| name.eq_ignore_ascii_case(wanted)) | ||
| 322 | + { | ||
| 323 | + draft.owner = owner.clone(); | ||
| 324 | + } | ||
| 309 | let csrf = viewer.1.csrf_token.clone(); | 325 | let csrf = viewer.1.csrf_token.clone(); |
| 310 | Ok(view! { cx => | 326 | Ok(view! { cx => |
| 311 | - shell(title: i18n::t(lang, Key::NewRepository), viewer: Some(&viewer), new_repo_form(lang: lang, csrf: csrf.as_str(), draft: Draft::fresh(), error: None, owners: owners)) | 327 | + 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)) |
| 312 | }) | 328 | }) |
| 313 | } | 329 | } |
| 314 | 330 | ||
crates/forge-web/src/pages/notifications.rsmodified+5 -5
| @@ -1545,18 +1545,18 @@ mod tests { | |||
| 1545 | } | 1545 | } |
| 1546 | 1546 | ||
| 1547 | #[tokio::test] | 1547 | #[tokio::test] |
| 1548 | - async fn sidebar_shows_the_unread_count() { | 1548 | + async fn corner_bell_shows_the_unread_count() { |
| 1549 | let site = site().await; | 1549 | let site = site().await; |
| 1550 | let w = world(&site, Visibility::Public).await; | 1550 | let w = world(&site, Visibility::Public).await; |
| 1551 | let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; | 1551 | let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; |
| 1552 | 1552 | ||
| 1553 | - let none = get(&site, "/", Some(&cookie)).await; | 1553 | + let none = get(&site, "/explore", Some(&cookie)).await; |
| 1554 | assert!(none.body.contains("href=\"/notifications\"")); | 1554 | assert!(none.body.contains("href=\"/notifications\"")); |
| 1555 | - assert!(!none.body.contains("<span class=\"count\">")); | 1555 | + assert!(!none.body.contains("<span class=\"bell-count\">")); |
| 1556 | 1556 | ||
| 1557 | notify(&site, &w, Reason::Mention).await; | 1557 | notify(&site, &w, Reason::Mention).await; |
| 1558 | - let one = get(&site, "/", Some(&cookie)).await; | 1558 | + let one = get(&site, "/explore", Some(&cookie)).await; |
| 1559 | - assert!(one.body.contains("<span class=\"count\">1</span>")); | 1559 | + assert!(one.body.contains("<span class=\"bell-count\">1</span>")); |
| 1560 | } | 1560 | } |
| 1561 | 1561 | ||
| 1562 | #[tokio::test] | 1562 | #[tokio::test] |
crates/forge-web/src/pages/org_ctx.rsmodified+2 -0
| @@ -56,6 +56,8 @@ pub const NOTICES: &[(&str, K, bool)] = &[ | |||
| 56 | ("has_repos", K::NoticeHasRepos, true), | 56 | ("has_repos", K::NoticeHasRepos, true), |
| 57 | ("confirm_name", K::NoticeConfirmName, true), | 57 | ("confirm_name", K::NoticeConfirmName, true), |
| 58 | ("description_length", K::NoticeDescriptionLength, true), | 58 | ("description_length", K::NoticeDescriptionLength, true), |
| 59 | + ("invalid_display_name", K::NoticeInvalidDisplayName, true), | ||
| 60 | + ("avatar_invalid", K::NoticeAvatarInvalid, true), | ||
| 59 | ]; | 61 | ]; |
| 60 | 62 | ||
| 61 | /// Roles a team can carry, in the order the selects show them. | 63 | /// Roles a team can carry, in the order the selects show them. |
crates/forge-web/src/pages/org_settings.rsmodified+189 -47
| @@ -1,6 +1,10 @@ | |||
| 1 | -//! Page: organization settings (`/org/{org}/settings`): the public description, the default role | 1 | +//! Page: organization settings (`/org/{org}/settings`): the display name, the avatar, the public |
| 2 | -//! members get on the org's repos, whether members may create repos, and deletion. Owners only: | 2 | +//! description, the default role members get on the org's repos, whether members may create repos, |
| 3 | -//! non-members get 404 and members who are not owners get 403. | 3 | +//! and deletion. Owners only: non-members get 404 and members who are not owners get 403. |
| 4 | +//! | ||
| 5 | +//! The avatar has its own routes under `/org/{org}/settings/avatar`, which take the same multipart | ||
| 6 | +//! form as a person's upload. Every write bumps the org's user topic through `OrgWriteLayer` | ||
| 7 | +//! (`org_live.rs`), so the profile page follows the change without a bump here. | ||
| 4 | 8 | ||
| 5 | use forge_core::AuditAction; | 9 | use forge_core::AuditAction; |
| 6 | use forge_core::store::orgs::{DefaultRepoRole, OrgSettings}; | 10 | use forge_core::store::orgs::{DefaultRepoRole, OrgSettings}; |
| @@ -8,20 +12,22 @@ use serde::Deserialize; | |||
| 8 | use topcoat::Result; | 12 | use topcoat::Result; |
| 9 | use topcoat::context::{Cx, app_context}; | 13 | use topcoat::context::{Cx, app_context}; |
| 10 | use topcoat::router::content::Form; | 14 | use topcoat::router::content::Form; |
| 15 | +use topcoat::router::content::multipart::Multipart; | ||
| 11 | use topcoat::router::error::{SeeOther, see_other}; | 16 | use topcoat::router::error::{SeeOther, see_other}; |
| 12 | use topcoat::router::{page, path_param, route}; | 17 | use topcoat::router::{page, path_param, route}; |
| 13 | use topcoat::view::{View, component, view}; | 18 | use topcoat::view::{View, component, view}; |
| 14 | 19 | ||
| 15 | use crate::audit::{self, Actor, Target}; | 20 | use crate::audit::{self, Actor, Target}; |
| 16 | use crate::i18n::orgs::{self as g, K}; | 21 | use crate::i18n::orgs::{self as g, K}; |
| 17 | -use crate::i18n::{self, Lang}; | 22 | +use crate::i18n::{self, Key, Lang, t}; |
| 18 | use crate::live::Topic; | 23 | use crate::live::Topic; |
| 19 | use crate::pages::org_ctx::{ | 24 | use crate::pages::org_ctx::{ |
| 20 | DEFAULT_ROLES, load_org, notice_href, org_head, org_notice, require_form_csrf, require_owner, | 25 | DEFAULT_ROLES, load_org, notice_href, org_head, org_notice, require_form_csrf, require_owner, |
| 21 | take_notice, | 26 | take_notice, |
| 22 | }; | 27 | }; |
| 28 | +use crate::pages::settings_profile::store_avatar; | ||
| 23 | use crate::state::AppState; | 29 | use crate::state::AppState; |
| 24 | -use crate::views::shell; | 30 | +use crate::views::{avatar_url, shell, user_facing_message}; |
| 25 | 31 | ||
| 26 | path_param!(org); | 32 | path_param!(org); |
| 27 | 33 | ||
| @@ -31,6 +37,9 @@ const MAX_DESCRIPTION_CHARS: usize = 2000; | |||
| 31 | struct SettingsForm { | 37 | struct SettingsForm { |
| 32 | #[serde(default)] | 38 | #[serde(default)] |
| 33 | csrf: String, | 39 | csrf: String, |
| 40 | + /// The org's display name. Empty clears it. | ||
| 41 | + #[serde(default)] | ||
| 42 | + display_name: String, | ||
| 34 | #[serde(default)] | 43 | #[serde(default)] |
| 35 | description: String, | 44 | description: String, |
| 36 | #[serde(default)] | 45 | #[serde(default)] |
| @@ -40,6 +49,12 @@ struct SettingsForm { | |||
| 40 | members_can_create: String, | 49 | members_can_create: String, |
| 41 | } | 50 | } |
| 42 | 51 | ||
| 52 | +#[derive(Deserialize)] | ||
| 53 | +struct CsrfForm { | ||
| 54 | + #[serde(default)] | ||
| 55 | + csrf: String, | ||
| 56 | +} | ||
| 57 | + | ||
| 43 | #[derive(Deserialize)] | 58 | #[derive(Deserialize)] |
| 44 | struct DeleteForm { | 59 | struct DeleteForm { |
| 45 | #[serde(default)] | 60 | #[serde(default)] |
| @@ -52,7 +67,10 @@ struct DeleteForm { | |||
| 52 | #[component] | 67 | #[component] |
| 53 | async fn settings_body( | 68 | async fn settings_body( |
| 54 | name: String, | 69 | name: String, |
| 70 | + display_name: String, | ||
| 55 | description: String, | 71 | description: String, |
| 72 | + has_avatar: bool, | ||
| 73 | + avatar_src: String, | ||
| 56 | base: String, | 74 | base: String, |
| 57 | csrf: String, | 75 | csrf: String, |
| 58 | default_role: String, | 76 | default_role: String, |
| @@ -62,52 +80,88 @@ async fn settings_body( | |||
| 62 | live: String, | 80 | live: String, |
| 63 | ) -> Result<impl View> { | 81 | ) -> Result<impl View> { |
| 64 | let save_action = format!("{base}/settings"); | 82 | let save_action = format!("{base}/settings"); |
| 83 | + let avatar_action = format!("{base}/settings/avatar"); | ||
| 84 | + let avatar_remove_action = format!("{base}/settings/avatar/delete"); | ||
| 65 | let delete_action = format!("{base}/settings/delete"); | 85 | let delete_action = format!("{base}/settings/delete"); |
| 66 | let confirm_label = g::type_to_confirm(lang, &name); | 86 | let confirm_label = g::type_to_confirm(lang, &name); |
| 67 | Ok(view! { | 87 | Ok(view! { |
| 68 | <div data-live=(live.as_str())> | 88 | <div data-live=(live.as_str())> |
| 69 | org_head(name: name, description: description.clone()) | 89 | org_head(name: name, description: description.clone()) |
| 70 | org_notice(notice: notice) | 90 | org_notice(notice: notice) |
| 71 | - <section class="card"> | 91 | + <div class="org-settings-grid"> |
| 72 | - <h2>(g::t(lang, K::Settings))</h2> | 92 | + <section class="card"> |
| 73 | - <form method="post" action=(save_action.as_str()) class="stack"> | 93 | + <h2>(g::t(lang, K::Settings))</h2> |
| 74 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | 94 | + <form method="post" action=(save_action.as_str()) class="stack"> |
| 75 | - <label> | 95 | + <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 76 | - <span>(g::t(lang, K::Description))</span> | 96 | + <label> |
| 77 | - <textarea name="description" rows="3" maxlength="2000">(description.as_str())</textarea> | 97 | + <span>(g::t(lang, K::DisplayNameLabel))</span> |
| 78 | - </label> | 98 | + <input type="text" name="display_name" maxlength="80" value=(display_name.as_str())> |
| 79 | - <label> | 99 | + </label> |
| 80 | - <span>(g::t(lang, K::DefaultRoleLabel))</span> | 100 | + <label> |
| 81 | - <select name="default_repo_role"> | 101 | + <span>(g::t(lang, K::Description))</span> |
| 82 | - for choice in DEFAULT_ROLES.iter() { | 102 | + <textarea name="description" rows="2" maxlength="2000">(description.as_str())</textarea> |
| 83 | - <option value=(*choice) selected=(*choice == default_role.as_str())>(g::role_name(lang, choice))</option> | 103 | + </label> |
| 84 | - } | 104 | + <label> |
| 85 | - </select> | 105 | + <span>(g::t(lang, K::DefaultRoleLabel))</span> |
| 86 | - </label> | 106 | + <select name="default_repo_role"> |
| 87 | - <p class="muted small">(g::t(lang, K::DefaultRoleHelp))</p> | 107 | + for choice in DEFAULT_ROLES.iter() { |
| 88 | - <label class="inline"> | 108 | + <option value=(*choice) selected=(*choice == default_role.as_str())>(g::role_name(lang, choice))</option> |
| 89 | - <input type="checkbox" name="members_can_create" value="on" checked=(members_can_create)> | 109 | + } |
| 90 | - <span>(g::t(lang, K::MembersCanCreate))</span> | 110 | + </select> |
| 91 | - </label> | 111 | + </label> |
| 92 | - <div> | 112 | + <p class="muted small">(g::t(lang, K::DefaultRoleHelp))</p> |
| 93 | - <button type="submit" class="primary">(g::t(lang, K::SaveSettings))</button> | 113 | + <label class="inline"> |
| 94 | - </div> | 114 | + <input type="checkbox" name="members_can_create" value="on" checked=(members_can_create)> |
| 95 | - </form> | 115 | + <span>(g::t(lang, K::MembersCanCreate))</span> |
| 96 | - </section> | 116 | + </label> |
| 97 | - <section class="card"> | 117 | + <div> |
| 98 | - <h2>(g::t(lang, K::DeleteOrg))</h2> | 118 | + <button type="submit" class="primary">(g::t(lang, K::SaveSettings))</button> |
| 99 | - <p class="muted small">(g::t(lang, K::DeleteOrgIntro))</p> | 119 | + </div> |
| 100 | - <form method="post" action=(delete_action.as_str()) class="stack"> | 120 | + </form> |
| 101 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | 121 | + </section> |
| 102 | - <label> | 122 | + <div class="stack"> |
| 103 | - <span>(confirm_label.as_str())</span> | 123 | + <section class="card"> |
| 104 | - <input type="text" name="confirm" autocomplete="off" spellcheck="false" required=(true)> | 124 | + <h2>(t(lang, Key::Avatar))</h2> |
| 105 | - </label> | 125 | + <aside class="profile-settings-avatar" aria-label=(t(lang, Key::Avatar))> |
| 106 | - <div> | 126 | + <div class="profile-settings-avatar-frame"> |
| 107 | - <button type="submit" class="danger">(g::t(lang, K::DeleteOrg))</button> | 127 | + <img class="avatar profile-settings-avatar-img" src=(avatar_src.as_str()) alt=(t(lang, Key::AvatarAlt)) width="180" height="180"> |
| 108 | - </div> | 128 | + <details class="menu profile-settings-avatar-menu"> |
| 109 | - </form> | 129 | + <summary>(t(lang, Key::Edit))</summary> |
| 110 | - </section> | 130 | + <div class="menu-list profile-settings-avatar-list"> |
| 131 | + <form method="post" action=(avatar_action.as_str()) enctype="multipart/form-data" class="profile-settings-avatar-upload"> | ||
| 132 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 133 | + <input class="profile-settings-avatar-file" type="file" id="org-settings-avatar-file" name="avatar" aria-label=(t(lang, Key::Image)) accept="image/png,image/jpeg,image/webp,image/gif" required=(true)> | ||
| 134 | + <label class="profile-settings-avatar-item" for="org-settings-avatar-file">(t(lang, Key::UploadPhoto))</label> | ||
| 135 | + <button type="submit" class="primary">(t(lang, Key::Upload))</button> | ||
| 136 | + </form> | ||
| 137 | + if has_avatar { | ||
| 138 | + <form method="post" action=(avatar_remove_action.as_str()) class="profile-settings-avatar-remove"> | ||
| 139 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 140 | + <button type="submit" class="link-button">(t(lang, Key::RemovePhoto))</button> | ||
| 141 | + </form> | ||
| 142 | + } | ||
| 143 | + </div> | ||
| 144 | + </details> | ||
| 145 | + </div> | ||
| 146 | + <small class="muted">(t(lang, Key::AvatarHint))</small> | ||
| 147 | + </aside> | ||
| 148 | + </section> | ||
| 149 | + <section class="card"> | ||
| 150 | + <h2>(g::t(lang, K::DeleteOrg))</h2> | ||
| 151 | + <p class="muted small">(g::t(lang, K::DeleteOrgIntro))</p> | ||
| 152 | + <form method="post" action=(delete_action.as_str()) class="stack"> | ||
| 153 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 154 | + <label> | ||
| 155 | + <span>(confirm_label.as_str())</span> | ||
| 156 | + <input type="text" name="confirm" autocomplete="off" spellcheck="false" required=(true)> | ||
| 157 | + </label> | ||
| 158 | + <div> | ||
| 159 | + <button type="submit" class="danger">(g::t(lang, K::DeleteOrg))</button> | ||
| 160 | + </div> | ||
| 161 | + </form> | ||
| 162 | + </section> | ||
| 163 | + </div> | ||
| 164 | + </div> | ||
| 111 | </div> | 165 | </div> |
| 112 | }) | 166 | }) |
| 113 | } | 167 | } |
| @@ -122,21 +176,27 @@ async fn org_settings_page(cx: &Cx) -> Result<impl View> { | |||
| 122 | let settings = state.store.org_settings(&ctx.org.id).await?; | 176 | let settings = state.store.org_settings(&ctx.org.id).await?; |
| 123 | let default_role = settings.default_repo_role.as_str().to_owned(); | 177 | let default_role = settings.default_repo_role.as_str().to_owned(); |
| 124 | let members_can_create = settings.members_can_create_repos; | 178 | let members_can_create = settings.members_can_create_repos; |
| 179 | + let avatar = state.store.avatar_hash(&ctx.org.id).await?; | ||
| 180 | + let has_avatar = avatar.is_some(); | ||
| 181 | + let avatar_src = avatar_url(&ctx.org.username, avatar.as_deref()); | ||
| 125 | let notice = take_notice(cx, lang); | 182 | let notice = take_notice(cx, lang); |
| 126 | let title = g::page_title(lang, &ctx.org.username, K::Settings); | 183 | let title = g::page_title(lang, &ctx.org.username, K::Settings); |
| 127 | let name = ctx.org.username.clone(); | 184 | let name = ctx.org.username.clone(); |
| 185 | + let display_name = ctx.org.display_name.clone().unwrap_or_default(); | ||
| 128 | let description = ctx.org.about.clone(); | 186 | let description = ctx.org.about.clone(); |
| 129 | let base = ctx.href(""); | 187 | let base = ctx.href(""); |
| 130 | let csrf = ctx.viewer.1.csrf_token.clone(); | 188 | let csrf = ctx.viewer.1.csrf_token.clone(); |
| 131 | let live = ctx.href("/settings/events"); | 189 | let live = ctx.href("/settings/events"); |
| 132 | Ok(view! { cx => | 190 | Ok(view! { cx => |
| 133 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), | 191 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 134 | - settings_body(name: name, description: description, base: base, csrf: csrf, | 192 | + settings_body(name: name, display_name: display_name, description: description, |
| 193 | + has_avatar: has_avatar, avatar_src: avatar_src, base: base, csrf: csrf, | ||
| 135 | default_role: default_role, members_can_create: members_can_create, notice: notice, lang: lang, live: live)) | 194 | default_role: default_role, members_can_create: members_can_create, notice: notice, lang: lang, live: live)) |
| 136 | }) | 195 | }) |
| 137 | } | 196 | } |
| 138 | 197 | ||
| 139 | -/// Saves the description and the org settings. Owners only. | 198 | +/// Saves the display name, the description and the org settings. Owners only. A display name the |
| 199 | +/// store refuses redirects with a notice before anything is written. | ||
| 140 | #[route(POST "/org/{org}/settings")] | 200 | #[route(POST "/org/{org}/settings")] |
| 141 | async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<SeeOther> { | 201 | async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<SeeOther> { |
| 142 | let ctx = load_org(cx, path_param::<Org>(cx)).await?; | 202 | let ctx = load_org(cx, path_param::<Org>(cx)).await?; |
| @@ -154,6 +214,17 @@ async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Se | |||
| 154 | }; | 214 | }; |
| 155 | let members_can_create_repos = !form.members_can_create.is_empty(); | 215 | let members_can_create_repos = !form.members_can_create.is_empty(); |
| 156 | 216 | ||
| 217 | + match state | ||
| 218 | + .store | ||
| 219 | + .set_display_name(&ctx.org.id, form.display_name.trim()) | ||
| 220 | + .await | ||
| 221 | + { | ||
| 222 | + Ok(()) => {} | ||
| 223 | + Err(forge_core::Error::Invalid(_)) => { | ||
| 224 | + return Ok(see_other(notice_href(&back, "invalid_display_name"))); | ||
| 225 | + } | ||
| 226 | + Err(e) => return Err(e.into()), | ||
| 227 | + } | ||
| 157 | state | 228 | state |
| 158 | .store | 229 | .store |
| 159 | .set_org_settings( | 230 | .set_org_settings( |
| @@ -187,6 +258,77 @@ async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Se | |||
| 187 | Ok(see_other(notice_href(&back, "settings_saved"))) | 258 | Ok(see_other(notice_href(&back, "settings_saved"))) |
| 188 | } | 259 | } |
| 189 | 260 | ||
| 261 | +/// Uploads the org's avatar. Owners only. The multipart fields are read as the person's upload | ||
| 262 | +/// reads them, then the CSRF token and the role are checked before the image is decoded. | ||
| 263 | +#[route(POST "/org/{org}/settings/avatar")] | ||
| 264 | +async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther> { | ||
| 265 | + let mut csrf = String::new(); | ||
| 266 | + let mut image = None; | ||
| 267 | + while let Some(field) = multipart.next_field().await? { | ||
| 268 | + let name = field.name().map(str::to_owned); | ||
| 269 | + match name.as_deref() { | ||
| 270 | + Some("csrf") => csrf = field.text().await?, | ||
| 271 | + Some("avatar") => image = Some(field.bytes().await?.to_vec()), | ||
| 272 | + _ => {} | ||
| 273 | + } | ||
| 274 | + } | ||
| 275 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 276 | + require_form_csrf(&ctx, &csrf)?; | ||
| 277 | + require_owner(&ctx)?; | ||
| 278 | + let state = app_context::<AppState>(cx); | ||
| 279 | + let lang = i18n::lang(cx, Some(&ctx.viewer.0)); | ||
| 280 | + let back = ctx.href("/settings"); | ||
| 281 | + | ||
| 282 | + match store_avatar(&state.store, &ctx.org.id, image, lang).await { | ||
| 283 | + Ok(()) => { | ||
| 284 | + audit::record( | ||
| 285 | + &state.store, | ||
| 286 | + Some(cx), | ||
| 287 | + Actor::User(&ctx.viewer.0), | ||
| 288 | + AuditAction::OrgSettingsUpdated, | ||
| 289 | + Target { | ||
| 290 | + kind: "org", | ||
| 291 | + id: &ctx.org.id, | ||
| 292 | + name: &ctx.org.username, | ||
| 293 | + }, | ||
| 294 | + serde_json::json!({ "avatar": "updated" }), | ||
| 295 | + ) | ||
| 296 | + .await; | ||
| 297 | + Ok(see_other(notice_href(&back, "settings_saved"))) | ||
| 298 | + } | ||
| 299 | + Err(e) if user_facing_message(&e).is_some() => { | ||
| 300 | + Ok(see_other(notice_href(&back, "avatar_invalid"))) | ||
| 301 | + } | ||
| 302 | + Err(e) => Err(e.into()), | ||
| 303 | + } | ||
| 304 | +} | ||
| 305 | + | ||
| 306 | +/// Removes the org's avatar. Owners only. | ||
| 307 | +#[route(POST "/org/{org}/settings/avatar/delete")] | ||
| 308 | +async fn org_avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | ||
| 309 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 310 | + require_form_csrf(&ctx, &form.csrf)?; | ||
| 311 | + require_owner(&ctx)?; | ||
| 312 | + let state = app_context::<AppState>(cx); | ||
| 313 | + let back = ctx.href("/settings"); | ||
| 314 | + | ||
| 315 | + state.store.delete_avatar(&ctx.org.id).await?; | ||
| 316 | + audit::record( | ||
| 317 | + &state.store, | ||
| 318 | + Some(cx), | ||
| 319 | + Actor::User(&ctx.viewer.0), | ||
| 320 | + AuditAction::OrgSettingsUpdated, | ||
| 321 | + Target { | ||
| 322 | + kind: "org", | ||
| 323 | + id: &ctx.org.id, | ||
| 324 | + name: &ctx.org.username, | ||
| 325 | + }, | ||
| 326 | + serde_json::json!({ "avatar": "removed" }), | ||
| 327 | + ) | ||
| 328 | + .await; | ||
| 329 | + Ok(see_other(notice_href(&back, "settings_saved"))) | ||
| 330 | +} | ||
| 331 | + | ||
| 190 | /// Deletes the org. Owners only, and the name must be typed again. Refused while the org owns | 332 | /// Deletes the org. Owners only, and the name must be typed again. Refused while the org owns |
| 191 | /// repositories; then the settings page says so. | 333 | /// repositories; then the settings page says so. |
| 192 | #[route(POST "/org/{org}/settings/delete")] | 334 | #[route(POST "/org/{org}/settings/delete")] |
crates/forge-web/src/pages/palette.rsmodified+2 -4
| @@ -1,6 +1,6 @@ | |||
| 1 | //! The command palette's destinations: `GET /-/palette` lists what the signed-in viewer can jump to, | 1 | //! The command palette's destinations: `GET /-/palette` lists what the signed-in viewer can jump to, |
| 2 | -//! their repos, the orgs they belong to and the fixed pages (the sidebar's links, the settings pages | 2 | +//! their repos, the orgs they belong to and the fixed pages (Explore, notifications, snippets, new |
| 3 | -//! and, for admins, the admin pages). The palette itself, its filtering and keys live in | 3 | +//! repository and settings, and for admins the admin pages). The palette itself, its filtering and keys live in |
| 4 | //! `assets/nav.js`. | 4 | //! `assets/nav.js`. |
| 5 | 5 | ||
| 6 | use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS}; | 6 | use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS}; |
| @@ -12,7 +12,6 @@ use topcoat::router::{Body, HeaderValue, StatusCode, route}; | |||
| 12 | 12 | ||
| 13 | use crate::auth::current_user; | 13 | use crate::auth::current_user; |
| 14 | use crate::i18n::community::{self as cm, K as CK}; | 14 | use crate::i18n::community::{self as cm, K as CK}; |
| 15 | -use crate::i18n::orgs::{self as o, K as OK}; | ||
| 16 | use crate::i18n::{self, Key, t}; | 15 | use crate::i18n::{self, Key, t}; |
| 17 | use crate::state::AppState; | 16 | use crate::state::AppState; |
| 18 | use crate::views::{admin_items, repo_href, settings_items, user_href}; | 17 | use crate::views::{admin_items, repo_href, settings_items, user_href}; |
| @@ -47,7 +46,6 @@ async fn palette(cx: &Cx) -> Result<Response> { | |||
| 47 | items.push(destination(&org.username, &user_href(&org.username), "org")); | 46 | items.push(destination(&org.username, &user_href(&org.username), "org")); |
| 48 | } | 47 | } |
| 49 | 48 | ||
| 50 | - items.push(destination(o::t(lang, OK::Dashboard), "/", "page")); | ||
| 51 | items.push(destination(t(lang, Key::Explore), "/explore", "page")); | 49 | items.push(destination(t(lang, Key::Explore), "/explore", "page")); |
| 52 | items.push(destination(t(lang, Key::Notifications), "/notifications", "page")); | 50 | items.push(destination(t(lang, Key::Notifications), "/notifications", "page")); |
| 53 | items.push(destination(cm::t(lang, CK::Snippets), "/snippets", "page")); | 51 | items.push(destination(cm::t(lang, CK::Snippets), "/snippets", "page")); |
crates/forge-web/src/pages/profile.rsmodified+228 -17
| @@ -1,9 +1,10 @@ | |||
| 1 | //! Page: public profile at `/{username}`. Avatar, about (rendered markdown) and local time, then | 1 | //! Page: public profile at `/{username}`. Avatar, about (rendered markdown) and local time, then |
| 2 | -//! three tabs: `overview` (pinned repos, or the most recently active ones when nothing is pinned, | 2 | +//! the tabs: `overview` (pinned repos, or the most recently active ones when nothing is pinned, |
| 3 | -//! plus an organization's members and teams), `repositories` and `stars`. The repo tabs list what | 3 | +//! plus an organization's members and teams, or a person's contribution calendar), `repositories`, |
| 4 | -//! the viewer is allowed to read, 30 per page, with a name filter and three sort orders; the | 4 | +//! `snippets` (people only), `stars`, `packages` and `organizations` (the viewer's own only). The |
| 5 | -//! filtering, sorting and paging run in the database. Fixed single-segment routes are registered | 5 | +//! repo tabs list what the viewer is allowed to read, 30 per page, with a name filter and three |
| 6 | -//! statically, so they win over this parameter route. | 6 | +//! sort orders; the filtering, sorting and paging run in the database. Fixed single-segment routes |
| 7 | +//! are registered statically, so they win over this parameter route. | ||
| 7 | 8 | ||
| 8 | use forge_core::authz::{Action, authorize}; | 9 | use forge_core::authz::{Action, authorize}; |
| 9 | use forge_core::store::RepoSort; | 10 | use forge_core::store::RepoSort; |
| @@ -20,17 +21,22 @@ use topcoat::router::{page, path_param, query_params, route}; | |||
| 20 | use topcoat::view::{Unescaped, View, component, view}; | 21 | use topcoat::view::{Unescaped, View, component, view}; |
| 21 | 22 | ||
| 22 | use crate::auth::current_user; | 23 | use crate::auth::current_user; |
| 24 | +use crate::i18n::community::{self as cm, K as CK}; | ||
| 23 | use crate::i18n::misc::{self as mi, K as MK}; | 25 | use crate::i18n::misc::{self as mi, K as MK}; |
| 24 | use crate::i18n::orgs::{self as g, K}; | 26 | use crate::i18n::orgs::{self as g, K}; |
| 25 | use crate::i18n::packages::{self as pk, K as PK}; | 27 | use crate::i18n::packages::{self as pk, K as PK}; |
| 26 | use crate::i18n::{self, Lang}; | 28 | use crate::i18n::{self, Lang}; |
| 27 | use crate::live::{Topic, stream_changes}; | 29 | use crate::live::{Topic, stream_changes}; |
| 28 | -use crate::pages::dashboard::badge_class; | 30 | +use crate::pages::org_new::may_create_org; |
| 29 | use crate::pages::packages::{self as packages, PackageRow}; | 31 | use crate::pages::packages::{self as packages, PackageRow}; |
| 32 | +use crate::pages::repo_settings::{notice_banner_for, take_notice}; | ||
| 33 | +use crate::pages::profile_calendar::{calendar_since, load_calendar}; | ||
| 34 | +use crate::pages::snippets::{ListRow, list_row, snippet_rows}; | ||
| 30 | use crate::render::markdown::render_markdown; | 35 | use crate::render::markdown::render_markdown; |
| 31 | use crate::state::AppState; | 36 | use crate::state::AppState; |
| 37 | +use crate::views::heatmap::{Calendar, DayDetail, contribution_calendar}; | ||
| 32 | use crate::views::repo_list::{ | 38 | use crate::views::repo_list::{ |
| 33 | - PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips, | 39 | + PageLink, RepoRow, SortLink, badge_class, pager, pager_links, repo_rows, sort_chips, |
| 34 | }; | 40 | }; |
| 35 | use crate::views::{avatar_url, empty_state, enc, now_unix, repo_href, shell}; | 41 | use crate::views::{avatar_url, empty_state, enc, now_unix, repo_href, shell}; |
| 36 | 42 | ||
| @@ -49,6 +55,8 @@ struct ProfileQuery { | |||
| 49 | q: Option<String>, | 55 | q: Option<String>, |
| 50 | sort: Option<String>, | 56 | sort: Option<String>, |
| 51 | page: Option<String>, | 57 | page: Option<String>, |
| 58 | + /// A calendar day whose contributions to list under the calendar on the overview. | ||
| 59 | + day: Option<String>, | ||
| 52 | } | 60 | } |
| 53 | 61 | ||
| 54 | /// Sort keys of the repo tabs in the order their chips are shown, with the label of each. The | 62 | /// Sort keys of the repo tabs in the order their chips are shown, with the label of each. The |
| @@ -89,7 +97,18 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 89 | 97 | ||
| 90 | let actor = viewer.as_ref().map(|(u, _)| u); | 98 | let actor = viewer.as_ref().map(|(u, _)| u); |
| 91 | let lang = i18n::lang(cx, actor); | 99 | let lang = i18n::lang(cx, actor); |
| 100 | + // Whether the viewer is this person. Only the person sees their Organizations tab and edit links. | ||
| 101 | + let own =!user.is_org() && actor.is_some_and(|u| u.id == user.id); | ||
| 102 | + // An organization cannot be starred or keep snippets, so those tabs show the overview instead. | ||
| 103 | + // The Organizations tab is the viewer's own, so anyone else gets the overview. | ||
| 92 | let tab = tab_key(query.tab.as_deref()); | 104 | let tab = tab_key(query.tab.as_deref()); |
| 105 | + let tab = if (user.is_org() && matches!(tab, "stars" | "snippets")) | ||
| 106 | + || (tab == "organizations" && !own) | ||
| 107 | + { | ||
| 108 | + "overview" | ||
| 109 | + } else { | ||
| 110 | + tab | ||
| 111 | + }; | ||
| 93 | let q: String = query | 112 | let q: String = query |
| 94 | .q | 113 | .q |
| 95 | .as_deref() | 114 | .as_deref() |
| @@ -135,11 +154,23 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 135 | } | 154 | } |
| 136 | } | 155 | } |
| 137 | 156 | ||
| 157 | + // The viewer's role in an organization, looked up once for the header, the tabs and the pins. | ||
| 158 | + let org_role = match actor { | ||
| 159 | + Some(u) if user.is_org() => state.store.org_member_role(&user.id, &u.id).await?, | ||
| 160 | + _ => None, | ||
| 161 | + }; | ||
| 162 | + let org_owner = org_role == Some(OrgMemberRole::Owner); | ||
| 163 | + let org_member = org_role.is_some(); | ||
| 164 | + let org_can_create = match actor { | ||
| 165 | + Some(u) if org_member => { | ||
| 166 | + crate::pages::org_ctx::may_create_repo_in(state, &user.id, &u.id).await? | ||
| 167 | + } | ||
| 168 | + _ => false, | ||
| 169 | + }; | ||
| 170 | + | ||
| 138 | // An organization's pins are edited by its owners, a user's by the user. | 171 | // An organization's pins are edited by its owners, a user's by the user. |
| 139 | let can_edit_pins = match actor { | 172 | let can_edit_pins = match actor { |
| 140 | - Some(u) if user.is_org() => { | 173 | + Some(_) if user.is_org() => org_owner, |
| 141 | - state.store.org_member_role(&user.id, &u.id).await? == Some(OrgMemberRole::Owner) | ||
| 142 | - } | ||
| 143 | Some(u) => u.id == user.id, | 174 | Some(u) => u.id == user.id, |
| 144 | None => false, | 175 | None => false, |
| 145 | }; | 176 | }; |
| @@ -150,7 +181,54 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 150 | "/settings/pins".to_owned() | 181 | "/settings/pins".to_owned() |
| 151 | } | 182 | } |
| 152 | }); | 183 | }); |
| 153 | - let edit_profile = !user.is_org() && actor.is_some_and(|u| u.id == user.id); | 184 | + |
| 185 | + // The overview's contribution calendar, for a person only. Its counts and day links use public | ||
| 186 | + // repos alone, so anyone may see it. | ||
| 187 | + let heat = if tab == "overview" && !user.is_org() { | ||
| 188 | + Some(load_calendar(state, &user, query.day.as_deref()).await?) | ||
| 189 | + } else { | ||
| 190 | + None | ||
| 191 | + }; | ||
| 192 | + | ||
| 193 | + // The Snippets tab lists the person's snippets the viewer may read. An organization keeps none. | ||
| 194 | + let snippets: Vec<ListRow> = if user.is_org() { | ||
| 195 | + Vec::new() | ||
| 196 | + } else { | ||
| 197 | + state | ||
| 198 | + .store | ||
| 199 | + .list_owner_snippets(&user.id, actor.map(|u| u.id.as_str())) | ||
| 200 | + .await? | ||
| 201 | + .into_iter() | ||
| 202 | + .map(|summary| list_row(lang, summary)) | ||
| 203 | + .collect() | ||
| 204 | + }; | ||
| 205 | + | ||
| 206 | + // The viewer's Organizations tab lists the organizations they belong to, and whether the | ||
| 207 | + // instance lets them create one. | ||
| 208 | + let (orgs, org_create_allowed) = match actor { | ||
| 209 | + Some(viewer_user) if tab == "organizations" => { | ||
| 210 | + let mut cards = Vec::new(); | ||
| 211 | + for (org, role) in state.store.orgs_for_user(&user.id).await? { | ||
| 212 | + let hash = state.store.avatar_hash(&org.id).await?; | ||
| 213 | + cards.push(OrgCard { | ||
| 214 | + href: format!("/{}", enc(&org.username)), | ||
| 215 | + avatar: avatar_url(&org.username, hash.as_deref()), | ||
| 216 | + name: org.username, | ||
| 217 | + display_name: org.display_name.unwrap_or_default(), | ||
| 218 | + role: g::t( | ||
| 219 | + lang, | ||
| 220 | + if role == OrgMemberRole::Owner { | ||
| 221 | + K::RoleOwner | ||
| 222 | + } else { | ||
| 223 | + K::RoleMember | ||
| 224 | + }, | ||
| 225 | + ), | ||
| 226 | + }); | ||
| 227 | + } | ||
| 228 | + (cards, may_create_org(state, viewer_user)) | ||
| 229 | + } | ||
| 230 | + _ => (Vec::new(), false), | ||
| 231 | + }; | ||
| 154 | 232 | ||
| 155 | let listing = match tab { | 233 | let listing = match tab { |
| 156 | "repositories" | "stars" => { | 234 | "repositories" | "stars" => { |
| @@ -223,14 +301,20 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 223 | let package_rows = packages::package_rows(state, actor, &user).await?; | 301 | let package_rows = packages::package_rows(state, actor, &user).await?; |
| 224 | let packages_on = tab == "packages"; | 302 | let packages_on = tab == "packages"; |
| 225 | 303 | ||
| 304 | + // A repo deleted just before this redirect here shows its one-line notice once. | ||
| 305 | + let notice = take_notice(cx); | ||
| 226 | let title = user.username.clone(); | 306 | let title = user.username.clone(); |
| 227 | Ok(view! { cx => | 307 | Ok(view! { cx => |
| 228 | shell(title: title.as_str(), viewer: viewer.as_ref(), | 308 | shell(title: title.as_str(), viewer: viewer.as_ref(), |
| 309 | + notice_banner_for(lang: lang, title: notice) | ||
| 229 | profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time, | 310 | profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time, |
| 230 | org: org, lang: lang, tab: tab.to_owned(), q: q, sort: sort, repo_total: repo_total, | 311 | org: org, lang: lang, tab: tab.to_owned(), q: q, sort: sort, repo_total: repo_total, |
| 231 | star_total: star_total, cards: cards, from_pins: from_pins, | 312 | star_total: star_total, cards: cards, from_pins: from_pins, |
| 232 | - pins_edit_href: pins_edit_href, edit_profile: edit_profile, listing: listing, | 313 | + pins_edit_href: pins_edit_href, edit_profile: own, listing: listing, |
| 233 | - packages_on: packages_on, package_rows: package_rows)) | 314 | + packages_on: packages_on, package_rows: package_rows, |
| 315 | + org_member: org_member, org_owner: org_owner, org_can_create: org_can_create, | ||
| 316 | + heat: heat, snippets: snippets, orgs: orgs, org_create_allowed: org_create_allowed, | ||
| 317 | + own_profile: own)) | ||
| 234 | }) | 318 | }) |
| 235 | } | 319 | } |
| 236 | 320 | ||
| @@ -293,6 +377,16 @@ async fn profile_fingerprint( | |||
| 293 | let members = state.store.org_members(&user.id).await?.len(); | 377 | let members = state.store.org_members(&user.id).await?.len(); |
| 294 | let teams = state.store.teams_for_org(&user.id).await?.len(); | 378 | let teams = state.store.teams_for_org(&user.id).await?.len(); |
| 295 | lines.push(format!("org {members} {teams}")); | 379 | lines.push(format!("org {members} {teams}")); |
| 380 | + } else { | ||
| 381 | + // A person's overview shows the contribution calendar, so its total moves with each one. | ||
| 382 | + let total: u64 = state | ||
| 383 | + .store | ||
| 384 | + .contribution_counts(&user.id, &calendar_since(), &user.timezone) | ||
| 385 | + .await? | ||
| 386 | + .iter() | ||
| 387 | + .map(|(_, count)| u64::from(*count)) | ||
| 388 | + .sum(); | ||
| 389 | + lines.push(format!("calendar {total}")); | ||
| 296 | } | 390 | } |
| 297 | let pins = readable( | 391 | let pins = readable( |
| 298 | state, | 392 | state, |
| @@ -330,6 +424,16 @@ struct PinCard { | |||
| 330 | stars: u64, | 424 | stars: u64, |
| 331 | } | 425 | } |
| 332 | 426 | ||
| 427 | +/// One organization on the viewer's own Organizations tab, with its strings ready for the view. | ||
| 428 | +struct OrgCard { | ||
| 429 | + href: String, | ||
| 430 | + avatar: String, | ||
| 431 | + name: String, | ||
| 432 | + /// Empty when the organization has no display name. | ||
| 433 | + display_name: String, | ||
| 434 | + role: &'static str, | ||
| 435 | +} | ||
| 436 | + | ||
| 333 | /// One page of a repo tab: the rows, the pager, the sort chips, the match count text and the | 437 | /// One page of a repo tab: the rows, the pager, the sort chips, the match count text and the |
| 334 | /// empty-list text. | 438 | /// empty-list text. |
| 335 | #[derive(Default)] | 439 | #[derive(Default)] |
| @@ -347,8 +451,10 @@ struct Listing { | |||
| 347 | fn tab_key(raw: Option<&str>) -> &'static str { | 451 | fn tab_key(raw: Option<&str>) -> &'static str { |
| 348 | match raw { | 452 | match raw { |
| 349 | Some("repositories") => "repositories", | 453 | Some("repositories") => "repositories", |
| 454 | + Some("snippets") => "snippets", | ||
| 350 | Some("stars") => "stars", | 455 | Some("stars") => "stars", |
| 351 | Some("packages") => "packages", | 456 | Some("packages") => "packages", |
| 457 | + Some("organizations") => "organizations", | ||
| 352 | _ => "overview", | 458 | _ => "overview", |
| 353 | } | 459 | } |
| 354 | } | 460 | } |
| @@ -438,8 +544,23 @@ async fn profile_card( | |||
| 438 | listing: Listing, | 544 | listing: Listing, |
| 439 | packages_on: bool, | 545 | packages_on: bool, |
| 440 | package_rows: Vec<PackageRow>, | 546 | package_rows: Vec<PackageRow>, |
| 547 | + org_member: bool, | ||
| 548 | + org_owner: bool, | ||
| 549 | + org_can_create: bool, | ||
| 550 | + heat: Option<(Calendar, Option<DayDetail>)>, | ||
| 551 | + snippets: Vec<ListRow>, | ||
| 552 | + own_profile: bool, | ||
| 553 | + orgs: Vec<OrgCard>, | ||
| 554 | + org_create_allowed: bool, | ||
| 441 | ) -> Result<impl View> { | 555 | ) -> Result<impl View> { |
| 442 | let package_count_text = package_rows.len().to_string(); | 556 | let package_count_text = package_rows.len().to_string(); |
| 557 | + let snippet_count_text = snippets.len().to_string(); | ||
| 558 | + let has_snippets = !snippets.is_empty(); | ||
| 559 | + let snippets_on = tab == "snippets"; | ||
| 560 | + let snippets_href = profile_href(&user.username, "snippets", "", SORTS[0].0, 1); | ||
| 561 | + let orgs_on = tab == "organizations"; | ||
| 562 | + let organizations_href = profile_href(&user.username, "organizations", "", SORTS[0].0, 1); | ||
| 563 | + let has_orgs = !orgs.is_empty(); | ||
| 443 | let packages_href = profile_href(&user.username, "packages", "", SORTS[0].0, 1); | 564 | let packages_href = profile_href(&user.username, "packages", "", SORTS[0].0, 1); |
| 444 | let packages_events = packages::events_href(&user.username); | 565 | let packages_events = packages::events_href(&user.username); |
| 445 | let has_packages = !package_rows.is_empty(); | 566 | let has_packages = !package_rows.is_empty(); |
| @@ -480,6 +601,10 @@ async fn profile_card( | |||
| 480 | empty, | 601 | empty, |
| 481 | } = listing; | 602 | } = listing; |
| 482 | let has_rows = !rows.is_empty(); | 603 | let has_rows = !rows.is_empty(); |
| 604 | + let new_repo_href = format!("/new?owner={}", enc(&user.username)); | ||
| 605 | + let settings_href = format!("/org/{}/settings", enc(&user.username)); | ||
| 606 | + let members_href = format!("/org/{}/members", enc(&user.username)); | ||
| 607 | + let teams_href = format!("/org/{}/teams", enc(&user.username)); | ||
| 483 | Ok(view! { | 608 | Ok(view! { |
| 484 | <article class="profile-page" data-live=(format!("/users/{}/events", user.username))> | 609 | <article class="profile-page" data-live=(format!("/users/{}/events", user.username))> |
| 485 | <header class="profile-head"> | 610 | <header class="profile-head"> |
| @@ -492,10 +617,22 @@ async fn profile_card( | |||
| 492 | if is_org { | 617 | if is_org { |
| 493 | <p class="muted small">(g::t(lang, K::Organization))</p> | 618 | <p class="muted small">(g::t(lang, K::Organization))</p> |
| 494 | } | 619 | } |
| 495 | - <p class="muted">(g::t(lang, K::LocalTime)) (local_time.as_str())</p> | 620 | + if !is_org { |
| 621 | + <p class="muted">(g::t(lang, K::LocalTime)) (local_time.as_str())</p> | ||
| 622 | + } | ||
| 496 | if edit_profile { | 623 | if edit_profile { |
| 497 | <a class="button profile-edit" href="/settings/profile">(edit_label)</a> | 624 | <a class="button profile-edit" href="/settings/profile">(edit_label)</a> |
| 498 | } | 625 | } |
| 626 | + if is_org && (org_can_create || org_owner) { | ||
| 627 | + <div class="profile-org-actions"> | ||
| 628 | + if org_can_create { | ||
| 629 | + <a class="button primary" href=(new_repo_href.as_str())>(g::t(lang, K::NewRepository))</a> | ||
| 630 | + } | ||
| 631 | + if org_owner { | ||
| 632 | + <a class="button" href=(settings_href.as_str())>(g::t(lang, K::Settings))</a> | ||
| 633 | + } | ||
| 634 | + </div> | ||
| 635 | + } | ||
| 499 | </div> | 636 | </div> |
| 500 | </header> | 637 | </header> |
| 501 | if has_about { | 638 | if has_about { |
| @@ -506,12 +643,29 @@ async fn profile_card( | |||
| 506 | <a class=(tab_class(repos_on)) href=(repositories_href.as_str())> | 643 | <a class=(tab_class(repos_on)) href=(repositories_href.as_str())> |
| 507 | (g::t(lang, K::Repositories)) " " <span class="tab-count">(repo_count_text.as_str())</span> | 644 | (g::t(lang, K::Repositories)) " " <span class="tab-count">(repo_count_text.as_str())</span> |
| 508 | </a> | 645 | </a> |
| 509 | - <a class=(tab_class(stars_on)) href=(stars_href.as_str())> | 646 | + if !is_org { |
| 510 | - (g::t(lang, K::TabStars)) " " <span class="tab-count">(star_count_text.as_str())</span> | 647 | + <a class=(tab_class(snippets_on)) href=(snippets_href.as_str())> |
| 511 | - </a> | 648 | + (cm::t(lang, CK::Snippets)) " " <span class="tab-count">(snippet_count_text.as_str())</span> |
| 649 | + </a> | ||
| 650 | + } | ||
| 651 | + if !is_org { | ||
| 652 | + <a class=(tab_class(stars_on)) href=(stars_href.as_str())> | ||
| 653 | + (g::t(lang, K::TabStars)) " " <span class="tab-count">(star_count_text.as_str())</span> | ||
| 654 | + </a> | ||
| 655 | + } | ||
| 512 | <a class=(tab_class(packages_on)) href=(packages_href.as_str())> | 656 | <a class=(tab_class(packages_on)) href=(packages_href.as_str())> |
| 513 | (pk::t(lang, PK::TabPackages)) " " <span class="tab-count">(package_count_text.as_str())</span> | 657 | (pk::t(lang, PK::TabPackages)) " " <span class="tab-count">(package_count_text.as_str())</span> |
| 514 | </a> | 658 | </a> |
| 659 | + if own_profile { | ||
| 660 | + <a class=(tab_class(orgs_on)) href=(organizations_href.as_str())>(g::t(lang, K::Organizations))</a> | ||
| 661 | + } | ||
| 662 | + if org_member { | ||
| 663 | + <a class=(tab_class(false)) href=(members_href.as_str())>(g::t(lang, K::Members))</a> | ||
| 664 | + <a class=(tab_class(false)) href=(teams_href.as_str())>(g::t(lang, K::Teams))</a> | ||
| 665 | + } | ||
| 666 | + if org_owner { | ||
| 667 | + <a class=(tab_class(false)) href=(settings_href.as_str())>(g::t(lang, K::Settings))</a> | ||
| 668 | + } | ||
| 515 | </nav> | 669 | </nav> |
| 516 | if overview_on { | 670 | if overview_on { |
| 517 | <section class="profile-pinned"> | 671 | <section class="profile-pinned"> |
| @@ -542,6 +696,9 @@ async fn profile_card( | |||
| 542 | empty_state(title: g::t(lang, K::NoVisibleRepos)) | 696 | empty_state(title: g::t(lang, K::NoVisibleRepos)) |
| 543 | } | 697 | } |
| 544 | </section> | 698 | </section> |
| 699 | + if let Some((calendar, selected)) = heat { | ||
| 700 | + contribution_calendar(calendar: calendar, selected: selected, lang: lang, base: base.clone()) | ||
| 701 | + } | ||
| 545 | if let Some(summary) = org { | 702 | if let Some(summary) = org { |
| 546 | <section class="profile-org"> | 703 | <section class="profile-org"> |
| 547 | <h2>(g::t(lang, K::Members))</h2> | 704 | <h2>(g::t(lang, K::Members))</h2> |
| @@ -560,6 +717,11 @@ async fn profile_card( | |||
| 560 | } | 717 | } |
| 561 | if list_on { | 718 | if list_on { |
| 562 | <section class="repo-listing"> | 719 | <section class="repo-listing"> |
| 720 | + if own_profile && repos_on { | ||
| 721 | + <div class="profile-section-head"> | ||
| 722 | + <a class="button primary" href="/new">(g::t(lang, K::NewRepository))</a> | ||
| 723 | + </div> | ||
| 724 | + } | ||
| 563 | <form method="get" action=(base.as_str()) class="explore-search" role="search"> | 725 | <form method="get" action=(base.as_str()) class="explore-search" role="search"> |
| 564 | <input type="hidden" name="tab" value=(tab.as_str())> | 726 | <input type="hidden" name="tab" value=(tab.as_str())> |
| 565 | <input type="hidden" name="sort" value=(sort)> | 727 | <input type="hidden" name="sort" value=(sort)> |
| @@ -611,6 +773,47 @@ async fn profile_card( | |||
| 611 | } | 773 | } |
| 612 | </section> | 774 | </section> |
| 613 | } | 775 | } |
| 776 | + if snippets_on { | ||
| 777 | + <section class="snippet-listing"> | ||
| 778 | + <div class="profile-section-head"> | ||
| 779 | + <h2>(cm::t(lang, CK::Snippets))</h2> | ||
| 780 | + if own_profile { | ||
| 781 | + <a class="button primary" href="/snippets/new">(cm::t(lang, CK::NewSnippet))</a> | ||
| 782 | + } | ||
| 783 | + </div> | ||
| 784 | + if has_snippets { | ||
| 785 | + snippet_rows(lang: lang, rows: snippets) | ||
| 786 | + } else { | ||
| 787 | + empty_state(title: cm::t(lang, CK::NoSnippets)) | ||
| 788 | + } | ||
| 789 | + </section> | ||
| 790 | + } | ||
| 791 | + if orgs_on { | ||
| 792 | + <section class="profile-orgs"> | ||
| 793 | + <div class="profile-section-head"> | ||
| 794 | + <h2>(g::t(lang, K::Organizations))</h2> | ||
| 795 | + if org_create_allowed { | ||
| 796 | + <a class="button primary" href="/org/new">(g::t(lang, K::NewOrganization))</a> | ||
| 797 | + } | ||
| 798 | + </div> | ||
| 799 | + if has_orgs { | ||
| 800 | + <ul class="item-list"> | ||
| 801 | + for org in orgs.into_iter() { | ||
| 802 | + <li> | ||
| 803 | + <img class="avatar avatar-sm" src=(org.avatar.as_str()) alt="" width="24" height="24"> | ||
| 804 | + <a href=(org.href.as_str())>(org.name.as_str())</a> | ||
| 805 | + if !org.display_name.is_empty() { | ||
| 806 | + " " <span class="muted small">(org.display_name.as_str())</span> | ||
| 807 | + } | ||
| 808 | + " " <span class="muted small">(org.role)</span> | ||
| 809 | + </li> | ||
| 810 | + } | ||
| 811 | + </ul> | ||
| 812 | + } else { | ||
| 813 | + empty_state(title: g::t(lang, K::NoOrganizations)) | ||
| 814 | + } | ||
| 815 | + </section> | ||
| 816 | + } | ||
| 614 | </article> | 817 | </article> |
| 615 | }) | 818 | }) |
| 616 | } | 819 | } |
| @@ -903,6 +1106,14 @@ mod tests { | |||
| 903 | !anon.contains("Customize pins"), | 1106 | !anon.contains("Customize pins"), |
| 904 | "org pins: anonymous has no edit link" | 1107 | "org pins: anonymous has no edit link" |
| 905 | ); | 1108 | ); |
| 1109 | + assert!( | ||
| 1110 | + owner.contains("href=\"/org/acme/settings\"") && owner.contains("/new?owner=acme"), | ||
| 1111 | + "org profile: owner sees Settings and New repository" | ||
| 1112 | + ); | ||
| 1113 | + assert!( | ||
| 1114 | + !anon.contains("/org/acme/members"), | ||
| 1115 | + "org profile: anonymous has no members link" | ||
| 1116 | + ); | ||
| 906 | } | 1117 | } |
| 907 | 1118 | ||
| 908 | /// Pins, the popular-repos fallback and the display name, on one seeded site. The | 1119 | /// Pins, the popular-repos fallback and the display name, on one seeded site. The |
crates/forge-web/src/pages/profile_calendar.rsadded+92 -0
| @@ -0,0 +1,92 @@ | |||
| 1 | +//! The contribution calendar and its selected day, shown on a person's profile. | ||
| 2 | +//! The counts and the day's contributions come from public repos only, so anyone may see them. | ||
| 3 | + | ||
| 4 | +use std::time::Duration; | ||
| 5 | + | ||
| 6 | +use forge_core::time::stamp_from_unix; | ||
| 7 | +use forge_core::User; | ||
| 8 | +use jiff::{Timestamp, civil}; | ||
| 9 | +use topcoat::Result; | ||
| 10 | + | ||
| 11 | +use crate::state::AppState; | ||
| 12 | +use crate::views::heatmap::{self, Calendar, DayDetail}; | ||
| 13 | + | ||
| 14 | +/// How far back the calendar reads contributions: 53 weeks plus the days of the current week. | ||
| 15 | +const CALENDAR_DAYS: u64 = 371; | ||
| 16 | + | ||
| 17 | +/// The `since` stamp for the calendar. One extra day covers the viewer's local day, which can | ||
| 18 | +/// start before the UTC day that `CALENDAR_DAYS` reaches back to. | ||
| 19 | +pub(crate) fn calendar_since() -> String { | ||
| 20 | + forge_core::time::stamp_ago(Duration::from_secs((CALENDAR_DAYS + 1) * 86_400)) | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +/// The day the `day` query asks for: a strict `YYYY-MM-DD` date from the calendar's first day to | ||
| 24 | +/// today. Anything else (malformed, a future day, or before the calendar) is ignored. | ||
| 25 | +pub(crate) fn selected_day( | ||
| 26 | + day: Option<&str>, | ||
| 27 | + first: (i64, i64, i64), | ||
| 28 | + today: (i64, i64, i64), | ||
| 29 | +) -> Option<civil::Date> { | ||
| 30 | + let text = day?; | ||
| 31 | + let date: civil::Date = text.parse().ok()?; | ||
| 32 | + // The parser takes more forms than the calendar link uses, so the date must print back as sent. | ||
| 33 | + if date.to_string() != text { | ||
| 34 | + return None; | ||
| 35 | + } | ||
| 36 | + let ymd = ( | ||
| 37 | + i64::from(date.year()), | ||
| 38 | + i64::from(date.month()), | ||
| 39 | + i64::from(date.day()), | ||
| 40 | + ); | ||
| 41 | + (first..=today).contains(&ymd).then_some(date) | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +/// The contributions the user made on their local day `date`, newest first. | ||
| 45 | +pub(crate) async fn day_detail( | ||
| 46 | + state: &AppState, | ||
| 47 | + user: &User, | ||
| 48 | + date: civil::Date, | ||
| 49 | +) -> Result<Option<DayDetail>> { | ||
| 50 | + let Some((start, end)) = forge_core::tz::day_span(date, &user.timezone) else { | ||
| 51 | + return Ok(None); | ||
| 52 | + }; | ||
| 53 | + let (Some(from), Some(to)) = (stamp_from_unix(start), stamp_from_unix(end)) else { | ||
| 54 | + return Ok(None); | ||
| 55 | + }; | ||
| 56 | + let items = state | ||
| 57 | + .store | ||
| 58 | + .contributions_between(&user.id, &from, &to) | ||
| 59 | + .await?; | ||
| 60 | + Ok(Some(DayDetail { | ||
| 61 | + date: ( | ||
| 62 | + i64::from(date.year()), | ||
| 63 | + i64::from(date.month()), | ||
| 64 | + i64::from(date.day()), | ||
| 65 | + ), | ||
| 66 | + items, | ||
| 67 | + })) | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +/// Reads the calendar for `user` and the day the `day` query picks, if it picks one. | ||
| 71 | +pub(crate) async fn load_calendar( | ||
| 72 | + state: &AppState, | ||
| 73 | + user: &User, | ||
| 74 | + day: Option<&str>, | ||
| 75 | +) -> Result<(Calendar, Option<DayDetail>)> { | ||
| 76 | + let local_now = forge_core::tz::local_datetime(Timestamp::now(), &user.timezone); | ||
| 77 | + let today = ( | ||
| 78 | + i64::from(local_now.year()), | ||
| 79 | + i64::from(local_now.month()), | ||
| 80 | + i64::from(local_now.day()), | ||
| 81 | + ); | ||
| 82 | + let counts = state | ||
| 83 | + .store | ||
| 84 | + .contribution_counts(&user.id, &calendar_since(), &user.timezone) | ||
| 85 | + .await?; | ||
| 86 | + let calendar = heatmap::build(&counts, today); | ||
| 87 | + let selected = match selected_day(day, calendar.first_day, today) { | ||
| 88 | + Some(date) => day_detail(state, user, date).await?, | ||
| 89 | + None => None, | ||
| 90 | + }; | ||
| 91 | + Ok((calendar, selected)) | ||
| 92 | +} | ||
crates/forge-web/src/pages/pull_files.rsmodified+1 -1
| @@ -130,7 +130,7 @@ async fn pull_files(cx: &Cx) -> Result<impl View> { | |||
| 130 | let commit_count = commits_of(state, &ctx, &pr).await?.len(); | 130 | let commit_count = commits_of(state, &ctx, &pr).await?.len(); |
| 131 | let full_diff = pull_diff(state, &ctx, &pr).await?; | 131 | let full_diff = pull_diff(state, &ctx, &pr).await?; |
| 132 | let frame = frame_in(lang, state, &ctx, &pr, commit_count, full_diff.files.len()).await?; | 132 | let frame = frame_in(lang, state, &ctx, &pr, commit_count, full_diff.files.len()).await?; |
| 133 | - let opts = DiffOpts::from_cx(cx, None); | 133 | + let opts = DiffOpts::from_cx(cx, None).await?; |
| 134 | // With whitespace ignored the file list can shrink, so file indexes differ from the comment | 134 | // With whitespace ignored the file list can shrink, so file indexes differ from the comment |
| 135 | // routes' view. Existing threads still show; new inline comments wait for the full diff. | 135 | // routes' view. Existing threads still show; new inline comments wait for the full diff. |
| 136 | let diff = if opts.ignore_ws { | 136 | let diff = if opts.ignore_ws { |
crates/forge-web/src/pages/repo.rsmodified+1 -1
| @@ -22,7 +22,6 @@ use crate::i18n::code::{self as g, K}; | |||
| 22 | use crate::i18n::{self, Lang}; | 22 | use crate::i18n::{self, Lang}; |
| 23 | use crate::pages::passkeys::s; | 23 | use crate::pages::passkeys::s; |
| 24 | use crate::pages::code_live::{follows_branch, home_live_url}; | 24 | use crate::pages::code_live::{follows_branch, home_live_url}; |
| 25 | -use crate::pages::dashboard::badge_class; | ||
| 26 | use crate::pages::finder::file_finder; | 25 | use crate::pages::finder::file_finder; |
| 27 | use crate::pages::repo_side::{repo_ci_line, repo_strip, run_rows, tree_facts}; | 26 | use crate::pages::repo_side::{repo_ci_line, repo_strip, run_rows, tree_facts}; |
| 28 | use crate::pages::issue_parts::stamp_unix; | 27 | use crate::pages::issue_parts::stamp_unix; |
| @@ -34,6 +33,7 @@ use crate::pages::tree::{ | |||
| 34 | entry_rows, last_commits, latest_bar, load_readme, read_dir, readme_card, tree_table, | 33 | entry_rows, last_commits, latest_bar, load_readme, read_dir, readme_card, tree_table, |
| 35 | }; | 34 | }; |
| 36 | use crate::state::AppState; | 35 | use crate::state::AppState; |
| 36 | +use crate::views::repo_list::badge_class; | ||
| 37 | use crate::views::{now_unix, ref_selector, rel_time, relative_time, repo_href, repo_tabs, shell, user_link}; | 37 | use crate::views::{now_unix, ref_selector, rel_time, relative_time, repo_href, repo_tabs, shell, user_link}; |
| 38 | 38 | ||
| 39 | path_param!(owner); | 39 | path_param!(owner); |
crates/forge-web/src/pages/repo_settings.rsmodified+7 -6
| @@ -40,12 +40,12 @@ use crate::pages::repo::repo_head; | |||
| 40 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | 40 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| 41 | use crate::pages::repo_settings_live::settings_head; | 41 | use crate::pages::repo_settings_live::settings_head; |
| 42 | use crate::state::AppState; | 42 | use crate::state::AppState; |
| 43 | -use crate::views::{alert, shell}; | 43 | +use crate::views::{alert, enc, shell}; |
| 44 | 44 | ||
| 45 | path_param!(owner); | 45 | path_param!(owner); |
| 46 | path_param!(repo); | 46 | path_param!(repo); |
| 47 | 47 | ||
| 48 | -/// Cookie that carries a one-shot notice (the deleted repo's `owner/name`) to the next home page. | 48 | +/// Cookie that carries a one-shot notice (the deleted repo's `owner/name`) to the next profile page. |
| 49 | pub const NOTICE_COOKIE: &str = "forge_notice"; | 49 | pub const NOTICE_COOKIE: &str = "forge_notice"; |
| 50 | 50 | ||
| 51 | /// Cookie that carries a one-shot settings notice to the next settings page. Its value is one of | 51 | /// Cookie that carries a one-shot settings notice to the next settings page. Its value is one of |
| @@ -145,7 +145,7 @@ struct BranchDeleteForm { | |||
| 145 | rule_id: String, | 145 | rule_id: String, |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | -/// Sets the notice shown on the next home page view. | 148 | +/// Sets the notice shown on the next profile page view. |
| 149 | pub fn set_notice(cx: &Cx, title: &str) { | 149 | pub fn set_notice(cx: &Cx, title: &str) { |
| 150 | cookies(cx).add( | 150 | cookies(cx).add( |
| 151 | Cookie::build((NOTICE_COOKIE, title.to_owned())) | 151 | Cookie::build((NOTICE_COOKIE, title.to_owned())) |
| @@ -227,7 +227,7 @@ async fn load_branch_names(ctx: &RepoCtx) -> Result<Vec<String>> { | |||
| 227 | .collect()) | 227 | .collect()) |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | -/// The one-line notice on the home page after a delete. | 230 | +/// The one-line notice on the profile page after a delete. |
| 231 | #[component] | 231 | #[component] |
| 232 | pub async fn notice_banner_for(lang: Lang, title: Option<String>) -> Result<impl View> { | 232 | pub async fn notice_banner_for(lang: Lang, title: Option<String>) -> Result<impl View> { |
| 233 | Ok(view! { | 233 | Ok(view! { |
| @@ -1101,7 +1101,7 @@ async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result | |||
| 1101 | 1101 | ||
| 1102 | /// Deletes the repo when the viewer may delete it, the CSRF token is valid and the confirmation | 1102 | /// Deletes the repo when the viewer may delete it, the CSRF token is valid and the confirmation |
| 1103 | /// is exactly `owner/name`. On success the repo is moved to trash, its rows are deleted, and the | 1103 | /// is exactly `owner/name`. On success the repo is moved to trash, its rows are deleted, and the |
| 1104 | -/// viewer is redirected home with a notice. If the database delete fails the directory goes back. | 1104 | +/// viewer is redirected to the owner's repositories tab with a notice. If the database delete fails the directory goes back. |
| 1105 | /// A wrong confirmation re-renders the page with an error and changes nothing. | 1105 | /// A wrong confirmation re-renders the page with an error and changes nothing. |
| 1106 | #[page(POST "/{owner}/{repo}/settings/delete")] | 1106 | #[page(POST "/{owner}/{repo}/settings/delete")] |
| 1107 | async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> { | 1107 | async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> { |
| @@ -1204,7 +1204,8 @@ async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl V | |||
| 1204 | ) | 1204 | ) |
| 1205 | .await; | 1205 | .await; |
| 1206 | set_notice(cx, &title); | 1206 | set_notice(cx, &title); |
| 1207 | - return Err(see_other("/").into()); | 1207 | + // The owner's profile repository list shows the notice (the profile reads the cookie). |
| 1208 | + return Err(see_other(format!("/{}?tab=repositories", enc(&ctx.repo.owner_name))).into()); | ||
| 1208 | } | 1209 | } |
| 1209 | 1210 | ||
| 1210 | let rules = app_context::<AppState>(cx) | 1211 | let rules = app_context::<AppState>(cx) |
crates/forge-web/src/pages/settings_profile.rsmodified+10 -4
| @@ -37,6 +37,12 @@ pub fn avatar_body_limit() -> BodyLimit { | |||
| 37 | BodyLimit::max(MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD).at("/settings/profile/avatar") | 37 | BodyLimit::max(MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD).at("/settings/profile/avatar") |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | +/// Body limit for the org avatar upload route. A `{org}` segment in a layer path matches any | ||
| 41 | +/// org name, as it does in the route path itself. | ||
| 42 | +pub fn org_avatar_body_limit() -> BodyLimit { | ||
| 43 | + BodyLimit::max(MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD).at("/org/{org}/settings/avatar") | ||
| 44 | +} | ||
| 45 | + | ||
| 40 | #[query_params(error = bad_request)] | 46 | #[query_params(error = bad_request)] |
| 41 | struct ProfileQuery { | 47 | struct ProfileQuery { |
| 42 | saved: Option<String>, | 48 | saved: Option<String>, |
| @@ -299,7 +305,7 @@ fn avatar_slots() -> &'static Arc<Semaphore> { | |||
| 299 | } | 305 | } |
| 300 | 306 | ||
| 301 | /// Stores a processed avatar, or removes it if no image was sent. | 307 | /// Stores a processed avatar, or removes it if no image was sent. |
| 302 | -async fn store_avatar( | 308 | +pub(crate) async fn store_avatar( |
| 303 | store: &Store, | 309 | store: &Store, |
| 304 | user_id: &str, | 310 | user_id: &str, |
| 305 | image: Option<Vec<u8>>, | 311 | image: Option<Vec<u8>>, |
| @@ -687,7 +693,7 @@ pub(crate) mod tests { | |||
| 687 | "Tahinli", | 693 | "Tahinli", |
| 688 | "capitalization: stored" | 694 | "capitalization: stored" |
| 689 | ); | 695 | ); |
| 690 | - let (status, _, body) = send(&fx.router, "GET", "/", true, None).await; | 696 | + let (status, _, body) = send(&fx.router, "GET", "/explore", true, None).await; |
| 691 | assert_eq!(status, 200, "capitalization: nav"); | 697 | assert_eq!(status, 200, "capitalization: nav"); |
| 692 | assert!( | 698 | assert!( |
| 693 | body.contains("<summary class=\"corner-btn\" aria-label=\"Tahinli\">"), | 699 | body.contains("<summary class=\"corner-btn\" aria-label=\"Tahinli\">"), |
| @@ -913,7 +919,7 @@ pub(crate) mod tests { | |||
| 913 | assert!(body.contains("Remove photo"), "page: remove item {body}"); | 919 | assert!(body.contains("Remove photo"), "page: remove item {body}"); |
| 914 | 920 | ||
| 915 | // The top-nav avatar uses the real hash too, not the default URL. | 921 | // The top-nav avatar uses the real hash too, not the default URL. |
| 916 | - let (_, _, body) = send(&fx.router, "GET", "/", true, None).await; | 922 | + let (_, _, body) = send(&fx.router, "GET", "/explore", true, None).await; |
| 917 | let nav_src = format!(r#"src="/avatars/tahinli?v={stored_hash}""#); | 923 | let nav_src = format!(r#"src="/avatars/tahinli?v={stored_hash}""#); |
| 918 | assert!(body.contains(&nav_src), "nav: avatar url {body}"); | 924 | assert!(body.contains(&nav_src), "nav: avatar url {body}"); |
| 919 | 925 | ||
| @@ -981,7 +987,7 @@ pub(crate) mod tests { | |||
| 981 | fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none(), | 987 | fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none(), |
| 982 | "remove: cleared" | 988 | "remove: cleared" |
| 983 | ); | 989 | ); |
| 984 | - let (_, _, body) = send(&fx.router, "GET", "/", true, None).await; | 990 | + let (_, _, body) = send(&fx.router, "GET", "/explore", true, None).await; |
| 985 | assert!( | 991 | assert!( |
| 986 | body.contains(r#"src="/avatars/tahinli?v=default""#), | 992 | body.contains(r#"src="/avatars/tahinli?v=default""#), |
| 987 | "remove: nav default {body}" | 993 | "remove: nav default {body}" |
crates/forge-web/src/pages/setup.rsmodified+4 -4
| @@ -297,10 +297,10 @@ mod tests { | |||
| 297 | .is_some_and(|p| p == format!("{PRECSRF_COOKIE}=")) | 297 | .is_some_and(|p| p == format!("{PRECSRF_COOKIE}=")) |
| 298 | ); | 298 | ); |
| 299 | 299 | ||
| 300 | - // The session cookie authenticates the dashboard. | 300 | + // The session cookie authenticates the signed-in pages. |
| 301 | - let (status, _, home) = send(&router, "GET", "/", Some(&cookie), None).await; | 301 | + let (status, _, home) = send(&router, "GET", "/explore", Some(&cookie), None).await; |
| 302 | assert_eq!(status, 200); | 302 | assert_eq!(status, 200); |
| 303 | - assert!(home.contains("Your repositories")); | 303 | + assert!(home.contains("class=\"corner-float\"")); |
| 304 | let csrf = field_from(&home, "csrf"); | 304 | let csrf = field_from(&home, "csrf"); |
| 305 | 305 | ||
| 306 | // Wrong CSRF token is refused. | 306 | // Wrong CSRF token is refused. |
| @@ -371,7 +371,7 @@ mod tests { | |||
| 371 | .unwrap() | 371 | .unwrap() |
| 372 | .contains("__Host-forge_session=") | 372 | .contains("__Host-forge_session=") |
| 373 | ); | 373 | ); |
| 374 | - let (status, _, _) = send(&router, "GET", "/", Some(&cookie), None).await; | 374 | + let (status, _, _) = send(&router, "GET", "/explore", Some(&cookie), None).await; |
| 375 | assert_eq!(status, 200); | 375 | assert_eq!(status, 200); |
| 376 | 376 | ||
| 377 | // Login is protected the same way: a mismatched pre-session token is refused. | 377 | // Login is protected the same way: a mismatched pre-session token is refused. |
crates/forge-web/src/pages/shell_events.rsmodified+8 -10
| @@ -1,13 +1,13 @@ | |||
| 1 | -//! `GET /-/shell/events`: the one live stream a page holds. It merges the four streams every | 1 | +//! `GET /-/shell/events`: the one live stream a page holds. It merges the streams every signed-in |
| 2 | -//! signed-in page used to open (`/-/alive`, `/notifications/stream`, `/-/activity/stream` and | 2 | +//! page used to open (`/-/alive`, `/notifications/stream` and `/-/activity/stream`) into one |
| 3 | -//! `/-/side/events`) into one response. Chromium allows six connections per host over HTTP/1.1, and | 3 | +//! response. Chromium allows six connections per host over HTTP/1.1, and a page that held more |
| 4 | -//! a page that held more than that could not load anything else. | 4 | +//! than that could not load anything else. |
| 5 | //! | 5 | //! |
| 6 | //! The events are named: `settings`, `theme`, `language` and `account` (the alive part, see | 6 | //! The events are named: `settings`, `theme`, `language` and `account` (the alive part, see |
| 7 | -//! `settings_live::alive_stream`), `unread` (the inbox count), `activity` (the viewer's live strip | 7 | +//! `settings_live::alive_stream`), `unread` (the inbox count) and `activity` (the viewer's live |
| 8 | -//! and ring) and `side` (the sidebar's repo list). An anonymous visitor gets the alive part only. | 8 | +//! strip and ring). An anonymous visitor gets the alive part only. Each part keeps its own |
| 9 | -//! Each part keeps its own fingerprint, so an event is sent only when that part changed. The old | 9 | +//! fingerprint, so an event is sent only when that part changed. The old routes stay registered |
| 10 | -//! routes stay registered for tabs opened before a deploy. | 10 | +//! for tabs opened before a deploy. |
| 11 | 11 | ||
| 12 | use futures_util::StreamExt; | 12 | use futures_util::StreamExt; |
| 13 | use futures_util::stream::{self, BoxStream}; | 13 | use futures_util::stream::{self, BoxStream}; |
| @@ -20,7 +20,6 @@ use topcoat::router::route; | |||
| 20 | use crate::auth::current_user; | 20 | use crate::auth::current_user; |
| 21 | use crate::pages::activity::activity_changes; | 21 | use crate::pages::activity::activity_changes; |
| 22 | use crate::pages::ci_runs::events_response; | 22 | use crate::pages::ci_runs::events_response; |
| 23 | -use crate::pages::dashboard::side_changes; | ||
| 24 | use crate::pages::notifications::unread_changes; | 23 | use crate::pages::notifications::unread_changes; |
| 25 | use crate::pages::settings_live::alive_stream; | 24 | use crate::pages::settings_live::alive_stream; |
| 26 | use crate::state::AppState; | 25 | use crate::state::AppState; |
| @@ -42,7 +41,6 @@ async fn shell_events(cx: &Cx) -> Result<Response> { | |||
| 42 | if let Some((user, _)) = viewer { | 41 | if let Some((user, _)) = viewer { |
| 43 | parts.push(unread_changes(&state, &user.id).await?.boxed()); | 42 | parts.push(unread_changes(&state, &user.id).await?.boxed()); |
| 44 | parts.push(activity_changes(state.clone(), user.clone(), "activity").boxed()); | 43 | parts.push(activity_changes(state.clone(), user.clone(), "activity").boxed()); |
| 45 | - parts.push(side_changes(&state, &user, "side").await?.boxed()); | ||
| 46 | } | 44 | } |
| 47 | events_response(cx, stream::select_all(parts)) | 45 | events_response(cx, stream::select_all(parts)) |
| 48 | } | 46 | } |
crates/forge-web/src/pages/snippets.rsmodified+35 -22
| @@ -194,8 +194,8 @@ struct RevisionView { | |||
| 194 | file_names: String, | 194 | file_names: String, |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | -/// One row of the list page. | 197 | +/// One row of the list page and of a profile's Snippets tab. |
| 198 | -struct ListRow { | 198 | +pub(crate) struct ListRow { |
| 199 | id: String, | 199 | id: String, |
| 200 | title: String, | 200 | title: String, |
| 201 | owner: String, | 201 | owner: String, |
| @@ -205,6 +205,18 @@ struct ListRow { | |||
| 205 | updated_at: String, | 205 | updated_at: String, |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | +/// The list row for a snippet summary, with its strings ready for the view. | ||
| 209 | +pub(crate) fn list_row(lang: Lang, summary: SnippetSummary) -> ListRow { | ||
| 210 | + ListRow { | ||
| 211 | + id: summary.id, | ||
| 212 | + title: summary.title, | ||
| 213 | + owner: summary.owner_name, | ||
| 214 | + visibility: visibility_label(lang, summary.visibility), | ||
| 215 | + files: g::files_count(lang, summary.file_count), | ||
| 216 | + updated_at: summary.updated_at, | ||
| 217 | + } | ||
| 218 | +} | ||
| 219 | + | ||
| 208 | fn visibility_label(lang: Lang, visibility: SnippetVisibility) -> &'static str { | 220 | fn visibility_label(lang: Lang, visibility: SnippetVisibility) -> &'static str { |
| 209 | match visibility { | 221 | match visibility { |
| 210 | SnippetVisibility::Public => g::t(lang, K::VisibilityPublic), | 222 | SnippetVisibility::Public => g::t(lang, K::VisibilityPublic), |
| @@ -260,6 +272,25 @@ async fn owned(cx: &Cx, user: &User, snippet_id: &str) -> Result<Snippet> { | |||
| 260 | } | 272 | } |
| 261 | } | 273 | } |
| 262 | 274 | ||
| 275 | +/// The snippet rows, one linked line each: title, owner, visibility, file count and update time. | ||
| 276 | +#[component] | ||
| 277 | +pub(crate) async fn snippet_rows(lang: Lang, rows: Vec<ListRow>) -> Result<impl View> { | ||
| 278 | + Ok(view! { | ||
| 279 | + <ul class="item-list snippet-list"> | ||
| 280 | + for row in rows.into_iter() { | ||
| 281 | + <li class="item"> | ||
| 282 | + <div class="item-main"> | ||
| 283 | + <a href=(format!("/snippets/{}", row.id))><strong>(row.title)</strong></a> | ||
| 284 | + <span class="muted small"> | ||
| 285 | + (row.owner) " · " (row.visibility) " · " (row.files) " · " (g::updated_before(lang)) rel_time(lang: lang, stamp: row.updated_at.as_str()) (g::updated_after(lang)) | ||
| 286 | + </span> | ||
| 287 | + </div> | ||
| 288 | + </li> | ||
| 289 | + } | ||
| 290 | + </ul> | ||
| 291 | + }) | ||
| 292 | +} | ||
| 293 | + | ||
| 263 | #[component] | 294 | #[component] |
| 264 | async fn snippet_list_body( | 295 | async fn snippet_list_body( |
| 265 | lang: Lang, | 296 | lang: Lang, |
| @@ -282,18 +313,7 @@ async fn snippet_list_body( | |||
| 282 | } | 313 | } |
| 283 | ) | 314 | ) |
| 284 | } else { | 315 | } else { |
| 285 | - <ul class="item-list snippet-list"> | 316 | + snippet_rows(lang: lang, rows: rows) |
| 286 | - for row in rows.into_iter() { | ||
| 287 | - <li class="item"> | ||
| 288 | - <div class="item-main"> | ||
| 289 | - <a href=(format!("/snippets/{}", row.id))><strong>(row.title)</strong></a> | ||
| 290 | - <span class="muted small"> | ||
| 291 | - (row.owner) " · " (row.visibility) " · " (row.files) " · " (g::updated_before(lang)) rel_time(lang: lang, stamp: row.updated_at.as_str()) (g::updated_after(lang)) | ||
| 292 | - </span> | ||
| 293 | - </div> | ||
| 294 | - </li> | ||
| 295 | - } | ||
| 296 | - </ul> | ||
| 297 | } | 317 | } |
| 298 | </section> | 318 | </section> |
| 299 | }) | 319 | }) |
| @@ -571,14 +591,7 @@ async fn snippets_list(cx: &Cx) -> Result<impl View> { | |||
| 571 | .await?; | 591 | .await?; |
| 572 | let rows: Vec<ListRow> = summaries | 592 | let rows: Vec<ListRow> = summaries |
| 573 | .into_iter() | 593 | .into_iter() |
| 574 | - .map(|s| ListRow { | 594 | + .map(|s| list_row(lang, s)) |
| 575 | - id: s.id, | ||
| 576 | - title: s.title, | ||
| 577 | - owner: s.owner_name, | ||
| 578 | - visibility: visibility_label(lang, s.visibility), | ||
| 579 | - files: g::files_count(lang, s.file_count), | ||
| 580 | - updated_at: s.updated_at, | ||
| 581 | - }) | ||
| 582 | .collect(); | 595 | .collect(); |
| 583 | let signed_in = viewer.is_some(); | 596 | let signed_in = viewer.is_some(); |
| 584 | let title = g::t(lang, K::Snippets); | 597 | let title = g::t(lang, K::Snippets); |
crates/forge-web/src/pages/user_prefs.rsadded+158 -0
| @@ -0,0 +1,158 @@ | |||
| 1 | +//! Route: `POST /-/prefs`, a signed-in user's account preferences: the tree width of a repo home, | ||
| 2 | +//! the profile corner's position and the diff view. The values live in the `user_prefs` table | ||
| 3 | +//! (store/user_prefs.rs). Only the keys below are accepted; each has its own check. An empty value | ||
| 4 | +//! deletes the key. Signed-out callers get what `require_csrf` gives. | ||
| 5 | + | ||
| 6 | +use http::StatusCode; | ||
| 7 | +use serde::Deserialize; | ||
| 8 | +use topcoat::Result; | ||
| 9 | +use topcoat::context::{Cx, app_context}; | ||
| 10 | +use topcoat::router::content::Form; | ||
| 11 | +use topcoat::router::error::bad_request; | ||
| 12 | +use topcoat::router::response::Response; | ||
| 13 | +use topcoat::router::{Body, route}; | ||
| 14 | + | ||
| 15 | +use crate::auth::require_csrf; | ||
| 16 | +use crate::state::AppState; | ||
| 17 | + | ||
| 18 | +/// Key of the repo home's file tree width, in CSS pixels. | ||
| 19 | +pub const TREE_WIDTH: &str = "tree_width"; | ||
| 20 | +/// Key of the profile corner's position: `x,y` as fractions of the free space, each 0 to 1. | ||
| 21 | +pub const CORNER_POS: &str = "corner_pos"; | ||
| 22 | +/// Key of the diff view: `split` or `unified`. | ||
| 23 | +pub const DIFF_VIEW: &str = "diff_view"; | ||
| 24 | + | ||
| 25 | +const MIN_TREE_WIDTH: u32 = 120; | ||
| 26 | +const MAX_TREE_WIDTH: u32 = 4000; | ||
| 27 | + | ||
| 28 | +#[derive(Deserialize)] | ||
| 29 | +struct PrefForm { | ||
| 30 | + #[serde(default)] | ||
| 31 | + csrf: String, | ||
| 32 | + #[serde(default)] | ||
| 33 | + key: String, | ||
| 34 | + #[serde(default)] | ||
| 35 | + value: String, | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +/// Checks one preference. `Ok(None)` means the empty value that deletes the key, `Ok(Some(v))` is | ||
| 39 | +/// the value to store (normalised), and `Err` is the reason a 400 gives. | ||
| 40 | +pub fn clean_pref(key: &str, value: &str) -> std::result::Result<Option<String>, &'static str> { | ||
| 41 | + match key { | ||
| 42 | + TREE_WIDTH => { | ||
| 43 | + if value.is_empty() { | ||
| 44 | + return Ok(None); | ||
| 45 | + } | ||
| 46 | + let width = value | ||
| 47 | + .bytes() | ||
| 48 | + .all(|b| b.is_ascii_digit()) | ||
| 49 | + .then(|| value.parse::<u32>().ok()) | ||
| 50 | + .flatten() | ||
| 51 | + .filter(|w| (MIN_TREE_WIDTH..=MAX_TREE_WIDTH).contains(w)); | ||
| 52 | + width | ||
| 53 | + .map(|w| Some(w.to_string())) | ||
| 54 | + .ok_or("tree_width must be a whole number from 120 to 4000") | ||
| 55 | + } | ||
| 56 | + CORNER_POS => { | ||
| 57 | + if value.is_empty() { | ||
| 58 | + return Ok(None); | ||
| 59 | + } | ||
| 60 | + let fraction = |s: &str| { | ||
| 61 | + s.parse::<f64>() | ||
| 62 | + .ok() | ||
| 63 | + .filter(|v| v.is_finite() && (0.0..=1.0).contains(v)) | ||
| 64 | + }; | ||
| 65 | + match value.split_once(',') { | ||
| 66 | + Some((x, y)) => match (fraction(x), fraction(y)) { | ||
| 67 | + (Some(x), Some(y)) => Ok(Some(format!("{x},{y}"))), | ||
| 68 | + _ => Err("corner_pos must be two numbers from 0 to 1 written x,y"), | ||
| 69 | + }, | ||
| 70 | + None => Err("corner_pos must be two numbers from 0 to 1 written x,y"), | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + DIFF_VIEW => match value { | ||
| 74 | + "" => Ok(None), | ||
| 75 | + "split" | "unified" => Ok(Some(value.to_owned())), | ||
| 76 | + _ => Err("diff_view must be split or unified"), | ||
| 77 | + }, | ||
| 78 | + _ => Err("unknown preference"), | ||
| 79 | + } | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +#[route(POST "/-/prefs")] | ||
| 83 | +async fn set_pref(cx: &Cx, Form(form): Form<PrefForm>) -> Result<Response> { | ||
| 84 | + let (user, _) = require_csrf(cx, &form.csrf).await?; | ||
| 85 | + let store = &app_context::<AppState>(cx).store; | ||
| 86 | + match clean_pref(&form.key, &form.value) { | ||
| 87 | + Err(message) => return Err(bad_request(message).into()), | ||
| 88 | + Ok(None) => store.delete_user_pref(&user.id, &form.key).await?, | ||
| 89 | + Ok(Some(value)) => store.set_user_pref(&user.id, &form.key, &value).await?, | ||
| 90 | + } | ||
| 91 | + let mut res = Response::new(Body::empty()); | ||
| 92 | + *res.status_mut() = StatusCode::NO_CONTENT; | ||
| 93 | + Ok(res) | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +#[cfg(test)] | ||
| 97 | +mod tests { | ||
| 98 | + use super::*; | ||
| 99 | + use topcoat::router::request::Request; | ||
| 100 | + use topcoat::router::to_bytes; | ||
| 101 | + | ||
| 102 | + use crate::auth::SESSION_COOKIE; | ||
| 103 | + use crate::test_support::{app_router, create_session, test_state}; | ||
| 104 | + | ||
| 105 | + #[tokio::test] | ||
| 106 | + async fn prefs_route_refuses_unknown_keys_and_stores_a_corner_position() { | ||
| 107 | + let dir = tempfile::tempdir().expect("tempdir"); | ||
| 108 | + let state = test_state(dir.path()).await; | ||
| 109 | + let user = state | ||
| 110 | + .store | ||
| 111 | + .create_user("tahinli", None, "unused", false) | ||
| 112 | + .await | ||
| 113 | + .expect("user"); | ||
| 114 | + create_session(&state.store, &user.id, "prefs-session", "prefs-csrf").await; | ||
| 115 | + let router = app_router(state.clone()); | ||
| 116 | + let cookie = format!("__Host-{SESSION_COOKIE}=prefs-session"); | ||
| 117 | + let post = |form: &'static str| { | ||
| 118 | + Request::builder() | ||
| 119 | + .method("POST") | ||
| 120 | + .uri("/-/prefs") | ||
| 121 | + .header("cookie", cookie.as_str()) | ||
| 122 | + .header("content-type", "application/x-www-form-urlencoded") | ||
| 123 | + .body(Body::from(form)) | ||
| 124 | + .unwrap() | ||
| 125 | + }; | ||
| 126 | + | ||
| 127 | + let unknown = router | ||
| 128 | + .handle(post("csrf=prefs-csrf&key=nope&value=1")) | ||
| 129 | + .await; | ||
| 130 | + assert_eq!(unknown.status().as_u16(), 400, "unknown key"); | ||
| 131 | + let _ = to_bytes(unknown.into_body(), usize::MAX).await.unwrap(); | ||
| 132 | + | ||
| 133 | + let stored = router | ||
| 134 | + .handle(post("csrf=prefs-csrf&key=corner_pos&value=0.5%2C0.25")) | ||
| 135 | + .await; | ||
| 136 | + assert_eq!(stored.status().as_u16(), 204, "corner position saved"); | ||
| 137 | + let _ = to_bytes(stored.into_body(), usize::MAX).await.unwrap(); | ||
| 138 | + let prefs = state.store.user_prefs(&user.id).await.unwrap(); | ||
| 139 | + assert_eq!(prefs.get(CORNER_POS).map(String::as_str), Some("0.5,0.25")); | ||
| 140 | + | ||
| 141 | + let page = router | ||
| 142 | + .handle( | ||
| 143 | + Request::builder() | ||
| 144 | + .method("GET") | ||
| 145 | + .uri("/tahinli") | ||
| 146 | + .header("cookie", cookie.as_str()) | ||
| 147 | + .body(Body::empty()) | ||
| 148 | + .unwrap(), | ||
| 149 | + ) | ||
| 150 | + .await; | ||
| 151 | + assert_eq!(page.status().as_u16(), 200); | ||
| 152 | + let bytes = to_bytes(page.into_body(), usize::MAX).await.unwrap(); | ||
| 153 | + assert!( | ||
| 154 | + String::from_utf8_lossy(&bytes).contains("data-corner-pos=\"0.5,0.25\""), | ||
| 155 | + "the page carries the stored corner" | ||
| 156 | + ); | ||
| 157 | + } | ||
| 158 | +} | ||
crates/forge-web/src/post_update.rsmodified+2 -2
| @@ -50,13 +50,13 @@ pub async fn after_ref_update( | |||
| 50 | state | 50 | state |
| 51 | .live | 51 | .live |
| 52 | .bump(&crate::live::Topic::RepoRefs(repo.id.clone())); | 52 | .bump(&crate::live::Topic::RepoRefs(repo.id.clone())); |
| 53 | - // The pusher's contribution calendar (dashboard and profile) counts the push. | 53 | + // The pusher's contribution calendar on their profile counts the push. |
| 54 | if !actor_id.is_empty() { | 54 | if !actor_id.is_empty() { |
| 55 | state | 55 | state |
| 56 | .live | 56 | .live |
| 57 | .bump(&crate::live::Topic::User(actor_id.to_owned())); | 57 | .bump(&crate::live::Topic::User(actor_id.to_owned())); |
| 58 | } | 58 | } |
| 59 | - // The owner's sidebar lists its repos by last update, so a push by someone else moves it too. | 59 | + // The owner's repo listing sorts by last update, so a push by someone else moves it too. |
| 60 | if repo.owner_id != actor_id { | 60 | if repo.owner_id != actor_id { |
| 61 | state | 61 | state |
| 62 | .live | 62 | .live |
crates/forge-web/src/test_support.rsmodified+2 -1
| @@ -18,7 +18,7 @@ use topcoat::router::tower::TowerLayer; | |||
| 18 | use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt}; | 18 | use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt}; |
| 19 | 19 | ||
| 20 | use crate::pages::repo_ctx::RepoMovedLayer; | 20 | use crate::pages::repo_ctx::RepoMovedLayer; |
| 21 | -use crate::pages::settings_profile::avatar_body_limit; | 21 | +use crate::pages::settings_profile::{avatar_body_limit, org_avatar_body_limit}; |
| 22 | use crate::state::AppState; | 22 | use crate::state::AppState; |
| 23 | use crate::throttle::Throttle; | 23 | use crate::throttle::Throttle; |
| 24 | 24 | ||
| @@ -109,6 +109,7 @@ pub fn app_router(state: AppState) -> Router { | |||
| 109 | .layer(crate::pages::settings_live::AccountWriteLayer) | 109 | .layer(crate::pages::settings_live::AccountWriteLayer) |
| 110 | .cookies() | 110 | .cookies() |
| 111 | .layer(avatar_body_limit()) | 111 | .layer(avatar_body_limit()) |
| 112 | + .layer(org_avatar_body_limit()) | ||
| 112 | .layer(RepoMovedLayer) | 113 | .layer(RepoMovedLayer) |
| 113 | .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer) | 114 | .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer) |
| 114 | .layer(crate::pages::pull_live::PullWriteLayer) | 115 | .layer(crate::pages::pull_live::PullWriteLayer) |
crates/forge-web/src/views/diff.rsmodified+45 -21
| @@ -13,16 +13,19 @@ use std::collections::HashMap; | |||
| 13 | use forge_core::{Side, Thread}; | 13 | use forge_core::{Side, Thread}; |
| 14 | use forge_git::history::{CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind}; | 14 | use forge_git::history::{CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind}; |
| 15 | use topcoat::Result; | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::Cx; | 16 | +use topcoat::context::{Cx, app_context}; |
| 17 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; | 17 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; |
| 18 | use topcoat::router::request::uri; | 18 | use topcoat::router::request::uri; |
| 19 | use topcoat::view::{View, component, view}; | 19 | use topcoat::view::{View, component, view}; |
| 20 | 20 | ||
| 21 | +use crate::auth::current_user; | ||
| 21 | use crate::i18n::Lang; | 22 | use crate::i18n::Lang; |
| 22 | use crate::i18n::browse as b; | 23 | use crate::i18n::browse as b; |
| 23 | use crate::i18n::code::{self as g, K}; | 24 | use crate::i18n::code::{self as g, K}; |
| 24 | use crate::i18n::pulls_review::{self as pr_g, K as PrK}; | 25 | use crate::i18n::pulls_review::{self as pr_g, K as PrK}; |
| 25 | use crate::pages::commits::url_path; | 26 | use crate::pages::commits::url_path; |
| 27 | +use crate::pages::user_prefs::DIFF_VIEW; | ||
| 28 | +use crate::state::AppState; | ||
| 26 | use crate::views::review_thread::{ThreadCtx, review_thread_in}; | 29 | use crate::views::review_thread::{ThreadCtx, review_thread_in}; |
| 27 | 30 | ||
| 28 | /// Per-diff limits used by the commit and pull-request pages. | 31 | /// Per-diff limits used by the commit and pull-request pages. |
| @@ -85,9 +88,11 @@ pub struct DiffOpts { | |||
| 85 | } | 88 | } |
| 86 | 89 | ||
| 87 | impl DiffOpts { | 90 | impl DiffOpts { |
| 88 | - /// Reads the request: `?view=split|unified` wins and is remembered in a cookie, else the | 91 | + /// Reads the request: `?w=1` ignores whitespace. The unified or split view comes from |
| 89 | - /// cookie decides; `?w=1` ignores whitespace. `downloads` are the patch and diff links. | 92 | + /// `?view=split|unified`, which wins and is remembered: in the account's `diff_view` |
| 90 | - pub fn from_cx(cx: &Cx, downloads: Option<(String, String)>) -> Self { | 93 | + /// preference when signed in, else in a cookie. Without `?view=` the remembered choice |
| 94 | + /// decides. `downloads` are the patch and diff links. | ||
| 95 | + pub async fn from_cx(cx: &Cx, downloads: Option<(String, String)>) -> Result<Self> { | ||
| 91 | let request = uri(cx); | 96 | let request = uri(cx); |
| 92 | let mut view_param = None; | 97 | let mut view_param = None; |
| 93 | let mut ignore_ws = false; | 98 | let mut ignore_ws = false; |
| @@ -102,31 +107,50 @@ impl DiffOpts { | |||
| 102 | } | 107 | } |
| 103 | } | 108 | } |
| 104 | } | 109 | } |
| 105 | - let split = match view_param.as_deref() { | 110 | + let split = match current_user(cx).await? { |
| 106 | - Some(v @ ("split" | "unified")) => { | 111 | + Some((user, _)) => { |
| 107 | - let max_age = time::Duration::seconds(365 * 24 * 60 * 60); | 112 | + let state = app_context::<AppState>(cx); |
| 108 | - cookies(cx).add( | 113 | + let stored = state |
| 109 | - Cookie::build((DIFF_VIEW_COOKIE, v.to_owned())) | 114 | + .store |
| 110 | - .path("/") | 115 | + .user_prefs(&user.id) |
| 111 | - .secure(true) | 116 | + .await? |
| 112 | - .same_site(SameSite::Lax) | 117 | + .remove(DIFF_VIEW); |
| 113 | - .max_age(max_age) | 118 | + match view_param.as_deref() { |
| 114 | - .build(), | 119 | + Some(v @ ("split" | "unified")) => { |
| 115 | - ); | 120 | + if stored.as_deref() != Some(v) { |
| 116 | - v == "split" | 121 | + state.store.set_user_pref(&user.id, DIFF_VIEW, v).await?; |
| 122 | + } | ||
| 123 | + v == "split" | ||
| 124 | + } | ||
| 125 | + _ => stored.as_deref() == Some("split"), | ||
| 126 | + } | ||
| 117 | } | 127 | } |
| 118 | - _ => cookies(cx) | 128 | + None => match view_param.as_deref() { |
| 119 | - .get(DIFF_VIEW_COOKIE) | 129 | + Some(v @ ("split" | "unified")) => { |
| 120 | - .is_some_and(|c| c.value() == "split"), | 130 | + let max_age = time::Duration::seconds(365 * 24 * 60 * 60); |
| 131 | + cookies(cx).add( | ||
| 132 | + Cookie::build((DIFF_VIEW_COOKIE, v.to_owned())) | ||
| 133 | + .path("/") | ||
| 134 | + .secure(true) | ||
| 135 | + .same_site(SameSite::Lax) | ||
| 136 | + .max_age(max_age) | ||
| 137 | + .build(), | ||
| 138 | + ); | ||
| 139 | + v == "split" | ||
| 140 | + } | ||
| 141 | + _ => cookies(cx) | ||
| 142 | + .get(DIFF_VIEW_COOKIE) | ||
| 143 | + .is_some_and(|c| c.value() == "split"), | ||
| 144 | + }, | ||
| 121 | }; | 145 | }; |
| 122 | - Self { | 146 | + Ok(Self { |
| 123 | enabled: true, | 147 | enabled: true, |
| 124 | split, | 148 | split, |
| 125 | ignore_ws, | 149 | ignore_ws, |
| 126 | path: request.path().to_owned(), | 150 | path: request.path().to_owned(), |
| 127 | query, | 151 | query, |
| 128 | downloads, | 152 | downloads, |
| 129 | - } | 153 | + }) |
| 130 | } | 154 | } |
| 131 | 155 | ||
| 132 | /// The page URL for the given view and whitespace setting. | 156 | /// The page URL for the given view and whitespace setting. |
crates/forge-web/src/views/heatmap.rsmodified+10 -8
| @@ -1,4 +1,4 @@ | |||
| 1 | -//! Dashboard contribution calendar: the last 53 weeks of daily contribution counts, one column per | 1 | +//! Contribution calendar: the last 53 weeks of daily contribution counts, one column per |
| 2 | //! week (Monday first), with the four summary stats, month labels and the motivating line. | 2 | //! week (Monday first), with the four summary stats, month labels and the motivating line. |
| 3 | //! | 3 | //! |
| 4 | //! `build` is pure date and streak maths over the counts from the store. `contribution_calendar` | 4 | //! `build` is pure date and streak maths over the counts from the store. `contribution_calendar` |
| @@ -209,14 +209,15 @@ struct DayView { | |||
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | /// The link for a calendar day: the day's contributions below the calendar, or back to the | 211 | /// The link for a calendar day: the day's contributions below the calendar, or back to the |
| 212 | -/// plain calendar when the day is the selected one. The anchor brings a full page load back to the | 212 | +/// plain calendar when the day is the selected one. `base` is the page the calendar sits on. The |
| 213 | -/// calendar; nav.js swaps in place and keeps the scroll (`data-keep-scroll`), so it is not used there. | 213 | +/// anchor brings a full page load back to the calendar; nav.js swaps in place and keeps the scroll |
| 214 | -fn day_href(date: (i64, i64, i64), selected: bool) -> String { | 214 | +/// (`data-keep-scroll`), so it is not used there. |
| 215 | +fn day_href(base: &str, date: (i64, i64, i64), selected: bool) -> String { | ||
| 215 | if selected { | 216 | if selected { |
| 216 | - "/#contributions-h".to_owned() | 217 | + format!("{base}#contributions-h") |
| 217 | } else { | 218 | } else { |
| 218 | format!( | 219 | format!( |
| 219 | - "/?day={:04}-{:02}-{:02}#contributions-h", | 220 | + "{base}?day={:04}-{:02}-{:02}#contributions-h", |
| 220 | date.0, date.1, date.2 | 221 | date.0, date.1, date.2 |
| 221 | ) | 222 | ) |
| 222 | } | 223 | } |
| @@ -335,12 +336,13 @@ fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry | |||
| 335 | 336 | ||
| 336 | /// The contribution card: heading and date range, the four stats, the month labels and the | 337 | /// The contribution card: heading and date range, the four stats, the month labels and the |
| 337 | /// 53-week grid, then the motivating line and the Less/More legend, then the selected day's | 338 | /// 53-week grid, then the motivating line and the Less/More legend, then the selected day's |
| 338 | -/// contributions when a day is picked. | 339 | +/// contributions when a day is picked. `base` is the URL the day links point at. |
| 339 | #[component] | 340 | #[component] |
| 340 | pub async fn contribution_calendar( | 341 | pub async fn contribution_calendar( |
| 341 | calendar: Calendar, | 342 | calendar: Calendar, |
| 342 | selected: Option<DayDetail>, | 343 | selected: Option<DayDetail>, |
| 343 | lang: Lang, | 344 | lang: Lang, |
| 345 | + base: String, | ||
| 344 | ) -> Result<impl View> { | 346 | ) -> Result<impl View> { |
| 345 | let range = { | 347 | let range = { |
| 346 | let from = g::date_text( | 348 | let from = g::date_text( |
| @@ -400,7 +402,7 @@ pub async fn contribution_calendar( | |||
| 400 | } else { | 402 | } else { |
| 401 | level.to_owned() | 403 | level.to_owned() |
| 402 | }, | 404 | }, |
| 403 | - href: Some(day_href(day.date, picked)), | 405 | + href: Some(day_href(&base, day.date, picked)), |
| 404 | title: g::contributions_on( | 406 | title: g::contributions_on( |
| 405 | lang, | 407 | lang, |
| 406 | day.count, | 408 | day.count, |
crates/forge-web/src/views/mod.rsmodified+74 -200
| @@ -10,8 +10,6 @@ pub mod review_thread; | |||
| 10 | use std::sync::OnceLock; | 10 | use std::sync::OnceLock; |
| 11 | 11 | ||
| 12 | use forge_core::ci::RunState; | 12 | use forge_core::ci::RunState; |
| 13 | -use forge_core::store::RepoSort; | ||
| 14 | -use forge_core::store::repo_listing::RepoScope; | ||
| 15 | use forge_core::store::shell_activity::{ActorRun, ActorRuns, InboxKinds}; | 13 | use forge_core::store::shell_activity::{ActorRun, ActorRuns, InboxKinds}; |
| 16 | use forge_core::{Error as CoreError, Session, User}; | 14 | use forge_core::{Error as CoreError, Session, User}; |
| 17 | use hex::encode; | 15 | use hex::encode; |
| @@ -30,13 +28,13 @@ use topcoat::view::{Child, Unescaped, View, ViewExt, component, view}; | |||
| 30 | use crate::i18n::admin::{self as ad, K as AK}; | 28 | use crate::i18n::admin::{self as ad, K as AK}; |
| 31 | use crate::i18n::browse as br; | 29 | use crate::i18n::browse as br; |
| 32 | use crate::i18n::code::{self as g, K}; | 30 | use crate::i18n::code::{self as g, K}; |
| 33 | -use crate::i18n::community::{self as cm, K as CK}; | ||
| 34 | use crate::i18n::link::{self as lk, K as LinkKey}; | 31 | use crate::i18n::link::{self as lk, K as LinkKey}; |
| 35 | use crate::i18n::migrate::{self as mg, K as MGK}; | 32 | use crate::i18n::migrate::{self as mg, K as MGK}; |
| 36 | use crate::i18n::misc::{self as mi, K as MK}; | 33 | use crate::i18n::misc::{self as mi, K as MK}; |
| 37 | use crate::i18n::orgs::{self as o, K as OK}; | 34 | use crate::i18n::orgs::{self as o, K as OK}; |
| 38 | use crate::i18n::{self, Key, Lang, t}; | 35 | use crate::i18n::{self, Key, Lang, t}; |
| 39 | use crate::pages::assets::highlight_css_text; | 36 | use crate::pages::assets::highlight_css_text; |
| 37 | +use crate::pages::user_prefs::{CORNER_POS, TREE_WIDTH, clean_pref}; | ||
| 40 | use crate::state::AppState; | 38 | use crate::state::AppState; |
| 41 | 39 | ||
| 42 | /// Stylesheet URL. The version is a hash of the compiled CSS (build.rs), so a changed stylesheet | 40 | /// Stylesheet URL. The version is a hash of the compiled CSS (build.rs), so a changed stylesheet |
| @@ -95,38 +93,6 @@ fn csp_header(base_url: &str) -> HeaderValue { | |||
| 95 | HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP)) | 93 | HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP)) |
| 96 | } | 94 | } |
| 97 | 95 | ||
| 98 | -/// How many repos the signed-in sidebar lists, freshest first. The sidebar's change stream reads it too. | ||
| 99 | -pub(crate) const SIDE_REPOS: u64 = 5; | ||
| 100 | - | ||
| 101 | -/// A repo link in the signed-in sidebar. | ||
| 102 | -#[derive(Clone)] | ||
| 103 | -struct SideRepo { | ||
| 104 | - name: String, | ||
| 105 | - href: String, | ||
| 106 | -} | ||
| 107 | - | ||
| 108 | -/// The global nav item for a request path: `dashboard` for `/`, `new-org` for `/org/new`, otherwise | ||
| 109 | -/// the first segment when it is a global page. Empty for repo pages and everything else. | ||
| 110 | -fn nav_key(path: &str) -> &'static str { | ||
| 111 | - if path.trim_matches('/') == "org/new" { | ||
| 112 | - return "new-org"; | ||
| 113 | - } | ||
| 114 | - match path.trim_matches('/').split('/').next().unwrap_or("") { | ||
| 115 | - "" => "dashboard", | ||
| 116 | - "explore" => "explore", | ||
| 117 | - "notifications" => "notifications", | ||
| 118 | - "snippets" => "snippets", | ||
| 119 | - "new" => "new", | ||
| 120 | - "settings" => "settings", | ||
| 121 | - _ => "", | ||
| 122 | - } | ||
| 123 | -} | ||
| 124 | - | ||
| 125 | -/// CSS class of a sidebar link. | ||
| 126 | -fn side_class(on: bool) -> &'static str { | ||
| 127 | - if on { "side-link on" } else { "side-link" } | ||
| 128 | -} | ||
| 129 | - | ||
| 130 | /// First path segments that are pages of their own, not owners. A `-` prefix is the same. | 96 | /// First path segments that are pages of their own, not owners. A `-` prefix is the same. |
| 131 | const TOP_LEVEL_PAGES: &[&str] = &[ | 97 | const TOP_LEVEL_PAGES: &[&str] = &[ |
| 132 | "explore", | 98 | "explore", |
| @@ -304,8 +270,8 @@ fn no_runs() -> ActorRuns { | |||
| 304 | } | 270 | } |
| 305 | } | 271 | } |
| 306 | 272 | ||
| 307 | -/// What the profile corner shows: the viewer, their inbox counts with where each leads, and whether | 273 | +/// What the profile corner shows: the viewer, their unread notification count, their inbox counts |
| 308 | -/// any of their runs is going (the ring glows). | 274 | +/// with where each leads, and whether any of their runs is going (the ring glows). |
| 309 | #[derive(Clone)] | 275 | #[derive(Clone)] |
| 310 | struct ProfileCorner { | 276 | struct ProfileCorner { |
| 311 | username: String, | 277 | username: String, |
| @@ -316,6 +282,8 @@ struct ProfileCorner { | |||
| 316 | back: String, | 282 | back: String, |
| 317 | is_admin: bool, | 283 | is_admin: bool, |
| 318 | theme: String, | 284 | theme: String, |
| 285 | + /// Unread notifications, shown as a count on the bell. | ||
| 286 | + unread: u64, | ||
| 319 | reviews: u64, | 287 | reviews: u64, |
| 320 | mentions: u64, | 288 | mentions: u64, |
| 321 | failing: u64, | 289 | failing: u64, |
| @@ -325,9 +293,9 @@ struct ProfileCorner { | |||
| 325 | failing_href: String, | 293 | failing_href: String, |
| 326 | } | 294 | } |
| 327 | 295 | ||
| 328 | -/// The account corner at the foot of the signed-in sidebar and in the phone menu. It opens upward: | 296 | +/// The floating account panel fixed at the bottom left of the window (signed in only). It opens |
| 329 | -/// the avatar, the chips, what waits on the viewer, the notifications link, the theme choice, | 297 | +/// upward: the avatar, the chips, the notifications bell with its unread count and popover, then |
| 330 | -/// and the profile, settings, admin and log out links. | 298 | +/// the Explore, profile, settings, admin and log out links and the theme choice. |
| 331 | #[component] | 299 | #[component] |
| 332 | async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View> { | 300 | async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View> { |
| 333 | let review_chip = (corner.reviews > 0).then(|| { | 301 | let review_chip = (corner.reviews > 0).then(|| { |
| @@ -383,6 +351,7 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View> | |||
| 383 | </span> | 351 | </span> |
| 384 | </summary> | 352 | </summary> |
| 385 | <div class="corner-menu"> | 353 | <div class="corner-menu"> |
| 354 | + <a class="corner-link" href="/explore">(t(lang, Key::Explore))</a> | ||
| 386 | <div class="corner-theme"><span>(theme_label)</span> | 355 | <div class="corner-theme"><span>(theme_label)</span> |
| 387 | <form method="post" action="/-/theme" class="corner-theme-set" data-no-tick="true"> | 356 | <form method="post" action="/-/theme" class="corner-theme-set" data-no-tick="true"> |
| 388 | <input type="hidden" name="csrf" value=(corner.csrf.as_str())> | 357 | <input type="hidden" name="csrf" value=(corner.csrf.as_str())> |
| @@ -409,7 +378,11 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View> | |||
| 409 | </form> | 378 | </form> |
| 410 | </div> | 379 | </div> |
| 411 | </details> | 380 | </details> |
| 412 | - <a class="corner-bell" href="/notifications" title=(bell_label) aria-label=(bell_label) aria-expanded="false"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg></a> | 381 | + <a class="corner-bell" href="/notifications" title=(bell_label) aria-label=(bell_label) aria-expanded="false"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg> |
| 382 | + if corner.unread > 0 { | ||
| 383 | + <span class="bell-count">(corner.unread.to_string())</span> | ||
| 384 | + } | ||
| 385 | + </a> | ||
| 413 | <div class="bell-pop" popover="auto" role="dialog" aria-label=(bell_title) data-loading=(loading_label) data-error=(error_label)> | 386 | <div class="bell-pop" popover="auto" role="dialog" aria-label=(bell_title) data-loading=(loading_label) data-error=(error_label)> |
| 414 | <div class="bell-box"> | 387 | <div class="bell-box"> |
| 415 | <div class="bell-head"> | 388 | <div class="bell-head"> |
| @@ -427,11 +400,11 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View> | |||
| 427 | }) | 400 | }) |
| 428 | } | 401 | } |
| 429 | 402 | ||
| 430 | -/// Page shell: sticky top bar (logo, path bar and, signed in, the live strip), the signed-in | 403 | +/// Page shell: sticky top bar (logo, path bar and, signed in, the live strip), the section sidebar |
| 431 | -/// sidebar with its profile corner, and `child` as the page content. `viewer` drives the chrome: | 404 | +/// on section pages, `child` as the page content, and for signed-in viewers the floating profile |
| 432 | -/// the sidebar, the live strip and the profile corner when signed in; search, theme, Explore and | 405 | +/// corner fixed at the bottom left. `viewer` drives the chrome: the live strip and the profile |
| 433 | -/// Log in otherwise. `extra_stylesheet` adds one more stylesheet link to the head (such as a | 406 | +/// corner when signed in; search, theme, Explore and Log in otherwise. `extra_stylesheet` adds one |
| 434 | -/// repo's generated label colors). | 407 | +/// more stylesheet link to the head (such as a repo's generated label colors). |
| 435 | #[component] | 408 | #[component] |
| 436 | pub async fn shell( | 409 | pub async fn shell( |
| 437 | title: &str, | 410 | title: &str, |
| @@ -440,59 +413,20 @@ pub async fn shell( | |||
| 440 | #[default] child: Child<'_>, | 413 | #[default] child: Child<'_>, |
| 441 | ) -> Result<impl View> { | 414 | ) -> Result<impl View> { |
| 442 | let full_title = format!("{title} \u{b7} forge"); | 415 | let full_title = format!("{title} \u{b7} forge"); |
| 443 | - // The unread count, the viewer's freshest repos for the sidebar (with the total), the profile | 416 | + // The unread count, the profile corner's inbox counts, their CI runs and the items waiting on |
| 444 | - // corner's inbox counts, their CI runs and the items waiting on them. Signed-in only. | 417 | + // them. Signed-in only. |
| 445 | - let (unread, (listed, _), inbox, runs, waiting) = match viewer { | 418 | + let (unread, inbox, runs, waiting) = match viewer { |
| 446 | Some((user, _)) => match try_app_context::<AppState>(__cx) { | 419 | Some((user, _)) => match try_app_context::<AppState>(__cx) { |
| 447 | Some(state) => ( | 420 | Some(state) => ( |
| 448 | state.store.unread_count(&user.id).await?, | 421 | state.store.unread_count(&user.id).await?, |
| 449 | - state | ||
| 450 | - .store | ||
| 451 | - .list_visible_repos( | ||
| 452 | - RepoScope::OwnedBy(&user.id), | ||
| 453 | - Some(user), | ||
| 454 | - None, | ||
| 455 | - RepoSort::RecentlyUpdated, | ||
| 456 | - 1, | ||
| 457 | - SIDE_REPOS, | ||
| 458 | - ) | ||
| 459 | - .await?, | ||
| 460 | state.store.inbox_kind_counts(&user.id).await?, | 422 | state.store.inbox_kind_counts(&user.id).await?, |
| 461 | state.store.actor_runs(&user.id, 120).await?, | 423 | state.store.actor_runs(&user.id, 120).await?, |
| 462 | state.store.waiting_on(&user.id, 5).await?, | 424 | state.store.waiting_on(&user.id, 5).await?, |
| 463 | ), | 425 | ), |
| 464 | - None => (0, (Vec::new(), 0), InboxKinds::default(), no_runs(), Vec::new()), | 426 | + None => (0, InboxKinds::default(), no_runs(), Vec::new()), |
| 465 | }, | 427 | }, |
| 466 | - None => (0, (Vec::new(), 0), InboxKinds::default(), no_runs(), Vec::new()), | 428 | + None => (0, InboxKinds::default(), no_runs(), Vec::new()), |
| 467 | - }; | ||
| 468 | - // The sidebar offers New organization only to those the instance's policy lets create one. | ||
| 469 | - let can_create_org = match (viewer, try_app_context::<AppState>(__cx)) { | ||
| 470 | - (Some((user, _)), Some(state)) => crate::pages::org_new::may_create_org(state, user), | ||
| 471 | - _ => false, | ||
| 472 | }; | 429 | }; |
| 473 | - let unread_badge = (unread > 0).then(|| unread.to_string()); | ||
| 474 | - let side_repos: Vec<SideRepo> = listed | ||
| 475 | - .iter() | ||
| 476 | - .map(|(repo, _, _)| SideRepo { | ||
| 477 | - name: repo.name.clone(), | ||
| 478 | - href: repo_href(&repo.owner_name, &repo.name, "", ""), | ||
| 479 | - }) | ||
| 480 | - .collect(); | ||
| 481 | - // The viewer's own profile Repositories tab has its own sidebar key, so the pinned link lights up there. | ||
| 482 | - let own_repos_tab = viewer.is_some_and(|(user, _)| { | ||
| 483 | - uri(__cx).path().trim_matches('/') == user.username | ||
| 484 | - && uri(__cx) | ||
| 485 | - .query() | ||
| 486 | - .is_some_and(|q| q.split('&').any(|p| p == "tab=repositories")) | ||
| 487 | - }); | ||
| 488 | - let current = if own_repos_tab { | ||
| 489 | - "repositories" | ||
| 490 | - } else { | ||
| 491 | - nav_key(uri(__cx).path()) | ||
| 492 | - }; | ||
| 493 | - let profile_repos_href = viewer | ||
| 494 | - .map(|(user, _)| format!("/{}?tab=repositories", enc(&user.username))) | ||
| 495 | - .unwrap_or_default(); | ||
| 496 | let signed_in = viewer.is_some(); | 430 | let signed_in = viewer.is_some(); |
| 497 | // Both kinds of visitor post to `/-/theme`. Signed-in users send their CSRF token and get the | 431 | // Both kinds of visitor post to `/-/theme`. Signed-in users send their CSRF token and get the |
| 498 | // stored preference saved. Anonymous visitors get the cookie. Either way the browser comes | 432 | // stored preference saved. Anonymous visitors get the cookie. Either way the browser comes |
| @@ -500,7 +434,21 @@ pub async fn shell( | |||
| 500 | let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone()); | 434 | let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone()); |
| 501 | let back = uri(__cx).path_and_query().map(|p| p.as_str().to_owned()); | 435 | let back = uri(__cx).path_and_query().map(|p| p.as_str().to_owned()); |
| 502 | let lang = i18n::lang(__cx, viewer.map(|(user, _)| user)); | 436 | let lang = i18n::lang(__cx, viewer.map(|(user, _)| user)); |
| 503 | - let banner = crate::pages::banner::current(__cx); | 437 | + // A signed-in viewer's account preferences, read once for the banner, the tree width and the |
| 438 | + // profile corner. Signed-out visitors keep theirs in the browser. | ||
| 439 | + let prefs = match (viewer, try_app_context::<AppState>(__cx)) { | ||
| 440 | + (Some((user, _)), Some(state)) => Some(state.store.user_prefs(&user.id).await?), | ||
| 441 | + _ => None, | ||
| 442 | + }; | ||
| 443 | + let banner = crate::pages::banner::current(__cx, prefs.as_ref()); | ||
| 444 | + let tree_w = prefs | ||
| 445 | + .as_ref() | ||
| 446 | + .and_then(|p| p.get(TREE_WIDTH)) | ||
| 447 | + .and_then(|v| clean_pref(TREE_WIDTH, v).ok().flatten()); | ||
| 448 | + let corner_pos = prefs | ||
| 449 | + .as_ref() | ||
| 450 | + .and_then(|p| p.get(CORNER_POS)) | ||
| 451 | + .and_then(|v| clean_pref(CORNER_POS, v).ok().flatten()); | ||
| 504 | let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); | 452 | let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); |
| 505 | let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); | 453 | let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); |
| 506 | // The admin area and the user settings swap the global links for their own list. Signed-in only. | 454 | // The admin area and the user settings swap the global links for their own list. Signed-in only. |
| @@ -591,10 +539,6 @@ pub async fn shell( | |||
| 591 | let search_label = o::t(lang, OK::SearchPublicRepos); | 539 | let search_label = o::t(lang, OK::SearchPublicRepos); |
| 592 | let palette_label = br::t(lang, br::K::PaletteOpen).to_owned(); | 540 | let palette_label = br::t(lang, br::K::PaletteOpen).to_owned(); |
| 593 | let menu_label = t(lang, Key::SiteMenu); | 541 | let menu_label = t(lang, Key::SiteMenu); |
| 594 | - let toggle_class = if unread > 0 { "icon-btn has-dot" } else { "icon-btn" }; | ||
| 595 | - let side_repos_menu = side_repos.clone(); | ||
| 596 | - let unread_menu = unread_badge.clone(); | ||
| 597 | - let unread_aside = unread_badge.clone(); | ||
| 598 | // The path bar: one segment per part of the request path, the last one unlinked. | 542 | // The path bar: one segment per part of the request path, the last one unlinked. |
| 599 | let segments = path_segments(uri(__cx).path(), title); | 543 | let segments = path_segments(uri(__cx).path(), title); |
| 600 | let path_attr = segments | 544 | let path_attr = segments |
| @@ -619,8 +563,7 @@ pub async fn shell( | |||
| 619 | let cancelled_tpl = count_template(&mi::cancelled_count(lang, 2), 2); | 563 | let cancelled_tpl = count_template(&mi::cancelled_count(lang, 2), 2); |
| 620 | let runs_label = mi::t(lang, MK::YourCiRuns); | 564 | let runs_label = mi::t(lang, MK::YourCiRuns); |
| 621 | let search_for_label = mi::t(lang, MK::SearchPublicReposFor); | 565 | let search_for_label = mi::t(lang, MK::SearchPublicReposFor); |
| 622 | - // The profile corner, the signed-in sidebar's account menu. The sidebar and the phone menu | 566 | + // The profile corner, the signed-in account panel. |
| 623 | - // each get their own copy. | ||
| 624 | // Each chip leads to the newest thing it counts; a review or mention past the five newest | 567 | // Each chip leads to the newest thing it counts; a review or mention past the five newest |
| 625 | // waiting items falls back to the inbox. | 568 | // waiting items falls back to the inbox. |
| 626 | let newest_waiting = |review: bool| { | 569 | let newest_waiting = |review: bool| { |
| @@ -643,6 +586,8 @@ pub async fn shell( | |||
| 643 | || "/notifications".to_owned(), | 586 | || "/notifications".to_owned(), |
| 644 | |(owner, repo, number)| repo_href(owner, repo, "ci", &format!("runs/{number}")), | 587 | |(owner, repo, number)| repo_href(owner, repo, "ci", &format!("runs/{number}")), |
| 645 | ); | 588 | ); |
| 589 | + // The corner's drag saves its position with this token, the same one the page's forms send. | ||
| 590 | + let prefs_csrf = viewer.map(|(_, session)| session.csrf_token.clone()).unwrap_or_default(); | ||
| 646 | let corner = viewer.map(|(user, session)| ProfileCorner { | 591 | let corner = viewer.map(|(user, session)| ProfileCorner { |
| 647 | username: user.username.clone(), | 592 | username: user.username.clone(), |
| 648 | name: user | 593 | name: user |
| @@ -657,6 +602,7 @@ pub async fn shell( | |||
| 657 | back: back.clone().unwrap_or_else(|| "/".to_owned()), | 602 | back: back.clone().unwrap_or_else(|| "/".to_owned()), |
| 658 | is_admin: user.is_admin, | 603 | is_admin: user.is_admin, |
| 659 | theme: theme_pref.to_owned(), | 604 | theme: theme_pref.to_owned(), |
| 605 | + unread, | ||
| 660 | reviews: inbox.reviews, | 606 | reviews: inbox.reviews, |
| 661 | mentions: inbox.mentions, | 607 | mentions: inbox.mentions, |
| 662 | failing: runs.failing, | 608 | failing: runs.failing, |
| @@ -664,8 +610,6 @@ pub async fn shell( | |||
| 664 | mention_href, | 610 | mention_href, |
| 665 | failing_href, | 611 | failing_href, |
| 666 | }); | 612 | }); |
| 667 | - let corner_panel = corner.clone(); | ||
| 668 | - let corner_aside = corner; | ||
| 669 | Ok(view! { | 613 | Ok(view! { |
| 670 | <!DOCTYPE html> | 614 | <!DOCTYPE html> |
| 671 | <html lang=(lang.code()) data-theme=(theme_attr) data-accent-light=(accent_light_id) data-accent-dark=(accent_dark_id) data-base-light=(base_light_id) data-base-dark=(base_dark_id) data-sidebar=(sidebar_side) data-rel-words=(rel_words_attr.as_str()) data-rel-now=(rel_now_attr.as_str())> | 615 | <html lang=(lang.code()) data-theme=(theme_attr) data-accent-light=(accent_light_id) data-accent-dark=(accent_dark_id) data-base-light=(base_light_id) data-base-dark=(base_dark_id) data-sidebar=(sidebar_side) data-rel-words=(rel_words_attr.as_str()) data-rel-now=(rel_now_attr.as_str())> |
| @@ -689,22 +633,15 @@ pub async fn shell( | |||
| 689 | } | 633 | } |
| 690 | <script src=(NAV_SCRIPT_HREF) defer="defer"></script> | 634 | <script src=(NAV_SCRIPT_HREF) defer="defer"></script> |
| 691 | </head> | 635 | </head> |
| 692 | - <body data-link-restarting=(lk::t(lang, LinkKey::Restarting)) data-link-back=(lk::t(lang, LinkKey::BackSubmit)) data-done-saved=(lk::t(lang, LinkKey::Saved)) data-done-ok=(lk::t(lang, LinkKey::Done)) data-draft-restored=(lk::t(lang, LinkKey::DraftRestored)) data-draft-discard=(lk::t(lang, LinkKey::DraftDiscard)) data-select-filter=(lk::t(lang, LinkKey::SelectFilter)) data-select-none=(lk::t(lang, LinkKey::SelectNone))> | 636 | + <body data-link-restarting=(lk::t(lang, LinkKey::Restarting)) data-link-back=(lk::t(lang, LinkKey::BackSubmit)) data-done-saved=(lk::t(lang, LinkKey::Saved)) data-done-ok=(lk::t(lang, LinkKey::Done)) data-draft-restored=(lk::t(lang, LinkKey::DraftRestored)) data-draft-discard=(lk::t(lang, LinkKey::DraftDiscard)) data-select-filter=(lk::t(lang, LinkKey::SelectFilter)) data-select-none=(lk::t(lang, LinkKey::SelectNone)) data-signed-in=(signed_in.then(|| "true".to_owned())) data-tree-w=(tree_w) data-corner-pos=(corner_pos)> |
| 693 | <header class="topbar"> | 637 | <header class="topbar"> |
| 694 | - if signed_in { | 638 | + if let Some(section) = section_menu { |
| 695 | <details class="nav-toggle"> | 639 | <details class="nav-toggle"> |
| 696 | - <summary class=(toggle_class) aria-label=(menu_label) title=(menu_label)> | 640 | + <summary class="icon-btn" aria-label=(menu_label) title=(menu_label)> |
| 697 | <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg> | 641 | <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg> |
| 698 | </summary> | 642 | </summary> |
| 699 | <div class="nav-panel"> | 643 | <div class="nav-panel"> |
| 700 | - if let Some(section) = section_menu { | 644 | + section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) |
| 701 | - section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) | ||
| 702 | - } else { | ||
| 703 | - side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_menu, repos: side_repos_menu, can_create_org: can_create_org) | ||
| 704 | - } | ||
| 705 | - if let Some(corner) = corner_panel { | ||
| 706 | - profile_corner(lang: lang, corner: corner) | ||
| 707 | - } | ||
| 708 | </div> | 645 | </div> |
| 709 | </details> | 646 | </details> |
| 710 | } | 647 | } |
| @@ -801,16 +738,9 @@ pub async fn shell( | |||
| 801 | </div> | 738 | </div> |
| 802 | } | 739 | } |
| 803 | <div class="shell"> | 740 | <div class="shell"> |
| 804 | - if signed_in { | 741 | + if let Some(section) = section { |
| 805 | <aside class="shell-sidebar"> | 742 | <aside class="shell-sidebar"> |
| 806 | - if let Some(section) = section { | 743 | + section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) |
| 807 | - section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) | ||
| 808 | - } else { | ||
| 809 | - side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_aside, repos: side_repos, can_create_org: can_create_org) | ||
| 810 | - } | ||
| 811 | - if let Some(corner) = corner_aside { | ||
| 812 | - profile_corner(lang: lang, corner: corner) | ||
| 813 | - } | ||
| 814 | </aside> | 744 | </aside> |
| 815 | } | 745 | } |
| 816 | <div class="shell-body"> | 746 | <div class="shell-body"> |
| @@ -835,6 +765,11 @@ pub async fn shell( | |||
| 835 | </footer> | 765 | </footer> |
| 836 | </div> | 766 | </div> |
| 837 | </div> | 767 | </div> |
| 768 | + if let Some(corner) = corner { | ||
| 769 | + <div class="corner-float" data-prefs-csrf=(prefs_csrf.as_str())> | ||
| 770 | + profile_corner(lang: lang, corner: corner) | ||
| 771 | + </div> | ||
| 772 | + } | ||
| 838 | </body> | 773 | </body> |
| 839 | </html> | 774 | </html> |
| 840 | } | 775 | } |
| @@ -842,82 +777,6 @@ pub async fn shell( | |||
| 842 | .boxed()) | 777 | .boxed()) |
| 843 | } | 778 | } |
| 844 | 779 | ||
| 845 | -/// The signed-in global links and the viewer's repos. The sidebar shows it, and so does the phone | ||
| 846 | -/// menu. `current` is the key from `nav_key`; `profile_repos_href` is the viewer's own Repositories | ||
| 847 | -/// tab; `unread` is the bell count shown next to Notifications. | ||
| 848 | -#[component] | ||
| 849 | -async fn side_nav( | ||
| 850 | - lang: Lang, | ||
| 851 | - current: &str, | ||
| 852 | - profile_repos_href: &str, | ||
| 853 | - unread: Option<String>, | ||
| 854 | - repos: Vec<SideRepo>, | ||
| 855 | - can_create_org: bool, | ||
| 856 | -) -> Result<impl View> { | ||
| 857 | - let dashboard = current == "dashboard"; | ||
| 858 | - let explore = current == "explore"; | ||
| 859 | - let repositories = current == "repositories"; | ||
| 860 | - let notifications = current == "notifications"; | ||
| 861 | - let snippets = current == "snippets"; | ||
| 862 | - let new_repo = current == "new"; | ||
| 863 | - let new_org = current == "new-org"; | ||
| 864 | - let settings = current == "settings"; | ||
| 865 | - let empty = repos.is_empty(); | ||
| 866 | - Ok(view! { | ||
| 867 | - <nav class="side-links"> | ||
| 868 | - <a class=(side_class(dashboard)) href="/" aria-current=(dashboard.then_some("page"))> | ||
| 869 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="3" width="7" height="9" rx="1.5"/><rect x="14" y="3" width="7" height="5" rx="1.5"/><rect x="14" y="12" width="7" height="9" rx="1.5"/><rect x="3" y="16" width="7" height="5" rx="1.5"/></svg> | ||
| 870 | - (o::t(lang, OK::Dashboard)) | ||
| 871 | - </a> | ||
| 872 | - <a class=(side_class(explore)) href="/explore" aria-current=(explore.then_some("page"))> | ||
| 873 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m15.5 8.5-2 5-5 2 2-5z"/></svg> | ||
| 874 | - (t(lang, Key::Explore)) | ||
| 875 | - </a> | ||
| 876 | - <a class=(side_class(repositories)) href=(profile_repos_href) aria-current=(repositories.then_some("page"))> | ||
| 877 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 4.5A1.5 1.5 0 0 1 6.5 3H19v15H6.5A1.5 1.5 0 0 0 5 19.5z"/><path d="M5 19.5A1.5 1.5 0 0 0 6.5 21H19v-3"/></svg> | ||
| 878 | - (o::t(lang, OK::Repositories)) | ||
| 879 | - </a> | ||
| 880 | - <a class=(side_class(notifications)) href="/notifications" aria-current=(notifications.then_some("page"))> | ||
| 881 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 7 3 9H3c0-2 3-2 3-9"/><path d="M10.3 21a1.9 1.9 0 0 0 3.4 0"/></svg> | ||
| 882 | - (t(lang, Key::Notifications)) | ||
| 883 | - if let Some(count) = unread { | ||
| 884 | - <span class="count">(count.as_str())</span> | ||
| 885 | - } | ||
| 886 | - </a> | ||
| 887 | - <a class=(side_class(snippets)) href="/snippets" aria-current=(snippets.then_some("page"))> | ||
| 888 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 3h7l5 5v13H7z"/><path d="M10 13h5M10 17h5"/></svg> | ||
| 889 | - (cm::t(lang, CK::Snippets)) | ||
| 890 | - </a> | ||
| 891 | - <a class=(side_class(new_repo)) href="/new" aria-current=(new_repo.then_some("page"))> | ||
| 892 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 8v8M8 12h8"/></svg> | ||
| 893 | - (t(lang, Key::NewRepository)) | ||
| 894 | - </a> | ||
| 895 | - if can_create_org { | ||
| 896 | - <a class=(side_class(new_org)) href="/org/new" aria-current=(new_org.then_some("page"))> | ||
| 897 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 21V5l8-2v18"/><path d="M12 9l8 2v10"/><path d="M2 21h20"/><path d="M8 8v.01M8 12v.01M8 16v.01M16 14v.01M16 18v.01"/></svg> | ||
| 898 | - (o::t(lang, OK::NewOrganization)) | ||
| 899 | - </a> | ||
| 900 | - } | ||
| 901 | - <a class=(side_class(settings)) href="/settings/profile" aria-current=(settings.then_some("page"))> | ||
| 902 | - <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3M5.3 5.3l2.1 2.1M16.6 16.6l2.1 2.1M5.3 18.7l2.1-2.1M16.6 7.4l2.1-2.1"/></svg> | ||
| 903 | - (o::t(lang, OK::Settings)) | ||
| 904 | - </a> | ||
| 905 | - </nav> | ||
| 906 | - <div class="side-group" data-shell-live="side"> | ||
| 907 | - <h2 class="side-h">(o::t(lang, OK::RecentRepositories))</h2> | ||
| 908 | - if empty { | ||
| 909 | - <p class="side-empty">(o::t(lang, OK::NoReposYet))</p> | ||
| 910 | - } else { | ||
| 911 | - <nav class="side-repos"> | ||
| 912 | - for repo in repos.into_iter() { | ||
| 913 | - <a href=(repo.href.as_str())>(repo.name.as_str())</a> | ||
| 914 | - } | ||
| 915 | - </nav> | ||
| 916 | - } | ||
| 917 | - </div> | ||
| 918 | - }) | ||
| 919 | -} | ||
| 920 | - | ||
| 921 | /// One link of a section sidebar. `key` is the second path segment it answers to (`users` for | 780 | /// One link of a section sidebar. `key` is the second path segment it answers to (`users` for |
| 922 | /// `/admin/users`), so the current link follows from the URL alone. | 781 | /// `/admin/users`), so the current link follows from the URL alone. |
| 923 | #[derive(Clone)] | 782 | #[derive(Clone)] |
| @@ -996,7 +855,21 @@ fn org_items(lang: Lang, org: &str) -> Vec<NavItem> { | |||
| 996 | label, | 855 | label, |
| 997 | icon, | 856 | icon, |
| 998 | }; | 857 | }; |
| 858 | + // Overview and Repositories go to the organization's profile, not to a page under `/org`. | ||
| 859 | + let profile = user_href(org); | ||
| 999 | vec![ | 860 | vec![ |
| 861 | + NavItem { | ||
| 862 | + key: "overview", | ||
| 863 | + href: profile.clone(), | ||
| 864 | + label: o::t(lang, OK::Overview), | ||
| 865 | + icon: "profile", | ||
| 866 | + }, | ||
| 867 | + NavItem { | ||
| 868 | + key: "repositories", | ||
| 869 | + href: format!("{profile}?tab=repositories"), | ||
| 870 | + label: o::t(lang, OK::Repositories), | ||
| 871 | + icon: "teams", | ||
| 872 | + }, | ||
| 1000 | item("members", o::t(lang, OK::Members), "users"), | 873 | item("members", o::t(lang, OK::Members), "users"), |
| 1001 | item("teams", o::t(lang, OK::Teams), "teams"), | 874 | item("teams", o::t(lang, OK::Teams), "teams"), |
| 1002 | item("settings", o::t(lang, OK::Settings), "appearance"), | 875 | item("settings", o::t(lang, OK::Settings), "appearance"), |
| @@ -1112,7 +985,7 @@ pub fn section_for(lang: Lang, path: &str) -> Option<Section> { | |||
| 1112 | }) | 985 | }) |
| 1113 | } | 986 | } |
| 1114 | 987 | ||
| 1115 | -/// The section sidebar: a link back to the global navigation, then the section's own links with | 988 | +/// The section sidebar: a link back to the site, then the section's own links with |
| 1116 | /// `aria-current="page"` on the current one. | 989 | /// `aria-current="page"` on the current one. |
| 1117 | #[component] | 990 | #[component] |
| 1118 | async fn section_nav( | 991 | async fn section_nav( |
| @@ -1123,11 +996,12 @@ async fn section_nav( | |||
| 1123 | live: &str, | 996 | live: &str, |
| 1124 | ) -> Result<impl View> { | 997 | ) -> Result<impl View> { |
| 1125 | let live = (!live.is_empty()).then_some(live); | 998 | let live = (!live.is_empty()).then_some(live); |
| 1126 | - let links: Vec<(NavItem, bool)> = items | 999 | + let links: Vec<(NavItem, bool, &'static str)> = items |
| 1127 | .into_iter() | 1000 | .into_iter() |
| 1128 | .map(|item| { | 1001 | .map(|item| { |
| 1129 | let on = item.key == current; | 1002 | let on = item.key == current; |
| 1130 | - (item, on) | 1003 | + let class = if on { "side-link on" } else { "side-link" }; |
| 1004 | + (item, on, class) | ||
| 1131 | }) | 1005 | }) |
| 1132 | .collect(); | 1006 | .collect(); |
| 1133 | Ok(view! { | 1007 | Ok(view! { |
| @@ -1140,8 +1014,8 @@ async fn section_nav( | |||
| 1140 | <div class="side-group"> | 1014 | <div class="side-group"> |
| 1141 | <h2 class="side-h">(title)</h2> | 1015 | <h2 class="side-h">(title)</h2> |
| 1142 | <nav class="side-links" aria-label=(title) data-live=(live)> | 1016 | <nav class="side-links" aria-label=(title) data-live=(live)> |
| 1143 | - for (item, on) in links.into_iter() { | 1017 | + for (item, on, class) in links.into_iter() { |
| 1144 | - <a class=(side_class(on)) href=(item.href) aria-current=(on.then_some("page"))> | 1018 | + <a class=(class) href=(item.href) aria-current=(on.then_some("page"))> |
| 1145 | nav_icon(name: item.icon) | 1019 | nav_icon(name: item.icon) |
| 1146 | (item.label) | 1020 | (item.label) |
| 1147 | </a> | 1021 | </a> |
crates/forge-web/src/views/repo_list.rsmodified+8 -1
| @@ -8,10 +8,17 @@ use topcoat::view::{View, component, view}; | |||
| 8 | 8 | ||
| 9 | use crate::i18n::orgs::{self as g, K}; | 9 | use crate::i18n::orgs::{self as g, K}; |
| 10 | use crate::i18n::{self, Lang}; | 10 | use crate::i18n::{self, Lang}; |
| 11 | -use crate::pages::dashboard::badge_class; | ||
| 12 | use crate::pages::issue_parts::When; | 11 | use crate::pages::issue_parts::When; |
| 13 | use crate::views::repo_href; | 12 | use crate::views::repo_href; |
| 14 | 13 | ||
| 14 | +/// CSS class for a visibility badge. | ||
| 15 | +pub fn badge_class(visibility: Visibility) -> &'static str { | ||
| 16 | + match visibility { | ||
| 17 | + Visibility::Public => "badge public", | ||
| 18 | + Visibility::Private => "badge private", | ||
| 19 | + } | ||
| 20 | +} | ||
| 21 | + | ||
| 15 | /// One listed repo, formatted for display. | 22 | /// One listed repo, formatted for display. |
| 16 | pub struct RepoRow { | 23 | pub struct RepoRow { |
| 17 | href: String, | 24 | href: String, |
crates/forge-web/tests/e2e/browse_e2e.rsmodified+3 -11
| @@ -943,13 +943,11 @@ async fn browsing_pages_stream_their_changes() { | |||
| 943 | ); | 943 | ); |
| 944 | let pushed = push_fixtures(&dir, &pub_url, &dir.join("pub-pages")); | 944 | let pushed = push_fixtures(&dir, &pub_url, &dir.join("pub-pages")); |
| 945 | 945 | ||
| 946 | - // The inbox, the dashboard and the header need a session. Without one they refuse, and no URL | 946 | + // The inbox needs a session. Without one it refuses, and no URL names another user's inbox: |
| 947 | - // names another user's inbox: the viewer always comes from the session. | 947 | + // the viewer always comes from the session. |
| 948 | for path in [ | 948 | for path in [ |
| 949 | "/notifications/events", | 949 | "/notifications/events", |
| 950 | "/notifications/events?all=1&user=tahinli", | 950 | "/notifications/events?all=1&user=tahinli", |
| 951 | - "/dashboard/events", | ||
| 952 | - "/-/side/events", | ||
| 953 | ] { | 951 | ] { |
| 954 | let anonymous = open_stream(&http, path, None).await; | 952 | let anonymous = open_stream(&http, path, None).await; |
| 955 | assert_eq!(anonymous.status().as_u16(), 401, "anonymous {path}"); | 953 | assert_eq!(anonymous.status().as_u16(), 401, "anonymous {path}"); |
| @@ -974,19 +972,13 @@ async fn browsing_pages_stream_their_changes() { | |||
| 974 | "the header shows the star" | 972 | "the header shows the star" |
| 975 | ); | 973 | ); |
| 976 | 974 | ||
| 977 | - // A push moves the pusher's calendar on the dashboard. The dashboard streams to its owner only. | 975 | + // A second push moves main. |
| 978 | - let mut dashboard = open_stream(&http, "/dashboard/events", Some(tahinli.as_str())).await; | ||
| 979 | - assert_eq!(dashboard.status().as_u16(), 200); | ||
| 980 | let work = dir.join("pub-pages"); | 976 | let work = dir.join("pub-pages"); |
| 981 | // push_fixtures leaves the clone on feature/x, so the new commit must go on main. | 977 | // push_fixtures leaves the clone on feature/x, so the new commit must go on main. |
| 982 | ok(&git(&work, &["checkout", "-q", "main"]), "checkout main"); | 978 | ok(&git(&work, &["checkout", "-q", "main"]), "checkout main"); |
| 983 | fs::write(work.join("PUSH.txt"), "pushed again\n").expect("write PUSH.txt"); | 979 | fs::write(work.join("PUSH.txt"), "pushed again\n").expect("write PUSH.txt"); |
| 984 | commit_all(&work, "a second push"); | 980 | commit_all(&work, "a second push"); |
| 985 | ok(&git(&work, &["push", "-q", "origin", "main"]), "push main"); | 981 | ok(&git(&work, &["push", "-q", "origin", "main"]), "push main"); |
| 986 | - let pushed_event = next_chunk(&mut dashboard) | ||
| 987 | - .await | ||
| 988 | - .expect("event for the push"); | ||
| 989 | - assert!(pushed_event.contains("event: changed"), "{pushed_event}"); | ||
| 990 | assert_ne!(pushed, head_sha(&work), "the second push moved main"); | 982 | assert_ne!(pushed, head_sha(&work), "the second push moved main"); |
| 991 | 983 | ||
| 992 | // The explore listing streams to anyone, and a new public repo changes it. | 984 | // The explore listing streams to anyone, and a new public repo changes it. |
crates/forge-web/tests/e2e/orgs_ui_e2e.rsmodified+5 -2
| @@ -387,6 +387,7 @@ async fn org_settings_delete_and_audit_end_to_end() { | |||
| 387 | settings, | 387 | settings, |
| 388 | &[ | 388 | &[ |
| 389 | ("csrf", &csrf), | 389 | ("csrf", &csrf), |
| 390 | + ("display_name", "Acme Inc"), | ||
| 390 | ("description", "Anvils and more"), | 391 | ("description", "Anvils and more"), |
| 391 | ("default_repo_role", "write"), | 392 | ("default_repo_role", "write"), |
| 392 | ("members_can_create", "on"), | 393 | ("members_can_create", "on"), |
| @@ -398,6 +399,8 @@ async fn org_settings_delete_and_audit_end_to_end() { | |||
| 398 | let shown = http.get(¬ice_location(&res), Some(&tahinli)).await; | 399 | let shown = http.get(¬ice_location(&res), Some(&tahinli)).await; |
| 399 | assert!(shown.body.contains("Settings saved."), "saved notice"); | 400 | assert!(shown.body.contains("Settings saved."), "saved notice"); |
| 400 | assert!(shown.body.contains("Anvils and more"), "description saved"); | 401 | assert!(shown.body.contains("Anvils and more"), "description saved"); |
| 402 | + let profile = http.get("/acme", Some(&tahinli)).await; | ||
| 403 | + assert!(profile.body.contains("Acme Inc"), "display name on the profile"); | ||
| 401 | assert_eq!( | 404 | assert_eq!( |
| 402 | selected_value(&shown.body, "default_repo_role").as_deref(), | 405 | selected_value(&shown.body, "default_repo_role").as_deref(), |
| 403 | Some("write"), | 406 | Some("write"), |
| @@ -492,14 +495,14 @@ async fn org_creation_can_be_limited_to_admins() { | |||
| 492 | 495 | ||
| 493 | assert!( | 496 | assert!( |
| 494 | !http | 497 | !http |
| 495 | - .get("/", Some(&tahinli)) | 498 | + .get("/tahinli?tab=organizations", Some(&tahinli)) |
| 496 | .await | 499 | .await |
| 497 | .body | 500 | .body |
| 498 | .contains("href=\"/org/new\""), | 501 | .contains("href=\"/org/new\""), |
| 499 | "a person who may not create orgs sees no New organization link" | 502 | "a person who may not create orgs sees no New organization link" |
| 500 | ); | 503 | ); |
| 501 | assert!( | 504 | assert!( |
| 502 | - http.get("/", Some(&root_session)) | 505 | + http.get("/root?tab=organizations", Some(&root_session)) |
| 503 | .await | 506 | .await |
| 504 | .body | 507 | .body |
| 505 | .contains("href=\"/org/new\""), | 508 | .contains("href=\"/org/new\""), |
crates/forge-web/tests/e2e/repo_settings_e2e.rsmodified+10 -10
| @@ -217,8 +217,11 @@ async fn repo_settings_end_to_end() { | |||
| 217 | ) | 217 | ) |
| 218 | .await; | 218 | .await; |
| 219 | assert_eq!(deleted.status, 303, "owner delete: {}", deleted.body); | 219 | assert_eq!(deleted.status, 303, "owner delete: {}", deleted.body); |
| 220 | - assert_eq!(deleted.header(LOCATION).as_deref(), Some("/")); | 220 | + assert_eq!(deleted.header(LOCATION).as_deref(), Some("/bob?tab=repositories")); |
| 221 | - let notice = cookie_named(&deleted, "forge_notice").expect("notice cookie"); | 221 | + assert!( |
| 222 | + cookie_named(&deleted, "forge_notice").is_some(), | ||
| 223 | + "notice cookie" | ||
| 224 | + ); | ||
| 222 | assert_eq!( | 225 | assert_eq!( |
| 223 | http.get("/bob/pub", Some(&bob)).await.status, | 226 | http.get("/bob/pub", Some(&bob)).await.status, |
| 224 | 404, | 227 | 404, |
| @@ -236,13 +239,10 @@ async fn repo_settings_end_to_end() { | |||
| 236 | "trash entry is a bare repo" | 239 | "trash entry is a bare repo" |
| 237 | ); | 240 | ); |
| 238 | 241 | ||
| 239 | - // The next home page shows the notice once. | 242 | + // The home page sends a signed-in viewer to their own profile. |
| 240 | - let home = http.get("/", Some(&format!("{bob}; {notice}"))).await; | 243 | + let home = http.get("/", Some(&bob)).await; |
| 241 | - assert!(home.body.contains("Repository"), "home page notice missing"); | 244 | + assert_eq!(home.status, 303, "home page for a signed-in viewer"); |
| 242 | - assert!( | 245 | + assert_eq!(home.header(LOCATION).as_deref(), Some("/bob")); |
| 243 | - home.body.contains("bob/pub"), | ||
| 244 | - "home page notice names the repo" | ||
| 245 | - ); | ||
| 246 | 246 | ||
| 247 | // An admin who does not own the repo can delete it. | 247 | // An admin who does not own the repo can delete it. |
| 248 | let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await; | 248 | let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await; |
| @@ -338,7 +338,7 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() { | |||
| 338 | "delete with missing dir: {}", | 338 | "delete with missing dir: {}", |
| 339 | deleted.body | 339 | deleted.body |
| 340 | ); | 340 | ); |
| 341 | - assert_eq!(deleted.header(LOCATION).as_deref(), Some("/")); | 341 | + assert_eq!(deleted.header(LOCATION).as_deref(), Some("/bob?tab=repositories")); |
| 342 | assert_eq!( | 342 | assert_eq!( |
| 343 | http.get("/bob/gone", Some(&bob)).await.status, | 343 | http.get("/bob/gone", Some(&bob)).await.status, |
| 344 | 404, | 344 | 404, |
style/_dashboard.scssdeleted+0 -273
| @@ -1,273 +0,0 @@ | |||
| 1 | -// dashboard: sage redesign of the signed-in home page (pages/dashboard.rs). Greeting, the | ||
| 2 | -// contribution card (see _heatmap.scss), then two columns: repositories and the inbox rows that | ||
| 3 | -// need the viewer. Stacks to one column below 1000px. | ||
| 4 | - | ||
| 5 | -.greet { | ||
| 6 | - margin: 0; | ||
| 7 | - font-size: 14px; | ||
| 8 | - font-weight: 400; | ||
| 9 | - color: var(--muted); | ||
| 10 | -} | ||
| 11 | - | ||
| 12 | -.dash-cols { | ||
| 13 | - display: grid; | ||
| 14 | - grid-template-columns: minmax(0, 1fr); | ||
| 15 | - gap: 36px; | ||
| 16 | - margin-top: 44px; | ||
| 17 | - | ||
| 18 | - @media (min-width: 1000px) { | ||
| 19 | - grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); | ||
| 20 | - gap: 40px; | ||
| 21 | - } | ||
| 22 | -} | ||
| 23 | - | ||
| 24 | -// Section heading with a bottom border, the count and an optional button on the right. | ||
| 25 | -.sec-head { | ||
| 26 | - display: flex; | ||
| 27 | - flex-wrap: wrap; | ||
| 28 | - align-items: center; | ||
| 29 | - gap: 12px; | ||
| 30 | - min-height: calc(var(--control-h) + 12px); | ||
| 31 | - margin-bottom: 4px; | ||
| 32 | - padding-bottom: 12px; | ||
| 33 | - border-bottom: 1px solid var(--border); | ||
| 34 | - | ||
| 35 | - h2 { | ||
| 36 | - margin: 0; | ||
| 37 | - font-size: 15px; | ||
| 38 | - font-weight: 600; | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - .small { | ||
| 42 | - margin-right: auto; | ||
| 43 | - color: var(--muted); | ||
| 44 | - } | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | -.dash-repos { | ||
| 48 | - min-width: 0; | ||
| 49 | - | ||
| 50 | - .table { | ||
| 51 | - min-width: 520px; | ||
| 52 | - font-size: 14.5px; | ||
| 53 | - | ||
| 54 | - th { | ||
| 55 | - padding: 12px 12px 10px 0; | ||
| 56 | - border-bottom: 1px solid var(--border); | ||
| 57 | - text-align: left; | ||
| 58 | - font-size: 12.5px; | ||
| 59 | - font-weight: 500; | ||
| 60 | - color: var(--muted); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - td { | ||
| 64 | - padding: 14px 12px 14px 0; | ||
| 65 | - border-bottom: 1px solid var(--border); | ||
| 66 | - vertical-align: middle; | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - td .badge { | ||
| 70 | - margin-left: 8px; | ||
| 71 | - vertical-align: middle; | ||
| 72 | - } | ||
| 73 | - } | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -// Phone width: the description column goes, so the name column fits without sideways scrolling. | ||
| 77 | -@media (max-width: 639px) { | ||
| 78 | - .dash-repos .table { | ||
| 79 | - min-width: 0; | ||
| 80 | - width: 100%; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - .dash-repos .dash-desc { | ||
| 84 | - display: none; | ||
| 85 | - } | ||
| 86 | -} | ||
| 87 | - | ||
| 88 | -.dash-attention { | ||
| 89 | - min-width: 0; | ||
| 90 | - | ||
| 91 | - .attn { | ||
| 92 | - list-style: none; | ||
| 93 | - margin: 14px 0 0; | ||
| 94 | - padding: 0; | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - .attn li { | ||
| 98 | - display: flex; | ||
| 99 | - flex-direction: column; | ||
| 100 | - gap: 2px; | ||
| 101 | - padding: 12px 0; | ||
| 102 | - border-bottom: 1px solid var(--border); | ||
| 103 | - font-size: 14.5px; | ||
| 104 | - | ||
| 105 | - &:last-child { | ||
| 106 | - border-bottom: 0; | ||
| 107 | - } | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - .attn a { | ||
| 111 | - color: var(--text); | ||
| 112 | - text-decoration: none; | ||
| 113 | - | ||
| 114 | - &:hover { | ||
| 115 | - text-decoration: underline; | ||
| 116 | - } | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - .attn .sub { | ||
| 120 | - color: var(--muted); | ||
| 121 | - font-size: 13px; | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - > p.small { | ||
| 125 | - margin: 14px 0 0; | ||
| 126 | - } | ||
| 127 | -} | ||
| 128 | - | ||
| 129 | -// Explore: one-row search (input, then its button) and a sort control of pill links. | ||
| 130 | -.explore-search { | ||
| 131 | - display: flex; | ||
| 132 | - flex-wrap: wrap; | ||
| 133 | - gap: 8px; | ||
| 134 | - align-items: center; | ||
| 135 | - margin: 18px 0 0; | ||
| 136 | - | ||
| 137 | - input[type="search"] { | ||
| 138 | - flex: 1 1 240px; | ||
| 139 | - width: auto; | ||
| 140 | - min-width: 0; | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - button { | ||
| 144 | - flex: 0 0 auto; | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - @media (max-width: 479px) { | ||
| 148 | - input[type="search"] { | ||
| 149 | - flex: 1 1 100%; | ||
| 150 | - } | ||
| 151 | - } | ||
| 152 | -} | ||
| 153 | - | ||
| 154 | -.explore-sort { | ||
| 155 | - display: flex; | ||
| 156 | - flex-wrap: wrap; | ||
| 157 | - gap: 6px 8px; | ||
| 158 | - align-items: center; | ||
| 159 | - margin: 14px 0 0; | ||
| 160 | - font-size: 13px; | ||
| 161 | - | ||
| 162 | - a, | ||
| 163 | - .current { | ||
| 164 | - display: inline-flex; | ||
| 165 | - align-items: center; | ||
| 166 | - height: 28px; | ||
| 167 | - padding: 0 12px; | ||
| 168 | - border: 1px solid var(--border); | ||
| 169 | - border-radius: var(--radius-full); | ||
| 170 | - color: var(--text-2); | ||
| 171 | - text-decoration: none; | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - a:hover { | ||
| 175 | - background: var(--surface-2); | ||
| 176 | - text-decoration: none; | ||
| 177 | - } | ||
| 178 | - | ||
| 179 | - .current { | ||
| 180 | - border-color: transparent; | ||
| 181 | - background: var(--accent-soft); | ||
| 182 | - color: var(--accent-ink); | ||
| 183 | - font-weight: 600; | ||
| 184 | - } | ||
| 185 | -} | ||
| 186 | - | ||
| 187 | -// A repo listing (profile tabs): search, sort chips, count, rows and pager as one tight block, so | ||
| 188 | -// the profile's section gap does not open between the count line and the list. | ||
| 189 | -.repo-listing { | ||
| 190 | - display: flex; | ||
| 191 | - flex-direction: column; | ||
| 192 | - gap: 10px; | ||
| 193 | - | ||
| 194 | - > .explore-search, | ||
| 195 | - > .explore-sort, | ||
| 196 | - > p { | ||
| 197 | - margin: 0; | ||
| 198 | - } | ||
| 199 | -} | ||
| 200 | - | ||
| 201 | -.repo-item-head { | ||
| 202 | - display: flex; | ||
| 203 | - align-items: center; | ||
| 204 | - gap: 8px; | ||
| 205 | - min-width: 0; | ||
| 206 | - | ||
| 207 | - .repo-name { | ||
| 208 | - min-width: 0; | ||
| 209 | - overflow: hidden; | ||
| 210 | - text-overflow: ellipsis; | ||
| 211 | - white-space: nowrap; | ||
| 212 | - } | ||
| 213 | - | ||
| 214 | - .badge { | ||
| 215 | - flex: 0 0 auto; | ||
| 216 | - } | ||
| 217 | -} | ||
| 218 | - | ||
| 219 | -.repo-item .repo-desc { | ||
| 220 | - overflow: hidden; | ||
| 221 | - text-overflow: ellipsis; | ||
| 222 | - white-space: nowrap; | ||
| 223 | -} | ||
| 224 | - | ||
| 225 | -.pager-numbered { | ||
| 226 | - flex-wrap: wrap; | ||
| 227 | - gap: 4px; | ||
| 228 | - font-size: 13px; | ||
| 229 | - | ||
| 230 | - .pager-page, | ||
| 231 | - .pager-step, | ||
| 232 | - .pager-gap { | ||
| 233 | - display: inline-flex; | ||
| 234 | - align-items: center; | ||
| 235 | - justify-content: center; | ||
| 236 | - min-width: 30px; | ||
| 237 | - height: 30px; | ||
| 238 | - padding: 0 8px; | ||
| 239 | - border-radius: var(--radius-full); | ||
| 240 | - color: var(--text-2); | ||
| 241 | - text-decoration: none; | ||
| 242 | - } | ||
| 243 | - | ||
| 244 | - a:hover { | ||
| 245 | - background: var(--surface-2); | ||
| 246 | - text-decoration: none; | ||
| 247 | - } | ||
| 248 | - | ||
| 249 | - .current { | ||
| 250 | - background: var(--accent-soft); | ||
| 251 | - color: var(--accent-ink); | ||
| 252 | - font-weight: 600; | ||
| 253 | - } | ||
| 254 | - | ||
| 255 | - .pager-gap { | ||
| 256 | - min-width: 20px; | ||
| 257 | - padding: 0; | ||
| 258 | - } | ||
| 259 | -} | ||
| 260 | - | ||
| 261 | -// Organization pages: the name and description stack; the section links are in the shell sidebar. | ||
| 262 | -.org-head { | ||
| 263 | - .org-head-text { | ||
| 264 | - display: grid; | ||
| 265 | - gap: 4px; | ||
| 266 | - min-width: 0; | ||
| 267 | - } | ||
| 268 | - | ||
| 269 | - h1, | ||
| 270 | - p { | ||
| 271 | - margin: 0; | ||
| 272 | - } | ||
| 273 | -} | ||
style/_heatmap.scssmodified+1 -1
| @@ -1,6 +1,6 @@ | |||
| 1 | // heatmap: sage redesign. See docs in the scratchpad PORT.md brief. | 1 | // heatmap: sage redesign. See docs in the scratchpad PORT.md brief. |
| 2 | // | 2 | // |
| 3 | -// The contribution card on the dashboard (views/heatmap.rs). Cells are squares with a 3px gap; | 3 | +// The contribution card on a profile (views/heatmap.rs). Cells are squares with a 3px gap; |
| 4 | // the grid lays out seven rows and fills columns, so a week is one column. Colours come from the | 4 | // the grid lays out seven rows and fills columns, so a week is one column. Colours come from the |
| 5 | // --h0..--h4 tokens below, mixed from the base's surface and the accent, so every accent, base | 5 | // --h0..--h4 tokens below, mixed from the base's surface and the accent, so every accent, base |
| 6 | // and theme gets the same scale. | 6 | // and theme gets the same scale. |
style/_import.scssmodified+6 -0
| @@ -201,6 +201,12 @@ | |||
| 201 | max-width: 100%; | 201 | max-width: 100%; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | +// The recent imports card under the import form (pages/import.rs, recent_imports): as wide as the form. | ||
| 205 | +.import-recent { | ||
| 206 | + max-width: 960px; | ||
| 207 | + margin-top: 16px; | ||
| 208 | +} | ||
| 209 | + | ||
| 204 | .import-job { | 210 | .import-job { |
| 205 | display: flex; | 211 | display: flex; |
| 206 | flex-direction: column; | 212 | flex-direction: column; |
style/_shell.scssmodified+101 -176
| @@ -465,19 +465,6 @@ | |||
| 465 | } | 465 | } |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | -// A dot on the menu button when there are unread notifications (the bell's count moved here). | ||
| 469 | -.nav-toggle summary.has-dot::after { | ||
| 470 | - content: ""; | ||
| 471 | - position: absolute; | ||
| 472 | - top: 5px; | ||
| 473 | - right: 5px; | ||
| 474 | - width: 8px; | ||
| 475 | - height: 8px; | ||
| 476 | - border-radius: 50%; | ||
| 477 | - background: var(--heat-3); | ||
| 478 | - box-shadow: 0 0 0 2px var(--bg); | ||
| 479 | -} | ||
| 480 | - | ||
| 481 | // The shared button keeps its natural width in columns; in the top bar it sits on the centre line. | 468 | // The shared button keeps its natural width in columns; in the top bar it sits on the centre line. |
| 482 | .topbar .button { | 469 | .topbar .button { |
| 483 | align-self: center; | 470 | align-self: center; |
| @@ -526,7 +513,7 @@ | |||
| 526 | top: calc(100% + 8px); | 513 | top: calc(100% + 8px); |
| 527 | } | 514 | } |
| 528 | 515 | ||
| 529 | -// Phone menu: the sidebar in a panel under the top bar. Hidden from 900px. | 516 | +// Phone menu: the section sidebar in a panel under the top bar. Hidden from 900px. |
| 530 | 517 | ||
| 531 | .nav-toggle { | 518 | .nav-toggle { |
| 532 | flex: none; | 519 | flex: none; |
| @@ -549,7 +536,7 @@ | |||
| 549 | box-shadow: var(--shadow); | 536 | box-shadow: var(--shadow); |
| 550 | } | 537 | } |
| 551 | 538 | ||
| 552 | -// Sidebar | 539 | +// Section sidebar (admin, settings and an org's pages). Other pages have none. |
| 553 | 540 | ||
| 554 | .shell { | 541 | .shell { |
| 555 | display: grid; | 542 | display: grid; |
| @@ -589,20 +576,12 @@ | |||
| 589 | color: var(--muted); | 576 | color: var(--muted); |
| 590 | } | 577 | } |
| 591 | 578 | ||
| 592 | - .count { | ||
| 593 | - margin-left: auto; | ||
| 594 | - font-size: 12.5px; | ||
| 595 | - color: var(--muted); | ||
| 596 | - font-variant-numeric: tabular-nums; | ||
| 597 | - } | ||
| 598 | - | ||
| 599 | &.on { | 579 | &.on { |
| 600 | background: var(--accent-soft); | 580 | background: var(--accent-soft); |
| 601 | color: var(--accent-ink); | 581 | color: var(--accent-ink); |
| 602 | font-weight: 600; | 582 | font-weight: 600; |
| 603 | 583 | ||
| 604 | - .ico, | 584 | + .ico { |
| 605 | - .count { | ||
| 606 | color: var(--accent-ink); | 585 | color: var(--accent-ink); |
| 607 | } | 586 | } |
| 608 | } | 587 | } |
| @@ -620,61 +599,22 @@ | |||
| 620 | color: var(--muted); | 599 | color: var(--muted); |
| 621 | } | 600 | } |
| 622 | 601 | ||
| 623 | -.side-empty { | 602 | +// Profile corner: the signed-in user's floating panel at the bottom left of the window (see |
| 624 | - margin: 0 12px; | 603 | +// `.corner-float`). Its menu opens upward from the panel. |
| 625 | - font-size: 13px; | ||
| 626 | - color: var(--muted); | ||
| 627 | -} | ||
| 628 | - | ||
| 629 | -.side-repos { | ||
| 630 | - display: flex; | ||
| 631 | - flex-direction: column; | ||
| 632 | - gap: 2px; | ||
| 633 | - | ||
| 634 | - a { | ||
| 635 | - display: flex; | ||
| 636 | - align-items: center; | ||
| 637 | - min-height: 32px; | ||
| 638 | - padding: 0 12px; | ||
| 639 | - overflow: hidden; | ||
| 640 | - border-radius: var(--radius-md); | ||
| 641 | - font-family: var(--mono); | ||
| 642 | - font-size: 13.5px; | ||
| 643 | - color: var(--text-2); | ||
| 644 | - white-space: nowrap; | ||
| 645 | - text-decoration: none; | ||
| 646 | - | ||
| 647 | - &:hover { | ||
| 648 | - background: var(--surface-2); | ||
| 649 | - text-decoration: none; | ||
| 650 | - } | ||
| 651 | - } | ||
| 652 | -} | ||
| 653 | - | ||
| 654 | -// Profile corner: the signed-in user at the bottom of the sidebar. Its menu opens upward. | ||
| 655 | - | ||
| 656 | -// The corner's outer box: the rule above it and its place at the sidebar's foot. The bell sits in it | ||
| 657 | -// beside the details, so the box holds both. | ||
| 658 | .corner-wrap { | 604 | .corner-wrap { |
| 659 | position: relative; | 605 | position: relative; |
| 660 | - margin-top: auto; | 606 | + display: flex; |
| 661 | - padding-top: 8px; | 607 | + align-items: center; |
| 662 | - border-top: 1px solid var(--border); | 608 | + gap: 4px; |
| 663 | -} | ||
| 664 | - | ||
| 665 | -.nav-panel .corner-wrap { | ||
| 666 | - margin-top: 12px; | ||
| 667 | } | 609 | } |
| 668 | 610 | ||
| 669 | .corner { | 611 | .corner { |
| 670 | position: relative; | 612 | position: relative; |
| 671 | } | 613 | } |
| 672 | 614 | ||
| 673 | -// The phone panel scrolls, so a menu opening upward would be cut at its top: it opens in place. | 615 | +// The panel's menu anchors to the panel's width, not to the summary, so it reads as a menu of its own. |
| 674 | -.nav-panel .corner-menu { | 616 | +.corner-float .corner { |
| 675 | position: static; | 617 | position: static; |
| 676 | - margin-top: 6px; | ||
| 677 | - box-shadow: none; | ||
| 678 | } | 618 | } |
| 679 | 619 | ||
| 680 | .corner-btn { | 620 | .corner-btn { |
| @@ -696,11 +636,6 @@ | |||
| 696 | } | 636 | } |
| 697 | } | 637 | } |
| 698 | 638 | ||
| 699 | -// The bell overlays the summary's right end, so the chips and the name keep clear of it. | ||
| 700 | -.corner-wrap .corner-btn { | ||
| 701 | - padding-right: 48px; | ||
| 702 | -} | ||
| 703 | - | ||
| 704 | // The name wraps onto at most two lines, breaking at spaces. A single word too long for the line | 639 | // The name wraps onto at most two lines, breaking at spaces. A single word too long for the line |
| 705 | // breaks inside it. | 640 | // breaks inside it. |
| 706 | .corner-name { | 641 | .corner-name { |
| @@ -769,12 +704,10 @@ a.chip { | |||
| 769 | } | 704 | } |
| 770 | } | 705 | } |
| 771 | 706 | ||
| 772 | -// The bell at the corner's right end, over the summary row (its 50px: the 8px top padding and the | 707 | +// The bell beside the summary, inside the floating panel. It opens the popover of the newest |
| 773 | -// 34px avatar with the summary's padding). It opens the popover of the newest notifications. | 708 | +// notifications, and its unread count sits on its top right corner. |
| 774 | .corner-bell { | 709 | .corner-bell { |
| 775 | - position: absolute; | 710 | + position: relative; |
| 776 | - top: 19px; | ||
| 777 | - right: 14px; | ||
| 778 | display: grid; | 711 | display: grid; |
| 779 | flex: none; | 712 | flex: none; |
| 780 | place-items: center; | 713 | place-items: center; |
| @@ -794,6 +727,19 @@ a.chip { | |||
| 794 | } | 727 | } |
| 795 | } | 728 | } |
| 796 | 729 | ||
| 730 | +// The unread count on the bell: a small badge over its top right corner. | ||
| 731 | +.corner-bell .bell-count { | ||
| 732 | + position: absolute; | ||
| 733 | + top: -4px; | ||
| 734 | + right: -4px; | ||
| 735 | + min-width: 16px; | ||
| 736 | + height: 16px; | ||
| 737 | + padding: 0 4px; | ||
| 738 | + font-size: 10px; | ||
| 739 | + line-height: 16px; | ||
| 740 | + box-shadow: 0 0 0 2px var(--surface); | ||
| 741 | +} | ||
| 742 | + | ||
| 797 | // The bell's popover: the newest notifications, opened upward from the bell (nav.js places it). The | 743 | // The bell's popover: the newest notifications, opened upward from the bell (nav.js places it). The |
| 798 | // UA's centring is reset so the fixed placement holds. It has no display of its own: the UA hides it | 744 | // UA's centring is reset so the fixed placement holds. It has no display of its own: the UA hides it |
| 799 | // while closed. | 745 | // while closed. |
| @@ -940,8 +886,6 @@ a.chip { | |||
| 940 | 886 | ||
| 941 | .corner-menu { | 887 | .corner-menu { |
| 942 | position: absolute; | 888 | position: absolute; |
| 943 | - left: 8px; | ||
| 944 | - right: 8px; | ||
| 945 | bottom: calc(100% + 6px); | 889 | bottom: calc(100% + 6px); |
| 946 | z-index: 40; | 890 | z-index: 40; |
| 947 | display: grid; | 891 | display: grid; |
| @@ -954,6 +898,63 @@ a.chip { | |||
| 954 | box-shadow: var(--shadow); | 898 | box-shadow: var(--shadow); |
| 955 | } | 899 | } |
| 956 | 900 | ||
| 901 | +// The profile corner: a small panel fixed at the bottom left of the window, the avatar, the chips and | ||
| 902 | +// the bell. The name is left out of the panel; its aria-label still names the viewer. | ||
| 903 | +.corner-float { | ||
| 904 | + position: fixed; | ||
| 905 | + left: 16px; | ||
| 906 | + bottom: 16px; | ||
| 907 | + z-index: 40; | ||
| 908 | + max-width: min(280px, calc(100vw - 32px)); | ||
| 909 | + background: var(--surface); | ||
| 910 | + border: 1px solid var(--border); | ||
| 911 | + border-radius: 999px; | ||
| 912 | + box-shadow: var(--shadow); | ||
| 913 | + padding: 4px 8px; | ||
| 914 | + // The panel can be dragged with a pointer (nav.js): touch must not scroll under it. | ||
| 915 | + touch-action: none; | ||
| 916 | + cursor: grab; | ||
| 917 | + user-select: none; | ||
| 918 | +} | ||
| 919 | + | ||
| 920 | +.corner-float.dragging { | ||
| 921 | + cursor: grabbing; | ||
| 922 | +} | ||
| 923 | + | ||
| 924 | +// Placed in the top half of the window: the menu opens below the panel. In the right half it anchors | ||
| 925 | +// to the panel's right edge instead of the left one. The default corner keeps the upward menu. | ||
| 926 | +.corner-float[data-open="down"] .corner-menu { | ||
| 927 | + top: calc(100% + 6px); | ||
| 928 | + bottom: auto; | ||
| 929 | +} | ||
| 930 | + | ||
| 931 | +// The menu is as wide as its content, at least the panel's width, and never wider than the window. | ||
| 932 | +.corner-float .corner-menu { | ||
| 933 | + left: 8px; | ||
| 934 | + right: auto; | ||
| 935 | + width: max-content; | ||
| 936 | + min-width: calc(100% - 16px); | ||
| 937 | + max-width: calc(100vw - 32px); | ||
| 938 | +} | ||
| 939 | + | ||
| 940 | +.corner-float[data-side="right"] .corner-menu { | ||
| 941 | + left: auto; | ||
| 942 | + right: 8px; | ||
| 943 | +} | ||
| 944 | + | ||
| 945 | +.corner-float .corner-name { | ||
| 946 | + display: none; | ||
| 947 | +} | ||
| 948 | + | ||
| 949 | +.corner-float .corner-btn { | ||
| 950 | + padding: 2px 4px; | ||
| 951 | +} | ||
| 952 | + | ||
| 953 | +.corner-float .corner-avatar .avatar { | ||
| 954 | + width: 28px; | ||
| 955 | + height: 28px; | ||
| 956 | +} | ||
| 957 | + | ||
| 957 | // `button.corner-link` too (Log out): the extra element in the selector outweighs `button.link-button`. | 958 | // `button.corner-link` too (Log out): the extra element in the selector outweighs `button.link-button`. |
| 958 | .corner-link, | 959 | .corner-link, |
| 959 | button.corner-link.link-button { | 960 | button.corner-link.link-button { |
| @@ -1060,7 +1061,21 @@ button.corner-link.link-button { | |||
| 1060 | border-top: 1px solid var(--border); | 1061 | border-top: 1px solid var(--border); |
| 1061 | } | 1062 | } |
| 1062 | 1063 | ||
| 1063 | -// Wide screens: the sidebar sits beside the page, and a repo's tabs replace its links. | 1064 | +// Signed-in pages without a sidebar: the floating profile panel sits over the footer's left edge. |
| 1065 | +body[data-signed-in] .shell:not(:has(> .shell-sidebar)) .site-footer { | ||
| 1066 | + padding-left: 132px; | ||
| 1067 | +} | ||
| 1068 | + | ||
| 1069 | +// The page is one full-width column. A section page (admin, settings, an org) adds its sidebar beside | ||
| 1070 | +// it from 900px, below. | ||
| 1071 | + | ||
| 1072 | +// The floating profile corner sits over the bottom left of the page below 900px: the page keeps | ||
| 1073 | +// clear of it at its end. | ||
| 1074 | +@media (max-width: 899px) { | ||
| 1075 | + .shell-body { | ||
| 1076 | + padding-bottom: 72px; | ||
| 1077 | + } | ||
| 1078 | +} | ||
| 1064 | 1079 | ||
| 1065 | @media (max-width: 699px) { | 1080 | @media (max-width: 699px) { |
| 1066 | .topbar .crumbs { | 1081 | .topbar .crumbs { |
| @@ -1132,7 +1147,6 @@ button.corner-link.link-button { | |||
| 1132 | position: sticky; | 1147 | position: sticky; |
| 1133 | top: var(--topbar-h); | 1148 | top: var(--topbar-h); |
| 1134 | align-self: start; | 1149 | align-self: start; |
| 1135 | - // A column, so the profile corner sits at its bottom (margin-top: auto). | ||
| 1136 | display: flex; | 1150 | display: flex; |
| 1137 | flex-direction: column; | 1151 | flex-direction: column; |
| 1138 | box-sizing: border-box; | 1152 | box-sizing: border-box; |
| @@ -1144,93 +1158,11 @@ button.corner-link.link-button { | |||
| 1144 | background: var(--surface); | 1158 | background: var(--surface); |
| 1145 | border-right: 1px solid var(--border); | 1159 | border-right: 1px solid var(--border); |
| 1146 | } | 1160 | } |
| 1147 | - | ||
| 1148 | - // The profile corner stays above a repo page's fixed tabs, which end where it starts: 50px of | ||
| 1149 | - // corner, its rule and the sidebar's 24px bottom padding. | ||
| 1150 | - .shell-sidebar .corner-wrap { | ||
| 1151 | - position: relative; | ||
| 1152 | - z-index: 6; | ||
| 1153 | - } | ||
| 1154 | - | ||
| 1155 | - .shell:has(> .shell-sidebar .corner-wrap) .repo-tabs { | ||
| 1156 | - bottom: 76px; | ||
| 1157 | - } | ||
| 1158 | - | ||
| 1159 | - // The sticky sidebar is its own stacking layer, under the fixed tabs, so the open menu would sit | ||
| 1160 | - // behind them: while it is open the sidebar rises above the tabs, see-through so they still show. | ||
| 1161 | - .shell-sidebar:has(.corner[open]) { | ||
| 1162 | - z-index: 6; | ||
| 1163 | - } | ||
| 1164 | - | ||
| 1165 | - .shell:has(.repo-tabs) .shell-sidebar:has(.corner[open]) { | ||
| 1166 | - background: transparent; | ||
| 1167 | - } | ||
| 1168 | - | ||
| 1169 | - // A repo page: its tabs become the sidebar, fixed under the top bar, and the global links go. | ||
| 1170 | - .shell:has(.repo-tabs) .shell-sidebar .side-links, | ||
| 1171 | - .shell:has(.repo-tabs) .shell-sidebar .side-group { | ||
| 1172 | - display: none; | ||
| 1173 | - } | ||
| 1174 | - | ||
| 1175 | - .shell:has(> .shell-sidebar) .repo-tabs { | ||
| 1176 | - position: fixed; | ||
| 1177 | - // nav.js sets --shell-top to where the page body starts, below the site banner when there is one. | ||
| 1178 | - top: max(var(--topbar-h), var(--shell-top, 0px)); | ||
| 1179 | - bottom: 0; | ||
| 1180 | - left: 0; | ||
| 1181 | - z-index: 5; | ||
| 1182 | - box-sizing: border-box; | ||
| 1183 | - width: var(--sidebar-w); | ||
| 1184 | - flex-direction: column; | ||
| 1185 | - align-items: stretch; | ||
| 1186 | - gap: 2px; | ||
| 1187 | - margin: 0; | ||
| 1188 | - padding: 16px 12px 24px; | ||
| 1189 | - overflow-x: hidden; | ||
| 1190 | - overflow-y: auto; | ||
| 1191 | - background: var(--surface); | ||
| 1192 | - border-right: 1px solid var(--border); | ||
| 1193 | - border-bottom: 0; | ||
| 1194 | - } | ||
| 1195 | - | ||
| 1196 | - .shell:has(> .shell-sidebar) .repo-tabs .tab { | ||
| 1197 | - display: flex; | ||
| 1198 | - align-items: center; | ||
| 1199 | - gap: 8px; | ||
| 1200 | - min-height: 36px; | ||
| 1201 | - padding: 0 12px; | ||
| 1202 | - border-radius: var(--radius-md); | ||
| 1203 | - box-shadow: none; | ||
| 1204 | - color: var(--text-2); | ||
| 1205 | - font-size: 14.5px; | ||
| 1206 | - font-weight: 500; | ||
| 1207 | - | ||
| 1208 | - &:hover { | ||
| 1209 | - background: var(--surface-2); | ||
| 1210 | - color: var(--text); | ||
| 1211 | - } | ||
| 1212 | - | ||
| 1213 | - &.active { | ||
| 1214 | - background: var(--accent-soft); | ||
| 1215 | - color: var(--accent-ink); | ||
| 1216 | - font-weight: 600; | ||
| 1217 | - box-shadow: none; | ||
| 1218 | - } | ||
| 1219 | - } | ||
| 1220 | - | ||
| 1221 | - .shell:has(> .shell-sidebar) .repo-tabs .tab-count { | ||
| 1222 | - margin-left: auto; | ||
| 1223 | - padding: 0; | ||
| 1224 | - background: none; | ||
| 1225 | - font-size: 12.5px; | ||
| 1226 | - color: var(--muted); | ||
| 1227 | - font-variant-numeric: tabular-nums; | ||
| 1228 | - } | ||
| 1229 | } | 1161 | } |
| 1230 | 1162 | ||
| 1231 | -// Sidebar on the right (the user's preference, set on <html> as data-sidebar). The sidebar takes the | 1163 | +// Sidebar on the right (the user's preference, set on <html> as data-sidebar). The section sidebar |
| 1232 | -// second column and its border moves to its inner edge. A repo's tabs follow it. Below 900px the | 1164 | +// takes the second column and its border moves to its inner edge. Below |
| 1233 | -// sidebar is hidden either way, so the phone layout and the nav toggle are unchanged. | 1165 | +// 900px the sidebar is hidden either way, so the phone layout and the nav toggle are unchanged. |
| 1234 | @media (min-width: 900px) { | 1166 | @media (min-width: 900px) { |
| 1235 | html[data-sidebar="right"] .shell:has(> .shell-sidebar) { | 1167 | html[data-sidebar="right"] .shell:has(> .shell-sidebar) { |
| 1236 | grid-template-columns: minmax(0, 1fr) var(--sidebar-w); | 1168 | grid-template-columns: minmax(0, 1fr) var(--sidebar-w); |
| @@ -1241,13 +1173,6 @@ button.corner-link.link-button { | |||
| 1241 | border-right: 0; | 1173 | border-right: 0; |
| 1242 | border-left: 1px solid var(--border); | 1174 | border-left: 1px solid var(--border); |
| 1243 | } | 1175 | } |
| 1244 | - | ||
| 1245 | - html[data-sidebar="right"] .shell:has(> .shell-sidebar) .repo-tabs { | ||
| 1246 | - left: auto; | ||
| 1247 | - right: 0; | ||
| 1248 | - border-right: 0; | ||
| 1249 | - border-left: 1px solid var(--border); | ||
| 1250 | - } | ||
| 1251 | } | 1176 | } |
| 1252 | 1177 | ||
| 1253 | // Soft navigation: a thin progress line along the top while a page is being fetched in place | 1178 | // Soft navigation: a thin progress line along the top while a page is being fetched in place |
style/main.scssmodified+20 -1
| @@ -2230,6 +2230,26 @@ code { | |||
| 2230 | margin-top: 12px; | 2230 | margin-top: 12px; |
| 2231 | } | 2231 | } |
| 2232 | 2232 | ||
| 2233 | +.profile-org-actions { | ||
| 2234 | + display: flex; | ||
| 2235 | + flex-wrap: wrap; | ||
| 2236 | + gap: 8px; | ||
| 2237 | + margin-top: 8px; | ||
| 2238 | +} | ||
| 2239 | + | ||
| 2240 | +.org-settings-grid { | ||
| 2241 | + display: grid; | ||
| 2242 | + grid-template-columns: minmax(0, 1fr); | ||
| 2243 | + gap: 16px; | ||
| 2244 | + align-items: start; | ||
| 2245 | +} | ||
| 2246 | + | ||
| 2247 | +@media (min-width: 900px) { | ||
| 2248 | + .org-settings-grid { | ||
| 2249 | + grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); | ||
| 2250 | + } | ||
| 2251 | +} | ||
| 2252 | + | ||
| 2233 | // Profile tabs: a horizontal underline strip under the header. Reuses the `.tab` and `.tab-count` | 2253 | // Profile tabs: a horizontal underline strip under the header. Reuses the `.tab` and `.tab-count` |
| 2234 | // looks; the sidebar rules for `.repo-tabs` do not apply here. Below the sidebar breakpoint the | 2254 | // looks; the sidebar rules for `.repo-tabs` do not apply here. Below the sidebar breakpoint the |
| 2235 | // strip runs to the screen edges, as `.repo-tabs` does, and the tabs snap as they scroll. | 2255 | // strip runs to the screen edges, as `.repo-tabs` does, and the tabs snap as they scroll. |
| @@ -7023,7 +7043,6 @@ button.ci-job-last { | |||
| 7023 | @import "heatmap"; | 7043 | @import "heatmap"; |
| 7024 | @import "repo"; | 7044 | @import "repo"; |
| 7025 | @import "pull"; | 7045 | @import "pull"; |
| 7026 | -@import "dashboard"; | ||
| 7027 | @import "wiki"; | 7046 | @import "wiki"; |
| 7028 | @import "browse"; | 7047 | @import "browse"; |
| 7029 | @import "import"; | 7048 | @import "import"; |