use askama::Template; #[derive(Debug, Clone)] pub struct Page { pub title: String, pub flash: String, pub has_flash: bool, pub flash_err: bool, pub csrf: String, pub pending: i64, pub running: i64, pub attention: i64, pub nav_reviews: &'static str, pub nav_builds: &'static str, pub nav_attention: &'static str, pub nav_packages: &'static str, pub nav_subscriptions: &'static str, pub nav_audit: &'static str, pub nav_settings: &'static str, pub gated: bool, } impl Page { pub fn new(title: &str, csrf: String) -> Self { Self { title: title.into(), flash: String::new(), has_flash: false, flash_err: false, csrf, pending: 0, running: 0, attention: 0, nav_reviews: "", nav_builds: "", nav_attention: "", nav_packages: "", nav_subscriptions: "", nav_audit: "", nav_settings: "", gated: false, } } pub fn flash(mut self, msg: String, err: bool) -> Self { self.flash = msg; self.has_flash = true; self.flash_err = err; self } } #[derive(Template)] #[template(path = "login.html")] pub struct Login { pub page: Page, pub error: String, } #[derive(Template)] #[template(path = "error.html")] pub struct ErrorPage { pub page: Page, pub status: String, pub message: String, pub detail: String, } #[derive(Template)] #[template(path = "dashboard.html")] pub struct Dashboard { pub page: Page, pub subscriptions: i64, pub index_count: i64, pub pending_reviews: i64, pub running_builds: i64, pub attention: i64, pub publishes: Vec, } #[derive(Debug, Clone)] pub struct PublishRow { pub name: String, pub version: String, pub published_at: String, pub aur_commit: String, pub aur_commit_short: String, } #[derive(Template)] #[template(path = "reviews.html")] pub struct ReviewsPage { pub page: Page, pub rows: Vec, } #[derive(Debug, Clone)] pub struct ReviewRow { pub id: i64, pub pkgbase: String, pub version: String, pub kind: String, pub risk: String, pub signals: Vec, pub age: String, pub revision: i64, } #[derive(Template)] #[template(path = "review.html")] pub struct ReviewDetail { pub page: Page, pub c: ReviewHead, pub base_version: String, pub has_base: bool, pub panels: Vec, pub recipe: String, pub srcinfo: String, pub has_srcinfo: bool, pub sources_resolved: String, pub deps_resolved: String, } #[derive(Debug, Clone)] pub struct ReviewHead { pub id: i64, pub pkgbase: String, pub version: String, pub kind: String, pub is_first: bool, pub risk: String, pub signals: Vec, pub missing_deps: Vec, pub dependents: Vec, pub revision: i64, pub aur_commit: String, pub aur_commit_short: String, pub identity_hash: String, pub diff_digest: String, } #[derive(Debug, Clone)] pub struct Panel { pub title: String, pub body: String, pub empty: bool, pub empty_note: String, } impl Panel { pub fn new(title: &str, body: String) -> Self { Self { title: title.into(), empty: body.trim().is_empty(), empty_note: "no change".into(), body, } } } #[derive(Template)] #[template(path = "subscriptions.html")] pub struct Subscriptions { pub page: Page, pub rows: Vec, } #[derive(Debug, Clone)] pub struct SubRow { pub name: String, pub state: String, pub maintainer: String, pub last_checked: String, pub next_check: String, pub last_error: String, pub has_error: bool, pub pending: i64, pub pause_label: &'static str, } #[derive(Template)] #[template(path = "attention.html")] pub struct Attention { pub page: Page, pub empty: bool, pub notices: Vec, pub unbuilt: Vec, pub outdated: Vec, pub missing: Vec, pub downgrades: Vec, pub blocked: Vec, } #[derive(Debug, Clone)] pub struct UnbuiltRow { pub pkgbase: String, pub approved: String, pub serving: String, pub error: String, pub build_id: String, } #[derive(Debug, Clone)] pub struct NoticeRow { pub id: i64, pub pkgbase: String, pub kind: String, pub severity: String, pub detail: String, pub created_at: String, } #[derive(Debug, Clone)] pub struct StaleRow { pub pkgbase: String, pub dependency: String, pub built_with: String, pub now: String, } #[derive(Debug, Clone)] pub struct BlockedRow { pub id: String, pub id_short: String, pub pkgbase: String, pub blocked_on: Vec, } #[derive(Template)] #[template(path = "packages.html")] pub struct Packages { pub page: Page, pub repo: String, pub rows: Vec, pub snippet: String, } #[derive(Debug, Clone)] pub struct IndexRow { pub name: String, pub version: String, pub arch: String, pub size: String, pub published_at: String, } #[derive(Template)] #[template(path = "package.html")] pub struct PackageDetail { pub page: Page, pub name: String, pub summary: String, pub can_withdraw: bool, pub stale: Vec, pub unbuilt: Vec, pub deps_in: Vec, pub deps_out: Vec, pub timeline: Vec, pub builds: Vec, } #[derive(Debug, Clone)] pub struct TimelineRow { pub version: String, pub state: String, pub aur_commit: String, pub aur_commit_short: String, pub published_at: String, pub approver: String, } #[derive(Template)] #[template(path = "builds.html")] pub struct Builds { pub page: Page, pub rows: Vec, pub recent: Vec, } #[derive(Template)] #[template(path = "builds_table.html")] pub struct BuildsTable { pub page: Page, pub rows: Vec, pub recent: Vec, } #[derive(Debug, Clone)] pub struct BuildLite { pub id: String, pub id_short: String, pub kind: String, pub state: String, pub step: String, } #[derive(Debug, Clone)] pub struct BuildRow { pub id: String, pub id_short: String, pub pkgbase: String, pub version: String, pub kind: String, pub state: String, pub step: String, pub lease: String, pub cancel: bool, pub error: String, } #[derive(Template)] #[template(path = "build.html")] pub struct BuildDetail { pub page: Page, pub id: String, pub id_short: String, pub pkgbase: String, pub version: String, pub kind: String, pub state: String, pub error: String, pub blocked_on: Vec, pub steps: Vec, pub log: String, pub log_lines: usize, pub log_truncated: bool, } #[derive(Debug, Clone)] pub struct StepRow { pub step: String, pub status: String, pub attempt: i64, pub digest: String, pub cls: String, pub error: String, } #[derive(Template)] #[template(path = "audit.html")] pub struct Audit { pub page: Page, pub rows: Vec, } #[derive(Debug, Clone)] pub struct AuditRow { pub at: String, pub actor_kind: String, pub actor: String, pub action: String, pub entity: String, pub entity_id: String, pub detail: String, } #[derive(Template)] #[template(path = "settings.html")] pub struct Settings { pub page: Page, pub rows: Vec, pub repo: String, } #[derive(Debug, Clone)] pub struct SettingRow { pub key: String, pub value: String, } pub fn static_asset(name: &str, accept_gzip: bool) -> crate::http::Res { use crate::http::Res; match name { "app.css" => { let mut r = Res::text(200, std::include_str!("../../static/app.css").to_string()); r.content_type = "text/css".into(); r } "htmx.min.js" => { if accept_gzip { let gz: &[u8] = std::include_bytes!("../../static/htmx.min.js.gz"); let mut r = Res::stream( "text/javascript", std::io::Cursor::new(gz.to_vec()), Some(gz.len()), ); r.header("Content-Encoding", "gzip"); r.header("Cache-Control", "public, max-age=86400"); return r; } let raw: &[u8] = std::include_bytes!("../../static/htmx.min.js"); let mut r = Res::stream( "text/javascript", std::io::Cursor::new(raw.to_vec()), Some(raw.len()), ); r.header("Cache-Control", "public, max-age=86400"); r } _ => Res::text(404, "not found\n".into()), } }