Add typed commit links
This commit is contained in:
parent
0253d2d90b
commit
c3c597897c
10 changed files with 82 additions and 69 deletions
|
|
@ -1,6 +1,7 @@
|
|||
mod api;
|
||||
mod commit;
|
||||
mod index;
|
||||
mod link;
|
||||
mod queue;
|
||||
mod runner;
|
||||
mod r#static;
|
||||
|
|
@ -12,8 +13,8 @@ use crate::{config::Config, somehow};
|
|||
use super::Server;
|
||||
|
||||
pub enum Tab {
|
||||
None,
|
||||
Index,
|
||||
Commit,
|
||||
Queue,
|
||||
}
|
||||
|
||||
|
|
@ -21,20 +22,20 @@ pub enum Tab {
|
|||
pub struct Base {
|
||||
root: String,
|
||||
repo_name: String,
|
||||
current: String,
|
||||
current: &'static str,
|
||||
}
|
||||
|
||||
impl Base {
|
||||
pub fn new(config: &Config, tab: Tab) -> Self {
|
||||
let current = match tab {
|
||||
Tab::None => "",
|
||||
Tab::Index => "index",
|
||||
Tab::Commit => "commit",
|
||||
Tab::Queue => "queue",
|
||||
};
|
||||
Self {
|
||||
root: config.web_base.clone(),
|
||||
repo_name: config.repo_name.clone(),
|
||||
current: current.to_string(),
|
||||
current,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,23 +9,8 @@ use sqlx::SqlitePool;
|
|||
|
||||
use crate::{config::Config, server::util, somehow};
|
||||
|
||||
use super::{Base, Tab};
|
||||
use super::{Base, Tab, link::CommitLink};
|
||||
|
||||
struct Commit {
|
||||
hash: String,
|
||||
short: String,
|
||||
reachable: i64,
|
||||
}
|
||||
|
||||
impl Commit {
|
||||
fn new(hash: String, message: &str, reachable: i64) -> Self {
|
||||
Self {
|
||||
short: util::format_commit_short(&hash, message),
|
||||
hash,
|
||||
reachable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "commit.html")]
|
||||
|
|
@ -36,8 +21,8 @@ struct CommitTemplate {
|
|||
author_date: String,
|
||||
commit: String,
|
||||
commit_date: String,
|
||||
parents: Vec<Commit>,
|
||||
children: Vec<Commit>,
|
||||
parents: Vec<CommitLink>,
|
||||
children: Vec<CommitLink>,
|
||||
summary: String,
|
||||
message: String,
|
||||
reachable: i64,
|
||||
|
|
@ -48,6 +33,8 @@ pub async fn get(
|
|||
State(config): State<&'static Config>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<Response> {
|
||||
let base = Base::new(config, Tab::None);
|
||||
|
||||
let Some(commit) = sqlx::query!(
|
||||
"\
|
||||
SELECT \
|
||||
|
|
@ -79,7 +66,7 @@ pub async fn get(
|
|||
hash
|
||||
)
|
||||
.fetch(&db)
|
||||
.map_ok(|r| Commit::new(r.hash, &r.message, r.reachable))
|
||||
.map_ok(|r| CommitLink::new(&base, r.hash, &r.message, r.reachable))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
|
|
@ -93,12 +80,12 @@ pub async fn get(
|
|||
hash
|
||||
)
|
||||
.fetch(&db)
|
||||
.map_ok(|r| Commit::new(r.hash, &r.message, r.reachable))
|
||||
.map_ok(|r| CommitLink::new(&base, r.hash, &r.message, r.reachable))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
Ok(CommitTemplate {
|
||||
base: Base::new(config, Tab::Commit),
|
||||
base,
|
||||
hash: commit.hash,
|
||||
author: commit.author,
|
||||
author_date: util::format_time(commit.author_date),
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@ use axum::{extract::State, response::IntoResponse};
|
|||
use futures::TryStreamExt;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{config::Config, server::util, somehow};
|
||||
use crate::{config::Config, somehow};
|
||||
|
||||
use super::{Base, Tab};
|
||||
use super::{link::CommitLink, Base, Tab};
|
||||
|
||||
struct Ref {
|
||||
name: String,
|
||||
hash: String,
|
||||
short: String,
|
||||
reachable: i64,
|
||||
commit: CommitLink,
|
||||
tracked: bool,
|
||||
}
|
||||
|
||||
|
|
@ -27,6 +25,8 @@ pub async fn get(
|
|||
State(config): State<&'static Config>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let base = Base::new(config, Tab::Index);
|
||||
|
||||
let refs = sqlx::query!(
|
||||
"\
|
||||
SELECT name, hash, message, reachable, tracked \
|
||||
|
|
@ -37,10 +37,8 @@ pub async fn get(
|
|||
)
|
||||
.fetch(&db)
|
||||
.map_ok(|r| Ref {
|
||||
short: util::format_commit_short(&r.hash, &r.message),
|
||||
name: r.name,
|
||||
hash: r.hash,
|
||||
reachable: r.reachable,
|
||||
name: r.name.clone(),
|
||||
commit: CommitLink::new(&base, r.hash, &r.message, r.reachable),
|
||||
tracked: r.tracked != 0,
|
||||
})
|
||||
.try_collect::<Vec<_>>()
|
||||
|
|
|
|||
36
src/server/web/link.rs
Normal file
36
src/server/web/link.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use askama::Template;
|
||||
|
||||
use crate::server::util;
|
||||
|
||||
use super::Base;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(
|
||||
ext = "html",
|
||||
source = "
|
||||
{% import \"util.html\" as util %}
|
||||
|
||||
<a href=\"{{ root }}commit/{{ hash }}\"
|
||||
class=\"{% call util::commit_class(reachable) %}\"
|
||||
title=\"{% call util::commit_title(reachable) %}\">
|
||||
{{ short }}
|
||||
</a>
|
||||
"
|
||||
)]
|
||||
pub struct CommitLink {
|
||||
root: String,
|
||||
hash: String,
|
||||
short: String,
|
||||
reachable: i64,
|
||||
}
|
||||
|
||||
impl CommitLink {
|
||||
pub fn new(base: &Base, hash: String, message: &str, reachable: i64) -> Self {
|
||||
Self {
|
||||
root: base.root.clone(),
|
||||
short: util::format_commit_short(&hash, message),
|
||||
hash,
|
||||
reachable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ pub async fn get(
|
|||
};
|
||||
|
||||
Ok(RunnerTemplate {
|
||||
base: Base::new(config, Tab::Commit),
|
||||
base: Base::new(config, Tab::None),
|
||||
name,
|
||||
last_seen: util::format_time(info.last_seen),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue