Change general config's branches and pull request list generation for faster page loading

This commit is contained in:
Adam 2015-03-02 19:31:11 +08:00
parent 49e9a50444
commit 30720b9cbd
5 changed files with 121 additions and 38 deletions

View file

@ -24,12 +24,14 @@
* Change browser, bs4 parser and classes code to PEP8 standards
* Change common and config code to PEP8 standards
* Change database code to PEP8 standards
* Change general config's branches and pull request list generation for faster page loading
[develop changelog]
* Fix traceback error when using the menu item Manage/Update Kodi
* Change BET network logo filename to lower case
* Change redirect from home to showlistView on changing Layout on showlistView
### 0.7.0 (2015-02-23 11:02:00 UTC)
* Fix slow database operations (port from midgetspy/sickbeard)

View file

@ -487,33 +487,28 @@
<span class="component-title">Branch version:</span>
<span class="component-desc">
<select id="branchVersion" class="form-control form-control-inline input-sm pull-left max300">
#for $cur_branch in $sickbeard.versionCheckScheduler.action.list_remote_branches():
<option value="$cur_branch" #if $cur_branch == $sickbeard.BRANCH then 'selected="selected"' else ''#>$cur_branch</option>
#end for
<option>Loading list from github</option>
</select>
<input class="btn btn-inline" style="margin-left: 6px;" type="button" id="branchCheckout" value="Checkout Branch">
<input class="btn btn-inline" style="margin-left: 6px;" type="button" id="branchCheckout" value="Checkout Branch" disabled="disabled">
<div class="clear-left"><p>select branch to use (restart required)</p></div>
</span>
</label>
</div>
#set pulls = sickbeard.versionCheckScheduler.action.list_remote_pulls()
#if len(pulls) > 0 and $sickbeard.BRANCH != 'master':
#if $sickbeard.BRANCH != 'master':
<div class="field-pair">
<label>
<span class="component-title">Pull request:</span>
<span class="component-desc">
<select id="pullRequestVersion" class="form-control form-control-inline input-sm pull-left max300">
#for $cur_branch in $pulls:
<option value="$cur_branch.fetch_name()" #if $cur_branch == $sickbeard.BRANCH then 'selected="selected"' else ''#>$cur_branch</option>
#end for
<option>Loading list from github</option>
</select>
<input class="btn btn-inline" style="margin-left: 6px;" type="button" id="pullRequestCheckout" value="Checkout Pull Request">
<input class="btn btn-inline" style="margin-left: 6px;" type="button" id="pullRequestCheckout" value="Checkout Pull Request" disabled="disabled">
<div class="clear-left"><p>select pull request to test (restart required)</p></div>
</span>
</label>
</div>
#end if
#end if
<div class="field-pair">
<label for="git_remote">

View file

@ -1,13 +1,13 @@
$(document).ready(function(){
$(document).ready(function () {
var enabler = $('.enabler'),
viewIf = $('.viewIf');
enabler.each(function(){
enabler.each(function () {
if (!$(this).prop('checked'))
$('#content_' + $(this).attr('id')).hide();
});
enabler.click(function(){
enabler.click(function () {
var content_id = $('#content_' + $(this).attr('id'));
if ($(this).prop('checked'))
content_id.fadeIn('fast', 'linear');
@ -15,11 +15,11 @@ $(document).ready(function(){
content_id.fadeOut('fast', 'linear');
});
viewIf.each(function(){
viewIf.each(function () {
$(($(this).prop('checked') ? '.hide_if_' : '.show_if_') + $(this).attr('id')).hide();
});
viewIf.click(function(){
viewIf.click(function () {
var if_id = '_if_' + $(this).attr('id');
if ($(this).prop('checked')) {
$('.hide' + if_id).fadeOut('fast', 'linear');
@ -30,14 +30,14 @@ $(document).ready(function(){
}
});
var ui_update_trim_zero = (function() {
var ui_update_trim_zero = (function () {
var secs = ('00' + new Date().getSeconds().toString()).slice(-2),
elSecs = $('#trim_info_seconds'),
elTrimZero = $('#trim_zero');
elTrimZero.each(function() {
elTrimZero.each(function () {
var checked = $(this).prop('checked') && $('#fuzzy_dating').prop('checked');
$('#time_presets').find('option').each(function() {
$('#time_presets').find('option').each(function () {
var text = ($(this).text());
$(this).text(checked
? text.replace(/(\b\d+:\d\d):\d+/mg, '$1')
@ -54,13 +54,13 @@ $(document).ready(function(){
elSecs.fadeIn('fast', 'linear');
});
$('#trim_zero, #fuzzy_dating').click(function() {
$('#trim_zero, #fuzzy_dating').click(function () {
ui_update_trim_zero();
});
ui_update_trim_zero();
$('.datePresets').click(function(){
$('.datePresets').click(function () {
var elDatePresets = $('#date_presets'),
defaultPreset = elDatePresets.val();
if ($(this).prop('checked') && '%x' == defaultPreset) {
@ -86,49 +86,113 @@ $(document).ready(function(){
// bind 'myForm' and provide a simple callback function
$('#configForm').ajaxForm({
beforeSubmit: function(){
$('.config_submitter').each(function(){
beforeSubmit: function () {
$('.config_submitter').each(function () {
$(this).attr('disabled', 'disabled');
$(this).after('<span><img src="' + sbRoot + '/images/loading16' + themeSpinner + '.gif"> Saving...</span>');
$(this).hide();
});
$('.show_update_hour_value').text($('#show_update_hour').val())
},
success: function(response){
setTimeout(function(){config_success(response)}, 2000);
success: function (response) {
setTimeout(function () {config_success(response)}, 2000);
}
});
$('#api_key').click(function(){ $('#api_key').select() });
$('#generate_new_apikey').click(function(){
$('#api_key').click(function () {$('#api_key').select()});
$('#generate_new_apikey').click(function () {
$.get(sbRoot + '/config/general/generateKey',
function(data){
function (data) {
if (data.error != undefined) {
alert(data.error);
return;
}
$('#api_key').val(data);
});
});
});
$('#branchCheckout').click(function(){
$('#branchCheckout').click(function () {
window.location.href = sbRoot + '/home/branchCheckout?branch=' + $('#branchVersion').val();
});
$('#pullRequestCheckout').click(function(){
$('#pullRequestCheckout').click(function () {
window.location.href = sbRoot + '/home/pullRequestCheckout?branch=' + $('#pullRequestVersion').val();
});
fetch_branches();
fetch_pullrequests();
});
function config_success(response){
if (response == 'reload'){
function config_success(response) {
if (response == 'reload') {
window.location.reload(true);
}
$('.config_submitter').each(function(){
$('.config_submitter').each(function () {
$(this).removeAttr('disabled');
$(this).next().remove();
$(this).show();
});
$('#email_show').trigger('notify');
}
function fetch_pullrequests() {
$.getJSON(sbRoot + '/config/general/fetch_pullrequests', function (data) {
$('#pullRequestVersion').find('option').remove();
if (data['result'] == 'success') {
var pulls = [];
$.each(data['pulls'], function (i, pull) {
if (pull[0] != '') {
pulls.push(pull);
}
});
if (pulls.length > 0) {
$.each(pulls, function (i, text) {
add_option_to_pulls(text);
});
$('#pullRequestCheckout').removeAttr('disabled');
} else {
add_option_to_pulls(['No pull requests available', '']);
}
} else {
add_option_to_pulls(['Failed to connect to github', '']);
}
});
}
function fetch_branches() {
$.getJSON(sbRoot + '/config/general/fetch_branches', function (data) {
$('#branchVersion').find('option').remove();
if (data['result'] == 'success') {
var branches = [];
$.each(data['branches'], function (i, branch) {
if (branch != '') {
branches.push(branch);
}
});
if (branches.length > 0) {
$.each(branches, function (i, text) {
add_option_to_branches(text);
});
$('#branchCheckout').removeAttr('disabled');
} else {
add_option_to_branches('No branches available');
}
} else {
add_option_to_branches('Failed to connect to github');
}
});
}
function add_option_to_pulls(text) {
option = $('<option>');
option.attr('value', text[1]);
option.html(text[0]);
option.appendTo('#pullRequestVersion');
}
function add_option_to_branches(text) {
option = $('<option>');
option.attr('value', text);
option.html(text);
option.appendTo('#branchVersion');
}

View file

@ -98,13 +98,14 @@ class GitHub(object):
access_API = self._access_API(
['repos', self.github_repo_user, self.github_repo, 'pulls'],
params={'per_page': 100})
pull = []
pulls = []
for x in access_API:
try:
pull.append(PullRequest(x['head']['ref'], x['number']))
pull = PullRequest(x['head']['ref'], x['number'])
pulls.append((repr(pull), pull.fetch_name()))
except:
continue
return pull
return pulls
class PullRequest(object):
def __init__(self, ref, number):

View file

@ -3445,6 +3445,27 @@ class ConfigGeneral(Config):
self.clear_cookie('sickgear-session')
self.write('reload')
@staticmethod
def fetch_pullrequests():
if sickbeard.BRANCH == 'master':
return json.dumps({'result': 'success', 'pulls': []})
else:
try:
pulls = sickbeard.versionCheckScheduler.action.list_remote_pulls()
return json.dumps({'result': 'success', 'pulls': pulls})
except Exception, e:
logger.log(u'exception msg: ' + str(e), logger.DEBUG)
return json.dumps({'result': 'fail'})
@staticmethod
def fetch_branches():
try:
branches = sickbeard.versionCheckScheduler.action.list_remote_branches()
return json.dumps({'result': 'success', 'branches': branches})
except Exception, e:
logger.log(u'exception msg: ' + str(e), logger.DEBUG)
return json.dumps({'result': 'fail'})
class ConfigSearch(Config):
def index(self, *args, **kwargs):