Skip to content

Commit

Permalink
Cleanup new/untagged support in datatables, adding them as special dy…
Browse files Browse the repository at this point in the history
…namic categories
  • Loading branch information
Difegue committed Jan 12, 2025
1 parent e0df929 commit 3c13881
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
19 changes: 11 additions & 8 deletions lib/LANraragi/Controller/Api/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ sub handle_datatables {
# Collection (tags column)
if ( $req->param("columns[$i][name]") eq "tags" ) {
$categoryfilter = $req->param("columns[$i][search][value]");
}

# New filter (isnew column)
if ( $req->param("columns[$i][name]") eq "isnew" ) {
$newfilter = $req->param("columns[$i][search][value]") eq "true";
}
# Specific hacks for the buily-in newonly/untagged selectors
# Those have hardcoded 'category' IDs
if ( $categoryfilter eq "NEW_ONLY" ) {
$newfilter = 1;
$categoryfilter = "";
}

if ( $categoryfilter eq "UNTAGGED_ONLY" ) {
$untaggedfilter = 1;
$categoryfilter = "";
}

# Untagged filter (untagged column)
if ( $req->param("columns[$i][name]") eq "untagged" ) {
$untaggedfilter = $req->param("columns[$i][search][value]") eq "true";
}
$i++;
}
Expand Down
11 changes: 10 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,16 @@ Index.loadCategories = function () {
// Pinned categories are shown at the beginning
data.sort((b, a) => b.name.localeCompare(a.name));
data.sort((a, b) => b.pinned - a.pinned);
let html = "";
// Queue some hardcoded categories at the beginning - those are special-cased in the DataTables variant of the search endpoint.
let html = `<div style='display:inline-block'>
<input class='favtag-btn ${(("NEW_ONLY" === Index.selectedCategory) ? "toggled" : "")}'
type='button' id='NEW_ONLY' value='🆕 New only'
onclick='Index.toggleCategory(this)' title='Click here to display new archives only.'/>
</div><div style='display:inline-block'>
<input class='favtag-btn ${(("UNTAGGED_ONLY" === Index.selectedCategory) ? "toggled" : "")}'
type='button' id='UNTAGGED_ONLY' value='🏷️ Untagged only'
onclick='Index.toggleCategory(this)' title='Click here to display untagged archives only.'/>
</div>`;

const iteration = (data.length > 10 ? 10 : data.length);

Expand Down

0 comments on commit 3c13881

Please sign in to comment.