Skip to content

Commit 7a5c0bd

Browse files
Spam2: pagination added (#8063)
* pagination added * indentation * pagination of spam2 * indentation * spam2 pagination * more pagination feature added * travis restart * travis restart 1 * tooltips added * formatting of spam2 * IMPROVE: _comments.html.erb - closed the `page-table` div * formatting of spam2 * author color Co-authored-by: Vladimir Mikulic <[email protected]>
1 parent f2b953d commit 7a5c0bd

File tree

7 files changed

+90
-47
lines changed

7 files changed

+90
-47
lines changed

app/assets/javascripts/spam2.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55

66
function table_main(id) {
77
var table = $(id).DataTable({
8-
"order": [[1, "desc"]],
9-
"stateSave": false,
108
"autoWidth": false,
119
"search": {
1210
"regex": true
1311
},
14-
"scrollX": true
12+
"scrollX": true,
13+
"language": {
14+
"search": "Search in this batch",
15+
"info": "Showing _START_ to _END_ of _TOTAL_ entries in batch",
16+
"infoFiltered": "(filtered from this batch of _MAX_ entries)",
17+
"lengthMenu": "Show _MENU_ entries for this batch"
18+
}
1519
});
1620
$('#selectall').click(function () {
1721
$('.selectedId').prop('checked', this.checked);
@@ -27,11 +31,10 @@ function table_main(id) {
2731
return table;
2832
}
2933

30-
function disable_buttons(id){
31-
if ($(id).is(":checked")){
34+
function disable_buttons(id) {
35+
if ($(id).is(":checked")) {
3236
$("#batch-spam, #batch-publish, #delete-batch, #batch-ban, #batch-unban").removeClass("disabled");
33-
}
34-
else {
37+
} else {
3538
$("#batch-spam, #batch-publish, #delete-batch, #batch-ban, #batch-unban").addClass("disabled");
3639
}
37-
}
40+
}

app/assets/stylesheets/spam2.css

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/*
22
*= require datatables/dataTables.bootstrap4
33
*/
4+
45
.nav_top {
56
z-index: 5;
67
width: 100%;
78
}
89

910
#batch-spam:hover {
10-
color: red !important;
11+
color: red !important;
1112
cursor: pointer;
1213
}
1314

@@ -32,53 +33,61 @@
3233
}
3334

3435
#batch-unban:hover {
35-
color: green !important;
36+
color: green !important;
3637
cursor: pointer;
3738
}
3839

39-
#node-hover:hover{
40-
color:blue !important;
40+
#node-hover:hover {
41+
color: blue !important;
4142
}
4243

4344
#table-card {
4445
width: 100%;
4546
}
4647

4748
#card-top {
48-
margin-top:2vh;
49+
margin-top: 2vh;
4950
}
5051

51-
#bulk-nav{
52+
#bulk-nav {
5253
margin-top: 2%;
5354
margin-bottom: 1%;
54-
width:100%;
55+
width: 100%;
5556
}
5657

57-
.active .drop{
58-
color:white !important;
58+
.active .drop {
59+
color: white !important;
5960
}
6061

61-
#col-search{
62+
#col-search {
6263
cursor: text;
63-
text-align:left !important;
64-
margin-top:2px;
64+
text-align: left !important;
65+
margin-top: 2px;
66+
}
67+
68+
#col-select {
69+
margin-top: 2px;
6570
}
6671

67-
#col-select{
68-
margin-top:2px;
72+
.page-table {
73+
width: 100%;
74+
margin-top: 10px;
6975
}
7076

7177
@media (max-width: 750px) {
72-
#table-card, #bulk-nav, .nav_top,
78+
#table-card,
79+
#bulk-nav,
80+
.nav_top,
81+
.page-table,
7382
#card-top {
74-
margin-left: 5vw;
75-
width:90vw;
83+
margin-left: 5vw;
84+
width: 90vw;
7685
}
77-
.nav_title{
86+
.nav_title {
7887
font-size: 18px;
79-
margin-bottom : 10px;
88+
margin-bottom: 10px;
8089
}
81-
#card-top .card-header{
90+
#card-top .card-header {
8291
font-size: 18px;
8392
}
8493
}

app/controllers/spam2_controller.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ class Spam2Controller < ApplicationController
33

44
def _spam
55
if logged_in_as(%w(moderator admin))
6-
@nodes = Node.order('nid DESC')
6+
@nodes = Node.order('changed DESC')
7+
.paginate(page: params[:page], per_page: 100)
78
@nodes = if params[:type] == 'wiki'
89
@nodes.where(type: 'page', status: 1)
910
else
@@ -22,7 +23,8 @@ def _spam
2223
def _spam_revisions
2324
if logged_in_as(%w(admin moderator))
2425
@revisions = Revision.where(status: 0)
25-
.order('timestamp DESC')
26+
.paginate(page: params[:page], per_page: 100)
27+
.order('timestamp DESC')
2628
render template: 'spam2/_spam'
2729
else
2830
flash[:error] = 'Only moderators and admins can moderate this.'
@@ -32,8 +34,9 @@ def _spam_revisions
3234

3335
def _spam_comments
3436
if logged_in_as(%w(moderator admin))
35-
@comments = Comment.order('timestamp DESC')
36-
.where(status: 0)
37+
@comments = Comment.where(status: 0)
38+
.order('timestamp DESC')
39+
.paginate(page: params[:page], per_page: 100)
3740
render template: 'spam2/_spam'
3841
else
3942
flash[:error] = 'Only moderators can moderate comments.'

app/views/spam2/_comments.html.erb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@ $(document).ready(function () {
7171
</tbody>
7272
</table>
7373
</div>
74-
</div>
74+
</div>
75+
<div class="page-table">
76+
<div class="float-right">
77+
<%= will_paginate @comments, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || @comments.empty?%>
78+
</div>
79+
<div class="float-left">
80+
Batch <%= @comments.current_page%> of <%= @comments.total_pages %> total Batches
81+
</div>
82+
</div>

app/views/spam2/_nodes.html.erb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ $(document).ready(function () {
100100
<div class="bg-light navbar navbar-expand">
101101
<ul class="nav navbar-expand navbar-nav-scroll">
102102
<li class="nav-item">
103-
<a class="btn nav-link small text-dark">Selected <span id="select-count" class="badge badge-dark">0</span></a>
103+
<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>
104104
</li>
105105
<li class="nav-item">
106106
<a class="btn nav-link small"id="reset">Reset all</a>
@@ -129,6 +129,9 @@ $(document).ready(function () {
129129
</select>
130130
</li>
131131
<% end %>
132+
<li class="nav-item">
133+
<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>
134+
</li>
132135
</ul>
133136
</div>
134137
<div class="card-body" style="overflow-x:hidden;">
@@ -149,22 +152,22 @@ $(document).ready(function () {
149152
<td><input class="selectedId" value="<%= node.nid %>" type="checkbox" /></td>
150153
<td>
151154
<i class="fa fa-file text-secondary"></i>
152-
<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 />
155+
<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 />
153156
</td>
154157
<td>
155-
<a href="/profile/<%= node.author&.name %>" class="text-dark"><%= node.author&.name %> <%= node.author&.new_contributor%></a>
158+
<a href="/profile/<%= node.author&.name %>" class="text-info"><%= node.author&.name %> <%= node.author&.new_contributor%></a>
156159
</td>
157160
<td>
158-
<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>
161+
<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>
159162
</td>
160163
<td>
161164
<span class="text-dark"><%= time_ago_in_words(node.updated_at) %> ago</span>
162165
</td>
163166
<td style="height:35px !important;">
164-
<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>
165-
<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>
166-
<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>
167-
<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>
167+
<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>
168+
<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>
169+
<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>
170+
<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>
168171
<%= link_to "/notes/delete/#{node.id}", data: { confirm: "Are you sure you want to delete #{node.path}?" }, :remote => true, :class => "px-3 delete" do %>
169172
<i class="fa fa-trash text-dark"></i>
170173
<% end %>
@@ -226,4 +229,13 @@ $(document).ready(function () {
226229
</tbody>
227230
</table>
228231
</div>
229-
</div>
232+
</div>
233+
</div>
234+
<div class="page-table">
235+
<div class="float-right">
236+
<%= will_paginate @nodes, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || @nodes.empty?%>
237+
</div>
238+
<div class="float-left">
239+
Batch <%= @nodes.current_page%> of <%= @nodes.total_pages %> total Batches
240+
</div>
241+
</div>

app/views/spam2/_revisions.html.erb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,12 @@ $(document).ready(function () {
6060
</tbody>
6161
</table>
6262
</div>
63-
</div>
63+
</div>
64+
<div class="page-table">
65+
<div class="float-right">
66+
<%= will_paginate @revisions, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || @revisions.empty?%>
67+
</div>
68+
<div class="float-left">
69+
Batch <%= @revisions.current_page%> of <%= @revisions.total_pages %> total Batches
70+
</div>
71+
</div>

app/views/spam2/_spam.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
</div>
3131

3232
<div class="card text-center" id="card-top">
33-
<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>
33+
<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>
3434
<div class="card-body">
35-
<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>
35+
<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>
3636
</div>
3737
</div>
3838

@@ -50,7 +50,7 @@
5050
<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>
5151
</li>
5252
<li class="nav-item pr-4">
53-
<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>
53+
<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>
5454
</li>
5555
<li class="nav-item pr-4">
5656
<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>
@@ -62,7 +62,7 @@
6262
<div class="btn-group" role="group">
6363
<input class="btn border" id="col-search" type="search" placeholder="Filter by column" aria-label="Search">
6464
<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">
65-
<option value="">Select filter </option>
65+
<option value="">Filter by None </option>
6666
<option value="1">Filter by Title</option>
6767
<option value="2">Filter by Author</option>
6868
<option value="3">Filter by Status</option>

0 commit comments

Comments
 (0)