Commit 361504f4 authored by cynddl's avatar cynddl

Implement priority on/off for the article lists

parent 7fef9c56
......@@ -37,3 +37,17 @@ class ArticleViewSet(viewsets.ModelViewSet):
article = self.get_object()
article.downvote(user_object=request.user.username)
return self.response_serialized_object(article)
@detail_route(methods=["post"], url_path="priority/on")
def priority_on(self, request, pk=None, priority=True):
article = self.get_object()
article.priority = True
article.save()
return self.response_serialized_object(article)
@detail_route(methods=["post"], url_path="priority/off")
def priority_off(self, request, pk=None, priority=True):
article = self.get_object()
article.priority = False
article.save()
return self.response_serialized_object(article)
......@@ -76,7 +76,7 @@
<table class="article-table table table-sm my-4">
<thead>
<tr>
<th>Priority</th>
{% if filter_view != "published" %}<th>Priority</th>{% endif %}
<th>ID</th>
<th>Date</th>
<th>Language</th>
......@@ -90,12 +90,19 @@
{% for article in object_list|slice:":10" %}
<tr id="row_empty_{{article.id}}" class="empty-row"><td colspan="8"></td></tr>
<tr id="row_{{article.id}}">
<td class="icon-cell"><i class="fa fa-dot-circle-o" aria-hidden="true" style="color:red"></i></td>
{% if filter_view != "published" %}
<td class="icon-cell actions-item" onclick="javascript:call_priority({{article.id}}, {{article.priority|yesno:"false,true"}})">
<i id="priority_{{article.id}}" class="fa fa-star{{ article.priority|yesno:",-o" }}" aria-hidden="true"></i>
</td>
{% endif %}
<td>{{article.id}}</td>
<td>{{article.created_at |date:'d/m/y'}}<br />{{article.created_at |date:'H:i'}}</td>
<td>{{article.lang}}</td>
<td class="title-cell"><a target="_blank" href="{{article.url}}"><strong>{{article.title}}</strong></a></td>
<td>
{% if filter_view == "published" %}
{{article.und_score}}
{% else %}
<ul class="votes-list">
<li class="actions-item" onclick="javascript:call_upvote({{article.id}})">
<span id="count_up_{{article.id}}">{{article.und_score_up}}</span>
......@@ -106,8 +113,9 @@
<i class="fa fa-thumbs-down" aria-hidden="true" style="color:red"></i>
</li>
</ul>
{% endif %}
</td>
<td>{{article.und_votes.first.username}}</td>
<td>{{article.created_by}}</td>
<td class="actions-cell">
<ul class="actions-list">
{% if filter_view == 'flux' %}
......@@ -201,5 +209,12 @@
$("#row_tags_" + id).hide();
});
}
function call_priority(id, flag) {
var url = "/api/articles/" + id + "/priority/" + (flag ? "on/" : "off/");
$.post(url, {'priority': flag}, function response(data) {
$("#priority_" + id).toggleClass("fa-star").toggleClass("fa-star-o");
});
}
</script>
{% endblock %}
......@@ -27,7 +27,7 @@ class ArticleListFlux(UDList):
qs = Article.objects.filter(status="PUBLISHED")
elif filter_view == "draft":
qs = Article.objects.extra(where=[
"und_score_up + und_score_down >= 3",
"(und_score_up + und_score_down >= 3) or priority",
"status='PENDING'"
])
elif filter_view == "rejected":
......@@ -41,7 +41,7 @@ class ArticleListFlux(UDList):
context = super().get_context_data(**kwargs)
context["filter_view"] = self.kwargs.get("filter_view", "draft")
context["nb_draft"] = Article.objects.extra(where=[
"und_score_up + und_score_down >= 3",
"(und_score_up + und_score_down >= 3) or priority",
"status='PENDING'"
]).count()
return context
......
......@@ -55,12 +55,12 @@ table.article-table td.icon-cell {
table.article-table ul {
padding: 0;
margin: 0;
}
& li.actions-item {
cursor: pointer;
.actions-item {
cursor: pointer;
&:--enter {
font-weight: 600;
}
&:--enter {
font-weight: 600;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment