diff --git a/lib/LANraragi/Controller/Batch.pm b/lib/LANraragi/Controller/Batch.pm index f9cf55626..0ca42a912 100644 --- a/lib/LANraragi/Controller/Batch.pm +++ b/lib/LANraragi/Controller/Batch.pm @@ -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 ); } @@ -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..."); diff --git a/lib/LANraragi/Controller/Index.pm b/lib/LANraragi/Controller/Index.pm index b81a5dded..8d4999010 100644 --- a/lib/LANraragi/Controller/Index.pm +++ b/lib/LANraragi/Controller/Index.pm @@ -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", diff --git a/lib/LANraragi/Controller/Reader.pm b/lib/LANraragi/Controller/Reader.pm index f96516f7e..28bb84550 100644 --- a/lib/LANraragi/Controller/Reader.pm +++ b/lib/LANraragi/Controller/Reader.pm @@ -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; diff --git a/lib/LANraragi/Controller/Upload.pm b/lib/LANraragi/Controller/Upload.pm index c473a65cb..1c86414ea 100644 --- a/lib/LANraragi/Controller/Upload.pm +++ b/lib/LANraragi/Controller/Upload.pm @@ -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", diff --git a/lib/LANraragi/Model/Category.pm b/lib/LANraragi/Model/Category.pm index 71c8f1766..0e4b6d563 100644 --- a/lib/LANraragi/Model/Category.pm +++ b/lib/LANraragi/Model/Category.pm @@ -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 { @@ -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 ); @@ -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 ); } diff --git a/lib/LANraragi/Plugin/Scripts/FolderToCat.pm b/lib/LANraragi/Plugin/Scripts/FolderToCat.pm index b4c45faa5..86f966006 100644 --- a/lib/LANraragi/Plugin/Scripts/FolderToCat.pm +++ b/lib/LANraragi/Plugin/Scripts/FolderToCat.pm @@ -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); } } diff --git a/public/js/batch.js b/public/js/batch.js index 6fc898981..29af42fe4 100644 --- a/public/js/batch.js +++ b/public/js/batch.js @@ -157,6 +157,7 @@ Batch.startBatch = function () { const commandBase = { operation: Batch.currentOperation, plugin: Batch.currentPlugin, + category: $("#category").val(), args, }; @@ -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 diff --git a/templates/batch.html.tt2 b/templates/batch.html.tt2 index 2b053b4c8..3d4bc6cb4 100644 --- a/templates/batch.html.tt2 +++ b/templates/batch.html.tt2 @@ -19,7 +19,7 @@ - + @@ -54,6 +54,7 @@ + @@ -123,6 +124,17 @@ + + Add to Category : + + + + +