diff --git a/CHANGES.md b/CHANGES.md
index b578cd8d..7922003a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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)
diff --git a/gui/slick/interfaces/default/config_general.tmpl b/gui/slick/interfaces/default/config_general.tmpl
index 3e12a774..79d2356d 100644
--- a/gui/slick/interfaces/default/config_general.tmpl
+++ b/gui/slick/interfaces/default/config_general.tmpl
@@ -487,33 +487,28 @@
Branch version:
-#for $cur_branch in $sickbeard.versionCheckScheduler.action.list_remote_branches():
- $cur_branch
-#end for
+ Loading list from github
-
+
select branch to use (restart required)
- #set pulls = sickbeard.versionCheckScheduler.action.list_remote_pulls()
- #if len(pulls) > 0 and $sickbeard.BRANCH != 'master':
+#if $sickbeard.BRANCH != 'master':
- #end if
+#end if
diff --git a/gui/slick/js/config.js b/gui/slick/js/config.js
index 9800d182..665bf42d 100644
--- a/gui/slick/js/config.js
+++ b/gui/slick/js/config.js
@@ -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(' Saving... ');
$(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.attr('value', text[1]);
+ option.html(text[0]);
+ option.appendTo('#pullRequestVersion');
+}
+
+function add_option_to_branches(text) {
+ option = $(' ');
+ option.attr('value', text);
+ option.html(text);
+ option.appendTo('#branchVersion');
}
\ No newline at end of file
diff --git a/sickbeard/gh_api.py b/sickbeard/gh_api.py
index 89ed8b48..6c888c9a 100644
--- a/sickbeard/gh_api.py
+++ b/sickbeard/gh_api.py
@@ -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):
diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py
index f768db4c..341e9519 100644
--- a/sickbeard/webserve.py
+++ b/sickbeard/webserve.py
@@ -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):