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 api;
|
||||||
mod commit;
|
mod commit;
|
||||||
mod index;
|
mod index;
|
||||||
|
mod link;
|
||||||
mod queue;
|
mod queue;
|
||||||
mod runner;
|
mod runner;
|
||||||
mod r#static;
|
mod r#static;
|
||||||
|
|
@ -12,8 +13,8 @@ use crate::{config::Config, somehow};
|
||||||
use super::Server;
|
use super::Server;
|
||||||
|
|
||||||
pub enum Tab {
|
pub enum Tab {
|
||||||
|
None,
|
||||||
Index,
|
Index,
|
||||||
Commit,
|
|
||||||
Queue,
|
Queue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,20 +22,20 @@ pub enum Tab {
|
||||||
pub struct Base {
|
pub struct Base {
|
||||||
root: String,
|
root: String,
|
||||||
repo_name: String,
|
repo_name: String,
|
||||||
current: String,
|
current: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Base {
|
impl Base {
|
||||||
pub fn new(config: &Config, tab: Tab) -> Self {
|
pub fn new(config: &Config, tab: Tab) -> Self {
|
||||||
let current = match tab {
|
let current = match tab {
|
||||||
|
Tab::None => "",
|
||||||
Tab::Index => "index",
|
Tab::Index => "index",
|
||||||
Tab::Commit => "commit",
|
|
||||||
Tab::Queue => "queue",
|
Tab::Queue => "queue",
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
root: config.web_base.clone(),
|
root: config.web_base.clone(),
|
||||||
repo_name: config.repo_name.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 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)]
|
#[derive(Template)]
|
||||||
#[template(path = "commit.html")]
|
#[template(path = "commit.html")]
|
||||||
|
|
@ -36,8 +21,8 @@ struct CommitTemplate {
|
||||||
author_date: String,
|
author_date: String,
|
||||||
commit: String,
|
commit: String,
|
||||||
commit_date: String,
|
commit_date: String,
|
||||||
parents: Vec<Commit>,
|
parents: Vec<CommitLink>,
|
||||||
children: Vec<Commit>,
|
children: Vec<CommitLink>,
|
||||||
summary: String,
|
summary: String,
|
||||||
message: String,
|
message: String,
|
||||||
reachable: i64,
|
reachable: i64,
|
||||||
|
|
@ -48,6 +33,8 @@ pub async fn get(
|
||||||
State(config): State<&'static Config>,
|
State(config): State<&'static Config>,
|
||||||
State(db): State<SqlitePool>,
|
State(db): State<SqlitePool>,
|
||||||
) -> somehow::Result<Response> {
|
) -> somehow::Result<Response> {
|
||||||
|
let base = Base::new(config, Tab::None);
|
||||||
|
|
||||||
let Some(commit) = sqlx::query!(
|
let Some(commit) = sqlx::query!(
|
||||||
"\
|
"\
|
||||||
SELECT \
|
SELECT \
|
||||||
|
|
@ -79,7 +66,7 @@ pub async fn get(
|
||||||
hash
|
hash
|
||||||
)
|
)
|
||||||
.fetch(&db)
|
.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<_>>()
|
.try_collect::<Vec<_>>()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
@ -93,12 +80,12 @@ pub async fn get(
|
||||||
hash
|
hash
|
||||||
)
|
)
|
||||||
.fetch(&db)
|
.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<_>>()
|
.try_collect::<Vec<_>>()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(CommitTemplate {
|
Ok(CommitTemplate {
|
||||||
base: Base::new(config, Tab::Commit),
|
base,
|
||||||
hash: commit.hash,
|
hash: commit.hash,
|
||||||
author: commit.author,
|
author: commit.author,
|
||||||
author_date: util::format_time(commit.author_date),
|
author_date: util::format_time(commit.author_date),
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,13 @@ use axum::{extract::State, response::IntoResponse};
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use sqlx::SqlitePool;
|
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 {
|
struct Ref {
|
||||||
name: String,
|
name: String,
|
||||||
hash: String,
|
commit: CommitLink,
|
||||||
short: String,
|
|
||||||
reachable: i64,
|
|
||||||
tracked: bool,
|
tracked: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,6 +25,8 @@ pub async fn get(
|
||||||
State(config): State<&'static Config>,
|
State(config): State<&'static Config>,
|
||||||
State(db): State<SqlitePool>,
|
State(db): State<SqlitePool>,
|
||||||
) -> somehow::Result<impl IntoResponse> {
|
) -> somehow::Result<impl IntoResponse> {
|
||||||
|
let base = Base::new(config, Tab::Index);
|
||||||
|
|
||||||
let refs = sqlx::query!(
|
let refs = sqlx::query!(
|
||||||
"\
|
"\
|
||||||
SELECT name, hash, message, reachable, tracked \
|
SELECT name, hash, message, reachable, tracked \
|
||||||
|
|
@ -37,10 +37,8 @@ pub async fn get(
|
||||||
)
|
)
|
||||||
.fetch(&db)
|
.fetch(&db)
|
||||||
.map_ok(|r| Ref {
|
.map_ok(|r| Ref {
|
||||||
short: util::format_commit_short(&r.hash, &r.message),
|
name: r.name.clone(),
|
||||||
name: r.name,
|
commit: CommitLink::new(&base, r.hash, &r.message, r.reachable),
|
||||||
hash: r.hash,
|
|
||||||
reachable: r.reachable,
|
|
||||||
tracked: r.tracked != 0,
|
tracked: r.tracked != 0,
|
||||||
})
|
})
|
||||||
.try_collect::<Vec<_>>()
|
.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 {
|
Ok(RunnerTemplate {
|
||||||
base: Base::new(config, Tab::Commit),
|
base: Base::new(config, Tab::None),
|
||||||
name,
|
name,
|
||||||
last_seen: util::format_time(info.last_seen),
|
last_seen: util::format_time(info.last_seen),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,6 @@ a:hover {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
dl {
|
|
||||||
display: grid;
|
|
||||||
grid: auto-flow / min-content 1fr;
|
|
||||||
column-gap: 1ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
dd {
|
dd {
|
||||||
margin-left: 4ch;
|
margin-left: 4ch;
|
||||||
}
|
}
|
||||||
|
|
@ -117,6 +111,12 @@ nav a:hover {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.commit dl {
|
||||||
|
display: grid;
|
||||||
|
grid: auto-flow / max-content 1fr;
|
||||||
|
column-gap: 1ch;
|
||||||
|
}
|
||||||
|
|
||||||
.commit .hash {
|
.commit .hash {
|
||||||
color: #b70;
|
color: #b70;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
|
@ -129,6 +129,16 @@ nav a:hover {
|
||||||
|
|
||||||
/* Runner */
|
/* Runner */
|
||||||
|
|
||||||
|
.runner * {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.runner dl {
|
||||||
|
display: grid;
|
||||||
|
grid: auto-flow / max-content 1fr;
|
||||||
|
column-gap: 1ch;
|
||||||
|
}
|
||||||
|
|
||||||
.runner .name {
|
.runner .name {
|
||||||
color: #380;
|
color: #380;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,15 @@
|
||||||
|
|
||||||
{% for commit in parents %}
|
{% for commit in parents %}
|
||||||
<dt>Parent:</dt>
|
<dt>Parent:</dt>
|
||||||
<dd>
|
<dd>{{ commit|safe }}</dd>
|
||||||
<a href="{{ commit.hash }}">
|
|
||||||
{% call util::commit_short(commit.short, commit.reachable)%}
|
|
||||||
</a>
|
|
||||||
</dd>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for commit in children %}
|
{% for commit in children %}
|
||||||
<dt>Child:</dt>
|
<dt>Child:</dt>
|
||||||
<dd>
|
<dd>{{ commit|safe }}</dd>
|
||||||
<a href="{{ commit.hash }}">
|
|
||||||
{% call util::commit_short(commit.short, commit.reachable)%}
|
|
||||||
</a>
|
|
||||||
</dd>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</dl>
|
</dl>
|
||||||
<pre class="{% call util::r_class(reachable) %}" title="{% call util::r_title(reachable) %}">{{ message }}</pre>
|
<pre class="{% call util::commit_class(reachable) %}"
|
||||||
|
title="{% call util::commit_title(reachable) %}">{{ message }}</pre>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,7 @@
|
||||||
<dl>
|
<dl>
|
||||||
{% for ref in tracked_refs %}
|
{% for ref in tracked_refs %}
|
||||||
<dt>{{ ref.name }}</dt>
|
<dt>{{ ref.name }}</dt>
|
||||||
<dd>
|
<dd>{{ ref.commit|safe }}</dd>
|
||||||
<a href="{{ base.root }}commit/{{ ref.hash }}">
|
|
||||||
{% call util::commit_short(ref.short, ref.reachable) %}
|
|
||||||
</a>
|
|
||||||
</dd>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</dl>
|
</dl>
|
||||||
</details>
|
</details>
|
||||||
|
|
@ -23,11 +19,7 @@
|
||||||
<dl>
|
<dl>
|
||||||
{% for ref in untracked_refs %}
|
{% for ref in untracked_refs %}
|
||||||
<dt>{{ ref.name }}</dt>
|
<dt>{{ ref.name }}</dt>
|
||||||
<dd>
|
<dd>{{ ref.commit|safe }}</dd>
|
||||||
<a href="{{ base.root }}commit/{{ ref.hash }}">
|
|
||||||
{% call util::commit_short(ref.short, ref.reachable) %}
|
|
||||||
</a>
|
|
||||||
</dd>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</dl>
|
</dl>
|
||||||
</details>
|
</details>
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<tr {% if task.odd %} class="odd" {% endif %}>
|
<tr {% if task.odd %} class="odd" {% endif %}>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ base.root }}commit/{{ task.hash }}">
|
<a href="{{ base.root }}commit/{{ task.hash }}">
|
||||||
{% call util::commit_short(task.short, task.reachable) %}
|
{# {% call util::commit_short(task.short, task.reachable) %} #}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ task.since }}</td>
|
<td>{{ task.since }}</td>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{% macro r_class(reachable) %}
|
{% macro commit_class(reachable) %}
|
||||||
{%- if reachable == 0 -%}
|
{%- if reachable == 0 -%}
|
||||||
orphaned
|
orphaned
|
||||||
{%- else if reachable == 1 -%}
|
{%- else if reachable == 1 -%}
|
||||||
|
|
@ -8,7 +8,7 @@ tracked
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro r_title(reachable) %}
|
{% macro commit_title(reachable) %}
|
||||||
{%- if reachable == 0 -%}
|
{%- if reachable == 0 -%}
|
||||||
This commit is orphaned. It can't be reached from any ref.
|
This commit is orphaned. It can't be reached from any ref.
|
||||||
{%- else if reachable == 1 -%}
|
{%- else if reachable == 1 -%}
|
||||||
|
|
@ -17,7 +17,3 @@ This commit can only be reached from untracked refs.
|
||||||
This commit can be reached from a tracked ref.
|
This commit can be reached from a tracked ref.
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro commit_short(short, reachable) -%}
|
|
||||||
<span class="{% call r_class(reachable) %}" title="{% call r_title(reachable) %}">{{ short }}</span>
|
|
||||||
{%- endmacro %}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue