Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spam2: pagination added #8063

Merged
merged 13 commits into from
Jun 30, 2020
19 changes: 11 additions & 8 deletions app/assets/javascripts/spam2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

function table_main(id) {
var table = $(id).DataTable({
"order": [[1, "desc"]],
"stateSave": false,
"autoWidth": false,
"search": {
"regex": true
},
"scrollX": true
"scrollX": true,
"language": {
"search": "Search in this batch",
"info": "Showing _START_ to _END_ of _TOTAL_ entries in batch",
"infoFiltered": "(filtered from this batch of _MAX_ entries)",
"lengthMenu": "Show _MENU_ entries for this batch"
}
});
$('#selectall').click(function () {
$('.selectedId').prop('checked', this.checked);
Expand All @@ -27,11 +31,10 @@ function table_main(id) {
return table;
}

function disable_buttons(id){
if ($(id).is(":checked")){
function disable_buttons(id) {
if ($(id).is(":checked")) {
$("#batch-spam, #batch-publish, #delete-batch, #batch-ban, #batch-unban").removeClass("disabled");
}
else {
} else {
$("#batch-spam, #batch-publish, #delete-batch, #batch-ban, #batch-unban").addClass("disabled");
}
}
}
49 changes: 29 additions & 20 deletions app/assets/stylesheets/spam2.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
*= require datatables/dataTables.bootstrap4
*/

.nav_top {
z-index: 5;
width: 100%;
}

#batch-spam:hover {
color: red !important;
color: red !important;
cursor: pointer;
}

Expand All @@ -32,53 +33,61 @@
}

#batch-unban:hover {
color: green !important;
color: green !important;
cursor: pointer;
}

#node-hover:hover{
color:blue !important;
#node-hover:hover {
color: blue !important;
}

#table-card {
width: 100%;
}

#card-top {
margin-top:2vh;
margin-top: 2vh;
}

#bulk-nav{
#bulk-nav {
margin-top: 2%;
margin-bottom: 1%;
width:100%;
width: 100%;
}

.active .drop{
color:white !important;
.active .drop {
color: white !important;
}

#col-search{
#col-search {
cursor: text;
text-align:left !important;
margin-top:2px;
text-align: left !important;
margin-top: 2px;
}

#col-select {
margin-top: 2px;
}

#col-select{
margin-top:2px;
.page-table {
width: 100%;
margin-top: 10px;
}

@media (max-width: 750px) {
#table-card, #bulk-nav, .nav_top,
#table-card,
#bulk-nav,
.nav_top,
.page-table,
#card-top {
margin-left: 5vw;
width:90vw;
margin-left: 5vw;
width: 90vw;
}
.nav_title{
.nav_title {
font-size: 18px;
margin-bottom : 10px;
margin-bottom: 10px;
}
#card-top .card-header{
#card-top .card-header {
font-size: 18px;
}
}
11 changes: 7 additions & 4 deletions app/controllers/spam2_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class Spam2Controller < ApplicationController

def _spam
if logged_in_as(%w(moderator admin))
@nodes = Node.order('nid DESC')
@nodes = Node.order('changed DESC')
.paginate(page: params[:page], per_page: 100)
@nodes = if params[:type] == 'wiki'
@nodes.where(type: 'page', status: 1)
else
Expand All @@ -22,7 +23,8 @@ def _spam
def _spam_revisions
if logged_in_as(%w(admin moderator))
@revisions = Revision.where(status: 0)
.order('timestamp DESC')
.paginate(page: params[:page], per_page: 100)
.order('timestamp DESC')
render template: 'spam2/_spam'
else
flash[:error] = 'Only moderators and admins can moderate this.'
Expand All @@ -32,8 +34,9 @@ def _spam_revisions

def _spam_comments
if logged_in_as(%w(moderator admin))
@comments = Comment.order('timestamp DESC')
.where(status: 0)
@comments = Comment.where(status: 0)
.order('timestamp DESC')
.paginate(page: params[:page], per_page: 100)
render template: 'spam2/_spam'
else
flash[:error] = 'Only moderators can moderate comments.'
Expand Down
10 changes: 9 additions & 1 deletion app/views/spam2/_comments.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ $(document).ready(function () {
</tbody>
</table>
</div>
</div>
</div>
<div class="page-table">
VladimirMikulic marked this conversation as resolved.
Show resolved Hide resolved
<div class="float-right">
<%= will_paginate @comments, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || @comments.empty?%>
</div>
<div class="float-left">
Batch <%= @comments.current_page%> of <%= @comments.total_pages %> total Batches
</div>
</div>
30 changes: 21 additions & 9 deletions app/views/spam2/_nodes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ $(document).ready(function () {
<div class="bg-light navbar navbar-expand">
<ul class="nav navbar-expand navbar-nav-scroll">
<li class="nav-item">
<a class="btn nav-link small text-dark">Selected <span id="select-count" class="badge badge-dark">0</span></a>
<a class="btn nav-link small text-dark" data-toggle="tooltip" data-placement="top" title="Selected per page">Selected <span id="select-count" class="badge badge-dark">0</span></a>
</li>
<li class="nav-item">
<a class="btn nav-link small"id="reset">Reset all</a>
Expand Down Expand Up @@ -129,6 +129,9 @@ $(document).ready(function () {
</select>
</li>
<% end %>
<li class="nav-item">
<a class="btn nav-link text-dark" data-toggle="tooltip" data-placement="top" title="Nodes are divided into batch of 100 entries"><%= page_entries_info(@nodes) %></a>
</li>
</ul>
</div>
<div class="card-body" style="overflow-x:hidden;">
Expand All @@ -149,22 +152,22 @@ $(document).ready(function () {
<td><input class="selectedId" value="<%= node.nid %>" type="checkbox" /></td>
<td>
<i class="fa fa-file text-secondary"></i>
<a href="javascript:void(0);" class="text-dark font-weight-bold" id="node-hover" data-toggle="modal" data-target="#ninfo<%= node.id %>"><%= node.title.truncate(20) %></a><br />
<a href="javascript:void(0);" class="text-dark font-weight-bold" id="node-hover" data-toggle="modal" data-target="#ninfo<%= node.id %>"><%= node.title.truncate(15) %></a><br />
</td>
<td>
<a href="/profile/<%= node.author&.name %>" class="text-dark"><%= node.author&.name %> <%= node.author&.new_contributor%></a>
<a href="/profile/<%= node.author&.name %>" class="text-info"><%= node.author&.name %> <%= node.author&.new_contributor%></a>
</td>
<td>
<span class="text-secondary"><%= node.type.capitalize %> <span style="color:<% if node.status == 1 %>green;<% elsif node.status == 0 %>red;<% elsif node.status == 4 %>blue;<% end %>">(<% if node.status == 1 %>Published<% elsif node.status == 0 %>Spammed<% elsif node.status == 4 %>Unmoderated<% end %>)</span>
<span class="text-secondary"><%= node.type.capitalize %> <span class="badge badge-pill badge-<% if node.status == 1 %>success<% elsif node.status == 0 %>danger<% elsif node.status == 4 %>primary<% end %>"> <% if node.status == 1 %>Published<% elsif node.status == 0 %>Spammed<% elsif node.status == 4 %>Unmoderated<% end %></span>
</td>
<td>
<span class="text-dark"><%= time_ago_in_words(node.updated_at) %> ago</span>
</td>
<td style="height:35px !important;">
<a class="badge btn badge-pill badge<% if node.status != 1 %>-success<% else %>-secondary<% end %> publish" data-remote="true" href="/moderate/publish/<%= node.id %>" ><i class="fa fa-check-circle fa-white"></i> Publish post</a>
<a class="badge btn badge-pill badge<% if node.status != 0 %>-danger<% else %>-secondary disabled<% end %> spam" data-remote="true" href="/moderate/spam/<%= node.id %>"><i class="fa fa-ban fa-white"></i> Spam post</a>
<a class="badge badge-pill badge-secondary ban a<%= node.author.id %>" <% if node.author.status == 0 %>style="display:none;"<% end %> data-remote="true" href="/ban/<%= node.author.id %>">Ban user</a>
<a class="badge badge-pill badge-secondary unban a-unban<%= node.author.id %>" <% if node.author.status == 1 %>style="display:none;"<% end %> data-remote="true" href="/unban/<%= node.author.id %>">Unban user</a>
<a class="badge btn badge<% if node.status != 1 %>-success<% else %>-secondary disabled<% end %> publish" data-remote="true" href="/moderate/publish/<%= node.id %>" ><i class="fa fa-check-circle fa-white"></i> Publish post</a>
<a class="badge btn badge<% if node.status != 0 %>-danger<% else %>-secondary disabled<% end %> spam" data-remote="true" href="/moderate/spam/<%= node.id %>"><i class="fa fa-ban fa-white"></i> Spam post</a>
<a class="badge badge-secondary ban a<%= node.author.id %>" <% if node.author.status == 0 %>style="display:none;"<% end %> data-remote="true" href="/ban/<%= node.author.id %>">Ban user</a>
<a class="badge badge-secondary unban a-unban<%= node.author.id %>" <% if node.author.status == 1 %>style="display:none;"<% end %> data-remote="true" href="/unban/<%= node.author.id %>">Unban user</a>
<%= link_to "/notes/delete/#{node.id}", data: { confirm: "Are you sure you want to delete #{node.path}?" }, :remote => true, :class => "px-3 delete" do %>
<i class="fa fa-trash text-dark"></i>
<% end %>
Expand Down Expand Up @@ -226,4 +229,13 @@ $(document).ready(function () {
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="page-table">
<div class="float-right">
<%= will_paginate @nodes, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || @nodes.empty?%>
</div>
<div class="float-left">
Batch <%= @nodes.current_page%> of <%= @nodes.total_pages %> total Batches
</div>
</div>
10 changes: 9 additions & 1 deletion app/views/spam2/_revisions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ $(document).ready(function () {
</tbody>
</table>
</div>
</div>
</div>
<div class="page-table">
<div class="float-right">
<%= will_paginate @revisions, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || @revisions.empty?%>
</div>
<div class="float-left">
Batch <%= @revisions.current_page%> of <%= @revisions.total_pages %> total Batches
</div>
</div>
8 changes: 4 additions & 4 deletions app/views/spam2/_spam.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
</div>

<div class="card text-center" id="card-top">
<p class="card-header text-dark border-bottom-0 h5"><b>Moderate Potential <i class=" pt-1 fa fa-ban text-secondary "></i> Spam </b></p>
<p class="card-header border-bottom-0 h4"><a class="text-secondary" href="#bulk-nav"><b>Moderate Potential Spam <i class="fa fa-check text-success"></i></b></a></p>
<div class="card-body">
<p class="card-text text-secondary font-italic">Moderators and admins have the ability to "spam" posts if they include inappropriate content, blatant advertising, or are otherwise problematic. If you're not sure, email at <a href="mailto:organizers@<%= request.host %>" class="badge badge-info text-white">moderators@<%= request.host %></a> If we all work together, we can keep spam to a minimum. Thanks for helping out!</p>
<p class="card-text text-secondary font-italic">Moderators and admins have the ability to "spam" posts if they include inappropriate content, blatant advertising, or are otherwise problematic. If you're not sure, email at <a href="mailto:organizers@<%= request.host %>" class="badge badge-info badge-pill text-white">moderators@<%= request.host %></a> If we all work together, we can keep spam to a minimum. Thanks for helping out!</p>
</div>
</div>

Expand All @@ -50,7 +50,7 @@
<a class="nav-link btn btn-light border disabled text-dark d-inline-flex" id="delete-batch"><i class=" pt-1 pr-2 fa fa-trash text-danger"></i> Delete</a>
</li>
<li class="nav-item pr-4">
<a class="nav-link btn btn-light border text-dark d-inline-flex" id="all"><i class=" pt-1 pr-2 fa fa-check text-primary"></i> Select</a>
<a class="nav-link btn btn-light border text-dark d-inline-flex" id="all" data-toggle="tooltip" data-placement="top" title="Increase entries per page to increase selections"><i class=" pt-1 pr-2 fa fa-check text-primary"></i> Select</a>
</li>
<li class="nav-item pr-4">
<a class="nav-link btn btn-light border disabled text-dark d-inline-flex" id="batch-ban"><i class=" pt-1 pr-2 fa fa-flag text-warning"></i> Ban</a>
Expand All @@ -62,7 +62,7 @@
<div class="btn-group" role="group">
<input class="btn border" id="col-search" type="search" placeholder="Filter by column" aria-label="Search">
<select id="col-select" class=" btn bg-light text-dark custom-select custom-select-sm form-control form-control-md" data-toggle="tooltip" data-placement="top" title="Select column here and then search to filter">
<option value="">Select filter </option>
<option value="">Filter by None </option>
<option value="1">Filter by Title</option>
<option value="2">Filter by Author</option>
<option value="3">Filter by Status</option>
Expand Down