diff --git a/js/ctrls/modal.js b/js/ctrls/modal.js index 962f552..41349c7 100644 --- a/js/ctrls/modal.js +++ b/js/ctrls/modal.js @@ -26,11 +26,11 @@ var parseFiles = function(files, cb) { angular .module('webui.ctrls.modal', [ - 'webui.services.deps', 'webui.services.modals' + 'webui.services.deps', 'webui.services.modals', 'webui.services.rpc' ]) .controller('ModalCtrl', [ - '$_', '$scope', '$modals', - function(_, scope, modals) { + '$_', '$scope', '$modals', '$rpc', + function(_, scope, modals, rpc) { scope.getUris = { shown: false, @@ -95,8 +95,12 @@ angular }, init: function(defaults, cb) { + var conf = rpc.getConfiguration(); + if (conf) this.conf = conf; + this.cb = cb; this.open = this.shown = true; + }, success: function() { console.log(this); diff --git a/js/services/rpc/rpc.js b/js/services/rpc/rpc.js index 52c3638..667303e 100644 --- a/js/services/rpc/rpc.js +++ b/js/services/rpc/rpc.js @@ -1,9 +1,10 @@ angular .module('webui.services.rpc', [ - 'webui.services.rpc.syscall', 'webui.services.constants', 'webui.services.alerts' + 'webui.services.rpc.syscall', 'webui.services.constants', 'webui.services.alerts', + 'webui.services.utils' ]) -.factory('$rpc', ['$syscall', '$globalTimeout', '$alerts', -function(syscall, time, alerts) { +.factory('$rpc', ['$syscall', '$globalTimeout', '$alerts', '$utils', +function(syscall, time, alerts, utils) { var subscriptions = [] , configurations = [{ host: 'localhost', port: 6800, encrypt: false }] @@ -11,6 +12,8 @@ function(syscall, time, alerts) { , timeout = null , forceNextUpdate = false; + var cookieConf = utils.getCookie('aria2conf'); + if (cookieConf) configurations.unshift(cookieConf); // update is implemented such that // only one syscall at max is ongoing @@ -52,6 +55,8 @@ function(syscall, time, alerts) { configurations = []; } + utils.setCookie('aria2conf', currentConf); + _.each(data.result, function(d, i) { var handle = subscriptions[i]; if (handle) { @@ -80,7 +85,7 @@ function(syscall, time, alerts) { timeout = setTimeout(update, 0); } else { - alerts.addAlert('Oh Snap! Could not connect to the aria2 server, retrying after ' + time / 1000 + ' secs', 'error'); + alerts.addAlert('Oh Snap! Could not connect to the aria2 server, retrying after ' + time / 1000 + ' secs. You might want to recheck the connection settings for your aria2 server by going to settings > connection settings', 'error'); timeout = setTimeout(update, time); } } @@ -101,7 +106,6 @@ function(syscall, time, alerts) { configurations = conf; else configurations = [conf]; - }, // get current configuration being used diff --git a/js/services/utils.js b/js/services/utils.js index 2d9d587..b87e900 100644 --- a/js/services/utils.js +++ b/js/services/utils.js @@ -1,6 +1,24 @@ angular.module('webui.services.utils', []) .factory('$utils', function() { return { + // saves the key value pair in cookies + setCookie: function(key, value) { + var exdate = new Date(); + exdate.setDate(exdate.getDate() + 30 * 12); + var cvalue = escape(JSON.stringify(value)) + "; expires=" + exdate.toUTCString(); + document.cookie = key + "=" + cvalue; + }, + // gets a value for a key stored in cookies + getCookie: function(key) { + var chunks = document.cookie.split(";"); + for (var i = 0; i < chunks.length; i++) { + var ckey = chunks[i].substr(0, chunks[i].indexOf("=")).replace(/^\s+|\s+$/g,""); + var cvalue = chunks[i].substr(chunks[i].indexOf("=") + 1); + if (key == ckey) { + return JSON.parse(unescape(cvalue)); + } + } + }, getFileName: function(path) { var seed = path.split(/[/\\]/); return seed[seed.length - 1];