Merge pull request #251 from adam111316/feature/ChangeFasterConfig

Change general config's branches and pull request list generation for fa...
This commit is contained in:
adam111316 2015-03-03 00:31:28 +08:00
commit 43ca775cdb
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,28 +487,23 @@
<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>

View file

@ -119,6 +119,8 @@ $(document).ready(function(){
window.location.href = sbRoot + '/home/pullRequestCheckout?branch=' + $('#pullRequestVersion').val();
});
fetch_branches();
fetch_pullrequests();
});
function config_success(response) {
@ -132,3 +134,65 @@ function config_success(response){
});
$('#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):