🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-18 1:17:39.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-18 1:17:46.0 +01:00:00
commit
c6dcadc2f3eb54000076fa95292f1c2486074d35 [patch]
tree
6ff1146a3e12b17ef1af6561130f6fa1793e8eb4
parent
81056c93b94bbe3800ccca6354ddf618ea384527
download
c6dcadc2f3eb54000076fa95292f1c2486074d35.tar.gz

Implement summary view



Diff

 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<Refs>,
    commit_list: Vec<&'a crate::database::schema::commit::Commit<'a>>,
}

#[allow(clippy::unused_async)]
pub async fn handle_summary(Extension(repo): Extension<Repository>) -> Response {
    into_response(&SummaryView { repo })
pub async fn handle_summary(
    Extension(repo): Extension<Repository>,
    Extension(RepositoryPath(repository_path)): Extension<RepositoryPath>,
    Extension(git): Extension<Arc<Git>>,
    Extension(db): Extension<sled::Db>,
) -> 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 %}
<table class="repositories">
    <thead>
    <tr>
        <th>Age</th>
        <th>Commit message</th>
        <th>Author</th>
    </tr>
    </thead>

    <tbody>
    {% for commit in commits %}
    <tr>
        <td>
            <time datetime="{{ commit.committer.time }}" title="{{ commit.committer.time }}">
                {{ commit.committer.time.clone()|timeago }}
            </time>
        </td>
        <td><a href="/{{ repo.display() }}/commit/?id={{ commit.hash|hex }}">{{ commit.summary }}</a></td>
        <td>
            <img src="https://www.gravatar.com/avatar/{{ commit.author.email|md5 }}?s=13&d=retro" width="13" height="13">
            {{ commit.author.name }}
        </td>
    </tr>
    {% endfor %}
    </tbody>
    {% call refs::commit_table(commits, false) %}
</table>

{% 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 %}
<table class="repositories">
    <thead>
    <tr>
        <th>Branch</th>
        <th>Commit message</th>
        <th>Author</th>
        <th>Age</th>
    </tr>
    </thead>

    <tbody>
    {% for branch in refs.branch %}
    <tr>
        <td><a href="/{{ repo.display() }}/log/?h={{ branch.name }}">{{ branch.name }}</a></td>
        <td><a href="/{{ repo.display() }}/commit/?id={{ branch.commit.oid() }}">{{ branch.commit.summary() }}</a></td>
        <td>
            <img src="https://www.gravatar.com/avatar/{{ branch.commit.author().email_md5() }}?s=13&d=retro" width="13" height="13">
            {{ branch.commit.author().name() }}
        </td>
        <td>
            <time datetime="{{ branch.commit.author().time() }}" title="{{ branch.commit.author().time() }}">
                {{ branch.commit.author().time()|timeago }}
            </time>
        </td>
    </tr>
    {% endfor %}
    </tbody>
    {% call refs::branch_table(refs.branch) %}

    <tbody>
    <tr class="separator">
@@ -38,33 +14,8 @@
        <td></td>
        <td></td>
    </tr>

    <tr>
        <th>Tag</th>
        <th>Download</th>
        <th>Author</th>
        <th>Age</th>
    </tr>

    {% for tag in refs.tag.iter().rev() %}
    <tr>
        <td><a href="/{{ repo.display() }}/tag/?h={{ tag.name }}">{{ tag.name }}</a></td>
        <td></td>
        <td>
            {% if let Some(tagger) = tag.tagger %}
                <img src="https://www.gravatar.com/avatar/{{ tagger.email_md5() }}?s=13&d=retro" width="13" height="13">
                {{ tagger.name() }}
            {% endif %}
        </td>
        <td>
            {% if let Some(tagger) = tag.tagger %}
                <time datetime="{{ tagger.time() }}" title="{{ tagger.time() }}">
                    {{ tagger.time()|timeago }}
                </time>
            {% endif %}
        </td>
    </tr>
    {% endfor %}
    </tbody>

    {% call refs::tag_table(refs.tag) %}
</table>
{% 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 %}
<table class="repositories">
    {% call refs::branch_table(refs.branch.iter().take(10)) %}
    {% if refs.branch.len() > 10 %}
    <tbody>
    <tr class="no-background">
        <td><a href="/{{ repo.display() }}/refs" class="no-style">[...]</a></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </tbody>
    {% endif %}

    <tbody>
    <tr class="separator">
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </tbody>

    {% call refs::tag_table(refs.tag.iter().take(10)) %}
    {% if refs.tag.len() > 10 %}
    <tbody>
    <tr class="no-background">
        <td><a href="/{{ repo.display() }}/refs" class="no-style">[...]</a></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </tbody>
    {% endif %}

    <tbody>
    <tr class="separator">
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </tbody>

    {% call refs::commit_table(commit_list.iter().take(10), true) %}
    {% if commit_list.len() > 10 %}
    <tbody>
    <tr class="no-background">
        <td><a href="/{{ repo.display() }}/log" class="no-style">[...]</a></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </tbody>
    {% endif %}
</table>
{% 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) %}
<thead>
<tr>
    <th>Branch</th>
    <th>Commit message</th>
    <th>Author</th>
    <th>Age</th>
</tr>
</thead>

<tbody>
{% for branch in branches %}
<tr>
    <td><a href="/{{ repo.display() }}/log/?h={{ branch.name }}">{{ branch.name }}</a></td>
    <td><a href="/{{ repo.display() }}/commit/?id={{ branch.commit.oid() }}">{{ branch.commit.summary() }}</a></td>
    <td>
        <img src="https://www.gravatar.com/avatar/{{ branch.commit.author().email_md5() }}?s=13&d=retro" width="13" height="13">
        {{ branch.commit.author().name() }}
    </td>
    <td>
        <time datetime="{{ branch.commit.author().time() }}" title="{{ branch.commit.author().time() }}">
            {{ branch.commit.author().time()|timeago }}
        </time>
    </td>
</tr>
{% endfor %}
</tbody>
{% endmacro %}

{% macro tag_table(tags) %}
<thead>
<tr class="no-background">
    <th>Tag</th>
    <th>Download</th>
    <th>Author</th>
    <th>Age</th>
</tr>
</thead>

<tbody>
{% for tag in tags %}
<tr>
    <td><a href="/{{ repo.display() }}/tag/?h={{ tag.name }}">{{ tag.name }}</a></td>
    <td></td>
    <td>
        {% if let Some(tagger) = tag.tagger %}
        <img src="https://www.gravatar.com/avatar/{{ tagger.email_md5() }}?s=13&d=retro" width="13" height="13">
        {{ tagger.name() }}
        {% endif %}
    </td>
    <td>
        {% if let Some(tagger) = tag.tagger %}
        <time datetime="{{ tagger.time() }}" title="{{ tagger.time() }}">
            {{ tagger.time()|timeago }}
        </time>
        {% endif %}
    </td>
</tr>
{% endfor %}
</thead>
{% endmacro %}

{% macro commit_table(commits, with_extras) %}
<thead>
<tr>
    <th>Age</th>
    <th>Commit message</th>
    <th>Author</th>
</tr>
</thead>

<tbody>
{% for commit in commits %}
<tr>
    <td>
        <time datetime="{{ commit.committer.time }}" title="{{ commit.committer.time }}">
            {{ commit.committer.time.clone()|timeago }}
        </time>
    </td>
    <td><a href="/{{ repo.display() }}/commit/?id={{ commit.hash|hex }}">{{ commit.summary }}</a></td>
    <td>
        <img src="https://www.gravatar.com/avatar/{{ commit.author.email|md5 }}?s=13&d=retro" width="13" height="13">
        {{ commit.author.name }}
    </td>

    {% if with_extras %}
    <td></td>
    {% endif %}
</tr>
{% endfor %}
</tbody>
{% endmacro %}