Add package dropdown to statistics pages

This commit is contained in:
rubenwardy 2022-11-09 18:58:58 +00:00
parent 724b80e91e
commit f7742d47ff
3 changed files with 35 additions and 5 deletions

@ -5,6 +5,30 @@
{% endmacro %}
{% macro render_package_selector(user, package=None) %}
<nav class="dropdown d-inline-block">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{% if package %}
{{ package.title }}
{% else %}
{{ _("%(display_name)s's packages", display_name=user.display_name) }}
{% endif %}
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="{{ url_for('users.statistics', username=user.username) }}">
{{ _("%(display_name)s's packages", display_name=user.display_name) }}
</a>
<div class="dropdown-divider"></div>
{% for package in user.packages.filter_by(state='APPROVED').all() %}
<a class="dropdown-item" href="{{ package.getURL('packages.statistics') }}">
{{ package.title }}
</a>
{% endfor %}
</div>
</nav>
{% endmacro %}
{% macro render_package_stats(source, downloads) %}
<noscript>
<p class="alert alert-danger">

@ -4,17 +4,20 @@
{{ _("Statistics") }} - {{ package.title }}
{% endblock %}
{% from "macros/stats.html" import render_package_stats, render_package_stats_js %}
{% from "macros/stats.html" import render_package_stats, render_package_stats_js, render_package_selector %}
{% block scriptextra %}
{{ render_package_stats_js() }}
{% endblock %}
{% block content %}
<a class="btn btn-secondary float-right" href="{{ package.getURL('packages.stats_csv') }}">
<i class="fas fa-download mr-1"></i>
{{ _("Download (.csv)") }}
</a>
<div class="float-right">
<a class="btn btn-secondary mr-2" href="{{ package.getURL('packages.stats_csv') }}">
<i class="fas fa-download mr-1"></i>
{{ _("Download (.csv)") }}
</a>
{{ render_package_selector(package.author, package=package) }}
</div>
<h2 class="mt-0">{{ _("Statistics") }}</h2>
{{ render_package_stats(package.getURL('api.package_stats'), package.downloads) }}
{% endblock %}

@ -11,6 +11,9 @@
{% endblock %}
{% block content %}
<div class="float-right">
{{ render_package_selector(user, package=None) }}
</div>
<h2 class="mt-0">{{ self.title() }}</h2>
{{ render_package_stats(url_for("api.user_stats", username=user.username), downloads) }}
{% endblock %}