Skip to content

Commit

Permalink
Use https://datatables.net to render the HTML table with the recipe i…
Browse files Browse the repository at this point in the history
…ndex

The benefit of using DataTables.net is that it renders the DOM
dynamically showing just a subset/page of the data at a time.
It also provides filtering, sorting and many more settings
(https://datatables.net/reference/option/)

Also on top I have added a small table that shows the number of recipes
with additional platforms and their ratio to the total.

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
  • Loading branch information
martin-g committed Nov 28, 2024
1 parent 8cb76d5 commit e8ceb5c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 11 deletions.
24 changes: 13 additions & 11 deletions source/_ext/bioconda_sphinx_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,22 @@ class PackageIndex(Index):

def generate(self, docnames: Optional[List[str]] = None):
"""build index"""
content = {}
content = []

objects = sorted(self.domain.data['objects'].items())
for (typ, name), (docname, labelid, description) in objects:
if docnames and docname not in docnames:
continue
entries = content.setdefault(name[0].lower(), [])
subtype = 0 # 1 has subentries, 2 is subentry
entries.append((
# TODO: Add meaningful info for extra/qualifier/description
# fields, e.g., latest package version.
# name, subtype, docname, labelid, 'extra', 'qualifier', 'description',
name, subtype, docname, labelid, '', '', description,
))

# TODO: Add meaningful info for extra/qualifier/description
# fields, e.g., latest package version.
content.append({
"name": name,
"archs": description
})

collapse = True
return sorted(content.items()), collapse
return content, collapse


class CondaDomain(Domain):
Expand Down Expand Up @@ -609,7 +608,10 @@ def generate_readme(recipe_basedir, output_dir, folder, repodata, renderer):
'packages': packages,
}

recipe_additional_platforms[recipe.name] = ', '.join(recipe_extra.get('additional-platforms', []))
if recipe_extra is None:
recipe_additional_platforms[recipe.name] = ''
else:
recipe_additional_platforms[recipe.name] = ', '.join(recipe_extra.get('additional-platforms', []))

renderer.render_to_file(output_file, 'readme.rst_t', template_options)
return [output_file]
Expand Down
102 changes: 102 additions & 0 deletions source/templates/domainindex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{# Template for domain indices (module index, ...). #}
{%- extends "layout.html" %}
{% set title = indextitle %}
{% block extrahead %}
{{ super() }}
{% if not embedded and collapse_index %}
<script>
DOCUMENTATION_OPTIONS.COLLAPSE_INDEX = true;
</script>
{% endif %}
<link rel="stylesheet" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/rowgroup/1.5.1/css/rowGroup.dataTables.min.css"/>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.datatables.net/2.1.8/js/dataTables.js"></script>
<script src="https://cdn.datatables.net/rowgroup/1.5.1/js/dataTables.rowGroup.min.js"></script>
{% endblock %}
{% block body %}

{%- set groupid = idgen() %}

<h1>{{ indextitle }}</h1>

<table>
<thead>
<tr>
<th></th>
<th>Count</th>
<th>Ratio</th>
</tr>
</thead>
<tbody>
<tr>
<td>Total recipes:</td>
<td id="total-count"></td>
<td></td>
</tr>
<tr>
<td>linux-aarch64 recipes:</td>
<td id="linux-aarch64-count"></td>
<td><span id="linux-aarch64-ratio"></span>%</td>
</tr>
<tr>
<td>osx-arm64 recipes:</td>
<td id="osx-arm64-count"></td>
<td><span id="osx-arm64-ratio"></span>%</td>
</tr>
</tbody>
</table>

<table class="indextable modindextable" id="recipes-table"></table>

<script>

let dataset = [
{%- for (entry) in content %}
["{{ entry.name }}", "{{ entry.archs }}"]{%- if not loop.last -%}{{ "," }}{%- endif -%}
{%- endfor %}
];

let aarch64Count = 0;
let arm64Count = 0;
for (let i=0; i<dataset.length; i++) {
let entry = dataset[i];
if (entry[1].includes("linux-aarch64")) {
aarch64Count += 1;
}
if (entry[1].includes("osx-arm64")) {
arm64Count += 1;
}
}
let totalCount = dataset.length;
document.getElementById("linux-aarch64-count").textContent = aarch64Count;
document.getElementById("linux-aarch64-ratio").textContent = (aarch64Count / totalCount * 100).toFixed(2);
document.getElementById("osx-arm64-count").textContent = arm64Count;
document.getElementById("osx-arm64-ratio").textContent = (arm64Count / totalCount * 100).toFixed(2);
document.getElementById("total-count").textContent = totalCount;

let table = new DataTable('#recipes-table', {
data: dataset,
columns: [
{ title: "Name" },
{
title: "Additional platforms",
orderable: false
},
],
displayLength: 25,
lengthMenu: [
[10, 25, 50, -1],
[10, 25, 50, 'All']
],
rowGroup: {
enable: true,
dataSrc: function(row) {
return row[0].charAt(0).toLowerCase();
}
}
});
</script>

{% endblock %}

0 comments on commit e8ceb5c

Please sign in to comment.