Skip to content

Commit

Permalink
Rewritten addExistingShows, to make use of json and html data attribu…
Browse files Browse the repository at this point in the history
…tes. A POST is now used instead of the get with crappy csv.
  • Loading branch information
p0psicles committed Apr 21, 2016
1 parent 3525561 commit 94332bc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 33 deletions.
25 changes: 19 additions & 6 deletions gui/slick/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3400,20 +3400,33 @@ var SICKRAGE = {
});

$('#submitShowDirs').on('click', function() {
var dirArr = [];
var dirArr = {"submitListOfShows" : [], "promptForSettings": ''};
$('.dirCheck').each(function() {
if (this.checked === true) {
var show = $(this).attr('id');
var indexer = $(this).closest('tr').find('select').val();
dirArr.push(encodeURIComponent(indexer + '|' + show));
var existingIndexerId = $(this).attr('data-existing-indexer-id');
var showName = $(this).attr('data-show-name');
var existingIndexer = $(this).attr('data-existing-indexer');
var selectedIndexer = $(this).closest('tr').find('select').val();
var showDir = $(this).attr('data-show-dir');
dirArr.submitListOfShows.push({"existingIndexerId": existingIndexerId, "showDir": showDir,
"showName": showName, "existingIndexer": existingIndexer,"selectedIndexer": selectedIndexer});
}
});

if (dirArr.length === 0) {
return false;
}

dirArr.promptForSettings = $('#promptForSettings').prop('checked') ? 'on' : 'off';

window.location.href = srRoot + '/addShows/addExistingShows?promptForSettings=' + ($('#promptForSettings').prop('checked') ? 'on' : 'off') + '&shows_to_add=' + dirArr.join('&shows_to_add=');
$.ajax({
type: "POST",
url: srRoot + '/addShows/addExistingShows',
data: JSON.stringify(dirArr),
})
.done(function(response) {
$('#container').html(response);
});
});

function loadContent() {
Expand Down
4 changes: 2 additions & 2 deletions gui/slick/js/massUpdate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(document).ready(function(){
$('.submitMassEdit').on('click', function(){

var data = {"editListOfShows" : []}
var data = {"editListOfShows" : []};
$('.editCheck').each(function() {
if(this.checked === true) { data.editListOfShows.push($(this).attr('id').split('-')[1]); }
});
Expand All @@ -10,7 +10,7 @@ $(document).ready(function(){

$.ajax({
type: "POST",
url: 'massEdit',
url: srRoot + '/massEdit',
data: JSON.stringify(data),
})
.done(function(response) {
Expand Down
18 changes: 10 additions & 8 deletions gui/slick/views/home_massAddTable.mako
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
continue
show_id = curDir['dir']
if curDir['existing_info'][0]:
show_id = show_id + '|' + str(curDir['existing_info'][0]) + '|' + str(curDir['existing_info'][1])
indexer = curDir['existing_info'][2]
if curDir['existing_info']['indexer_id']:
show_id = show_id + '|' + str(curDir['existing_info']['indexer_id']) + '|' + str(curDir['existing_info']['show_name'])
indexer = curDir['existing_info']['indexer']
indexer = 0
if curDir['existing_info'][0]:
indexer = curDir['existing_info'][2]
if curDir['existing_info']['indexer_id']:
indexer = curDir['existing_info']['indexer']
elif sickbeard.INDEXER_DEFAULT > 0:
indexer = sickbeard.INDEXER_DEFAULT
%>
<tr>
<td class="col-checkbox"><input type="checkbox" id="${show_id}" class="dirCheck" checked=checked></td>
<td class="col-checkbox"><input type="checkbox" id="${show_id}" class="dirCheck" checked=checked
data-existing-indexer-id="${curDir['existing_info']['indexer_id']}" data-show-name="${curDir['existing_info']['show_name']}"
data-existing-indexer="${curDir['existing_info']['indexer']}" data-show-dir="${curDir['dir']}" data-allready-added="${curDir['added_already']}"></td>
<td><label for="${show_id}">${curDir['display_dir']}</label></td>
% if curDir['existing_info'][1] and indexer > 0:
<td><a href="${anon_url(sickbeard.indexerApi(indexer).config['show_url'], curDir['existing_info'][0])}">${curDir['existing_info'][1]}</a></td>
% if curDir['existing_info']['show_name'] and indexer > 0:
<td><a href="${anon_url(sickbeard.indexerApi(indexer).config['show_url'], curDir['existing_info']['indexer_id'])}">${curDir['existing_info']['show_name']}</a></td>
% else:
<td>?</td>
% endif
Expand Down
46 changes: 29 additions & 17 deletions sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,6 @@ def titler(x):
'name': showObj.name,
})


episode_history = []
try:
main_db_con = db.DBConnection()
Expand All @@ -1648,7 +1647,7 @@ def titler(x):
episode_history.append(dict(item))
except Exception as e:
logger.log("Couldn't read latest episode statust. Error: {}".format(e))

show_words = show_name_helpers.show_words(showObj)

return t.render(
Expand Down Expand Up @@ -2694,7 +2693,7 @@ def massAddTable(self, rootDir=None):
if not indexer_id and i:
indexer_id = i

cur_dir['existing_info'] = (indexer_id, show_name, indexer)
cur_dir['existing_info'] = {"indexer_id": indexer_id, "show_name": show_name, "indexer": indexer}

if indexer_id and Show.find(sickbeard.showList, indexer_id):
cur_dir['added_already'] = True
Expand Down Expand Up @@ -3138,41 +3137,52 @@ def split_extra_show(extra_show):

return indexer, show_dir, indexer_id, show_name

def addExistingShows(self, shows_to_add=None, promptForSettings=None):
def addExistingShows(self, **data):
"""
Receives a dir list and add them. Adds the ones with given TVDB IDs first, then forwards
along to the newShow page.
"""

# We need to do this, because somewhere Tornado wraps the json in another json object.
json_param = json.loads(data.iteritems().next()[0])

# Get the passed attributes
shows_to_add = json_param.get('submitListOfShows')
prompt_for_settings = config.checkbox_to_value(json_param.get('promptForSettings'))

# grab a list of other shows to add, if provided
if not shows_to_add:
shows_to_add = []
elif not isinstance(shows_to_add, list):
shows_to_add = [shows_to_add]

shows_to_add = [unquote_plus(x) for x in shows_to_add]

promptForSettings = config.checkbox_to_value(promptForSettings)
# shows_to_add = [unquote_plus(x) for x in shows_to_add]

indexer_id_given = []
dirs_only = []
# separate all the ones with Indexer IDs
for cur_dir in shows_to_add:
if '|' in cur_dir:
split_vals = cur_dir.split('|')
if len(split_vals) < 3:
dirs_only.append(cur_dir)
if '|' not in cur_dir:
selected_indexer = cur_dir.get('selectedIndexer')
existing_indexer = cur_dir.get('existingIndexer')
existing_indexer_id = cur_dir.get('existingIndexerId')
show_name = cur_dir.get('showName')
show_dir = cur_dir.get('showDir')

if existing_indexer_id and existing_indexer:
indexer = existing_indexer
elif sickbeard.INDEXER_DEFAULT > 0:
indexer = sickbeard.INDEXER_DEFAULT

if not selected_indexer:
dirs_only.append(cur_dir)
else:
indexer, show_dir, indexer_id, show_name = self.split_extra_show(cur_dir)

if not show_dir or not indexer_id or not show_name:
if not show_dir or not existing_indexer_id or not show_name:
continue

indexer_id_given.append((int(indexer), show_dir, int(indexer_id), show_name))
indexer_id_given.append((int(indexer), show_dir, int(existing_indexer_id), show_name))

# if they want me to prompt for settings then I will just carry on to the newShow page
if promptForSettings and shows_to_add:
if prompt_for_settings and shows_to_add:
return self.newShow(shows_to_add[0], shows_to_add[1:])

# if they don't want me to prompt for settings then I can just add all the nfo shows now
Expand Down Expand Up @@ -3478,6 +3488,8 @@ def massEdit(self, **shows):
# I need to do this, because somewhere Tornado wraps the json in another json object.
showIDs = json.loads(shows.iteritems().next()[0]).get('editListOfShows')

# This doesn't do anything, at least not that I can think of. Because of no checkboxes selected
# massEdit is never called.
if not showIDs:
return json.dumps({"redirect": "/manage/"})

Expand Down

0 comments on commit 94332bc

Please sign in to comment.