From 24584503d9d554a12b2ebb21c9ba254b4935e254 Mon Sep 17 00:00:00 2001 From: buinsky Date: Thu, 21 Jan 2016 18:58:08 +0300 Subject: [PATCH] WebUI: Implement removing unused categories --- src/webui/webapplication.cpp | 11 ++++++----- src/webui/webapplication.h | 2 +- src/webui/www/private/index.html | 1 + src/webui/www/public/filters.html | 3 +++ src/webui/www/public/scripts/client.js | 2 +- src/webui/www/public/scripts/dynamicTable.js | 13 ++++++------- src/webui/www/public/scripts/mocha-init.js | 20 ++++++++++++++++++-- 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 3924cd973..95f895bf8 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -116,7 +116,7 @@ QMap > WebApplication::initialize ADD_ACTION(command, recheck); ADD_ACTION(command, setCategory); ADD_ACTION(command, addCategory); - ADD_ACTION(command, removeCategory); + ADD_ACTION(command, removeCategories); ADD_ACTION(command, getSavePath); ADD_ACTION(version, api); ADD_ACTION(version, api_min); @@ -745,13 +745,14 @@ void WebApplication::action_command_addCategory() BitTorrent::Session::instance()->addCategory(category); } -void WebApplication::action_command_removeCategory() +void WebApplication::action_command_removeCategories() { CHECK_URI(0); - CHECK_PARAMETERS("category"); + CHECK_PARAMETERS("categories"); - QString category = request().posts["category"].trimmed(); - BitTorrent::Session::instance()->removeCategory(category); + QStringList categories = request().posts["categories"].split('\n'); + foreach (const QString &category, categories) + BitTorrent::Session::instance()->removeCategory(category); } void WebApplication::action_command_getSavePath() diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 248695de8..722f7d5e4 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -89,7 +89,7 @@ private: void action_command_recheck(); void action_command_setCategory(); void action_command_addCategory(); - void action_command_removeCategory(); + void action_command_removeCategories(); void action_command_getSavePath(); void action_version_api(); void action_version_api_min(); diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 999b1fab9..db49432ad 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -128,6 +128,7 @@
diff --git a/src/webui/www/public/filters.html b/src/webui/www/public/filters.html index 295173332..d35489c19 100644 --- a/src/webui/www/public/filters.html +++ b/src/webui/www/public/filters.html @@ -25,6 +25,9 @@ }, DeleteCategory : function (element, ref) { removeCategoryFN(element.id); + }, + DeleteUnusedCategories : function (element, ref) { + deleteUnusedCategoriesFN(); } }, offsets : { diff --git a/src/webui/www/public/scripts/client.js b/src/webui/www/public/scripts/client.js index 32dce770f..589614984 100644 --- a/src/webui/www/public/scripts/client.js +++ b/src/webui/www/public/scripts/client.js @@ -203,7 +203,7 @@ window.addEvent('load', function () { }; var updateFilter = function(filter, filterTitle) { - $(filter + '_filter').firstChild.childNodes[1].nodeValue = filterTitle.replace('%1', torrentsTable.getFilteredTorrentsNumber(filter)); + $(filter + '_filter').firstChild.childNodes[1].nodeValue = filterTitle.replace('%1', torrentsTable.getFilteredTorrentsNumber(filter, CATEGORIES_ALL)); }; var updateFiltersList = function() { diff --git a/src/webui/www/public/scripts/dynamicTable.js b/src/webui/www/public/scripts/dynamicTable.js index 574f0212a..d669e1d3e 100644 --- a/src/webui/www/public/scripts/dynamicTable.js +++ b/src/webui/www/public/scripts/dynamicTable.js @@ -620,7 +620,7 @@ var TorrentsTable = new Class({ }; }, - applyFilter : function (row, filterName, categoryName) { + applyFilter : function (row, filterName, categoryHash) { var state = row['full_data'].state; var inactive = false; var r; @@ -662,25 +662,24 @@ var TorrentsTable = new Class({ break; } - if (categoryName == CATEGORIES_ALL) + if (categoryHash == CATEGORIES_ALL) return true; - if (categoryName == CATEGORIES_UNCATEGORIZED && row['full_data'].category.length === 0) + if (categoryHash == CATEGORIES_UNCATEGORIZED && row['full_data'].category.length === 0) return true; - if (categoryName != genHash(row['full_data'].category)) + if (categoryHash != genHash(row['full_data'].category)) return false; return true; }, - getFilteredTorrentsNumber : function (filterName) { + getFilteredTorrentsNumber : function (filterName, categoryHash) { var cnt = 0; var rows = this.rows.getValues(); for (i = 0; i < rows.length; i++) - if (this.applyFilter(rows[i], filterName, CATEGORIES_ALL)) cnt++; - + if (this.applyFilter(rows[i], filterName, categoryHash)) cnt++; return cnt; }, diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index 338e81ca7..2daba0795 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -360,10 +360,26 @@ initializeWindows = function() { removeCategoryFN = function (categoryHash) { var categoryName = category_list[categoryHash].name; new Request({ - url: 'command/removeCategory', + url: 'command/removeCategories', method: 'post', data: { - category: categoryName + categories: categoryName + } + }).send(); + setCategoryFilter(CATEGORIES_ALL); + }; + + deleteUnusedCategoriesFN = function () { + var categories = []; + for (var hash in category_list) { + if (torrentsTable.getFilteredTorrentsNumber('all', hash) == 0) + categories.push(category_list[hash].name); + } + new Request({ + url: 'command/removeCategories', + method: 'post', + data: { + categories: categories.join('\n') } }).send(); setCategoryFilter(CATEGORIES_ALL);