Improve unified navigation further

This commit is contained in:
rubenwardy 2021-07-24 03:56:43 +01:00
parent 545968a71f
commit 187202d363
9 changed files with 185 additions and 70 deletions

@ -46,6 +46,16 @@ def get_package_tabs(user: User, package: Package):
"title": "Maintainers",
"url": package.getEditMaintainersURL()
},
{
"id": "audit",
"title": "Audit Log",
"url": package.getURL("packages.audit")
},
{
"id": "share",
"title": "Share and Badges",
"url": package.getURL("packages.share")
},
{
"id": "remove",
"title": "Remove",

@ -518,7 +518,8 @@ def audit(package):
query = package.audit_log_entries.order_by(db.desc(AuditLogEntry.created_at))
pagination = query.paginate(page, num, True)
return render_template("admin/audit.html", log=pagination.items, pagination=pagination)
return render_template("packages/audit.html", log=pagination.items, pagination=pagination,
package=package, tabs=get_package_tabs(current_user, package), current_tab="audit")
class PackageAliasForm(FlaskForm):
@ -558,3 +559,11 @@ def alias_create_edit(package: Package, alias_id: int = None):
return redirect(package.getAliasListURL())
return render_template("packages/alias_create_edit.html", package=package, form=form)
@bp.route("/packages/<author>/<name>/share/")
@login_required
@is_package_page
def share(package):
return render_template("packages/share.html", package=package,
tabs=get_package_tabs(current_user, package), current_tab="share")

@ -460,6 +460,9 @@ class Package(db.Model):
else:
return screenshot.url
def getURL(self, endpoint):
return url_for(endpoint, author=self.author.username, name=self.name)
def getDetailsURL(self, absolute=False):
if absolute:
from app.utils import abs_url_for
@ -535,8 +538,8 @@ class Package(db.Model):
return url_for("packages.remove_self_maintainers",
author=self.author.username, name=self.name)
def getReviewURL(self):
return url_for('packages.review',
def getReviewURL(self, external=False):
return url_for('packages.review', _external=external,
author=self.author.username, name=self.name)
def getAuditLogURL(self):

@ -1,14 +1,66 @@
{% macro render_releases_edit(releases, package) %}
{% for rel in releases %}
<a class="list-group-item list-group-item-action" href="{{ rel.getEditURL() }}">
{{ rel.title }}
<span class="text-muted ml-1">
{% if rel.min_rel and rel.max_rel %}
[MT {{ rel.min_rel.name }}-{{ rel.max_rel.name }}]
{% elif rel.min_rel %}
[MT {{ rel.min_rel.name }}+]
{% elif rel.max_rel %}
[MT &le;{{ rel.max_rel.name }}]
{% endif %}
</span>
<br />
<small style="color:#999;">
{% if rel.commit_hash %}
[{{ rel.commit_hash | truncate(5, end='') }}]
{% endif %}
created {{ rel.releaseDate | date }}.
</small>
</a>
{% endfor %}
{% endmacro %}
{% macro render_releases_download(releases, package) %}
{% for rel in releases %}
{% if rel.approved or package.checkPerm(current_user, "MAKE_RELEASE") or rel.checkPerm(current_user, "APPROVE_RELEASE") %}
<a class="list-group-item list-group-item-action" href="{{ rel.getDownloadURL() }}">
{{ rel.title }}
<span class="text-muted ml-1">
{% if rel.min_rel and rel.max_rel %}
[MT {{ rel.min_rel.name }}-{{ rel.max_rel.name }}]
{% elif rel.min_rel %}
[MT {{ rel.min_rel.name }}+]
{% elif rel.max_rel %}
[MT &le;{{ rel.max_rel.name }}]
{% endif %}
</span>
<br />
<small style="color:#999;">
{% if rel.commit_hash %}
[{{ rel.commit_hash | truncate(5, end='') }}]
{% endif %}
created {{ rel.releaseDate | date }}.
</small>
</a>
{% endif %}
{% endfor %}
{% endmacro %}
{% macro render_releases(releases, package, current_user) -%}
{% for rel in releases %}
{% if rel.approved or package.checkPerm(current_user, "MAKE_RELEASE") or rel.checkPerm(current_user, "APPROVE_RELEASE") %}
<li class="list-group-item">
{% if package.checkPerm(current_user, "MAKE_RELEASE") or rel.checkPerm(current_user, "APPROVE_RELEASE") %}
<a class="btn btn-sm btn-primary float-right" href="{{ rel.getEditURL() }}">Edit
{% if not rel.task_id and not rel.approved and rel.checkPerm(current_user, "APPROVE_RELEASE") %}
/ Approve
{% endif %}
</a>
<div class="list-group-item">
<a class="btn btn-sm btn-primary float-right" href="{{ rel.getEditURL() }}">Edit
{% if not rel.task_id and not rel.approved and rel.checkPerm(current_user, "APPROVE_RELEASE") %}
/ Approve
{% endif %}
</a>
{% if not rel.approved %}<i>{% endif %}
@ -16,7 +68,7 @@
{{ rel.title }}
</a>
<span style="color:#ddd;">
<span class="text-muted ml-1">
{% if rel.min_rel and rel.max_rel %}
[MT {{ rel.min_rel.name }}-{{ rel.max_rel.name }}]
{% elif rel.min_rel %}
@ -42,10 +94,9 @@
{% endif %}
{% if not rel.approved %}</i>{% endif %}
</li>
</div>
{% endif %}
{% else %}
<li class="list-group-item">No releases available.</li>
<div class="list-group-item">No releases available.</div>
{% endfor %}
{% endmacro %}

@ -0,0 +1,16 @@
{% extends "packages/package_base.html" %}
{% block title %}
Audit Log
{% endblock %}
{% block content %}
<h2 class="mt-0">Audit Log</h2>
{% from "macros/pagination.html" import render_pagination %}
{% from "macros/audit_log.html" import render_audit_log %}
{{ render_pagination(pagination, url_set_query) }}
{{ render_audit_log(log, current_user) }}
{{ render_pagination(pagination, url_set_query) }}
{% endblock %}

@ -5,6 +5,8 @@
{% endblock %}
{% block content %}
<h1>{{ self.title() }}</h1>
{% from "macros/forms.html" import render_field, render_submit_field, render_checkbox_field %}
<form method="POST" action="">
{{ form.hidden_tag() }}

@ -5,34 +5,40 @@
{% endblock %}
{% block content %}
<p class="float-right">
{% if package.update_config %}
<a class="btn btn-secondary" href="{{ package.getUpdateConfigURL() }}">
<i class="fas fa-cog mr-1"></i>
{{ _("Update settings") }}
</a>
{% elif package.repo %}
<a class="btn btn-secondary" href="{{ package.getSetupReleasesURL() }}">
<i class="fas fa-hat-wizard mr-1"></i>
{{ _("Set up automatic releases") }}
</a>
{% endif %}
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
<p class="float-right">
{% if package.update_config %}
<a class="btn btn-secondary" href="{{ package.getUpdateConfigURL() }}">
<i class="fas fa-cog mr-1"></i>
{{ _("Update settings") }}
</a>
{% elif package.repo %}
<a class="btn btn-secondary" href="{{ package.getSetupReleasesURL() }}">
<i class="fas fa-hat-wizard mr-1"></i>
{{ _("Set up automatic releases") }}
</a>
{% endif %}
<a class="btn btn-secondary ml-1" href="{{ package.getBulkReleaseURL() }}">
<i class="fas fa-wrench mr-1"></i>
Bulk update
</a>
<a class="btn btn-secondary ml-1" href="{{ package.getBulkReleaseURL() }}">
<i class="fas fa-wrench mr-1"></i>
Bulk update
</a>
<a class="btn btn-primary ml-1" href="{{ package.getCreateReleaseURL() }}">
<i class="fas fa-plus mr-1"></i>
Create
</a>
</p>
<a class="btn btn-primary ml-1" href="{{ package.getCreateReleaseURL() }}">
<i class="fas fa-plus mr-1"></i>
Create
</a>
</p>
{% endif %}
<h2 class="mt-0">{{ _("Releases") }}</h2>
<ul class="list-group">
{% from "macros/releases.html" import render_releases %}
{{ render_releases(package.releases, package, current_user) }}
</ul>
<div class="list-group">
{% from "macros/releases.html" import render_releases_edit, render_releases_download %}
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
{{ render_releases_edit(package.releases, package) }}
{% else %}
{{ render_releases_download(package.releases, package) }}
{% endif %}
</div>
{% endblock %}

@ -0,0 +1,35 @@
{% extends "packages/package_base.html" %}
{% block title %}
Share and Badges
{% endblock %}
{% block content %}
<h2 class="mt-0">{{ self.title() }}</h2>
<h3>Links</h3>
<p>
Review link:
</p>
<pre><code>{{ package.getReviewURL(external=True) }}</code></pre>
<h3>Badges</h3>
<p>
{{ package.makeShield("title") | markdown }}
</p>
<p>
<pre><code>{{ package.makeShield("title") }}</code></pre>
</p>
<p>
{{ package.makeShield("downloads") | markdown }}
</p>
<p>
<pre><code>{{ package.makeShield("downloads") }}</code></pre>
</p>
{% endblock %}

@ -286,26 +286,6 @@
{% endfor %}
</ul>
{% endif %}
{% if package.checkPerm(current_user, "EDIT_PACKAGE") %}
<h2>Badges</h2>
<p>
{{ package.makeShield("title") | markdown }}
</p>
<p>
<pre><code>{{ package.makeShield("title") }}</code></pre>
</p>
<p>
{{ package.makeShield("downloads") | markdown }}
</p>
<p>
<pre><code>{{ package.makeShield("downloads") }}</code></pre>
</p>
{% endif %}
</div>
<aside class="col-md-3 info-sidebar">
@ -411,12 +391,8 @@
<dd>{{ package.created_at | datetime }}</dd>
<dt>Maintainers</dt>
<dd>
{% if package.checkPerm(current_user, "EDIT_MAINTAINERS") %}
<a class="btn btn-primary btn-sm ml-1 float-right" href="{{ package.getEditMaintainersURL() }}"><i class="fas fa-pen"></i></a>
{% endif %}
{% for user in package.maintainers %}
<a class="badge badge-primary"
<a class="badge badge-secondary"
href="{{ url_for('users.profile', username=user.username) }}">
{{ user.display_name }}
</a>
@ -425,7 +401,7 @@
{% if current_user in package.maintainers and current_user != package.author %}
<form class="mt-2" method="post" action="{{ package.getRemoveSelfMaintainerURL() }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input class="btn btn-sm btn-link p-0" type="submit" value="{{ _("Remove myself") }}" />
<input class="btn btn-sm btn-link p-0" type="submit" value="{{ _('Remove myself') }}" />
</form>
{% endif %}
</dd>
@ -448,12 +424,19 @@
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
<a class="btn btn-primary btn-sm float-right" href="{{ package.getCreateReleaseURL() }}"><i class="fas fa-plus"></i></a>
{% endif %}
<a href="{{ package.getReleaseListURL() }}">{{ _("Releases") }}</a>
{{ _("Releases") }}
</h3>
<ul class="list-group">
{% from "macros/releases.html" import render_releases %}
{{ render_releases(releases, package, current_user) }}
</ul>
<div class="list-group">
{% from "macros/releases.html" import render_releases, render_releases_download %}
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
{{ render_releases(releases, package, current_user) }}
{% else %}
{{ render_releases_download(releases, package) }}
{% endif %}
<a class="list-group-item list-group-item-action text-center py-1 text-muted" href="{{ package.getReleaseListURL() }}">
More
</a>
</div>
<h3>
{% if package.approved and package.checkPerm(current_user, "CREATE_THREAD") %}