Sort and count refs

This commit is contained in:
Joscha 2023-08-06 13:46:10 +02:00
parent 72f762464d
commit 520ee0f7da
3 changed files with 22 additions and 13 deletions

View file

@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "SELECT name, hash, tracked, message FROM refs JOIN commits USING (hash) ",
"query": "SELECT name, hash, tracked, message FROM refs JOIN commits USING (hash) ORDER BY name ASC ",
"describe": {
"columns": [
{
@ -34,5 +34,5 @@
false
]
},
"hash": "1e09e422a6fd826b7dfdaf52a271e77672c4dbc933af42a59fd8a8459e495732"
"hash": "39e21f75c4f68be1e4f64c4a9c0a38974f12556b6ac463f21f7729f758dec886"
}

View file

@ -8,8 +8,8 @@ use crate::{config::Config, db, somehow};
struct Ref {
name: String,
hash: String,
tracked: bool,
short: String,
tracked: bool,
}
#[derive(Template)]
@ -18,7 +18,8 @@ struct IndexTemplate {
base: String,
repo_name: String,
current: String,
refs: Vec<Ref>,
tracked_refs: Vec<Ref>,
untracked_refs: Vec<Ref>,
}
pub async fn get(
@ -29,6 +30,7 @@ pub async fn get(
"\
SELECT name, hash, tracked, message FROM refs \
JOIN commits USING (hash) \
ORDER BY name ASC \
"
)
.fetch(&db)
@ -41,10 +43,21 @@ pub async fn get(
.try_collect::<Vec<_>>()
.await?;
let mut tracked_refs = vec![];
let mut untracked_refs = vec![];
for reference in refs {
if reference.tracked {
tracked_refs.push(reference);
} else {
untracked_refs.push(reference);
}
}
Ok(IndexTemplate {
base: config.web.base(),
repo_name: config.repo.name(),
current: "index".to_string(),
refs,
tracked_refs,
untracked_refs,
})
}

View file

@ -5,24 +5,20 @@
{% block body %}
<h2>Refs</h2>
<details>
<summary>Tracked</summary>
<summary>Tracked ({{ tracked_refs.len() }})</summary>
<dl>
{% for ref in refs %}
{% if ref.tracked %}
{% for ref in tracked_refs %}
<dt>{{ ref.name }}</dt>
<dd><a href="{{ base }}/commit/{{ ref.hash }}">{{ ref.short }}</a></dd>
{% endif %}
{% endfor %}
</dl>
</details>
<details>
<summary>Untracked</summary>
<summary>Untracked ({{ untracked_refs.len() }})</summary>
<dl>
{% for ref in refs %}
{% if !ref.tracked %}
{% for ref in untracked_refs %}
<dt>{{ ref.name }}</dt>
<dd><a href="{{ base }}/commit/{{ ref.hash }}">{{ ref.short }}</a></dd>
{% endif %}
{% endfor %}
</dl>
</details>