From c6dcadc2f3eb54000076fa95292f1c2486074d35 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Mon, 18 Jul 2022 01:17:39 +0100 Subject: [PATCH] Implement summary view --- src/git.rs | 4 ++-- src/methods/repo.rs | 28 +++++++++++++++++++++++++--- statics/sass/tables.scss | 4 ++++ templates/repo/log.html | 26 ++------------------------ templates/repo/refs.html | 57 ++++----------------------------------------------------- templates/repo/summary.html | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ templates/repo/macros/refs.html | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 183 insertions(+), 84 deletions(-) diff --git a/src/git.rs b/src/git.rs index 65a78f8..fd72db9 100644 --- a/src/git.rs +++ a/src/git.rs @@ -212,12 +212,12 @@ } built_refs.branch.sort_unstable_by(|one, two| { - one.commit.committer.time.cmp(&two.commit.committer.time) + two.commit.committer.time.cmp(&one.commit.committer.time) }); built_refs.tag.sort_unstable_by(|one, two| { let one_tagger = one.tagger.as_ref().map(|v| v.time); let two_tagger = two.tagger.as_ref().map(|v| v.time); - one_tagger.cmp(&two_tagger) + two_tagger.cmp(&one_tagger) }); Arc::new(built_refs) diff --git a/src/methods/repo.rs b/src/methods/repo.rs index 09f0744..259635a 100644 --- a/src/methods/repo.rs +++ a/src/methods/repo.rs @@ -113,13 +113,31 @@ #[derive(Template)] #[template(path = "repo/summary.html")] -pub struct SummaryView { - pub repo: Repository, +pub struct SummaryView<'a> { + repo: Repository, + refs: Arc, + commit_list: Vec<&'a crate::database::schema::commit::Commit<'a>>, } -#[allow(clippy::unused_async)] -pub async fn handle_summary(Extension(repo): Extension) -> Response { - into_response(&SummaryView { repo }) +pub async fn handle_summary( + Extension(repo): Extension, + Extension(RepositoryPath(repository_path)): Extension, + Extension(git): Extension>, + Extension(db): Extension, +) -> Response { + let open_repo = git.repo(repository_path).await; + let refs = open_repo.refs().await; + + let repository = crate::database::schema::repository::Repository::open(&db, &*repo).unwrap(); + let commit_tree = repository.get().commit_tree(&db, "refs/heads/master"); + let commits = commit_tree.fetch_latest(11, 0).await; + let commit_list = commits.iter().map(Yoke::get).collect(); + + into_response(&SummaryView { + repo, + refs, + commit_list, + }) } #[derive(Deserialize)] diff --git a/statics/sass/tables.scss b/statics/sass/tables.scss index 920fd2e..bfc4a1a 100644 --- a/statics/sass/tables.scss +++ a/statics/sass/tables.scss @@ -23,6 +23,10 @@ background: #f7f7f7; } + &.no-background { + background: none; + } + &.has-parent td:first-of-type { padding-left: 1rem; } diff --git a/templates/repo/log.html b/templates/repo/log.html index 2d8167d..12ca23c 100644 --- a/templates/repo/log.html +++ a/templates/repo/log.html @@ -1,33 +1,11 @@ +{% import "macros/refs.html" as refs %} {% extends "repo/base.html" %} {% block log_nav_class %}active{% endblock %} {% block content %} - - - - - - - - - - {% for commit in commits %} - - - - - - {% endfor %} - + {% call refs::commit_table(commits, false) %}
AgeCommit messageAuthor
- - {{ commit.summary }} - - {{ commit.author.name }} -
{% if let Some(next_offset) = next_offset %} diff --git a/templates/repo/refs.html b/templates/repo/refs.html index 0c7adb4..40f4d06 100644 --- a/templates/repo/refs.html +++ a/templates/repo/refs.html @@ -1,35 +1,11 @@ +{% import "macros/refs.html" as refs %} {% extends "repo/base.html" %} {% block refs_nav_class %}active{% endblock %} {% block content %} - - - - - - - - - - - {% for branch in refs.branch %} - - - - - - - {% endfor %} - + {% call refs::branch_table(refs.branch) %} @@ -38,33 +14,8 @@ - - - - - - - - - {% for tag in refs.tag.iter().rev() %} - - - - - - - {% endfor %} + + {% call refs::tag_table(refs.tag) %}
BranchCommit messageAuthorAge
{{ branch.name }}{{ branch.commit.summary() }} - - {{ branch.commit.author().name() }} - - -
TagDownloadAuthorAge
{{ tag.name }} - {% if let Some(tagger) = tag.tagger %} - - {{ tagger.name() }} - {% endif %} - - {% if let Some(tagger) = tag.tagger %} - - {% endif %} -
{% endblock %}diff --git a/templates/repo/summary.html b/templates/repo/summary.html index d72f5be..09a2897 100644 --- a/templates/repo/summary.html +++ a/templates/repo/summary.html @@ -1,6 +1,62 @@ +{% import "macros/refs.html" as refs %} {% extends "repo/base.html" %} {% block summary_nav_class %}active{% endblock %} {% block content %} + + {% call refs::branch_table(refs.branch.iter().take(10)) %} + {% if refs.branch.len() > 10 %} + + + + + + + + + {% endif %} + + + + + + + + + + + {% call refs::tag_table(refs.tag.iter().take(10)) %} + {% if refs.tag.len() > 10 %} + + + + + + + + + {% endif %} + + + + + + + + + + + {% call refs::commit_table(commit_list.iter().take(10), true) %} + {% if commit_list.len() > 10 %} + + + + + + + + + {% endif %} +
[...]
[...]
[...]
{% endblock %}diff --git a/templates/repo/macros/refs.html b/templates/repo/macros/refs.html new file mode 100644 index 0000000..a3bfecd 100644 --- /dev/null +++ a/templates/repo/macros/refs.html @@ -1,0 +1,92 @@ +{% macro branch_table(branches) %} + + + Branch + Commit message + Author + Age + + + + +{% for branch in branches %} + + {{ branch.name }} + {{ branch.commit.summary() }} + + + {{ branch.commit.author().name() }} + + + + + +{% endfor %} + +{% endmacro %} + +{% macro tag_table(tags) %} + + + Tag + Download + Author + Age + + + + +{% for tag in tags %} + + {{ tag.name }} + + + {% if let Some(tagger) = tag.tagger %} + + {{ tagger.name() }} + {% endif %} + + + {% if let Some(tagger) = tag.tagger %} + + {% endif %} + + +{% endfor %} + +{% endmacro %} + +{% macro commit_table(commits, with_extras) %} + + + Age + Commit message + Author + + + + +{% for commit in commits %} + + + + + {{ commit.summary }} + + + {{ commit.author.name }} + + + {% if with_extras %} + + {% endif %} + +{% endfor %} + +{% endmacro %}-- rgit 0.1.3