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, 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()

View File

@ -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();

View File

@ -128,6 +128,7 @@
<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="#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>
<div id="desktopFooterWrapper">
<div id="desktopFooter">

View File

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

View File

@ -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() {

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 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;
},

View File

@ -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);