Browse Source

Change file browser to permit manually entering a path.

pull/604/head
JackDandy 9 years ago
parent
commit
a59fe898b5
  1. 4
      CHANGES.md
  2. 4
      gui/slick/css/dark.css
  3. BIN
      gui/slick/css/lib/images/ui-icons_09a2ff_256x240.png
  4. 2
      gui/slick/css/light.css
  5. 4
      gui/slick/css/style.css
  6. 161
      gui/slick/js/browser.js
  7. 82
      sickbeard/browser.py
  8. 7
      sickbeard/webserve.py

4
CHANGES.md

@ -108,7 +108,9 @@
* Fix issue on Add Existing Shows page where shows were listed that should not have been * Fix issue on Add Existing Shows page where shows were listed that should not have been
* Change get_size helper to also handle files * Change get_size helper to also handle files
* Change improve handling of a bad email notify setting * Change improve handling of a bad email notify setting
* Change give OMGWTFNZBS provider more time to respond * Fix provider MTV download URL
* Change give provider OMGWTFNZBS more time to respond
* Change file browser to permit manually entering a path
### 0.10.0 (2015-08-06 11:05:00 UTC) ### 0.10.0 (2015-08-06 11:05:00 UTC)

4
gui/slick/css/dark.css

@ -20,7 +20,7 @@ inc_top.tmpl
} }
.browserDialog.busy .ui-dialog-buttonpane{ .browserDialog.busy .ui-dialog-buttonpane{
background:url("../images/loading.gif") 10px 50% no-repeat !important background:url("../images/loading32-dark.gif") 10px 50% no-repeat !important
} }
.ui-progressbar .ui-progressbar-overlay{ .ui-progressbar .ui-progressbar-overlay{
@ -61,6 +61,8 @@ inc_top.tmpl
.ui-state-default, .ui-state-default,
.ui-widget-content .ui-state-default, .ui-widget-content .ui-state-default,
.ui-widget-header .ui-state-default{ .ui-widget-header .ui-state-default{
background:#3d3d3d;
color:#fff;
border:1px solid #111 border:1px solid #111
} }

BIN
gui/slick/css/lib/images/ui-icons_09a2ff_256x240.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

2
gui/slick/css/light.css

@ -16,7 +16,7 @@ inc_top.tmpl
} }
.browserDialog.busy .ui-dialog-buttonpane{ .browserDialog.busy .ui-dialog-buttonpane{
background:url("../images/loading.gif") 10px 50% no-repeat !important background:url("../images/loading32.gif") 10px 50% no-repeat !important
} }
.ui-progressbar .ui-progressbar-overlay{ .ui-progressbar .ui-progressbar-overlay{

4
gui/slick/css/style.css

@ -3032,6 +3032,10 @@ fieldset[disabled] .navbar-default .btn-link:focus{
display:inline display:inline
} }
#fileBrowserDialog .form-control{background-color:#f5f1e4}
#fileBrowserDialog .form-control:active,
#fileBrowserDialog .form-control:hover{background-color:#ffffca}
.btn{ .btn{
display:inline-block; display:inline-block;
*display:inline; *display:inline;

161
gui/slick/js/browser.js

@ -1,12 +1,13 @@
;(function($) { ;(function($) {
"use strict"; 'use strict';
$.Browser = { $.Browser = {
defaults: { defaults: {
title: 'Choose Directory', title: 'Choose Directory (or enter manually)',
url: sbRoot + '/browser/', url: sbRoot + '/browser/',
autocompleteURL: sbRoot + '/browser/complete', autocompleteURL: sbRoot + '/browser/complete',
includeFiles: 0 includeFiles: 0,
showBrowseButton: !0
} }
}; };
@ -14,7 +15,7 @@
function browse(path, endpoint, includeFiles) { function browse(path, endpoint, includeFiles) {
if (currentBrowserPath == path) { if (path === currentBrowserPath) {
return; return;
} }
@ -26,68 +27,91 @@
fileBrowserDialog.dialog('option', 'dialogClass', 'browserDialog busy'); fileBrowserDialog.dialog('option', 'dialogClass', 'browserDialog busy');
currentRequest = $.getJSON(endpoint, { path: path, includeFiles: includeFiles }, function (data) { currentRequest = $.getJSON(endpoint, {path: path, includeFiles: includeFiles}, function(data){
fileBrowserDialog.empty(); fileBrowserDialog.empty();
var first_val = data[0]; var firstVal = data[0], i = 0, list, link = null;
var i = 0; data = $.grep(data, function(){
var list, link = null;
data = $.grep(data, function (value) {
return i++ != 0; return i++ != 0;
}); });
$('<h2>').text(first_val.current_path).appendTo(fileBrowserDialog); $('<input type="text" class="form-control input-sm">')
.val(firstVal.currentPath)
.on('keypress', function(e){
if (13 === e.which) {
browse(e.target.value, endpoint, includeFiles);
}
})
.appendTo(fileBrowserDialog)
.fileBrowser({showBrowseButton: !1})
.on('autocompleteselect',
function(e, ui){browse(ui.item.value, endpoint, includeFiles);
});
list = $('<ul>').appendTo(fileBrowserDialog); list = $('<ul>').appendTo(fileBrowserDialog);
$.each(data, function (i, entry) { $.each(data, function(i, entry){
link = $("<a href='javascript:void(0)' />").click(function () { browse(entry.path, endpoint, includeFiles); }).text(entry.name); link = $('<a href="javascript:void(0)">').on('click',
$('<span class="ui-icon ui-icon-folder-collapsed"></span>').prependTo(link); function(){
link.hover( if (entry.isFile) {
function () {$("span", this).addClass("ui-icon-folder-open"); }, currentBrowserPath = entry.path;
function () {$("span", this).removeClass("ui-icon-folder-open"); } $('.browserDialog .ui-button:contains("Ok")').click();
); } else {
browse(entry.path, endpoint, includeFiles);
}
}).text(entry.name);
if (entry.isFile) {
link.prepend('<span class="ui-icon ui-icon-blank"></span>');
} else {
link.prepend('<span class="ui-icon ui-icon-folder-collapsed"></span>')
.on('mouseenter', function(){$('span', this).addClass('ui-icon-folder-open');})
.on('mouseleave', function(){$('span', this).removeClass('ui-icon-folder-open');});
}
link.appendTo(list); link.appendTo(list);
}); });
$("a", list).wrap('<li class="ui-state-default ui-corner-all">'); $('a', list).wrap('<li class="ui-state-default ui-corner-all">');
fileBrowserDialog.dialog('option', 'dialogClass', 'browserDialog'); fileBrowserDialog.dialog('option', 'dialogClass', 'browserDialog');
}); });
} }
$.fn.nFileBrowser = function (callback, options) { $.fn.nFileBrowser = function(callback, options){
options = $.extend({}, $.Browser.defaults, options); options = $.extend({}, $.Browser.defaults, options);
// make a fileBrowserDialog object if one doesn't exist already // make a fileBrowserDialog object if one doesn't exist already
if (!fileBrowserDialog) { if (fileBrowserDialog) {
fileBrowserDialog.dialog('option', 'title', options.title);
} else {
// set up the jquery dialog // set up the jquery dialog
fileBrowserDialog = $('<div id="fileBrowserDialog" style="display:hidden"></div>').appendTo('body').dialog({ var docWidth = $(document).width(), dlgWidth = Math.min(docWidth - 80, 650),
docHeight = $(document).height() - 80, winHeight = $(window).height() - 80;
fileBrowserDialog = $('<div id="fileBrowserDialog" style="display:none"></div>').appendTo('body').dialog({
dialogClass: 'browserDialog', dialogClass: 'browserDialog',
title: options.title, title: options.title,
position: ['center', 40], position: [(docWidth - dlgWidth)/2, 60],
minWidth: Math.min($(document).width() - 80, 650), minWidth: dlgWidth,
height: Math.min($(document).height() - 80, $(window).height() - 80), height: Math.min(docHeight, winHeight),
maxHeight: Math.min($(document).height() - 80, $(window).height() - 80), maxHeight: Math.min(docHeight, winHeight),
maxWidth: $(document).width() - 80, maxWidth: docWidth - 80,
modal: true, modal: true,
autoOpen: false autoOpen: false
}); });
} }
fileBrowserDialog.dialog('option', 'buttons', [ fileBrowserDialog.dialog('option', 'buttons',
{ [{
text: "Ok", text: 'Ok',
"class": "btn", 'class': 'btn',
click: function() { click: function(){
// store the browsed path to the associated text field // store the browsed path to the associated text field
callback(currentBrowserPath, options); callback(currentBrowserPath, options);
$(this).dialog("close"); $(this).dialog('close');
} }
}, },
{ {
text: "Cancel", text: 'Cancel',
"class": "btn", 'class': 'btn',
click: function() { click: function(){
$(this).dialog("close"); $(this).dialog('close');
}
} }
]); }]);
// set up the browser and launch the dialog // set up the browser and launch the dialog
var initialDir = ''; var initialDir = '';
@ -101,7 +125,7 @@
return false; return false;
}; };
$.fn.fileBrowser = function (options) { $.fn.fileBrowser = function(options){
options = $.extend({}, $.Browser.defaults, options); options = $.extend({}, $.Browser.defaults, options);
// text field used for the result // text field used for the result
options.field = $(this); options.field = $(this);
@ -109,45 +133,44 @@
if (options.field.autocomplete && options.autocompleteURL) { if (options.field.autocomplete && options.autocompleteURL) {
var query = ''; var query = '';
options.field.autocomplete({ options.field.autocomplete({
position: { my : "top", at: "bottom", collision: "flipfit" }, position: {my: 'top', at: 'bottom', collision: 'flipfit'},
source: function (request, response) { source: function(request, response){
//keep track of user submitted search term //keep track of user submitted search term
query = $.ui.autocomplete.escapeRegex(request.term, options.includeFiles); query = $.ui.autocomplete.escapeRegex(request.term, options.includeFiles);
$.ajax({ $.ajax({
url: options.autocompleteURL, url: options.autocompleteURL,
data: request, data: request,
dataType: "json", dataType: 'json',
success: function (data, item) { success: function(data){
//implement a startsWith filter for the results //implement a startsWith filter for the results
var matcher = new RegExp("^" + query, "i"); var matcher = new RegExp('^' + query, 'i');
var a = $.grep(data, function (item, index) { var a = $.grep(data, function(item){
return matcher.test(item); return matcher.test(item);
}); });
response(a); response(a);
} }
}); });
}, },
open: function (event, ui) { open: function(){
$(".ui-autocomplete li.ui-menu-item a").removeClass("ui-corner-all"); $('.ui-autocomplete li.ui-menu-item a').removeClass('ui-corner-all');
$(".ui-autocomplete li.ui-menu-item:odd a").addClass("ui-menu-item-alternate"); $('.ui-autocomplete li.ui-menu-item:odd a').addClass('ui-menu-item-alternate');
} }
}) }).data('ui-autocomplete')._renderItem = function(ul, item){
.data("ui-autocomplete")._renderItem = function (ul, item) {
//highlight the matched search term from the item -- note that this is global and will match anywhere //highlight the matched search term from the item -- note that this is global and will match anywhere
var result_item = item.label; var resultItem = item.label;
var x = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + query + ")(?![^<>]*>)(?![^&;]+;)", "gi"); var x = new RegExp('(?![^&;]+;)(?!<[^<>]*)(' + query + ')(?![^<>]*>)(?![^&;]+;)', 'gi');
result_item = result_item.replace(x, function (FullMatch, n) { resultItem = resultItem.replace(x, function(fullMatch){
return '<b>' + FullMatch + '</b>'; return '<b>' + fullMatch + '</b>';
}); });
return $("<li></li>") return $('<li></li>')
.data("ui-autocomplete-item", item) .data('ui-autocomplete-item', item)
.append("<a class='nowrap'>" + result_item + "</a>") .append('<a class="nowrap">' + resultItem + '</a>')
.appendTo(ul); .appendTo(ul);
}; };
} }
var initialDir, path, callback, ls = false; var path, callback, ls = false;
// if the text field is empty and we're given a key then populate it with the last browsed value from localStorage // if empty text field and given a key then populate it with the last browsed value from localStorage
try { ls = !!(localStorage.getItem); } catch (e) {} try { ls = !!(localStorage.getItem); } catch (e) {}
if (ls && options.key) { if (ls && options.key) {
path = localStorage['fileBrowser-' + options.key]; path = localStorage['fileBrowser-' + options.key];
@ -156,7 +179,7 @@
options.field.val(path); options.field.val(path);
} }
callback = function (path, options) { callback = function(path, options){
// store the browsed path to the associated text field // store the browsed path to the associated text field
options.field.val(path); options.field.val(path);
@ -164,18 +187,22 @@
if (ls && options.key) { if (ls && options.key) {
localStorage['fileBrowser-' + options.key] = path; localStorage['fileBrowser-' + options.key] = path;
} }
}; };
initialDir = options.field.val() || (options.key && path) || '';
options = $.extend(options, {initialDir: initialDir});
options.field.addClass('fileBrowserField');
if (options.showBrowseButton) {
// append the browse button and give it a click behaviour // append the browse button and give it a click behaviour
return options.field.addClass('fileBrowserField').after($('<input type="button" value="Browse&hellip;" class="btn btn-inline fileBrowser" />').click(function () { options.field.after(
$(this).nFileBrowser(callback, options); $('<input type="button" value="Browse&hellip;" class="btn btn-inline fileBrowser">').on('click',
function(){
$(this).nFileBrowser(callback, $.extend(
{}, options, {initialDir: options.field.val() || (options.key && path) || ''}
));
return false; return false;
})); }));
}
return options.field;
}; };
})(jQuery); })(jQuery);

82
sickbeard/browser.py

@ -30,17 +30,18 @@ except ImportError:
from lib import simplejson as json from lib import simplejson as json
# this is for the drive letter code, it only works on windows # this is for the drive letter code, it only works on windows
if os.name == 'nt': if 'nt' == os.name:
from ctypes import windll from ctypes import windll
# adapted from http://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python/827490 # adapted from
# http://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python/827490
def getWinDrives(): def getWinDrives():
""" Return list of detected drives """ """ Return list of detected drives """
assert os.name == 'nt' assert 'nt' == os.name
drives = [] drives = []
bitmask = windll.kernel32.GetLogicalDrives() #@UndefinedVariable bitmask = windll.kernel32.GetLogicalDrives()
for letter in string.uppercase: for letter in string.uppercase:
if bitmask & 1: if bitmask & 1:
drives.append(letter) drives.append(letter)
@ -56,54 +57,67 @@ def foldersAtPath(path, includeParent=False, includeFiles=False):
""" """
# walk up the tree until we find a valid path # walk up the tree until we find a valid path
while path and not os.path.isdir(path): while path and not ek.ek(os.path.isdir, path):
if path == os.path.dirname(path): if path == ek.ek(os.path.dirname, path):
path = '' path = ''
break break
else: else:
path = os.path.dirname(path) path = ek.ek(os.path.dirname, path)
if path == '': if '' == path:
if os.name == 'nt': if 'nt' == os.name:
entries = [{'current_path': 'Root'}] entries = [{'currentPath': '\My Computer'}]
for letter in getWinDrives(): for letter in getWinDrives():
letterPath = '%s:\\' % letter letter_path = '%s:\\' % letter
entries.append({'name': letterPath, 'path': letterPath}) entries.append({'name': letter_path, 'path': letter_path})
return entries return entries
else: else:
path = '/' path = '/'
# fix up the path and find the parent # fix up the path and find the parent
path = os.path.abspath(os.path.normpath(path)) path = ek.ek(os.path.abspath, ek.ek(os.path.normpath, path))
parentPath = os.path.dirname(path) parent_path = ek.ek(os.path.dirname, path)
# if we're at the root then the next step is the meta-node showing our drive letters # if we're at the root then the next step is the meta-node showing our drive letters
if path == parentPath and os.name == 'nt': if 'nt' == os.name and path == parent_path:
parentPath = '' parent_path = ''
try: try:
fileList = [{'name': filename, 'path': ek.ek(os.path.join, path, filename)} for filename in file_list = get_file_list(path, includeFiles)
ek.ek(os.listdir, path)]
except OSError as e: except OSError as e:
logger.log(u'Unable to open %s: %r / %s' % (path, e, e), logger.WARNING) logger.log(u'Unable to open %s: %r / %s' % (path, e, e), logger.WARNING)
fileList = [{'name': filename, 'path': ek.ek(os.path.join, parentPath, filename)} for filename in file_list = get_file_list(parent_path, includeFiles)
ek.ek(os.listdir, parentPath)]
if not includeFiles: file_list = sorted(file_list, lambda x, y: cmp(ek.ek(os.path.basename, x['name']).lower(),
fileList = filter(lambda entry: ek.ek(os.path.isdir, entry['path']), fileList) ek.ek(os.path.basename, y['path']).lower()))
# prune out directories to proect the user from doing stupid things (already lower case the dir to reduce calls) entries = [{'currentPath': path}]
hideList = ['boot', 'bootmgr', 'cache', 'msocache', 'recovery', '$recycle.bin', 'recycler', if includeParent and path != parent_path:
'system volume information', 'temporary internet files'] # windows specific entries.append({'name': '..', 'path': parent_path})
hideList += ['.fseventd', '.spotlight', '.trashes', '.vol', 'cachedmessages', 'caches', 'trash'] # osx specific entries.extend(file_list)
fileList = filter(lambda entry: entry['name'].lower() not in hideList, fileList)
fileList = sorted(fileList, return entries
lambda x, y: cmp(os.path.basename(x['name']).lower(), os.path.basename(y['path']).lower()))
entries = [{'current_path': path}]
if includeParent and parentPath != path:
entries.append({'name': '..', 'path': parentPath})
entries.extend(fileList)
return entries def get_file_list(path, include_files):
result = []
hide_names = [
# windows specific
'boot', 'bootmgr', 'cache', 'config.msi', 'msocache', 'recovery', '$recycle.bin', 'recycler',
'system volume information', 'temporary internet files',
# osx specific
'.fseventd', '.spotlight', '.trashes', '.vol', 'cachedmessages', 'caches', 'trash',
# general
'.git']
# filter directories to protect
for name in ek.ek(os.listdir, path):
if name.lower() not in hide_names:
path_file = ek.ek(os.path.join, path, name)
is_dir = ek.ek(os.path.isdir, path_file)
if include_files or is_dir:
result.append({'name': name, 'path': path_file, 'isFile': (1, 0)[is_dir]})
return result

7
sickbeard/webserve.py

@ -3366,6 +3366,13 @@ class Manage(MainHandler):
cur_show_dir = ek.ek(os.path.basename, showObj._location) cur_show_dir = ek.ek(os.path.basename, showObj._location)
if cur_root_dir in dir_map and cur_root_dir != dir_map[cur_root_dir]: if cur_root_dir in dir_map and cur_root_dir != dir_map[cur_root_dir]:
new_show_dir = ek.ek(os.path.join, dir_map[cur_root_dir], cur_show_dir) new_show_dir = ek.ek(os.path.join, dir_map[cur_root_dir], cur_show_dir)
if 'nt' != os.name and ':\\' in cur_show_dir:
cur_show_dir = showObj._location.split('\\')[-1]
try:
base_dir = dir_map[cur_root_dir].rsplit(cur_show_dir)[0].rstrip('/')
except IndexError:
base_dir = dir_map[cur_root_dir]
new_show_dir = ek.ek(os.path.join, base_dir, cur_show_dir)
logger.log( logger.log(
u'For show ' + showObj.name + ' changing dir from ' + showObj._location + ' to ' + new_show_dir) u'For show ' + showObj.name + ' changing dir from ' + showObj._location + ' to ' + new_show_dir)
else: else:

Loading…
Cancel
Save