Skip to content

Commit

Permalink
(#672) Add category operation to batch tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Oct 13, 2022
1 parent 136cc06 commit ce9a1d9
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 27 deletions.
34 changes: 27 additions & 7 deletions lib/LANraragi/Controller/Batch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ sub index {
#Build plugin listing
my @pluginlist = get_plugins("metadata");

# Get static category list
my @categories = LANraragi::Model::Category->get_static_category_list;

$self->render(
template => "batch",
plugins => \@pluginlist,
title => $self->LRR_CONF->get_htmltitle,
descstr => $self->LRR_DESC,
csshead => generate_themes_header($self),
tagrules => restore_CRLF( $self->LRR_CONF->get_tagrules ),
version => $self->LRR_VERSION
template => "batch",
plugins => \@pluginlist,
title => $self->LRR_CONF->get_htmltitle,
descstr => $self->LRR_DESC,
csshead => generate_themes_header($self),
tagrules => restore_CRLF( $self->LRR_CONF->get_tagrules ),
categories => \@categories,
version => $self->LRR_VERSION
);
}

Expand Down Expand Up @@ -96,6 +100,22 @@ sub socket {
return;
}

if ( $operation eq "addcat" ) {
my $catid = $command->{"category"};
my ( $catsucc, $caterr ) = LANraragi::Model::Category::add_to_category( $catid, $id );

$client->send(
{ json => {
id => $id,
category => $catid,
success => $catsucc,
message => $caterr
}
}
);
return;
}

if ( $operation eq "tagrules" ) {

$logger->debug("Applying tag rules to $id...");
Expand Down
3 changes: 1 addition & 2 deletions lib/LANraragi/Controller/Index.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ sub index {
my $userlogged = $self->LRR_CONF->enable_pass == 0 || $self->session('is_logged');

# Get static category list to populate the right-click menu
my @categories = LANraragi::Model::Category->get_category_list;
@categories = grep { %$_{"search"} eq "" } @categories;
my @categories = LANraragi::Model::Category->get_static_category_list;

$self->render(
template => "index",
Expand Down
7 changes: 2 additions & 5 deletions lib/LANraragi/Controller/Reader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ sub index {

if ( $self->req->param('id') ) {

# Allow adding to category
my @categories = LANraragi::Model::Category->get_category_list;

# But only to static categories
@categories = grep { %$_{"search"} eq "" } @categories;
# Allow adding to static categories
my @categories = LANraragi::Model::Category->get_static_category_list;

# Get query string from referrer URL, if there's one
my $referrer = $self->req->headers->referrer;
Expand Down
5 changes: 1 addition & 4 deletions lib/LANraragi/Controller/Upload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ sub index {
my $self = shift;

# Allow adding to category on direct uploads
my @categories = LANraragi::Model::Category->get_category_list;

# But only to static categories
@categories = grep { %$_{"search"} eq "" } @categories;
my @categories = LANraragi::Model::Category->get_static_category_list;

$self->render(
template => "upload",
Expand Down
16 changes: 14 additions & 2 deletions lib/LANraragi/Model/Category.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ sub get_category_list {
return @result;
}

# get_static_category_list()
# Returns a list of all the static category objects.
sub get_static_category_list() {

my @categories = get_category_list;

# Filter out dynamic categories
@categories = grep { %$_{"search"} eq "" } @categories;
return @categories;
}

# get_categories_containing_archive(id)
# Returns a list of all the categories that contain the given archive.
sub get_categories_containing_archive {
Expand Down Expand Up @@ -178,7 +189,7 @@ sub add_to_category {
if ( $redis->exists($cat_id) ) {

unless ( $redis->hget( $cat_id, "search" ) eq "" ) {
$err = "$cat_id is a favorite search, can't add archives to it.";
$err = "$cat_id is a favorite search/dynamic category, can't add archives to it.";
$logger->error($err);
$redis->quit;
return ( 0, $err );
Expand All @@ -203,7 +214,8 @@ sub add_to_category {
}

if ( "@cat_archives" =~ m/$arc_id/ ) {
$logger->warn("$arc_id already present in category $cat_id, doing nothing.");
$err = "$arc_id already present in category $cat_id, doing nothing.";
$logger->warn($err);
$redis->quit;
return ( 1, $err );
}
Expand Down
10 changes: 4 additions & 6 deletions lib/LANraragi/Plugin/Scripts/FolderToCat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ sub run_script {
if ($delete_old_cats) {
$logger->info("Deleting all Static Categories before folder walking as instructed.");

my @categories = LANraragi::Model::Category->get_category_list;
my @categories = LANraragi::Model::Category->get_static_category_list;
for my $category (@categories) {
if ( %{$category}{"search"} eq "" ) {
my $cat_id = %{$category}{"id"};
$logger->debug("Deleting '$cat_id'");
LANraragi::Model::Category::delete_category($cat_id);
}
my $cat_id = %{$category}{"id"};
$logger->debug("Deleting '$cat_id'");
LANraragi::Model::Category::delete_category($cat_id);
}
}

Expand Down
6 changes: 6 additions & 0 deletions public/js/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Batch.startBatch = function () {
const commandBase = {
operation: Batch.currentOperation,
plugin: Batch.currentPlugin,
category: $("#category").val(),
args,
};

Expand Down Expand Up @@ -223,6 +224,11 @@ Batch.updateBatchStatus = function (event) {
case "tagrules":
$("#log-container").append(`Replaced tags for ID ${msg.id} (New tags: ${msg.tags})\n\n`);
break;
case "addcat":
// Append the message at the end of this log,
// as it can contain the warning about the ID already being in the category
$("#log-container").append(`Added ID ${msg.id} to category ${msg.category}! ${msg.message} \n\n`);
break;
case "clearnew": {
$("#log-container").append(`Cleared new flag for ID ${msg.id}\n\n`);
// Remove last character from matching row
Expand Down
14 changes: 13 additions & 1 deletion templates/batch.html.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<script src="/js/vendor/preact.umd.js" type="text/JAVASCRIPT"></script>
<script src="/js/vendor/hooks.umd.js" type="text/JAVASCRIPT"></script>
<script src="/js/vendor/compat.umd.js" type="text/JAVASCRIPT"></script>
<script>window.React=window.preactCompat;window.react=window.preactCompat;</script>
<script>window.React = window.preactCompat; window.react = window.preactCompat;</script>
<script src="/js/vendor/clsx.min.js" type="text/JAVASCRIPT"></script>
<script src="/js/vendor/react-toastify.umd.js" type="text/JAVASCRIPT"></script>
<script src="/js/vendor/sweetalert2.min.js" type="text/JAVASCRIPT"></script>
Expand Down Expand Up @@ -54,6 +54,7 @@
<option value="plugin">🧩 Use Plugin</option>
<option value="clearnew">🆕 Remove New Flag</option>
<option value="tagrules">📏 Apply Tag Rules</option>
<option value="addcat">📚 Add To Category</option>
<option value="delete">🗑️ Delete Archive</option>
</select>
</td>
Expand Down Expand Up @@ -123,6 +124,17 @@
</td>
</tr>

<tr class="operation addcat-operation">
<td>Add to Category :</td>
<td>
<select id="category" class="favtag-btn">
[% FOREACH categories %]
<option value="[% id %]">[% name %]</option>
[% END %]
</select>
</td>
</tr>

<tr class="operation delete-operation">
<td></td>
<td style="font-size:36px; text-align: center;">
Expand Down

0 comments on commit ce9a1d9

Please sign in to comment.