Add new to do list UI

This commit is contained in:
rubenwardy 2021-01-29 19:38:14 +00:00
parent b613ac4b89
commit 4f920f011f
14 changed files with 299 additions and 110 deletions

@ -56,7 +56,7 @@ def admin_page():
import time import time
time.sleep(0.1) time.sleep(0.1)
return redirect(url_for("todo.view")) return redirect(url_for("todo.view_editor"))
elif action == "reimportpackages": elif action == "reimportpackages":
tasks = [] tasks = []
@ -72,7 +72,7 @@ def admin_page():
import time import time
time.sleep(0.1) time.sleep(0.1)
return redirect(url_for("todo.view")) return redirect(url_for("todo.view_editor"))
elif action == "importforeign": elif action == "importforeign":
releases = PackageRelease.query.filter(PackageRelease.url.like("http%")).all() releases = PackageRelease.query.filter(PackageRelease.url.like("http%")).all()
@ -87,7 +87,7 @@ def admin_page():
import time import time
time.sleep(0.1) time.sleep(0.1)
return redirect(url_for("todo.view")) return redirect(url_for("todo.view_editor"))
elif action == "importmodlist": elif action == "importmodlist":
task = importTopicList.delay() task = importTopicList.delay()

@ -26,7 +26,7 @@ bp = Blueprint("todo", __name__)
@bp.route("/todo/", methods=["GET", "POST"]) @bp.route("/todo/", methods=["GET", "POST"])
@login_required @login_required
def view(): def view_editor():
canApproveNew = Permission.APPROVE_NEW.check(current_user) canApproveNew = Permission.APPROVE_NEW.check(current_user)
canApproveRel = Permission.APPROVE_RELEASE.check(current_user) canApproveRel = Permission.APPROVE_RELEASE.check(current_user)
canApproveScn = Permission.APPROVE_SCREENSHOT.check(current_user) canApproveScn = Permission.APPROVE_SCREENSHOT.check(current_user)
@ -57,17 +57,13 @@ def view():
PackageScreenshot.query.update({ "approved": True }) PackageScreenshot.query.update({ "approved": True })
db.session.commit() db.session.commit()
return redirect(url_for("todo.view")) return redirect(url_for("todo.view_editor"))
else: else:
abort(400) abort(400)
topic_query = ForumTopic.query \ topic_query = ForumTopic.query \
.filter_by(discarded=False) .filter_by(discarded=False)
total_topics = topic_query.count()
topics_to_add = topic_query \
.filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \
.count()
total_packages = Package.query.filter_by(state=PackageState.APPROVED).count() total_packages = Package.query.filter_by(state=PackageState.APPROVED).count()
total_to_tag = Package.query.filter_by(state=PackageState.APPROVED, tags=None).count() total_to_tag = Package.query.filter_by(state=PackageState.APPROVED, tags=None).count()
@ -77,12 +73,15 @@ def view():
.filter(MetaPackage.dependencies.any(optional=False)) \ .filter(MetaPackage.dependencies.any(optional=False)) \
.order_by(db.asc(MetaPackage.name)).count() .order_by(db.asc(MetaPackage.name)).count()
return render_template("todo/list.html", title="Reports and Work Queue", outdated_packages = Package.query \
packages=packages, wip_packages=wip_packages, releases=releases, screenshots=screenshots, .filter(Package.state == PackageState.APPROVED,
canApproveNew=canApproveNew, canApproveRel=canApproveRel, canApproveScn=canApproveScn, Package.update_config.has(outdated=True)).count()
topics_to_add=topics_to_add, total_topics=total_topics,
return render_template("todo/editor.html", current_tab="editor",
packages=packages, wip_packages=wip_packages, releases=releases, screenshots=screenshots,
canApproveNew=canApproveNew, canApproveRel=canApproveRel, canApproveScn=canApproveScn,
total_packages=total_packages, total_to_tag=total_to_tag, total_packages=total_packages, total_to_tag=total_to_tag,
unfulfilled_meta_packages=unfulfilled_meta_packages) unfulfilled_meta_packages=unfulfilled_meta_packages, outdated_packages=outdated_packages)
@bp.route("/todo/topics/") @bp.route("/todo/topics/")
@ -111,7 +110,7 @@ def topics():
show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \ show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \
if query.has_prev else None if query.has_prev else None
return render_template("todo/topics.html", topics=query.items, total=total, return render_template("todo/topics.html", current_tab="topics", topics=query.items, total=total,
topic_count=topic_count, query=qb.search, show_discarded=qb.show_discarded, topic_count=topic_count, query=qb.search, show_discarded=qb.show_discarded,
next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages, next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages,
n=num, sort_by=qb.order_by) n=num, sort_by=qb.order_by)
@ -143,3 +142,44 @@ def metapackages():
.order_by(db.asc(MetaPackage.name)).all() .order_by(db.asc(MetaPackage.name)).all()
return render_template("todo/metapackages.html", mpackages=mpackages) return render_template("todo/metapackages.html", mpackages=mpackages)
@bp.route("/users/<username>/todo/")
@login_required
def view_user(username):
user : User = User.query.filter_by(username=username).first()
if not user:
abort(404)
if current_user != user and not current_user.rank.atLeast(UserRank.EDITOR):
abort(403)
unapproved_packages = user.packages \
.filter(or_(Package.state == PackageState.WIP,
Package.state == PackageState.CHANGES_NEEDED)) \
.order_by(db.asc(Package.created_at)).all()
outdated_packages = user.maintained_packages \
.filter(Package.state != PackageState.DELETED,
Package.update_config.has(outdated=True)) \
.order_by(db.asc(Package.title)).all()
topics_to_add = ForumTopic.query \
.filter_by(author_id=user.id) \
.filter(~ db.exists().where(Package.forums == ForumTopic.topic_id)) \
.order_by(db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \
.all()
return render_template("todo/user.html", current_tab="user", user=user,
unapproved_packages=unapproved_packages, outdated_packages=outdated_packages,
topics_to_add=topics_to_add)
@bp.route("/todo/outdated/")
@login_required
def outdated():
outdated_packages = Package.query \
.filter(Package.state == PackageState.APPROVED,
Package.update_config.has(outdated=True)).all()
return render_template("todo/outdated.html", current_tab="outdated", outdated_packages=outdated_packages)

@ -54,17 +54,8 @@ def profile(username):
packages = packages.filter_by(state=PackageState.APPROVED) packages = packages.filter_by(state=PackageState.APPROVED)
packages = packages.order_by(db.asc(Package.title)) packages = packages.order_by(db.asc(Package.title))
topics_to_add = None
if current_user == user or user.checkPerm(current_user, Permission.CHANGE_AUTHOR):
topics_to_add = ForumTopic.query \
.filter_by(author_id=user.id) \
.filter(~ db.exists().where(Package.forums == ForumTopic.topic_id)) \
.order_by(db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \
.all()
# Process GET or invalid POST # Process GET or invalid POST
return render_template("users/profile.html", return render_template("users/profile.html", user=user, packages=packages)
user=user, packages=packages, topics_to_add=topics_to_add)
@bp.route("/users/<username>/check/", methods=["POST"]) @bp.route("/users/<username>/check/", methods=["POST"])

@ -167,6 +167,8 @@ class User(db.Model, UserMixin):
audit_log_entries = db.relationship("AuditLogEntry", foreign_keys="AuditLogEntry.causer_id", back_populates="causer", audit_log_entries = db.relationship("AuditLogEntry", foreign_keys="AuditLogEntry.causer_id", back_populates="causer",
order_by=desc("audit_log_entry_created_at"), lazy="dynamic") order_by=desc("audit_log_entry_created_at"), lazy="dynamic")
maintained_packages = db.relationship("Package", lazy="dynamic", secondary="maintainers")
packages = db.relationship("Package", back_populates="author", lazy="dynamic") packages = db.relationship("Package", back_populates="author", lazy="dynamic")
reviews = db.relationship("PackageReview", back_populates="author", order_by=db.desc("package_review_created_at"), cascade="all, delete, delete-orphan") reviews = db.relationship("PackageReview", back_populates="author", order_by=db.desc("package_review_created_at"), cascade="all, delete, delete-orphan")
tokens = db.relationship("APIToken", back_populates="owner", lazy="dynamic", cascade="all, delete, delete-orphan") tokens = db.relationship("APIToken", back_populates="owner", lazy="dynamic", cascade="all, delete, delete-orphan")

@ -139,3 +139,12 @@ blockquote {
margin-bottom: 0; margin-bottom: 0;
} }
} }
.tabs-container {
background: #1c1c1c;
border-bottom: 1px solid #444;
.nav {
border-bottom: none;
}
}

@ -63,7 +63,7 @@
{% if todo_list_count is not none %} {% if todo_list_count is not none %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link notification-icon" <a class="nav-link notification-icon"
href="{{ url_for('todo.view') }}" href="{{ url_for('todo.view_editor') }}"
title="{{ _('Work Queue') }}"> title="{{ _('Work Queue') }}">
{% if todo_list_count > 0 %} {% if todo_list_count > 0 %}
<i class="fas fa-inbox"></i> <i class="fas fa-inbox"></i>
@ -73,7 +73,16 @@
{% endif %} {% endif %}
</a> </a>
</li> </li>
{% else %}
<li class="nav-item">
<a class="nav-link notification-icon"
href="{{ url_for('todo.view_user', username=current_user.username) }}"
title="{{ _('To do list') }}">
<i class="fas fa-tasks" ></i>
</a>
</li>
{% endif %} {% endif %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link notification-icon" <a class="nav-link notification-icon"
href="{{ url_for('notifications.list_all') }}" href="{{ url_for('notifications.list_all') }}"
@ -105,22 +114,22 @@
<a class="nav-link" href="{{ url_for('users.profile', username=current_user.username) }}">Profile</a> <a class="nav-link" href="{{ url_for('users.profile', username=current_user.username) }}">Profile</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ url_for('users.profile', username=current_user.username) }}#unadded-topics">Your unadded topics</a> <a class="nav-link" href="{{ url_for('todo.view_user', username=current_user.username) }}">To do list</a>
</li> </li>
{% if current_user.rank.atLeast(current_user.rank.MODERATOR) %} {% if current_user.rank.atLeast(current_user.rank.MODERATOR) %}
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.audit') }}">{{ _("Audit Log") }}</a></li> <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.audit') }}">{{ _("Audit Log") }}</a></li>
{% endif %} {% if current_user.rank == current_user.rank.ADMIN %}
{% if current_user.rank == current_user.rank.ADMIN %} <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.admin_page') }}">{{ _("Admin") }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.admin_page') }}">{{ _("Admin") }}</a></li> {% else %}
{% else %} {% if check_global_perm(current_user, "EDIT_TAGS") %}
{% if check_global_perm(current_user, "EDIT_TAGS") %} <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.tag_list') }}">{{ _("Tag Editor") }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.tag_list') }}">{{ _("Tag Editor") }}</a></li> {% elif check_global_perm(current_user, "CREATE_TAG") %}
{% elif check_global_perm(current_user, "CREATE_TAG") %} <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.create_edit_tag') }}">{{ _("Create Tag") }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.create_edit_tag') }}">{{ _("Create Tag") }}</a></li> {% endif %}
{% endif %} {% if current_user.rank == current_user.rank.MODERATOR %}
{% if current_user.rank == current_user.rank.MODERATOR %} <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.license_list') }}">{{ _("License Editor") }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.license_list') }}">{{ _("License Editor") }}</a></li> {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>

@ -0,0 +1,45 @@
{% macro render_outdated_packages(outdated_packages) -%}
<ul class="list-group mt-3">
{% for package in outdated_packages %}
<li class="list-group-item">
<div class="row">
{% if package %}
<a class="col-sm-2 text-muted" href="{{ package.getDetailsURL() }}">
<img
class="img-fluid"
style="max-height: 22px; max-width: 22px;"
src="{{ package.getThumbnailURL(1) }}" />
<span class="pl-2">
{{ package.title }}
</span>
</a>
{% endif %}
<div class="col-sm">
{{ _("Git repo has commit %(ref)s", ref=package.update_config.last_commit[0:5]) }}
</div>
<div class="col-sm-auto">
<a class="btn btn-sm btn-primary mr-2" href="{{ package.getCreateReleaseURL() }}">
<i class="fas fa-plus mr-1"></i>
{{ _("Release") }}
</a>
<a class="btn btn-sm btn-secondary mr-2" href="{{ package.repo }}">
<i class="fas fa-code-branch mr-1"></i>
{{ _("Repo") }}
</a>
<a class="btn btn-sm btn-secondary" href="{{ package.getUpdateConfigURL() }}">
<i class="fas fa-cog mr-1"></i>
{{ _("Update settings") }}
</a>
</div>
</div>
</li>
{% else %}
<p class="list-group-item"><i>No outdated packages.</i></p>
{% endfor %}
</ul>
{% endmacro %}

@ -1,5 +1,5 @@
{% macro render_topics_table(topics, show_author=True, show_discard=False, current_user=current_user) -%} {% macro render_topics_table(topics, show_author=True, show_discard=False, current_user=current_user, class_=None) -%}
<table class="table"> <table class="table {{ class_ }}">
<tr> <tr>
<th></th> <th></th>
<th>Title</th> <th>Title</th>

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "todo/todo_base.html" %}
{% block title %} {% block title %}
{{ title }} {{ _("Editor Work Queue") }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -9,7 +9,7 @@
{% if canApproveScn and screenshots %} {% if canApproveScn and screenshots %}
<div class="card my-4"> <div class="card my-4">
<h3 class="card-header">Screenshots <h3 class="card-header">Screenshots
<form class="float-right" method="post" action="{{ url_for('todo.view') }}"> <form class="float-right" method="post" action="{{ url_for('todo.view_editor') }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" /> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="action" value="screenshots_approve_all" /> <input type="hidden" name="action" value="screenshots_approve_all" />
<input class="btn btn-sm btn-primary" type="submit" value="Approve All" /> <input class="btn btn-sm btn-primary" type="submit" value="Approve All" />
@ -68,31 +68,6 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
<div class="card mt-5">
<h3 class="card-header">WIP Packages</h3>
<div class="list-group list-group-flush" style="max-height: 300px; overflow: hidden auto;">
{% for p in wip_packages %}
<a href="{{ p.getDetailsURL() }}" class="list-group-item list-group-item-action">
<span class="float-right" title="Created {{ p.created_at | datetime }}">
<small>
{{ p.created_at | timedelta }} ago
</small>
</span>
{% if p.state == p.state.WIP %}
<span class="mr-2 badge badge-warning">WIP</span>
{% else %}
<span class="mr-2 badge badge-danger">{{ p.state.value }}</span>
{% endif %}
{{ p.title }} by {{ p.author.display_name }}
</a>
{% else %}
<li class="list-group-item"><i>No packages need reviewing.</i></li>
{% endfor %}
</div>
</div>
</div> </div>
{% endif %} {% endif %}
@ -157,24 +132,46 @@
{% endif %} {% endif %}
<h2 class="mt-5">Unadded Topic List</h2> <h2 class="mt-5">{{ _("Outdated packages") }}</h2>
{% if total_topics > 0 %} {% if outdated_packages > 0 %}
<p> <p>
{{ total_topics - topics_to_add }} / {{ total_topics }} packages have been been added to cdb, {{ _("There are %(count)s potentially outdated packages packages", count=outdated_packages) }}
based on cdb's forum parser. {{ topics_to_add }} remaining.
</p> </p>
<a class="btn btn-primary" href="{{ url_for('todo.outdated') }}">{{ _("View Outdated") }}</a>
<div class="progress my-4">
{% set perc = 100 * (total_topics - topics_to_add) / total_topics %}
<div class="progress-bar bg-success" role="progressbar"
style="width: {{ perc }}%" aria-valuenow="{{ perc }}" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<a class="btn btn-primary" href="{{ url_for('todo.topics') }}">View Unadded Topic List</a>
{% else %} {% else %}
<p> <p>
The forum topic crawler needs to run at least once for this section to work. <i>{{ _("No outdated packages") }}</i>
</p> </p>
{% endif %} {% endif %}
<h2 class="mt-5">WIP</h2>
{% if canApproveNew and (packages or wip_packages) %}
<div class="card">
<h3 class="card-header">WIP Packages</h3>
<div class="list-group list-group-flush" style="max-height: 300px; overflow: hidden auto;">
{% for p in wip_packages %}
<a href="{{ p.getDetailsURL() }}" class="list-group-item list-group-item-action">
<span class="float-right" title="Created {{ p.created_at | datetime }}">
<small>
{{ p.created_at | timedelta }} ago
</small>
</span>
{% if p.state == p.state.WIP %}
<span class="mr-2 badge badge-warning">WIP</span>
{% else %}
<span class="mr-2 badge badge-danger">{{ p.state.value }}</span>
{% endif %}
{{ p.title }} by {{ p.author.display_name }}
</a>
{% else %}
<li class="list-group-item"><i>No packages need reviewing.</i></li>
{% endfor %}
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}

@ -0,0 +1,12 @@
{% extends "todo/todo_base.html" %}
{% block title %}
{{ _("Outdated packages") }}
{% endblock %}
{% block content %}
<h2>{{ self.title() }}</h2>
{% from "macros/todo.html" import render_outdated_packages %}
{{ render_outdated_packages(outdated_packages) }}
{% endblock %}

@ -0,0 +1,44 @@
{% extends "base.html" %}
{% block container %}
{% if current_user.rank.atLeast(current_user.rank.EDITOR) %}
<nav class="pt-4 tabs-container">
<div class="container">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link {% if current_tab == "user" %}active{% endif %}"
href="{{ url_for('todo.view_user', username=current_user.username) }}">
{{ _("%(username)s's to do list", username=current_user.display_name) }}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if current_tab == "editor" %}active{% endif %}"
href="{{ url_for('todo.view_editor') }}">
{{ _("Editor Work Queue") }}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if current_tab == "outdated" %}active{% endif %}"
href="{{ url_for('todo.outdated') }}">
{{ _("All Outdated Packages") }}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if current_tab == "topics" %}active{% endif %}"
href="{{ url_for('todo.topics') }}">
{{ _("Topics") }}
</a>
</li>
</ul>
</div>
</nav>
{% endif %}
<main class="container mt-5">
{% if not current_user.rank.atLeast(current_user.rank.EDITOR) %}
<h1 class="mb-5">{{ self.title() }}</h1>
{% endif %}
{{ self.content() }}
</main>
{% endblock %}

@ -1,4 +1,4 @@
{% extends "base.html" %} {% extends "todo/todo_base.html" %}
{% block title %} {% block title %}
Topics to be Added Topics to be Added

@ -0,0 +1,64 @@
{% extends "todo/todo_base.html" %}
{% block title %}
{{ _("%(username)s's to do list", username=user.display_name) }}
{% endblock %}
{% block content %}
<h2>{{ _("Unapproved Packages Needing Action") }}</h2>
<div class="list-group mt-3">
{% for package in unapproved_packages %}
<a class="list-group-item list-group-item-action" href="{{ package.getDetailsURL() }}">
<div class="row">
{% if package %}
<div class="col-sm-2 text-muted">
<img
class="img-fluid"
style="max-height: 22px; max-width: 22px;"
src="{{ package.getThumbnailURL(1) }}" />
<span class="pl-2">
{{ package.title }}
</span>
</div>
{% endif %}
<div class="col-sm">
State: {{ package.state.value }}
</div>
</div>
</a>
{% else %}
<p class="list-group-item"><i>No outdated packages.</i></p>
{% endfor %}
</div>
<h2 class="mt-5">{{ _("Outdated Packages") }}</h2>
{% from "macros/todo.html" import render_outdated_packages %}
{{ render_outdated_packages(outdated_packages) }}
<h2 class="mt-5">{{ _("Unadded Topics") }}</h2>
{% if topics_to_add %}
<p>
List of your forum topics which do not have a matching package.
Topics with a strikethrough have been marked as discarded.
</p>
<div style="max-height: 20em; overflow-y: auto">
{% from "macros/topics.html" import render_topics_table %}
{{ render_topics_table(topics_to_add, show_author=False, show_discard=True, current_user=current_user) }}
</div>
{% else %}
<p class="card-body">Congrats! You don't have any topics which aren't on CDB.</p>
{% endif %}
{% endblock %}
{% block scriptextra %}
<script>
const csrf_token = "{{ csrf_token() }}";
</script>
<script src="/static/topic_discard.js"></script>
{% endblock %}

@ -15,6 +15,10 @@
<a class="btn btn-primary float-right" href="{{ url_for('users.profile_edit', username=user.username) }}"> <a class="btn btn-primary float-right" href="{{ url_for('users.profile_edit', username=user.username) }}">
{{ _("Edit Profile") }} {{ _("Edit Profile") }}
</a> </a>
<a class="btn btn-secondary float-right mr-3" href="{{ url_for('todo.view_user', username=user.username) }}">
{{ _("To Do List") }}
</a>
{% endif %} {% endif %}
{% if current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.MODERATOR) and user.email %} {% if current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.MODERATOR) and user.email %}
@ -128,32 +132,4 @@
{% from "macros/reviews.html" import render_reviews %} {% from "macros/reviews.html" import render_reviews %}
{{ render_reviews(user.reviews, current_user, True) }} {{ render_reviews(user.reviews, current_user, True) }}
{% if current_user == user or (current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.EDITOR)) %}
<div class="card mt-5">
<a name="unadded-topics"></a>
<h2 class="card-header">Unadded topics</h2>
{% if topics_to_add %}
<p class="card-body">
List of your forum topics which do not have a matching package.
Topics with a strikethrough have been marked as discarded.
</p>
{% from "macros/topics.html" import render_topics_table %}
{{ render_topics_table(topics_to_add, show_author=False, show_discard=True, current_user=current_user) }}
{% else %}
<p class="card-body">Congrats! You don't have any topics which aren't on CDB.</p>
{% endif %}
</div>
{% endif %}
{% endblock %}
{% block scriptextra %}
<script>
const csrf_token = "{{ csrf_token() }}";
</script>
<script src="/static/topic_discard.js"></script>
{% endblock %} {% endblock %}