[Bps-public-commit] rt-extension-spamfilter branch add-checkbox-selection created. 913d89e8c5285a35220a4f91f09ad02e7e8dde2e
BPS Git Server
git at git.bestpractical.com
Mon Jul 10 12:20:43 UTC 2023
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt-extension-spamfilter".
The branch, add-checkbox-selection has been created
at 913d89e8c5285a35220a4f91f09ad02e7e8dde2e (commit)
- Log -----------------------------------------------------------------
commit 913d89e8c5285a35220a4f91f09ad02e7e8dde2e
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 18:02:34 2023 -0300
Add Rows Per Page selection to the Spam Filter List page
diff --git a/html/Tools/SpamFilter/List.html b/html/Tools/SpamFilter/List.html
index db25444..be921a4 100644
--- a/html/Tools/SpamFilter/List.html
+++ b/html/Tools/SpamFilter/List.html
@@ -124,13 +124,26 @@
lastDeleteSelected = this;
}
});
+ // Submit form on Rows change
+ jQuery('select[name="Rows"]').change( function () {
+ jQuery('#SpamUpdate').submit();
+ });
});
</script>
+<form method="post" enctype="multipart/form-data" name="SpamUpdate" id="SpamUpdate">
<& /Elements/ListActions, actions => \@results &>
+<div class="col-12 form-row justify-content-center">
+ <div class="label col-auto">
+ <&|/l&>Rows per page</&>:
+ </div>
+ <div class="value col-2">
+ <& /Elements/SelectResultsPerPage, Name => "Rows", Default => $Rows &>
+ </div>
+</div>
+<hr/>
<div class="spams">
-<form method="post" enctype="multipart/form-data" name="SpamUpdate" id="SpamUpdate">
<& /Elements/CollectionList,
Collection => $emails,
AllowSorting => 1,
@@ -139,7 +152,7 @@
Rows => $Rows,
Page => $Page,
Format => $Format,
- PassArguments => ['Status'],
+ PassArguments => ['Status','Rows','OrderBy','Order'],
Status => $Status,
&>
</div>
@@ -185,7 +198,8 @@ if (!$Status || $Status eq 'new') {
$Order ||= 'ASC';
$OrderBy ||= 'id';
-$Rows ||= 50;
+# Normalize Rows variable if we got 2 or more values
+$Rows = $Rows->[0] if ref $Rows eq 'ARRAY';
$Page = 1 unless $Page && $Page > 0;
use RT::Spams;
@@ -231,8 +245,6 @@ if ($Release) {
my $emails = RT::Spams->new($session{'CurrentUser'}) ;
$emails->Limit(FIELD => 'Status', VALUE => $Status );
$emails->OrderBy( FIELD => $OrderBy, ORDER => $Order );
-$emails->RowsPerPage( $Rows );
-$emails->GotoPage( $Page - 1 );
my $title;
if ( $Status eq 'new' ) {
@@ -247,7 +259,7 @@ else {
</%init>
<%ARGS>
$Format => undef
-$Rows => undef
+$Rows => 50
$Page => 1
$OrderBy => undef
$Order => undef
commit b2f64c912de1822cde5d828a4f3552915d82862f
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 16:49:44 2023 -0300
Implement multiple selection of checkboxes holding shift key
Improve the selection of large number of Tickets/Messages by holding
shift key and clicking on the checkbox.
diff --git a/html/Tools/SpamFilter/List.html b/html/Tools/SpamFilter/List.html
index 8f4aff8..db25444 100644
--- a/html/Tools/SpamFilter/List.html
+++ b/html/Tools/SpamFilter/List.html
@@ -48,6 +48,12 @@
<& /Elements/Header, Title => $title &>
<& /Elements/Tabs &>
+<style type="text/css">
+ /* allow multiple checkboxes to be checked holding shift key*/
+ .checkbox {
+ z-index: 1;
+ }
+</style>
<script type="text/javascript">
jQuery( function() {
jQuery('#not_spam_all').change( function () {
@@ -85,6 +91,39 @@
}
}
});
+ // Enable shift selection of checkboxes
+ lastReleaseSelected = null;
+ lastDeleteSelected = null;
+ ReleaseCheckboxes = jQuery('input.not_spam');
+ DeleteCheckboxes = jQuery('input.discard');
+ jQuery('input.not_spam,input.discard').click( function (e) {
+ console.log("logie");
+ // get id and split it
+ var id = this.id.split('-');
+ if (id[0] == 'Release') {
+ if (!lastReleaseSelected) {
+ lastReleaseSelected = this;
+ return;
+ }
+ if (e.shiftKey) {
+ var start = ReleaseCheckboxes.index(this);
+ var end = ReleaseCheckboxes.index(lastReleaseSelected);
+ ReleaseCheckboxes.slice(Math.min(start,end), Math.max(start,end)+ 1).prop('checked', lastReleaseSelected.checked).change();
+ }
+ lastReleaseSelected = this;
+ } else {
+ if (!lastDeleteSelected) {
+ lastDeleteSelected = this;
+ return;
+ }
+ if (e.shiftKey) {
+ var start = DeleteCheckboxes.index(this);
+ var end = DeleteCheckboxes.index(lastDeleteSelected);
+ DeleteCheckboxes.slice(Math.min(start,end), Math.max(start,end)+ 1).prop('checked', lastDeleteSelected.checked).change();
+ }
+ lastDeleteSelected = this;
+ }
+ });
});
</script>
commit 5c16c51b0b272dd560a1ec80baf167b43b02ea3e
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 16:26:05 2023 -0300
Implement checkbox selection for spam filter actions
It's now possible to select multiple spam filter actions and perform
bulk actions on them.
diff --git a/html/Elements/RT__Spam/ColumnMap b/html/Elements/RT__Spam/ColumnMap
index 339867d..1541667 100644
--- a/html/Elements/RT__Spam/ColumnMap
+++ b/html/Elements/RT__Spam/ColumnMap
@@ -53,25 +53,6 @@ $Attr => undef
<%once>
-# For readability, ncapsulate the button-generating code into a
-# function here rather than putting it inline in the big hash.
-my $buttons_sub = sub {
- my ($email) = @_;
-
- my $ret = '';
- if ($email->Status ne 'resolved') {
- $ret .= '<button type="button" class="create_user" name="Release-' . $email->id . '">' . loc('Not Spam') . '</button>';
- }
- if ($email->Status ne 'deleted') {
- $ret .= ' <button type="button" class="discard" name="Delete-' . $email->id . '">' . loc('Delete') . '</button>';
- }
-
- # Here's a magical thing... if you return a *reference* to a scalar,
- # the result is not HTML-escaped. If you just return a scalar, it is.
- # Hence the \ before $ret.
- return \$ret;
-};
-
my $COLUMN_MAP;
$COLUMN_MAP = {
@@ -111,9 +92,49 @@ $COLUMN_MAP = {
title => 'Score', # loc
value => sub { return $_[0]->Score }
},
- Disposition => {
- title => 'Disposition', #loc
- value => $buttons_sub,
+ NotSpam => {
+ # Here's a magical thing... if you return a *reference* to a scalar,
+ # the result is not HTML-escaped. If you just return a scalar, it is.
+ # Hence the \ before $ret.
+ title => sub {
+ return \qq{
+<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="not_spam_all" id="not_spam_all" value="1" class="checkbox custom-control-input" />
+ <label class="custom-control-label" for="not_spam_all">Not Spam</label>
+</div>
+};
+ },
+ value => sub {
+ if ( $_[0]->Status ne 'resolved' ) {
+ return \(
+'<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="Release" id="Release-'.$_[0]->id.'" value="'.$_[0]->id.'" class="not_spam checkbox custom-control-input" />
+ <label class="custom-control-label" for="Release-'.$_[0]->id.'"></label>
+</div>');
+ }
+ },
+ },
+ Delete => {
+ # Here's a magical thing... if you return a *reference* to a scalar,
+ # the result is not HTML-escaped. If you just return a scalar, it is.
+ # Hence the \ before $ret.
+ title => sub {
+ return \qq{
+<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="discard_all" id="discard_all" value="1" class="checkbox custom-control-input" />
+ <label class="custom-control-label" for="discard_all">Delete</label>
+</div>
+};
+ },
+ value => sub {
+ if ( $_[0]->Status ne 'deleted' ) {
+ return \(
+'<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="Delete" id="Delete-'.$_[0]->id.'" value="'.$_[0]->id.'" class="discard checkbox custom-control-input" />
+ <label class="custom-control-label" for="Delete-'.$_[0]->id.'"></label>
+</div>');
+ }
+ },
},
};
diff --git a/html/Tools/SpamFilter/List.html b/html/Tools/SpamFilter/List.html
index cd02b90..8f4aff8 100644
--- a/html/Tools/SpamFilter/List.html
+++ b/html/Tools/SpamFilter/List.html
@@ -50,17 +50,40 @@
<script type="text/javascript">
jQuery( function() {
- jQuery('button.create_user').click( function () {
- url = new URL(window.location.href);
- status = url.searchParams.get('Status') || 'new';
- bits = this.name.split('-');
- window.location.href = '?emailid=' + bits[1] + '&Action=' + bits[0] + '&Status=' + status;
+ jQuery('#not_spam_all').change( function () {
+ // toggle all checkboxes
+ jQuery('input.not_spam').prop('checked', this.checked).change();
+ jQuery('#discard_all').prop('checked', false);
});
- jQuery('button.discard').click( function () {
- url = new URL(window.location.href);
- status = url.searchParams.get('Status') || 'new';
- bits = this.name.split('-');
- window.location.href = '?emailid=' + bits[1] + '&Action=' + bits[0] + '&Status=' + status;
+ jQuery('#discard_all').change( function () {
+ // toggle all checkboxes
+ jQuery('input.discard').prop('checked', this.checked).change();
+ jQuery('#not_spam_all').prop('checked', false);
+ });
+ // check if the corresponding Release-X or Delete-X is already checked
+ // and uncheck it
+ jQuery('input.not_spam,input.discard').change( function () {
+ // get id and split it
+ var id = this.id.split('-');
+
+ if (!this.checked) {
+ // disable the oposite checkbox
+ if (id[0] == 'Release') {
+ jQuery('#not_spam_all').prop('checked', false);
+ } else {
+ jQuery('#discard_all').prop('checked', false);
+ }
+ return;
+ } else {
+ // disable the oposite checkbox
+ if (id[0] == 'Release') {
+ jQuery('#Delete-' + id[1]).prop('checked', false);
+ jQuery('#discard_all').prop('checked', false);
+ } else {
+ jQuery('#Release-' + id[1]).prop('checked', false);
+ jQuery('#not_spam_all').prop('checked', false);
+ }
+ }
});
});
</script>
@@ -68,6 +91,7 @@
<& /Elements/ListActions, actions => \@results &>
<div class="spams">
+<form method="post" enctype="multipart/form-data" name="SpamUpdate" id="SpamUpdate">
<& /Elements/CollectionList,
Collection => $emails,
AllowSorting => 1,
@@ -81,10 +105,43 @@
&>
</div>
+<hr />
+
+<div class="form-row">
+ <div class="col-12">
+ <& /Elements/Submit, Label => loc('Update') &>
+ </div>
+</div>
+
+</form>
+
<%init>
my @results;
-$Format ||= qq{'<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__id__</a>/TITLE:#','<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__Subject__</a>',__From__,__To__,__Status__,__Date__,__Score__,__Disposition__};
+$Format ||= qq{
+ '<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__id__</a>/TITLE:#',
+ '<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__Subject__</a>',
+ __From__,
+ __To__,
+ __Status__,
+ __Date__,
+ __Score__
+};
+
+if (!$Status || $Status eq 'new') {
+ $Format .= qq{
+ __NotSpam__,
+ __Delete__
+ };
+} elsif ($Status eq 'resolved') {
+ $Format .= qq{
+ __Delete__
+ };
+} elsif ($Status eq 'deleted') {
+ $Format .= qq{
+ __NotSpam__
+ };
+}
$Order ||= 'ASC';
$OrderBy ||= 'id';
@@ -95,18 +152,36 @@ $Page = 1 unless $Page && $Page > 0;
use RT::Spams;
use RT::Spam;
-if ($Action && $emailid) {
- my $email = RT::Spam->new($session{'CurrentUser'}) ;
- $email->Load($emailid);
- if ($email->id) {
- my ($ret, $msg, $ticket);
- if ($Action eq 'Delete') {
- ($ret, $msg) = $email->Delete();
+if ($Delete) {
+ my @ToBeDeleted;
+ if (ref $Delete eq 'ARRAY') {
+ @ToBeDeleted = @$Delete;
+ } else {
+ push @ToBeDeleted, $Delete;
+ };
+ foreach my $id (@ToBeDeleted) {
+ my $email = RT::Spam->new($session{'CurrentUser'}) ;
+ $email->Load($id);
+ if ($email->id) {
+ my ($ret, $msg) = $email->Delete();
if ($ret) {
push(@results, loc('Marked item [_1] as spam', $email->id));
}
- } elsif ($Action eq 'Release') {
- ($ret, $msg, $ticket) = $email->Release(\%session);
+ }
+ }
+}
+if ($Release) {
+ my @ToBeReleased;
+ if (ref $Release eq 'ARRAY') {
+ @ToBeReleased = @$Release;
+ } else {
+ push @ToBeReleased, $Release;
+ };
+ foreach my $id (@ToBeReleased) {
+ my $email = RT::Spam->new($session{'CurrentUser'}) ;
+ $email->Load($id);
+ if ($email->id) {
+ my ($ret, $msg, $ticket) = $email->Release(\%session);
if ($ret) {
push(@results, loc('Marked item [_1] as non-spam and created ticket #[_2]', $email->id, $ticket->Id));
}
@@ -138,6 +213,6 @@ $Page => 1
$OrderBy => undef
$Order => undef
$Status => 'new'
-$Action => undef,
-$emailid => undef
+$Delete => undef
+$Release => undef
</%ARGS>
commit e7a4079a5471dd8edb674060179b178f380742aa
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 16:23:17 2023 -0300
Fix keeping the same Status after update
SpamFilter List was loosing Status filter and going back to the home page
after update.
diff --git a/html/Tools/SpamFilter/List.html b/html/Tools/SpamFilter/List.html
index 79db9eb..cd02b90 100644
--- a/html/Tools/SpamFilter/List.html
+++ b/html/Tools/SpamFilter/List.html
@@ -76,6 +76,8 @@
Rows => $Rows,
Page => $Page,
Format => $Format,
+ PassArguments => ['Status'],
+ Status => $Status,
&>
</div>
commit 58bb58fd600fb52594ea829c36c261aa9580cec8
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 16:09:39 2023 -0300
Update POD with correct version of RT where patch was cored
The required patch was added to RT 5.0.5 and not on 5.0.2.
diff --git a/lib/RT/Extension/SpamFilter.pm b/lib/RT/Extension/SpamFilter.pm
index 4cef706..6be72b5 100644
--- a/lib/RT/Extension/SpamFilter.pm
+++ b/lib/RT/Extension/SpamFilter.pm
@@ -72,7 +72,7 @@ in your database.
If you are upgrading this module, check for upgrading instructions
in case changes need to be made to your database.
-=item Patch RT earlier than 5.0.2
+=item Patch RT earlier than 5.0.5
patch -d /opt/rt5 -p1 < patches/0001-Pass-action-info-to-GetCurrentUser-for-email-interfa.patch
-----------------------------------------------------------------------
hooks/post-receive
--
rt-extension-spamfilter
More information about the Bps-public-commit
mailing list