8 files changed, 162 insertions(+), 18 deletions(-)
@@ -31,6 +31,10 @@
Self { gix }
}
pub fn seconds(&self) -> i64 {
self.gix.seconds
}
pub fn format(&self) -> String {
let dt: DateTime<Utc> = Utc.timestamp_opt(self.gix.seconds, 0).unwrap();
let offset = FixedOffset::east_opt(self.gix.offset).unwrap();
@@ -147,6 +147,48 @@
border-bottom: 1px solid var(--surface1);
}
main table thead th {
cursor: pointer;
user-select: none;
position: relative;
transition: background-color 0.1s ease, color 0.1s ease;
}
main table thead th:hover {
background: var(--one_bg);
color: var(--rosewater);
}
main table thead th::after {
content: ' ⇅';
font-size: 0.75em;
color: var(--overlay0);
opacity: 0;
margin-left: 0.35rem;
}
main table thead th:hover::after {
opacity: 0.75;
}
main table thead th.sort-asc,
main table thead th.sort-desc {
background: var(--one_bg);
border-bottom: 2px solid var(--peach);
}
main table thead th.sort-asc::after {
content: ' ▲';
color: var(--green);
opacity: 1;
}
main table thead th.sort-desc::after {
content: ' ▼';
color: var(--red);
opacity: 1;
}
td {
text-align: left;
white-space: nowrap;
@@ -29,5 +29,84 @@
</main>
{% endblock %}
</div>
<script>
document.querySelectorAll("main table").forEach((table) => {
const headers = table.querySelectorAll("thead th");
const tbody = table.querySelector("tbody");
if (!headers.length || !tbody) return;
const cellValue = (row, idx) => {
const cell = row.children[idx];
if (!cell) return { num: NaN, text: "" };
const rawSort = cell.getAttribute("data-sort");
if (rawSort !== null) {
return { num: Number(rawSort), text: rawSort };
}
const text = cell.textContent.trim();
return { num: NaN, text };
};
headers.forEach((th, colIdx) => {
th.setAttribute("tabindex", "0");
th.setAttribute("role", "columnheader");
if (!th.hasAttribute("aria-sort")) {
th.setAttribute("aria-sort", "none");
}
const applySort = () => {
// 1st click -> ascending (top-down), 2nd click -> descending (bottom-up)
const nextDir = th.classList.contains("sort-asc") ? "desc" : "asc";
const factor = nextDir === "asc" ? 1 : -1;
headers.forEach((h) => {
h.classList.remove("sort-asc", "sort-desc");
h.setAttribute("aria-sort", "none");
});
th.classList.add(nextDir === "asc" ? "sort-asc" : "sort-desc");
th.setAttribute(
"aria-sort",
nextDir === "asc" ? "ascending" : "descending"
);
const allRows = Array.from(tbody.querySelectorAll(":scope > tr"));
const topPinned = allRows.filter((r) =>
r.classList.contains("tree-parent")
);
const bottomPinned = allRows.filter((r) =>
r.classList.contains("no-background")
);
const sortableRows = allRows.filter(
(r) =>
!r.classList.contains("tree-parent") &&
!r.classList.contains("no-background")
);
sortableRows.sort((rowA, rowB) => {
const a = cellValue(rowA, colIdx);
const b = cellValue(rowB, colIdx);
if (!Number.isNaN(a.num) && !Number.isNaN(b.num)) {
return (a.num - b.num) * factor;
}
return (
a.text.localeCompare(b.text, undefined, {
numeric: true,
sensitivity: "base",
}) * factor
);
});
tbody.append(...topPinned, ...sortableRows, ...bottomPinned);
};
th.addEventListener("click", applySort);
th.addEventListener("keydown", (e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
applySort();
}
});
});
});
</script>
</body>
</html>
@@ -111,7 +111,7 @@
{{ branch.author.name }}
</td>
{% let time = branch.last_commit.committer.time.format_relative() %}
<td class="{{ time.1 }}" title="{{ branch.last_commit.committer.time.format() }}">{{ time.0 }}</td>
<td class="{{ time.1 }}" data-sort="-{{ branch.last_commit.committer.time.seconds() }}" title="{{ branch.last_commit.committer.time.format() }}">{{ time.0 }}</td>
</tr>
{% endfor %}
<tr class="no-background">
@@ -142,7 +142,7 @@
{% macro tags(tags, tags_has_more, has_prev, page, mode) %}
<thead>
<tr>
<th>Tag</th>
<th class="sort-desc" aria-sort="descending">Tag</th>
<th>Download</th>
<th>Author</th>
<th>Age</th>
@@ -165,8 +165,7 @@
{% endif %}
</td>
{% let time = tag.time.format_relative() %}
<td class="
{{ time.1 }}" title="{{ tag.time.format() }}">{{ time.0 }}</td>
<td class="{{ time.1 }}" data-sort="-{{ tag.time.seconds() }}" title="{{ tag.time.format() }}">{{ time.0 }}</td>
</tr>
{% endfor %}
<tr class="no-background">
@@ -197,7 +196,7 @@
{% macro commits(commits, commits_has_more, has_prev, page, mode) %}
<thead>
<tr>
<th>Age</th>
<th class="sort-asc" aria-sort="ascending">Age</th>
<th>Commit message</th>
<th>Author</th>
</tr>
@@ -206,7 +205,7 @@
{% for commit in commits %}
<tr>
{% let time = commit.committer.time.format_relative() %}
<td class="{{ time.1 }}" title="{{ commit.committer.time.format() }}">{{ time.0 }}</td>
<td class="{{ time.1 }}" data-sort="-{{ commit.committer.time.seconds() }}" title="{{ commit.committer.time.format() }}">{{ time.0 }}</td>
<td>
<a href="/{{ repo.name }}/commit/?id={{ commit.id }}">{{ commit.summary()? | truncate(80)}}</a>
{% if commit.is_head(repo)? %}<a href="/{{ repo.name }}/commit/?id={{ commit.id }}" class="badge_head">HEAD</a>{% endif %}
@@ -28,7 +28,7 @@
<th>Name</th>
<th>Description</th>
<th>Owner</th>
<th>Idle</th>
<th class="sort-asc" aria-sort="ascending">Idle</th>
<th>Links</th>
</tr>
</thead>
@@ -38,16 +38,17 @@
<td><a href="/{{ repo.name }}/">{{ repo.name }}</a></td>
<td><a href="/{{ repo.name }}/">{{ repo.description }}</a></td>
<td>{% if let Some(owner) = repo.owner %}{{ owner }}{% endif %}</td>
<td>
{% let gix_repo = repo.gix() %}
{% if let Some(last_commit) = repo.last_commit(gix_repo)? %}
{% let time = last_commit.time.format_relative() %}
<span class="{{ time.1 }}" title="{{ last_commit.time.format() }}">{{ time.0 }}</span>
{% else %}
{% let gix_repo = repo.gix() %}
{% if let Some(last_commit) = repo.last_commit(gix_repo)? %}
{% let time = last_commit.committer.time.format_relative() %}
<td data-sort="-{{ last_commit.committer.time.seconds() }}">
<span class="{{ time.1 }}" title="{{ last_commit.committer.time.format() }}">{{ time.0 }}</span>
</td>
{% else %}
<td data-sort="999999999999">
<span class="stale">Unknown</span>
{% endif %}
</td>
</td>
{% endif %}
<td><a href="/{{ repo.name }}/">summary</a><a href="/{{ repo.name }}/log/">log</a><a href="/{{ repo.name }}/tree/">tree</a></td>
</tr>
{% endfor %}
@@ -89,6 +89,17 @@
Ok(None)
}
/// Returns the committer timestamp (in seconds) of the repository's latest commit,
/// or `i64::MIN` if the repository has no commits yet.
pub fn last_commit_timestamp(&self) -> i64 {
let gix_repo = self.gix();
self.last_commit(&gix_repo)
.ok()
.flatten()
.map(|c| c.committer.time.seconds())
.unwrap_or(i64::MIN)
}
pub fn branch_tips_by_commit(&self) -> Result<HashMap<String, Vec<String>>, Error> {
let gix_repo = self.gix();
let references = gix_repo.references()?;
@@ -86,7 +86,15 @@
if let (qt, Some(value)) = (query.query_type.as_deref(), query.value.as_deref()) {
let value_lower = value.to_lowercase();
repos.sort_by_key(|a| relevance(a, qt, &value_lower));
repos.sort_by_key(|a| {
(
relevance(a, qt, &value_lower),
std::cmp::Reverse(a.last_commit_timestamp()),
)
});
} else {
// Auto-sort repositories by Idle/Age (most recently updated first)
repos.sort_by_key(|a| std::cmp::Reverse(a.last_commit_timestamp()));
}
ReposPage { repos }.render()
};
@@ -59,7 +59,7 @@
<a href="/{{ repo.name }}/tree/{{ entry.path }}{{ parameters }}">{{ entry.name }}</a>
{% endmatch %}
</td>
<td class="size">{{ entry.size_display() }}</td>
<td class="size" data-sort="{{ entry.size.unwrap_or(0) }}">{{ entry.size_display() }}</td>
</tr>
{% endfor %}
</tbody>