Skip to content

Commit

Permalink
Fixed webui according to new core.get_torrents_status changes and imp…
Browse files Browse the repository at this point in the history
…lemented quick search field
  • Loading branch information
bendikro committed Sep 30, 2014
1 parent 5d08f09 commit c356ae7
Show file tree
Hide file tree
Showing 11 changed files with 825 additions and 89 deletions.
51 changes: 37 additions & 14 deletions deluge/plugins/Label/deluge/plugins/label/data/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,22 +373,51 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
text: _('No Label'),
label: '',
handler: this.onTorrentMenuClick,
checked: false,
group: "label",
scope: this
});

for (var state in states) {
if (!state || state == 'All') continue;
this.torrentMenu.addMenuItem({
text: state,
label: state,
handler: this.onTorrentMenuClick,
checked: false,
group: "label",
scope: this
});
}
},

onMenuDisplayed: function(rowIndex) {
var ids = deluge.torrents.getSelectedIds();
/* Set none of the labels checked */
if (ids.length > 1) {
for (var i = 0; i < this.torrentMenu.items.items.length; i++) {
this.torrentMenu.items.items[i].setChecked(false);
}
return;
}

/* Set the correct label item checked */
label = deluge.torrents.getTorrent(rowIndex).data.label;
if (label == "") {
label = _('No Label');
}

for (var i = 0; i < this.torrentMenu.items.items.length; i++) {
if (this.torrentMenu.items.items[i].text == label) {
this.torrentMenu.items.items[i].setChecked(true);
break;
}
}
},

onDisable: function() {
deluge.sidebar.un('filtercreate', this.onFilterCreate);
deluge.sidebar.un('afterfiltercreate', this.onAfterFilterCreate);
deluge.filterbar.un('filtercreate', this.onFilterCreate);
deluge.filterbar.un('afterfiltercreate', this.onAfterFilterCreate);
delete Deluge.FilterPanel.templates.label;
this.deregisterTorrentStatus('label');
deluge.menus.torrent.remove(this.tmSep);
Expand All @@ -402,26 +431,23 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
xtype: 'menuseparator'
});

this.tm = deluge.menus.torrent.add({
text: _('Label'),
menu: this.torrentMenu
});
this.tm = deluge.menus.addMenuItem(_('Label'), this.torrentMenu, this);

var lbltpl = '<div class="x-deluge-filter">' +
'<tpl if="filter">{filter}</tpl>' +
'<tpl if="!filter">No Label</tpl>' +
' ({count})' +
'</div>';

if (deluge.sidebar.hasFilter('label')) {
var filter = deluge.sidebar.getFilter('label');
if (deluge.filterbar.hasFilter('label')) {
var filter = deluge.filterbar.getFilter('label');
filter.list.columns[0].tpl = new Ext.XTemplate(lbltpl);
this.setFilter(filter);
this.updateTorrentMenu(filter.getStates());
filter.list.refresh();
} else {
deluge.sidebar.on('filtercreate', this.onFilterCreate, this);
deluge.sidebar.on('afterfiltercreate', this.onAfterFilterCreate, this);
deluge.filterbar.on('filtercreate', this.onFilterCreate, this);
deluge.filterbar.on('afterfiltercreate', this.onAfterFilterCreate, this);
Deluge.FilterPanel.templates.label = lbltpl;
}
this.registerTorrentStatus('label', _('Label'));
Expand All @@ -446,7 +472,7 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
},

onLabelAdded: function(label) {
var filter = deluge.sidebar.getFilter('label');
var filter = deluge.filterbar.getFilter('label');
var states = filter.getStates();
var statesArray = [];

Expand All @@ -458,9 +484,6 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
statesArray.push(label.toLowerCase());
statesArray.sort();

//console.log(states);
//console.log(statesArray);

states = {}

for (i = 0; i < statesArray.length; ++i) {
Expand Down
10 changes: 5 additions & 5 deletions deluge/ui/web/js/deluge-all/Deluge.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ Ext.apply(Deluge, {

// private
pluginStore: {},

// private
progressTpl: '<div class="x-progress-wrap x-progress-renderered">' +
'<div class="x-progress-inner">' +
'<div style="width: {2}px" class="x-progress-bar">' +
'<div style="z-index: 99; width: {3}px" class="x-progress-text">' +
'<div style="width: {1}px;">{0}</div>' +
'<div style="width: {1}px;white-space:pre;">{0}</div>' +
'</div>' +
'</div>' +
'<div class="x-progress-text x-progress-text-back">' +
'<div style="width: {1}px;">{0}</div>' +
'<div style="width: {1}px;white-space:pre;">{0}</div>' +
'</div>' +
'</div>' +
'</div>',


/**
* A method to create a progress bar that can be used by renderers
* to display a bar within a grid or tree.
Expand All @@ -119,7 +119,7 @@ Ext.apply(Deluge, {
var progressWidth = ((width / 100.0) * progress).toFixed(0);
var barWidth = progressWidth - 1;
var textWidth = ((progressWidth - modifier) > 0 ? progressWidth - modifier : 0);
return String.format(Deluge.progressTpl, text, width, barWidth, textWidth);
return String.format(Deluge.progressTpl, text, width, barWidth, textWidth);
},

/**
Expand Down
165 changes: 165 additions & 0 deletions deluge/ui/web/js/deluge-all/Filterbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*!
* Deluge.Sidebar.js
*
* Copyright (c) Damien Churchill 2009-2010 <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the OpenSSL
* library.
* You must obey the GNU General Public License in all respects for all of
* the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete
* this exception statement from your version. If you delete this exception
* statement from all source files in the program, then also delete it here.
*/

// These are just so gen_gettext.py will pick up the strings
// _('State')
// _('Tracker Host')

/**
* @class Deluge.Sidebar
* @author Damien Churchill <[email protected]>
* @version 1.3
*/
Deluge.Filterbar = Ext.extend(Ext.Panel, {

// private
panels: {},

// private
selected: null,

constructor: function(config) {
config = Ext.apply({
id: 'filterbar',
region: 'west',
cls: 'deluge-filterbar',
title: _('Filters'),
layout: 'accordion',
split: true,
width: 200,
minSize: 100,
collapsible: true,
margins: '5 0 0 5',
cmargins: '5 0 0 5'
}, config);
Deluge.Filterbar.superclass.constructor.call(this, config);
},

// private
initComponent: function() {
Deluge.Filterbar.superclass.initComponent.call(this);
deluge.events.on("disconnect", this.onDisconnect, this);
},

createFilter: function(filter, states) {
var panel = new Deluge.FilterPanel({
filter: filter
});
panel.on('selectionchange', function(view, nodes) {
deluge.ui.update();
});
this.add(panel);
this.doLayout();
this.panels[filter] = panel;
//for (var e in panel) {
// console.log("Panel e: %s", e);
//}

//panel.header.on('click', function(header) {
// if (!deluge.config.filterbar_multiple_filters) {
// deluge.ui.update();
// }
// if (!panel.list.getSelectionCount()) {
// panel.list.select(0);
// }
//});
this.fireEvent('filtercreate', this, panel);

panel.updateStates(states);
this.fireEvent('afterfiltercreate', this, panel);
},

getFilter: function(filter) {
return this.panels[filter];
},

getFilterStates: function() {
var states = {}

if (deluge.config.filterbar_multiple_filters) {
// Grab the filters from each of the filter panels
this.items.each(function(panel) {
var state = panel.getState();
if (state == null) return;
states[panel.filterType] = state;
}, this);
} else {
var panel = this.getLayout().activeItem;
if (panel) {
var state = panel.getState();
if (!state == null) return;
states[panel.filterType] = state;
}
}

return states;
},

hasFilter: function(filter) {
return (this.panels[filter]) ? true : false;
},

// private
onDisconnect: function() {
for (var filter in this.panels) {
this.remove(this.panels[filter]);
}
this.panels = {};
this.selected = null;
},

onFilterSelect: function(selModel, rowIndex, record) {
console.log("onFilterSelect");
deluge.ui.update();
},

update: function(filters) {
for (var filter in filters) {
var states = filters[filter];
if (Ext.getKeys(this.panels).indexOf(filter) > -1) {
this.panels[filter].updateStates(states);
} else {
this.createFilter(filter, states);
}
}

// Perform a cleanup of fitlers that aren't enabled any more
Ext.each(Ext.keys(this.panels), function(filter) {
if (Ext.keys(filters).indexOf(filter) == -1) {
// We need to remove the panel
this.remove(this.panels[filter]);
this.doLayout();
delete this.panels[filter];
}
}, this);
}
});
18 changes: 18 additions & 0 deletions deluge/ui/web/js/deluge-all/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,21 @@ deluge.menus = {
case 'move':
deluge.moveStorage.show(ids);
break;
case 'auto_managed':
var opts = { auto_managed : true };
deluge.client.core.set_torrent_options(ids, opts);
break;
}
},
menu_items: {},
addMenuItem: function(name, menu, plugin) {
this.menu_items[name] = plugin;
console.log("Menus - addMenuItem: %s", name);
tm = deluge.menus.torrent.add({
text: name,
menu: menu
});
return tm;
}
}

Expand All @@ -96,6 +110,7 @@ deluge.menus.torrent = new Ext.menu.Menu({
handler: deluge.menus.onTorrentAction,
scope: deluge.menus
}, '-', {
id: 'options',
text: _('Options'),
iconCls: 'icon-options',
hideOnClick: false,
Expand Down Expand Up @@ -179,6 +194,9 @@ deluge.menus.torrent = new Ext.menu.Menu({
}, {
id: 'auto_managed',
text: _('Auto Managed'),
torrentAction: 'auto_managed',
handler: deluge.menus.onTorrentAction,
scope: deluge.menus,
checked: false
}]
})
Expand Down
Loading

0 comments on commit c356ae7

Please sign in to comment.