summaryrefslogtreecommitdiffstats
path: root/src/http/render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/render.rs')
-rw-r--r--src/http/render.rs373
1 files changed, 373 insertions, 0 deletions
diff --git a/src/http/render.rs b/src/http/render.rs
new file mode 100644
index 0000000..2fad5c8
--- /dev/null
+++ b/src/http/render.rs
@@ -0,0 +1,373 @@
+//! Template contexts (§12, §13).
+//!
+//! Askama compiles every template into Rust at build time, so a missing field
+//! is a compile error rather than a blank page at 2am. Contexts are built from
+//! live DB state; nothing here writes.
+
+use askama::Template;
+
+/// Everything the shared chrome needs. Embedded in each page context because
+/// askama inheritance passes the whole struct down.
+#[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,
+ /// True when a password gate is configured, so the chrome offers a logout.
+ 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<PublishRow>,
+}
+
+#[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<ReviewRow>,
+}
+
+#[derive(Debug, Clone)]
+pub struct ReviewRow {
+ pub id: i64,
+ pub pkgbase: String,
+ pub version: String,
+ pub kind: String,
+ pub risk: String,
+ pub signals: Vec<String>,
+ 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<Panel>,
+ /// First introductions show the whole recipe instead of a diff (§7.1b).
+ 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<String>,
+ pub missing_deps: Vec<String>,
+ 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<SubRow>,
+}
+
+#[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<NoticeRow>,
+ pub outdated: Vec<StaleRow>,
+ pub missing: Vec<StaleRow>,
+ pub downgrades: Vec<StaleRow>,
+ pub blocked: Vec<BlockedRow>,
+}
+
+#[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 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<String>,
+}
+
+#[derive(Template)]
+#[template(path = "packages.html")]
+pub struct Packages {
+ pub page: Page,
+ pub repo: String,
+ pub rows: Vec<IndexRow>,
+ 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<String>,
+ pub deps_in: Vec<String>,
+ pub deps_out: Vec<String>,
+ pub timeline: Vec<TimelineRow>,
+ pub builds: Vec<BuildLite>,
+}
+
+#[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<BuildRow>,
+ pub recent: Vec<BuildRow>,
+}
+
+#[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<String>,
+ pub steps: Vec<StepRow>,
+ 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<AuditRow>,
+}
+
+#[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<SettingRow>,
+ pub repo: String,
+}
+
+#[derive(Debug, Clone)]
+pub struct SettingRow {
+ pub key: String,
+ pub value: String,
+}
+
+/// Vendored static assets. htmx arrives in P3; until then this serves the
+/// favicon and refuses everything else rather than walking the filesystem.
+pub fn static_asset(name: &str) -> crate::http::Res {
+ use crate::http::Res;
+ match name {
+ "htmx.min.js" => Res::text(404, "htmx is vendored in P3\n".into()),
+ "app.css" => {
+ let s = std::include_str!("../../static/app.css");
+ let mut r = Res::text(200, s.to_string());
+ r.content_type = "text/css".into();
+ r
+ }
+ _ => Res::text(404, "not found\n".into()),
+ }
+}