A repo made private or a lost membership stops showing everywhere
Browse files at this commit50d52fa870add94321724c43c100038535621c1dParent: 374e721- fix
- a repo made private or a lost membership stops showing everywhere
- feat
- command palette, hover prefetch, saved ticks, comment drafts, list memory, empty states, relative times with the exact time on hover, motion on the reader's own actions, and confirm popups in place of "I understand" ticks
82 changed files +2188 -556
- crates/forge-core/src/store/contributions.rs +54 -6
- crates/forge-core/src/store/notifications.rs +41 -13
- crates/forge-core/src/store/repo_listing.rs +26 -2
- crates/forge-web/assets/nav.js +799 -18
- crates/forge-web/src/i18n/admin.rs +28 -0
- crates/forge-web/src/i18n/browse.rs +8 -0
- crates/forge-web/src/i18n/code.rs +6 -6
- crates/forge-web/src/i18n/community.rs +18 -13
- crates/forge-web/src/i18n/integrations.rs +9 -10
- crates/forge-web/src/i18n/issues.rs +4 -0
- crates/forge-web/src/i18n/link.rs +17 -1
- crates/forge-web/src/i18n/migrate.rs +4 -4
- crates/forge-web/src/i18n/orgs.rs +4 -0
- crates/forge-web/src/i18n/packages.rs +3 -0
- crates/forge-web/src/i18n/push.rs +8 -8
- crates/forge-web/src/i18n/releases_ci.rs +2 -6
- crates/forge-web/src/i18n/repo_admin.rs +41 -22
- crates/forge-web/src/package_ops.rs +31 -3
- crates/forge-web/src/pages/admin_backups.rs +9 -9
- crates/forge-web/src/pages/admin_health.rs +12 -18
- crates/forge-web/src/pages/admin_mail.rs +15 -19
- crates/forge-web/src/pages/admin_replication.rs +20 -26
- crates/forge-web/src/pages/admin_runners.rs +5 -3
- crates/forge-web/src/pages/admin_user_detail.rs +4 -8
- crates/forge-web/src/pages/admin_users.rs +4 -7
- crates/forge-web/src/pages/audit_log.rs +9 -12
- crates/forge-web/src/pages/authoring.rs +3 -1
- crates/forge-web/src/pages/branches.rs +2 -2
- crates/forge-web/src/pages/ci_job.rs +25 -4
- crates/forge-web/src/pages/ci_runs.rs +17 -12
- crates/forge-web/src/pages/ci_tests.rs +2 -0
- crates/forge-web/src/pages/code_search.rs +2 -2
- crates/forge-web/src/pages/commits.rs +6 -2
- crates/forge-web/src/pages/compare.rs +2 -2
- crates/forge-web/src/pages/dashboard.rs +5 -3
- crates/forge-web/src/pages/discussions.rs +6 -2
- crates/forge-web/src/pages/explore.rs +7 -2
- crates/forge-web/src/pages/import.rs +19 -15
- crates/forge-web/src/pages/issues_list.rs +20 -6
- crates/forge-web/src/pages/labels_page.rs +11 -10
- crates/forge-web/src/pages/merge_queue.rs +4 -12
- crates/forge-web/src/pages/milestones_page.rs +7 -2
- crates/forge-web/src/pages/mod.rs +1 -0
- crates/forge-web/src/pages/notifications.rs +10 -8
- crates/forge-web/src/pages/org_teams.rs +16 -7
- crates/forge-web/src/pages/packages.rs +5 -3
- crates/forge-web/src/pages/packages_oci.rs +4 -4
- crates/forge-web/src/pages/palette.rs +74 -0
- crates/forge-web/src/pages/profile.rs +4 -4
- crates/forge-web/src/pages/profile_pins.rs +3 -2
- crates/forge-web/src/pages/pulls_list.rs +16 -2
- crates/forge-web/src/pages/refs.rs +2 -2
- crates/forge-web/src/pages/releases.rs +42 -30
- crates/forge-web/src/pages/repo.rs +20 -7
- crates/forge-web/src/pages/repo_collaborators.rs +4 -3
- crates/forge-web/src/pages/repo_ctx.rs +28 -6
- crates/forge-web/src/pages/repo_mirrors.rs +28 -25
- crates/forge-web/src/pages/repo_secrets.rs +9 -8
- crates/forge-web/src/pages/repo_security.rs +7 -9
- crates/forge-web/src/pages/repo_settings.rs +71 -42
- crates/forge-web/src/pages/repo_transfer.rs +22 -12
- crates/forge-web/src/pages/repo_webhooks.rs +28 -15
- crates/forge-web/src/pages/review_requests.rs +2 -2
- crates/forge-web/src/pages/settings_export.rs +3 -12
- crates/forge-web/src/pages/settings_gpg.rs +4 -3
- crates/forge-web/src/pages/settings_keys.rs +4 -3
- crates/forge-web/src/pages/settings_notifications.rs +4 -9
- crates/forge-web/src/pages/settings_sessions.rs +3 -3
- crates/forge-web/src/pages/settings_tokens.rs +4 -3
- crates/forge-web/src/pages/snippets.rs +16 -18
- crates/forge-web/src/pages/wiki.rs +13 -13
- crates/forge-web/src/raw.rs +4 -2
- crates/forge-web/src/views/heatmap.rs +3 -2
- crates/forge-web/src/views/mod.rs +34 -3
- style/_account_admin.scss +2 -0
- style/_drafts.scss +7 -0
- style/_empty.scss +44 -0
- style/_feedback.scss +74 -0
- style/_motion.scss +70 -0
- style/_palette.scss +174 -0
- style/_shell.scss +4 -2
- style/main.scss +6 -1
crates/forge-core/src/store/contributions.rsmodified+54 -6
| @@ -73,7 +73,8 @@ impl Store { | ||
| 73 | 73 | /// Events are grouped by minute and each minute is placed on its local day, so zones with |
| 74 | 74 | /// half-hour or quarter-hour offsets and DST changes land on the right day. |
| 75 | 75 | /// A contribution is a push (ref deletions are left out), an issue or pull request opened |
| 76 | - /// (pull requests are `issues` rows with `kind = 'pull'`), or a comment. | |
| 76 | + /// (pull requests are `issues` rows with `kind = 'pull'`), or a comment. Only public repos count: | |
| 77 | + /// a repo made private takes its contributions off the calendar. | |
| 77 | 78 | pub async fn contribution_counts( |
| 78 | 79 | &self, |
| 79 | 80 | user_id: &str, |
| @@ -84,15 +85,17 @@ impl Store { | ||
| 84 | 85 | let sql = "SELECT minute, COUNT(*) FROM ( \ |
| 85 | 86 | SELECT substr(created_at, 1, 16) AS minute FROM push_events \ |
| 86 | 87 | WHERE actor_id = ?1 AND created_at >= ?2 AND new_oid NOT IN (?3, ?4) \ |
| 88 | + AND repo_id IN (SELECT id FROM repos WHERE visibility = 'public') \ | |
| 87 | 89 | UNION ALL \ |
| 88 | 90 | SELECT substr(created_at, 1, 16) FROM issues \ |
| 89 | 91 | WHERE author_id = ?1 AND created_at >= ?2 AND kind IN ('issue', 'pull') \ |
| 92 | + AND repo_id IN (SELECT id FROM repos WHERE visibility = 'public') \ | |
| 90 | 93 | UNION ALL \ |
| 91 | - SELECT substr(created_at, 1, 16) FROM comments \ | |
| 92 | - WHERE author_id = ?1 AND created_at >= ?2 \ | |
| 94 | + SELECT substr(c.created_at, 1, 16) FROM comments c JOIN issues i ON i.id = c.issue_id \ | |
| 95 | + WHERE c.author_id = ?1 AND c.created_at >= ?2 AND i.repo_id IN (SELECT id FROM repos WHERE visibility = 'public') \ | |
| 93 | 96 | UNION ALL \ |
| 94 | 97 | SELECT substr(created_at, 1, 16) FROM coauthored_commits \ |
| 95 | - WHERE user_id = ?1 AND created_at >= ?2 \ | |
| 98 | + WHERE user_id = ?1 AND created_at >= ?2 AND repo_id IN (SELECT id FROM repos WHERE visibility = 'public') \ | |
| 96 | 99 | ) GROUP BY minute"; |
| 97 | 100 | let params = vec![ |
| 98 | 101 | Value::Text(user_id.to_string()), |
| @@ -133,22 +136,24 @@ impl Store { | ||
| 133 | 136 | 0, '', '' FROM push_events p \ |
| 134 | 137 | JOIN repos r ON r.id = p.repo_id JOIN users o ON o.id = r.owner_id \ |
| 135 | 138 | WHERE p.actor_id = ?1 AND p.created_at >= ?2 AND p.created_at < ?3 \ |
| 136 | - AND p.new_oid NOT IN (?4, ?5) \ | |
| 139 | + AND p.new_oid NOT IN (?4, ?5) AND r.visibility = 'public' \ | |
| 137 | 140 | UNION ALL \ |
| 138 | 141 | SELECT i.kind, o.username, r.name, i.created_at, '', i.number, i.title, '' FROM issues i \ |
| 139 | 142 | JOIN repos r ON r.id = i.repo_id JOIN users o ON o.id = r.owner_id \ |
| 140 | 143 | WHERE i.author_id = ?1 AND i.created_at >= ?2 AND i.created_at < ?3 \ |
| 141 | - AND i.kind IN ('issue', 'pull') \ | |
| 144 | + AND i.kind IN ('issue', 'pull') AND r.visibility = 'public' \ | |
| 142 | 145 | UNION ALL \ |
| 143 | 146 | SELECT 'comment', o.username, r.name, c.created_at, '', i.number, i.title, '' \ |
| 144 | 147 | FROM comments c JOIN issues i ON i.id = c.issue_id \ |
| 145 | 148 | JOIN repos r ON r.id = i.repo_id JOIN users o ON o.id = r.owner_id \ |
| 146 | 149 | WHERE c.author_id = ?1 AND c.created_at >= ?2 AND c.created_at < ?3 \ |
| 150 | + AND r.visibility = 'public' \ | |
| 147 | 151 | UNION ALL \ |
| 148 | 152 | SELECT 'coauthored', o.username, r.name, k.created_at, '', 0, k.summary, k.commit_oid \ |
| 149 | 153 | FROM coauthored_commits k \ |
| 150 | 154 | JOIN repos r ON r.id = k.repo_id JOIN users o ON o.id = r.owner_id \ |
| 151 | 155 | WHERE k.user_id = ?1 AND k.created_at >= ?2 AND k.created_at < ?3 \ |
| 156 | + AND r.visibility = 'public' \ | |
| 152 | 157 | ORDER BY created_at DESC LIMIT ?6"; |
| 153 | 158 | let params = vec![ |
| 154 | 159 | Value::Text(user_id.to_string()), |
| @@ -405,4 +410,47 @@ mod tests { | ||
| 405 | 410 | .is_empty() |
| 406 | 411 | ); |
| 407 | 412 | } |
| 413 | + #[tokio::test] | |
| 414 | + async fn private_repos_are_left_out() { | |
| 415 | + let dir = tempfile::tempdir().unwrap(); | |
| 416 | + let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); | |
| 417 | + let tahinli = store | |
| 418 | + .create_user("tahinli", None, "x", false) | |
| 419 | + .await | |
| 420 | + .unwrap(); | |
| 421 | + let demo = store | |
| 422 | + .create_repo(&tahinli.id, "demo", "", Visibility::Public, "main") | |
| 423 | + .await | |
| 424 | + .unwrap(); | |
| 425 | + let at = "2026-03-01T10:00:00.000000000Z"; | |
| 426 | + store | |
| 427 | + .record_push_event_at(&demo.id, &tahinli.id, "refs/heads/main", ZERO, OID, at) | |
| 428 | + .await | |
| 429 | + .unwrap(); | |
| 430 | + let since = "2026-03-01T00:00:00.000000000Z"; | |
| 431 | + let until = "2026-03-02T00:00:00.000000000Z"; | |
| 432 | + assert_eq!( | |
| 433 | + store.contribution_counts(&tahinli.id, since, "UTC").await.unwrap().len(), | |
| 434 | + 1 | |
| 435 | + ); | |
| 436 | + | |
| 437 | + store | |
| 438 | + .set_repo_visibility(&demo.id, Visibility::Private) | |
| 439 | + .await | |
| 440 | + .unwrap(); | |
| 441 | + assert!( | |
| 442 | + store | |
| 443 | + .contribution_counts(&tahinli.id, since, "UTC") | |
| 444 | + .await | |
| 445 | + .unwrap() | |
| 446 | + .is_empty() | |
| 447 | + ); | |
| 448 | + assert!( | |
| 449 | + store | |
| 450 | + .contributions_between(&tahinli.id, since, until) | |
| 451 | + .await | |
| 452 | + .unwrap() | |
| 453 | + .is_empty() | |
| 454 | + ); | |
| 455 | + } | |
| 408 | 456 | } |
crates/forge-core/src/store/notifications.rsmodified+41 -13
| @@ -4,6 +4,7 @@ use turso::transaction::Transaction; | ||
| 4 | 4 | use turso::{Row, Value}; |
| 5 | 5 | |
| 6 | 6 | use super::issues::finish; |
| 7 | +use super::repo_listing::READABLE_BY_VIEWER; | |
| 7 | 8 | use super::{Store, col_int, col_text, db_err, fetch_all, fetch_opt, new_id}; |
| 8 | 9 | use crate::error::{Error, Result}; |
| 9 | 10 | use crate::model::Id; |
| @@ -13,6 +14,20 @@ use crate::time::now_stamp; | ||
| 13 | 14 | /// Largest page `list_notifications` returns, whatever the caller asks for. |
| 14 | 15 | const MAX_NOTIFICATION_PAGE: u32 = 200; |
| 15 | 16 | |
| 17 | +/// The condition under which the inbox owner may still read repo `r`: the read rule, or an | |
| 18 | +/// instance admin. Takes the user id five times. A repo made private, or one the user was removed | |
| 19 | +/// from, drops out of the inbox, the dashboard and the unread count at once. | |
| 20 | +fn readable_repo() -> String { | |
| 21 | + format!( | |
| 22 | + "({READABLE_BY_VIEWER} OR EXISTS (SELECT 1 FROM users ua WHERE ua.id = ? AND ua.is_admin = 1))" | |
| 23 | + ) | |
| 24 | +} | |
| 25 | + | |
| 26 | +/// The user id, bound once per `?` of `readable_repo`. | |
| 27 | +fn readable_params(user_id: &str) -> impl Iterator<Item = Value> + '_ { | |
| 28 | + (0..5).map(move |_| Value::Text(user_id.to_string())) | |
| 29 | +} | |
| 30 | + | |
| 16 | 31 | /// Inbox rows joined with their repo, owner, issue or pull, and last actor. `?` placeholders |
| 17 | 32 | /// are appended to by `list_notifications`. |
| 18 | 33 | const NOTIFICATION_SELECT: &str = "SELECT n.id, n.repo_id, o.username, r.name, n.issue_id, \ |
| @@ -301,8 +316,12 @@ impl Store { | ||
| 301 | 316 | before: Option<&str>, |
| 302 | 317 | limit: u32, |
| 303 | 318 | ) -> Result<Vec<Notification>> { |
| 304 | - let mut sql = format!("{NOTIFICATION_SELECT} WHERE n.user_id = ?"); | |
| 319 | + let mut sql = format!( | |
| 320 | + "{NOTIFICATION_SELECT} WHERE n.user_id = ? AND {}", | |
| 321 | + readable_repo() | |
| 322 | + ); | |
| 305 | 323 | let mut params = vec![Value::Text(user_id.to_string())]; |
| 324 | + params.extend(readable_params(user_id)); | |
| 306 | 325 | if unread_only { |
| 307 | 326 | sql.push_str(" AND n.unread = 1"); |
| 308 | 327 | } |
| @@ -318,20 +337,29 @@ impl Store { | ||
| 318 | 337 | fetch_all(&conn, &sql, params, map_notification).await |
| 319 | 338 | } |
| 320 | 339 | |
| 321 | - /// Number of unread inbox rows of the user, issues and discussions together. | |
| 340 | + /// Number of unread inbox rows of the user, issues and discussions together. Rows of repos the | |
| 341 | + /// user can no longer read are left out. | |
| 322 | 342 | pub async fn unread_count(&self, user_id: &str) -> Result<u64> { |
| 343 | + let readable = readable_repo(); | |
| 344 | + let sql = format!( | |
| 345 | + "SELECT (SELECT COUNT(*) FROM notifications n JOIN repos r ON r.id = n.repo_id \ | |
| 346 | + WHERE n.user_id = ? AND n.unread = 1 AND {readable}) + \ | |
| 347 | + (SELECT COUNT(*) FROM discussion_notifications n JOIN repos r ON r.id = n.repo_id \ | |
| 348 | + WHERE n.user_id = ? AND n.unread = 1 AND {readable}) + \ | |
| 349 | + (SELECT COUNT(*) FROM advisory_notifications n JOIN repos r ON r.id = n.repo_id \ | |
| 350 | + WHERE n.user_id = ? AND n.unread = 1 AND {readable}) + \ | |
| 351 | + (SELECT COUNT(*) FROM admin_notifications WHERE user_id = ? AND unread = 1)" | |
| 352 | + ); | |
| 353 | + let mut params = Vec::new(); | |
| 354 | + for _ in 0..3 { | |
| 355 | + params.push(Value::Text(user_id.to_string())); | |
| 356 | + params.extend(readable_params(user_id)); | |
| 357 | + } | |
| 358 | + params.push(Value::Text(user_id.to_string())); | |
| 323 | 359 | let conn = self.read_conn().await; |
| 324 | - let n = fetch_opt( | |
| 325 | - &conn, | |
| 326 | - "SELECT (SELECT COUNT(*) FROM notifications WHERE user_id = ?1 AND unread = 1) + \ | |
| 327 | - (SELECT COUNT(*) FROM discussion_notifications WHERE user_id = ?1 AND unread = 1) + \ | |
| 328 | - (SELECT COUNT(*) FROM advisory_notifications WHERE user_id = ?1 AND unread = 1) + \ | |
| 329 | - (SELECT COUNT(*) FROM admin_notifications WHERE user_id = ?1 AND unread = 1)", | |
| 330 | - (user_id.to_string(),), | |
| 331 | - |row| col_int(row, 0), | |
| 332 | - ) | |
| 333 | - .await? | |
| 334 | - .unwrap_or(0); | |
| 360 | + let n = fetch_opt(&conn, &sql, params, |row| col_int(row, 0)) | |
| 361 | + .await? | |
| 362 | + .unwrap_or(0); | |
| 335 | 363 | u64::try_from(n).map_err(|_| Error::Database("negative count".into())) |
| 336 | 364 | } |
| 337 | 365 |
crates/forge-core/src/store/repo_listing.rsmodified+26 -2
| @@ -9,7 +9,7 @@ use super::{ | ||
| 9 | 9 | map_repo, |
| 10 | 10 | }; |
| 11 | 11 | use crate::error::Result; |
| 12 | -use crate::model::User; | |
| 12 | +use crate::model::{Repo, User}; | |
| 13 | 13 | |
| 14 | 14 | /// Whose repos a profile tab lists. |
| 15 | 15 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -31,7 +31,7 @@ const STARS: &str = "(SELECT COUNT(*) FROM stars s WHERE s.repo_id = r.id)"; | ||
| 31 | 31 | /// public repos, the viewer's own repos, repos where the viewer is a collaborator, and repos of an |
| 32 | 32 | /// org where the viewer's org role (`Store::org_repo_role`) is some role: an org owner, a member |
| 33 | 33 | /// when the default repo role is not `none`, or a member of a team covering the repo. |
| 34 | -const READABLE_BY_VIEWER: &str = "(r.visibility = 'public' OR r.owner_id = ? \ | |
| 34 | +pub(crate) const READABLE_BY_VIEWER: &str = "(r.visibility = 'public' OR r.owner_id = ? \ | |
| 35 | 35 | OR EXISTS (SELECT 1 FROM collaborators c WHERE c.repo_id = r.id AND c.user_id = ?) \ |
| 36 | 36 | OR EXISTS (SELECT 1 FROM org_members m WHERE m.org_id = r.owner_id AND m.user_id = ? AND ( \ |
| 37 | 37 | m.role = 'owner' \ |
| @@ -94,6 +94,30 @@ impl Store { | ||
| 94 | 94 | Ok(u64::try_from(n).unwrap_or(0)) |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | + /// Up to `limit` repos the signed-in `viewer` is part of: their own, ones they collaborate on, and | |
| 98 | + /// org repos they reach. Sorted by owner and name, for the command palette. Other public repos are | |
| 99 | + /// left out (Explore lists them), and so are an admin's: on a big instance they would push the | |
| 100 | + /// viewer's own repos past the limit. The rule is `READABLE_BY_VIEWER` without its public clause. | |
| 101 | + pub async fn list_viewer_repos(&self, viewer: &User, limit: u64) -> Result<Vec<Repo>> { | |
| 102 | + let where_sql = READABLE_BY_VIEWER.replacen("r.visibility = 'public' OR ", "", 1); | |
| 103 | + debug_assert_ne!(where_sql, READABLE_BY_VIEWER, "the public clause moved"); | |
| 104 | + let params: Vec<Value> = (0..4).map(|_| Value::Text(viewer.id.clone())).collect(); | |
| 105 | + let limit = i64::try_from(limit).unwrap_or(i64::MAX); | |
| 106 | + let mut params = params; | |
| 107 | + params.push(Value::Integer(limit)); | |
| 108 | + let conn = self.read_conn().await; | |
| 109 | + fetch_all( | |
| 110 | + &conn, | |
| 111 | + &format!( | |
| 112 | + "SELECT {REPO_COLS} FROM repos r JOIN users u ON u.id = r.owner_id \ | |
| 113 | + WHERE {where_sql} ORDER BY u.username_folded ASC, r.name_folded ASC LIMIT ?" | |
| 114 | + ), | |
| 115 | + params, | |
| 116 | + map_repo, | |
| 117 | + ) | |
| 118 | + .await | |
| 119 | + } | |
| 120 | + | |
| 97 | 121 | /// One page of the repos `from_sql` (which joins `repos r` and its owner `users u`) yields |
| 98 | 122 | /// under `where_sql`, in `sort` order, with the total match count. `page` is 1-based and is |
| 99 | 123 | /// clamped to the last page; `per_page` to 1..=100. |
crates/forge-web/assets/nav.jsmodified+799 -18
| @@ -175,6 +175,8 @@ | ||
| 175 | 175 | syncTick(); |
| 176 | 176 | syncRel(); |
| 177 | 177 | syncBannerExpiry(); |
| 178 | + syncShellTop(); | |
| 179 | + syncDrafts(); | |
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | // The log tail is a terminal: it opens at its end. A reader who scrolls up keeps their place. |
| @@ -363,18 +365,20 @@ | ||
| 363 | 365 | var user = o.how !== 'live'; |
| 364 | 366 | if (user) { userBusy += 1; clearNote(); } |
| 365 | 367 | busyStart(); |
| 366 | - fetch(o.target.href, o.init).then(function (r) { | |
| 368 | + // A link the reader hovered may already be on its way (takePrefetch); a POST never is. | |
| 369 | + (o.how === 'nav' && !o.form && takePrefetch(o.target.href) || fetch(o.target.href, o.init)).then(function (r) { | |
| 367 | 370 | if (RESTART.indexOf(r.status) >= 0) { return { down: true }; } |
| 368 | 371 | var final = new URL(r.url || o.target.href); |
| 369 | 372 | var html = /^\s*text\/html/i.test(r.headers.get('content-type') || ''); |
| 370 | 373 | if (final.origin !== location.origin || !html) { |
| 371 | 374 | return { leave: true, url: final, redirected: r.redirected }; |
| 372 | 375 | } |
| 373 | - return r.text().then(function (text) { return { html: text, url: final, status: r.status }; }); | |
| 376 | + return r.text().then(function (text) { return { html: text, url: final, status: r.status, redirected: r.redirected }; }); | |
| 374 | 377 | }, function () { |
| 375 | 378 | // No answer at all: the server is down. |
| 376 | 379 | return { down: true }; |
| 377 | 380 | }).then(function (res) { |
| 381 | + o.result = res; | |
| 378 | 382 | if (mark !== latest) { return; } |
| 379 | 383 | if (res.down) { if (o.how !== 'live') { outage(o); } return; } |
| 380 | 384 | if (res.leave) { leave(res, o); return; } |
| @@ -389,11 +393,21 @@ | ||
| 389 | 393 | // navigation: it gets a history entry, so the address bar shows where the page now is. |
| 390 | 394 | var how = o.how === 'live' && res.url.pathname !== o.target.pathname ? 'nav' : o.how; |
| 391 | 395 | swap(res.html, dest, how, !!o.keep && res.url.pathname === o.target.pathname); |
| 396 | + // Other parts of this file follow page changes through this event (list memory, say). | |
| 397 | + document.dispatchEvent(new CustomEvent('forge:swapped', { detail: { how: how, url: dest } })); | |
| 392 | 398 | }).catch(function () { |
| 393 | 399 | if (mark !== latest || o.how === 'live') { return; } |
| 394 | 400 | if (o.post) { o.form.submit(); } else { location.assign(o.dest.href); } |
| 395 | 401 | }).then(function () { |
| 396 | 402 | busyEnd(); |
| 403 | + if (o.post) { | |
| 404 | + submitDone(o, mark === latest); | |
| 405 | + // A POST counts as done only when the server answered with a redirect to a page: the | |
| 406 | + // post-redirect-get every successful form here ends in. Drafts listen for it. | |
| 407 | + var r = o.result; | |
| 408 | + var ok = mark === latest && !!(r && r.html && r.redirected && r.status < 400); | |
| 409 | + document.dispatchEvent(new CustomEvent('forge:submitted', { detail: { form: o.form, ok: ok } })); | |
| 410 | + } | |
| 397 | 411 | if (o.form) { pending.delete(o.form); } |
| 398 | 412 | if (o.how === 'live') { liveBusy = false; } |
| 399 | 413 | if (user) { userBusy -= 1; } |
| @@ -583,7 +597,7 @@ | ||
| 583 | 597 | } |
| 584 | 598 | |
| 585 | 599 | // Dropdown menus: the <details> that float over the page (avatar menu, branch selector, clone |
| 586 | - // popover, phone menu). Inline disclosures are not listed here and keep their state. | |
| 600 | + // popover, phone menu). Inline disclosures are not listed: a click outside leaves them open. | |
| 587 | 601 | var DROPDOWN = 'details.menu, details.ref-select, details.clone, details.nav-toggle'; |
| 588 | 602 | |
| 589 | 603 | // Closes every open dropdown except `keep` (pass null to close them all). |
| @@ -593,11 +607,13 @@ | ||
| 593 | 607 | }); |
| 594 | 608 | } |
| 595 | 609 | |
| 596 | - // Each dropdown gets a key that survives a re-render: its id when it has one, else its summary | |
| 597 | - // text plus a count for repeats (two menus with the same text stay apart, in document order). | |
| 610 | + // Each <details> gets a key that survives a re-render: its id when it has one, else its summary | |
| 611 | + // text plus a count for repeats (two with the same text stay apart, in document order). A live swap | |
| 612 | + // keeps every one as the reader left it: a menu stays open, and so does an inline editor (a branch | |
| 613 | + // rule) the server renders closed, or a form it renders open that the reader closed. | |
| 598 | 614 | function dropdownKeys() { |
| 599 | 615 | var seen = Object.create(null); |
| 600 | - return Array.prototype.map.call(document.querySelectorAll(DROPDOWN), function (d) { | |
| 616 | + return Array.prototype.map.call(document.querySelectorAll('details'), function (d) { | |
| 601 | 617 | if (d.id) { return { key: 'id:' + d.id, el: d }; } |
| 602 | 618 | var s = d.querySelector('summary'); |
| 603 | 619 | var text = s ? s.textContent.replace(/\s+/g, ' ').trim() : ''; |
| @@ -606,21 +622,22 @@ | ||
| 606 | 622 | }); |
| 607 | 623 | } |
| 608 | 624 | |
| 609 | - // Before a live swap: the keys of the open dropdowns, and the key of the one holding focus. | |
| 625 | + // Before a live swap: whether each <details> is open, and the key of the open one holding focus | |
| 626 | + // (the innermost, as nested ones come later in document order). | |
| 610 | 627 | function captureDropdowns() { |
| 611 | 628 | var active = document.activeElement; |
| 612 | - var out = { open: [], focus: null }; | |
| 629 | + var out = { open: Object.create(null), focus: null }; | |
| 613 | 630 | dropdownKeys().forEach(function (item) { |
| 614 | - if (!item.el.open) { return; } | |
| 615 | - out.open.push(item.key); | |
| 616 | - if (active && item.el.contains(active)) { out.focus = item.key; } | |
| 631 | + out.open[item.key] = item.el.open; | |
| 632 | + if (item.el.open && active && item.el.contains(active)) { out.focus = item.key; } | |
| 617 | 633 | }); |
| 618 | 634 | return out; |
| 619 | 635 | } |
| 620 | 636 | |
| 621 | 637 | function openDropdowns(kept) { |
| 622 | 638 | dropdownKeys().forEach(function (item) { |
| 623 | - if (kept.open.indexOf(item.key) >= 0) { item.el.open = true; } | |
| 639 | + var was = kept.open[item.key]; | |
| 640 | + if (was !== undefined && item.el.open !== was) { item.el.open = was; } | |
| 624 | 641 | }); |
| 625 | 642 | } |
| 626 | 643 | |
| @@ -658,6 +675,83 @@ | ||
| 658 | 675 | } |
| 659 | 676 | }, false); |
| 660 | 677 | |
| 678 | + // Inline disclosures (a branch rule, a review thread, a delivery, a <details> in markdown) slide | |
| 679 | + // open and shut instead of jumping. The details' height is animated from where it is to where it | |
| 680 | + // goes, clipped only while it moves, so an open one never clips what it holds. Closing keeps it open | |
| 681 | + // until the slide ends. A click during a slide turns it around. Floating panels (menus, popovers, | |
| 682 | + // inline confirms) are left to the browser, as is a reader who asks for reduced motion. | |
| 683 | + var FLOATING = DROPDOWN + ', details.row-menu, details.confirm-inline, details.commit-status, details.reaction-picker'; | |
| 684 | + var reducedMotion = window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : null; | |
| 685 | + | |
| 686 | + function slideDetails(d) { | |
| 687 | + var opening = d.__closing || !d.open; | |
| 688 | + var from = d.getBoundingClientRect().height; | |
| 689 | + if (d.__slide) { d.__slide.cancel(); } | |
| 690 | + d.open = false; | |
| 691 | + var shut = d.getBoundingClientRect().height; | |
| 692 | + d.open = true; | |
| 693 | + var to = opening ? d.getBoundingClientRect().height : shut; | |
| 694 | + d.__closing = !opening; | |
| 695 | + d.style.overflow = 'hidden'; | |
| 696 | + var slide = d.animate({ height: [from + 'px', to + 'px'] }, { duration: 200, easing: 'cubic-bezier(0.2, 0, 0, 1)' }); | |
| 697 | + d.__slide = slide; | |
| 698 | + slide.onfinish = function () { | |
| 699 | + d.__slide = null; | |
| 700 | + d.style.overflow = ''; | |
| 701 | + if (d.__closing) { d.__closing = false; d.open = false; } | |
| 702 | + }; | |
| 703 | + } | |
| 704 | + | |
| 705 | + document.addEventListener('click', function (e) { | |
| 706 | + if (e.defaultPrevented || !e.target || !e.target.closest) { return; } | |
| 707 | + var summary = e.target.closest('summary'); | |
| 708 | + var d = summary && summary.parentElement; | |
| 709 | + if (!d || d.tagName !== 'DETAILS' || d.querySelector('summary') !== summary) { return; } | |
| 710 | + if (d.matches(FLOATING) || (reducedMotion && reducedMotion.matches)) { return; } | |
| 711 | + // A link or control inside the summary does its own thing. | |
| 712 | + var control = e.target.closest('a, button, input, select, textarea'); | |
| 713 | + if (control && summary.contains(control)) { return; } | |
| 714 | + e.preventDefault(); | |
| 715 | + slideDetails(d); | |
| 716 | + }, false); | |
| 717 | + | |
| 718 | + // Plays a one-shot motion class (see _motion.scss) on the reader's own action. | |
| 719 | + function play(el, cls) { | |
| 720 | + el.classList.remove(cls); | |
| 721 | + void el.offsetWidth; | |
| 722 | + el.classList.add(cls); | |
| 723 | + setTimeout(function () { el.classList.remove(cls); }, 400); | |
| 724 | + } | |
| 725 | + | |
| 726 | + // A menu or popover the reader opens drops in. Only a click opens it this way: a live swap that | |
| 727 | + // keeps one open sets `open` directly and plays nothing. | |
| 728 | + document.addEventListener('click', function (e) { | |
| 729 | + var summary = e.target && e.target.closest ? e.target.closest('summary') : null; | |
| 730 | + var d = summary && summary.parentElement; | |
| 731 | + if (d && d.tagName === 'DETAILS' && !d.open && d.matches(FLOATING)) { play(d, 'pop'); } | |
| 732 | + }, false); | |
| 733 | + | |
| 734 | + // Dismissing the site banner folds it away, then the dismissal is sent. This runs before the | |
| 735 | + // soft submit below, which then sends it. | |
| 736 | + document.addEventListener('submit', function (e) { | |
| 737 | + var form = e.target; | |
| 738 | + var banner = form && form.closest ? form.closest('.site-banner') : null; | |
| 739 | + if (!banner || form.__folded || (reducedMotion && reducedMotion.matches)) { return; } | |
| 740 | + e.preventDefault(); | |
| 741 | + e.stopPropagation(); | |
| 742 | + banner.style.overflow = 'hidden'; | |
| 743 | + banner.animate({ | |
| 744 | + height: [banner.offsetHeight + 'px', '0px'], | |
| 745 | + paddingTop: [getComputedStyle(banner).paddingTop, '0px'], | |
| 746 | + paddingBottom: [getComputedStyle(banner).paddingBottom, '0px'], | |
| 747 | + opacity: [1, 0] | |
| 748 | + }, { duration: 180, easing: 'cubic-bezier(0.2, 0, 0, 1)', fill: 'forwards' }).onfinish = function () { | |
| 749 | + form.__folded = true; | |
| 750 | + form.requestSubmit(); | |
| 751 | + syncShellTop(); | |
| 752 | + }; | |
| 753 | + }, true); | |
| 754 | + | |
| 661 | 755 | // Branch rule form: a suggested check context is added to the required checks field. |
| 662 | 756 | document.addEventListener('click', function (e) { |
| 663 | 757 | var chip = e.target && e.target.closest ? e.target.closest('[data-check-add]') : null; |
| @@ -684,6 +778,13 @@ | ||
| 684 | 778 | // A fragment on the page already shown: the browser scrolls by itself. |
| 685 | 779 | if (url.pathname + url.search === shown && url.hash) { return; } |
| 686 | 780 | e.preventDefault(); |
| 781 | + // A link that only changes what part of this page shows (a calendar day) swaps in place: the | |
| 782 | + // reader's scroll stays, and its anchor, meant for a full page load, is not followed. | |
| 783 | + if (a.hasAttribute('data-keep-scroll') && url.pathname === location.pathname) { | |
| 784 | + var here = withoutHash(url); | |
| 785 | + load({ target: here, dest: here, init: GET_INIT, how: 'query', keep: true, post: false, form: null }); | |
| 786 | + return; | |
| 787 | + } | |
| 687 | 788 | saveScroll(); |
| 688 | 789 | load({ target: withoutHash(url), dest: url, init: GET_INIT, how: 'nav', keep: false, post: false, form: null }); |
| 689 | 790 | }, true); |
| @@ -716,6 +817,7 @@ | ||
| 716 | 817 | } |
| 717 | 818 | |
| 718 | 819 | var multipart = (form.enctype || '').toLowerCase().indexOf('multipart') === 0; |
| 820 | + submitStart(form, submitter); | |
| 719 | 821 | load({ |
| 720 | 822 | target: withoutHash(url), |
| 721 | 823 | dest: url, |
| @@ -727,7 +829,8 @@ | ||
| 727 | 829 | how: 'post', |
| 728 | 830 | keep: true, |
| 729 | 831 | post: true, |
| 730 | - form: form | |
| 832 | + form: form, | |
| 833 | + submitter: submitter | |
| 731 | 834 | }); |
| 732 | 835 | }, false); |
| 733 | 836 | |
| @@ -782,6 +885,7 @@ | ||
| 782 | 885 | var max = parseFloat(field.max); |
| 783 | 886 | if (!isNaN(min)) { next = Math.max(min, next); } |
| 784 | 887 | if (!isNaN(max)) { next = Math.min(max, next); } |
| 888 | + if (String(next) !== field.value) { play(field, 'tick'); } | |
| 785 | 889 | field.value = String(next); |
| 786 | 890 | field.dispatchEvent(new Event('input', { bubbles: true })); |
| 787 | 891 | }); |
| @@ -1833,23 +1937,42 @@ | ||
| 1833 | 1937 | // is removed here, so an open page does not keep one that is gone. One timer is armed for the |
| 1834 | 1938 | // banner on the page; a swap re-arms it. setTimeout takes a 32-bit delay, so a longer wait is armed |
| 1835 | 1939 | // again when this one fires. |
| 1836 | - var bannerTimer = null; | |
| 1940 | + var expiryTimer = null; | |
| 1837 | 1941 | |
| 1838 | 1942 | function syncBannerExpiry() { |
| 1839 | - if (bannerTimer) { clearTimeout(bannerTimer); } | |
| 1840 | - bannerTimer = null; | |
| 1943 | + if (expiryTimer) { clearTimeout(expiryTimer); } | |
| 1944 | + expiryTimer = null; | |
| 1841 | 1945 | var banner = document.querySelector('.site-banner[data-expires]'); |
| 1842 | 1946 | if (!banner) { return; } |
| 1843 | 1947 | var wait = (parseInt(banner.getAttribute('data-expires'), 10) || 0) * 1000 - Date.now(); |
| 1844 | - if (wait <= 0) { banner.remove(); return; } | |
| 1845 | - bannerTimer = setTimeout(syncBannerExpiry, Math.min(wait, 2147483647)); | |
| 1948 | + if (wait <= 0) { banner.remove(); syncShellTop(); return; } | |
| 1949 | + expiryTimer = setTimeout(syncBannerExpiry, Math.min(wait, 2147483647)); | |
| 1950 | + } | |
| 1951 | + | |
| 1952 | + // A repo's tabs are a fixed column (see _shell.scss). They start where the page body starts, so | |
| 1953 | + // whatever sits above it (the site banner) shows, and they rise with it to the top bar on scroll. | |
| 1954 | + var shellFrame = 0; | |
| 1955 | + | |
| 1956 | + function syncShellTop() { | |
| 1957 | + shellFrame = 0; | |
| 1958 | + var shell = document.querySelector('.shell'); | |
| 1959 | + if (!shell) { return; } | |
| 1960 | + document.documentElement.style.setProperty('--shell-top', Math.round(shell.getBoundingClientRect().top) + 'px'); | |
| 1846 | 1961 | } |
| 1847 | 1962 | |
| 1963 | + function queueShellTop() { | |
| 1964 | + if (!shellFrame) { shellFrame = requestAnimationFrame(syncShellTop); } | |
| 1965 | + } | |
| 1966 | + | |
| 1967 | + window.addEventListener('scroll', queueShellTop, { passive: true }); | |
| 1968 | + window.addEventListener('resize', queueShellTop); | |
| 1969 | + | |
| 1848 | 1970 | function syncRel() { |
| 1849 | 1971 | var now = document.documentElement.getAttribute('data-rel-now'); |
| 1850 | 1972 | relSkew = now === null ? 0 : (parseInt(now, 10) || 0) * 1000 - Date.now(); |
| 1851 | 1973 | if (relTimer) { clearTimeout(relTimer); relTimer = null; } |
| 1852 | 1974 | relUpdate(); |
| 1975 | + relTitles(); | |
| 1853 | 1976 | } |
| 1854 | 1977 | |
| 1855 | 1978 | function fmtDuration(secs, root) { |
| @@ -1921,6 +2044,8 @@ | ||
| 1921 | 2044 | syncTick(); |
| 1922 | 2045 | syncRel(); |
| 1923 | 2046 | syncBannerExpiry(); |
| 2047 | + syncShellTop(); | |
| 2048 | + syncDrafts(); | |
| 1924 | 2049 | |
| 1925 | 2050 | window.__forgeQuery = function (href) { |
| 1926 | 2051 | var url = pageUrl(href); |
| @@ -1928,6 +2053,662 @@ | ||
| 1928 | 2053 | load({ target: withoutHash(url), dest: url, init: GET_INIT, how: 'query', keep: true, post: false, form: null }); |
| 1929 | 2054 | }; |
| 1930 | 2055 | placeRun(); |
| 2056 | + | |
| 2057 | + // Hover prefetch: a link the pointer rests on for a moment starts its page request early, so the | |
| 2058 | + // click that often follows finds the answer already on its way. Only what the click handler would | |
| 2059 | + // soft-navigate is fetched, and never a path that writes when viewed or serves a file. | |
| 2060 | + var PREFETCH_DELAY = 80; // ms the pointer must rest on a link before its request starts | |
| 2061 | + var PREFETCH_TTL = 10000; // ms a finished or running prefetch is still used by a click | |
| 2062 | + var PREFETCH_MAX = 4; // stored prefetches; the oldest is dropped first | |
| 2063 | + var NO_PREFETCH = /\/-\/|\/(live|events|stream|open|download)$|\/(archive|raw|actions|attachments|artifacts)\/|\.zip$|\.tar\.gz$|\/releases\/download\/|^\/(logout|notifications)(\/|$)/; | |
| 2064 | + var prefetches = []; // { key, promise, at }: the request for a URL without its hash | |
| 2065 | + var prefetchTimer = null; | |
| 2066 | + var prefetchLink = null; | |
| 2067 | + | |
| 2068 | + // Touch screens have no hover, and a saver asks for less data: neither gets prefetches. | |
| 2069 | + function prefetchAllowed() { | |
| 2070 | + var conn = navigator.connection; | |
| 2071 | + if (conn && conn.saveData) { return false; } | |
| 2072 | + return !(window.matchMedia && window.matchMedia('(hover: none)').matches); | |
| 2073 | + } | |
| 2074 | + | |
| 2075 | + // The URL to prefetch for link `a`, or null. The same rules as the click handler apply, so a | |
| 2076 | + // prefetch never fetches a page a click would not show. | |
| 2077 | + function prefetchUrl(a) { | |
| 2078 | + if (a.target || a.hasAttribute('download') || a.hasAttribute('data-hard') || a.hasAttribute('data-no-prefetch')) { return null; } | |
| 2079 | + var href = a.getAttribute('href') || ''; | |
| 2080 | + if (href.charAt(0) !== '/' || href.charAt(1) === '/') { return null; } | |
| 2081 | + var url = pageUrl(href); | |
| 2082 | + if (!url || NO_PREFETCH.test(url.pathname)) { return null; } | |
| 2083 | + if (url.pathname + url.search === shown) { return null; } | |
| 2084 | + return withoutHash(url); | |
| 2085 | + } | |
| 2086 | + | |
| 2087 | + function startPrefetch(url) { | |
| 2088 | + var key = url.href; | |
| 2089 | + // A page fetched while a form is on its way may show the state before the write. | |
| 2090 | + if (userBusy > 0) { return; } | |
| 2091 | + for (var i = prefetches.length - 1; i >= 0; i--) { | |
| 2092 | + if (prefetches[i].key === key) { prefetches.splice(i, 1); } | |
| 2093 | + } | |
| 2094 | + // A prefetch that fails is asked again when the click takes it, so a blip while hovering never | |
| 2095 | + // reads as an outage. Nothing surfaces from one nobody clicks. | |
| 2096 | + var promise = fetch(key, GET_INIT).catch(function () { return fetch(key, GET_INIT); }); | |
| 2097 | + promise.catch(function () {}); | |
| 2098 | + prefetches.push({ key: key, promise: promise, at: Date.now() }); | |
| 2099 | + while (prefetches.length > PREFETCH_MAX) { prefetches.shift(); } | |
| 2100 | + } | |
| 2101 | + | |
| 2102 | + // Returns a pending fetch Promise<Response> for `href` started on hover, or null. Taken once: a | |
| 2103 | + // Response body can be read only once, so the entry goes whether or not it is still fresh. | |
| 2104 | + function takePrefetch(href) { | |
| 2105 | + for (var i = 0; i < prefetches.length; i++) { | |
| 2106 | + if (prefetches[i].key !== href) { continue; } | |
| 2107 | + var hit = prefetches.splice(i, 1)[0]; | |
| 2108 | + return Date.now() - hit.at < PREFETCH_TTL ? hit.promise : null; | |
| 2109 | + } | |
| 2110 | + return null; | |
| 2111 | + } | |
| 2112 | + | |
| 2113 | + document.addEventListener('mouseover', function (e) { | |
| 2114 | + var a = e.target && e.target.closest ? e.target.closest('a[href]') : null; | |
| 2115 | + if (!a || a === prefetchLink) { return; } | |
| 2116 | + clearTimeout(prefetchTimer); | |
| 2117 | + prefetchTimer = null; | |
| 2118 | + prefetchLink = a; | |
| 2119 | + var url = prefetchUrl(a); | |
| 2120 | + if (!url || !prefetchAllowed()) { return; } | |
| 2121 | + prefetchTimer = setTimeout(function () { | |
| 2122 | + prefetchTimer = null; | |
| 2123 | + startPrefetch(url); | |
| 2124 | + }, PREFETCH_DELAY); | |
| 2125 | + }, true); | |
| 2126 | + | |
| 2127 | + // Leaving the link (not moving between its children) cancels a prefetch that has not started yet. | |
| 2128 | + document.addEventListener('mouseout', function (e) { | |
| 2129 | + var a = e.target && e.target.closest ? e.target.closest('a[href]') : null; | |
| 2130 | + if (!a || a !== prefetchLink || (e.relatedTarget && a.contains(e.relatedTarget))) { return; } | |
| 2131 | + clearTimeout(prefetchTimer); | |
| 2132 | + prefetchTimer = null; | |
| 2133 | + prefetchLink = null; | |
| 2134 | + }, true); | |
| 2135 | + | |
| 2136 | + // A write can change every page, so no prefetch made before a form goes out is kept. | |
| 2137 | + document.addEventListener('submit', function () { | |
| 2138 | + prefetches.length = 0; | |
| 2139 | + clearTimeout(prefetchTimer); | |
| 2140 | + prefetchTimer = null; | |
| 2141 | + prefetchLink = null; | |
| 2142 | + }, true); | |
| 2143 | + | |
| 2144 | + // Submit feedback | |
| 2145 | + // The button shows busy only when the answer is slow (after BUSY_MS), so a quick reply never flickers. | |
| 2146 | + // The tick comes only once the server redirected to a page without an error: nothing looks saved first. | |
| 2147 | + var BUSY_MS = 150; | |
| 2148 | + var TICK_MS = 2200; | |
| 2149 | + var SUBMIT_SEL = 'button[type=submit], button:not([type]), input[type=submit]'; | |
| 2150 | + | |
| 2151 | + function buttonLabel(b) { | |
| 2152 | + return ((b.tagName === 'INPUT' ? b.value : b.textContent) || '').replace(/\s+/g, ' ').trim(); | |
| 2153 | + } | |
| 2154 | + | |
| 2155 | + // The page's forms with this action and method, in document order. | |
| 2156 | + function sameForms(action, method) { | |
| 2157 | + return Array.prototype.filter.call(document.querySelectorAll('form'), function (f) { | |
| 2158 | + return f.getAttribute('action') === action && (f.getAttribute('method') || 'get').toLowerCase() === method; | |
| 2159 | + }); | |
| 2160 | + } | |
| 2161 | + | |
| 2162 | + // Which form and button a POST came from. Taken before the swap: the old form is gone by the answer. | |
| 2163 | + function submitKey(form, btn) { | |
| 2164 | + var action = form.getAttribute('action'); | |
| 2165 | + var method = (form.getAttribute('method') || 'get').toLowerCase(); | |
| 2166 | + return { | |
| 2167 | + action: action, | |
| 2168 | + method: method, | |
| 2169 | + index: sameForms(action, method).indexOf(form), | |
| 2170 | + name: btn ? btn.name : '', | |
| 2171 | + value: btn ? btn.value : '', | |
| 2172 | + text: btn ? buttonLabel(btn) : '', | |
| 2173 | + dirty: form.hasAttribute('data-dirty-form'), | |
| 2174 | + banner: !!(form.closest && form.closest('.site-banner')) | |
| 2175 | + }; | |
| 2176 | + } | |
| 2177 | + | |
| 2178 | + function submitStart(form, submitter) { | |
| 2179 | + var btn = submitter || form.querySelector(SUBMIT_SEL); | |
| 2180 | + var busy = { timer: null, btn: btn, key: submitKey(form, btn) }; | |
| 2181 | + busy.timer = setTimeout(function () { | |
| 2182 | + if (!btn) { return; } | |
| 2183 | + btn.classList.add('is-busy'); | |
| 2184 | + btn.setAttribute('aria-busy', 'true'); | |
| 2185 | + }, BUSY_MS); | |
| 2186 | + form.__busy = busy; | |
| 2187 | + } | |
| 2188 | + | |
| 2189 | + // The button a finished POST came from, in the page now shown: the same-index form with the same | |
| 2190 | + // action and method, then its button by name and value, then by text, then its first submit button. | |
| 2191 | + function doneButton(key) { | |
| 2192 | + var form = sameForms(key.action, key.method)[key.index]; | |
| 2193 | + if (!form) { return null; } | |
| 2194 | + var buttons = form.querySelectorAll('button, input[type=submit]'); | |
| 2195 | + var i; | |
| 2196 | + if (key.name) { | |
| 2197 | + for (i = 0; i < buttons.length; i++) { | |
| 2198 | + if (buttons[i].name === key.name && buttons[i].value === key.value) { return buttons[i]; } | |
| 2199 | + } | |
| 2200 | + } | |
| 2201 | + if (key.text) { | |
| 2202 | + for (i = 0; i < buttons.length; i++) { | |
| 2203 | + if (buttonLabel(buttons[i]) === key.text) { return buttons[i]; } | |
| 2204 | + } | |
| 2205 | + } | |
| 2206 | + return form.querySelector(SUBMIT_SEL); | |
| 2207 | + } | |
| 2208 | + | |
| 2209 | + function showTick(btn, word) { | |
| 2210 | + var svgNs = 'http://www.w3.org/2000/svg'; | |
| 2211 | + var tick = document.createElement('span'); | |
| 2212 | + tick.className = 'done-tick'; | |
| 2213 | + tick.setAttribute('role', 'status'); | |
| 2214 | + var svg = document.createElementNS(svgNs, 'svg'); | |
| 2215 | + svg.setAttribute('class', 'ico'); | |
| 2216 | + svg.setAttribute('viewBox', '0 0 24 24'); | |
| 2217 | + svg.setAttribute('aria-hidden', 'true'); | |
| 2218 | + var path = document.createElementNS(svgNs, 'path'); | |
| 2219 | + path.setAttribute('d', 'M5 12.5l4.5 4.5L19 7.5'); | |
| 2220 | + svg.appendChild(path); | |
| 2221 | + tick.appendChild(svg); | |
| 2222 | + tick.appendChild(document.createTextNode(word)); | |
| 2223 | + btn.insertAdjacentElement('afterend', tick); | |
| 2224 | + setTimeout(function () { tick.remove(); }, TICK_MS); | |
| 2225 | + } | |
| 2226 | + | |
| 2227 | + function submitDone(o, current) { | |
| 2228 | + var form = o.form; | |
| 2229 | + var busy = form && form.__busy; | |
| 2230 | + if (!busy) { return; } | |
| 2231 | + form.__busy = null; | |
| 2232 | + clearTimeout(busy.timer); | |
| 2233 | + if (busy.btn && document.documentElement.contains(busy.btn)) { | |
| 2234 | + busy.btn.classList.remove('is-busy'); | |
| 2235 | + busy.btn.removeAttribute('aria-busy'); | |
| 2236 | + } | |
| 2237 | + var r = o.result; | |
| 2238 | + if (!current || !r || !r.html || !r.redirected || !(r.status < 400)) { return; } | |
| 2239 | + // A refusal sent back on the query (merge_error, branch_error, error...) is not a success. | |
| 2240 | + if (/[?&]\w*error=/.test(r.url.search)) { return; } | |
| 2241 | + var key = busy.key; | |
| 2242 | + if (key.banner || document.querySelector('main .alert, main [role="alert"]')) { return; } | |
| 2243 | + var word = document.body.getAttribute(key.dirty ? 'data-done-saved' : 'data-done-ok'); | |
| 2244 | + var target = doneButton(key); | |
| 2245 | + if (target && word) { showTick(target, word); } | |
| 2246 | + } | |
| 2247 | + | |
| 2248 | + // Comment drafts. Free text in a POST form (comments, bodies, wiki pages, the profile about) is kept | |
| 2249 | + // in localStorage as the reader types, so a closed tab, a crash or a navigation keeps it. An empty | |
| 2250 | + // field with a draft gets the text back, with a note to discard it. A successful post clears them. | |
| 2251 | + function draftConfig() { | |
| 2252 | + // A function, not a var: syncDrafts runs at startup, above this block, and needs these values. | |
| 2253 | + return { | |
| 2254 | + prefix: 'forge-draft:', | |
| 2255 | + maxAge: 7 * 24 * 60 * 60 * 1000, | |
| 2256 | + max: 50, | |
| 2257 | + fields: 'form[method="post"] textarea[name="body"], form[method="post"] textarea[name="content"], form[method="post"] textarea[name="about"]' | |
| 2258 | + }; | |
| 2259 | + } | |
| 2260 | + var draftTimers = new WeakMap(); // a field's pending save: typing again restarts its 400 ms wait | |
| 2261 | + var draftsOnSubmit = new WeakMap(); // a form being posted: the draft keys it held when it was sent | |
| 2262 | + | |
| 2263 | + function draftText(name) { | |
| 2264 | + return (document.body && document.body.getAttribute('data-draft-' + name)) || ''; | |
| 2265 | + } | |
| 2266 | + | |
| 2267 | + // Each field's key: its page, the action it posts to, its name, and its occurrence among the same. | |
| 2268 | + function draftFields() { | |
| 2269 | + var cfg = draftConfig(); | |
| 2270 | + var seen = Object.create(null); | |
| 2271 | + return Array.prototype.map.call(document.querySelectorAll(cfg.fields), function (el) { | |
| 2272 | + var base = cfg.prefix + location.pathname + '|' + ((el.form && el.form.getAttribute('action')) || '') + '|' + el.name; | |
| 2273 | + var n = seen[base] || 0; | |
| 2274 | + seen[base] = n + 1; | |
| 2275 | + return { el: el, k: base + '#' + n }; | |
| 2276 | + }); | |
| 2277 | + } | |
| 2278 | + | |
| 2279 | + function draftKey(el) { | |
| 2280 | + var items = draftFields(); | |
| 2281 | + for (var i = 0; i < items.length; i++) { | |
| 2282 | + if (items[i].el === el) { return items[i].k; } | |
| 2283 | + } | |
| 2284 | + return null; | |
| 2285 | + } | |
| 2286 | + | |
| 2287 | + function readDraft(key) { | |
| 2288 | + try { | |
| 2289 | + var rec = JSON.parse(localStorage.getItem(key)); | |
| 2290 | + return rec && typeof rec.v === 'string' && typeof rec.at === 'number' ? rec : null; | |
| 2291 | + } catch (err) { return null; } | |
| 2292 | + } | |
| 2293 | + | |
| 2294 | + // An empty text removes the draft. Storage can refuse (private mode, a full quota): the draft is then | |
| 2295 | + // not kept, and the page works as before. | |
| 2296 | + function setDraft(key, text) { | |
| 2297 | + try { | |
| 2298 | + if (text === '') { localStorage.removeItem(key); } | |
| 2299 | + else { localStorage.setItem(key, JSON.stringify({ v: text, at: Date.now() })); } | |
| 2300 | + } catch (err) { } | |
| 2301 | + } | |
| 2302 | + | |
| 2303 | + // A draft older than the limit is no draft: it is removed as it is found. | |
| 2304 | + function freshDraft(key) { | |
| 2305 | + var rec = readDraft(key); | |
| 2306 | + if (!rec) { return null; } | |
| 2307 | + if (Date.now() - rec.at > draftConfig().maxAge) { setDraft(key, ''); return null; } | |
| 2308 | + return rec; | |
| 2309 | + } | |
| 2310 | + | |
| 2311 | + // At startup: drop drafts older than the limit and, past the cap, the oldest ones. | |
| 2312 | + function pruneDrafts() { | |
| 2313 | + var cfg = draftConfig(); | |
| 2314 | + try { | |
| 2315 | + var live = []; | |
| 2316 | + for (var i = localStorage.length - 1; i >= 0; i--) { | |
| 2317 | + var key = localStorage.key(i); | |
| 2318 | + if (!key || key.indexOf(cfg.prefix) !== 0) { continue; } | |
| 2319 | + var rec = freshDraft(key); | |
| 2320 | + if (rec) { live.push({ k: key, at: rec.at }); } | |
| 2321 | + } | |
| 2322 | + live.sort(function (a, b) { return b.at - a.at; }); | |
| 2323 | + live.slice(cfg.max).forEach(function (d) { setDraft(d.k, ''); }); | |
| 2324 | + } catch (err) { } | |
| 2325 | + } | |
| 2326 | + | |
| 2327 | + // Puts each stored draft into the empty field it belongs to, once per field, with a note under it. | |
| 2328 | + function restoreDrafts() { | |
| 2329 | + draftFields().forEach(function (item) { | |
| 2330 | + var el = item.el; | |
| 2331 | + if (el.hasAttribute('data-draft-done') || el.value !== '') { return; } | |
| 2332 | + var rec = freshDraft(item.k); | |
| 2333 | + if (!rec) { return; } | |
| 2334 | + el.setAttribute('data-draft-done', ''); | |
| 2335 | + el.value = rec.v; | |
| 2336 | + // The input event lets the dirty-form logic see the field as changed. | |
| 2337 | + el.dispatchEvent(new Event('input', { bubbles: true })); | |
| 2338 | + var note = document.createElement('p'); | |
| 2339 | + note.className = 'draft-note'; | |
| 2340 | + note.appendChild(document.createTextNode(draftText('restored') + ' · ')); | |
| 2341 | + var discard = document.createElement('button'); | |
| 2342 | + discard.type = 'button'; | |
| 2343 | + discard.className = 'link-button'; | |
| 2344 | + discard.setAttribute('data-draft-discard', ''); | |
| 2345 | + discard.textContent = draftText('discard'); | |
| 2346 | + note.appendChild(discard); | |
| 2347 | + el.insertAdjacentElement('afterend', note); | |
| 2348 | + }); | |
| 2349 | + } | |
| 2350 | + | |
| 2351 | + // A swap adopts the new body before its history entry is pushed, so the restore waits a tick and | |
| 2352 | + // the keys then carry the page's own path. | |
| 2353 | + function syncDrafts() { setTimeout(restoreDrafts, 0); } | |
| 2354 | + | |
| 2355 | + pruneDrafts(); | |
| 2356 | + | |
| 2357 | + // A save waits 400 ms after the last keystroke. The key is taken at the keystroke, so a save still | |
| 2358 | + // lands under the page it was typed on when the reader leaves within that wait. | |
| 2359 | + document.addEventListener('input', function (e) { | |
| 2360 | + var el = e.target; | |
| 2361 | + if (!el || !el.matches || !el.matches(draftConfig().fields)) { return; } | |
| 2362 | + var key = draftKey(el); | |
| 2363 | + if (!key) { return; } | |
| 2364 | + clearTimeout(draftTimers.get(el)); | |
| 2365 | + draftTimers.set(el, setTimeout(function () { setDraft(key, el.value); }, 400)); | |
| 2366 | + }); | |
| 2367 | + | |
| 2368 | + // The keys a form holds are taken as it is sent: after a swap the old form is detached. | |
| 2369 | + document.addEventListener('submit', function (e) { | |
| 2370 | + var form = e.target; | |
| 2371 | + if (!form || !form.matches || !form.matches('form[method="post"]')) { return; } | |
| 2372 | + var items = draftFields().filter(function (item) { return form.contains(item.el); }); | |
| 2373 | + // A save still waiting would land after a confirmed post cleared the draft: it is made now. | |
| 2374 | + items.forEach(function (item) { | |
| 2375 | + clearTimeout(draftTimers.get(item.el)); | |
| 2376 | + setDraft(item.k, item.el.value); | |
| 2377 | + }); | |
| 2378 | + draftsOnSubmit.set(form, items.map(function (item) { return item.k; })); | |
| 2379 | + }, true); | |
| 2380 | + | |
| 2381 | + // A post the server confirmed clears the drafts it held. A failed one keeps them. | |
| 2382 | + document.addEventListener('forge:submitted', function (e) { | |
| 2383 | + var form = e.detail ? e.detail.form : null; | |
| 2384 | + var keys = form ? draftsOnSubmit.get(form) : null; | |
| 2385 | + if (!keys) { return; } | |
| 2386 | + draftsOnSubmit.delete(form); | |
| 2387 | + if (e.detail.ok) { keys.forEach(function (k) { setDraft(k, ''); }); } | |
| 2388 | + }); | |
| 2389 | + | |
| 2390 | + // Discard: the field is emptied, its draft removed, and the note goes. | |
| 2391 | + document.addEventListener('click', function (e) { | |
| 2392 | + var btn = e.target && e.target.closest ? e.target.closest('button[data-draft-discard]') : null; | |
| 2393 | + if (!btn) { return; } | |
| 2394 | + var note = btn.parentNode; | |
| 2395 | + var field = note.previousElementSibling; | |
| 2396 | + if (field && field.matches(draftConfig().fields)) { | |
| 2397 | + clearTimeout(draftTimers.get(field)); | |
| 2398 | + var key = draftKey(field); | |
| 2399 | + if (key) { setDraft(key, ''); } | |
| 2400 | + field.value = ''; | |
| 2401 | + field.dispatchEvent(new Event('input', { bubbles: true })); | |
| 2402 | + } | |
| 2403 | + note.remove(); | |
| 2404 | + }); | |
| 2405 | + | |
| 2406 | + // List memory: a list page keeps its filters (per path, in sessionStorage) and its scroll position | |
| 2407 | + // when the reader leaves and comes back. Paging parameters are not filters. | |
| 2408 | + var LIST_PAGE = /^\/[^\/]+\/[^\/]+\/(issues|pulls|ci|commits\/.*|releases|tags|branches|discussions|labels|milestones|merge-queue|search)$|^\/(explore|notifications|review-requests|admin\/users|admin\/runners|admin\/audit|settings\/security\/log|org\/[^\/]+\/members)$/; | |
| 2409 | + var LIST_PAGING = ['page', 'before', 'after', 'cursor']; | |
| 2410 | + var LIST_Y_TTL = 30 * 60 * 1000; // ms a remembered scroll position is still used | |
| 2411 | + | |
| 2412 | + function listStore(key, value) { | |
| 2413 | + try { | |
| 2414 | + if (value === null) { sessionStorage.removeItem(key); } else { sessionStorage.setItem(key, value); } | |
| 2415 | + } catch (err) { } | |
| 2416 | + } | |
| 2417 | + | |
| 2418 | + function listLoad(key) { | |
| 2419 | + try { return sessionStorage.getItem(key); } catch (err) { return null; } | |
| 2420 | + } | |
| 2421 | + | |
| 2422 | + // The filters of a list page's search, with a leading `?`, or '' when there are none. | |
| 2423 | + function listFilters(search) { | |
| 2424 | + var params = new URLSearchParams(search); | |
| 2425 | + LIST_PAGING.forEach(function (key) { params.delete(key); }); | |
| 2426 | + var text = params.toString(); | |
| 2427 | + return text ? '?' + text : ''; | |
| 2428 | + } | |
| 2429 | + | |
| 2430 | + // An empty filter set forgets the page: a cleared list comes back clear. | |
| 2431 | + function rememberList(path, search) { | |
| 2432 | + if (!LIST_PAGE.test(path)) { return; } | |
| 2433 | + var filters = listFilters(search); | |
| 2434 | + listStore('forge-list:' + path, filters || null); | |
| 2435 | + } | |
| 2436 | + | |
| 2437 | + rememberList(location.pathname, location.search); | |
| 2438 | + | |
| 2439 | + document.addEventListener('forge:swapped', function (e) { | |
| 2440 | + var url = e.detail.url; | |
| 2441 | + rememberList(url.pathname, url.search); | |
| 2442 | + // Only a navigation lands at the top of a list the reader had scrolled; back and forward have their own place. | |
| 2443 | + if (e.detail.how !== 'nav' || !LIST_PAGE.test(url.pathname) || url.hash) { return; } | |
| 2444 | + var saved = null; | |
| 2445 | + try { saved = JSON.parse(listLoad('forge-list-y:' + url.pathname + url.search) || 'null'); } catch (err) { saved = null; } | |
| 2446 | + if (!saved || typeof saved.y !== 'number' || Date.now() - saved.t > LIST_Y_TTL) { return; } | |
| 2447 | + // Only when the page is tall enough to reach the place; a shorter page would scroll to its end. | |
| 2448 | + if (document.documentElement.scrollHeight - window.innerHeight < saved.y) { return; } | |
| 2449 | + window.scrollTo(0, saved.y); | |
| 2450 | + }); | |
| 2451 | + | |
| 2452 | + // Runs before the navigation handler below: a link to a list's bare path goes to its remembered | |
| 2453 | + // filters, unless the reader is on that list already (then the bare link clears them). | |
| 2454 | + window.addEventListener('click', function (e) { | |
| 2455 | + if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) { return; } | |
| 2456 | + var a = e.target && e.target.closest ? e.target.closest('a[href]') : null; | |
| 2457 | + if (!a || a.target || a.hasAttribute('download') || a.hasAttribute('data-hard')) { return; } | |
| 2458 | + var href = a.getAttribute('href') || ''; | |
| 2459 | + if (href.charAt(0) !== '/' || href.charAt(1) === '/') { return; } | |
| 2460 | + var url = pageUrl(href); | |
| 2461 | + if (!url) { return; } | |
| 2462 | + // Leaving a list by a link: its scroll position is kept for when the reader comes back. | |
| 2463 | + if (LIST_PAGE.test(location.pathname) && !(url.pathname + url.search === shown && url.hash)) { | |
| 2464 | + listStore('forge-list-y:' + shown, JSON.stringify({ y: window.scrollY, t: Date.now() })); | |
| 2465 | + } | |
| 2466 | + if (href === url.pathname && url.pathname !== location.pathname && LIST_PAGE.test(href)) { | |
| 2467 | + var kept = listLoad('forge-list:' + href); | |
| 2468 | + if (kept) { a.setAttribute('href', href + kept); } | |
| 2469 | + } | |
| 2470 | + }, true); | |
| 2471 | + | |
| 2472 | + // Command palette | |
| 2473 | + // Ctrl+K (Cmd+K on a Mac, or the topbar button) opens a dialog that jumps to the viewer's repos, | |
| 2474 | + // orgs and pages. The server list is fetched on the first open and kept for a minute; on a repo | |
| 2475 | + // page that repo's tabs are read from the page instead, so they never wait for the server. | |
| 2476 | + var PALETTE_TTL = 60000; // ms a fetched list stays fresh | |
| 2477 | + var PALETTE_MAX = 50; // options shown at once | |
| 2478 | + var PALETTE_WORD = /[\s\/._\-·]/; // a character that starts a word, for the word-start match | |
| 2479 | + var pal = { dlg: null, input: null, list: null, note: null, hits: [], sel: 0, str: null, | |
| 2480 | + data: null, request: null, failed: false }; | |
| 2481 | + | |
| 2482 | + // The words the palette shows, read from the topbar button: the server writes them in the viewer's | |
| 2483 | + // language, so this script carries no text of its own. | |
| 2484 | + function paletteStrings(opener) { | |
| 2485 | + function word(name) { return opener.getAttribute('data-' + name) || ''; } | |
| 2486 | + return { | |
| 2487 | + label: opener.getAttribute('aria-label') || '', | |
| 2488 | + placeholder: word('placeholder'), | |
| 2489 | + hint: word('hint'), | |
| 2490 | + empty: word('empty'), | |
| 2491 | + loading: word('loading'), | |
| 2492 | + failed: word('failed'), | |
| 2493 | + heads: { repo: word('repos'), org: word('orgs'), page: word('pages') } | |
| 2494 | + }; | |
| 2495 | + } | |
| 2496 | + | |
| 2497 | + // How well the lowercased query matches a label: 3 for a prefix, 2 for a match at a word start, | |
| 2498 | + // 1 for the letters in order anywhere, 0 for no match. A shorter label wins within a tier, and the | |
| 2499 | + // bonus stays under 0.5 so it never lifts a label into the tier above. An empty query matches all. | |
| 2500 | + function paletteScore(q, label) { | |
| 2501 | + if (!q) { return 1; } | |
| 2502 | + var s = label.toLowerCase(); | |
| 2503 | + var bonus = 1 / (s.length + 2); | |
| 2504 | + var at = s.indexOf(q); | |
| 2505 | + while (at >= 0) { | |
| 2506 | + if (at === 0) { return 3 + bonus; } | |
| 2507 | + if (PALETTE_WORD.test(s.charAt(at - 1))) { return 2 + bonus; } | |
| 2508 | + at = s.indexOf(q, at + 1); | |
| 2509 | + } | |
| 2510 | + var qi = 0; | |
| 2511 | + for (var i = 0; i < s.length && qi < q.length; i++) { | |
| 2512 | + if (s.charAt(i) === q.charAt(qi)) { qi++; } | |
| 2513 | + } | |
| 2514 | + return qi === q.length ? 1 + bonus : 0; | |
| 2515 | + } | |
| 2516 | + | |
| 2517 | + // The destinations to filter: the current repo's tabs first, then the fetched list. | |
| 2518 | + function paletteItems() { | |
| 2519 | + var items = []; | |
| 2520 | + var tabs = document.querySelectorAll('.repo-tabs a'); | |
| 2521 | + if (tabs.length) { | |
| 2522 | + // The first tab is the repo's Code link, so its path starts with owner/name. | |
| 2523 | + var parts = tabs[0].pathname.split('/'); | |
| 2524 | + var repo = parts.length >= 3 ? parts[1] + '/' + parts[2] : ''; | |
| 2525 | + if (repo) { | |
| 2526 | + Array.prototype.forEach.call(tabs, function (a) { | |
| 2527 | + // Counts sit in a span at the end of the tab ("Issues 3"); the name is the rest. | |
| 2528 | + var name = a.textContent.replace(/\s+/g, ' ').trim().replace(/ \d+$/, ''); | |
| 2529 | + items.push({ label: repo + ' · ' + name, href: a.getAttribute('href') || '', kind: 'repo' }); | |
| 2530 | + }); | |
| 2531 | + } | |
| 2532 | + } | |
| 2533 | + return pal.data ? items.concat(pal.data.items) : items; | |
| 2534 | + } | |
| 2535 | + | |
| 2536 | + function paletteSelect(index) { | |
| 2537 | + var opts = pal.list.querySelectorAll('li[role="option"]'); | |
| 2538 | + if (!opts.length) { pal.input.removeAttribute('aria-activedescendant'); return; } | |
| 2539 | + pal.sel = Math.max(0, Math.min(opts.length - 1, index)); | |
| 2540 | + for (var i = 0; i < opts.length; i++) { | |
| 2541 | + opts[i].setAttribute('aria-selected', i === pal.sel ? 'true' : 'false'); | |
| 2542 | + } | |
| 2543 | + pal.input.setAttribute('aria-activedescendant', opts[pal.sel].id); | |
| 2544 | + opts[pal.sel].scrollIntoView({ block: 'nearest' }); | |
| 2545 | + } | |
| 2546 | + | |
| 2547 | + // Filters and draws the list. Groups keep the order of their best match, so a page named exactly | |
| 2548 | + // like the query leads; with no query, the order is tabs, repos, orgs, then pages. | |
| 2549 | + function renderPalette() { | |
| 2550 | + var q = pal.input.value.trim().toLowerCase(); | |
| 2551 | + var scored = []; | |
| 2552 | + paletteItems().forEach(function (item, idx) { | |
| 2553 | + if (!Object.prototype.hasOwnProperty.call(pal.str.heads, item.kind)) { return; } | |
| 2554 | + var s = paletteScore(q, item.label); | |
| 2555 | + if (s > 0) { scored.push({ item: item, score: s, idx: idx }); } | |
| 2556 | + }); | |
| 2557 | + scored.sort(function (a, b) { return b.score - a.score || a.idx - b.idx; }); | |
| 2558 | + scored = scored.slice(0, PALETTE_MAX); | |
| 2559 | + var kinds = [], groups = {}; | |
| 2560 | + scored.forEach(function (h) { | |
| 2561 | + var kind = h.item.kind; | |
| 2562 | + if (!groups[kind]) { groups[kind] = []; kinds.push(kind); } | |
| 2563 | + groups[kind].push(h.item); | |
| 2564 | + }); | |
| 2565 | + pal.list.textContent = ''; | |
| 2566 | + pal.hits = []; | |
| 2567 | + kinds.forEach(function (kind) { | |
| 2568 | + var head = document.createElement('li'); | |
| 2569 | + head.className = 'palette-head'; | |
| 2570 | + head.setAttribute('role', 'presentation'); | |
| 2571 | + head.textContent = pal.str.heads[kind]; | |
| 2572 | + pal.list.appendChild(head); | |
| 2573 | + groups[kind].forEach(function (item) { | |
| 2574 | + var n = pal.hits.length; | |
| 2575 | + pal.hits.push(item); | |
| 2576 | + var li = document.createElement('li'); | |
| 2577 | + li.id = 'palette-opt-' + n; | |
| 2578 | + li.setAttribute('role', 'option'); | |
| 2579 | + li.setAttribute('aria-selected', 'false'); | |
| 2580 | + li.setAttribute('data-n', String(n)); | |
| 2581 | + li.textContent = item.label; | |
| 2582 | + pal.list.appendChild(li); | |
| 2583 | + }); | |
| 2584 | + }); | |
| 2585 | + if (pal.hits.length) { | |
| 2586 | + pal.note.textContent = pal.str.hint; | |
| 2587 | + paletteSelect(0); | |
| 2588 | + } else { | |
| 2589 | + pal.note.textContent = pal.failed ? pal.str.failed : (pal.data ? pal.str.empty : pal.str.loading); | |
| 2590 | + pal.input.removeAttribute('aria-activedescendant'); | |
| 2591 | + } | |
| 2592 | + } | |
| 2593 | + | |
| 2594 | + // Fetches the server list unless a fresh one is held or a request is already on the wire. | |
| 2595 | + function paletteFetch() { | |
| 2596 | + if (pal.request || (pal.data && Date.now() - pal.data.at < PALETTE_TTL)) { return; } | |
| 2597 | + pal.failed = false; | |
| 2598 | + pal.request = fetch('/-/palette', { headers: { accept: 'application/json' }, credentials: 'same-origin' }).then(function (r) { | |
| 2599 | + if (!r.ok) { throw new Error('status ' + r.status); } | |
| 2600 | + return r.json(); | |
| 2601 | + }).then(function (json) { | |
| 2602 | + pal.data = { at: Date.now(), items: Array.isArray(json.items) ? json.items : [] }; | |
| 2603 | + pal.request = null; | |
| 2604 | + if (pal.dlg.open) { renderPalette(); } | |
| 2605 | + }).catch(function () { | |
| 2606 | + pal.request = null; | |
| 2607 | + pal.failed = true; | |
| 2608 | + if (pal.dlg.open) { renderPalette(); } | |
| 2609 | + }); | |
| 2610 | + } | |
| 2611 | + | |
| 2612 | + // Leaves the palette for a destination. The dialog closes first, then the page loads the same way | |
| 2613 | + // a sidebar link does; a link the browser must handle itself goes through location. | |
| 2614 | + function paletteGo(href) { | |
| 2615 | + if (!href) { return; } | |
| 2616 | + pal.dlg.close(); | |
| 2617 | + var url = pageUrl(href); | |
| 2618 | + if (!url) { location.assign(href); return; } | |
| 2619 | + saveScroll(); | |
| 2620 | + load({ target: withoutHash(url), dest: url, init: GET_INIT, how: 'nav', keep: false, post: false, form: null }); | |
| 2621 | + } | |
| 2622 | + | |
| 2623 | + // Built once. Its markup is static; every word in it arrives through the button's data attributes. | |
| 2624 | + function buildPalette() { | |
| 2625 | + var dlg = document.createElement('dialog'); | |
| 2626 | + dlg.className = 'palette'; | |
| 2627 | + dlg.innerHTML = '<div class="palette-box">' + | |
| 2628 | + '<div class="palette-search"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>' + | |
| 2629 | + '<input type="text" class="palette-input" autocomplete="off" spellcheck="false" role="combobox" ' + | |
| 2630 | + 'aria-expanded="true" aria-controls="palette-list" aria-autocomplete="list"></div>' + | |
| 2631 | + '<ul id="palette-list" class="palette-list" role="listbox"></ul>' + | |
| 2632 | + '<p class="palette-note muted small"></p></div>'; | |
| 2633 | + pal.dlg = dlg; | |
| 2634 | + pal.input = dlg.querySelector('.palette-input'); | |
| 2635 | + pal.list = dlg.querySelector('.palette-list'); | |
| 2636 | + pal.note = dlg.querySelector('.palette-note'); | |
| 2637 | + | |
| 2638 | + pal.input.addEventListener('input', renderPalette); | |
| 2639 | + pal.input.addEventListener('keydown', function (e) { | |
| 2640 | + if (e.isComposing) { return; } | |
| 2641 | + if (e.key === 'ArrowDown') { e.preventDefault(); paletteSelect(pal.sel + 1); } | |
| 2642 | + else if (e.key === 'ArrowUp') { e.preventDefault(); paletteSelect(pal.sel - 1); } | |
| 2643 | + else if (e.key === 'Enter') { e.preventDefault(); if (pal.hits[pal.sel]) { paletteGo(pal.hits[pal.sel].href); } } | |
| 2644 | + }); | |
| 2645 | + // Hover selects; the check keeps a row that is already selected from being touched again. | |
| 2646 | + pal.list.addEventListener('mousemove', function (e) { | |
| 2647 | + var li = e.target && e.target.closest ? e.target.closest('li[role="option"]') : null; | |
| 2648 | + if (li && Number(li.getAttribute('data-n')) !== pal.sel) { paletteSelect(Number(li.getAttribute('data-n'))); } | |
| 2649 | + }); | |
| 2650 | + pal.list.addEventListener('click', function (e) { | |
| 2651 | + var li = e.target && e.target.closest ? e.target.closest('li[role="option"]') : null; | |
| 2652 | + if (li) { paletteGo(pal.hits[Number(li.getAttribute('data-n'))].href); } | |
| 2653 | + }); | |
| 2654 | + // The backdrop is the dialog element itself; the box fills the rest. | |
| 2655 | + dlg.addEventListener('click', function (e) { if (e.target === dlg) { dlg.close(); } }); | |
| 2656 | + } | |
| 2657 | + | |
| 2658 | + function openPalette() { | |
| 2659 | + var opener = document.querySelector('[data-palette-open]'); | |
| 2660 | + if (!opener) { return; } | |
| 2661 | + if (!pal.dlg) { buildPalette(); } | |
| 2662 | + var dlg = pal.dlg; | |
| 2663 | + if (dlg.open) { return; } | |
| 2664 | + // A page swap removes body children, the dialog among them, so it is put back on each open. | |
| 2665 | + if (dlg.parentNode !== document.body) { document.body.appendChild(dlg); } | |
| 2666 | + pal.str = paletteStrings(opener); | |
| 2667 | + dlg.setAttribute('aria-label', pal.str.label); | |
| 2668 | + pal.input.placeholder = pal.str.placeholder; | |
| 2669 | + pal.input.setAttribute('aria-label', pal.str.placeholder); | |
| 2670 | + if (typeof dlg.showModal !== 'function') { return; } | |
| 2671 | + dlg.showModal(); | |
| 2672 | + pal.input.value = ''; | |
| 2673 | + renderPalette(); | |
| 2674 | + pal.input.focus(); | |
| 2675 | + paletteFetch(); | |
| 2676 | + } | |
| 2677 | + | |
| 2678 | + // Ctrl+K and Cmd+K toggle the palette even while a text field has focus, since that is when a | |
| 2679 | + // jump is most likely. Other modifiers keep their own meaning. | |
| 2680 | + document.addEventListener('keydown', function (e) { | |
| 2681 | + if (!(e.ctrlKey || e.metaKey) || e.altKey || e.shiftKey || (e.key !== 'k' && e.key !== 'K')) { return; } | |
| 2682 | + if (!document.querySelector('[data-palette-open]')) { return; } | |
| 2683 | + e.preventDefault(); | |
| 2684 | + if (pal.dlg && pal.dlg.open) { pal.dlg.close(); } else { openPalette(); } | |
| 2685 | + }); | |
| 2686 | + | |
| 2687 | + document.addEventListener('click', function (e) { | |
| 2688 | + var t = e.target; | |
| 2689 | + if (!t || !t.closest) { return; } | |
| 2690 | + if (t.closest('[data-palette-open]')) { e.preventDefault(); openPalette(); } | |
| 2691 | + }); | |
| 2692 | + | |
| 2693 | + // Every relative time shows its exact moment on hover, in the reader's own time zone and language, | |
| 2694 | + // so one format holds across the site whatever title the server wrote. | |
| 2695 | + var relFormat = null, relLang = null; | |
| 2696 | + | |
| 2697 | + function relTitles() { | |
| 2698 | + var lang = root.getAttribute('lang') || ''; | |
| 2699 | + if (!relFormat || relLang !== lang) { | |
| 2700 | + try { | |
| 2701 | + relFormat = new Intl.DateTimeFormat(lang || undefined, { dateStyle: 'medium', timeStyle: 'short' }); | |
| 2702 | + relLang = lang; | |
| 2703 | + } catch (err) { return; } | |
| 2704 | + } | |
| 2705 | + Array.prototype.forEach.call(document.querySelectorAll('time[data-rel][datetime]'), function (el) { | |
| 2706 | + var at = Date.parse(el.getAttribute('datetime') || ''); | |
| 2707 | + if (isNaN(at)) { return; } | |
| 2708 | + var exact = relFormat.format(at); | |
| 2709 | + if (el.getAttribute('title') !== exact) { el.setAttribute('title', exact); } | |
| 2710 | + }); | |
| 2711 | + } | |
| 1931 | 2712 | })(); |
| 1932 | 2713 | |
| 1933 | 2714 | // Code browsing: line selection on blobs and blame, the permalink copy and `y` shortcut, the file |
crates/forge-web/src/i18n/admin.rsmodified+28 -0
| @@ -107,6 +107,7 @@ pub enum K { | ||
| 107 | 107 | MailTransportInUse, |
| 108 | 108 | MailQueueIntro, |
| 109 | 109 | MailNothingMatches, |
| 110 | + MailQueueEmpty, | |
| 110 | 111 | MailPort, |
| 111 | 112 | MailSettingsSaved, |
| 112 | 113 | MovedToGhost, |
| @@ -116,6 +117,10 @@ pub enum K { | ||
| 116 | 117 | NoRunnersYet, |
| 117 | 118 | NoRunnerWithId, |
| 118 | 119 | NoRunsYet, |
| 120 | + BackupsEmptyHint, | |
| 121 | + ReplicationConfigHint, | |
| 122 | + ReposEmptyHint, | |
| 123 | + RunnersEmptyHint, | |
| 119 | 124 | Older, |
| 120 | 125 | OwnLogIntro, |
| 121 | 126 | PasswordStoredHint, |
| @@ -419,6 +424,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 419 | 424 | } |
| 420 | 425 | (MailNothingMatches, En) => "No message is in this state.", |
| 421 | 426 | (MailNothingMatches, Tr) => "Bu durumda ileti yok.", |
| 427 | + (MailQueueEmpty, En) => "Nothing waiting to be sent.", | |
| 428 | + (MailQueueEmpty, Tr) => "Gönderilmeyi bekleyen ileti yok.", | |
| 422 | 429 | (MailHost, En) => "Host", |
| 423 | 430 | (MailHost, Tr) => "Sunucu", |
| 424 | 431 | (MailIntro, En) => { |
| @@ -445,6 +452,22 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 445 | 452 | (NoRunnerWithId, Tr) => "Bu kimlikte bir çalıştırıcı yok. Hiçbir şey değiştirilmedi.", |
| 446 | 453 | (NoRunsYet, En) => "No runs yet.", |
| 447 | 454 | (NoRunsYet, Tr) => "Henüz çalıştırma yok.", |
| 455 | + (BackupsEmptyHint, En) => "Scheduled and manual runs are listed here.", | |
| 456 | + (BackupsEmptyHint, Tr) => "Zamanlanmış ve elle başlatılan çalıştırmalar burada listelenir.", | |
| 457 | + (ReplicationConfigHint, En) => { | |
| 458 | + "Replication is set under [replication] in the config file. See docs/backup.md." | |
| 459 | + } | |
| 460 | + (ReplicationConfigHint, Tr) => { | |
| 461 | + "Replikasyon, yapılandırma dosyasındaki [replication] bölümünde ayarlanır. Bkz. docs/backup.md." | |
| 462 | + } | |
| 463 | + (ReposEmptyHint, En) => "Each repo is copied to the standby and listed here.", | |
| 464 | + (ReposEmptyHint, Tr) => "Her depo yedek sunucuya kopyalanır ve burada listelenir.", | |
| 465 | + (RunnersEmptyHint, En) => { | |
| 466 | + "Create a registration token below, then run this command on the runner machine." | |
| 467 | + } | |
| 468 | + (RunnersEmptyHint, Tr) => { | |
| 469 | + "Aşağıdan bir kayıt belirteci oluşturun, ardından bu komutu çalıştırıcı makinesinde çalıştırın." | |
| 470 | + } | |
| 448 | 471 | (Older, En) => "Older", |
| 449 | 472 | (Older, Tr) => "Daha eski", |
| 450 | 473 | (OwnLogIntro, En) => { |
| @@ -896,6 +919,11 @@ mod tests { | ||
| 896 | 919 | K::NoRunnersYet, |
| 897 | 920 | K::NoRunnerWithId, |
| 898 | 921 | K::NoRunsYet, |
| 922 | + K::BackupsEmptyHint, | |
| 923 | + K::ReplicationConfigHint, | |
| 924 | + K::ReposEmptyHint, | |
| 925 | + K::RunnersEmptyHint, | |
| 926 | + K::MailQueueEmpty, | |
| 899 | 927 | K::Older, |
| 900 | 928 | K::OwnLogIntro, |
| 901 | 929 | K::PasswordStoredHint, |
crates/forge-web/src/i18n/browse.rsmodified+8 -0
| @@ -53,6 +53,14 @@ strings! { | ||
| 53 | 53 | FinderFailed => "The file list could not be loaded.", "Dosya listesi yüklenemedi."; |
| 54 | 54 | FinderTruncated => "Very large tree: only the first files are searchable.", "Çok büyük ağaç: yalnızca ilk dosyalar aranabilir."; |
| 55 | 55 | |
| 56 | + PaletteOpen => "Open command palette", "Komut paletini aç"; | |
| 57 | + PalettePlaceholder => "Jump to…", "Şuraya git…"; | |
| 58 | + PaletteRepos => "Repositories", "Depolar"; | |
| 59 | + PalettePages => "Pages", "Sayfalar"; | |
| 60 | + PaletteNoMatches => "No matches", "Eşleşme yok"; | |
| 61 | + PaletteLoading => "Loading…", "Yükleniyor…"; | |
| 62 | + PaletteFailed => "The list could not be loaded.", "Liste yüklenemedi."; | |
| 63 | + | |
| 56 | 64 | BranchAuthorHeader => "Author", "Yazar"; |
| 57 | 65 | BranchAheadBehindHeader => "Ahead / behind", "Önde / geride"; |
| 58 | 66 | BranchActionsHeader => "Actions", "İşlemler"; |
crates/forge-web/src/i18n/code.rsmodified+6 -6
| @@ -521,18 +521,18 @@ pub fn forks_count(lang: Lang, forks: u64) -> String { | ||
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /// The mirror status after a successful sync. |
| 524 | -pub fn mirror_synced(lang: Lang, at: &str) -> String { | |
| 524 | +pub fn mirror_synced(lang: Lang) -> (&'static str, &'static str) { | |
| 525 | 525 | match lang { |
| 526 | - Lang::En => format!("last synced {at}"), | |
| 527 | - Lang::Tr => format!("son eşitleme: {at}"), | |
| 526 | + Lang::En => ("last synced ", ""), | |
| 527 | + Lang::Tr => ("son eşitleme: ", ""), | |
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /// The mirror status after a failed sync. |
| 532 | -pub fn mirror_sync_failed(lang: Lang, at: &str) -> String { | |
| 532 | +pub fn mirror_sync_failed(lang: Lang) -> (&'static str, &'static str) { | |
| 533 | 533 | match lang { |
| 534 | - Lang::En => format!("last sync {at} failed"), | |
| 535 | - Lang::Tr => format!("son eşitleme {at} başarısız oldu"), | |
| 534 | + Lang::En => ("last sync ", " failed"), | |
| 535 | + Lang::Tr => ("son eşitleme ", " başarısız oldu"), | |
| 536 | 536 | } |
| 537 | 537 | } |
| 538 | 538 |
crates/forge-web/src/i18n/community.rsmodified+18 -13
| @@ -406,22 +406,27 @@ pub fn page_too_large(lang: Lang, max: usize) -> String { | ||
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | -/// `2 files · updated 3 days ago` / `2 dosya · 3 gün önce güncellendi`. | |
| 410 | -/// `updated 3 days ago` / `3 gün önce güncellendi`. | |
| 411 | -pub fn updated_on(lang: Lang, updated: &str) -> String { | |
| 409 | +/// Words before a relative update time: `updated ` in English. Turkish puts the time first. | |
| 410 | +pub fn updated_before(lang: Lang) -> &'static str { | |
| 412 | 411 | match lang { |
| 413 | - Lang::En => format!("updated {updated}"), | |
| 414 | - Lang::Tr => format!("{updated} güncellendi"), | |
| 412 | + Lang::En => "updated ", | |
| 413 | + Lang::Tr => "", | |
| 415 | 414 | } |
| 416 | 415 | } |
| 417 | 416 | |
| 418 | -pub fn files_updated(lang: Lang, count: u64, updated: &str) -> String { | |
| 417 | +/// Words after a relative update time: ` güncellendi` in Turkish. English puts the time last. | |
| 418 | +pub fn updated_after(lang: Lang) -> &'static str { | |
| 419 | 419 | match lang { |
| 420 | - Lang::En => format!( | |
| 421 | - "{count} {} · updated {updated}", | |
| 422 | - if count == 1 { "file" } else { "files" } | |
| 423 | - ), | |
| 424 | - Lang::Tr => format!("{count} dosya · {updated} güncellendi"), | |
| 420 | + Lang::En => "", | |
| 421 | + Lang::Tr => " güncellendi", | |
| 422 | + } | |
| 423 | +} | |
| 424 | + | |
| 425 | +/// `2 files` / `1 file` / `2 dosya`. | |
| 426 | +pub fn files_count(lang: Lang, count: u64) -> String { | |
| 427 | + match lang { | |
| 428 | + Lang::En => format!("{count} {}", if count == 1 { "file" } else { "files" }), | |
| 429 | + Lang::Tr => format!("{count} dosya"), | |
| 425 | 430 | } |
| 426 | 431 | } |
| 427 | 432 | |
| @@ -573,7 +578,7 @@ mod tests { | ||
| 573 | 578 | assert_eq!(comments_count(Lang::En, 3), "3 comments"); |
| 574 | 579 | assert_eq!(comments_count(Lang::Tr, 3), "3 yorum"); |
| 575 | 580 | assert_eq!(page_number(Lang::Tr, 2), "Sayfa 2"); |
| 576 | - assert_eq!(files_updated(Lang::En, 2, "now"), "2 files · updated now"); | |
| 577 | - assert_eq!(files_updated(Lang::En, 1, "now"), "1 file · updated now"); | |
| 581 | + assert_eq!(files_count(Lang::En, 2), "2 files"); | |
| 582 | + assert_eq!(files_count(Lang::En, 1), "1 file"); | |
| 578 | 583 | } |
| 579 | 584 | } |
crates/forge-web/src/i18n/integrations.rsmodified+9 -10
| @@ -17,6 +17,7 @@ pub enum K { | ||
| 17 | 17 | ClearSecret, |
| 18 | 18 | CreateWebhook, |
| 19 | 19 | CurrentUrl, |
| 20 | + Cancel, | |
| 20 | 21 | DeleteConfirm, |
| 21 | 22 | DeleteIntro, |
| 22 | 23 | DeleteMirror, |
| @@ -54,7 +55,6 @@ pub enum K { | ||
| 54 | 55 | ManualOnly, |
| 55 | 56 | Mirrors, |
| 56 | 57 | MirrorsIntro, |
| 57 | - Never, | |
| 58 | 58 | NoDeliveries, |
| 59 | 59 | NoMirrors, |
| 60 | 60 | NoWebhooks, |
| @@ -164,7 +164,6 @@ pub const ALL: &[K] = &[ | ||
| 164 | 164 | K::ManualOnly, |
| 165 | 165 | K::Mirrors, |
| 166 | 166 | K::MirrorsIntro, |
| 167 | - K::Never, | |
| 168 | 167 | K::NoDeliveries, |
| 169 | 168 | K::NoMirrors, |
| 170 | 169 | K::NoWebhooks, |
| @@ -268,8 +267,10 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 268 | 267 | (CreateWebhook, Tr) => "Web kancası oluştur", |
| 269 | 268 | (CurrentUrl, En) => "Current URL:", |
| 270 | 269 | (CurrentUrl, Tr) => "Mevcut URL:", |
| 271 | - (DeleteConfirm, En) => "I understand this cannot be undone", | |
| 272 | - (DeleteConfirm, Tr) => "Bunun geri alınamayacağını anlıyorum", | |
| 270 | + (Cancel, En) => "Cancel", | |
| 271 | + (Cancel, Tr) => "Vazgeç", | |
| 272 | + (DeleteConfirm, En) => "Delete it? This cannot be undone.", | |
| 273 | + (DeleteConfirm, Tr) => "Silinsin mi? Bu işlem geri alınamaz.", | |
| 273 | 274 | (DeleteIntro, En) => { |
| 274 | 275 | "Deleting removes the webhook and its delivery history. Events stop being sent to its URL at once." |
| 275 | 276 | } |
| @@ -339,10 +340,10 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 339 | 340 | "Bu depo arşivlenmiş. Web kancaları salt okunurdur: değiştirilemez, test edilemez ya da yeniden teslim edilemez." |
| 340 | 341 | } |
| 341 | 342 | (HookNoticeConfirm, En) => { |
| 342 | - "Tick the confirmation box to delete the webhook. Nothing was deleted." | |
| 343 | + "The delete was not confirmed. Nothing was deleted." | |
| 343 | 344 | } |
| 344 | 345 | (HookNoticeConfirm, Tr) => { |
| 345 | - "Web kancasını silmek için onay kutusunu işaretleyin. Hiçbir şey silinmedi." | |
| 346 | + "Silme onaylanmadı. Hiçbir şey silinmedi." | |
| 346 | 347 | } |
| 347 | 348 | (HookNoticeCreated, En) => "Webhook created. A ping was queued.", |
| 348 | 349 | (HookNoticeCreated, Tr) => "Web kancası oluşturuldu. Bir ping sıraya alındı.", |
| @@ -368,8 +369,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 368 | 369 | (MirrorsIntro, Tr) => { |
| 369 | 370 | "Çekme yansısı bu depoyu uzak bir depoyla eşit tutar: dallar ve etiketler aralıkla ya da istendiğinde çekilir, göndermeler reddedilir. Gönderme yansısı her göndermeden sonra dalları ve etiketleri uzak depoya gönderir. Çekme istekleri ve sorunlar yerel kalır." |
| 370 | 371 | } |
| 371 | - (Never, En) => "never", | |
| 372 | - (Never, Tr) => "hiç", | |
| 373 | 372 | (NoDeliveries, En) => "No deliveries yet.", |
| 374 | 373 | (NoDeliveries, Tr) => "Henüz teslimat yok.", |
| 375 | 374 | (NoMirrors, En) => "No mirrors yet.", |
| @@ -381,10 +380,10 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 381 | 380 | (NoResponse, En) => "no response", |
| 382 | 381 | (NoResponse, Tr) => "yanıt yok", |
| 383 | 382 | (NoticeConfirm, En) => { |
| 384 | - "Tick the confirmation box to delete the mirror. Nothing was deleted." | |
| 383 | + "The delete was not confirmed. Nothing was deleted." | |
| 385 | 384 | } |
| 386 | 385 | (NoticeConfirm, Tr) => { |
| 387 | - "Yansıyı silmek için onay kutusunu işaretleyin. Hiçbir şey silinmedi." | |
| 386 | + "Silme onaylanmadı. Hiçbir şey silinmedi." | |
| 388 | 387 | } |
| 389 | 388 | (NoticeCreated, En) => { |
| 390 | 389 | "Push mirror created. It will be pushed after the next push or on its interval." |
crates/forge-web/src/i18n/issues.rsmodified+4 -0
| @@ -151,6 +151,7 @@ pub enum K { | ||
| 151 | 151 | SortUpdated, |
| 152 | 152 | NewIssue, |
| 153 | 153 | NoIssuesMatch, |
| 154 | + NoIssuesYet, | |
| 154 | 155 | SearchTitles, |
| 155 | 156 | IssuesByState, |
| 156 | 157 | LabelsAndMilestones, |
| @@ -460,6 +461,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 460 | 461 | (K::NewIssue, Lang::Tr) => "Yeni sorun", |
| 461 | 462 | (K::NoIssuesMatch, Lang::En) => "No issues match these filters.", |
| 462 | 463 | (K::NoIssuesMatch, Lang::Tr) => "Bu filtrelerle eşleşen sorun yok.", |
| 464 | + (K::NoIssuesYet, Lang::En) => "No issues yet.", | |
| 465 | + (K::NoIssuesYet, Lang::Tr) => "Henüz sorun yok.", | |
| 463 | 466 | (K::SearchTitles, Lang::En) => "Search titles", |
| 464 | 467 | (K::SearchTitles, Lang::Tr) => "Başlıklarda ara", |
| 465 | 468 | (K::IssuesByState, Lang::En) => "Issues by state", |
| @@ -1032,6 +1035,7 @@ mod tests { | ||
| 1032 | 1035 | K::SortUpdated, |
| 1033 | 1036 | K::NewIssue, |
| 1034 | 1037 | K::NoIssuesMatch, |
| 1038 | + K::NoIssuesYet, | |
| 1035 | 1039 | K::SearchTitles, |
| 1036 | 1040 | K::IssuesByState, |
| 1037 | 1041 | K::LabelsAndMilestones, |
crates/forge-web/src/i18n/link.rsmodified+17 -1
| @@ -7,6 +7,14 @@ use super::Lang; | ||
| 7 | 7 | pub enum K { |
| 8 | 8 | Restarting, |
| 9 | 9 | BackSubmit, |
| 10 | + /// The tick after a settings form saved. | |
| 11 | + Saved, | |
| 12 | + /// The tick after another form succeeded. | |
| 13 | + Done, | |
| 14 | + /// The note under a comment draft put back into its field. | |
| 15 | + DraftRestored, | |
| 16 | + /// The button that drops a restored draft. | |
| 17 | + DraftDiscard, | |
| 10 | 18 | } |
| 11 | 19 | |
| 12 | 20 | /// The phrase for `key`. |
| @@ -17,6 +25,14 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 17 | 25 | (Restarting, Lang::Tr) => "Sunucu yeniden başlıyor\u{2026} sayfanız korunuyor", |
| 18 | 26 | (BackSubmit, Lang::En) => "Server is back, submit again", |
| 19 | 27 | (BackSubmit, Lang::Tr) => "Sunucu geri geldi, tekrar gönderin", |
| 28 | + (Saved, Lang::En) => "Saved", | |
| 29 | + (Saved, Lang::Tr) => "Kaydedildi", | |
| 30 | + (Done, Lang::En) => "Done", | |
| 31 | + (Done, Lang::Tr) => "Tamam", | |
| 32 | + (DraftRestored, Lang::En) => "Draft restored", | |
| 33 | + (DraftRestored, Lang::Tr) => "Taslak geri yüklendi", | |
| 34 | + (DraftDiscard, Lang::En) => "Discard", | |
| 35 | + (DraftDiscard, Lang::Tr) => "Vazgeç", | |
| 20 | 36 | } |
| 21 | 37 | } |
| 22 | 38 | |
| @@ -27,7 +43,7 @@ mod tests { | ||
| 27 | 43 | #[test] |
| 28 | 44 | fn every_string_has_no_em_dash() { |
| 29 | 45 | for lang in [Lang::En, Lang::Tr] { |
| 30 | - for key in [K::Restarting, K::BackSubmit] { | |
| 46 | + for key in [K::Restarting, K::BackSubmit, K::Saved, K::Done, K::DraftRestored, K::DraftDiscard] { | |
| 31 | 47 | assert!(!t(lang, key).contains('\u{2014}')); |
| 32 | 48 | } |
| 33 | 49 | } |
crates/forge-web/src/i18n/migrate.rsmodified+4 -4
| @@ -325,11 +325,11 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | -/// "Expires in N days" style line for the export list. | |
| 329 | -pub fn expires_on(lang: Lang, date: &str) -> String { | |
| 328 | +/// The label before an export's expiry time, which follows as a relative time. | |
| 329 | +pub fn expires_label(lang: Lang) -> &'static str { | |
| 330 | 330 | match lang { |
| 331 | - Lang::En => format!("Expires {date}"), | |
| 332 | - Lang::Tr => format!("Son geçerlilik {date}"), | |
| 331 | + Lang::En => "Expires", | |
| 332 | + Lang::Tr => "Son geçerlilik", | |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 |
crates/forge-web/src/i18n/orgs.rsmodified+4 -0
| @@ -120,6 +120,7 @@ pub enum K { | ||
| 120 | 120 | TabStars, |
| 121 | 121 | FilterRepos, |
| 122 | 122 | NoReposMatch, |
| 123 | + ClearSearch, | |
| 123 | 124 | // Dashboard and landing. |
| 124 | 125 | Dashboard, |
| 125 | 126 | Home, |
| @@ -367,6 +368,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 367 | 368 | (FilterRepos, Tr) => "Depo ara", |
| 368 | 369 | (NoReposMatch, En) => "No repositories match.", |
| 369 | 370 | (NoReposMatch, Tr) => "Aramayla eşleşen depo yok.", |
| 371 | + (ClearSearch, En) => "Clear search", | |
| 372 | + (ClearSearch, Tr) => "Aramayı temizle", | |
| 370 | 373 | (Dashboard, En) => "Dashboard", |
| 371 | 374 | (Dashboard, Tr) => "Pano", |
| 372 | 375 | (Home, En) => "Home", |
| @@ -607,6 +610,7 @@ mod tests { | ||
| 607 | 610 | K::TabStars, |
| 608 | 611 | K::FilterRepos, |
| 609 | 612 | K::NoReposMatch, |
| 613 | + K::ClearSearch, | |
| 610 | 614 | K::Dashboard, |
| 611 | 615 | K::Home, |
| 612 | 616 | K::LandingTagline, |
crates/forge-web/src/i18n/packages.rsmodified+3 -0
| @@ -41,6 +41,7 @@ pub enum K { | ||
| 41 | 41 | DeleteTagMessage, |
| 42 | 42 | DeleteTagConfirm, |
| 43 | 43 | NoTags, |
| 44 | + NoVersions, | |
| 44 | 45 | PackageTagCount, |
| 45 | 46 | PackageTagCountOne, |
| 46 | 47 | } |
| @@ -83,6 +84,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 83 | 84 | (DeleteTagConfirm, Tr) => "Evet, sil", |
| 84 | 85 | (NoTags, En) => "No tags yet. Push an image to see it here.", |
| 85 | 86 | (NoTags, Tr) => "Henüz etiket yok. Burada görmek için bir imaj gönderin.", |
| 87 | + (NoVersions, En) => "No versions published yet.", | |
| 88 | + (NoVersions, Tr) => "Henüz sürüm yayımlanmadı.", | |
| 86 | 89 | (PackageTagCount, En) => "tags", |
| 87 | 90 | (PackageTagCount, Tr) => "etiket", |
| 88 | 91 | (PackageTagCountOne, En) => "tag", |
crates/forge-web/src/i18n/push.rsmodified+8 -8
| @@ -97,19 +97,19 @@ pub fn test_sent(lang: Lang, devices: usize) -> String { | ||
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | -/// "Added 2026-10-02" and the matching delivery line. | |
| 101 | -pub fn added_on(lang: Lang, date: &str) -> String { | |
| 100 | +/// The label before a device's added time: "Added 3 days ago" with the time after it. | |
| 101 | +pub fn added_label(lang: Lang) -> &'static str { | |
| 102 | 102 | match lang { |
| 103 | - Lang::En => format!("Added {date}"), | |
| 104 | - Lang::Tr => format!("Eklendi {date}"), | |
| 103 | + Lang::En => "Added", | |
| 104 | + Lang::Tr => "Eklendi", | |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | -/// "Last delivered 2026-10-02". | |
| 109 | -pub fn last_delivered(lang: Lang, date: &str) -> String { | |
| 108 | +/// The label before a device's last delivery: "Last delivered 5 minutes ago". | |
| 109 | +pub fn last_delivered_label(lang: Lang) -> &'static str { | |
| 110 | 110 | match lang { |
| 111 | - Lang::En => format!("Last delivered {date}"), | |
| 112 | - Lang::Tr => format!("Son teslim {date}"), | |
| 111 | + Lang::En => "Last delivered", | |
| 112 | + Lang::Tr => "Son teslim", | |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 |
crates/forge-web/src/i18n/releases_ci.rsmodified+2 -6
| @@ -128,7 +128,6 @@ pub enum K { | ||
| 128 | 128 | Assets, |
| 129 | 129 | AllReleases, |
| 130 | 130 | SourceCode, |
| 131 | - Confirm, | |
| 132 | 131 | DeleteRelease, |
| 133 | 132 | BackToRelease, |
| 134 | 133 | UploadAsset, |
| @@ -347,8 +346,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 347 | 346 | (RelAssetInvalid, Tr) => { |
| 348 | 347 | "Yüklenen dosya okunamadı. Hiçbir şey değiştirilmedi; yeniden deneyin." |
| 349 | 348 | } |
| 350 | - (RelConfirm, En) => "Tick the confirmation box to delete the release. Nothing was deleted.", | |
| 351 | - (RelConfirm, Tr) => "Sürümü silmek için onay kutusunu işaretleyin. Hiçbir şey silinmedi.", | |
| 349 | + (RelConfirm, En) => "The delete was not confirmed. Nothing was deleted.", | |
| 350 | + (RelConfirm, Tr) => "Silme onaylanmadı. Hiçbir şey silinmedi.", | |
| 352 | 351 | (RelInvalid, En) => { |
| 353 | 352 | "Enter a title of up to 200 characters and release notes of up to 65536 characters. Nothing was changed." |
| 354 | 353 | } |
| @@ -423,8 +422,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 423 | 422 | (AllReleases, Tr) => "Tüm sürümler", |
| 424 | 423 | (SourceCode, En) => "Source code", |
| 425 | 424 | (SourceCode, Tr) => "Kaynak kodu", |
| 426 | - (Confirm, En) => "Confirm", | |
| 427 | - (Confirm, Tr) => "Onayla", | |
| 428 | 425 | (DeleteRelease, En) => "Delete release", |
| 429 | 426 | (DeleteRelease, Tr) => "Sürümü sil", |
| 430 | 427 | (BackToRelease, En) => "Back to the release", |
| @@ -656,7 +653,6 @@ mod tests { | ||
| 656 | 653 | K::Assets, |
| 657 | 654 | K::AllReleases, |
| 658 | 655 | K::SourceCode, |
| 659 | - K::Confirm, | |
| 660 | 656 | K::DeleteRelease, |
| 661 | 657 | K::BackToRelease, |
| 662 | 658 | K::UploadAsset, |
crates/forge-web/src/i18n/repo_admin.rsmodified+41 -22
| @@ -17,9 +17,11 @@ pub enum K { | ||
| 17 | 17 | ApprovalsRange, |
| 18 | 18 | ArchiveHeading, |
| 19 | 19 | ArchiveHelp, |
| 20 | + ArchiveConfirm, | |
| 20 | 21 | ArchiveRepo, |
| 21 | 22 | ArchivedHelp, |
| 22 | 23 | ArchivedSecrets, |
| 24 | + Cancel, | |
| 23 | 25 | BadForm, |
| 24 | 26 | BlockWhileChanges, |
| 25 | 27 | BranchMissing, |
| @@ -31,7 +33,7 @@ pub enum K { | ||
| 31 | 33 | BuiltinRowText, |
| 32 | 34 | CancelRule, |
| 33 | 35 | CancelTransfer, |
| 34 | - ChangeVisibility, | |
| 36 | + MakePrivate, | |
| 35 | 37 | CollabAdded, |
| 36 | 38 | CollabRemoved, |
| 37 | 39 | Collaborators, |
| @@ -58,7 +60,8 @@ pub enum K { | ||
| 58 | 60 | ForcePushDesc, |
| 59 | 61 | General, |
| 60 | 62 | GeneralSaved, |
| 61 | - IUnderstand, | |
| 63 | + MakePublic, | |
| 64 | + MakePublicConfirm, | |
| 62 | 65 | InvalidRole, |
| 63 | 66 | LastUpdated, |
| 64 | 67 | Mirrors, |
| @@ -140,7 +143,7 @@ pub enum K { | ||
| 140 | 143 | ValueTooLarge, |
| 141 | 144 | VisibilityChanged, |
| 142 | 145 | VisibilityHeading, |
| 143 | - VisibilityHelp, | |
| 146 | + MakePrivateConfirm, | |
| 144 | 147 | Webhooks, |
| 145 | 148 | } |
| 146 | 149 | |
| @@ -186,6 +189,10 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 186 | 189 | (ArchiveHelp, Tr) => { |
| 187 | 190 | "Arşivleme depoyu salt okunur yapar: gönderimler reddedilir; sorunlar, etiketler ve kilometre taşları değiştirilemez. Arşivden istediğiniz zaman çıkarabilirsiniz." |
| 188 | 191 | } |
| 192 | + (ArchiveConfirm, En) => "Archive this repository? You can unarchive it at any time.", | |
| 193 | + (ArchiveConfirm, Tr) => "Depo arşivlensin mi? İstediğiniz zaman arşivden çıkarabilirsiniz.", | |
| 194 | + (Cancel, En) => "Cancel", | |
| 195 | + (Cancel, Tr) => "Vazgeç", | |
| 189 | 196 | (ArchiveRepo, En) => "Archive repository", |
| 190 | 197 | (ArchiveRepo, Tr) => "Depoyu arşivle", |
| 191 | 198 | (ArchivedHelp, En) => { |
| @@ -226,8 +233,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 226 | 233 | (CancelRule, Tr) => "Vazgeç", |
| 227 | 234 | (CancelTransfer, En) => "Cancel transfer", |
| 228 | 235 | (CancelTransfer, Tr) => "Devri iptal et", |
| 229 | - (ChangeVisibility, En) => "Change visibility", | |
| 230 | - (ChangeVisibility, Tr) => "Görünürlüğü değiştir", | |
| 236 | + (MakePrivate, En) => "Make private", | |
| 237 | + (MakePrivate, Tr) => "Özel yap", | |
| 231 | 238 | (CollabAdded, En) => "Collaborator added.", |
| 232 | 239 | (CollabAdded, Tr) => "Ortak çalışan eklendi.", |
| 233 | 240 | (CollabRemoved, En) => "Collaborator removed.", |
| @@ -300,8 +307,14 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 300 | 307 | (General, Tr) => "Genel", |
| 301 | 308 | (GeneralSaved, En) => "General settings saved.", |
| 302 | 309 | (GeneralSaved, Tr) => "Genel ayarlar kaydedildi.", |
| 303 | - (IUnderstand, En) => "I understand", | |
| 304 | - (IUnderstand, Tr) => "Anlıyorum", | |
| 310 | + (MakePublic, En) => "Make public", | |
| 311 | + (MakePublic, Tr) => "Herkese açık yap", | |
| 312 | + (MakePublicConfirm, En) => { | |
| 313 | + "Make it public? Anyone will be able to read its code, issues and pull requests. It takes effect at once." | |
| 314 | + } | |
| 315 | + (MakePublicConfirm, Tr) => { | |
| 316 | + "Herkese açık yapılsın mı? Kodunu, sorunlarını ve çekme isteklerini herkes okuyabilir. Hemen geçerli olur." | |
| 317 | + } | |
| 305 | 318 | (InvalidRole, En) => "Choose a valid role.", |
| 306 | 319 | (InvalidRole, Tr) => "Geçerli bir rol seçin.", |
| 307 | 320 | (LastUpdated, En) => "Last updated", |
| @@ -487,10 +500,10 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 487 | 500 | (UnarchiveRepo, En) => "Unarchive repository", |
| 488 | 501 | (UnarchiveRepo, Tr) => "Depoyu arşivden çıkar", |
| 489 | 502 | (UnderstandNeeded, En) => { |
| 490 | - "To change the visibility, tick I understand. Nothing was changed." | |
| 503 | + "The change was not confirmed. Nothing was changed." | |
| 491 | 504 | } |
| 492 | 505 | (UnderstandNeeded, Tr) => { |
| 493 | - "Görünürlüğü değiştirmek için \"Anlıyorum\" kutusunu işaretleyin. Hiçbir şey değiştirilmedi." | |
| 506 | + "Değişiklik onaylanmadı. Hiçbir şey değiştirilmedi." | |
| 494 | 507 | } |
| 495 | 508 | (UnknownUser, En) => "No user has that username.", |
| 496 | 509 | (UnknownUser, Tr) => "Bu kullanıcı adına sahip bir kullanıcı yok.", |
| @@ -504,11 +517,11 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 504 | 517 | (VisibilityChanged, Tr) => "Görünürlük değiştirildi.", |
| 505 | 518 | (VisibilityHeading, En) => "Visibility", |
| 506 | 519 | (VisibilityHeading, Tr) => "Görünürlük", |
| 507 | - (VisibilityHelp, En) => { | |
| 508 | - "Tick I understand to change the visibility. The change takes effect at once." | |
| 520 | + (MakePrivateConfirm, En) => { | |
| 521 | + "Make it private? Only its owner, collaborators and instance admins will see it; others get a 404. It takes effect at once." | |
| 509 | 522 | } |
| 510 | - (VisibilityHelp, Tr) => { | |
| 511 | - "Görünürlüğü değiştirmek için \"Anlıyorum\" kutusunu işaretleyin. Değişiklik hemen geçerli olur." | |
| 523 | + (MakePrivateConfirm, Tr) => { | |
| 524 | + "Özel yapılsın mı? Yalnızca sahibi, ortak çalışanları ve sunucu yöneticileri görebilir; diğerleri 404 hatası alır. Hemen geçerli olur." | |
| 512 | 525 | } |
| 513 | 526 | (Webhooks, En) => "Webhooks", |
| 514 | 527 | (Webhooks, Tr) => "Web kancaları", |
| @@ -601,8 +614,7 @@ pub fn transfer_summary( | ||
| 601 | 614 | to_is_org: bool, |
| 602 | 615 | to_name: &str, |
| 603 | 616 | started_by: &str, |
| 604 | - expires_on: &str, | |
| 605 | -) -> String { | |
| 617 | +) -> (String, &'static str) { | |
| 606 | 618 | match lang { |
| 607 | 619 | Lang::En => { |
| 608 | 620 | let target = if to_is_org { |
| @@ -610,8 +622,9 @@ pub fn transfer_summary( | ||
| 610 | 622 | } else { |
| 611 | 623 | to_name.to_owned() |
| 612 | 624 | }; |
| 613 | - format!( | |
| 614 | - "Pending transfer to {target}, started by {started_by}. It expires on {expires_on} unless accepted." | |
| 625 | + ( | |
| 626 | + format!("Pending transfer to {target}, started by {started_by}. It expires "), | |
| 627 | + " unless accepted.", | |
| 615 | 628 | ) |
| 616 | 629 | } |
| 617 | 630 | Lang::Tr => { |
| @@ -620,8 +633,11 @@ pub fn transfer_summary( | ||
| 620 | 633 | } else { |
| 621 | 634 | format!("{to_name} kullanıcısı") |
| 622 | 635 | }; |
| 623 | - format!( | |
| 624 | - "{target} için bekleyen devir, {started_by} tarafından başlatıldı. Kabul edilmezse {expires_on} tarihinde sona erer." | |
| 636 | + ( | |
| 637 | + format!( | |
| 638 | + "{target} için bekleyen devir, {started_by} tarafından başlatıldı. Kabul edilmezse " | |
| 639 | + ), | |
| 640 | + " sona erer.", | |
| 625 | 641 | ) |
| 626 | 642 | } |
| 627 | 643 | } |
| @@ -671,9 +687,11 @@ mod tests { | ||
| 671 | 687 | K::ApprovalsRange, |
| 672 | 688 | K::ArchiveHeading, |
| 673 | 689 | K::ArchiveHelp, |
| 690 | + K::ArchiveConfirm, | |
| 674 | 691 | K::ArchiveRepo, |
| 675 | 692 | K::ArchivedHelp, |
| 676 | 693 | K::ArchivedSecrets, |
| 694 | + K::Cancel, | |
| 677 | 695 | K::BadForm, |
| 678 | 696 | K::BlockWhileChanges, |
| 679 | 697 | K::BranchMissing, |
| @@ -685,7 +703,7 @@ mod tests { | ||
| 685 | 703 | K::BuiltinRowText, |
| 686 | 704 | K::CancelRule, |
| 687 | 705 | K::CancelTransfer, |
| 688 | - K::ChangeVisibility, | |
| 706 | + K::MakePrivate, | |
| 689 | 707 | K::CollabAdded, |
| 690 | 708 | K::CollabRemoved, |
| 691 | 709 | K::Collaborators, |
| @@ -712,7 +730,8 @@ mod tests { | ||
| 712 | 730 | K::ForcePushDesc, |
| 713 | 731 | K::General, |
| 714 | 732 | K::GeneralSaved, |
| 715 | - K::IUnderstand, | |
| 733 | + K::MakePublic, | |
| 734 | + K::MakePublicConfirm, | |
| 716 | 735 | K::InvalidRole, |
| 717 | 736 | K::LastUpdated, |
| 718 | 737 | K::Mirrors, |
| @@ -794,7 +813,7 @@ mod tests { | ||
| 794 | 813 | K::ValueTooLarge, |
| 795 | 814 | K::VisibilityChanged, |
| 796 | 815 | K::VisibilityHeading, |
| 797 | - K::VisibilityHelp, | |
| 816 | + K::MakePrivateConfirm, | |
| 798 | 817 | K::Webhooks, |
| 799 | 818 | ]; |
| 800 | 819 |
crates/forge-web/src/package_ops.rsmodified+31 -3
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | //! `api::packages` and the pages translate these results. Bytes go to the blob store under |
| 5 | 5 | //! `packages/<version id>`, and each change is announced on the owner's live signal. |
| 6 | 6 | |
| 7 | +use forge_core::authz::{Action, authorize}; | |
| 7 | 8 | use forge_core::cargo; |
| 8 | 9 | use forge_core::model::User; |
| 9 | 10 | use forge_core::packages::{KIND_CARGO, KIND_OCI, NewPackageVersion, Package}; |
| @@ -49,8 +50,32 @@ pub async fn owner_named(state: &AppState, name: &str) -> Result<Option<User>, P | ||
| 49 | 50 | Ok(state.store.user_by_username(name).await?) |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | -/// True when `actor` may read `package`. Public packages are readable by anyone. A private one | |
| 53 | -/// is readable by the instance admin, the owner and the owner's org members. | |
| 53 | +/// True when `actor` may read the repo a package is linked to. A link to a missing repo counts | |
| 54 | +/// as unreadable, so a dangling link never exposes the package. | |
| 55 | +async fn linked_repo_readable( | |
| 56 | + state: &AppState, | |
| 57 | + actor: Option<&User>, | |
| 58 | + repo_id: &str, | |
| 59 | +) -> Result<bool, PackageError> { | |
| 60 | + let Some(repo) = state.store.repo_by_id(repo_id).await? else { | |
| 61 | + return Ok(false); | |
| 62 | + }; | |
| 63 | + let (role, org_role) = match actor { | |
| 64 | + Some(user) => ( | |
| 65 | + state.store.collaborator_role(&repo.id, &user.id).await?, | |
| 66 | + state | |
| 67 | + .store | |
| 68 | + .org_repo_role(&repo.owner_id, &user.id, &repo.id) | |
| 69 | + .await?, | |
| 70 | + ), | |
| 71 | + None => (None, None), | |
| 72 | + }; | |
| 73 | + Ok(authorize(actor, &repo, role, org_role, Action::Read).is_ok()) | |
| 74 | +} | |
| 75 | + | |
| 76 | +/// True when `actor` may read `package`. A public package is readable by anyone, unless it is | |
| 77 | +/// linked to a repo the actor may not read. A private one is readable by the instance admin, the | |
| 78 | +/// owner and the owner's org members. | |
| 54 | 79 | pub async fn may_read( |
| 55 | 80 | state: &AppState, |
| 56 | 81 | actor: Option<&User>, |
| @@ -58,7 +83,10 @@ pub async fn may_read( | ||
| 58 | 83 | package: &Package, |
| 59 | 84 | ) -> Result<bool, PackageError> { |
| 60 | 85 | if !package.private { |
| 61 | - return Ok(true); | |
| 86 | + return match &package.repo_id { | |
| 87 | + Some(repo_id) => linked_repo_readable(state, actor, repo_id).await, | |
| 88 | + None => Ok(true), | |
| 89 | + }; | |
| 62 | 90 | } |
| 63 | 91 | let Some(actor) = actor else { |
| 64 | 92 | return Ok(false); |
crates/forge-web/src/pages/admin_backups.rsmodified+9 -9
| @@ -5,7 +5,6 @@ | ||
| 5 | 5 | //! A button press is audited and redirects back here with a notice. |
| 6 | 6 | |
| 7 | 7 | use forge_core::store::backup_runs::{BackupRun, RunKind}; |
| 8 | -use forge_core::tz::format_in_tz; | |
| 9 | 8 | use forge_core::{AuditAction, Error, Store, User}; |
| 10 | 9 | use serde::Deserialize; |
| 11 | 10 | use topcoat::Result; |
| @@ -25,7 +24,7 @@ use crate::live::{Topic, stream_changes}; | ||
| 25 | 24 | use crate::pages::admin_users::admin_only; |
| 26 | 25 | use crate::pages::issues_list::stamp_unix; |
| 27 | 26 | use crate::state::AppState; |
| 28 | -use crate::views::{enc, shell}; | |
| 27 | +use crate::views::{empty_state, enc, rel_time, shell}; | |
| 29 | 28 | |
| 30 | 29 | /// Runs shown on the page. |
| 31 | 30 | const RUN_LIMIT: u32 = 20; |
| @@ -109,7 +108,7 @@ fn duration_text(run: &BackupRun) -> String { | ||
| 109 | 108 | } |
| 110 | 109 | } |
| 111 | 110 | |
| 112 | -fn run_row(run: &BackupRun, tz: &str, lang: Lang) -> RunRow { | |
| 111 | +fn run_row(run: &BackupRun, lang: Lang) -> RunRow { | |
| 113 | 112 | let (status, detail) = match (run.finished_at.is_some(), run.ok) { |
| 114 | 113 | (false, _) => (g::t(lang, K::StatusInProgress).to_owned(), String::new()), |
| 115 | 114 | (true, Some(true)) => (g::t(lang, K::StatusOk).to_owned(), String::new()), |
| @@ -121,7 +120,7 @@ fn run_row(run: &BackupRun, tz: &str, lang: Lang) -> RunRow { | ||
| 121 | 120 | RunRow { |
| 122 | 121 | kind: g::kind_name(lang, run.kind).to_owned(), |
| 123 | 122 | trigger: g::trigger_name(lang, run.trigger).to_owned(), |
| 124 | - started: format_in_tz(stamp_unix(&run.started_at), tz), | |
| 123 | + started: run.started_at.clone(), | |
| 125 | 124 | duration: duration_text(run), |
| 126 | 125 | size: run.bytes.map(human_bytes).unwrap_or_default(), |
| 127 | 126 | status, |
| @@ -166,7 +165,7 @@ async fn backups_view( | ||
| 166 | 165 | <p class="muted">(g::running_line(lang, kind))</p> |
| 167 | 166 | } |
| 168 | 167 | <div class="actions"> |
| 169 | - <form method="post" action="/admin/backups/run"> | |
| 168 | + <form id="run-backup" method="post" action="/admin/backups/run"> | |
| 170 | 169 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 171 | 170 | <button type="submit" class="primary">(g::t(lang, K::RunBackupNow))</button> |
| 172 | 171 | </form> |
| @@ -179,7 +178,9 @@ async fn backups_view( | ||
| 179 | 178 | <section class="card"> |
| 180 | 179 | <h2>(g::t(lang, K::RecentRuns))</h2> |
| 181 | 180 | if rows.is_empty() { |
| 182 | - <p class="muted">(g::t(lang, K::NoRunsYet))</p> | |
| 181 | + empty_state(title: g::t(lang, K::NoRunsYet), hint: Some(g::t(lang, K::BackupsEmptyHint))) { | |
| 182 | + <a class="button" href="#run-backup">(g::t(lang, K::RunBackupNow))</a> | |
| 183 | + } | |
| 183 | 184 | } else { |
| 184 | 185 | <div class="table-wrap"> |
| 185 | 186 | <table class="table queue-table"> |
| @@ -198,7 +199,7 @@ async fn backups_view( | ||
| 198 | 199 | <tr> |
| 199 | 200 | <td data-label=(g::t(lang, K::TableKind))>(row.kind.as_str())</td> |
| 200 | 201 | <td data-label=(g::t(lang, K::TableTrigger))>(row.trigger.as_str())</td> |
| 201 | - <td class="small" data-label=(g::t(lang, K::TableStarted))>(row.started.as_str())</td> | |
| 202 | + <td class="small" data-label=(g::t(lang, K::TableStarted))>rel_time(lang: lang, stamp: row.started.as_str())</td> | |
| 202 | 203 | <td class="small" data-label=(g::t(lang, K::TableDuration))>(row.duration.as_str())</td> |
| 203 | 204 | <td class="small" data-label=(g::t(lang, K::TableSize))>(row.size.as_str())</td> |
| 204 | 205 | <td data-label=(g::t(lang, K::TableResult))> |
| @@ -251,8 +252,7 @@ async fn backups_page(cx: &Cx) -> Result<impl View> { | ||
| 251 | 252 | let state = app_context::<AppState>(cx); |
| 252 | 253 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 253 | 254 | let runs = state.store.recent_runs(RUN_LIMIT).await?; |
| 254 | - let tz = viewer.0.timezone.as_str(); | |
| 255 | - let rows: Vec<RunRow> = runs.iter().map(|run| run_row(run, tz, lang)).collect(); | |
| 255 | + let rows: Vec<RunRow> = runs.iter().map(|run| run_row(run, lang)).collect(); | |
| 256 | 256 | let running = state.jobs.running(); |
| 257 | 257 | let settings = settings_view(lang, &state.config.backup); |
| 258 | 258 | let csrf = viewer.1.csrf_token.clone(); |
crates/forge-web/src/pages/admin_health.rsmodified+12 -18
| @@ -12,7 +12,6 @@ use forge_core::mail::MailState; | ||
| 12 | 12 | use forge_core::store::backup_runs::RunKind; |
| 13 | 13 | use forge_core::store::replication::DB_SUBJECT; |
| 14 | 14 | use forge_core::time::stamp_to_unix; |
| 15 | -use forge_core::tz::format_in_tz; | |
| 16 | 15 | use tokio::process::Command; |
| 17 | 16 | use topcoat::Result; |
| 18 | 17 | use topcoat::context::{Cx, app_context}; |
| @@ -205,7 +204,7 @@ fn uptime_secs() -> Option<u64> { | ||
| 205 | 204 | Some((system - start_ticks / 100.0).max(0.0) as u64) |
| 206 | 205 | } |
| 207 | 206 | |
| 208 | -async fn gather(state: &AppState, lang: Lang, tz: &str) -> Result<Health> { | |
| 207 | +async fn gather(state: &AppState, lang: Lang) -> Result<Health> { | |
| 209 | 208 | let live = state.live(); |
| 210 | 209 | let now = now_unix(); |
| 211 | 210 | let data_dir = live.data_dir.clone(); |
| @@ -321,7 +320,6 @@ async fn gather(state: &AppState, lang: Lang, tz: &str) -> Result<Health> { | ||
| 321 | 320 | }; |
| 322 | 321 | services.push(match backup { |
| 323 | 322 | Some(run) => { |
| 324 | - let at_unix = stamp_to_unix(&run.started_at).unwrap_or(0); | |
| 325 | 323 | let (value, dot) = match run.ok { |
| 326 | 324 | Some(true) => (at(lang, A::Ok), Dot::Ok), |
| 327 | 325 | Some(false) => (at(lang, A::Failed), Dot::Bad), |
| @@ -331,7 +329,7 @@ async fn gather(state: &AppState, lang: Lang, tz: &str) -> Result<Health> { | ||
| 331 | 329 | label: at(lang, A::LastBackup), |
| 332 | 330 | dot, |
| 333 | 331 | value: value.to_owned(), |
| 334 | - detail: format_in_tz(at_unix, tz), | |
| 332 | + detail: String::new(), | |
| 335 | 333 | stamp: Some(run.started_at.clone()), |
| 336 | 334 | } |
| 337 | 335 | } |
| @@ -426,39 +424,35 @@ async fn gather(state: &AppState, lang: Lang, tz: &str) -> Result<Health> { | ||
| 426 | 424 | struct AlertRow { |
| 427 | 425 | title: String, |
| 428 | 426 | body: String, |
| 429 | - /// The raised time as the server formats it, and its stamp for the live relative time. | |
| 430 | - date: String, | |
| 427 | + /// The raised time, as a live relative time. | |
| 431 | 428 | stamp: String, |
| 432 | 429 | } |
| 433 | 430 | |
| 434 | 431 | /// The alerts active now, worded for the viewer. |
| 435 | -async fn alert_rows(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<AlertRow>> { | |
| 436 | - let now = now_unix(); | |
| 432 | +async fn alert_rows(state: &AppState, lang: Lang) -> Result<Vec<AlertRow>> { | |
| 437 | 433 | Ok(state |
| 438 | 434 | .store |
| 439 | 435 | .active_alerts() |
| 440 | 436 | .await? |
| 441 | 437 | .into_iter() |
| 442 | 438 | .map(|alert| { |
| 443 | - let raised = stamp_to_unix(&alert.raised_at).unwrap_or(now); | |
| 444 | 439 | AlertRow { |
| 445 | 440 | title: alert_text::title(lang, &alert.kind, &alert.subject, false), |
| 446 | 441 | body: alert_text::body(lang, &alert.kind, &alert.subject, &alert.detail, false), |
| 447 | - date: format_in_tz(raised, tz), | |
| 448 | 442 | stamp: alert.raised_at.clone(), |
| 449 | 443 | } |
| 450 | 444 | }) |
| 451 | 445 | .collect()) |
| 452 | 446 | } |
| 453 | 447 | |
| 454 | -/// The alert's raised time: "since <date> · <live time>", worded per language. | |
| 448 | +/// The alert's raised time as a live relative time, worded per language. | |
| 455 | 449 | #[component] |
| 456 | -async fn since_line(lang: Lang, date: &str, stamp: &str) -> Result<impl View> { | |
| 450 | +async fn since_line(lang: Lang, stamp: &str) -> Result<impl View> { | |
| 457 | 451 | Ok(view! { |
| 458 | 452 | if matches!(lang, Lang::Tr) { |
| 459 | - (date) " · " rel_time(lang: lang, stamp: stamp) " tarihinden beri" | |
| 453 | + rel_time(lang: lang, stamp: stamp) " başladı" | |
| 460 | 454 | } else { |
| 461 | - "since " (date) " · " rel_time(lang: lang, stamp: stamp) | |
| 455 | + "raised " rel_time(lang: lang, stamp: stamp) | |
| 462 | 456 | } |
| 463 | 457 | }) |
| 464 | 458 | } |
| @@ -496,7 +490,7 @@ async fn health_view(lang: Lang, health: Health, alerts: Vec<AlertRow>) -> Resul | ||
| 496 | 490 | for a in alerts.into_iter() { |
| 497 | 491 | <li> |
| 498 | 492 | <strong>(a.title.as_str())</strong> |
| 499 | - <span class="muted small">since_line(lang: lang, date: a.date.as_str(), stamp: a.stamp.as_str())</span> | |
| 493 | + <span class="muted small">since_line(lang: lang, stamp: a.stamp.as_str())</span> | |
| 500 | 494 | if !a.body.is_empty() { |
| 501 | 495 | <div class="small">(a.body.as_str())</div> |
| 502 | 496 | } |
| @@ -565,8 +559,8 @@ async fn health_page(cx: &Cx) -> Result<impl View> { | ||
| 565 | 559 | let viewer = admin_only(cx).await?; |
| 566 | 560 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 567 | 561 | let state = app_context::<AppState>(cx); |
| 568 | - let health = gather(state, lang, &viewer.0.timezone).await?; | |
| 569 | - let alerts = alert_rows(state, lang, &viewer.0.timezone).await?; | |
| 562 | + let health = gather(state, lang).await?; | |
| 563 | + let alerts = alert_rows(state, lang).await?; | |
| 570 | 564 | let title = at(lang, A::Health); |
| 571 | 565 | Ok(view! { |
| 572 | 566 | shell(title: title, viewer: Some(&viewer), health_view(lang: lang, health: health, alerts: alerts)) |
| @@ -583,7 +577,7 @@ async fn health_fingerprint(state: &AppState) -> Result<String> { | ||
| 583 | 577 | .store |
| 584 | 578 | .mail_state_counts(&forge_core::time::now_stamp()) |
| 585 | 579 | .await?; |
| 586 | - let alerts: Vec<(String, String)> = alert_rows(state, Lang::En, "UTC") | |
| 580 | + let alerts: Vec<(String, String)> = alert_rows(state, Lang::En) | |
| 587 | 581 | .await? |
| 588 | 582 | .into_iter() |
| 589 | 583 | .map(|alert| (alert.title, alert.body)) |
crates/forge-web/src/pages/admin_mail.rsmodified+15 -19
| @@ -12,7 +12,6 @@ use forge_core::mail::{ | ||
| 12 | 12 | MailKind, MailSettings, MailSettingsUpdate, MailState, OutboxEntry, Security, |
| 13 | 13 | }; |
| 14 | 14 | use forge_core::time::now_stamp; |
| 15 | -use forge_core::tz::format_in_tz; | |
| 16 | 15 | use forge_core::{AuditAction, Error}; |
| 17 | 16 | use futures_util::{Stream, stream}; |
| 18 | 17 | use serde::Deserialize; |
| @@ -33,9 +32,8 @@ use crate::i18n::{self, Key, Lang}; | ||
| 33 | 32 | use crate::mail::{enqueue, live, templates}; |
| 34 | 33 | use crate::pages::admin_users::admin_only; |
| 35 | 34 | use crate::pages::ci_runs::{changed_event, events_response}; |
| 36 | -use crate::pages::issues_list::stamp_unix; | |
| 37 | 35 | use crate::state::AppState; |
| 38 | -use crate::views::{enc, shell}; | |
| 36 | +use crate::views::{empty_state, enc, rel_time, shell}; | |
| 39 | 37 | |
| 40 | 38 | /// Rows shown in the queue at most. |
| 41 | 39 | const LIST_LIMIT: u32 = 100; |
| @@ -65,7 +63,7 @@ struct QueueRow { | ||
| 65 | 63 | attempts: u32, |
| 66 | 64 | error: String, |
| 67 | 65 | created: String, |
| 68 | - sent: String, | |
| 66 | + sent: Option<String>, | |
| 69 | 67 | failed: bool, |
| 70 | 68 | } |
| 71 | 69 | |
| @@ -126,7 +124,7 @@ fn tab_class(on: bool) -> &'static str { | ||
| 126 | 124 | } |
| 127 | 125 | } |
| 128 | 126 | |
| 129 | -fn row_view(entry: &OutboxEntry, now: &str, tz: &str, lang: Lang) -> QueueRow { | |
| 127 | +fn row_view(entry: &OutboxEntry, now: &str, lang: Lang) -> QueueRow { | |
| 130 | 128 | let state = entry.state_at(now); |
| 131 | 129 | QueueRow { |
| 132 | 130 | id: entry.id.clone(), |
| @@ -137,12 +135,8 @@ fn row_view(entry: &OutboxEntry, now: &str, tz: &str, lang: Lang) -> QueueRow { | ||
| 137 | 135 | state_class: state_class(state), |
| 138 | 136 | attempts: entry.attempts, |
| 139 | 137 | error: entry.last_error.clone().unwrap_or_default(), |
| 140 | - created: format_in_tz(stamp_unix(&entry.created_at), tz), | |
| 141 | - sent: entry | |
| 142 | - .sent_at | |
| 143 | - .as_deref() | |
| 144 | - .map(|sent| format_in_tz(stamp_unix(sent), tz)) | |
| 145 | - .unwrap_or_default(), | |
| 138 | + created: entry.created_at.clone(), | |
| 139 | + sent: entry.sent_at.clone(), | |
| 146 | 140 | failed: state == MailState::Failed, |
| 147 | 141 | } |
| 148 | 142 | } |
| @@ -150,7 +144,6 @@ fn row_view(entry: &OutboxEntry, now: &str, tz: &str, lang: Lang) -> QueueRow { | ||
| 150 | 144 | /// The queue tab's data. `filter` of `None` lists every state. |
| 151 | 145 | async fn queue_data( |
| 152 | 146 | state: &AppState, |
| 153 | - tz: &str, | |
| 154 | 147 | lang: Lang, |
| 155 | 148 | filter: Option<MailState>, |
| 156 | 149 | ) -> forge_core::Result<QueueData> { |
| @@ -176,7 +169,7 @@ async fn queue_data( | ||
| 176 | 169 | .list_mail(filter, &now, LIST_LIMIT) |
| 177 | 170 | .await? |
| 178 | 171 | .iter() |
| 179 | - .map(|entry| row_view(entry, &now, tz, lang)) | |
| 172 | + .map(|entry| row_view(entry, &now, lang)) | |
| 180 | 173 | .collect(); |
| 181 | 174 | Ok(QueueData { |
| 182 | 175 | chips, |
| @@ -187,14 +180,13 @@ async fn queue_data( | ||
| 187 | 180 | |
| 188 | 181 | async fn page_data( |
| 189 | 182 | state: &AppState, |
| 190 | - tz: &str, | |
| 191 | 183 | lang: Lang, |
| 192 | 184 | tab: Tab, |
| 193 | 185 | filter: Option<MailState>, |
| 194 | 186 | ) -> forge_core::Result<PageData> { |
| 195 | 187 | let settings: MailSettings = state.store.mail_settings().await?; |
| 196 | 188 | let queue = match tab { |
| 197 | - Tab::Queue => Some(queue_data(state, tz, lang, filter).await?), | |
| 189 | + Tab::Queue => Some(queue_data(state, lang, filter).await?), | |
| 198 | 190 | Tab::Settings => None, |
| 199 | 191 | }; |
| 200 | 192 | Ok(PageData { |
| @@ -296,7 +288,11 @@ async fn mail_view( | ||
| 296 | 288 | </div> |
| 297 | 289 | <div data-live="/admin/mail/events"> |
| 298 | 290 | if queue.rows.is_empty() { |
| 299 | - <p class="muted">(g::t(lang, K::MailNothingMatches))</p> | |
| 291 | + if queue.filter_param.is_empty() { | |
| 292 | + empty_state(title: g::t(lang, K::MailQueueEmpty)) | |
| 293 | + } else { | |
| 294 | + empty_state(title: g::t(lang, K::MailNothingMatches)) | |
| 295 | + } | |
| 300 | 296 | } else { |
| 301 | 297 | <div class="table-wrap"> |
| 302 | 298 | <table class="table mail-queue queue-table"> |
| @@ -316,13 +312,13 @@ async fn mail_view( | ||
| 316 | 312 | <tbody> |
| 317 | 313 | for row in queue.rows.into_iter() { |
| 318 | 314 | <tr> |
| 319 | - <td class="small" data-label=(g::t(lang, K::TableQueued))>(row.created.as_str())</td> | |
| 315 | + <td class="small" data-label=(g::t(lang, K::TableQueued))>rel_time(lang: lang, stamp: row.created.as_str())</td> | |
| 320 | 316 | <td data-label=(g::t(lang, K::TableTo))>(row.to.as_str())</td> |
| 321 | 317 | <td data-label=(g::t(lang, K::TableKind))>(row.kind)</td> |
| 322 | 318 | <td data-label=(g::t(lang, K::TableSubject))>(row.subject.as_str())</td> |
| 323 | 319 | <td data-label=(g::t(lang, K::TableState))><span class=(row.state_class)>(row.state)</span></td> |
| 324 | 320 | <td data-label=(g::t(lang, K::TableTries))>(row.attempts)</td> |
| 325 | - <td class="small" data-label=(g::t(lang, K::MailSentAt))>(row.sent.as_str())</td> | |
| 321 | + <td class="small" data-label=(g::t(lang, K::MailSentAt))>if let Some(sent) = row.sent.as_deref() { rel_time(lang: lang, stamp: sent) }</td> | |
| 326 | 322 | <td class="small" data-label=(g::t(lang, K::TableLastError))>(row.error.as_str())</td> |
| 327 | 323 | <td class="mail-actions"> |
| 328 | 324 | if row.failed { |
| @@ -369,7 +365,7 @@ async fn mail_page(cx: &Cx) -> Result<impl View> { | ||
| 369 | 365 | Tab::Settings |
| 370 | 366 | }; |
| 371 | 367 | let filter = query.state.as_deref().and_then(MailState::parse); |
| 372 | - let data = page_data(state, viewer.0.timezone.as_str(), lang, tab, filter).await?; | |
| 368 | + let data = page_data(state, lang, tab, filter).await?; | |
| 373 | 369 | let csrf = viewer.1.csrf_token.clone(); |
| 374 | 370 | let title = g::t(lang, K::Mail); |
| 375 | 371 | Ok(view! { |
crates/forge-web/src/pages/admin_replication.rsmodified+20 -26
| @@ -10,7 +10,6 @@ use std::time::Duration; | ||
| 10 | 10 | |
| 11 | 11 | use forge_core::store::replication::{DB_SUBJECT, ReplicationStatus}; |
| 12 | 12 | use forge_core::time::stamp_ago; |
| 13 | -use forge_core::tz::format_in_tz; | |
| 14 | 13 | use forge_core::{AuditAction, Error}; |
| 15 | 14 | use serde::Deserialize; |
| 16 | 15 | use topcoat::Result; |
| @@ -24,12 +23,11 @@ use topcoat::view::{View, component, view}; | ||
| 24 | 23 | use crate::audit::{self, Actor, Target}; |
| 25 | 24 | use crate::auth::check_csrf; |
| 26 | 25 | use crate::i18n::admin::{self as g, K}; |
| 27 | -use crate::i18n::{self, Key, Lang}; | |
| 26 | +use crate::i18n::{self, Lang}; | |
| 28 | 27 | use crate::live::{Topic, stream_changes}; |
| 29 | 28 | use crate::pages::admin_users::admin_only; |
| 30 | -use crate::pages::issues_list::stamp_unix; | |
| 31 | 29 | use crate::state::AppState; |
| 32 | -use crate::views::{enc, shell}; | |
| 30 | +use crate::views::{empty_state, enc, rel_time_or_never, shell}; | |
| 33 | 31 | |
| 34 | 32 | #[query_params(error = bad_request)] |
| 35 | 33 | pub(crate) struct NoticeQuery { |
| @@ -95,7 +93,8 @@ struct RepoRow { | ||
| 95 | 93 | dot: &'static str, |
| 96 | 94 | tone: &'static str, |
| 97 | 95 | health: &'static str, |
| 98 | - last_ok: String, | |
| 96 | + /// The last good copy's stamp, shown as a live relative time. | |
| 97 | + last_ok: Option<String>, | |
| 99 | 98 | error: String, |
| 100 | 99 | } |
| 101 | 100 | |
| @@ -105,23 +104,16 @@ struct PageData { | ||
| 105 | 104 | target: String, |
| 106 | 105 | db_dot: &'static str, |
| 107 | 106 | db_health: &'static str, |
| 108 | - db_last_ok: String, | |
| 109 | - db_last_attempt: String, | |
| 107 | + db_last_ok: Option<String>, | |
| 108 | + db_last_attempt: Option<String>, | |
| 110 | 109 | db_error: String, |
| 111 | 110 | interval: String, |
| 112 | 111 | healthcheck: &'static str, |
| 113 | 112 | repos: Vec<RepoRow>, |
| 114 | 113 | } |
| 115 | 114 | |
| 116 | -fn ok_text(stamp: Option<&str>, tz: &str, lang: Lang) -> String { | |
| 117 | - match stamp { | |
| 118 | - Some(stamp) => format_in_tz(stamp_unix(stamp), tz), | |
| 119 | - None => i18n::t(lang, Key::Never).to_owned(), | |
| 120 | - } | |
| 121 | -} | |
| 122 | - | |
| 123 | 115 | /// Builds the page data from the config, the status rows and the repo list. |
| 124 | -async fn page_data(state: &AppState, tz: &str, lang: Lang) -> forge_core::Result<PageData> { | |
| 116 | +async fn page_data(state: &AppState, lang: Lang) -> forge_core::Result<PageData> { | |
| 125 | 117 | let config = &state.config.replication; |
| 126 | 118 | let db_cutoff = stamp_ago(Duration::from_secs(config.db_snapshot_minutes * 60 * 2)); |
| 127 | 119 | let repo_cutoff = stamp_ago(Duration::from_secs(config.reconcile_minutes * 60 * 2)); |
| @@ -149,7 +141,7 @@ async fn page_data(state: &AppState, tz: &str, lang: Lang) -> forge_core::Result | ||
| 149 | 141 | dot: h.dot(), |
| 150 | 142 | tone: h.tone(), |
| 151 | 143 | health: h.label(lang), |
| 152 | - last_ok: ok_text(status.and_then(|s| s.last_ok_at.as_deref()), tz, lang), | |
| 144 | + last_ok: status.and_then(|s| s.last_ok_at.clone()), | |
| 153 | 145 | error: status |
| 154 | 146 | .and_then(|s| s.last_error.clone()) |
| 155 | 147 | .unwrap_or_default(), |
| @@ -164,7 +156,7 @@ async fn page_data(state: &AppState, tz: &str, lang: Lang) -> forge_core::Result | ||
| 164 | 156 | dot: h.dot(), |
| 165 | 157 | tone: h.tone(), |
| 166 | 158 | health: h.label(lang), |
| 167 | - last_ok: ok_text(status.last_ok_at.as_deref(), tz, lang), | |
| 159 | + last_ok: status.last_ok_at.clone(), | |
| 168 | 160 | error: status.last_error.clone().unwrap_or_default(), |
| 169 | 161 | }); |
| 170 | 162 | } |
| @@ -175,8 +167,8 @@ async fn page_data(state: &AppState, tz: &str, lang: Lang) -> forge_core::Result | ||
| 175 | 167 | target: config.target.clone(), |
| 176 | 168 | db_dot: health(db, &db_cutoff).dot(), |
| 177 | 169 | db_health: health(db, &db_cutoff).label(lang), |
| 178 | - db_last_ok: ok_text(db.and_then(|s| s.last_ok_at.as_deref()), tz, lang), | |
| 179 | - db_last_attempt: ok_text(db.and_then(|s| s.last_attempt_at.as_deref()), tz, lang), | |
| 170 | + db_last_ok: db.and_then(|s| s.last_ok_at.clone()), | |
| 171 | + db_last_attempt: db.and_then(|s| s.last_attempt_at.clone()), | |
| 180 | 172 | db_error: db.and_then(|s| s.last_error.clone()).unwrap_or_default(), |
| 181 | 173 | interval: g::interval_line(lang, config.db_snapshot_minutes, config.reconcile_minutes), |
| 182 | 174 | healthcheck: if config.healthcheck_url.is_empty() { |
| @@ -214,8 +206,8 @@ async fn replication_view( | ||
| 214 | 206 | <dt>(g::t(lang, K::Interval))</dt><dd>(data.interval.as_str())</dd> |
| 215 | 207 | <dt>(g::t(lang, K::Healthcheck))</dt><dd>(data.healthcheck)</dd> |
| 216 | 208 | <dt>(g::t(lang, K::Database))</dt><dd><span class="admin-status"><span class=(data.db_dot) aria-hidden="true"></span>(data.db_health)</span></dd> |
| 217 | - <dt>(g::t(lang, K::LastDbSnapshotShipped))</dt><dd class="small">(data.db_last_ok.as_str())</dd> | |
| 218 | - <dt>(g::t(lang, K::LastDbAttempt))</dt><dd class="small">(data.db_last_attempt.as_str())</dd> | |
| 209 | + <dt>(g::t(lang, K::LastDbSnapshotShipped))</dt><dd class="small">rel_time_or_never(lang: lang, stamp: data.db_last_ok.as_deref())</dd> | |
| 210 | + <dt>(g::t(lang, K::LastDbAttempt))</dt><dd class="small">rel_time_or_never(lang: lang, stamp: data.db_last_attempt.as_deref())</dd> | |
| 219 | 211 | </dl> |
| 220 | 212 | if !data.db_error.is_empty() { |
| 221 | 213 | <p class="error">(g::t(lang, K::DatabaseErrorPrefix))(data.db_error.as_str())</p> |
| @@ -233,7 +225,9 @@ async fn replication_view( | ||
| 233 | 225 | <section class="card"> |
| 234 | 226 | <h2>(g::t(lang, K::Repos))</h2> |
| 235 | 227 | if data.repos.is_empty() { |
| 236 | - <p class="muted">(g::t(lang, K::NoReposYet))</p> | |
| 228 | + empty_state(title: g::t(lang, K::NoReposYet), hint: Some(g::t(lang, K::ReposEmptyHint))) { | |
| 229 | + <p class="muted small">(g::t(lang, K::ReplicationConfigHint))</p> | |
| 230 | + } | |
| 237 | 231 | } else { |
| 238 | 232 | <ul class="admin-rows"> |
| 239 | 233 | for row in data.repos.into_iter() { |
| @@ -243,7 +237,7 @@ async fn replication_view( | ||
| 243 | 237 | <span class=(row.dot) aria-hidden="true"></span> |
| 244 | 238 | <span class="admin-row-name">(row.name.as_str())</span> |
| 245 | 239 | </div> |
| 246 | - <p class="runner-meta muted">(g::t(lang, K::LastSuccess))": "(row.last_ok.as_str())</p> | |
| 240 | + <p class="runner-meta muted">(g::t(lang, K::LastSuccess))": " rel_time_or_never(lang: lang, stamp: row.last_ok.as_deref())</p> | |
| 247 | 241 | if !row.error.is_empty() { |
| 248 | 242 | <p class="admin-row-error">(row.error.as_str())</p> |
| 249 | 243 | } |
| @@ -261,14 +255,14 @@ async fn replication_view( | ||
| 261 | 255 | /// What the replication page shows, as one string. The health labels are read at each wake, so a |
| 262 | 256 | /// wake also refreshes a copy that has gone stale since the last change. |
| 263 | 257 | async fn page_fingerprint(state: &AppState) -> Result<String> { |
| 264 | - let data = page_data(state, "UTC", Lang::En).await?; | |
| 258 | + let data = page_data(state, Lang::En).await?; | |
| 265 | 259 | let rows: Vec<_> = data |
| 266 | 260 | .repos |
| 267 | 261 | .iter() |
| 268 | 262 | .map(|row| (&row.name, row.health, &row.last_ok, &row.error)) |
| 269 | 263 | .collect(); |
| 270 | 264 | Ok(format!( |
| 271 | - "{}|{}|{}|{}|{}|{}|{:?}", | |
| 265 | + "{}|{}|{:?}|{:?}|{}|{}|{:?}", | |
| 272 | 266 | data.enabled, |
| 273 | 267 | data.db_health, |
| 274 | 268 | data.db_last_ok, |
| @@ -302,7 +296,7 @@ async fn replication_page(cx: &Cx) -> Result<impl View> { | ||
| 302 | 296 | let query = query_params::<NoticeQuery>(cx)?; |
| 303 | 297 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 304 | 298 | let state = app_context::<AppState>(cx); |
| 305 | - let data = page_data(state, viewer.0.timezone.as_str(), lang).await?; | |
| 299 | + let data = page_data(state, lang).await?; | |
| 306 | 300 | let csrf = viewer.1.csrf_token.clone(); |
| 307 | 301 | let title = g::t(lang, K::Replication); |
| 308 | 302 | Ok(view! { |
crates/forge-web/src/pages/admin_runners.rsmodified+5 -3
| @@ -30,7 +30,7 @@ use crate::pages::admin_users::admin_only; | ||
| 30 | 30 | use crate::pages::ci_runs::events_response; |
| 31 | 31 | use crate::pages::repo_mirrors::stamp_in_tz; |
| 32 | 32 | use crate::state::AppState; |
| 33 | -use crate::views::{enc, now_unix, relative_time, shell}; | |
| 33 | +use crate::views::{empty_state, enc, now_unix, relative_time, shell}; | |
| 34 | 34 | |
| 35 | 35 | path_param!(runner_id); |
| 36 | 36 | |
| @@ -327,7 +327,9 @@ async fn runners_view( | ||
| 327 | 327 | <section class="card"> |
| 328 | 328 | <h2>(g::t(lang, K::Runners))</h2> |
| 329 | 329 | if rows.is_empty() { |
| 330 | - <p class="muted">(g::t(lang, K::NoRunnersYet))</p> | |
| 330 | + empty_state(title: g::t(lang, K::NoRunnersYet), hint: Some(g::t(lang, K::RunnersEmptyHint))) { | |
| 331 | + <pre><code>"forge runner register --url <forge-url> --token <token> --name <name> --labels linux,x86_64"</code></pre> | |
| 332 | + } | |
| 331 | 333 | } else { |
| 332 | 334 | <ul class="runner-list"> |
| 333 | 335 | for row in rows.iter() { |
| @@ -1688,8 +1690,8 @@ mod tests { | ||
| 1688 | 1690 | "token in the box and the command" |
| 1689 | 1691 | ); |
| 1690 | 1692 | let (_, list) = send(&router, "GET", "/admin/runners", Some(ADMIN_TOKEN), None).await; |
| 1693 | + // The empty list shows the register command with a placeholder, never the token. | |
| 1691 | 1694 | assert!(!list.contains(&token), "the list never shows the token"); |
| 1692 | - assert!(!list.contains("forge runner register")); | |
| 1693 | 1695 | // Only the hash is stored, so the list and the database hold no plain token. |
| 1694 | 1696 | assert!(store.list_runners().await.expect("list").is_empty()); |
| 1695 | 1697 |
crates/forge-web/src/pages/admin_user_detail.rsmodified+4 -8
| @@ -5,7 +5,6 @@ | ||
| 5 | 5 | use forge_core::names::normalize_name; |
| 6 | 6 | use forge_core::store::suspension::{AccountFacts, Suspension}; |
| 7 | 7 | use forge_core::store::user_delete::GHOST_USERNAME; |
| 8 | -use forge_core::tz::format_in_tz; | |
| 9 | 8 | use forge_core::{AuditAction, Store, User}; |
| 10 | 9 | use serde::Deserialize; |
| 11 | 10 | use topcoat::Result; |
| @@ -23,10 +22,9 @@ use crate::i18n::admin::{self as g, K}; | ||
| 23 | 22 | use crate::i18n::{self, Key, Lang}; |
| 24 | 23 | use crate::live::{Topic, stream_changes}; |
| 25 | 24 | use crate::pages::admin_users::admin_only; |
| 26 | -use crate::pages::issues_list::stamp_unix; | |
| 27 | 25 | use crate::pages::passkeys::s; |
| 28 | 26 | use crate::state::AppState; |
| 29 | -use crate::views::{alert, avatar_url, enc, rel_time_or_never, shell, user_facing_message}; | |
| 27 | +use crate::views::{alert, avatar_url, enc, rel_time, rel_time_or_never, shell, user_facing_message}; | |
| 30 | 28 | |
| 31 | 29 | #[query_params(error = bad_request)] |
| 32 | 30 | pub(crate) struct DoneQuery { |
| @@ -113,7 +111,6 @@ fn done_text(lang: Lang, done: &str) -> Option<&'static str> { | ||
| 113 | 111 | async fn detail_body( |
| 114 | 112 | lang: Lang, |
| 115 | 113 | csrf: &str, |
| 116 | - tz: &str, | |
| 117 | 114 | viewer_id: &str, |
| 118 | 115 | detail: Detail, |
| 119 | 116 | notice: Notice, |
| @@ -127,7 +124,6 @@ async fn detail_body( | ||
| 127 | 124 | } = detail; |
| 128 | 125 | let base = format!("/admin/users/{}", enc(&target.id)); |
| 129 | 126 | let own = target.id == viewer_id; |
| 130 | - let created = format_in_tz(stamp_unix(&target.created_at), tz); | |
| 131 | 127 | let last_login = facts.last_login.clone(); |
| 132 | 128 | let repos = facts.repo_count.to_string(); |
| 133 | 129 | let suspended = suspension.is_some(); |
| @@ -181,7 +177,7 @@ async fn detail_body( | ||
| 181 | 177 | if !email.is_empty() { |
| 182 | 178 | (email.as_str()) " · " |
| 183 | 179 | } |
| 184 | - (at(lang, A::Joined)) " " (created.as_str()) " · " (at(lang, A::LastLogin)) " " rel_time_or_never(lang: lang, stamp: last_login.as_deref()) | |
| 180 | + (at(lang, A::Joined)) " " rel_time(lang: lang, stamp: target.created_at.as_str()) " · " (at(lang, A::LastLogin)) " " rel_time_or_never(lang: lang, stamp: last_login.as_deref()) | |
| 185 | 181 | </p> |
| 186 | 182 | </div> |
| 187 | 183 | </div> |
| @@ -384,7 +380,7 @@ async fn detail_page(cx: &Cx) -> Result<impl View> { | ||
| 384 | 380 | let csrf = viewer.1.csrf_token.clone(); |
| 385 | 381 | let title = detail.target.username.clone(); |
| 386 | 382 | Ok(view! { |
| 387 | - shell(title: title.as_str(), viewer: Some(&viewer), detail_body(lang: lang, csrf: csrf.as_str(), tz: viewer.0.timezone.as_str(), viewer_id: viewer.0.id.as_str(), detail: detail, notice: notice)) | |
| 383 | + shell(title: title.as_str(), viewer: Some(&viewer), detail_body(lang: lang, csrf: csrf.as_str(), viewer_id: viewer.0.id.as_str(), detail: detail, notice: notice)) | |
| 388 | 384 | }) |
| 389 | 385 | } |
| 390 | 386 | |
| @@ -546,7 +542,7 @@ async fn respond(cx: &Cx, form: ActionForm, action: Action) -> Result<impl View> | ||
| 546 | 542 | let csrf = viewer.1.csrf_token.clone(); |
| 547 | 543 | let title = detail.target.username.clone(); |
| 548 | 544 | Ok(view! { |
| 549 | - shell(title: title.as_str(), viewer: Some(&viewer), detail_body(lang: lang, csrf: csrf.as_str(), tz: viewer.0.timezone.as_str(), viewer_id: viewer.0.id.as_str(), detail: detail, notice: notice)) | |
| 545 | + shell(title: title.as_str(), viewer: Some(&viewer), detail_body(lang: lang, csrf: csrf.as_str(), viewer_id: viewer.0.id.as_str(), detail: detail, notice: notice)) | |
| 550 | 546 | }) |
| 551 | 547 | } |
| 552 | 548 |
crates/forge-web/src/pages/admin_users.rsmodified+4 -7
| @@ -2,7 +2,6 @@ | ||
| 2 | 2 | |
| 3 | 3 | use forge_core::names::{normalize_name, validate_username}; |
| 4 | 4 | use forge_core::store::user_delete::{DeletionReport, GHOST_USERNAME}; |
| 5 | -use forge_core::tz::format_in_tz; | |
| 6 | 5 | use forge_core::{AuditAction, Session, Store, User}; |
| 7 | 6 | use serde::Deserialize; |
| 8 | 7 | use topcoat::Result; |
| @@ -18,9 +17,8 @@ use crate::auth::{check_csrf, current_user, hash_password_async}; | ||
| 18 | 17 | use crate::i18n::admin::{self as g, K}; |
| 19 | 18 | use crate::i18n::{self, Key, Lang}; |
| 20 | 19 | use crate::live::{Topic, stream_changes}; |
| 21 | -use crate::pages::issues_list::stamp_unix; | |
| 22 | 20 | use crate::state::AppState; |
| 23 | -use crate::views::{alert, enc, shell, user_facing_message}; | |
| 21 | +use crate::views::{alert, enc, rel_time, shell, user_facing_message}; | |
| 24 | 22 | |
| 25 | 23 | const MIN_PASSWORD_CHARS: usize = 12; |
| 26 | 24 | const MAX_PASSWORD_BYTES: usize = 1024; |
| @@ -58,7 +56,6 @@ async fn users_view( | ||
| 58 | 56 | lang: Lang, |
| 59 | 57 | csrf: &str, |
| 60 | 58 | viewer_id: &str, |
| 61 | - tz: &str, | |
| 62 | 59 | users: Vec<User>, |
| 63 | 60 | error: Option<String>, |
| 64 | 61 | ) -> Result<impl View> { |
| @@ -85,7 +82,7 @@ async fn users_view( | ||
| 85 | 82 | </td> |
| 86 | 83 | <td data-label=(i18n::t(lang, Key::Email))>(user.email.clone().unwrap_or_default())</td> |
| 87 | 84 | <td data-label=(g::t(lang, K::Role))>(if user.is_org() { g::t(lang, K::RoleOrganization) } else if user.is_admin { g::t(lang, K::RoleAdmin) } else { g::t(lang, K::RoleUser) })</td> |
| 88 | - <td class="small nowrap" data-label=(i18n::t(lang, Key::Created))>(format_in_tz(stamp_unix(&user.created_at), tz))</td> | |
| 85 | + <td class="small nowrap" data-label=(i18n::t(lang, Key::Created))>rel_time(lang: lang, stamp: user.created_at.as_str())</td> | |
| 89 | 86 | <td> |
| 90 | 87 | if user.id != viewer_id && !is_ghost(&user) { |
| 91 | 88 | <a class="danger" href=(format!("/admin/users/{}/delete", enc(&user.id)))>(i18n::t(lang, Key::Delete))</a> |
| @@ -168,7 +165,7 @@ async fn users_page(cx: &Cx) -> Result<impl View> { | ||
| 168 | 165 | let csrf = viewer.1.csrf_token.clone(); |
| 169 | 166 | let title = g::t(lang, K::Users); |
| 170 | 167 | Ok(view! { |
| 171 | - shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), viewer_id: viewer.0.id.as_str(), tz: viewer.0.timezone.as_str(), users: users, error: None)) | |
| 168 | + shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), viewer_id: viewer.0.id.as_str(), users: users, error: None)) | |
| 172 | 169 | }) |
| 173 | 170 | } |
| 174 | 171 | |
| @@ -205,7 +202,7 @@ async fn users_create(cx: &Cx, Form(form): Form<CreateUserForm>) -> Result<impl | ||
| 205 | 202 | let csrf = viewer.1.csrf_token.clone(); |
| 206 | 203 | let title = g::t(lang, K::Users); |
| 207 | 204 | Ok(view! { |
| 208 | - shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), viewer_id: viewer.0.id.as_str(), tz: viewer.0.timezone.as_str(), users: users, error: Some(message))) | |
| 205 | + shell(title: title, viewer: Some(&viewer), users_view(lang: lang, csrf: csrf.as_str(), viewer_id: viewer.0.id.as_str(), users: users, error: Some(message))) | |
| 209 | 206 | }) |
| 210 | 207 | } |
| 211 | 208 | } |
crates/forge-web/src/pages/audit_log.rsmodified+9 -12
| @@ -2,7 +2,6 @@ | ||
| 2 | 2 | //! own security log (`/settings/security/log`: entries the viewer acted in, or that targeted |
| 3 | 3 | //! them). Both list newest first, 50 per page, continued with a cursor. |
| 4 | 4 | |
| 5 | -use forge_core::tz::format_in_tz; | |
| 6 | 5 | use forge_core::{AuditAction, AuditCursor, AuditEntry, AuditFilter, Store}; |
| 7 | 6 | use topcoat::Result; |
| 8 | 7 | use topcoat::context::{Cx, app_context}; |
| @@ -15,9 +14,9 @@ use crate::i18n::admin::{self as g, K}; | ||
| 15 | 14 | use crate::i18n::{self, Lang}; |
| 16 | 15 | use crate::live::{Topic, stream_changes}; |
| 17 | 16 | use crate::pages::admin_users::admin_only; |
| 18 | -use crate::pages::issues_list::{list_href, stamp_unix}; | |
| 17 | +use crate::pages::issues_list::list_href; | |
| 19 | 18 | use crate::state::AppState; |
| 20 | -use crate::views::shell; | |
| 19 | +use crate::views::{empty_state, rel_time, shell}; | |
| 21 | 20 | |
| 22 | 21 | /// Entries per page. |
| 23 | 22 | const PAGE_SIZE: usize = 50; |
| @@ -39,7 +38,7 @@ struct RowView { | ||
| 39 | 38 | details: String, |
| 40 | 39 | } |
| 41 | 40 | |
| 42 | -fn row_view(entry: &AuditEntry, tz: &str, lang: Lang) -> RowView { | |
| 41 | +fn row_view(entry: &AuditEntry, lang: Lang) -> RowView { | |
| 43 | 42 | let actor = match (entry.actor_name.as_str(), entry.actor_id.is_some()) { |
| 44 | 43 | ("", _) => g::t(lang, K::Anonymous).to_owned(), |
| 45 | 44 | (name, _) => name.to_owned(), |
| @@ -55,7 +54,7 @@ fn row_view(entry: &AuditEntry, tz: &str, lang: Lang) -> RowView { | ||
| 55 | 54 | format!("{}: {name}", entry.target_kind) |
| 56 | 55 | }; |
| 57 | 56 | RowView { |
| 58 | - when: format_in_tz(stamp_unix(&entry.at), tz), | |
| 57 | + when: entry.at.clone(), | |
| 59 | 58 | actor, |
| 60 | 59 | action: entry.action.as_str().to_owned(), |
| 61 | 60 | target, |
| @@ -94,7 +93,7 @@ async fn fetch_page( | ||
| 94 | 93 | async fn audit_table(lang: Lang, rows: Vec<RowView>, show_actor: bool) -> Result<impl View> { |
| 95 | 94 | Ok(view! { |
| 96 | 95 | if rows.is_empty() { |
| 97 | - <p class="muted">(g::t(lang, K::NoEntries))</p> | |
| 96 | + empty_state(title: g::t(lang, K::NoEntries)) | |
| 98 | 97 | } else { |
| 99 | 98 | <div class="table-wrap"> |
| 100 | 99 | <table class="table audit-table queue-table"> |
| @@ -113,7 +112,7 @@ async fn audit_table(lang: Lang, rows: Vec<RowView>, show_actor: bool) -> Result | ||
| 113 | 112 | <tbody> |
| 114 | 113 | for row in rows.into_iter() { |
| 115 | 114 | <tr> |
| 116 | - <td class="small nowrap" data-label=(g::t(lang, K::TableWhen))>(row.when.as_str())</td> | |
| 115 | + <td class="small nowrap" data-label=(g::t(lang, K::TableWhen))>rel_time(lang: lang, stamp: row.when.as_str())</td> | |
| 117 | 116 | if show_actor { |
| 118 | 117 | <td data-label=(g::t(lang, K::TableActor))>(row.actor.as_str())</td> |
| 119 | 118 | } |
| @@ -233,10 +232,9 @@ async fn admin_audit_page(cx: &Cx) -> Result<impl View> { | ||
| 233 | 232 | fetch_page(store, &filter, query.before.as_deref()).await? |
| 234 | 233 | }; |
| 235 | 234 | |
| 236 | - let tz = viewer.0.timezone.as_str(); | |
| 237 | 235 | let rows: Vec<RowView> = entries |
| 238 | 236 | .iter() |
| 239 | - .map(|entry| row_view(entry, tz, lang)) | |
| 237 | + .map(|entry| row_view(entry, lang)) | |
| 240 | 238 | .collect(); |
| 241 | 239 | let older_href = next.map(|cursor| { |
| 242 | 240 | list_href( |
| @@ -311,10 +309,9 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> { | ||
| 311 | 309 | }; |
| 312 | 310 | let (entries, next) = fetch_page(store, &filter, query.before.as_deref()).await?; |
| 313 | 311 | |
| 314 | - let tz = viewer.0.timezone.as_str(); | |
| 315 | 312 | let rows: Vec<RowView> = entries |
| 316 | 313 | .iter() |
| 317 | - .map(|entry| row_view(entry, tz, lang)) | |
| 314 | + .map(|entry| row_view(entry, lang)) | |
| 318 | 315 | .collect(); |
| 319 | 316 | let older_href = |
| 320 | 317 | next.map(|cursor| list_href("/settings/security/log", &[("before", cursor.as_str())])); |
| @@ -479,7 +476,7 @@ mod tests { | ||
| 479 | 476 | fn anonymous_actor_and_target_fallbacks() { |
| 480 | 477 | let mut entry = AuditEntry::new(AuditAction::LoginFailed); |
| 481 | 478 | entry.target_name = "mallory".into(); |
| 482 | - let row = row_view(&entry, "UTC", Lang::En); | |
| 479 | + let row = row_view(&entry, Lang::En); | |
| 483 | 480 | assert_eq!(row.actor, "anonymous"); |
| 484 | 481 | assert_eq!(row.target, "mallory"); |
| 485 | 482 | assert_eq!(row.details, ""); |
crates/forge-web/src/pages/authoring.rsmodified+3 -1
| @@ -278,7 +278,9 @@ async fn download(cx: &Cx) -> Result<Response> { | ||
| 278 | 278 | ); |
| 279 | 279 | h.insert( |
| 280 | 280 | HeaderName::from_static("cache-control"), |
| 281 | - HeaderValue::from_static("private, max-age=3600"), | |
| 281 | + // No max-age: a repo made private must stop serving its attachments at once, so | |
| 282 | + // browsers revalidate on every use instead of reusing a cached copy. | |
| 283 | + HeaderValue::from_static("private, no-cache"), | |
| 282 | 284 | ); |
| 283 | 285 | Ok(res) |
| 284 | 286 | } |
crates/forge-web/src/pages/branches.rsmodified+2 -2
| @@ -29,7 +29,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo}; | ||
| 29 | 29 | use crate::pages::tree::{LastCommit, last_commit_view}; |
| 30 | 30 | use crate::post_update::after_ref_update; |
| 31 | 31 | use crate::state::AppState; |
| 32 | -use crate::views::{alert, iso_time, now_unix, relative_time, repo_href, shell}; | |
| 32 | +use crate::views::{alert, empty_state, iso_time, now_unix, relative_time, repo_href, shell}; | |
| 33 | 33 | |
| 34 | 34 | path_param!(owner); |
| 35 | 35 | path_param!(repo); |
| @@ -317,7 +317,7 @@ async fn branches_page(cx: &Cx) -> Result<impl View> { | ||
| 317 | 317 | default_branch: default_branch, options: options) |
| 318 | 318 | } |
| 319 | 319 | if empty { |
| 320 | - <p class="muted">(g::t(lang, K::NothingHere))</p> | |
| 320 | + empty_state(title: g::t(lang, K::NothingHere)) | |
| 321 | 321 | } else { |
| 322 | 322 | branch_table(rows: rows, lang: lang, csrf: csrf.clone(), delete_action: delete_action, can_delete: can_write) |
| 323 | 323 | } |
crates/forge-web/src/pages/ci_job.rsmodified+25 -4
| @@ -11,8 +11,8 @@ use std::sync::Arc; | ||
| 11 | 11 | use std::time::Duration; |
| 12 | 12 | |
| 13 | 13 | use bytes::Bytes; |
| 14 | -use forge_core::Store; | |
| 15 | 14 | use forge_core::ci::{CiArtifact, CiJob, CiRun}; |
| 15 | +use forge_core::{Store, User}; | |
| 16 | 16 | use futures_util::{Stream, TryStreamExt}; |
| 17 | 17 | use http::header::{CONTENT_DISPOSITION, CONTENT_LENGTH, CONTENT_TYPE}; |
| 18 | 18 | use http_body::Frame; |
| @@ -38,7 +38,7 @@ use crate::pages::ci_runs::{ | ||
| 38 | 38 | state_text, |
| 39 | 39 | }; |
| 40 | 40 | use crate::pages::repo::repo_head; |
| 41 | -use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | |
| 41 | +use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo, still_readable}; | |
| 42 | 42 | use crate::state::AppState; |
| 43 | 43 | use crate::views::{enc, human_size, shell}; |
| 44 | 44 | |
| @@ -161,13 +161,15 @@ async fn log_tail(path: &Path) -> Result<Tail> { | ||
| 161 | 161 | |
| 162 | 162 | /// Follows a log: yields what the file holds, then sends new bytes each time the job changes (its |
| 163 | 163 | /// log grew or its state did). The stream ends when the job is terminal and a read after seeing |
| 164 | -/// that returns nothing, so every byte the runner wrote is sent. A job that is gone, or a read | |
| 165 | -/// error, ends the stream. | |
| 164 | +/// that returns nothing, so every byte the runner wrote is sent. A job that is gone, a read | |
| 165 | +/// error, or a repo the viewer can no longer read ends the stream. | |
| 166 | 166 | pub(crate) fn follow_log( |
| 167 | 167 | store: Store, |
| 168 | 168 | live: Arc<CiLive>, |
| 169 | 169 | job_id: String, |
| 170 | 170 | path: PathBuf, |
| 171 | + viewer: Option<User>, | |
| 172 | + repo_id: String, | |
| 171 | 173 | ) -> impl Stream<Item = std::io::Result<Bytes>> + Send + 'static { |
| 172 | 174 | struct Follow { |
| 173 | 175 | store: Store, |
| @@ -177,6 +179,8 @@ pub(crate) fn follow_log( | ||
| 177 | 179 | file: Option<tokio::fs::File>, |
| 178 | 180 | /// Subscribed before the first read, so a change between the read and the wait is seen. |
| 179 | 181 | wake: watch::Receiver<u64>, |
| 182 | + viewer: Option<User>, | |
| 183 | + repo_id: String, | |
| 180 | 184 | } |
| 181 | 185 | let wake = live.subscribe_job(&job_id); |
| 182 | 186 | futures_util::stream::unfold( |
| @@ -187,9 +191,14 @@ pub(crate) fn follow_log( | ||
| 187 | 191 | path, |
| 188 | 192 | file: None, |
| 189 | 193 | wake, |
| 194 | + viewer, | |
| 195 | + repo_id, | |
| 190 | 196 | }, |
| 191 | 197 | |mut follow| async move { |
| 192 | 198 | loop { |
| 199 | + if !still_readable(&follow.store, follow.viewer.as_ref(), &follow.repo_id).await { | |
| 200 | + return None; | |
| 201 | + } | |
| 193 | 202 | // Checked before the read, so a read that finds nothing after this is the end. |
| 194 | 203 | let terminal = match follow.store.job_by_id(&follow.job_id).await { |
| 195 | 204 | Ok(Some(job)) => job.state.is_terminal(), |
| @@ -524,6 +533,8 @@ async fn job_events(cx: &Cx) -> Result<Response> { | ||
| 524 | 533 | primed: false, |
| 525 | 534 | pending_fingerprint: None, |
| 526 | 535 | pending_log: None, |
| 536 | + viewer: ctx.viewer.as_ref().map(|(user, _)| user.clone()), | |
| 537 | + repo_id: ctx.repo.id.clone(), | |
| 527 | 538 | }; |
| 528 | 539 | events_response(cx, job_stream(follow)) |
| 529 | 540 | } |
| @@ -555,11 +566,19 @@ struct JobFollow { | ||
| 555 | 566 | pending_fingerprint: Option<String>, |
| 556 | 567 | /// The text and the offset past it. |
| 557 | 568 | pending_log: Option<(String, u64)>, |
| 569 | + /// The viewer the stream opened for, and the repo, so each send is checked for read access. | |
| 570 | + viewer: Option<User>, | |
| 571 | + repo_id: String, | |
| 558 | 572 | } |
| 559 | 573 | |
| 560 | 574 | fn job_stream(follow: JobFollow) -> impl Stream<Item = Result<Event>> + Send + 'static { |
| 561 | 575 | futures_util::stream::unfold(follow, |mut f| async move { |
| 562 | 576 | loop { |
| 577 | + // Checked before anything is sent, so a repo made private or a removed collaborator ends | |
| 578 | + // the stream on the next wake, not when it reopens. | |
| 579 | + if !still_readable(&f.store, f.viewer.as_ref(), &f.repo_id).await { | |
| 580 | + return None; | |
| 581 | + } | |
| 563 | 582 | if let Some(fingerprint) = f.pending_fingerprint.take() { |
| 564 | 583 | return Some((changed_event(fingerprint), f)); |
| 565 | 584 | } |
| @@ -643,6 +662,8 @@ async fn job_log(cx: &Cx) -> Result<Response> { | ||
| 643 | 662 | Arc::clone(&state.ci_live), |
| 644 | 663 | job.id.clone(), |
| 645 | 664 | path, |
| 665 | + ctx.viewer.as_ref().map(|(user, _)| user.clone()), | |
| 666 | + ctx.repo.id.clone(), | |
| 646 | 667 | ) |
| 647 | 668 | .map_ok(Frame::data); |
| 648 | 669 | let mut res = Response::new(Body::new(StreamBody::new(chunks))); |
crates/forge-web/src/pages/ci_runs.rsmodified+17 -12
| @@ -40,9 +40,9 @@ use crate::i18n::{ | ||
| 40 | 40 | }; |
| 41 | 41 | use crate::pages::refs::load_refs; |
| 42 | 42 | use crate::pages::repo::repo_head; |
| 43 | -use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | |
| 43 | +use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo, still_readable}; | |
| 44 | 44 | use crate::state::AppState; |
| 45 | -use crate::views::{alert, enc, human_size, now_unix, relative_time, shell, short_oid}; | |
| 45 | +use crate::views::{alert, empty_state, enc, human_size, now_unix, rel_time, relative_time, shell, short_oid}; | |
| 46 | 46 | |
| 47 | 47 | path_param!(owner); |
| 48 | 48 | path_param!(repo); |
| @@ -321,11 +321,9 @@ fn trigger_text(lang: Lang, trigger: &str) -> String { | ||
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | -/// The next scheduled run as `2026-10-21 03:00 UTC`. | |
| 324 | +/// The next scheduled run as an RFC 3339 stamp, shown as a live relative time. | |
| 325 | 325 | fn next_run_text(at: i64) -> Option<String> { |
| 326 | - let when = time::OffsetDateTime::from_unix_timestamp(at).ok()?; | |
| 327 | - let format = time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]"); | |
| 328 | - Some(format!("{} UTC", when.format(&format).ok()?)) | |
| 326 | + forge_core::time::stamp_from_unix(at) | |
| 329 | 327 | } |
| 330 | 328 | |
| 331 | 329 | /// One run in the list. `bar` is its duration bar on the page's shared scale. |
| @@ -1662,13 +1660,10 @@ async fn runs_body( | ||
| 1662 | 1660 | </div> |
| 1663 | 1661 | </div> |
| 1664 | 1662 | if let Some(next) = next_scheduled.as_ref() { |
| 1665 | - <p class="ci-next muted small">(g::t(lang, K::NextScheduledRun)) ": " <time>(next.as_str())</time></p> | |
| 1663 | + <p class="ci-next muted small">(g::t(lang, K::NextScheduledRun)) ": " rel_time(lang: lang, stamp: next.as_str())</p> | |
| 1666 | 1664 | } |
| 1667 | 1665 | if rows.is_empty() { |
| 1668 | - <div class="ci-empty"> | |
| 1669 | - <p>(g::t(lang, K::NoRunsYet))</p> | |
| 1670 | - <p class="muted small">(g::t(lang, K::NoRunsHint))</p> | |
| 1671 | - </div> | |
| 1666 | + empty_state(title: g::t(lang, K::NoRunsYet), hint: Some(g::t(lang, K::NoRunsHint))) | |
| 1672 | 1667 | } else { |
| 1673 | 1668 | <p class="ci-scale">(scale.as_str())</p> |
| 1674 | 1669 | <ul class="ci-run-list"> |
| @@ -2070,10 +2065,20 @@ async fn run_events(cx: &Cx) -> Result<Response> { | ||
| 2070 | 2065 | let wake = state.ci_live.subscribe_run(&run.id); |
| 2071 | 2066 | let store = state.store.clone(); |
| 2072 | 2067 | let run_id = run.id.clone(); |
| 2068 | + let viewer = ctx.viewer.as_ref().map(|(user, _)| user.clone()); | |
| 2069 | + let repo_id = ctx.repo.id.clone(); | |
| 2073 | 2070 | let events = changed_stream(wake, false, move || { |
| 2074 | 2071 | let store = store.clone(); |
| 2075 | 2072 | let run_id = run_id.clone(); |
| 2076 | - async move { run_status(&store, &run_id).await } | |
| 2073 | + let viewer = viewer.clone(); | |
| 2074 | + let repo_id = repo_id.clone(); | |
| 2075 | + async move { | |
| 2076 | + // A repo the viewer can no longer read ends the stream before the status is sent. | |
| 2077 | + if !still_readable(&store, viewer.as_ref(), &repo_id).await { | |
| 2078 | + return Ok(None); | |
| 2079 | + } | |
| 2080 | + run_status(&store, &run_id).await | |
| 2081 | + } | |
| 2077 | 2082 | }); |
| 2078 | 2083 | events_response(cx, events) |
| 2079 | 2084 | } |
crates/forge-web/src/pages/ci_tests.rsmodified+2 -0
| @@ -848,6 +848,8 @@ async fn log_txt_and_log_follower() { | ||
| 848 | 848 | Arc::clone(&live), |
| 849 | 849 | job.id.clone(), |
| 850 | 850 | path.clone(), |
| 851 | + fx.store.user_by_id(&fx.tahinli).await.expect("viewer"), | |
| 852 | + run.repo_id.clone(), | |
| 851 | 853 | )); |
| 852 | 854 | let (tx, mut chunks) = tokio::sync::mpsc::unbounded_channel(); |
| 853 | 855 | tokio::spawn(async move { |
crates/forge-web/src/pages/code_search.rsmodified+2 -2
| @@ -20,7 +20,7 @@ use crate::pages::commits::blocking; | ||
| 20 | 20 | use crate::pages::repo::repo_head; |
| 21 | 21 | use crate::pages::repo_ctx::load_repo; |
| 22 | 22 | use crate::state::AppState; |
| 23 | -use crate::views::{repo_href, shell}; | |
| 23 | +use crate::views::{empty_state, repo_href, shell}; | |
| 24 | 24 | |
| 25 | 25 | path_param!(owner); |
| 26 | 26 | path_param!(repo); |
| @@ -260,7 +260,7 @@ async fn search_page(cx: &Cx) -> Result<impl View> { | ||
| 260 | 260 | } |
| 261 | 261 | </section> |
| 262 | 262 | } else if searched { |
| 263 | - <p class="muted">(g::t(lang, K::NoMatches))</p> | |
| 263 | + empty_state(title: g::t(lang, K::NoMatches)) | |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | ) |
crates/forge-web/src/pages/commits.rsmodified+6 -2
| @@ -24,7 +24,7 @@ use crate::render::emoji::emojify; | ||
| 24 | 24 | use crate::signatures::{self, SigBadge}; |
| 25 | 25 | use crate::state::AppState; |
| 26 | 26 | use crate::views::commit_status::{StatusLang, StatusSummary, commit_status}; |
| 27 | -use crate::views::shell; | |
| 27 | +use crate::views::{empty_state, shell}; | |
| 28 | 28 | |
| 29 | 29 | path_param!(owner); |
| 30 | 30 | path_param!(repo); |
| @@ -286,7 +286,11 @@ async fn commits_page(cx: &Cx) -> Result<impl View> { | ||
| 286 | 286 | <p class="muted">(g::t(lang, K::FilteredTo)) <code>(filter_text.as_str())</code> " · " <a href=(clear_href.as_str())>(g::t(lang, K::ClearFilter))</a></p> |
| 287 | 287 | } |
| 288 | 288 | if empty { |
| 289 | - <p class="muted">(g::t(lang, K::NoCommits))</p> | |
| 289 | + empty_state(title: g::t(lang, K::NoCommits), | |
| 290 | + if has_filter { | |
| 291 | + <a class="button" href=(clear_href.as_str())>(g::t(lang, K::ClearFilter))</a> | |
| 292 | + } | |
| 293 | + ) | |
| 290 | 294 | } else { |
| 291 | 295 | <ul class="commit-list"> |
| 292 | 296 | for row in rows.iter() { |
crates/forge-web/src/pages/compare.rsmodified+2 -2
| @@ -37,7 +37,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo}; | ||
| 37 | 37 | use crate::state::AppState; |
| 38 | 38 | use crate::templates; |
| 39 | 39 | use crate::views::diff::{DiffLang, DiffOpts, LIMITS, diff_section}; |
| 40 | -use crate::views::{alert, repo_href, shell, user_facing_message}; | |
| 40 | +use crate::views::{alert, empty_state, repo_href, shell, user_facing_message}; | |
| 41 | 41 | use crate::webhooks::emit::{Sender, emit_pull}; |
| 42 | 42 | |
| 43 | 43 | path_param!(owner); |
| @@ -337,7 +337,7 @@ async fn compare_view( | ||
| 337 | 337 | <p class="muted">(g::t(lang, K::Unrelated))</p> |
| 338 | 338 | } |
| 339 | 339 | if nothing { |
| 340 | - <p class="muted">(g::t(lang, K::NothingToCompare))</p> | |
| 340 | + empty_state(title: g::t(lang, K::NothingToCompare)) | |
| 341 | 341 | } |
| 342 | 342 | if has_commits { |
| 343 | 343 | <h3>(commits_label.as_str())</h3> |
crates/forge-web/src/pages/dashboard.rsmodified+5 -3
| @@ -25,7 +25,7 @@ use crate::pages::issue_parts::stamp_unix; | ||
| 25 | 25 | use crate::pages::repo_settings::{notice_banner_for, take_notice}; |
| 26 | 26 | use crate::state::AppState; |
| 27 | 27 | use crate::views::heatmap::{self, Calendar, DayDetail, contribution_calendar}; |
| 28 | -use crate::views::{SIDE_REPOS, display_name, now_unix, relative_time, shell}; | |
| 28 | +use crate::views::{SIDE_REPOS, display_name, empty_state, now_unix, relative_time, shell}; | |
| 29 | 29 | |
| 30 | 30 | /// How far back the calendar reads contributions: 53 weeks plus the days of the current week. |
| 31 | 31 | const CALENDAR_DAYS: u64 = 371; |
| @@ -303,7 +303,9 @@ async fn dashboard(dash: Dashboard, lang: Lang) -> Result<impl View> { | ||
| 303 | 303 | <a class="button primary" href="/new">(g::t(lang, K::NewRepository))</a> |
| 304 | 304 | </div> |
| 305 | 305 | if empty { |
| 306 | - <p class="muted">(g::t(lang, K::NoReposYet))</p> | |
| 306 | + empty_state(title: g::t(lang, K::NoReposYet), | |
| 307 | + <a class="button primary" href="/new">(g::t(lang, K::NewRepository))</a> | |
| 308 | + <a class="button" href="/new/import">(crate::i18n::migrate::t(lang, crate::i18n::migrate::K::ImportTitle))</a>) | |
| 307 | 309 | } else { |
| 308 | 310 | <div class="table-wrap"> |
| 309 | 311 | <table class="table"> |
| @@ -337,7 +339,7 @@ async fn dashboard(dash: Dashboard, lang: Lang) -> Result<impl View> { | ||
| 337 | 339 | <h2 id="attn-h">(m::t(lang, MK::NeedsAttention))</h2> |
| 338 | 340 | </div> |
| 339 | 341 | if attention_empty { |
| 340 | - <p class="muted">(m::t(lang, MK::NothingNeedsYou))</p> | |
| 342 | + empty_state(title: m::t(lang, MK::NothingNeedsYou)) | |
| 341 | 343 | } else { |
| 342 | 344 | <ul class="attn"> |
| 343 | 345 | for item in dash.attention.into_iter() { |
crates/forge-web/src/pages/discussions.rsmodified+6 -2
| @@ -27,7 +27,7 @@ use crate::pages::repo::repo_head; | ||
| 27 | 27 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| 28 | 28 | use crate::render::markdown::mentioned_usernames; |
| 29 | 29 | use crate::state::AppState; |
| 30 | -use crate::views::{alert, csrf_field, now_unix, repo_href, shell, user_link}; | |
| 30 | +use crate::views::{alert, csrf_field, empty_state, now_unix, repo_href, shell, user_link}; | |
| 31 | 31 | |
| 32 | 32 | path_param!(owner); |
| 33 | 33 | path_param!(repo); |
| @@ -317,7 +317,11 @@ async fn discussions_list_page(cx: &Cx) -> Result<impl View> { | ||
| 317 | 317 | } |
| 318 | 318 | </div> |
| 319 | 319 | if rows.is_empty() { |
| 320 | - <p class="muted">(empty_text)</p> | |
| 320 | + empty_state(title: empty_text, | |
| 321 | + if can_start { | |
| 322 | + <a class="button primary" href=(new_href.as_str())>(new_label)</a> | |
| 323 | + } | |
| 324 | + ) | |
| 321 | 325 | } else { |
| 322 | 326 | <ul class="issue-list"> |
| 323 | 327 | for row in rows.iter() { |
crates/forge-web/src/pages/explore.rsmodified+7 -2
| @@ -18,7 +18,7 @@ use crate::state::AppState; | ||
| 18 | 18 | use crate::views::repo_list::{ |
| 19 | 19 | PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips, |
| 20 | 20 | }; |
| 21 | -use crate::views::{enc, now_unix, shell}; | |
| 21 | +use crate::views::{empty_state, enc, now_unix, shell}; | |
| 22 | 22 | |
| 23 | 23 | const PER_PAGE: u64 = 30; |
| 24 | 24 | /// Longest search text kept, in characters. |
| @@ -194,8 +194,10 @@ async fn explore_body( | ||
| 194 | 194 | live: String, |
| 195 | 195 | ) -> Result<impl View> { |
| 196 | 196 | let empty = rows.is_empty(); |
| 197 | + let has_search = !q.is_empty(); | |
| 197 | 198 | let has_orgs = !orgs.is_empty(); |
| 198 | 199 | let (links, prev, next) = nav; |
| 200 | + let clear_href = explore_href("", sort, 1); | |
| 199 | 201 | Ok(view! { |
| 200 | 202 | <section class="explore" data-live=(live.as_str())> |
| 201 | 203 | <h1>(g::t(lang, K::Explore))</h1> |
| @@ -219,7 +221,10 @@ async fn explore_body( | ||
| 219 | 221 | sort_chips(links: sort_links, lang: lang) |
| 220 | 222 | <p class="muted small">(g::repo_count(lang, total))</p> |
| 221 | 223 | if empty { |
| 222 | - <p class="muted">(g::t(lang, K::NoPublicReposMatch))</p> | |
| 224 | + empty_state(title: g::t(lang, K::NoPublicReposMatch), | |
| 225 | + if has_search { | |
| 226 | + <a class="button" href=(clear_href.as_str())>(g::t(lang, K::ClearSearch))</a> | |
| 227 | + }) | |
| 223 | 228 | } else { |
| 224 | 229 | repo_rows(rows: rows, lang: lang) |
| 225 | 230 | } |
crates/forge-web/src/pages/import.rsmodified+19 -15
| @@ -5,7 +5,6 @@ | ||
| 5 | 5 | use std::collections::HashMap; |
| 6 | 6 | |
| 7 | 7 | use forge_core::store::imports::{ImportJob, ImportState}; |
| 8 | -use forge_core::time::stamp_to_unix; | |
| 9 | 8 | use forge_core::{AuditAction, Repo, User, Visibility}; |
| 10 | 9 | use forge_git::repo::{init_bare, repo_path}; |
| 11 | 10 | use futures_util::stream; |
| @@ -30,8 +29,9 @@ use crate::importer::{ | ||
| 30 | 29 | }; |
| 31 | 30 | use crate::pages::ci_runs::{changed_event, events_response}; |
| 32 | 31 | use crate::pages::new_repo::{owner_choices, repo_owner}; |
| 32 | +use crate::pages::repo_ctx::still_readable; | |
| 33 | 33 | use crate::state::AppState; |
| 34 | -use crate::views::{alert, csrf_field, now_unix, relative_time, shell, user_facing_message}; | |
| 34 | +use crate::views::{alert, csrf_field, empty_state, rel_time, shell, user_facing_message}; | |
| 35 | 35 | |
| 36 | 36 | path_param!(job_id); |
| 37 | 37 | |
| @@ -682,7 +682,7 @@ async fn bulk_select( | ||
| 682 | 682 | </div> |
| 683 | 683 | </header> |
| 684 | 684 | if empty { |
| 685 | - <p class="muted">(g::t(lang, K::BulkNone))</p> | |
| 685 | + empty_state(title: g::t(lang, K::BulkNone)) | |
| 686 | 686 | } else { |
| 687 | 687 | <div class="newrepo-card import-pick"> |
| 688 | 688 | <label class="inline import-pick-all"> |
| @@ -968,8 +968,16 @@ fn stage_name(lang: Lang, stage: &str) -> &'static str { | ||
| 968 | 968 | } |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | -fn ago(lang: Lang, stamp: &str) -> String { | |
| 972 | - stamp_to_unix(stamp).map_or_else(String::new, |t| relative_time(lang, t, now_unix())) | |
| 971 | +/// The job's repository, once it exists and while `user` may still read it: an import into an | |
| 972 | +/// org the user has since left, or a repo transferred away, is not named. | |
| 973 | +async fn job_repo(state: &AppState, user: Option<&User>, job: &ImportJob) -> Result<Option<Repo>> { | |
| 974 | + let Some(id) = &job.repo_id else { | |
| 975 | + return Ok(None); | |
| 976 | + }; | |
| 977 | + if !still_readable(&state.store, user, id).await { | |
| 978 | + return Ok(None); | |
| 979 | + } | |
| 980 | + Ok(state.store.repo_by_id(id).await?) | |
| 973 | 981 | } |
| 974 | 982 | |
| 975 | 983 | /// The user's newest import jobs, each with its repository once it exists. |
| @@ -978,13 +986,11 @@ async fn load_job_rows( | ||
| 978 | 986 | user_id: &str, |
| 979 | 987 | limit: u32, |
| 980 | 988 | ) -> Result<Vec<(ImportJob, Option<Repo>)>> { |
| 989 | + let user = state.store.user_by_id(user_id).await?; | |
| 981 | 990 | let jobs = state.store.list_import_jobs(user_id, limit).await?; |
| 982 | 991 | let mut rows = Vec::with_capacity(jobs.len()); |
| 983 | 992 | for job in jobs { |
| 984 | - let repo = match &job.repo_id { | |
| 985 | - Some(id) => state.store.repo_by_id(id).await?, | |
| 986 | - None => None, | |
| 987 | - }; | |
| 993 | + let repo = job_repo(state, user.as_ref(), &job).await?; | |
| 988 | 994 | rows.push((job, repo)); |
| 989 | 995 | } |
| 990 | 996 | Ok(rows) |
| @@ -999,7 +1005,7 @@ async fn job_rows(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<im | ||
| 999 | 1005 | <li class="item import-job-row"> |
| 1000 | 1006 | <div class="item-main"> |
| 1001 | 1007 | <a href=(format!("/import/{}", job.id)) class="import-job-name">(job.source_ref.as_str())</a> |
| 1002 | - <span class="muted small">(g::t(lang, K::JobStarted)) " " <time data-rel="true" datetime=(job.created_at.as_str())>(ago(lang, &job.created_at))</time></span> | |
| 1008 | + <span class="muted small">(g::t(lang, K::JobStarted)) " " rel_time(lang: lang, stamp: job.created_at.as_str())</span> | |
| 1003 | 1009 | </div> |
| 1004 | 1010 | if let Some(repo) = repo { |
| 1005 | 1011 | <a href=(format!("/{}/{}", repo.owner_name, repo.name)) class="muted small mono">(format!("{}/{}", repo.owner_name, repo.name))</a> |
| @@ -1042,7 +1048,8 @@ async fn jobs_list(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<i | ||
| 1042 | 1048 | <h1>(g::t(lang, K::JobsTitle))</h1> |
| 1043 | 1049 | </section> |
| 1044 | 1050 | if empty { |
| 1045 | - <p class="muted">(g::t(lang, K::NoJobs))</p> | |
| 1051 | + empty_state(title: g::t(lang, K::NoJobs), | |
| 1052 | + <a class="button" href="/new/import">(g::t(lang, K::ImportTitle))</a>) | |
| 1046 | 1053 | } else { |
| 1047 | 1054 | <section class="card"> |
| 1048 | 1055 | job_rows(lang: lang, jobs: jobs) |
| @@ -1195,10 +1202,7 @@ async fn job_page(cx: &Cx) -> Result<impl View> { | ||
| 1195 | 1202 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 1196 | 1203 | let state = app_context::<AppState>(cx); |
| 1197 | 1204 | let job = owned_job(cx, &viewer.0).await?; |
| 1198 | - let repo = match &job.repo_id { | |
| 1199 | - Some(id) => state.store.repo_by_id(id).await?, | |
| 1200 | - None => None, | |
| 1201 | - }; | |
| 1205 | + let repo = job_repo(state, Some(&viewer.0), &job).await?; | |
| 1202 | 1206 | let log = state.store.list_import_events(&job.id, 200).await?; |
| 1203 | 1207 | let csrf = viewer.1.csrf_token.clone(); |
| 1204 | 1208 | let title = job.source_ref.clone(); |
crates/forge-web/src/pages/issues_list.rsmodified+20 -6
| @@ -26,8 +26,8 @@ use crate::pages::repo_ctx::{RepoHead, load_repo}; | ||
| 26 | 26 | use crate::state::AppState; |
| 27 | 27 | use crate::templates::{self, Template}; |
| 28 | 28 | use crate::views::{ |
| 29 | - alert, avatar_url, csrf_field, enc, iso_time, now_unix, relative_time, repo_href, shell, | |
| 30 | - user_facing_message, user_link, | |
| 29 | + alert, avatar_url, csrf_field, empty_state, enc, iso_time, now_unix, relative_time, repo_href, | |
| 30 | + shell, user_facing_message, user_link, | |
| 31 | 31 | }; |
| 32 | 32 | use crate::webhooks::emit::{Sender, emit_issue}; |
| 33 | 33 | |
| @@ -484,7 +484,11 @@ async fn issues_list_page(cx: &Cx) -> Result<impl View> { | ||
| 484 | 484 | let labels_page_href = repo_href(&owner_name, &repo_name, "labels", ""); |
| 485 | 485 | let milestones_href = repo_href(&owner_name, &repo_name, "milestones", ""); |
| 486 | 486 | let title = g::issues_title(lang, &format!("{owner_name}/{repo_name}")); |
| 487 | - let empty_text = g::t(lang, K::NoIssuesMatch); | |
| 487 | + let empty_text = if has_filters { | |
| 488 | + g::t(lang, K::NoIssuesMatch) | |
| 489 | + } else { | |
| 490 | + g::t(lang, K::NoIssuesYet) | |
| 491 | + }; | |
| 488 | 492 | let state_word = sel.state; |
| 489 | 493 | |
| 490 | 494 | let live_href = list_live_url(&owner_name, &repo_name); |
| @@ -543,7 +547,17 @@ async fn issues_list_page(cx: &Cx) -> Result<impl View> { | ||
| 543 | 547 | </section> |
| 544 | 548 | } |
| 545 | 549 | if rows.is_empty() { |
| 546 | - <p class="muted">(empty_text)</p> | |
| 550 | + if has_filters { | |
| 551 | + empty_state(title: empty_text, | |
| 552 | + <a class="button" href=(clear_href.as_str())>(g::t(lang, K::ClearFilters))</a> | |
| 553 | + ) | |
| 554 | + } else { | |
| 555 | + empty_state(title: empty_text, | |
| 556 | + if can_create { | |
| 557 | + <a class="button primary" href=(new_href.as_str())>(g::t(lang, K::NewIssue))</a> | |
| 558 | + } | |
| 559 | + ) | |
| 560 | + } | |
| 547 | 561 | } else { |
| 548 | 562 | <ul class="issue-list"> |
| 549 | 563 | for row in rows.iter() { |
| @@ -1020,7 +1034,7 @@ mod tests { | ||
| 1020 | 1034 | } |
| 1021 | 1035 | let empty = send(&fx.router, "GET", &base(), true, None, &[]).await; |
| 1022 | 1036 | assert_eq!(empty.status, 200, "empty list"); |
| 1023 | - assert!(empty.text().contains("No issues match these filters.")); | |
| 1037 | + assert!(empty.text().contains("No issues yet.")); | |
| 1024 | 1038 | assert_eq!(rows(&empty.text()), 0); |
| 1025 | 1039 | let tr = send( |
| 1026 | 1040 | &fx.router, |
| @@ -1033,7 +1047,7 @@ mod tests { | ||
| 1033 | 1047 | .await |
| 1034 | 1048 | .text(); |
| 1035 | 1049 | assert!(tr.contains(">Yeni sorun</a>"), "{tr}"); |
| 1036 | - assert!(tr.contains("Bu filtrelerle eşleşen sorun yok."), "{tr}"); | |
| 1050 | + assert!(tr.contains("Henüz sorun yok."), "{tr}"); | |
| 1037 | 1051 | |
| 1038 | 1052 | // [refusals] an empty-title draft keeps its body and creates nothing; bad CSRF is 403. |
| 1039 | 1053 | let draft = send( |
crates/forge-web/src/pages/labels_page.rsmodified+11 -10
| @@ -21,7 +21,7 @@ use crate::pages::issues_live::list_live_url; | ||
| 21 | 21 | use crate::pages::repo::repo_head; |
| 22 | 22 | use crate::pages::repo_ctx::load_repo; |
| 23 | 23 | use crate::state::AppState; |
| 24 | -use crate::views::{enc, shell}; | |
| 24 | +use crate::views::{empty_state, enc, shell}; | |
| 25 | 25 | |
| 26 | 26 | path_param!(owner); |
| 27 | 27 | path_param!(repo); |
| @@ -88,15 +88,16 @@ async fn labels_body( | ||
| 88 | 88 | <section class="card" data-live=(live.as_str()) data-live-now=""> |
| 89 | 89 | <h2>(g::t(lang, K::Labels))</h2> |
| 90 | 90 | if empty { |
| 91 | - <p class="muted">(g::t(lang, K::NoLabelsYet))</p> | |
| 92 | - if can_triage && !archived { | |
| 93 | - <form method="post" action=(defaults_action.as_str()) class="stack"> | |
| 94 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 95 | - <div> | |
| 96 | - <button type="submit">(g::t(lang, K::AddDefaultLabels))</button> | |
| 97 | - </div> | |
| 98 | - </form> | |
| 99 | - } | |
| 91 | + empty_state(title: g::t(lang, K::NoLabelsYet), | |
| 92 | + if can_triage && !archived { | |
| 93 | + <form method="post" action=(defaults_action.as_str()) class="stack"> | |
| 94 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 95 | + <div> | |
| 96 | + <button type="submit">(g::t(lang, K::AddDefaultLabels))</button> | |
| 97 | + </div> | |
| 98 | + </form> | |
| 99 | + } | |
| 100 | + ) | |
| 100 | 101 | } |
| 101 | 102 | <ul class="label-list"> |
| 102 | 103 | for row in rows.iter() { |
crates/forge-web/src/pages/merge_queue.rsmodified+4 -12
| @@ -35,7 +35,7 @@ use crate::pages::pulls_merge::ERR_NOT_OPEN; | ||
| 35 | 35 | use crate::pages::repo::repo_head; |
| 36 | 36 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| 37 | 37 | use crate::state::AppState; |
| 38 | -use crate::views::{repo_href, shell}; | |
| 38 | +use crate::views::{rel_time, repo_href, shell}; | |
| 39 | 39 | |
| 40 | 40 | path_param!(owner); |
| 41 | 41 | path_param!(repo); |
| @@ -191,21 +191,13 @@ struct QueueRow { | ||
| 191 | 191 | state: &'static str, |
| 192 | 192 | state_class: &'static str, |
| 193 | 193 | by: String, |
| 194 | - queued: String, | |
| 194 | + queued_at: String, | |
| 195 | 195 | run_href: Option<String>, |
| 196 | 196 | run_label: String, |
| 197 | 197 | reason: String, |
| 198 | 198 | remove: bool, |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | -/// `2026-10-21T19:11:22.700Z` as `2026-10-21 19:11` (UTC), for the queue table. | |
| 202 | -fn stamp_minute(stamp: &str) -> String { | |
| 203 | - match stamp.get(..16) { | |
| 204 | - Some(minute) => minute.replace('T', " "), | |
| 205 | - None => stamp.to_owned(), | |
| 206 | - } | |
| 207 | -} | |
| 208 | - | |
| 209 | 201 | async fn queue_rows( |
| 210 | 202 | state: &AppState, |
| 211 | 203 | ctx: &RepoCtx, |
| @@ -282,7 +274,7 @@ async fn queue_rows( | ||
| 282 | 274 | state: state_label(lang, entry.state), |
| 283 | 275 | state_class: state_class(entry.state), |
| 284 | 276 | by, |
| 285 | - queued: stamp_minute(&entry.enqueued_at), | |
| 277 | + queued_at: entry.enqueued_at.clone(), | |
| 286 | 278 | run_href, |
| 287 | 279 | run_label, |
| 288 | 280 | reason: entry |
| @@ -403,7 +395,7 @@ async fn queue_body( | ||
| 403 | 395 | <td data-label=(g::t(lang, K::QueueColBranch))><code>(row.branch.as_str())</code></td> |
| 404 | 396 | <td data-label=(g::t(lang, K::QueueColState))><span class=(row.state_class)>(row.state)</span></td> |
| 405 | 397 | <td data-label=(g::t(lang, K::QueueColBy))>(row.by.as_str())</td> |
| 406 | - <td class="muted small" data-label=(g::t(lang, K::QueueColQueued))>(row.queued.as_str())</td> | |
| 398 | + <td class="muted small" data-label=(g::t(lang, K::QueueColQueued))>rel_time(lang: lang, stamp: row.queued_at.as_str())</td> | |
| 407 | 399 | <td data-label=(g::t(lang, K::QueueColRun))> |
| 408 | 400 | if let Some(href) = row.run_href.as_ref() { |
| 409 | 401 | <a href=(href.as_str())>(row.run_label.as_str())</a> |
crates/forge-web/src/pages/milestones_page.rsmodified+7 -2
| @@ -25,7 +25,7 @@ use crate::pages::repo::repo_head; | ||
| 25 | 25 | use crate::pages::repo_ctx::load_repo; |
| 26 | 26 | use crate::render::markdown::render_markdown; |
| 27 | 27 | use crate::state::AppState; |
| 28 | -use crate::views::{enc, shell}; | |
| 28 | +use crate::views::{empty_state, enc, shell}; | |
| 29 | 29 | |
| 30 | 30 | path_param!(owner); |
| 31 | 31 | path_param!(repo); |
| @@ -258,6 +258,11 @@ async fn milestones_body( | ||
| 258 | 258 | let can_triage = frame.can_triage; |
| 259 | 259 | let row_csrf = csrf.clone(); |
| 260 | 260 | let header = frame.head.clone(); |
| 261 | + let empty_text = if closed { | |
| 262 | + g::t(lang, K::NoClosedMilestones) | |
| 263 | + } else { | |
| 264 | + g::t(lang, K::NoOpenMilestones) | |
| 265 | + }; | |
| 261 | 266 | Ok(view! { |
| 262 | 267 | repo_head(head: header) |
| 263 | 268 | issue_subnav(lang: lang, title: title.clone(), active: "milestones".to_owned()) |
| @@ -267,7 +272,7 @@ async fn milestones_body( | ||
| 267 | 272 | state_tabs(lang: lang, title: title.clone(), closed: closed) |
| 268 | 273 | <section class="card" data-live=(live.as_str()) data-live-now=""> |
| 269 | 274 | if empty { |
| 270 | - <p class="muted">(if closed { g::t(lang, K::NoClosedMilestones) } else { g::t(lang, K::NoOpenMilestones) })</p> | |
| 275 | + empty_state(title: empty_text) | |
| 271 | 276 | } |
| 272 | 277 | <ul class="milestone-list"> |
| 273 | 278 | for row in rows.into_iter() { |
crates/forge-web/src/pages/mod.rsmodified+1 -0
| @@ -79,6 +79,7 @@ pub mod org_settings; | ||
| 79 | 79 | pub mod org_teams; |
| 80 | 80 | pub mod packages; |
| 81 | 81 | pub mod packages_oci; |
| 82 | +pub mod palette; | |
| 82 | 83 | pub mod passkeys; |
| 83 | 84 | #[cfg(test)] |
| 84 | 85 | mod passkeys_tests; |
crates/forge-web/src/pages/notifications.rsmodified+10 -8
| @@ -35,7 +35,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo}; | ||
| 35 | 35 | use crate::pages::repo_transfer::transfer_list_for; |
| 36 | 36 | use crate::pages::star::return_path; |
| 37 | 37 | use crate::state::AppState; |
| 38 | -use crate::views::{csrf_field, display_name, iso_time, now_unix, relative_time, repo_href, shell}; | |
| 38 | +use crate::views::{csrf_field, display_name, empty_state, iso_time, now_unix, relative_time, repo_href, shell}; | |
| 39 | 39 | |
| 40 | 40 | /// Rows per inbox page. |
| 41 | 41 | const PAGE_SIZE: u32 = 50; |
| @@ -972,6 +972,11 @@ async fn inbox_list( | ||
| 972 | 972 | live: String, |
| 973 | 973 | ) -> Result<impl View> { |
| 974 | 974 | let empty = groups.is_empty(); |
| 975 | + let empty_text = if all { | |
| 976 | + g::t(lang, K::NoNotificationsYet) | |
| 977 | + } else { | |
| 978 | + g::t(lang, K::NoUnreadNotifications) | |
| 979 | + }; | |
| 975 | 980 | let unread_class = if all { "" } else { "active" }; |
| 976 | 981 | let all_class = if all { "active" } else { "" }; |
| 977 | 982 | let unread_text = format!("{} ({unread_count})", g::t(lang, K::Unread)); |
| @@ -992,13 +997,10 @@ async fn inbox_list( | ||
| 992 | 997 | <a href="/review-requests">(crate::i18n::authoring::t(lang, crate::i18n::authoring::K::ReviewRequestsTab))</a> |
| 993 | 998 | </nav> |
| 994 | 999 | if empty { |
| 995 | - <p class="muted"> | |
| 996 | - if all { | |
| 997 | - (g::t(lang, K::NoNotificationsYet)) | |
| 998 | - } else { | |
| 999 | - (g::t(lang, K::NoUnreadNotifications)) | |
| 1000 | - } | |
| 1001 | - </p> | |
| 1000 | + empty_state(title: empty_text, | |
| 1001 | + if !all { | |
| 1002 | + <a class="button" href="/notifications?all=1">(g::t(lang, K::ViewAllNotifications))</a> | |
| 1003 | + }) | |
| 1002 | 1004 | } |
| 1003 | 1005 | for group in groups.into_iter() { |
| 1004 | 1006 | <section class="card notif-group"> |
crates/forge-web/src/pages/org_teams.rsmodified+16 -7
| @@ -24,7 +24,7 @@ use crate::pages::org_ctx::{ | ||
| 24 | 24 | }; |
| 25 | 25 | use crate::pages::passkeys; |
| 26 | 26 | use crate::state::AppState; |
| 27 | -use crate::views::{avatar_url, display_name, repo_href, shell}; | |
| 27 | +use crate::views::{avatar_url, display_name, empty_state, repo_href, shell}; | |
| 28 | 28 | |
| 29 | 29 | path_param!(org); |
| 30 | 30 | path_param!(team); |
| @@ -199,7 +199,10 @@ async fn teams_body( | ||
| 199 | 199 | <h2>(g::t(lang, K::Teams))</h2> |
| 200 | 200 | <p class="muted small">(g::t(lang, K::TeamsIntro))</p> |
| 201 | 201 | if rows.is_empty() { |
| 202 | - <p class="muted">(g::t(lang, K::NoTeamsYet))</p> | |
| 202 | + empty_state(title: g::t(lang, K::NoTeamsYet), | |
| 203 | + if owner { | |
| 204 | + <a class="button" href="#new-team">(g::t(lang, K::NewTeam))</a> | |
| 205 | + }) | |
| 203 | 206 | } else { |
| 204 | 207 | <ul class="item-list"> |
| 205 | 208 | for row in rows.iter() { |
| @@ -217,7 +220,7 @@ async fn teams_body( | ||
| 217 | 220 | } |
| 218 | 221 | </section> |
| 219 | 222 | if owner { |
| 220 | - <section class="card"> | |
| 223 | + <section class="card" id="new-team"> | |
| 221 | 224 | <h3>(g::t(lang, K::NewTeam))</h3> |
| 222 | 225 | <form method="post" action=(create_action.as_str()) class="stack"> |
| 223 | 226 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| @@ -347,7 +350,10 @@ async fn team_body( | ||
| 347 | 350 | <section class="card"> |
| 348 | 351 | <h3>(g::t(lang, K::Members))</h3> |
| 349 | 352 | if data.members.is_empty() { |
| 350 | - <p class="muted">(g::t(lang, K::NoTeamMembers))</p> | |
| 353 | + empty_state(title: g::t(lang, K::NoTeamMembers), | |
| 354 | + if owner { | |
| 355 | + <a class="button" href="#add-member">(g::t(lang, K::AddMember))</a> | |
| 356 | + }) | |
| 351 | 357 | } else { |
| 352 | 358 | <ul class="item-list"> |
| 353 | 359 | for member in data.members.iter() { |
| @@ -375,7 +381,7 @@ async fn team_body( | ||
| 375 | 381 | </ul> |
| 376 | 382 | } |
| 377 | 383 | if owner { |
| 378 | - <form method="post" action=(add_member_action.as_str()) class="team-form"> | |
| 384 | + <form method="post" action=(add_member_action.as_str()) class="team-form" id="add-member"> | |
| 379 | 385 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 380 | 386 | <input type="text" name="username" placeholder=(g::t(lang, K::Username)) aria-label=(g::t(lang, K::Username)) autocomplete="off" spellcheck="false" required=(true)> |
| 381 | 387 | <button type="submit">(g::t(lang, K::AddToTeam))</button> |
| @@ -385,7 +391,10 @@ async fn team_body( | ||
| 385 | 391 | <section class="card"> |
| 386 | 392 | <h3>(g::t(lang, K::Repositories))</h3> |
| 387 | 393 | if data.repos.is_empty() { |
| 388 | - <p class="muted">(g::t(lang, K::NoTeamRepos))</p> | |
| 394 | + empty_state(title: g::t(lang, K::NoTeamRepos), | |
| 395 | + if owner && has_choices { | |
| 396 | + <a class="button" href="#link-repository">(g::t(lang, K::LinkRepository))</a> | |
| 397 | + }) | |
| 389 | 398 | } else { |
| 390 | 399 | <ul class="item-list"> |
| 391 | 400 | for repo in data.repos.iter() { |
| @@ -410,7 +419,7 @@ async fn team_body( | ||
| 410 | 419 | </ul> |
| 411 | 420 | } |
| 412 | 421 | if owner && has_choices { |
| 413 | - <form method="post" action=(add_repo_action.as_str()) class="team-form"> | |
| 422 | + <form method="post" action=(add_repo_action.as_str()) class="team-form" id="link-repository"> | |
| 414 | 423 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 415 | 424 | <select name="repo_id" aria-label=(g::t(lang, K::Repository))> |
| 416 | 425 | for choice in data.choices.iter() { |
crates/forge-web/src/pages/packages.rsmodified+5 -3
| @@ -26,7 +26,7 @@ use crate::pages::ci_runs::{changed_event, events_response}; | ||
| 26 | 26 | use crate::pages::packages_oci::{self, oci_package_view}; |
| 27 | 27 | use crate::render::markdown::render_markdown; |
| 28 | 28 | use crate::state::AppState; |
| 29 | -use crate::views::{enc, shell}; | |
| 29 | +use crate::views::{empty_state, enc, rel_time, shell}; | |
| 30 | 30 | |
| 31 | 31 | path_param!(owner); |
| 32 | 32 | path_param!(name); |
| @@ -163,7 +163,7 @@ async fn package_page(cx: &Cx) -> Result<impl View> { | ||
| 163 | 163 | .map(|v| { |
| 164 | 164 | ( |
| 165 | 165 | v.version.clone(), |
| 166 | - v.created_at.get(..10).unwrap_or(&v.created_at).to_owned(), | |
| 166 | + v.created_at.clone(), | |
| 167 | 167 | v.yanked, |
| 168 | 168 | v.checksum.clone(), |
| 169 | 169 | ) |
| @@ -356,7 +356,7 @@ async fn package_view(page: PackagePage) -> Result<impl View> { | ||
| 356 | 356 | <li> |
| 357 | 357 | <span class="repo-name">(version.as_str())</span> |
| 358 | 358 | " " |
| 359 | - <span class="muted small">(date.as_str())</span> | |
| 359 | + <span class="muted small">rel_time(lang: lang, stamp: date.as_str())</span> | |
| 360 | 360 | if *yanked { |
| 361 | 361 | " " |
| 362 | 362 | <span class="badge">(pk::t(lang, K::VersionYanked))</span> |
| @@ -366,6 +366,8 @@ async fn package_view(page: PackagePage) -> Result<impl View> { | ||
| 366 | 366 | </li> |
| 367 | 367 | } |
| 368 | 368 | </ul> |
| 369 | + } else { | |
| 370 | + empty_state(title: pk::t(lang, K::NoVersions)) | |
| 369 | 371 | } |
| 370 | 372 | } else { |
| 371 | 373 | if has_readme { |
crates/forge-web/src/pages/packages_oci.rsmodified+4 -4
| @@ -11,7 +11,7 @@ use crate::i18n::Lang; | ||
| 11 | 11 | use crate::i18n::packages::{self as pk, K}; |
| 12 | 12 | use crate::package_ops; |
| 13 | 13 | use crate::state::AppState; |
| 14 | -use crate::views::{enc, human_size}; | |
| 14 | +use crate::views::{empty_state, enc, human_size, rel_time}; | |
| 15 | 15 | |
| 16 | 16 | /// What the container package page shows, prepared by the handler. |
| 17 | 17 | pub struct OciPage { |
| @@ -105,7 +105,7 @@ pub async fn oci_package_view(page: OciPage) -> Result<impl View> { | ||
| 105 | 105 | short_digest(&t.digest), |
| 106 | 106 | t.digest.clone(), |
| 107 | 107 | human_size(lang, t.size), |
| 108 | - t.created_at.get(..10).unwrap_or(&t.created_at).to_owned(), | |
| 108 | + t.created_at.clone(), | |
| 109 | 109 | ) |
| 110 | 110 | }) |
| 111 | 111 | .collect(); |
| @@ -163,7 +163,7 @@ pub async fn oci_package_view(page: OciPage) -> Result<impl View> { | ||
| 163 | 163 | <td><code>(tag.as_str())</code></td> |
| 164 | 164 | <td><code class="small" title=(full.as_str())>(short.as_str())</code></td> |
| 165 | 165 | <td class="muted small">(size.as_str())</td> |
| 166 | - <td class="muted small">(created.as_str())</td> | |
| 166 | + <td class="muted small">rel_time(lang: lang, stamp: created.as_str())</td> | |
| 167 | 167 | if can_delete { |
| 168 | 168 | <td> |
| 169 | 169 | <details class="confirm-inline"> |
| @@ -187,7 +187,7 @@ pub async fn oci_package_view(page: OciPage) -> Result<impl View> { | ||
| 187 | 187 | </table> |
| 188 | 188 | </div> |
| 189 | 189 | } else { |
| 190 | - <p class="muted">(pk::t(lang, K::NoTags))</p> | |
| 190 | + empty_state(title: pk::t(lang, K::NoTags)) | |
| 191 | 191 | } |
| 192 | 192 | </section> |
| 193 | 193 | </article> |
crates/forge-web/src/pages/palette.rsadded+74 -0
| @@ -0,0 +1,74 @@ | ||
| 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 | |
| 3 | +//! and, for admins, the admin pages). The palette itself, its filtering and keys live in | |
| 4 | +//! `assets/nav.js`. | |
| 5 | + | |
| 6 | +use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS}; | |
| 7 | +use serde_json::{Value, json}; | |
| 8 | +use topcoat::Result; | |
| 9 | +use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::router::response::Response; | |
| 11 | +use topcoat::router::{Body, HeaderValue, StatusCode, route}; | |
| 12 | + | |
| 13 | +use crate::auth::current_user; | |
| 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}; | |
| 17 | +use crate::state::AppState; | |
| 18 | +use crate::views::{admin_items, repo_href, settings_items, user_href}; | |
| 19 | + | |
| 20 | +/// Repos listed at most. The palette filters in the browser, so a longer list would only cost time. | |
| 21 | +pub const MAX_REPOS: u64 = 500; | |
| 22 | + | |
| 23 | +/// One destination: its label, its path and what it is (`repo`, `org` or `page`). | |
| 24 | +fn destination(label: &str, href: &str, kind: &str) -> Value { | |
| 25 | + json!({ "label": label, "href": href, "kind": kind }) | |
| 26 | +} | |
| 27 | + | |
| 28 | +/// `{"items": [{"label", "href", "kind"}, ...]}` for the signed-in viewer. Anonymous visitors get | |
| 29 | +/// 401, as the other signed-in-only JSON routes do. | |
| 30 | +#[route(GET "/-/palette")] | |
| 31 | +async fn palette(cx: &Cx) -> Result<Response> { | |
| 32 | + let Some((user, _)) = current_user(cx).await? else { | |
| 33 | + let mut res = Response::new(Body::empty()); | |
| 34 | + *res.status_mut() = StatusCode::UNAUTHORIZED; | |
| 35 | + return Ok(res); | |
| 36 | + }; | |
| 37 | + let state = app_context::<AppState>(cx); | |
| 38 | + let lang = i18n::lang(cx, Some(&user)); | |
| 39 | + | |
| 40 | + let mut items = Vec::new(); | |
| 41 | + for repo in state.store.list_viewer_repos(&user, MAX_REPOS).await? { | |
| 42 | + let label = format!("{}/{}", repo.owner_name, repo.name); | |
| 43 | + let href = repo_href(&repo.owner_name, &repo.name, "", ""); | |
| 44 | + items.push(destination(&label, &href, "repo")); | |
| 45 | + } | |
| 46 | + for (org, _) in state.store.orgs_for_user(&user.id).await? { | |
| 47 | + items.push(destination(&org.username, &user_href(&org.username), "org")); | |
| 48 | + } | |
| 49 | + | |
| 50 | + items.push(destination(o::t(lang, OK::Dashboard), "/", "page")); | |
| 51 | + items.push(destination(t(lang, Key::Explore), "/explore", "page")); | |
| 52 | + items.push(destination(t(lang, Key::Notifications), "/notifications", "page")); | |
| 53 | + items.push(destination(cm::t(lang, CK::Snippets), "/snippets", "page")); | |
| 54 | + items.push(destination(t(lang, Key::NewRepository), "/new", "page")); | |
| 55 | + for item in settings_items(lang) { | |
| 56 | + items.push(destination(item.label, &item.href, "page")); | |
| 57 | + } | |
| 58 | + if user.is_admin { | |
| 59 | + for item in admin_items(lang) { | |
| 60 | + items.push(destination(item.label, &item.href, "page")); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + let body = json!({ "items": items }); | |
| 65 | + let mut response = Response::new(Body::from(body.to_string().into_bytes())); | |
| 66 | + let headers = response.headers_mut(); | |
| 67 | + headers.insert( | |
| 68 | + CONTENT_TYPE, | |
| 69 | + HeaderValue::from_static("application/json; charset=utf-8"), | |
| 70 | + ); | |
| 71 | + headers.insert(CACHE_CONTROL, HeaderValue::from_static("private, no-cache")); | |
| 72 | + headers.insert(X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff")); | |
| 73 | + Ok(response) | |
| 74 | +} |
crates/forge-web/src/pages/profile.rsmodified+4 -4
| @@ -32,7 +32,7 @@ use crate::state::AppState; | ||
| 32 | 32 | use crate::views::repo_list::{ |
| 33 | 33 | PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips, |
| 34 | 34 | }; |
| 35 | -use crate::views::{avatar_url, enc, now_unix, repo_href, shell}; | |
| 35 | +use crate::views::{avatar_url, empty_state, enc, now_unix, repo_href, shell}; | |
| 36 | 36 | |
| 37 | 37 | path_param!(username); |
| 38 | 38 | |
| @@ -539,7 +539,7 @@ async fn profile_card( | ||
| 539 | 539 | } |
| 540 | 540 | </ul> |
| 541 | 541 | } else { |
| 542 | - <p class="muted">(g::t(lang, K::NoVisibleRepos))</p> | |
| 542 | + empty_state(title: g::t(lang, K::NoVisibleRepos)) | |
| 543 | 543 | } |
| 544 | 544 | </section> |
| 545 | 545 | if let Some(summary) = org { |
| @@ -547,7 +547,7 @@ async fn profile_card( | ||
| 547 | 547 | <h2>(g::t(lang, K::Members))</h2> |
| 548 | 548 | <p class="muted small">(g::members_and_teams(lang, summary.members.len(), summary.teams))</p> |
| 549 | 549 | if summary.members.is_empty() { |
| 550 | - <p class="muted">(g::t(lang, K::NoMembers))</p> | |
| 550 | + empty_state(title: g::t(lang, K::NoMembers)) | |
| 551 | 551 | } else { |
| 552 | 552 | <ul class="item-list"> |
| 553 | 553 | for name in summary.members.iter() { |
| @@ -572,7 +572,7 @@ async fn profile_card( | ||
| 572 | 572 | if has_rows { |
| 573 | 573 | repo_rows(rows: rows, lang: lang) |
| 574 | 574 | } else { |
| 575 | - <p class="muted">(empty)</p> | |
| 575 | + empty_state(title: empty) | |
| 576 | 576 | } |
| 577 | 577 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) |
| 578 | 578 | </section> |
crates/forge-web/src/pages/profile_pins.rsmodified+3 -2
| @@ -20,7 +20,7 @@ use crate::live::{Topic, stream_changes}; | ||
| 20 | 20 | use crate::pages::issue_meta::{form_all, form_field, form_pairs}; |
| 21 | 21 | use crate::pages::org_ctx::{load_org, require_form_csrf, require_owner}; |
| 22 | 22 | use crate::state::AppState; |
| 23 | -use crate::views::shell; | |
| 23 | +use crate::views::{empty_state, shell}; | |
| 24 | 24 | |
| 25 | 25 | path_param!(org); |
| 26 | 26 | |
| @@ -117,7 +117,8 @@ async fn pins_body( | ||
| 117 | 117 | </div> |
| 118 | 118 | </form> |
| 119 | 119 | } else { |
| 120 | - <p class="muted">(empty)</p> | |
| 120 | + empty_state(title: empty, | |
| 121 | + <a class="button" href="/new">(g::t(lang, K::NewRepository))</a>) | |
| 121 | 122 | } |
| 122 | 123 | </section> |
| 123 | 124 | }) |
crates/forge-web/src/pages/pulls_list.rsmodified+16 -2
| @@ -22,7 +22,9 @@ use crate::pages::issues_list::{ | ||
| 22 | 22 | use crate::pages::repo::repo_head; |
| 23 | 23 | use crate::pages::repo_ctx::load_repo; |
| 24 | 24 | use crate::state::AppState; |
| 25 | -use crate::views::{avatar_url, iso_time, now_unix, relative_time, repo_href, shell, user_link}; | |
| 25 | +use crate::views::{ | |
| 26 | + avatar_url, empty_state, iso_time, now_unix, relative_time, repo_href, shell, user_link, | |
| 27 | +}; | |
| 26 | 28 | |
| 27 | 29 | path_param!(owner); |
| 28 | 30 | path_param!(repo); |
| @@ -300,7 +302,19 @@ async fn pulls_list_page(cx: &Cx) -> Result<impl View> { | ||
| 300 | 302 | <p class="muted small">(g::t(lang, K::FiltersApplied)) <a href=(clear_href.as_str())>(g::t(lang, K::ClearFilters))</a></p> |
| 301 | 303 | } |
| 302 | 304 | if rows.is_empty() { |
| 303 | - <p class="muted">(empty_text)</p> | |
| 305 | + if has_filters { | |
| 306 | + empty_state(title: empty_text, | |
| 307 | + <a class="button" href=(clear_href.as_str())>(g::t(lang, K::ClearFilters))</a> | |
| 308 | + ) | |
| 309 | + } else if open_count + closed_count == 0 { | |
| 310 | + empty_state(title: empty_text, | |
| 311 | + if can_create { | |
| 312 | + <a class="button primary" href=(compare_href.as_str())>(g::t(lang, K::NewPullRequest))</a> | |
| 313 | + } | |
| 314 | + ) | |
| 315 | + } else { | |
| 316 | + empty_state(title: empty_text) | |
| 317 | + } | |
| 304 | 318 | } else { |
| 305 | 319 | <ul class="issue-list"> |
| 306 | 320 | for row in rows.iter() { |
crates/forge-web/src/pages/refs.rsmodified+2 -2
| @@ -18,7 +18,7 @@ use crate::pages::ref_live; | ||
| 18 | 18 | use crate::pages::repo::repo_head; |
| 19 | 19 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| 20 | 20 | use crate::pages::tree::{LastCommit, last_commit_view}; |
| 21 | -use crate::views::{RefLink, now_unix, repo_href, shell}; | |
| 21 | +use crate::views::{RefLink, empty_state, now_unix, repo_href, shell}; | |
| 22 | 22 | |
| 23 | 23 | path_param!(owner); |
| 24 | 24 | path_param!(repo); |
| @@ -108,7 +108,7 @@ async fn refs_table(rows: Vec<RefRow>, kind_label: &str, lang: Lang) -> Result<i | ||
| 108 | 108 | let empty = rows.is_empty(); |
| 109 | 109 | Ok(view! { |
| 110 | 110 | if empty { |
| 111 | - <p class="muted">(g::t(lang, K::NothingHere))</p> | |
| 111 | + empty_state(title: g::t(lang, K::NothingHere)) | |
| 112 | 112 | } else { |
| 113 | 113 | <div class="table-wrap"> |
| 114 | 114 | <table class="table refs-table"> |
crates/forge-web/src/pages/releases.rsmodified+42 -30
| @@ -38,11 +38,11 @@ use crate::pages::refs::load_refs; | ||
| 38 | 38 | use crate::pages::releases_live; |
| 39 | 39 | use crate::pages::repo::repo_head; |
| 40 | 40 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| 41 | -use crate::pages::repo_mirrors::stamp_in_tz; | |
| 41 | +use crate::pages::issue_parts::When; | |
| 42 | 42 | use crate::release_ops::{self, CreateRelease, EditRelease, ReleaseError}; |
| 43 | 43 | use crate::render::markdown::render_markdown; |
| 44 | 44 | use crate::state::AppState; |
| 45 | -use crate::views::{alert, enc, shell, user_link}; | |
| 45 | +use crate::views::{alert, empty_state, enc, now_unix, shell, user_link}; | |
| 46 | 46 | |
| 47 | 47 | path_param!(owner); |
| 48 | 48 | path_param!(repo); |
| @@ -179,7 +179,7 @@ pub struct ReleaseCard { | ||
| 179 | 179 | pub href: String, |
| 180 | 180 | pub edit_href: String, |
| 181 | 181 | pub body: String, |
| 182 | - pub when: String, | |
| 182 | + pub(crate) when: When, | |
| 183 | 183 | pub author: String, |
| 184 | 184 | pub draft: bool, |
| 185 | 185 | pub prerelease: bool, |
| @@ -192,7 +192,7 @@ pub struct LatestRelease { | ||
| 192 | 192 | pub title: String, |
| 193 | 193 | pub tag: String, |
| 194 | 194 | pub href: String, |
| 195 | - pub when: String, | |
| 195 | + pub(crate) when: When, | |
| 196 | 196 | pub assets: Vec<AssetLink>, |
| 197 | 197 | } |
| 198 | 198 | |
| @@ -213,7 +213,7 @@ fn card_of( | ||
| 213 | 213 | href: tag_href(&title, &release.tag), |
| 214 | 214 | edit_href: release_edit_href(&title, &release.id), |
| 215 | 215 | body: release.body.clone(), |
| 216 | - when: stamp_in_tz(when, ctx.viewer_tz()), | |
| 216 | + when: When::new(ctx.lang, when, ctx.viewer_tz(), now_unix()), | |
| 217 | 217 | author: release.author_name.clone(), |
| 218 | 218 | draft: release.draft, |
| 219 | 219 | prerelease: release.prerelease, |
| @@ -243,7 +243,7 @@ pub async fn latest_release_for_home( | ||
| 243 | 243 | title: release.title.clone(), |
| 244 | 244 | tag: release.tag.clone(), |
| 245 | 245 | href: tag_href(&title, &release.tag), |
| 246 | - when: stamp_in_tz(when, ctx.viewer_tz()), | |
| 246 | + when: When::new(ctx.lang, when, ctx.viewer_tz(), now_unix()), | |
| 247 | 247 | assets: assets |
| 248 | 248 | .iter() |
| 249 | 249 | .map(|asset| asset_link(&title, &release.tag, asset)) |
| @@ -475,7 +475,7 @@ pub async fn latest_card(release: LatestRelease, lang: Lang) -> Result<impl View | ||
| 475 | 475 | <a href=(release.href.as_str())>(release.title.as_str())</a> |
| 476 | 476 | " \u{b7} " <code>(release.tag.as_str())</code> |
| 477 | 477 | </p> |
| 478 | - <p class="muted small">(release.when.as_str())</p> | |
| 478 | + <p class="muted small"><time data-rel="true" datetime=(release.when.iso.as_str()) title=(release.when.absolute.as_str())>(release.when.relative.as_str())</time></p> | |
| 479 | 479 | if !release.assets.is_empty() { |
| 480 | 480 | <ul class="release-asset-list"> |
| 481 | 481 | for asset in release.assets.iter() { |
| @@ -509,12 +509,16 @@ async fn list_body( | ||
| 509 | 509 | <section class="card" data-live=(live.as_str())> |
| 510 | 510 | <div class="release-list-head"> |
| 511 | 511 | <h2>(g::t(lang, K::Releases))</h2> |
| 512 | - if let Some(href) = new_href { | |
| 512 | + if let Some(href) = &new_href { | |
| 513 | 513 | <a class="button" href=(href.as_str())>(g::t(lang, K::NewRelease))</a> |
| 514 | 514 | } |
| 515 | 515 | </div> |
| 516 | 516 | if cards.is_empty() { |
| 517 | - <p class="muted">(g::t(lang, K::NoReleasesYet))</p> | |
| 517 | + empty_state(title: g::t(lang, K::NoReleasesYet), | |
| 518 | + if let Some(href) = &new_href { | |
| 519 | + <a class="button primary" href=(href.as_str())>(g::t(lang, K::NewRelease))</a> | |
| 520 | + } | |
| 521 | + ) | |
| 518 | 522 | } |
| 519 | 523 | for card in cards.iter() { |
| 520 | 524 | <article class="release-card"> |
| @@ -532,7 +536,7 @@ async fn list_body( | ||
| 532 | 536 | </h3> |
| 533 | 537 | <p class="muted small"> |
| 534 | 538 | <code>(card.tag.as_str())</code> |
| 535 | - " \u{b7} " (card.when.as_str()) | |
| 539 | + " \u{b7} " <time data-rel="true" datetime=(card.when.iso.as_str()) title=(card.when.absolute.as_str())>(card.when.relative.as_str())</time> | |
| 536 | 540 | if !card.author.is_empty() { |
| 537 | 541 | " \u{b7} " user_link(shown: card.author.as_str(), login: card.author.as_str()) |
| 538 | 542 | } |
| @@ -747,7 +751,7 @@ async fn release_tag_page(cx: &Cx) -> Result<impl View> { | ||
| 747 | 751 | .published_at |
| 748 | 752 | .as_deref() |
| 749 | 753 | .unwrap_or(&release.created_at); |
| 750 | - let when = stamp_in_tz(when, ctx.viewer_tz()); | |
| 754 | + let when = When::new(ctx.lang, when, ctx.viewer_tz(), now_unix()); | |
| 751 | 755 | let body_html = render_markdown(&release.body, None); |
| 752 | 756 | let page_title = format!("{title} \u{b7} {}", release.title); |
| 753 | 757 | let archive_tar = format!("/{title}/archive/{}.tar.gz", enc(&release.tag)); |
| @@ -800,7 +804,7 @@ async fn release_tag_page(cx: &Cx) -> Result<impl View> { | ||
| 800 | 804 | </h2> |
| 801 | 805 | <p class="muted small"> |
| 802 | 806 | <code>(card.tag.as_str())</code> |
| 803 | - " \u{b7} " (card.when.as_str()) | |
| 807 | + " \u{b7} " <time data-rel="true" datetime=(card.when.iso.as_str()) title=(card.when.absolute.as_str())>(card.when.relative.as_str())</time> | |
| 804 | 808 | if !card.author.is_empty() { |
| 805 | 809 | " \u{b7} " user_link(shown: card.author.as_str(), login: card.author.as_str()) |
| 806 | 810 | } |
| @@ -830,14 +834,18 @@ async fn release_tag_page(cx: &Cx) -> Result<impl View> { | ||
| 830 | 834 | if writer { |
| 831 | 835 | <div class="release-actions"> |
| 832 | 836 | <a href=(edit_href.as_str())>(g::t(lang, K::Edit))</a> |
| 833 | - <form method="post" action=(delete_href.as_str()) class="inline-form"> | |
| 834 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 835 | - <label class="inline"> | |
| 836 | - <input type="checkbox" name="confirm" value="on"> | |
| 837 | - <span>(g::t(lang, K::Confirm))</span> | |
| 838 | - </label> | |
| 839 | - <button type="submit">(g::t(lang, K::DeleteRelease))</button> | |
| 840 | - </form> | |
| 837 | + <details class="confirm-inline"> | |
| 838 | + <summary class="button danger">(g::t(lang, K::DeleteRelease))</summary> | |
| 839 | + <div class="confirm-pop"> | |
| 840 | + <p>(g::t(lang, K::DeleteReleaseHelp))</p> | |
| 841 | + <form method="post" action=(delete_href.as_str())> | |
| 842 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 843 | + <input type="hidden" name="confirm" value="on"> | |
| 844 | + <button type="submit" class="danger">(g::t(lang, K::YesDeleteRelease))</button> | |
| 845 | + <button type="button" data-close-details="">(g::t(lang, K::Cancel))</button> | |
| 846 | + </form> | |
| 847 | + </div> | |
| 848 | + </details> | |
| 841 | 849 | </div> |
| 842 | 850 | } |
| 843 | 851 | </section> |
| @@ -897,16 +905,20 @@ async fn edit_body( | ||
| 897 | 905 | <section class="card"> |
| 898 | 906 | <h2>(g::t(lang, K::DeleteRelease))</h2> |
| 899 | 907 | <p class="muted small">(g::t(lang, K::DeleteReleaseHelp))</p> |
| 900 | - <form method="post" action=(delete_href.as_str()) class="stack"> | |
| 901 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 902 | - <label class="inline"> | |
| 903 | - <input type="checkbox" name="confirm" value="on"> | |
| 904 | - <span>(g::t(lang, K::YesDeleteRelease))</span> | |
| 905 | - </label> | |
| 906 | - <div> | |
| 907 | - <button type="submit">(g::t(lang, K::DeleteRelease))</button> | |
| 908 | - </div> | |
| 909 | - </form> | |
| 908 | + <div> | |
| 909 | + <details class="confirm-inline"> | |
| 910 | + <summary class="button danger">(g::t(lang, K::DeleteRelease))</summary> | |
| 911 | + <div class="confirm-pop"> | |
| 912 | + <p>(g::t(lang, K::DeleteReleaseHelp))</p> | |
| 913 | + <form method="post" action=(delete_href.as_str())> | |
| 914 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 915 | + <input type="hidden" name="confirm" value="on"> | |
| 916 | + <button type="submit" class="danger">(g::t(lang, K::YesDeleteRelease))</button> | |
| 917 | + <button type="button" data-close-details="">(g::t(lang, K::Cancel))</button> | |
| 918 | + </form> | |
| 919 | + </div> | |
| 920 | + </details> | |
| 921 | + </div> | |
| 910 | 922 | </section> |
| 911 | 923 | }) |
| 912 | 924 | } |
crates/forge-web/src/pages/repo.rsmodified+20 -7
| @@ -33,7 +33,7 @@ use crate::pages::tree::{ | ||
| 33 | 33 | entry_rows, last_commits, latest_bar, load_readme, read_dir, readme_card, tree_table, |
| 34 | 34 | }; |
| 35 | 35 | use crate::state::AppState; |
| 36 | -use crate::views::{now_unix, ref_selector, relative_time, repo_href, repo_tabs, shell, user_link}; | |
| 36 | +use crate::views::{now_unix, ref_selector, rel_time, relative_time, repo_href, repo_tabs, shell, user_link}; | |
| 37 | 37 | |
| 38 | 38 | path_param!(owner); |
| 39 | 39 | path_param!(repo); |
| @@ -136,13 +136,20 @@ pub async fn repo_head(head: RepoHead) -> Result<impl View> { | ||
| 136 | 136 | let fork_count = g::forks_count(lang, forks); |
| 137 | 137 | let search_action = repo_href(&owner, &name, "search", ""); |
| 138 | 138 | let mirror_line = mirror.as_ref().map(|source| source.url.clone()); |
| 139 | - let mirror_status = match mirror { | |
| 139 | + // A stamp is shown as a live relative time between the two words; without one, the status is plain text. | |
| 140 | + let (mirror_before, mirror_after, mirror_at, mirror_status) = match mirror { | |
| 140 | 141 | Some(source) => match (source.last_sync, source.last_ok) { |
| 141 | - (Some(at), Some(true)) => g::mirror_synced(lang, &at), | |
| 142 | - (Some(at), _) => g::mirror_sync_failed(lang, &at), | |
| 143 | - (None, _) => g::t(lang, K::NotSyncedYet).to_owned(), | |
| 142 | + (Some(at), Some(true)) => { | |
| 143 | + let (before, after) = g::mirror_synced(lang); | |
| 144 | + (before, after, Some(at), String::new()) | |
| 145 | + } | |
| 146 | + (Some(at), _) => { | |
| 147 | + let (before, after) = g::mirror_sync_failed(lang); | |
| 148 | + (before, after, Some(at), String::new()) | |
| 149 | + } | |
| 150 | + (None, _) => ("", "", None, g::t(lang, K::NotSyncedYet).to_owned()), | |
| 144 | 151 | }, |
| 145 | - None => String::new(), | |
| 152 | + None => ("", "", None, String::new()), | |
| 146 | 153 | }; |
| 147 | 154 | let live_attr = (!live.is_empty()).then(|| live.clone()); |
| 148 | 155 | Ok(view! { |
| @@ -156,7 +163,13 @@ pub async fn repo_head(head: RepoHead) -> Result<impl View> { | ||
| 156 | 163 | <p class="muted small">(g::t(lang, K::ForkedFrom)) <a href=(href.as_str())>(label.as_str())</a></p> |
| 157 | 164 | } |
| 158 | 165 | if let Some(source) = mirror_line { |
| 159 | - <p class="muted small mirror-line">(g::t(lang, K::MirrorOf)) <code>(source.as_str())</code> ", " (mirror_status.as_str())</p> | |
| 166 | + <p class="muted small mirror-line">(g::t(lang, K::MirrorOf)) <code>(source.as_str())</code> ", " | |
| 167 | + if let Some(at) = mirror_at.as_deref() { | |
| 168 | + (mirror_before) rel_time(lang: lang, stamp: at) (mirror_after) | |
| 169 | + } else { | |
| 170 | + (mirror_status.as_str()) | |
| 171 | + } | |
| 172 | + </p> | |
| 160 | 173 | } |
| 161 | 174 | </div> |
| 162 | 175 | <div class="header-actions"> |
crates/forge-web/src/pages/repo_collaborators.rsmodified+4 -3
| @@ -31,7 +31,7 @@ use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | ||
| 31 | 31 | use crate::pages::repo_settings::settings_nav_for; |
| 32 | 32 | use crate::pages::repo_settings_live::settings_head; |
| 33 | 33 | use crate::state::AppState; |
| 34 | -use crate::views::{alert, avatar_url, display_name, shell}; | |
| 34 | +use crate::views::{alert, avatar_url, display_name, empty_state, shell}; | |
| 35 | 35 | |
| 36 | 36 | path_param!(owner); |
| 37 | 37 | path_param!(repo); |
| @@ -183,7 +183,8 @@ async fn collaborators_table( | ||
| 183 | 183 | ) -> Result<impl View> { |
| 184 | 184 | Ok(view! { |
| 185 | 185 | if rows.is_empty() { |
| 186 | - <p class="muted">(g::t(lang, K::NoCollaborators))</p> | |
| 186 | + empty_state(title: g::t(lang, K::NoCollaborators), | |
| 187 | + <a class="button" href="#add-collaborator">(g::t(lang, K::AddCollaboratorHeading))</a>) | |
| 187 | 188 | } else { |
| 188 | 189 | <div class="table-wrap"> |
| 189 | 190 | <table class="table collaborators members-table"> |
| @@ -248,7 +249,7 @@ async fn collaborators_table( | ||
| 248 | 249 | async fn add_form(lang: Lang, add_action: String, csrf: String) -> Result<impl View> { |
| 249 | 250 | Ok(view! { |
| 250 | 251 | <h3>(g::t(lang, K::AddCollaboratorHeading))</h3> |
| 251 | - <form method="post" action=(add_action.as_str()) class="stack"> | |
| 252 | + <form method="post" action=(add_action.as_str()) class="stack" id="add-collaborator"> | |
| 252 | 253 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 253 | 254 | <label> |
| 254 | 255 | <span>(g::t(lang, K::Username))</span> |
crates/forge-web/src/pages/repo_ctx.rsmodified+28 -6
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | use std::path::PathBuf; |
| 7 | 7 | |
| 8 | 8 | use forge_core::authz::{Action, authorize}; |
| 9 | -use forge_core::{Repo, Role, Session, User, Visibility, WatchLevel}; | |
| 9 | +use forge_core::{Repo, Role, Session, Store, User, Visibility, WatchLevel}; | |
| 10 | 10 | use forge_git::repo::repo_path; |
| 11 | 11 | use http::{HeaderValue, header::LOCATION}; |
| 12 | 12 | use topcoat::Result; |
| @@ -18,7 +18,7 @@ use topcoat::router::{Body, Layer, LayerFuture, Next, Path, StatusCode}; | ||
| 18 | 18 | |
| 19 | 19 | use crate::auth::current_user; |
| 20 | 20 | use crate::i18n::{self, Lang}; |
| 21 | -use crate::pages::repo_mirrors::{redacted_url, stamp_in_tz}; | |
| 21 | +use crate::pages::repo_mirrors::redacted_url; | |
| 22 | 22 | use crate::state::AppState; |
| 23 | 23 | |
| 24 | 24 | pub struct RepoCtx { |
| @@ -233,10 +233,7 @@ impl RepoCtx { | ||
| 233 | 233 | .await? |
| 234 | 234 | .map(|mirror| MirrorSource { |
| 235 | 235 | url: redacted_url(&mirror.url), |
| 236 | - last_sync: mirror | |
| 237 | - .last_sync_at | |
| 238 | - .as_deref() | |
| 239 | - .map(|stamp| stamp_in_tz(stamp, self.viewer_tz())), | |
| 236 | + last_sync: mirror.last_sync_at.clone(), | |
| 240 | 237 | last_ok: mirror.last_ok, |
| 241 | 238 | }); |
| 242 | 239 | Ok(RepoHead { |
| @@ -322,6 +319,31 @@ pub async fn load_repo(cx: &Cx, owner: &str, name: &str) -> Result<RepoCtx> { | ||
| 322 | 319 | }) |
| 323 | 320 | } |
| 324 | 321 | |
| 322 | +/// Whether `viewer` may still read the repo, checked against the store now. A live stream calls it | |
| 323 | +/// after each wake, so a repo made private or a collaborator removed since the stream opened ends | |
| 324 | +/// it. A missing repo or a failed read counts as not readable. | |
| 325 | +pub async fn still_readable(store: &Store, viewer: Option<&User>, repo_id: &str) -> bool { | |
| 326 | + let Ok(Some(repo)) = store.repo_by_id(repo_id).await else { | |
| 327 | + return false; | |
| 328 | + }; | |
| 329 | + let (role, org_role) = match viewer { | |
| 330 | + Some(user) => { | |
| 331 | + let Ok(role) = store.collaborator_role(&repo.id, &user.id).await else { | |
| 332 | + return false; | |
| 333 | + }; | |
| 334 | + let Ok(org_role) = store | |
| 335 | + .org_repo_role(&repo.owner_id, &user.id, &repo.id) | |
| 336 | + .await | |
| 337 | + else { | |
| 338 | + return false; | |
| 339 | + }; | |
| 340 | + (role, org_role) | |
| 341 | + } | |
| 342 | + None => (None, None), | |
| 343 | + }; | |
| 344 | + authorize(viewer, &repo, role, org_role, Action::Read).is_ok() | |
| 345 | +} | |
| 346 | + | |
| 325 | 347 | /// The URL to send a past owner/name to: the same path and query with the owner and name segments |
| 326 | 348 | /// replaced. `None` unless the redirect target exists and the viewer may read it, so a hidden repo |
| 327 | 349 | /// answers exactly like a missing one. |
crates/forge-web/src/pages/repo_mirrors.rsmodified+28 -25
| @@ -36,7 +36,7 @@ use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | ||
| 36 | 36 | use crate::pages::repo_settings::settings_nav_for; |
| 37 | 37 | use crate::pages::repo_settings_live::settings_head; |
| 38 | 38 | use crate::state::AppState; |
| 39 | -use crate::views::{alert, enc, now_unix, relative_time, shell, user_facing_message}; | |
| 39 | +use crate::views::{alert, empty_state, enc, now_unix, rel_time_or_never, relative_time, shell, user_facing_message}; | |
| 40 | 40 | use crate::webhooks::client::{WebhookPolicy, validate_url}; |
| 41 | 41 | |
| 42 | 42 | path_param!(owner); |
| @@ -504,13 +504,20 @@ async fn mirrors_list_body( | ||
| 504 | 504 | lang: Lang, |
| 505 | 505 | ) -> Result<impl View> { |
| 506 | 506 | let add_action = mirrors_href(&title); |
| 507 | + let can_pull = pull_form.is_some(); | |
| 507 | 508 | Ok(view! { |
| 508 | 509 | frame_top(head: head, title: title.clone(), notice: notice, archived: archived, lang: lang) |
| 509 | 510 | <section class="card"> |
| 510 | 511 | <h2>(g::t(lang, K::Mirrors))</h2> |
| 511 | 512 | <p class="muted small">(g::t(lang, K::MirrorsIntro))</p> |
| 512 | 513 | if rows.is_empty() { |
| 513 | - <p class="muted">(g::t(lang, K::NoMirrors))</p> | |
| 514 | + empty_state(title: g::t(lang, K::NoMirrors), | |
| 515 | + if !archived { | |
| 516 | + if can_pull { | |
| 517 | + <a class="button" href="#add-pull-mirror">(g::t(lang, K::AddPullMirror))</a> | |
| 518 | + } | |
| 519 | + <a class="button" href="#add-push-mirror">(g::t(lang, K::AddPushMirror))</a> | |
| 520 | + }) | |
| 514 | 521 | } else { |
| 515 | 522 | <ul class="runner-list mirror-list"> |
| 516 | 523 | for row in rows.iter() { |
| @@ -552,7 +559,7 @@ async fn mirrors_list_body( | ||
| 552 | 559 | </section> |
| 553 | 560 | if !archived { |
| 554 | 561 | if let Some(pull) = pull_form { |
| 555 | - <section class="card"> | |
| 562 | + <section class="card" id="add-pull-mirror"> | |
| 556 | 563 | <h2>(g::t(lang, K::AddPullMirror))</h2> |
| 557 | 564 | <p class="muted small">(g::t(lang, K::AddPullIntro))</p> |
| 558 | 565 | mirror_form(action: add_action.clone(), csrf: csrf.clone(), pull: true, current_url: String::new(), |
| @@ -560,7 +567,7 @@ async fn mirrors_list_body( | ||
| 560 | 567 | enabled: None, error: pull.error, submit: g::t(lang, K::AddPullMirror), direction: "pull", lang: lang) |
| 561 | 568 | </section> |
| 562 | 569 | } |
| 563 | - <section class="card"> | |
| 570 | + <section class="card" id="add-push-mirror"> | |
| 564 | 571 | <h2>(g::t(lang, K::AddPushMirror))</h2> |
| 565 | 572 | <p class="muted small">(g::t(lang, K::AddPushIntro))</p> |
| 566 | 573 | mirror_form(action: add_action.clone(), csrf: csrf.clone(), pull: false, current_url: String::new(), |
| @@ -781,11 +788,6 @@ async fn mirror_body( | ||
| 781 | 788 | let sync_action = format!("{edit_action}/sync"); |
| 782 | 789 | let delete_action = format!("{edit_action}/delete"); |
| 783 | 790 | let pull = mirror.direction == MirrorDirection::Pull; |
| 784 | - let last_sync = mirror | |
| 785 | - .last_sync_at | |
| 786 | - .as_deref() | |
| 787 | - .map(|stamp| stamp_in_tz(stamp, &draft.tz)) | |
| 788 | - .unwrap_or_else(|| g::t(lang, K::Never).to_owned()); | |
| 789 | 791 | let delete_text = if pull { |
| 790 | 792 | g::t(lang, K::DeleteTextPull) |
| 791 | 793 | } else { |
| @@ -798,7 +800,7 @@ async fn mirror_body( | ||
| 798 | 800 | <h2>(mirror_kind(lang, mirror.direction))</h2> |
| 799 | 801 | if archived { |
| 800 | 802 | <p><code>(current_url.as_str())</code></p> |
| 801 | - <p class="muted small">(g::t(lang, K::LastSync))" " (last_sync.as_str())</p> | |
| 803 | + <p class="muted small">(g::t(lang, K::LastSync))" " rel_time_or_never(lang: lang, stamp: mirror.last_sync_at.as_deref())</p> | |
| 802 | 804 | if let Some(error) = mirror.last_error.clone() { |
| 803 | 805 | <pre class="mirror-error">(error.as_str())</pre> |
| 804 | 806 | } |
| @@ -821,16 +823,20 @@ async fn mirror_body( | ||
| 821 | 823 | <section class="card"> |
| 822 | 824 | <h2>(g::t(lang, K::DeleteMirror))</h2> |
| 823 | 825 | <p class="muted small">(delete_text)</p> |
| 824 | - <form method="post" action=(delete_action.as_str()) class="stack"> | |
| 825 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 826 | - <label class="inline"> | |
| 827 | - <input type="checkbox" name="confirm" value="on"> | |
| 828 | - <span>(g::t(lang, K::DeleteConfirm))</span> | |
| 829 | - </label> | |
| 830 | - <div> | |
| 831 | - <button type="submit" class="danger">(g::t(lang, K::DeleteMirror))</button> | |
| 832 | - </div> | |
| 833 | - </form> | |
| 826 | + <div> | |
| 827 | + <details class="confirm-inline"> | |
| 828 | + <summary class="button danger">(g::t(lang, K::DeleteMirror))</summary> | |
| 829 | + <div class="confirm-pop"> | |
| 830 | + <p>(g::t(lang, K::DeleteConfirm))</p> | |
| 831 | + <form method="post" action=(delete_action.as_str())> | |
| 832 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 833 | + <input type="hidden" name="confirm" value="on"> | |
| 834 | + <button type="submit" class="danger">(g::t(lang, K::DeleteMirror))</button> | |
| 835 | + <button type="button" data-close-details="">(g::t(lang, K::Cancel))</button> | |
| 836 | + </form> | |
| 837 | + </div> | |
| 838 | + </details> | |
| 839 | + </div> | |
| 834 | 840 | </section> |
| 835 | 841 | } |
| 836 | 842 | }) |
| @@ -838,7 +844,6 @@ async fn mirror_body( | ||
| 838 | 844 | |
| 839 | 845 | /// The edit form's values: the username and the interval as stored, or as submitted on error. |
| 840 | 846 | struct EditDraft { |
| 841 | - tz: String, | |
| 842 | 847 | username: String, |
| 843 | 848 | interval: String, |
| 844 | 849 | enabled: bool, |
| @@ -846,9 +851,8 @@ struct EditDraft { | ||
| 846 | 851 | } |
| 847 | 852 | |
| 848 | 853 | impl EditDraft { |
| 849 | - fn of_mirror(mirror: &Mirror, tz: &str) -> Self { | |
| 854 | + fn of_mirror(mirror: &Mirror) -> Self { | |
| 850 | 855 | Self { |
| 851 | - tz: tz.to_owned(), | |
| 852 | 856 | username: mirror.username.clone(), |
| 853 | 857 | interval: mirror.interval_minutes.to_string(), |
| 854 | 858 | enabled: mirror.enabled, |
| @@ -872,7 +876,7 @@ async fn mirror_page(cx: &Cx) -> Result<impl View> { | ||
| 872 | 876 | let mirror = repo_mirror(state, &ctx, id).await?; |
| 873 | 877 | let lang = lang_of(cx, &ctx); |
| 874 | 878 | let frame = Frame::new(&ctx, state, lang).await?; |
| 875 | - let draft = EditDraft::of_mirror(&mirror, &frame.tz); | |
| 879 | + let draft = EditDraft::of_mirror(&mirror); | |
| 876 | 880 | let csrf = session.csrf_token.clone(); |
| 877 | 881 | let notice = notice_from_query(cx, lang); |
| 878 | 882 | let mirror_id = mirror.id.clone(); |
| @@ -920,7 +924,6 @@ async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> | ||
| 920 | 924 | Err(message) => { |
| 921 | 925 | let frame = Frame::new(&ctx, state, lang).await?; |
| 922 | 926 | let draft = EditDraft { |
| 923 | - tz: frame.tz.clone(), | |
| 924 | 927 | username: form.username.trim().to_owned(), |
| 925 | 928 | interval: form.interval.trim().to_owned(), |
| 926 | 929 | enabled: form.enabled.is_some(), |
crates/forge-web/src/pages/repo_secrets.rsmodified+9 -8
| @@ -20,11 +20,10 @@ use crate::i18n::repo_admin::{self as g, K}; | ||
| 20 | 20 | use crate::i18n::{self, Lang}; |
| 21 | 21 | use crate::pages::repo::repo_head; |
| 22 | 22 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| 23 | -use crate::pages::repo_mirrors::stamp_in_tz; | |
| 24 | 23 | use crate::pages::repo_settings::settings_nav_for; |
| 25 | 24 | use crate::pages::repo_settings_live::settings_head; |
| 26 | 25 | use crate::state::AppState; |
| 27 | -use crate::views::{alert, enc, shell}; | |
| 26 | +use crate::views::{alert, empty_state, enc, rel_time, shell}; | |
| 28 | 27 | |
| 29 | 28 | path_param!(owner); |
| 30 | 29 | path_param!(repo); |
| @@ -113,7 +112,7 @@ fn notice_from_query(cx: &Cx) -> Option<(K, bool)> { | ||
| 113 | 112 | /// One row of the list: the name and when it was last set, already formatted. |
| 114 | 113 | struct SecretRow { |
| 115 | 114 | name: String, |
| 116 | - updated: String, | |
| 115 | + updated_at: String, | |
| 117 | 116 | } |
| 118 | 117 | |
| 119 | 118 | /// What the page shows, read once from the repo context and the store. |
| @@ -128,7 +127,6 @@ struct SecretsData { | ||
| 128 | 127 | impl SecretsData { |
| 129 | 128 | async fn load(state: &AppState, ctx: &RepoCtx, lang: Lang) -> Result<Self> { |
| 130 | 129 | let title = title_of(ctx); |
| 131 | - let tz = ctx.viewer_tz().to_owned(); | |
| 132 | 130 | let rows = state |
| 133 | 131 | .store |
| 134 | 132 | .list_ci_secret_names(&ctx.repo.id) |
| @@ -136,7 +134,7 @@ impl SecretsData { | ||
| 136 | 134 | .into_iter() |
| 137 | 135 | .map(|(name, updated)| SecretRow { |
| 138 | 136 | name, |
| 139 | - updated: stamp_in_tz(&updated, &tz), | |
| 137 | + updated_at: updated, | |
| 140 | 138 | }) |
| 141 | 139 | .collect(); |
| 142 | 140 | Ok(Self { |
| @@ -197,7 +195,10 @@ async fn secrets_body( | ||
| 197 | 195 | <h2>(g::t(lang, K::Secrets))</h2> |
| 198 | 196 | <p class="muted small">(g::t(lang, K::SecretsHelp))</p> |
| 199 | 197 | if rows.is_empty() { |
| 200 | - <p class="muted">(g::t(lang, K::NoSecrets))</p> | |
| 198 | + empty_state(title: g::t(lang, K::NoSecrets), | |
| 199 | + if !archived { | |
| 200 | + <a class="button" href="#add-secret">(g::t(lang, K::AddOrUpdate))</a> | |
| 201 | + }) | |
| 201 | 202 | } else { |
| 202 | 203 | <div class="table-wrap"> |
| 203 | 204 | <table class="table secrets"> |
| @@ -212,7 +213,7 @@ async fn secrets_body( | ||
| 212 | 213 | for row in rows.iter() { |
| 213 | 214 | <tr> |
| 214 | 215 | <td><code>(row.name.as_str())</code></td> |
| 215 | - <td class="small">(row.updated.as_str())</td> | |
| 216 | + <td class="small">rel_time(lang: lang, stamp: row.updated_at.as_str())</td> | |
| 216 | 217 | <td> |
| 217 | 218 | if !archived { |
| 218 | 219 | <form method="post" action=(delete_action.as_str()) class="inline-form"> |
| @@ -230,7 +231,7 @@ async fn secrets_body( | ||
| 230 | 231 | } |
| 231 | 232 | </section> |
| 232 | 233 | if !archived { |
| 233 | - <section class="card"> | |
| 234 | + <section class="card" id="add-secret"> | |
| 234 | 235 | <h2>(g::t(lang, K::AddOrUpdate))</h2> |
| 235 | 236 | if let Some(message) = error { |
| 236 | 237 | <p class="alert" role="alert">(message.as_str())</p> |
crates/forge-web/src/pages/repo_security.rsmodified+7 -9
| @@ -21,10 +21,9 @@ use crate::i18n::misc::{self as g, K}; | ||
| 21 | 21 | use crate::i18n::{self, Key, Lang}; |
| 22 | 22 | use crate::pages::repo::repo_head; |
| 23 | 23 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| 24 | -use crate::pages::repo_mirrors::stamp_in_tz; | |
| 25 | 24 | use crate::pages::repo_settings_live::security_live_url; |
| 26 | 25 | use crate::state::AppState; |
| 27 | -use crate::views::shell; | |
| 26 | +use crate::views::{empty_state, rel_time, shell}; | |
| 28 | 27 | |
| 29 | 28 | path_param!(owner); |
| 30 | 29 | path_param!(repo); |
| @@ -54,7 +53,7 @@ struct AlertRow { | ||
| 54 | 53 | summary: String, |
| 55 | 54 | state_text: &'static str, |
| 56 | 55 | state_class: &'static str, |
| 57 | - created: String, | |
| 56 | + created_at: String, | |
| 58 | 57 | open: bool, |
| 59 | 58 | dismissed: bool, |
| 60 | 59 | dismiss_action: String, |
| @@ -76,7 +75,7 @@ pub(crate) fn can_write(ctx: &RepoCtx) -> bool { | ||
| 76 | 75 | authorize(actor, &ctx.repo, ctx.role, ctx.org_role, Action::Write).is_ok() |
| 77 | 76 | } |
| 78 | 77 | |
| 79 | -fn row_of(alert: &Alert, title: &str, tz: &str, lang: Lang) -> AlertRow { | |
| 78 | +fn row_of(alert: &Alert, title: &str, lang: Lang) -> AlertRow { | |
| 80 | 79 | let (state_text, state_class) = match alert.state { |
| 81 | 80 | AlertState::Open => (g::t(lang, K::StateOpen), "hook-state fail"), |
| 82 | 81 | AlertState::Dismissed => (g::t(lang, K::StateDismissed), "hook-state"), |
| @@ -96,7 +95,7 @@ fn row_of(alert: &Alert, title: &str, tz: &str, lang: Lang) -> AlertRow { | ||
| 96 | 95 | summary: alert.summary.clone(), |
| 97 | 96 | state_text, |
| 98 | 97 | state_class, |
| 99 | - created: stamp_in_tz(&alert.created_at, tz), | |
| 98 | + created_at: alert.created_at.clone(), | |
| 100 | 99 | open: alert.state == AlertState::Open, |
| 101 | 100 | dismissed: alert.state == AlertState::Dismissed, |
| 102 | 101 | dismiss_action: format!("{base}/dismiss"), |
| @@ -133,7 +132,7 @@ async fn security_body( | ||
| 133 | 132 | </section> |
| 134 | 133 | <section class="card"> |
| 135 | 134 | if rows.is_empty() { |
| 136 | - <p class="muted">(g::t(lang, K::NoAlerts))</p> | |
| 135 | + empty_state(title: g::t(lang, K::NoAlerts)) | |
| 137 | 136 | } else { |
| 138 | 137 | <div class="table-wrap"> |
| 139 | 138 | <table class="table security-alerts"> |
| @@ -158,7 +157,7 @@ async fn security_body( | ||
| 158 | 157 | <td>(row.severity.as_str())</td> |
| 159 | 158 | <td>(row.summary.as_str())</td> |
| 160 | 159 | <td><span class=(row.state_class)>(row.state_text)</span></td> |
| 161 | - <td>(row.created.as_str())</td> | |
| 160 | + <td>rel_time(lang: lang, stamp: row.created_at.as_str())</td> | |
| 162 | 161 | <td> |
| 163 | 162 | if row.open { |
| 164 | 163 | <form method="post" action=(row.dismiss_action.as_str()) class="inline-form"> |
| @@ -207,13 +206,12 @@ async fn security_page(cx: &Cx) -> Result<impl View> { | ||
| 207 | 206 | let mut head = ctx.head(state, "security").await?; |
| 208 | 207 | head.live = security_live_url(&ctx.repo.owner_name, &ctx.repo.name); |
| 209 | 208 | let dependencies = state.store.dependency_count(&ctx.repo.id).await?; |
| 210 | - let tz = ctx.viewer_tz().to_owned(); | |
| 211 | 209 | let rows: Vec<AlertRow> = state |
| 212 | 210 | .store |
| 213 | 211 | .list_alerts(&ctx.repo.id) |
| 214 | 212 | .await? |
| 215 | 213 | .iter() |
| 216 | - .map(|alert| row_of(alert, &title, &tz, lang)) | |
| 214 | + .map(|alert| row_of(alert, &title, lang)) | |
| 217 | 215 | .collect(); |
| 218 | 216 | let csrf = session.csrf_token.clone(); |
| 219 | 217 | let enabled = state.config.advisories.enabled; |
crates/forge-web/src/pages/repo_settings.rsmodified+71 -42
| @@ -90,7 +90,7 @@ struct GeneralForm { | ||
| 90 | 90 | default_branch: String, |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | -/// The visibility form. An unchecked "I understand" box is absent from the body. | |
| 93 | +/// The visibility form. `understand` is the confirm popup's hidden field; a request without it is refused. | |
| 94 | 94 | #[derive(Deserialize)] |
| 95 | 95 | struct VisibilityForm { |
| 96 | 96 | #[serde(default)] |
| @@ -340,13 +340,21 @@ async fn general_section( | ||
| 340 | 340 | let general_action = format!("/{title}/settings/general"); |
| 341 | 341 | let visibility_action = format!("/{title}/settings/visibility"); |
| 342 | 342 | let archive_action = format!("/{title}/settings/archive"); |
| 343 | - let is_public = visibility == Visibility::Public; | |
| 344 | - let private_checked = !is_public; | |
| 345 | - let archive_value = if archived { "0" } else { "1" }; | |
| 346 | - let archive_label = if archived { | |
| 347 | - g::t(lang, K::UnarchiveRepo) | |
| 343 | + // The visibility row shows where the repo is now and offers the other side behind a confirm. | |
| 344 | + let (current_visibility, flip_label, flip_confirm, flip_to) = if visibility == Visibility::Public { | |
| 345 | + ( | |
| 346 | + g::t(lang, K::PublicOption), | |
| 347 | + g::t(lang, K::MakePrivate), | |
| 348 | + g::t(lang, K::MakePrivateConfirm), | |
| 349 | + "private", | |
| 350 | + ) | |
| 348 | 351 | } else { |
| 349 | - g::t(lang, K::ArchiveRepo) | |
| 352 | + ( | |
| 353 | + g::t(lang, K::PrivateOption), | |
| 354 | + g::t(lang, K::MakePublic), | |
| 355 | + g::t(lang, K::MakePublicConfirm), | |
| 356 | + "public", | |
| 357 | + ) | |
| 350 | 358 | }; |
| 351 | 359 | let options: Vec<(String, bool)> = branches |
| 352 | 360 | .into_iter() |
| @@ -382,40 +390,61 @@ async fn general_section( | ||
| 382 | 390 | </div> |
| 383 | 391 | </form> |
| 384 | 392 | |
| 385 | - <h3>(g::t(lang, K::VisibilityHeading))</h3> | |
| 386 | - <form method="post" action=(visibility_action) class="stack"> | |
| 387 | - <input type="hidden" name="csrf" value=(csrf.clone())> | |
| 388 | - <label class="inline"> | |
| 389 | - <input type="radio" name="visibility" value="public" checked=(is_public)> | |
| 390 | - <span>(g::t(lang, K::PublicOption))</span> | |
| 391 | - </label> | |
| 392 | - <label class="inline"> | |
| 393 | - <input type="radio" name="visibility" value="private" checked=(private_checked)> | |
| 394 | - <span>(g::t(lang, K::PrivateOption))</span> | |
| 395 | - </label> | |
| 396 | - <label class="inline"> | |
| 397 | - <input type="checkbox" name="understand" value="on"> | |
| 398 | - <span>(g::t(lang, K::IUnderstand))</span> | |
| 399 | - </label> | |
| 400 | - <p class="muted small">(g::t(lang, K::VisibilityHelp))</p> | |
| 401 | - <div> | |
| 402 | - <button type="submit">(g::t(lang, K::ChangeVisibility))</button> | |
| 403 | - </div> | |
| 404 | - </form> | |
| 405 | - | |
| 406 | - <h3>(g::t(lang, K::ArchiveHeading))</h3> | |
| 407 | - if archived { | |
| 408 | - <p class="muted small">(g::t(lang, K::ArchivedHelp))</p> | |
| 409 | - } else { | |
| 410 | - <p class="muted small">(g::t(lang, K::ArchiveHelp))</p> | |
| 411 | - } | |
| 412 | - <form method="post" action=(archive_action) class="stack"> | |
| 413 | - <input type="hidden" name="csrf" value=(csrf.clone())> | |
| 414 | - <input type="hidden" name="archived" value=(archive_value)> | |
| 415 | - <div> | |
| 416 | - <button type="submit">(archive_label)</button> | |
| 417 | - </div> | |
| 418 | - </form> | |
| 393 | + <ul class="action-list"> | |
| 394 | + <li class="action-row"> | |
| 395 | + <div class="action-text"> | |
| 396 | + <h3>(g::t(lang, K::VisibilityHeading))</h3> | |
| 397 | + <p class="muted small">(current_visibility)</p> | |
| 398 | + </div> | |
| 399 | + <div class="action-control"> | |
| 400 | + <details class="confirm-inline"> | |
| 401 | + <summary class="button">(flip_label)</summary> | |
| 402 | + <div class="confirm-pop"> | |
| 403 | + <p>(flip_confirm)</p> | |
| 404 | + <form method="post" action=(visibility_action)> | |
| 405 | + <input type="hidden" name="csrf" value=(csrf.clone())> | |
| 406 | + <input type="hidden" name="visibility" value=(flip_to)> | |
| 407 | + <input type="hidden" name="understand" value="on"> | |
| 408 | + <button type="submit" class="danger">(flip_label)</button> | |
| 409 | + <button type="button" data-close-details="">(g::t(lang, K::Cancel))</button> | |
| 410 | + </form> | |
| 411 | + </div> | |
| 412 | + </details> | |
| 413 | + </div> | |
| 414 | + </li> | |
| 415 | + <li class="action-row"> | |
| 416 | + <div class="action-text"> | |
| 417 | + <h3>(g::t(lang, K::ArchiveHeading))</h3> | |
| 418 | + if archived { | |
| 419 | + <p class="muted small">(g::t(lang, K::ArchivedHelp))</p> | |
| 420 | + } else { | |
| 421 | + <p class="muted small">(g::t(lang, K::ArchiveHelp))</p> | |
| 422 | + } | |
| 423 | + </div> | |
| 424 | + <div class="action-control"> | |
| 425 | + if archived { | |
| 426 | + <form method="post" action=(archive_action.as_str())> | |
| 427 | + <input type="hidden" name="csrf" value=(csrf.clone())> | |
| 428 | + <input type="hidden" name="archived" value="0"> | |
| 429 | + <button type="submit">(g::t(lang, K::UnarchiveRepo))</button> | |
| 430 | + </form> | |
| 431 | + } else { | |
| 432 | + <details class="confirm-inline"> | |
| 433 | + <summary class="button">(g::t(lang, K::ArchiveRepo))</summary> | |
| 434 | + <div class="confirm-pop"> | |
| 435 | + <p>(g::t(lang, K::ArchiveConfirm))</p> | |
| 436 | + <form method="post" action=(archive_action.as_str())> | |
| 437 | + <input type="hidden" name="csrf" value=(csrf.clone())> | |
| 438 | + <input type="hidden" name="archived" value="1"> | |
| 439 | + <button type="submit" class="danger">(g::t(lang, K::ArchiveRepo))</button> | |
| 440 | + <button type="button" data-close-details="">(g::t(lang, K::Cancel))</button> | |
| 441 | + </form> | |
| 442 | + </div> | |
| 443 | + </details> | |
| 444 | + } | |
| 445 | + </div> | |
| 446 | + </li> | |
| 447 | + </ul> | |
| 419 | 448 | </section> |
| 420 | 449 | }) |
| 421 | 450 | } |
| @@ -963,7 +992,7 @@ async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result | ||
| 963 | 992 | Ok(back_to_settings(&title)) |
| 964 | 993 | } |
| 965 | 994 | |
| 966 | -/// Changes the visibility. Changing it needs the "I understand" box. Picking the current value | |
| 995 | +/// Changes the visibility. Changing it needs `understand`, which only the confirm popup sends. Picking the current value | |
| 967 | 996 | /// changes nothing. |
| 968 | 997 | #[route(POST "/{owner}/{repo}/settings/visibility")] |
| 969 | 998 | async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> Result<SeeOther> { |
crates/forge-web/src/pages/repo_transfer.rsmodified+22 -12
| @@ -26,7 +26,7 @@ use crate::pages::repo::repo_head; | ||
| 26 | 26 | use crate::pages::repo_ctx::{RepoHead, load_repo}; |
| 27 | 27 | use crate::pages::repo_settings_live::{bump_settings, transfer_live_url}; |
| 28 | 28 | use crate::state::AppState; |
| 29 | -use crate::views::{csrf_field, shell}; | |
| 29 | +use crate::views::{csrf_field, rel_time, shell}; | |
| 30 | 30 | |
| 31 | 31 | path_param!(owner); |
| 32 | 32 | path_param!(repo); |
| @@ -39,15 +39,25 @@ struct ActionForm { | ||
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /// One line describing an open transfer, for the repo page. |
| 42 | -fn summary_text(lang: Lang, transfer: &PendingTransfer) -> String { | |
| 43 | - let until = transfer.expires_at.split('T').next().unwrap_or_default(); | |
| 44 | - g::transfer_summary( | |
| 42 | +fn summary_text(lang: Lang, transfer: &PendingTransfer) -> TransferSummary { | |
| 43 | + let (before, after) = g::transfer_summary( | |
| 45 | 44 | lang, |
| 46 | 45 | transfer.to_is_org, |
| 47 | 46 | &transfer.to_owner_name, |
| 48 | 47 | &transfer.initiated_by_name, |
| 49 | - until, | |
| 50 | - ) | |
| 48 | + ); | |
| 49 | + TransferSummary { | |
| 50 | + before, | |
| 51 | + expires_at: transfer.expires_at.clone(), | |
| 52 | + after, | |
| 53 | + } | |
| 54 | +} | |
| 55 | + | |
| 56 | +/// The pending-transfer sentence, with its expiry as a live relative time between two parts. | |
| 57 | +struct TransferSummary { | |
| 58 | + before: String, | |
| 59 | + expires_at: String, | |
| 60 | + after: &'static str, | |
| 51 | 61 | } |
| 52 | 62 | |
| 53 | 63 | /// The open transfer and the action forms the viewer may use. Each action is `None` when hidden. |
| @@ -55,7 +65,7 @@ fn summary_text(lang: Lang, transfer: &PendingTransfer) -> String { | ||
| 55 | 65 | async fn transfer_body( |
| 56 | 66 | lang: Lang, |
| 57 | 67 | head: RepoHead, |
| 58 | - summary: String, | |
| 68 | + summary: Option<TransferSummary>, | |
| 59 | 69 | accept: Option<String>, |
| 60 | 70 | decline: Option<String>, |
| 61 | 71 | cancel: Option<String>, |
| @@ -66,8 +76,8 @@ async fn transfer_body( | ||
| 66 | 76 | repo_head(head: head) |
| 67 | 77 | <section class="card"> |
| 68 | 78 | <h2>(g::t(lang, K::TransferTitle))</h2> |
| 69 | - if !summary.is_empty() { | |
| 70 | - <p>(summary.as_str())</p> | |
| 79 | + if let Some(summary) = summary.as_ref() { | |
| 80 | + <p>(summary.before.as_str()) rel_time(lang: lang, stamp: summary.expires_at.as_str()) (summary.after)</p> | |
| 71 | 81 | if let Some(action) = accept { |
| 72 | 82 | <form method="post" action=(action.as_str()) class="stack"> |
| 73 | 83 | csrf_field(token: csrf.as_str()) |
| @@ -93,7 +103,7 @@ async fn transfer_body( | ||
| 93 | 103 | </form> |
| 94 | 104 | } |
| 95 | 105 | } |
| 96 | - if summary.is_empty() { | |
| 106 | + if summary.is_none() { | |
| 97 | 107 | <p class="muted">(g::t(lang, K::NoPendingTransfer))</p> |
| 98 | 108 | } |
| 99 | 109 | if let Some(href) = settings { |
| @@ -122,13 +132,13 @@ async fn transfer_get(cx: &Cx) -> Result<impl View> { | ||
| 122 | 132 | let may_accept = state.store.can_accept_transfer(&user.id, transfer).await?; |
| 123 | 133 | let may_cancel = may_delete || transfer.initiated_by_id == user.id; |
| 124 | 134 | ( |
| 125 | - summary_text(lang, transfer), | |
| 135 | + Some(summary_text(lang, transfer)), | |
| 126 | 136 | may_accept.then(|| format!("/-/transfers/{}/accept", transfer.repo_id)), |
| 127 | 137 | may_accept.then(|| format!("/-/transfers/{}/decline", transfer.repo_id)), |
| 128 | 138 | may_cancel.then(|| format!("/-/transfers/{}/cancel", transfer.repo_id)), |
| 129 | 139 | ) |
| 130 | 140 | } |
| 131 | - None => (String::new(), None, None, None), | |
| 141 | + None => (None, None, None, None), | |
| 132 | 142 | }; |
| 133 | 143 | let settings = may_delete.then(|| format!("/{title}/settings/rename")); |
| 134 | 144 | let mut head = ctx.head(state, "settings").await?; |
crates/forge-web/src/pages/repo_webhooks.rsmodified+28 -15
| @@ -31,7 +31,7 @@ use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | ||
| 31 | 31 | use crate::pages::repo_settings::settings_nav_for; |
| 32 | 32 | use crate::pages::repo_settings_live::settings_head; |
| 33 | 33 | use crate::state::AppState; |
| 34 | -use crate::views::{alert, enc, now_unix, relative_time, shell}; | |
| 34 | +use crate::views::{alert, empty_state, enc, now_unix, relative_time, shell}; | |
| 35 | 35 | use crate::webhooks::client::{WebhookPolicy, validate_url}; |
| 36 | 36 | use crate::webhooks::emit::emit_ping; |
| 37 | 37 | |
| @@ -404,7 +404,9 @@ struct DeliveryRow { | ||
| 404 | 404 | state_text: &'static str, |
| 405 | 405 | event: String, |
| 406 | 406 | guid: String, |
| 407 | - time: String, | |
| 407 | + time_iso: String, | |
| 408 | + time_full: String, | |
| 409 | + time_rel: String, | |
| 408 | 410 | duration: String, |
| 409 | 411 | status: String, |
| 410 | 412 | request_headers: String, |
| @@ -437,7 +439,11 @@ fn delivery_row( | ||
| 437 | 439 | state_text, |
| 438 | 440 | event, |
| 439 | 441 | guid: delivery.guid.clone(), |
| 440 | - time: local_stamp(&delivery.created_at, tz), | |
| 442 | + time_iso: delivery.created_at.clone(), | |
| 443 | + time_full: local_stamp(&delivery.created_at, tz), | |
| 444 | + time_rel: OffsetDateTime::parse(&delivery.created_at, &Rfc3339) | |
| 445 | + .map(|at| relative_time(lang, at.unix_timestamp(), now_unix())) | |
| 446 | + .unwrap_or_default(), | |
| 441 | 447 | duration: delivery |
| 442 | 448 | .duration_ms |
| 443 | 449 | .map_or_else(|| "-".to_owned(), |ms| format!("{ms} ms")), |
| @@ -572,7 +578,10 @@ async fn hooks_list_body( | ||
| 572 | 578 | <p><a href=(new_href.as_str()) class="button">(g::t(lang, K::AddWebhook))</a></p> |
| 573 | 579 | } |
| 574 | 580 | if rows.is_empty() { |
| 575 | - <p class="muted">(g::t(lang, K::NoWebhooks))</p> | |
| 581 | + empty_state(title: g::t(lang, K::NoWebhooks), | |
| 582 | + if !archived { | |
| 583 | + <a class="button" href=(new_href.as_str())>(g::t(lang, K::AddWebhook))</a> | |
| 584 | + }) | |
| 576 | 585 | } else { |
| 577 | 586 | <ul class="runner-list hook-list"> |
| 578 | 587 | for row in rows.iter() { |
| @@ -625,7 +634,7 @@ async fn delivery_list( | ||
| 625 | 634 | " " |
| 626 | 635 | <code>(row.event.as_str())</code> |
| 627 | 636 | " " |
| 628 | - <span class="muted small">(row.time.as_str())</span> | |
| 637 | + <time class="muted small" data-rel="true" datetime=(row.time_iso.as_str()) title=(row.time_full.as_str())>(row.time_rel.as_str())</time> | |
| 629 | 638 | " " |
| 630 | 639 | <span class="muted small">(row.duration.as_str())</span> |
| 631 | 640 | " " |
| @@ -707,16 +716,20 @@ async fn hook_body( | ||
| 707 | 716 | <section class="card"> |
| 708 | 717 | <h2>(g::t(lang, K::DeleteWebhook))</h2> |
| 709 | 718 | <p class="muted small">(g::t(lang, K::DeleteIntro))</p> |
| 710 | - <form method="post" action=(delete_action.as_str()) class="stack"> | |
| 711 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 712 | - <label class="inline"> | |
| 713 | - <input type="checkbox" name="confirm" value="on"> | |
| 714 | - <span>(g::t(lang, K::DeleteConfirm))</span> | |
| 715 | - </label> | |
| 716 | - <div> | |
| 717 | - <button type="submit" class="danger">(g::t(lang, K::DeleteWebhook))</button> | |
| 718 | - </div> | |
| 719 | - </form> | |
| 719 | + <div> | |
| 720 | + <details class="confirm-inline"> | |
| 721 | + <summary class="button danger">(g::t(lang, K::DeleteWebhook))</summary> | |
| 722 | + <div class="confirm-pop"> | |
| 723 | + <p>(g::t(lang, K::DeleteConfirm))</p> | |
| 724 | + <form method="post" action=(delete_action.as_str())> | |
| 725 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 726 | + <input type="hidden" name="confirm" value="on"> | |
| 727 | + <button type="submit" class="danger">(g::t(lang, K::DeleteWebhook))</button> | |
| 728 | + <button type="button" data-close-details="">(g::t(lang, K::Cancel))</button> | |
| 729 | + </form> | |
| 730 | + </div> | |
| 731 | + </details> | |
| 732 | + </div> | |
| 720 | 733 | </section> |
| 721 | 734 | } |
| 722 | 735 | }) |
crates/forge-web/src/pages/review_requests.rsmodified+2 -2
| @@ -23,7 +23,7 @@ use crate::notify; | ||
| 23 | 23 | use crate::pages::issue_parts::{ItemKind, check_write, may_change, parse_number}; |
| 24 | 24 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| 25 | 25 | use crate::state::AppState; |
| 26 | -use crate::views::{rel_time, repo_href, shell}; | |
| 26 | +use crate::views::{empty_state, rel_time, repo_href, shell}; | |
| 27 | 27 | |
| 28 | 28 | path_param!(owner); |
| 29 | 29 | path_param!(repo); |
| @@ -289,7 +289,7 @@ async fn review_requests(cx: &Cx) -> Result<impl View> { | ||
| 289 | 289 | <h1>(heading)</h1> |
| 290 | 290 | </section> |
| 291 | 291 | if empty { |
| 292 | - <p class="muted">(ga::t(lang, AK::NoReviewRequests))</p> | |
| 292 | + empty_state(title: ga::t(lang, AK::NoReviewRequests)) | |
| 293 | 293 | } |
| 294 | 294 | if !empty { |
| 295 | 295 | <section class="card"> |
crates/forge-web/src/pages/settings_export.rsmodified+3 -12
| @@ -3,7 +3,6 @@ | ||
| 3 | 3 | //! while an export is building, so it turns ready with no reload and no polling. |
| 4 | 4 | |
| 5 | 5 | use forge_core::store::exports::{DataExport, ExportState}; |
| 6 | -use forge_core::time::stamp_to_unix; | |
| 7 | 6 | use futures_util::{TryStreamExt, stream}; |
| 8 | 7 | use http::header::{ |
| 9 | 8 | CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_LENGTH, CONTENT_TYPE, HeaderValue, |
| @@ -27,7 +26,7 @@ use crate::i18n::migrate::{self as g, K}; | ||
| 27 | 26 | use crate::i18n::{self, Lang}; |
| 28 | 27 | use crate::pages::ci_runs::{changed_event, events_response}; |
| 29 | 28 | use crate::state::AppState; |
| 30 | -use crate::views::{alert, csrf_field, human_size, now_unix, relative_time, shell}; | |
| 29 | +use crate::views::{alert, csrf_field, human_size, rel_time, shell}; | |
| 31 | 30 | |
| 32 | 31 | path_param!(export_id); |
| 33 | 32 | |
| @@ -51,14 +50,6 @@ fn signature(exports: &[DataExport]) -> String { | ||
| 51 | 50 | .join(",") |
| 52 | 51 | } |
| 53 | 52 | |
| 54 | -fn ago(lang: Lang, stamp: &str) -> String { | |
| 55 | - stamp_to_unix(stamp).map_or_else(String::new, |t| relative_time(lang, t, now_unix())) | |
| 56 | -} | |
| 57 | - | |
| 58 | -fn day(stamp: &str) -> String { | |
| 59 | - stamp.chars().take(10).collect() | |
| 60 | -} | |
| 61 | - | |
| 62 | 53 | #[component] |
| 63 | 54 | async fn export_view(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Result<impl View> { |
| 64 | 55 | let building = exports.iter().any(|e| e.state == ExportState::Building); |
| @@ -92,11 +83,11 @@ async fn export_view(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Result | ||
| 92 | 83 | for export in exports.iter() { |
| 93 | 84 | <li class="item export-row"> |
| 94 | 85 | <div class="item-main"> |
| 95 | - <strong>(g::t(lang, K::ExportRequested)) " " <time data-rel="true" datetime=(export.created_at.as_str())>(ago(lang, &export.created_at))</time></strong> | |
| 86 | + <strong>(g::t(lang, K::ExportRequested)) " " rel_time(lang: lang, stamp: export.created_at.as_str())</strong> | |
| 96 | 87 | if export.state == ExportState::Ready { |
| 97 | 88 | <span class="muted small"> |
| 98 | 89 | (g::t(lang, K::ExportSize)) ": " (human_size(lang, u64::try_from(export.size).unwrap_or(0))) |
| 99 | - " · " (g::expires_on(lang, &day(&export.expires_at))) | |
| 90 | + " · " (g::expires_label(lang)) " " rel_time(lang: lang, stamp: export.expires_at.as_str()) | |
| 100 | 91 | </span> |
| 101 | 92 | } |
| 102 | 93 | </div> |
crates/forge-web/src/pages/settings_gpg.rsmodified+4 -3
| @@ -16,7 +16,7 @@ use crate::auth::{require_csrf, require_user}; | ||
| 16 | 16 | use crate::i18n::{self, Key, Lang, t}; |
| 17 | 17 | use crate::signatures; |
| 18 | 18 | use crate::state::AppState; |
| 19 | -use crate::views::{added_status, alert, shell, user_facing_message}; | |
| 19 | +use crate::views::{added_status, alert, empty_state, shell, user_facing_message}; | |
| 20 | 20 | |
| 21 | 21 | #[derive(Deserialize)] |
| 22 | 22 | struct AddKeyForm { |
| @@ -52,7 +52,8 @@ async fn gpg_view( | ||
| 52 | 52 | } |
| 53 | 53 | <section class="card"> |
| 54 | 54 | if keys.is_empty() { |
| 55 | - <p class="muted">(t(lang, Key::NoGpgKeys))</p> | |
| 55 | + empty_state(title: t(lang, Key::NoGpgKeys), | |
| 56 | + <a class="button" href="#add-gpg-key">(t(lang, Key::AddGpgKeyTitle))</a>) | |
| 56 | 57 | } else { |
| 57 | 58 | <ul class="item-list"> |
| 58 | 59 | for key in keys.into_iter() { |
| @@ -72,7 +73,7 @@ async fn gpg_view( | ||
| 72 | 73 | </ul> |
| 73 | 74 | } |
| 74 | 75 | </section> |
| 75 | - <section class="card"> | |
| 76 | + <section class="card" id="add-gpg-key"> | |
| 76 | 77 | <h2>(t(lang, Key::AddGpgKeyTitle))</h2> |
| 77 | 78 | if let Some(message) = error { |
| 78 | 79 | alert(message: message.as_str()) |
crates/forge-web/src/pages/settings_keys.rsmodified+4 -3
| @@ -15,7 +15,7 @@ use crate::audit::{self, Actor, Target}; | ||
| 15 | 15 | use crate::auth::{require_csrf, require_user}; |
| 16 | 16 | use crate::i18n::{self, Key, Lang, t, unsupported_key_type}; |
| 17 | 17 | use crate::state::AppState; |
| 18 | -use crate::views::{added_status, alert, shell, user_facing_message}; | |
| 18 | +use crate::views::{added_status, alert, empty_state, shell, user_facing_message}; | |
| 19 | 19 | |
| 20 | 20 | /// Algorithms accepted for web-registered keys. `ssh-rsa` is rejected with its own message. |
| 21 | 21 | const ACCEPTED: &[&str] = &[ |
| @@ -149,7 +149,8 @@ async fn keys_view( | ||
| 149 | 149 | </section> |
| 150 | 150 | <section class="card"> |
| 151 | 151 | if keys.is_empty() { |
| 152 | - <p class="muted">(t(lang, Key::NoSshKeys))</p> | |
| 152 | + empty_state(title: t(lang, Key::NoSshKeys), | |
| 153 | + <a class="button" href="#add-key">(t(lang, Key::AddSshKeyTitle))</a>) | |
| 153 | 154 | } else { |
| 154 | 155 | <ul class="item-list"> |
| 155 | 156 | for key in keys.into_iter() { |
| @@ -170,7 +171,7 @@ async fn keys_view( | ||
| 170 | 171 | </ul> |
| 171 | 172 | } |
| 172 | 173 | </section> |
| 173 | - <section class="card"> | |
| 174 | + <section class="card" id="add-key"> | |
| 174 | 175 | <h2>(t(lang, Key::AddSshKeyTitle))</h2> |
| 175 | 176 | if let Some(message) = error { |
| 176 | 177 | alert(message: message.as_str()) |
crates/forge-web/src/pages/settings_notifications.rsmodified+4 -9
| @@ -18,7 +18,7 @@ use crate::auth::{require_csrf, require_user}; | ||
| 18 | 18 | use crate::i18n::push as push_text; |
| 19 | 19 | use crate::i18n::{self, Key, Lang, t}; |
| 20 | 20 | use crate::state::AppState; |
| 21 | -use crate::views::{csrf_field, shell}; | |
| 21 | +use crate::views::{csrf_field, empty_state, rel_time, shell}; | |
| 22 | 22 | |
| 23 | 23 | #[query_params(error = bad_request)] |
| 24 | 24 | struct NotificationsQuery { |
| @@ -53,11 +53,6 @@ struct NotificationsPage { | ||
| 53 | 53 | can_test: bool, |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -/// A device's date for the list: the `YYYY-MM-DD` part of its stamp. | |
| 57 | -fn day_of(stamp: &str) -> &str { | |
| 58 | - stamp.get(..10).unwrap_or(stamp) | |
| 59 | -} | |
| 60 | - | |
| 61 | 56 | #[component] |
| 62 | 57 | async fn notifications_body(page: NotificationsPage) -> Result<impl View> { |
| 63 | 58 | let NotificationsPage { |
| @@ -131,17 +126,17 @@ async fn notifications_body(page: NotificationsPage) -> Result<impl View> { | ||
| 131 | 126 | <section class="card"> |
| 132 | 127 | <h2>(push_text::t(lang, push_text::K::DevicesHeading))</h2> |
| 133 | 128 | if devices.is_empty() { |
| 134 | - <p class="muted">(push_text::t(lang, push_text::K::DevicesEmpty))</p> | |
| 129 | + empty_state(title: push_text::t(lang, push_text::K::DevicesEmpty)) | |
| 135 | 130 | } |
| 136 | 131 | <ul class="push-devices"> |
| 137 | 132 | for device in devices.into_iter() { |
| 138 | 133 | <li class="push-device"> |
| 139 | 134 | <div> |
| 140 | 135 | <strong>(device.agent_label.as_str())</strong> |
| 141 | - <small class="muted">(push_text::added_on(lang, day_of(&device.created_at)))</small> | |
| 136 | + <small class="muted">(push_text::added_label(lang)) " " rel_time(lang: lang, stamp: device.created_at.as_str())</small> | |
| 142 | 137 | <small class="muted"> |
| 143 | 138 | if let Some(stamp) = device.last_success_at.as_deref() { |
| 144 | - (push_text::last_delivered(lang, day_of(stamp))) | |
| 139 | + (push_text::last_delivered_label(lang)) " " rel_time(lang: lang, stamp: stamp) | |
| 145 | 140 | } else { |
| 146 | 141 | (push_text::t(lang, push_text::K::NeverDelivered)) |
| 147 | 142 | } |
crates/forge-web/src/pages/settings_sessions.rsmodified+3 -3
| @@ -119,9 +119,9 @@ async fn session_detail_view( | ||
| 119 | 119 | <div><dt>(t(lang, Key::UserAgent))</dt><dd>(user_agent.as_str())</dd></div> |
| 120 | 120 | <div><dt>(t(lang, Key::SignInIp))</dt><dd>(sign_in_ip.as_str())</dd></div> |
| 121 | 121 | <div><dt>(t(lang, Key::LastIp))</dt><dd>(last_ip.as_str())</dd></div> |
| 122 | - <div><dt>(t(lang, Key::SignedIn))</dt><dd>rel_time(lang: lang, stamp: session.created_at.as_str()) " (" (session.created_at.as_str()) ")"</dd></div> | |
| 123 | - <div><dt>(t(lang, Key::LastSeenAt))</dt><dd>rel_time(lang: lang, stamp: session.last_seen.as_str()) " (" (session.last_seen.as_str()) ")"</dd></div> | |
| 124 | - <div><dt>(t(lang, Key::ExpiresAt))</dt><dd>rel_time(lang: lang, stamp: session.expires_at.as_str()) " (" (session.expires_at.as_str()) ")"</dd></div> | |
| 122 | + <div><dt>(t(lang, Key::SignedIn))</dt><dd>rel_time(lang: lang, stamp: session.created_at.as_str())</dd></div> | |
| 123 | + <div><dt>(t(lang, Key::LastSeenAt))</dt><dd>rel_time(lang: lang, stamp: session.last_seen.as_str())</dd></div> | |
| 124 | + <div><dt>(t(lang, Key::ExpiresAt))</dt><dd>rel_time(lang: lang, stamp: session.expires_at.as_str())</dd></div> | |
| 125 | 125 | </dl> |
| 126 | 126 | </section> |
| 127 | 127 | <section class="card"> |
crates/forge-web/src/pages/settings_tokens.rsmodified+4 -3
| @@ -24,7 +24,7 @@ use crate::i18n::releases_ci::{self as rc, K as RC}; | ||
| 24 | 24 | use crate::i18n::{self, Key, Lang, t, token_name_length}; |
| 25 | 25 | use crate::pages::admin_runners::confirm_post; |
| 26 | 26 | use crate::state::AppState; |
| 27 | -use crate::views::{alert, rel_time, rel_time_or_never, shell}; | |
| 27 | +use crate::views::{alert, empty_state, rel_time, rel_time_or_never, shell}; | |
| 28 | 28 | |
| 29 | 29 | /// Scopes are fixed to `repo` for M1. |
| 30 | 30 | const SCOPES: &[&str] = &["repo"]; |
| @@ -102,7 +102,8 @@ async fn tokens_view( | ||
| 102 | 102 | } |
| 103 | 103 | <section class="card"> |
| 104 | 104 | if tokens.is_empty() { |
| 105 | - <p class="muted">(t(lang, Key::NoAccessTokens))</p> | |
| 105 | + empty_state(title: t(lang, Key::NoAccessTokens), | |
| 106 | + <a class="button" href="#add-token">(t(lang, Key::NewToken))</a>) | |
| 106 | 107 | } else { |
| 107 | 108 | <ul class="item-list"> |
| 108 | 109 | for token in tokens.into_iter() { |
| @@ -117,7 +118,7 @@ async fn tokens_view( | ||
| 117 | 118 | </ul> |
| 118 | 119 | } |
| 119 | 120 | </section> |
| 120 | - <section class="card"> | |
| 121 | + <section class="card" id="add-token"> | |
| 121 | 122 | <h2>(t(lang, Key::NewToken))</h2> |
| 122 | 123 | if let Some(message) = error { |
| 123 | 124 | alert(message: message.as_str()) |
crates/forge-web/src/pages/snippets.rsmodified+16 -18
| @@ -27,7 +27,7 @@ use crate::pages::snippets_live::{bump_snippet, item_live_url, list_live_url}; | ||
| 27 | 27 | use crate::render::highlight::highlight_lines; |
| 28 | 28 | use crate::render::markdown::render_markdown; |
| 29 | 29 | use crate::state::AppState; |
| 30 | -use crate::views::{alert, shell, user_facing_message}; | |
| 30 | +use crate::views::{alert, empty_state, rel_time, shell, user_facing_message}; | |
| 31 | 31 | |
| 32 | 32 | path_param!(id); |
| 33 | 33 | |
| @@ -201,7 +201,8 @@ struct ListRow { | ||
| 201 | 201 | owner: String, |
| 202 | 202 | visibility: &'static str, |
| 203 | 203 | /// The file count and the last update, as one line. |
| 204 | - meta: String, | |
| 204 | + files: String, | |
| 205 | + updated_at: String, | |
| 205 | 206 | } |
| 206 | 207 | |
| 207 | 208 | fn visibility_label(lang: Lang, visibility: SnippetVisibility) -> &'static str { |
| @@ -237,13 +238,6 @@ fn file_view(state: &AppState, snippet: &Snippet, file: &SnippetFile) -> FileVie | ||
| 237 | 238 | } |
| 238 | 239 | } |
| 239 | 240 | |
| 240 | -/// `2026-10-19T18:39:50.4389Z` as `2026-10-19 18:39`: stored timestamps carry nanoseconds. | |
| 241 | -fn short_time(stamp: &str) -> String { | |
| 242 | - stamp | |
| 243 | - .get(..16) | |
| 244 | - .map_or_else(|| stamp.to_owned(), |s| s.replace('T', " ")) | |
| 245 | -} | |
| 246 | - | |
| 247 | 241 | /// The snippet if the viewer may read it, else 404. |
| 248 | 242 | pub(crate) async fn readable( |
| 249 | 243 | cx: &Cx, |
| @@ -282,7 +276,11 @@ async fn snippet_list_body( | ||
| 282 | 276 | </section> |
| 283 | 277 | <section class="card"> |
| 284 | 278 | if rows.is_empty() { |
| 285 | - <p class="muted">(g::t(lang, K::NoSnippets))</p> | |
| 279 | + empty_state(title: g::t(lang, K::NoSnippets), | |
| 280 | + if signed_in { | |
| 281 | + <a class="button primary" href="/snippets/new">(g::t(lang, K::NewSnippet))</a> | |
| 282 | + } | |
| 283 | + ) | |
| 286 | 284 | } else { |
| 287 | 285 | <ul class="item-list snippet-list"> |
| 288 | 286 | for row in rows.into_iter() { |
| @@ -290,7 +288,7 @@ async fn snippet_list_body( | ||
| 290 | 288 | <div class="item-main"> |
| 291 | 289 | <a href=(format!("/snippets/{}", row.id))><strong>(row.title)</strong></a> |
| 292 | 290 | <span class="muted small"> |
| 293 | - (row.owner) " · " (row.visibility) " · " (row.meta) | |
| 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)) | |
| 294 | 292 | </span> |
| 295 | 293 | </div> |
| 296 | 294 | </li> |
| @@ -452,7 +450,7 @@ async fn snippet_body( | ||
| 452 | 450 | owner: &str, |
| 453 | 451 | description: &str, |
| 454 | 452 | visibility: &'static str, |
| 455 | - updated: &str, | |
| 453 | + updated_at: &str, | |
| 456 | 454 | files: Vec<FileView>, |
| 457 | 455 | owner_csrf: Option<String>, |
| 458 | 456 | live: Option<String>, |
| @@ -464,7 +462,7 @@ async fn snippet_body( | ||
| 464 | 462 | Ok(view! { |
| 465 | 463 | <section class="page-head snippet-view-head" data-live=(live.as_deref())> |
| 466 | 464 | <h1>(title)</h1> |
| 467 | - <span class="muted small">(owner) " · " (visibility) " · " (g::updated_on(lang, updated))</span> | |
| 465 | + <span class="muted small">(owner) " · " (visibility) " · " (g::updated_before(lang)) rel_time(lang: lang, stamp: updated_at) (g::updated_after(lang))</span> | |
| 468 | 466 | </section> |
| 469 | 467 | if !description.is_empty() { |
| 470 | 468 | <p class="snippet-description">(description)</p> |
| @@ -527,7 +525,7 @@ async fn revisions_body( | ||
| 527 | 525 | <div class="item-main"> |
| 528 | 526 | <strong>(g::t(lang, K::RevisionLabel))(rev.number)</strong> |
| 529 | 527 | <span class="muted small"> |
| 530 | - (rev.author) " · " (rev.at) " · " (rev.file_names) | |
| 528 | + (rev.author) " · " rel_time(lang: lang, stamp: rev.at.as_str()) " · " (rev.file_names) | |
| 531 | 529 | </span> |
| 532 | 530 | </div> |
| 533 | 531 | </li> |
| @@ -578,7 +576,8 @@ async fn snippets_list(cx: &Cx) -> Result<impl View> { | ||
| 578 | 576 | title: s.title, |
| 579 | 577 | owner: s.owner_name, |
| 580 | 578 | visibility: visibility_label(lang, s.visibility), |
| 581 | - meta: g::files_updated(lang, s.file_count, &short_time(&s.updated_at)), | |
| 579 | + files: g::files_count(lang, s.file_count), | |
| 580 | + updated_at: s.updated_at, | |
| 582 | 581 | }) |
| 583 | 582 | .collect(); |
| 584 | 583 | let signed_in = viewer.is_some(); |
| @@ -675,13 +674,12 @@ async fn snippet_view(cx: &Cx) -> Result<impl View> { | ||
| 675 | 674 | Some((user, session)) if user.id == snippet.owner_id => Some(session.csrf_token.clone()), |
| 676 | 675 | _ => None, |
| 677 | 676 | }; |
| 678 | - let updated = short_time(&snippet.updated_at); | |
| 679 | 677 | let visibility = visibility_label(lang, snippet.visibility); |
| 680 | 678 | Ok(view! { |
| 681 | 679 | shell(title: snippet.title.as_str(), viewer: viewer.as_ref(), |
| 682 | 680 | snippet_body(lang: lang, snippet_id: snippet.id.as_str(), title: snippet.title.as_str(), |
| 683 | 681 | owner: snippet.owner_name.as_str(), description: snippet.description.as_str(), |
| 684 | - visibility: visibility, updated: updated.as_str(), files: files, | |
| 682 | + visibility: visibility, updated_at: snippet.updated_at.as_str(), files: files, | |
| 685 | 683 | owner_csrf: owner_csrf, live: Some(item_live_url(snippet.id.as_str()))) |
| 686 | 684 | ) |
| 687 | 685 | }) |
| @@ -779,7 +777,7 @@ async fn snippet_revisions(cx: &Cx) -> Result<impl View> { | ||
| 779 | 777 | .map(|(index, rev)| RevisionView { |
| 780 | 778 | number: index + 1, |
| 781 | 779 | author: rev.author_name, |
| 782 | - at: short_time(&rev.created_at), | |
| 780 | + at: rev.created_at.clone(), | |
| 783 | 781 | file_names: rev |
| 784 | 782 | .files |
| 785 | 783 | .iter() |
crates/forge-web/src/pages/wiki.rsmodified+13 -13
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | use std::path::PathBuf; |
| 9 | 9 | |
| 10 | 10 | use forge_core::AuditAction; |
| 11 | -use forge_core::tz::format_in_tz; | |
| 11 | +use forge_core::time::stamp_from_unix; | |
| 12 | 12 | use forge_git::repo::wiki_path; |
| 13 | 13 | use forge_git::wiki::{self, MAX_PAGE_BYTES, PageEdit, PageRevision, valid_page_name}; |
| 14 | 14 | use serde::Deserialize; |
| @@ -29,7 +29,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo}; | ||
| 29 | 29 | use crate::pages::wiki_live::{bump_wiki, page_live_url, wiki_live_url}; |
| 30 | 30 | use crate::render::markdown::render_markdown; |
| 31 | 31 | use crate::state::AppState; |
| 32 | -use crate::views::{alert, repo_href, shell}; | |
| 32 | +use crate::views::{alert, empty_state, rel_time, repo_href, shell}; | |
| 33 | 33 | |
| 34 | 34 | path_param!(owner); |
| 35 | 35 | path_param!(repo); |
| @@ -134,13 +134,13 @@ pub struct RevisionRow { | ||
| 134 | 134 | pub subject: String, |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | -fn revision_rows(ctx: &RepoCtx, revs: &[PageRevision], tz: &str) -> Vec<RevisionRow> { | |
| 137 | +fn revision_rows(ctx: &RepoCtx, revs: &[PageRevision]) -> Vec<RevisionRow> { | |
| 138 | 138 | revs.iter() |
| 139 | 139 | .map(|rev| RevisionRow { |
| 140 | 140 | short: rev.oid.chars().take(10).collect(), |
| 141 | 141 | href: repo_href(&ctx.repo.owner_name, &ctx.repo.name, "commit", &rev.oid), |
| 142 | 142 | author: rev.author.clone(), |
| 143 | - when: format_in_tz(rev.at, tz), | |
| 143 | + when: stamp_from_unix(rev.at).unwrap_or_default(), | |
| 144 | 144 | subject: rev.subject.clone(), |
| 145 | 145 | }) |
| 146 | 146 | .collect() |
| @@ -220,10 +220,11 @@ async fn wiki_empty_body( | ||
| 220 | 220 | let new = repo_href(&owner, &repo, "wiki", "-/new"); |
| 221 | 221 | Ok(view! { |
| 222 | 222 | <section class="card wiki-page"> |
| 223 | - <p class="muted">(g::t(lang, K::WikiNoPages))</p> | |
| 224 | - if can_write { | |
| 225 | - <a class="button primary" href=(new)>(g::t(lang, K::CreateFirstPage))</a> | |
| 226 | - } | |
| 223 | + empty_state(title: g::t(lang, K::WikiNoPages), | |
| 224 | + if can_write { | |
| 225 | + <a class="button primary" href=(new.as_str())>(g::t(lang, K::CreateFirstPage))</a> | |
| 226 | + } | |
| 227 | + ) | |
| 227 | 228 | </section> |
| 228 | 229 | }) |
| 229 | 230 | } |
| @@ -245,7 +246,7 @@ async fn wiki_list_body( | ||
| 245 | 246 | Ok(view! { |
| 246 | 247 | <section class="card wiki-page"> |
| 247 | 248 | if rows.is_empty() { |
| 248 | - <p class="muted">(g::t(lang, K::NoPagesYet))</p> | |
| 249 | + empty_state(title: g::t(lang, K::NoPagesYet)) | |
| 249 | 250 | } else { |
| 250 | 251 | <ul class="item-list wiki-pages"> |
| 251 | 252 | for (title, href) in rows.into_iter() { |
| @@ -262,7 +263,7 @@ async fn wiki_history_body(lang: Lang, rows: Vec<RevisionRow>) -> Result<impl Vi | ||
| 262 | 263 | Ok(view! { |
| 263 | 264 | <section class="card wiki-page"> |
| 264 | 265 | if rows.is_empty() { |
| 265 | - <p class="muted">(g::t(lang, K::NoChangesYet))</p> | |
| 266 | + empty_state(title: g::t(lang, K::NoChangesYet)) | |
| 266 | 267 | } else { |
| 267 | 268 | <div class="table-wrap"> |
| 268 | 269 | <table class="table wiki-history"> |
| @@ -272,7 +273,7 @@ async fn wiki_history_body(lang: Lang, rows: Vec<RevisionRow>) -> Result<impl Vi | ||
| 272 | 273 | <td class="nowrap"><a href=(row.href)><code>(row.short.as_str())</code></a></td> |
| 273 | 274 | <td>(row.subject.as_str())</td> |
| 274 | 275 | <td class="muted small nowrap">(row.author.as_str())</td> |
| 275 | - <td class="muted small nowrap">(row.when.as_str())</td> | |
| 276 | + <td class="muted small nowrap">rel_time(lang: lang, stamp: row.when.as_str())</td> | |
| 276 | 277 | </tr> |
| 277 | 278 | } |
| 278 | 279 | </tbody> |
| @@ -457,8 +458,7 @@ async fn wiki_page_history(cx: &Cx) -> Result<impl View> { | ||
| 457 | 458 | let dir = wiki_dir(state, &ctx)?; |
| 458 | 459 | let git = state.git.clone(); |
| 459 | 460 | let revs = wiki::page_history(&git, &dir, &page_name).await?; |
| 460 | - let tz = ctx.viewer_tz().to_owned(); | |
| 461 | - let rows = revision_rows(&ctx, &revs, &tz); | |
| 461 | + let rows = revision_rows(&ctx, &revs); | |
| 462 | 462 | let owner_name = ctx.repo.owner_name.clone(); |
| 463 | 463 | let repo_name = ctx.repo.name.clone(); |
| 464 | 464 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
crates/forge-web/src/raw.rsmodified+4 -2
| @@ -37,8 +37,10 @@ pub(crate) const LINK_TTL_SECS: i64 = 600; | ||
| 37 | 37 | |
| 38 | 38 | const CSP: &str = "default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; sandbox"; |
| 39 | 39 | const CORP: &str = "cross-origin"; |
| 40 | -pub(crate) const CACHE_PRIVATE: &str = "private, max-age=300"; | |
| 41 | -pub(crate) const CACHE_PUBLIC: &str = "public, max-age=300"; | |
| 40 | +/// Raw responses revalidate on every use (an unchanged blob answers 304 through If-None-Match), | |
| 41 | +/// so a repo made private, or a reader who lost access, stops being served at once. | |
| 42 | +pub(crate) const CACHE_PRIVATE: &str = "private, no-cache"; | |
| 43 | +pub(crate) const CACHE_PUBLIC: &str = "public, no-cache"; | |
| 42 | 44 | pub(crate) const CACHE_NONE: &str = "no-store"; |
| 43 | 45 | const TEXT: &str = "text/plain; charset=utf-8"; |
| 44 | 46 | pub(crate) const OCTET: &str = "application/octet-stream"; |
crates/forge-web/src/views/heatmap.rsmodified+3 -2
| @@ -209,7 +209,8 @@ struct DayView { | ||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 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. | |
| 212 | +/// plain calendar when the day is the selected one. The anchor brings a full page load back to the | |
| 213 | +/// calendar; nav.js swaps in place and keeps the scroll (`data-keep-scroll`), so it is not used there. | |
| 213 | 214 | fn day_href(date: (i64, i64, i64), selected: bool) -> String { |
| 214 | 215 | if selected { |
| 215 | 216 | "/#contributions-h".to_owned() |
| @@ -461,7 +462,7 @@ pub async fn contribution_calendar( | ||
| 461 | 462 | <div class="heat-grid" role="group" aria-label=(summary.as_str())> |
| 462 | 463 | for cell in cells.into_iter() { |
| 463 | 464 | if let Some(href) = cell.href { |
| 464 | - <a class=(cell.class.as_str()) href=(href.as_str()) title=(cell.title.as_str())></a> | |
| 465 | + <a class=(cell.class.as_str()) href=(href.as_str()) title=(cell.title.as_str()) data-keep-scroll="true"></a> | |
| 465 | 466 | } else { |
| 466 | 467 | <span class=(cell.class.as_str()) title=(cell.title.as_str())></span> |
| 467 | 468 | } |
crates/forge-web/src/views/mod.rsmodified+34 -3
| @@ -26,6 +26,7 @@ use topcoat::router::{Body, Next, layer}; | ||
| 26 | 26 | use topcoat::view::{Child, Unescaped, View, component, view}; |
| 27 | 27 | |
| 28 | 28 | use crate::i18n::admin::{self as ad, K as AK}; |
| 29 | +use crate::i18n::browse as br; | |
| 29 | 30 | use crate::i18n::code::{self as g, K}; |
| 30 | 31 | use crate::i18n::community::{self as cm, K as CK}; |
| 31 | 32 | use crate::i18n::link::{self as lk, K as LinkKey}; |
| @@ -282,6 +283,7 @@ pub async fn shell( | ||
| 282 | 283 | ); |
| 283 | 284 | let anonymous = viewer.is_none(); |
| 284 | 285 | let search_label = o::t(lang, OK::SearchPublicRepos); |
| 286 | + let palette_label = br::t(lang, br::K::PaletteOpen).to_owned(); | |
| 285 | 287 | let notif_label = t(lang, Key::Notifications); |
| 286 | 288 | let menu_label = t(lang, Key::SiteMenu); |
| 287 | 289 | let side_repos_menu = side_repos.clone(); |
| @@ -310,7 +312,7 @@ pub async fn shell( | ||
| 310 | 312 | } |
| 311 | 313 | <script src=(NAV_SCRIPT_HREF) defer="defer"></script> |
| 312 | 314 | </head> |
| 313 | - <body data-link-restarting=(lk::t(lang, LinkKey::Restarting)) data-link-back=(lk::t(lang, LinkKey::BackSubmit))> | |
| 315 | + <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))> | |
| 314 | 316 | <header class="topbar"> |
| 315 | 317 | if signed_in { |
| 316 | 318 | <details class="nav-toggle"> |
| @@ -361,6 +363,15 @@ pub async fn shell( | ||
| 361 | 363 | </button> |
| 362 | 364 | </form> |
| 363 | 365 | if let Some((username, csrf, avatar_src, is_admin)) = nav { |
| 366 | + // The palette's strings ride on its button, so nav.js builds the dialog in the viewer's language. | |
| 367 | + <button type="button" class="palette-open" data-palette-open="" aria-label=(palette_label.as_str()) title=(palette_label.as_str()) | |
| 368 | + data-placeholder=(br::t(lang, br::K::PalettePlaceholder)) data-repos=(br::t(lang, br::K::PaletteRepos)) | |
| 369 | + data-orgs=(o::t(lang, OK::Organizations)) data-pages=(br::t(lang, br::K::PalettePages)) | |
| 370 | + data-empty=(br::t(lang, br::K::PaletteNoMatches)) data-loading=(br::t(lang, br::K::PaletteLoading)) | |
| 371 | + data-failed=(br::t(lang, br::K::PaletteFailed)) data-hint=(br::t(lang, br::K::FinderHint))> | |
| 372 | + <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg> | |
| 373 | + <kbd>"Ctrl K"</kbd> | |
| 374 | + </button> | |
| 364 | 375 | <a class="icon-btn bell" href="/notifications" aria-label=(notif_label) title=(notif_label)> |
| 365 | 376 | <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> |
| 366 | 377 | if let Some(badge) = unread_badge { |
| @@ -526,7 +537,7 @@ pub struct Section { | ||
| 526 | 537 | pub live: &'static str, |
| 527 | 538 | } |
| 528 | 539 | |
| 529 | -fn admin_items(lang: Lang) -> Vec<NavItem> { | |
| 540 | +pub fn admin_items(lang: Lang) -> Vec<NavItem> { | |
| 530 | 541 | let item = |key, href: &'static str, label, icon| NavItem { |
| 531 | 542 | key, |
| 532 | 543 | href: href.to_owned(), |
| @@ -590,7 +601,7 @@ fn org_items(lang: Lang, org: &str) -> Vec<NavItem> { | ||
| 590 | 601 | ] |
| 591 | 602 | } |
| 592 | 603 | |
| 593 | -fn settings_items(lang: Lang) -> Vec<NavItem> { | |
| 604 | +pub fn settings_items(lang: Lang) -> Vec<NavItem> { | |
| 594 | 605 | let item = |key, href: &'static str, label, icon| NavItem { |
| 595 | 606 | key, |
| 596 | 607 | href: href.to_owned(), |
| @@ -858,6 +869,26 @@ pub async fn alert(message: &str) -> Result<impl View> { | ||
| 858 | 869 | }) |
| 859 | 870 | } |
| 860 | 871 | |
| 872 | +/// What a list shows when it has nothing yet: one line saying so, an optional hint, and an optional | |
| 873 | +/// next step as the child (a button, a link, or a command to copy). Pages use it so every empty list | |
| 874 | +/// reads the same way. | |
| 875 | +#[component] | |
| 876 | +pub async fn empty_state( | |
| 877 | + title: &str, | |
| 878 | + #[default] hint: Option<&str>, | |
| 879 | + #[default] child: Child<'_>, | |
| 880 | +) -> Result<impl View> { | |
| 881 | + Ok(view! { | |
| 882 | + <div class="empty-state"> | |
| 883 | + <p class="empty-state-title">(title)</p> | |
| 884 | + if let Some(hint) = hint { | |
| 885 | + <p class="empty-state-hint">(hint)</p> | |
| 886 | + } | |
| 887 | + <div class="empty-state-action">(child)</div> | |
| 888 | + </div> | |
| 889 | + }) | |
| 890 | +} | |
| 891 | + | |
| 861 | 892 | /// Owned copy of a user-facing error message, for the errors a form can recover from. |
| 862 | 893 | /// Returns `None` for internal failures, which should propagate as 500s. |
| 863 | 894 | pub fn user_facing_message(err: &CoreError) -> Option<String> { |
style/_account_admin.scssmodified+2 -0
| @@ -231,6 +231,8 @@ | ||
| 231 | 231 | top: calc(100% + 6px); |
| 232 | 232 | z-index: 10; |
| 233 | 233 | width: min(300px, calc(100vw - 32px)); |
| 234 | + // The general rule caps the pop at its summary's width; here it hangs out to the left. | |
| 235 | + max-width: none; | |
| 234 | 236 | padding: 12px 14px; |
| 235 | 237 | border: 1px solid var(--border); |
| 236 | 238 | border-radius: var(--radius-lg); |
style/_drafts.scssadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +// The note under a comment draft that nav.js put back into its field. Small and quiet, so it reads as | |
| 2 | +// a hint, not as part of the form. | |
| 3 | +.draft-note { | |
| 4 | + margin: 4px 0 0; | |
| 5 | + font-size: 0.8125rem; | |
| 6 | + color: var(--muted); | |
| 7 | +} |
style/_empty.scssadded+44 -0
| @@ -0,0 +1,44 @@ | ||
| 1 | +// An empty list (views::empty_state): a quiet centred block with the next step under it. | |
| 2 | +.empty-state { | |
| 3 | + display: flex; | |
| 4 | + flex-direction: column; | |
| 5 | + align-items: center; | |
| 6 | + gap: 6px; | |
| 7 | + padding: 28px 16px; | |
| 8 | + text-align: center; | |
| 9 | + color: var(--muted); | |
| 10 | + | |
| 11 | + .empty-state-title { | |
| 12 | + margin: 0; | |
| 13 | + color: var(--text-2); | |
| 14 | + font-weight: 600; | |
| 15 | + } | |
| 16 | + | |
| 17 | + .empty-state-hint { | |
| 18 | + max-width: 52ch; | |
| 19 | + margin: 0; | |
| 20 | + font-size: 0.875rem; | |
| 21 | + } | |
| 22 | + | |
| 23 | + .empty-state-action { | |
| 24 | + display: flex; | |
| 25 | + flex-wrap: wrap; | |
| 26 | + justify-content: center; | |
| 27 | + gap: 8px; | |
| 28 | + margin-top: 8px; | |
| 29 | + | |
| 30 | + &:empty { | |
| 31 | + display: none; | |
| 32 | + } | |
| 33 | + | |
| 34 | + > button, | |
| 35 | + > .button { | |
| 36 | + align-self: center; | |
| 37 | + } | |
| 38 | + | |
| 39 | + pre, | |
| 40 | + code { | |
| 41 | + text-align: left; | |
| 42 | + } | |
| 43 | + } | |
| 44 | +} |
style/_feedback.scssadded+74 -0
| @@ -0,0 +1,74 @@ | ||
| 1 | +// Submit feedback. A button whose POST is slow gets is-busy (nav.js adds it after 150 ms, and only | |
| 2 | +// while the request is in flight). It dims and shows a small spinner; it is never disabled. Once the | |
| 3 | +// server confirmed the save, a done-tick sits after the button for a moment, then fades out. | |
| 4 | + | |
| 5 | +.is-busy { | |
| 6 | + cursor: progress; | |
| 7 | + opacity: 0.75; | |
| 8 | + | |
| 9 | + &::after { | |
| 10 | + content: ""; | |
| 11 | + display: inline-block; | |
| 12 | + width: 12px; | |
| 13 | + height: 12px; | |
| 14 | + margin-left: 8px; | |
| 15 | + vertical-align: -2px; | |
| 16 | + border: 2px solid currentColor; | |
| 17 | + border-right-color: transparent; | |
| 18 | + border-radius: 50%; | |
| 19 | + animation: busy-spin 0.7s linear infinite; | |
| 20 | + } | |
| 21 | +} | |
| 22 | + | |
| 23 | +@keyframes busy-spin { | |
| 24 | + to { | |
| 25 | + transform: rotate(360deg); | |
| 26 | + } | |
| 27 | +} | |
| 28 | + | |
| 29 | +.done-tick { | |
| 30 | + display: inline-flex; | |
| 31 | + align-items: center; | |
| 32 | + gap: 4px; | |
| 33 | + margin-left: 8px; | |
| 34 | + color: var(--ok); | |
| 35 | + font-size: 0.875em; | |
| 36 | + font-weight: 500; | |
| 37 | + white-space: nowrap; | |
| 38 | + animation: done-tick 2.2s ease-out both; | |
| 39 | + | |
| 40 | + .ico { | |
| 41 | + width: 14px; | |
| 42 | + height: 14px; | |
| 43 | + fill: none; | |
| 44 | + stroke: currentColor; | |
| 45 | + stroke-width: 2.2; | |
| 46 | + stroke-linecap: round; | |
| 47 | + stroke-linejoin: round; | |
| 48 | + } | |
| 49 | +} | |
| 50 | + | |
| 51 | +// Quick fade in, hold, then fade out over the last part of the 2.2 s. | |
| 52 | +@keyframes done-tick { | |
| 53 | + 0% { | |
| 54 | + opacity: 0; | |
| 55 | + } | |
| 56 | + 12%, | |
| 57 | + 78% { | |
| 58 | + opacity: 1; | |
| 59 | + } | |
| 60 | + 100% { | |
| 61 | + opacity: 0; | |
| 62 | + } | |
| 63 | +} | |
| 64 | + | |
| 65 | +@media (prefers-reduced-motion: reduce) { | |
| 66 | + // No spin: the dimmed label alone shows it is busy. | |
| 67 | + .is-busy::after { | |
| 68 | + display: none; | |
| 69 | + } | |
| 70 | + | |
| 71 | + .done-tick { | |
| 72 | + animation: none; | |
| 73 | + } | |
| 74 | +} |
style/_motion.scssadded+70 -0
| @@ -0,0 +1,70 @@ | ||
| 1 | +// Motion for what the reader does: a button they press, a menu they open, a stepper they click, the | |
| 2 | +// banner they dismiss. The classes below are added by nav.js on the reader's own action, never on a | |
| 3 | +// live re-render, so a page that updates itself does not move on its own. Inline disclosures slide in | |
| 4 | +// nav.js (slideDetails). Individual `translate` and `scale` are used, so a panel placed with | |
| 5 | +// `transform` keeps its place. | |
| 6 | + | |
| 7 | +$ease-out: cubic-bezier(0.2, 0, 0, 1); | |
| 8 | + | |
| 9 | +// A press sinks the button a little. | |
| 10 | +.button, | |
| 11 | +button { | |
| 12 | + transition: background-color 0.15s ease, scale 0.1s ease; | |
| 13 | + | |
| 14 | + &:active:not(:disabled) { | |
| 15 | + scale: 0.97; | |
| 16 | + } | |
| 17 | +} | |
| 18 | + | |
| 19 | +// A menu or popover the reader opens drops in from its summary. | |
| 20 | +details.pop[open] > :not(summary) { | |
| 21 | + animation: pop-in 0.14s $ease-out; | |
| 22 | +} | |
| 23 | + | |
| 24 | +@keyframes pop-in { | |
| 25 | + from { | |
| 26 | + opacity: 0; | |
| 27 | + translate: 0 -4px; | |
| 28 | + scale: 0.98; | |
| 29 | + } | |
| 30 | +} | |
| 31 | + | |
| 32 | +// The phone branch switcher is a sheet from the bottom: it rises instead. | |
| 33 | +@media (max-width: 600px) { | |
| 34 | + details.ref-select.pop[open] > .ref-menu { | |
| 35 | + animation: sheet-up 0.2s $ease-out; | |
| 36 | + } | |
| 37 | +} | |
| 38 | + | |
| 39 | +@keyframes sheet-up { | |
| 40 | + from { | |
| 41 | + translate: 0 100%; | |
| 42 | + } | |
| 43 | +} | |
| 44 | + | |
| 45 | +// A stepper's number flashes the accent when a click moves it. | |
| 46 | +input.tick { | |
| 47 | + animation: tick 0.3s ease-out; | |
| 48 | +} | |
| 49 | + | |
| 50 | +@keyframes tick { | |
| 51 | + from { | |
| 52 | + color: var(--accent); | |
| 53 | + } | |
| 54 | +} | |
| 55 | + | |
| 56 | +@media (prefers-reduced-motion: reduce) { | |
| 57 | + .button, | |
| 58 | + button { | |
| 59 | + transition: none; | |
| 60 | + | |
| 61 | + &:active:not(:disabled) { | |
| 62 | + scale: none; | |
| 63 | + } | |
| 64 | + } | |
| 65 | + | |
| 66 | + details.pop[open] > :not(summary), | |
| 67 | + input.tick { | |
| 68 | + animation: none; | |
| 69 | + } | |
| 70 | +} |
style/_palette.scssadded+174 -0
| @@ -0,0 +1,174 @@ | ||
| 1 | +// Command palette (Ctrl+K): a dialog over the page with a search row, one scrolling list grouped by | |
| 2 | +// kind, and a footer note. It follows the branch switcher's command palette look. | |
| 3 | + | |
| 4 | +// The topbar button that opens it: a search icon and the shortcut, sized like the other top bar links. | |
| 5 | +.palette-open { | |
| 6 | + display: inline-flex; | |
| 7 | + align-items: center; | |
| 8 | + flex: none; | |
| 9 | + align-self: center; // buttons default to flex-start, which lifts it off the top bar's centre line | |
| 10 | + gap: 6px; | |
| 11 | + height: 36px; | |
| 12 | + padding: 0 8px; | |
| 13 | + color: var(--muted); | |
| 14 | + background: var(--surface); | |
| 15 | + border: 1px solid var(--border); | |
| 16 | + border-radius: var(--radius-md); | |
| 17 | + cursor: pointer; | |
| 18 | + | |
| 19 | + &:hover { | |
| 20 | + color: var(--text); | |
| 21 | + border-color: var(--border-strong); | |
| 22 | + } | |
| 23 | + | |
| 24 | + kbd { | |
| 25 | + padding: 0 5px; | |
| 26 | + font-family: var(--mono); | |
| 27 | + font-size: 0.6875rem; | |
| 28 | + line-height: 18px; | |
| 29 | + color: var(--text-2); | |
| 30 | + background: var(--surface-2); | |
| 31 | + border: 1px solid var(--border-strong); | |
| 32 | + border-radius: var(--radius-sm); | |
| 33 | + } | |
| 34 | +} | |
| 35 | + | |
| 36 | +// Phones have no keyboard, so the shortcut hint goes and the button is only the icon. | |
| 37 | +@media (max-width: 600px) { | |
| 38 | + .palette-open kbd { | |
| 39 | + display: none; | |
| 40 | + } | |
| 41 | +} | |
| 42 | + | |
| 43 | +dialog.palette { | |
| 44 | + width: min(560px, calc(100vw - 32px)); | |
| 45 | + max-height: min(70vh, 520px); | |
| 46 | + margin: 12vh auto 0; | |
| 47 | + padding: 0; | |
| 48 | + color: var(--text); | |
| 49 | + background: var(--surface); | |
| 50 | + border: 1px solid var(--border-strong); | |
| 51 | + border-radius: var(--radius-lg); | |
| 52 | + box-shadow: var(--shadow); | |
| 53 | + | |
| 54 | + &::backdrop { | |
| 55 | + background: rgba(20, 24, 22, 0.45); | |
| 56 | + } | |
| 57 | + | |
| 58 | + &[open] { | |
| 59 | + display: flex; | |
| 60 | + flex-direction: column; | |
| 61 | + } | |
| 62 | +} | |
| 63 | + | |
| 64 | +.palette-box { | |
| 65 | + display: flex; | |
| 66 | + flex-direction: column; | |
| 67 | + min-height: 0; | |
| 68 | + flex: 1 1 auto; | |
| 69 | +} | |
| 70 | + | |
| 71 | +// The search row is part of the palette, not a field inside it: no box, only the divider below. | |
| 72 | +.palette-search { | |
| 73 | + flex: none; | |
| 74 | + display: flex; | |
| 75 | + align-items: center; | |
| 76 | + gap: 10px; | |
| 77 | + padding: 0 12px; | |
| 78 | + color: var(--muted); | |
| 79 | + border-bottom: 1px solid var(--border); | |
| 80 | + | |
| 81 | + &:focus-within { | |
| 82 | + color: var(--accent); | |
| 83 | + } | |
| 84 | +} | |
| 85 | + | |
| 86 | +.palette-input { | |
| 87 | + flex: 1 1 auto; | |
| 88 | + min-width: 0; | |
| 89 | + height: 46px; | |
| 90 | + padding: 0; | |
| 91 | + font: inherit; | |
| 92 | + font-size: 15px; | |
| 93 | + color: var(--text); | |
| 94 | + background: transparent; | |
| 95 | + border: 0; | |
| 96 | + | |
| 97 | + &::placeholder { | |
| 98 | + color: var(--muted); | |
| 99 | + } | |
| 100 | + | |
| 101 | + &:focus, | |
| 102 | + &:focus-visible { | |
| 103 | + outline: none; | |
| 104 | + box-shadow: none; | |
| 105 | + } | |
| 106 | +} | |
| 107 | + | |
| 108 | +.palette-list { | |
| 109 | + flex: 1 1 auto; | |
| 110 | + min-height: 0; | |
| 111 | + margin: 0; | |
| 112 | + padding: 6px; | |
| 113 | + overflow-y: auto; | |
| 114 | + list-style: none; | |
| 115 | + font-size: 0.875rem; | |
| 116 | + | |
| 117 | + li { | |
| 118 | + margin: 0; | |
| 119 | + } | |
| 120 | + | |
| 121 | + // Group headings: small caps like the branch switcher's, with a dashed rule between groups. | |
| 122 | + .palette-head { | |
| 123 | + padding: 6px 8px 4px; | |
| 124 | + font-size: 11px; | |
| 125 | + font-weight: 600; | |
| 126 | + letter-spacing: 0.06em; | |
| 127 | + text-transform: uppercase; | |
| 128 | + color: var(--muted); | |
| 129 | + } | |
| 130 | + | |
| 131 | + .palette-head:not(:first-child) { | |
| 132 | + margin-top: 6px; | |
| 133 | + padding-top: 10px; | |
| 134 | + border-top: 1px dashed var(--border); | |
| 135 | + } | |
| 136 | + | |
| 137 | + // Options: the selected row (keys or pointer) gets the soft accent fill. | |
| 138 | + li[role="option"] { | |
| 139 | + padding: 7px 10px; | |
| 140 | + color: var(--text); | |
| 141 | + border-radius: var(--radius-md); | |
| 142 | + cursor: pointer; | |
| 143 | + overflow-wrap: anywhere; | |
| 144 | + } | |
| 145 | + | |
| 146 | + li[aria-selected="true"] { | |
| 147 | + background: var(--accent-soft); | |
| 148 | + } | |
| 149 | +} | |
| 150 | + | |
| 151 | +.palette-note { | |
| 152 | + flex: none; | |
| 153 | + margin: 0; | |
| 154 | + padding: 8px 12px; | |
| 155 | + border-top: 1px solid var(--border); | |
| 156 | +} | |
| 157 | + | |
| 158 | +// Phones: the palette spans the screen width and sits at the top, with larger rows to tap. | |
| 159 | +@media (max-width: 600px) { | |
| 160 | + dialog.palette { | |
| 161 | + width: calc(100vw - 16px); | |
| 162 | + max-height: calc(100vh - 16px); | |
| 163 | + margin: 8px auto 0; | |
| 164 | + } | |
| 165 | + | |
| 166 | + .palette-input { | |
| 167 | + height: 52px; | |
| 168 | + font-size: 16px; | |
| 169 | + } | |
| 170 | + | |
| 171 | + .palette-list li[role="option"] { | |
| 172 | + padding: 12px 10px; | |
| 173 | + } | |
| 174 | +} |
style/_shell.scssmodified+4 -2
| @@ -415,7 +415,8 @@ | ||
| 415 | 415 | align-self: start; |
| 416 | 416 | display: block; |
| 417 | 417 | box-sizing: border-box; |
| 418 | - height: calc(100vh - var(--topbar-h)); | |
| 418 | + // Ends at the viewport's bottom while the site banner still shows above it (--shell-top, nav.js). | |
| 419 | + height: calc(100vh - max(var(--topbar-h), var(--shell-top, 0px))); | |
| 419 | 420 | min-width: 0; |
| 420 | 421 | padding: 16px 12px 24px; |
| 421 | 422 | overflow-y: auto; |
| @@ -431,7 +432,8 @@ | ||
| 431 | 432 | |
| 432 | 433 | .shell:has(> .shell-sidebar) .repo-tabs { |
| 433 | 434 | position: fixed; |
| 434 | - top: var(--topbar-h); | |
| 435 | + // nav.js sets --shell-top to where the page body starts, below the site banner when there is one. | |
| 436 | + top: max(var(--topbar-h), var(--shell-top, 0px)); | |
| 435 | 437 | bottom: 0; |
| 436 | 438 | left: 0; |
| 437 | 439 | z-index: 5; |
style/main.scssmodified+6 -1
| @@ -5759,7 +5759,7 @@ html.js form.runner-load[data-dirty-form][data-dirty] .runner-save { | ||
| 5759 | 5759 | top: calc(var(--topbar-h) + 16px); |
| 5760 | 5760 | display: flex; |
| 5761 | 5761 | flex-direction: column; |
| 5762 | - max-height: calc(100dvh - var(--topbar-h) - 104px); | |
| 5762 | + max-height: calc(100dvh - max(var(--topbar-h), var(--shell-top, 0px)) - 104px); | |
| 5763 | 5763 | } |
| 5764 | 5764 | |
| 5765 | 5765 | .ci-side-head, |
| @@ -7754,6 +7754,11 @@ button.ci-job-last { | ||
| 7754 | 7754 | @import "members"; |
| 7755 | 7755 | @import "hooks"; |
| 7756 | 7756 | @import "admin_rows"; |
| 7757 | +@import "motion"; | |
| 7758 | +@import "empty"; | |
| 7759 | +@import "feedback"; | |
| 7760 | +@import "drafts"; | |
| 7761 | +@import "palette"; | |
| 7757 | 7762 | |
| 7758 | 7763 | // A monospace value with its Copy button on the right; long values wrap inside the box. |
| 7759 | 7764 | .copy-box { |