From 520ee0f7dab64595082c95691d78137a98a02dd6 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 6 Aug 2023 13:46:10 +0200 Subject: [PATCH] Sort and count refs --- ...38974f12556b6ac463f21f7729f758dec886.json} | 4 ++-- src/web/index.rs | 19 ++++++++++++++++--- templates/index.html | 12 ++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) rename .sqlx/{query-1e09e422a6fd826b7dfdaf52a271e77672c4dbc933af42a59fd8a8459e495732.json => query-39e21f75c4f68be1e4f64c4a9c0a38974f12556b6ac463f21f7729f758dec886.json} (84%) diff --git a/.sqlx/query-1e09e422a6fd826b7dfdaf52a271e77672c4dbc933af42a59fd8a8459e495732.json b/.sqlx/query-39e21f75c4f68be1e4f64c4a9c0a38974f12556b6ac463f21f7729f758dec886.json similarity index 84% rename from .sqlx/query-1e09e422a6fd826b7dfdaf52a271e77672c4dbc933af42a59fd8a8459e495732.json rename to .sqlx/query-39e21f75c4f68be1e4f64c4a9c0a38974f12556b6ac463f21f7729f758dec886.json index 8312d5b..0e6da13 100644 --- a/.sqlx/query-1e09e422a6fd826b7dfdaf52a271e77672c4dbc933af42a59fd8a8459e495732.json +++ b/.sqlx/query-39e21f75c4f68be1e4f64c4a9c0a38974f12556b6ac463f21f7729f758dec886.json @@ -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" } diff --git a/src/web/index.rs b/src/web/index.rs index a324dc2..fd8a861 100644 --- a/src/web/index.rs +++ b/src/web/index.rs @@ -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, + tracked_refs: Vec, + untracked_refs: Vec, } 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::>() .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, }) } diff --git a/templates/index.html b/templates/index.html index 7aed046..2535cfc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,24 +5,20 @@ {% block body %}

Refs

- Tracked + Tracked ({{ tracked_refs.len() }})
- {% for ref in refs %} - {% if ref.tracked %} + {% for ref in tracked_refs %}
{{ ref.name }}
{{ ref.short }}
- {% endif %} {% endfor %}
- Untracked + Untracked ({{ untracked_refs.len() }})
- {% for ref in refs %} - {% if !ref.tracked %} + {% for ref in untracked_refs %}
{{ ref.name }}
{{ ref.short }}
- {% endif %} {% endfor %}