mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Remove some forum topic related features (#527)
This commit is contained in:
parent
bb81e1387a
commit
6280cd5947
@ -234,24 +234,6 @@ def topics():
|
||||
return jsonify([t.as_dict() for t in query.all()])
|
||||
|
||||
|
||||
@bp.route("/api/topic_discard/", methods=["POST"])
|
||||
@login_required
|
||||
def topic_set_discard():
|
||||
tid = request.args.get("tid")
|
||||
discard = request.args.get("discard")
|
||||
if tid is None or discard is None:
|
||||
error(400, "Missing topic ID or discard bool")
|
||||
|
||||
topic = ForumTopic.query.get(tid)
|
||||
if not topic.check_perm(current_user, Permission.TOPIC_DISCARD):
|
||||
error(403, "Permission denied, need: TOPIC_DISCARD")
|
||||
|
||||
topic.discarded = discard == "true"
|
||||
db.session.commit()
|
||||
|
||||
return jsonify(topic.as_dict())
|
||||
|
||||
|
||||
@bp.route("/api/whoami/")
|
||||
@is_api_authd
|
||||
@cors_allowed
|
||||
|
@ -101,7 +101,6 @@ def list_all():
|
||||
|
||||
topics = None
|
||||
if qb.search and not query.has_next:
|
||||
qb.show_discarded = True
|
||||
topics = qb.build_topic_query().all()
|
||||
|
||||
tags_query = db.session.query(func.count(Tags.c.tag_id), Tag) \
|
||||
|
@ -90,38 +90,6 @@ def view_editor():
|
||||
unfulfilled_meta_packages=unfulfilled_meta_packages, audit_log=audit_log)
|
||||
|
||||
|
||||
@bp.route("/todo/topics/")
|
||||
@login_required
|
||||
def topics():
|
||||
qb = QueryBuilder(request.args, cookies=True)
|
||||
qb.set_sort_if_none("date")
|
||||
query = qb.build_topic_query()
|
||||
|
||||
tmp_q = ForumTopic.query
|
||||
if not qb.show_discarded:
|
||||
tmp_q = tmp_q.filter_by(discarded=False)
|
||||
total = tmp_q.count()
|
||||
topic_count = query.count()
|
||||
|
||||
page = get_int_or_abort(request.args.get("page"), 1)
|
||||
num = get_int_or_abort(request.args.get("n"), 100)
|
||||
if num > 100 and not current_user.rank.at_least(UserRank.APPROVER):
|
||||
num = 100
|
||||
|
||||
query = query.paginate(page=page, per_page=num)
|
||||
next_url = url_for("todo.topics", page=query.next_num, query=qb.search,
|
||||
show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \
|
||||
if query.has_next else None
|
||||
prev_url = url_for("todo.topics", page=query.prev_num, query=qb.search,
|
||||
show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \
|
||||
if query.has_prev else None
|
||||
|
||||
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,
|
||||
next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages,
|
||||
n=num, sort_by=qb.order_by)
|
||||
|
||||
|
||||
@bp.route("/todo/tags/")
|
||||
@login_required
|
||||
def tags():
|
||||
|
@ -435,7 +435,6 @@ Supported query parameters:
|
||||
* `type`: Package types (`mod`, `game`, `txp`).
|
||||
* `sort`: Sort by (`name`, `views`, `created_at`).
|
||||
* `show_added`: Show topics that have an existing package.
|
||||
* `show_discarded`: Show topics marked as discarded.
|
||||
* `limit`: Return at most `limit` topics.
|
||||
|
||||
|
||||
|
@ -26,7 +26,6 @@ The [Editor Work Queue](/todo/) and related pages contain useful information for
|
||||
* The package, release, and screenshot approval queues.
|
||||
* Packages which are outdated or are missing tags.
|
||||
* A list of forum topics without packages.
|
||||
Editors can create the packages or "discard" them if they don't think it's worth adding them.
|
||||
|
||||
## Editor Notifications
|
||||
|
||||
|
@ -142,6 +142,7 @@ class ForumTopic(db.Model):
|
||||
author = db.relationship("User", back_populates="forum_topics")
|
||||
|
||||
wip = db.Column(db.Boolean, default=False, nullable=False)
|
||||
# TODO: remove
|
||||
discarded = db.Column(db.Boolean, default=False, nullable=False)
|
||||
|
||||
type = db.Column(db.Enum(PackageType), nullable=False)
|
||||
@ -175,7 +176,6 @@ class ForumTopic(db.Model):
|
||||
"posts": self.posts,
|
||||
"views": self.views,
|
||||
"is_wip": self.wip,
|
||||
"discarded": self.discarded,
|
||||
"created_at": self.created_at.isoformat(),
|
||||
}
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
// @author rubenwardy
|
||||
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
|
||||
|
||||
"use strict";
|
||||
|
||||
document.querySelectorAll(".topic-discard").forEach(ele => ele.addEventListener("click", (e) => {
|
||||
const row = ele.parentNode.parentNode;
|
||||
const tid = ele.getAttribute("data-tid");
|
||||
const discard = !row.classList.contains("discardtopic");
|
||||
fetch(new Request("/api/topic_discard/?tid=" + tid +
|
||||
"&discard=" + (discard ? "true" : "false"), {
|
||||
method: "post",
|
||||
credentials: "same-origin",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"X-CSRFToken": csrf_token,
|
||||
},
|
||||
})).then(function(response) {
|
||||
response.text().then(function(txt) {
|
||||
if (JSON.parse(txt).discarded) {
|
||||
row.classList.add("discardtopic");
|
||||
ele.classList.remove("btn-danger");
|
||||
ele.classList.add("btn-success");
|
||||
ele.innerText = "Show";
|
||||
} else {
|
||||
row.classList.remove("discardtopic");
|
||||
ele.classList.remove("btn-success");
|
||||
ele.classList.add("btn-danger");
|
||||
ele.innerText = "Discard";
|
||||
}
|
||||
}).catch(console.error);
|
||||
}).catch(console.error);
|
||||
}));
|
@ -121,7 +121,6 @@ class QueryBuilder:
|
||||
else:
|
||||
self.version = None
|
||||
|
||||
self.show_discarded = is_yes(args.get("show_discarded"))
|
||||
self.show_added = args.get("show_added")
|
||||
if self.show_added is not None:
|
||||
self.show_added = is_yes(self.show_added)
|
||||
@ -300,9 +299,6 @@ class QueryBuilder:
|
||||
def build_topic_query(self, show_added=False):
|
||||
query = ForumTopic.query
|
||||
|
||||
if not self.show_discarded:
|
||||
query = query.filter_by(discarded=False)
|
||||
|
||||
show_added = self.show_added == True or (self.show_added is None and show_added)
|
||||
if not show_added:
|
||||
query = query.filter(~ db.exists().where(Package.forums==ForumTopic.topic_id))
|
||||
|
@ -1,4 +1,4 @@
|
||||
{% macro render_topics_table(topics, show_author=True, show_discard=False, current_user=current_user, class_=None) -%}
|
||||
{% macro render_topics_table(topics, show_author=True, current_user=current_user, class_=None) -%}
|
||||
<table class="table {{ class_ }}">
|
||||
<tr>
|
||||
<th></th>
|
||||
@ -9,7 +9,7 @@
|
||||
<th>{{ _("Actions") }}</th>
|
||||
</tr>
|
||||
{% for topic in topics %}
|
||||
<tr class="{% if topic.wip %}wiptopic{% endif %} {% if topic.discarded %}discardtopic{% endif %}">
|
||||
<tr class="{% if topic.wip %}wiptopic{% endif %}">
|
||||
<td>
|
||||
[{{ topic.type.text }}]
|
||||
</td>
|
||||
@ -29,15 +29,6 @@
|
||||
{{ _("Create") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if show_discard and current_user.is_authenticated and topic.check_perm(current_user, "TOPIC_DISCARD") %}
|
||||
<a class="btn btn-{% if topic.discarded %}success{% else %}danger{% endif %} topic-discard" data-tid={{ topic.topic_id }}>
|
||||
{% if topic.discarded %}
|
||||
{{ _("Show") }}
|
||||
{% else %}
|
||||
{{ _("Discard") }}
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if topic.link %}
|
||||
<a class="btn btn-info" href="{{ topic.link }}">{{ topic.link | domain | truncate(18) }}</a>
|
||||
{% endif %}
|
||||
@ -48,24 +39,22 @@
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro render_topics(topics, current_user, show_author=True) -%}
|
||||
<ul>
|
||||
{% macro render_topics(topics, current_user) -%}
|
||||
<div class="list-group">
|
||||
{% for topic in topics %}
|
||||
<li{% if topic.wip %} class="wiptopic"{% endif %}>
|
||||
<a href="https://forum.minetest.net/viewtopic.php?t={{ topic.topic_id}}">{{ topic.title }}</a>
|
||||
{% if topic.wip %}[{{ _("WIP") }}]{% endif %}
|
||||
{% if topic.discarded %}[{{ _("Old") }}]{% endif %}
|
||||
{% if topic.name %}[{{ topic.name }}]{% endif %}
|
||||
{% if show_author %}
|
||||
by <a href="{{ url_for('users.profile', username=topic.author.username) }}">{{ topic.author.display_name }}</a>
|
||||
{% endif %}
|
||||
{% if topic.author == current_user or topic.author.check_perm(current_user, "CHANGE_AUTHOR") %}
|
||||
|
|
||||
<a href="{{ url_for('packages.create_edit', author=topic.author.username, repo=topic.get_repo_url(), forums=topic.topic_id, title=topic.title, bname=topic.name) }}">
|
||||
{{ _("Create") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
<a class="list-group-item list-group-item-action" href="https://forum.minetest.net/viewtopic.php?t={{ topic.topic_id}}">
|
||||
<span class="float-end text-muted">
|
||||
{{ topic.created_at | date }}
|
||||
</span>
|
||||
{% set title %}
|
||||
<strong>{{ topic.title }}</strong>
|
||||
{% endset %}
|
||||
{{ _("%(title)s by %(author)s", title=title, author=topic.author.display_name) }}
|
||||
<span class="text-muted">
|
||||
{% if topic.wip %}[{{ _("WIP") }}]{% endif %}
|
||||
{% if topic.name %}[{{ topic.name }}]{% endif %}
|
||||
</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
@ -35,12 +35,6 @@
|
||||
{{ _("Missing Screenshots") }}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if current_tab == 'topics' %}active{% endif %}"
|
||||
href="{{ url_for('todo.topics') }}">
|
||||
{{ _("Forum Topics") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -1,101 +0,0 @@
|
||||
{% extends "todo/todo_base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Topics to be Added
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="float-end">
|
||||
<div class="btn-group btn-group-sm me-2">
|
||||
<a class="btn btn-secondary {% if sort_by=='date' %}active{% endif %}"
|
||||
href="{{ url_for('todo.topics', q=query, show_discarded=show_discarded, n=n, sort='date') }}">
|
||||
{{ _("Sort by date") }}
|
||||
</a>
|
||||
<a class="btn btn-secondary {% if sort_by=='name' %}active{% endif %}"
|
||||
href="{{ url_for('todo.topics', q=query, show_discarded=show_discarded, n=n, sort='name') }}">
|
||||
{{ _("Sort by name") }}
|
||||
</a>
|
||||
<a class="btn btn-secondary {% if sort_by=='views' %}active{% endif %}"
|
||||
href="{{ url_for('todo.topics', q=query, show_discarded=show_discarded, n=n, sort='views') }}">
|
||||
{{ _("Sort by views") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="btn-group btn-group-sm">
|
||||
{% if current_user.rank.at_least(current_user.rank.APPROVER) %}
|
||||
{% if n >= 10000 %}
|
||||
<a class="btn btn-secondary"
|
||||
href="{{ url_for('todo.topics', q=query, show_discarded=show_discarded, n=100, sort=sort_by) }}">
|
||||
{{ _("Paginated list") }}
|
||||
</a>
|
||||
{% else %}
|
||||
<a class="btn btn-secondary"
|
||||
href="{{ url_for('todo.topics', q=query, show_discarded=show_discarded, n=10000, sort=sort_by) }}">
|
||||
{{ _("Unlimited list") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<a class="btn btn-secondary" href="{{ url_for('todo.topics', q=query, show_discarded=not show_discarded, n=n, sort=sort_by) }}">
|
||||
{% if not show_discarded %}
|
||||
{{ _("Show discarded topics") }}
|
||||
{% else %}
|
||||
{{ _("Hide discarded topics") }}
|
||||
{% endif %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>{{ _("Topics to be Added") }}</h1>
|
||||
|
||||
{% if topic_count > 0 %}
|
||||
<p>
|
||||
{{ total - topic_count }} / {{ total }} topics have been added as packages to CDB.
|
||||
{{ topic_count }} remaining.
|
||||
</p>
|
||||
<div class="progress">
|
||||
{% set perc = 100 * (total - topic_count) / total %}
|
||||
<div class="progress-bar bg-success" role="progressbar"
|
||||
style="width: {{ perc }}%" aria-valuenow="{{ perc }}" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>
|
||||
The forum topic crawler needs to run at least once for this section to work.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<form method="GET" action="{{ url_for('todo.topics') }}" class="my-4">
|
||||
<input type="hidden" name="show_discarded" value={{ show_discarded and "True" or "False" }} />
|
||||
<input type="hidden" name="n" value={{ n }} />
|
||||
<input type="hidden" name="sort" value={{ sort_by or "date" }} />
|
||||
<input name="q" type="text" placeholder="Search topics" value="{{ query or ''}}">
|
||||
<input class="btn btn-secondary my-2 my-sm-0 me-sm-2" type="submit" value="Search" />
|
||||
</form>
|
||||
|
||||
{% from "macros/topics.html" import render_topics_table %}
|
||||
{{ render_topics_table(topics, show_discard=True, current_user=current_user) }}
|
||||
|
||||
<ul class="pagination mt-4">
|
||||
<li class="page-item {% if not prev_url %}disabled{% endif %}">
|
||||
<a class="page-link" {% if prev_url %}href="{{ prev_url }}"{% endif %}>«</a>
|
||||
</li>
|
||||
{% for i in range(1, page_max+1) %}
|
||||
<li class="page-item {% if i == page %}active{% endif %}">
|
||||
<a class="page-link"
|
||||
href="{{ url_for('todo.topics', page=i, query=query, show_discarded=show_discarded, n=n, sort=sort_by) }}">
|
||||
{{ i }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li class="page-item {% if not next_url %}disabled{% endif %}">
|
||||
<a class="page-link" {% if next_url %}href="{{ next_url }}"{% endif %}>»</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
{% block scriptextra %}
|
||||
<script>
|
||||
const csrf_token = "{{ csrf_token() }}";
|
||||
</script>
|
||||
<script src="/static/js/topic_discard.js"></script>
|
||||
{% endblock %}
|
@ -203,12 +203,11 @@
|
||||
{% 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) }}
|
||||
{{ render_topics_table(topics_to_add, show_author=False, current_user=current_user) }}
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="card-body">{{ _("Congrats! You don't have any topics which aren't on CDB.") }}</p>
|
||||
@ -220,5 +219,4 @@
|
||||
<script>
|
||||
const csrf_token = "{{ csrf_token() }}";
|
||||
</script>
|
||||
<script src="/static/js/topic_discard.js"></script>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user