diff --git a/src/Jackett.Common/Content/custom.js b/src/Jackett.Common/Content/custom.js index 9ecceacc0..5bbf2a369 100644 --- a/src/Jackett.Common/Content/custom.js +++ b/src/Jackett.Common/Content/custom.js @@ -5,6 +5,7 @@ var configuredIndexers = []; var unconfiguredIndexers = []; var configuredTags = []; var availableFilters = []; +var currentFilter = null; $.fn.inView = function () { if (!this.length) return false; @@ -48,22 +49,28 @@ $(document).ready(function () { var pathPrefix = window.location.pathname.substr(0, index); api.root = pathPrefix + api.root; + const hashArgs = getHashArgs(); + if ("indexers" in hashArgs) + currentFilter = hashArgs.filter bindUIButtons(); loadJackettSettings(); }); function openSearchIfNecessary() { - const hashArgs = location.hash.substring(1).split('&').reduce((prev, item) => - Object.assign({ - [item.split('=')[0]]: (item.split('=').length < 2 ? - undefined : - decodeURIComponent(item.split('=')[1].replace(/\+/g, '%20'))) - }, prev), {}); + const hashArgs = getHashArgs(); if ("search" in hashArgs) { showSearch(hashArgs.filter, hashArgs.tracker, hashArgs.search, hashArgs.category); } } +function getHashArgs() { + return location.hash.substring(1).split('&').reduce((prev, item) => Object.assign({ + [item.split('=')[0]]: (item.split('=').length < 2 ? + undefined : + decodeURIComponent(item.split('=')[1].replace(/\+/g, '%20'))) + }, prev), {}); +} + function insertWordWrap(str) { // insert optional word wrap after punctuation to avoid overflows on long scene titles return str.replace(/([\.\-_\/\\])/g, "$1\u200B"); @@ -187,7 +194,7 @@ function reloadIndexers() { configureFilters(configuredIndexers); - displayConfiguredIndexersList(configuredIndexers); + displayFilteredIndexersList(configuredIndexers, currentFilter); $('#indexers div.dataTables_filter input').focusWithoutScrolling(); openSearchIfNecessary(); @@ -213,6 +220,33 @@ function configureFilters(indexers) { .forEach(add); } +function displayFilteredIndexersList(indexers, filter) { + var active = availableFilters.find(x => x.id == filter); + if (availableFilters.length > 0) { + var filtersTemplate = Handlebars.compile($("#jackett-filters").html()); + var filters = $(filtersTemplate({ + filters: availableFilters, + active: active ? active.id : null + })); + + $("li a", filters).on('click', function(){ + displayFilteredIndexersList(configuredIndexers, $(this).data("id")); + }); + + $('#filters').empty(); + $('#filters').append(filters); + $('#filters').fadeIn(); + } + if (active) { + indexers = indexers.filter(active.apply, active); + currentFilter = active.id; + } + else { + currentFilter = null; + } + displayConfiguredIndexersList(indexers) +} + function displayConfiguredIndexersList(indexers) { var indexersTemplate = Handlebars.compile($("#configured-indexer-table").html()); var indexersTable = $(indexersTemplate({ @@ -519,8 +553,8 @@ function prepareSearchButtons(element) { var $btn = $(btn); var id = $btn.data("id"); $btn.click(function () { - window.location.hash = "search&tracker=" + id; - showSearch(null, id); + window.location.hash = "search&tracker=" + id + (currentFilter ? "&filter=" + currentFilter : ""); + showSearch(currentFilter, id); }); }); } @@ -887,7 +921,7 @@ function showSearch(selectedFilter, selectedIndexer, query, category) { releaseDialog.on('hidden.bs.modal', function (e) { $('#indexers div.dataTables_filter input').focusWithoutScrolling(); - window.location.hash = ''; + window.location.hash = currentFilter ? "indexers&filter=" + currentFilter : ''; }); var setTrackers = function (filterId, trackers) { @@ -1344,8 +1378,8 @@ function bindUIButtons() { }); $("#jackett-show-search").click(function () { - showSearch(); - window.location.hash = "search"; + showSearch(currentFilter); + window.location.hash = "search" + (currentFilter ? "&filter=" + currentFilter : ""); }); $("#view-jackett-logs").click(function () { diff --git a/src/Jackett.Common/Content/index.html b/src/Jackett.Common/Content/index.html index 3d8b69780..10bdc6caa 100644 --- a/src/Jackett.Common/Content/index.html +++ b/src/Jackett.Common/Content/index.html @@ -54,6 +54,8 @@