From c17294052d58d78e4ebb4ce56982d759743fa38b Mon Sep 17 00:00:00 2001 From: kaso17 Date: Fri, 3 Feb 2017 19:11:46 +0100 Subject: [PATCH] Add dead torrents filter --- src/Jackett/Content/custom.css | 6 +++++ src/Jackett/Content/custom.js | 47 ++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/Jackett/Content/custom.css b/src/Jackett/Content/custom.css index 876afc8b9..715fa739e 100644 --- a/src/Jackett/Content/custom.css +++ b/src/Jackett/Content/custom.css @@ -259,4 +259,10 @@ table td.fit{ .type-semi-private { color: #ec971f +} + +.dataTables_deadfilter { + float: right; + text-align: right; + margin-right: 1em; } \ No newline at end of file diff --git a/src/Jackett/Content/custom.js b/src/Jackett/Content/custom.js index 4ff66e2e7..efd952bba 100644 --- a/src/Jackett/Content/custom.js +++ b/src/Jackett/Content/custom.js @@ -714,17 +714,44 @@ function showSearch(selectedIndexer) { releaseDialog.modal("show"); } +// dataTable dead torrent filter +$.fn.dataTable.ext.search = [ + function (settings, data, dataIndex) { + if (settings.sInstance != "jackett-search-results-datatable") + return true; + var deadfiltercheckbox = $(settings.nTableWrapper).find(".dataTables_deadfilter input") + if (!deadfiltercheckbox.length) { + return true; + } + var seeders = data[9]; + if (!deadfiltercheckbox.get(0).checked && seeders == 0) + return false; + return true; + } +] + function updateSearchResultTable(element, results) { var resultsTemplate = Handlebars.compile($("#jackett-search-results").html()); element.html($(resultsTemplate(results))); element.find('tr.jackett-search-results-row').each(function () { updateReleasesRow(this); }); - + var settings = { "deadfilter": true }; var datatable = element.find('table').DataTable( { + "fnStateSaveParams": function (oSettings, sValue) { + console.log(oSettings); + sValue.deadfilter = settings.deadfilter; + return sValue; + }, + "fnStateLoadParams": function (oSettings, sValue) { + if ("deadfilter" in sValue) + settings.deadfilter = sValue.deadfilter; + }, + + "dom": "lfr<\"dataTables_deadfilter\">tip", "stateSave": true, "bAutoWidth": false, "pageLength": 20, - "lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]], + "lengthMenu": [[10, 20, 50, 100, 250, 500, -1], [10, 20, 50, 100, 250, 500, "All"]], "order": [[0, "desc"]], "columnDefs": [ { @@ -752,6 +779,22 @@ function updateSearchResultTable(element, results) { "iDataSort": 4 } ], + fnPreDrawCallback: function () { + var table = this; + var deadfilterdiv = element.find(".dataTables_deadfilter"); + var deadfiltercheckbox = deadfilterdiv.find("input"); + if (!deadfiltercheckbox.length) { + deadfilterlabel = $('' + ); + deadfilterdiv.append(deadfilterlabel); + deadfiltercheckbox = deadfilterlabel.find("input") + deadfiltercheckbox.on("change", function () { + settings.deadfilter = this.checked; + table.api().draw(); + }); + deadfiltercheckbox.prop('checked', settings.deadfilter); + } + }, initComplete: function () { var count = 0; this.api().columns().every(function () {