UI to allow update of comment filter status
This commit is contained in:
parent
4b0c4fcc73
commit
a0488f2b23
3 changed files with 69 additions and 26 deletions
|
@ -8,10 +8,9 @@ function filter_new_status(id, new_status) {
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.result === 'Update successful') {
|
if(json.result === 'Update successful') {
|
||||||
const postRow = document.getElementById(`post-${id}`);
|
const postRow = document.getElementById(`post-${id}`);
|
||||||
if(document.location.pathname === '/admin/filtered_submissions' || document.location.pathname === '/admin/reported/posts' ) {
|
if(document.location.pathname === '/admin/filtered/posts' || document.location.pathname === '/admin/reported/posts' ) {
|
||||||
postRow.parentElement.removeChild(postRow);
|
postRow.parentElement.removeChild(postRow);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
const approveLink = postRow.querySelector('a#filter-approve')
|
const approveLink = postRow.querySelector('a#filter-approve')
|
||||||
const removeLink = postRow.querySelector('a#filter-remove')
|
const removeLink = postRow.querySelector('a#filter-remove')
|
||||||
if(approveLink && removeLink) {
|
if(approveLink && removeLink) {
|
||||||
|
@ -28,6 +27,37 @@ function filter_new_status(id, new_status) {
|
||||||
if(reportButton) {
|
if(reportButton) {
|
||||||
reportButton.parentElement.removeChild(reportButton);
|
reportButton.parentElement.removeChild(reportButton);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('toast-post-success-text').innerText = json.result;
|
||||||
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show();
|
||||||
|
} else {
|
||||||
|
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
||||||
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function filter_new_comment_status(id, new_status) {
|
||||||
|
fetch('/admin/update_filter_status', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ comment_id: id, new_status: new_status, formkey: formkey() }),
|
||||||
|
headers: { 'content-type': 'application/json' }
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(json => {
|
||||||
|
if(json.result === 'Update successful') {
|
||||||
|
const commentRow = document.getElementById(`comment-${id}`);
|
||||||
|
if(document.location.pathname === '/admin/filtered/comments' || document.location.pathname === '/admin/reported/comments' ) {
|
||||||
|
commentRow.parentElement.removeChild(commentRow);
|
||||||
|
} else {
|
||||||
|
const approveLink = commentRow.querySelector('button#filter-approve')
|
||||||
|
const removeLink = commentRow.querySelector('button#filter-remove')
|
||||||
|
if(approveLink && removeLink) {
|
||||||
|
approveLink.parentElement.removeChild(approveLink);
|
||||||
|
removeLink.parentElement.removeChild(removeLink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('toast-post-success-text').innerText = json.result;
|
document.getElementById('toast-post-success-text').innerText = json.result;
|
||||||
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show();
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show();
|
||||||
|
|
|
@ -494,17 +494,22 @@ def update_filter_status(v):
|
||||||
update_body = request.get_json()
|
update_body = request.get_json()
|
||||||
new_status = update_body.get('new_status')
|
new_status = update_body.get('new_status')
|
||||||
post_id = update_body.get('post_id')
|
post_id = update_body.get('post_id')
|
||||||
|
comment_id = update_body.get('comment_id')
|
||||||
if new_status not in ['normal', 'removed', 'ignored']:
|
if new_status not in ['normal', 'removed', 'ignored']:
|
||||||
return { 'result': f'Status of {new_status} is not permitted' }
|
return { 'result': f'Status of {new_status} is not permitted' }
|
||||||
|
|
||||||
|
if post_id:
|
||||||
rows_updated = g.db.query(Submission).where(Submission.id == post_id).update({Submission.filter_state: new_status})
|
rows_updated = g.db.query(Submission).where(Submission.id == post_id).update({Submission.filter_state: new_status})
|
||||||
|
elif comment_id:
|
||||||
|
rows_updated = g.db.query(Comment).where(Comment.id == comment_id).update({Comment.filter_state: new_status})
|
||||||
|
else:
|
||||||
|
return { 'result': f'No valid item ID provided' }
|
||||||
|
|
||||||
if rows_updated == 1:
|
if rows_updated == 1:
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return { 'result': 'Update successful' }
|
return { 'result': 'Update successful' }
|
||||||
else:
|
else:
|
||||||
return { 'result': f'Submission ID {post_id} does not exist' }
|
return { 'result': 'Item ID does not exist' }
|
||||||
|
|
||||||
|
|
||||||
@app.get("/admin/image_posts")
|
@app.get("/admin/image_posts")
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
|
|
|
@ -457,6 +457,11 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if v and v.admin_level > 2 and c.filter_state == 'filtered' %}
|
||||||
|
<button class="btn" role="button" id="filter-approve" onclick="filter_new_comment_status({{ c.id }}, 'normal')"><span>Approve</span></button>
|
||||||
|
<button class="btn" role="button" id="filter-remove" onclick="filter_new_comment_status({{ c.id }}, 'removed')"><span>Remove</span></button>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if v %}
|
{% if v %}
|
||||||
<button style="margin-top:0.2rem" class="btn caction py-0 nobackground px-1 text-muted" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-ellipsis-h fa-fw"></i></button>
|
<button style="margin-top:0.2rem" class="btn caction py-0 nobackground px-1 text-muted" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-ellipsis-h fa-fw"></i></button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
|
@ -842,6 +847,9 @@
|
||||||
|
|
||||||
{% if v and v.admin_level > 1 %}
|
{% if v and v.admin_level > 1 %}
|
||||||
<script src="/assets/js/comments_admin.js?v=250"></script>
|
<script src="/assets/js/comments_admin.js?v=250"></script>
|
||||||
|
{% if v.admin_level > 2 %}
|
||||||
|
<script src="/assets/js/filter_actions.js?v=2"></script>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% include "expanded_image_modal.html" %}
|
{% include "expanded_image_modal.html" %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue