WebUI: Implement removing unused categories

This commit is contained in:
buinsky 2016-01-21 18:58:08 +03:00
parent 50f2437ac3
commit 24584503d9
7 changed files with 36 additions and 16 deletions

View file

@ -116,7 +116,7 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, recheck); ADD_ACTION(command, recheck);
ADD_ACTION(command, setCategory); ADD_ACTION(command, setCategory);
ADD_ACTION(command, addCategory); ADD_ACTION(command, addCategory);
ADD_ACTION(command, removeCategory); ADD_ACTION(command, removeCategories);
ADD_ACTION(command, getSavePath); ADD_ACTION(command, getSavePath);
ADD_ACTION(version, api); ADD_ACTION(version, api);
ADD_ACTION(version, api_min); ADD_ACTION(version, api_min);
@ -745,13 +745,14 @@ void WebApplication::action_command_addCategory()
BitTorrent::Session::instance()->addCategory(category); BitTorrent::Session::instance()->addCategory(category);
} }
void WebApplication::action_command_removeCategory() void WebApplication::action_command_removeCategories()
{ {
CHECK_URI(0); CHECK_URI(0);
CHECK_PARAMETERS("category"); CHECK_PARAMETERS("categories");
QString category = request().posts["category"].trimmed(); QStringList categories = request().posts["categories"].split('\n');
BitTorrent::Session::instance()->removeCategory(category); foreach (const QString &category, categories)
BitTorrent::Session::instance()->removeCategory(category);
} }
void WebApplication::action_command_getSavePath() void WebApplication::action_command_getSavePath()

View file

@ -89,7 +89,7 @@ private:
void action_command_recheck(); void action_command_recheck();
void action_command_setCategory(); void action_command_setCategory();
void action_command_addCategory(); void action_command_addCategory();
void action_command_removeCategory(); void action_command_removeCategories();
void action_command_getSavePath(); void action_command_getSavePath();
void action_version_api(); void action_version_api();
void action_version_api_min(); void action_version_api_min();

View file

@ -128,6 +128,7 @@
<ul id="categoriesFilterMenu" class="contextMenu"> <ul id="categoriesFilterMenu" class="contextMenu">
<li><a href="#CreateCategory"><img src="theme/list-add" alt="QBT_TR(Add category...)QBT_TR"/> QBT_TR(Add category...)QBT_TR</a></li> <li><a href="#CreateCategory"><img src="theme/list-add" alt="QBT_TR(Add category...)QBT_TR"/> QBT_TR(Add category...)QBT_TR</a></li>
<li><a href="#DeleteCategory"><img src="theme/list-remove" alt="QBT_TR(Remove category)QBT_TR"/> QBT_TR(Remove category)QBT_TR</a></li> <li><a href="#DeleteCategory"><img src="theme/list-remove" alt="QBT_TR(Remove category)QBT_TR"/> QBT_TR(Remove category)QBT_TR</a></li>
<li><a href="#DeleteUnusedCategories"><img src="theme/list-remove" alt="QBT_TR(Remove unused categories)QBT_TR"/> QBT_TR(Remove unused categories)QBT_TR</a></li>
</ul> </ul>
<div id="desktopFooterWrapper"> <div id="desktopFooterWrapper">
<div id="desktopFooter"> <div id="desktopFooter">

View file

@ -25,6 +25,9 @@
}, },
DeleteCategory : function (element, ref) { DeleteCategory : function (element, ref) {
removeCategoryFN(element.id); removeCategoryFN(element.id);
},
DeleteUnusedCategories : function (element, ref) {
deleteUnusedCategoriesFN();
} }
}, },
offsets : { offsets : {

View file

@ -203,7 +203,7 @@ window.addEvent('load', function () {
}; };
var updateFilter = function(filter, filterTitle) { 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() { var updateFiltersList = function() {

View file

@ -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 state = row['full_data'].state;
var inactive = false; var inactive = false;
var r; var r;
@ -662,25 +662,24 @@ var TorrentsTable = new Class({
break; break;
} }
if (categoryName == CATEGORIES_ALL) if (categoryHash == CATEGORIES_ALL)
return true; return true;
if (categoryName == CATEGORIES_UNCATEGORIZED && row['full_data'].category.length === 0) if (categoryHash == CATEGORIES_UNCATEGORIZED && row['full_data'].category.length === 0)
return true; return true;
if (categoryName != genHash(row['full_data'].category)) if (categoryHash != genHash(row['full_data'].category))
return false; return false;
return true; return true;
}, },
getFilteredTorrentsNumber : function (filterName) { getFilteredTorrentsNumber : function (filterName, categoryHash) {
var cnt = 0; var cnt = 0;
var rows = this.rows.getValues(); var rows = this.rows.getValues();
for (i = 0; i < rows.length; i++) 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; return cnt;
}, },

View file

@ -360,10 +360,26 @@ initializeWindows = function() {
removeCategoryFN = function (categoryHash) { removeCategoryFN = function (categoryHash) {
var categoryName = category_list[categoryHash].name; var categoryName = category_list[categoryHash].name;
new Request({ new Request({
url: 'command/removeCategory', url: 'command/removeCategories',
method: 'post', method: 'post',
data: { 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(); }).send();
setCategoryFilter(CATEGORIES_ALL); setCategoryFilter(CATEGORIES_ALL);