improvements the angular rpc system
This commit is contained in:
parent
3e89b06f17
commit
32b25f29b4
@ -71,7 +71,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<!-- }}} -->
|
<!-- }}} -->
|
||||||
|
|
||||||
<body>
|
<body ng-app="webui">
|
||||||
|
|
||||||
<!-- {{{ header -->
|
<!-- {{{ header -->
|
||||||
<div class="navbar navbar-inverse navbar-fixed-top" ng-controller="NavCtrl">
|
<div class="navbar navbar-inverse navbar-fixed-top" ng-controller="NavCtrl">
|
||||||
@ -151,7 +151,7 @@
|
|||||||
class="dropdown-toggle">Settings <b class="caret"></b></a>
|
class="dropdown-toggle">Settings <b class="caret"></b></a>
|
||||||
|
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li ng-show="false">
|
<li>
|
||||||
<a
|
<a
|
||||||
ng-click="changeCSettings()"
|
ng-click="changeCSettings()"
|
||||||
href="#"><i class="icon-wrench"></i> Connection Settings</a>
|
href="#"><i class="icon-wrench"></i> Connection Settings</a>
|
||||||
@ -446,7 +446,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr ng-click="download.collapsed = !download.collapsed" class="download-detail">
|
<tr ng-click="download.collapsed = !download.collapsed" class="download-detail">
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<div class="more_info" collapse="download.collapsed">
|
<div collapse="download.collapsed">
|
||||||
<canvas bitfield="download.bitfield" draw="!download.collapsed" pieces="download.numPieces" class="progress chunk-canvas" width="1400" style="width: 100%; margin: 5px;" chunkbar></canvas>
|
<canvas bitfield="download.bitfield" draw="!download.collapsed" pieces="download.numPieces" class="progress chunk-canvas" width="1400" style="width: 100%; margin: 5px;" chunkbar></canvas>
|
||||||
<ul class="stats">
|
<ul class="stats">
|
||||||
<li class="label">Status: <span class="download-status">{{download.status}}</span></li>
|
<li class="label">Status: <span class="download-status">{{download.status}}</span></li>
|
||||||
|
@ -13,10 +13,12 @@ angular.module('webui.ctrls.alert', [
|
|||||||
var obj = { msg: msg, type: type };
|
var obj = { msg: msg, type: type };
|
||||||
scope.pendingAlerts.push(obj);
|
scope.pendingAlerts.push(obj);
|
||||||
|
|
||||||
|
/*
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var ind = scope.pendingAlerts.indexOf(obj);
|
var ind = scope.pendingAlerts.indexOf(obj);
|
||||||
if (ind != -1) scope.removeAlert(ind);
|
if (ind != -1) scope.removeAlert(ind);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
*/
|
||||||
|
|
||||||
scope.$digest();
|
scope.$digest();
|
||||||
});
|
});
|
||||||
|
@ -66,7 +66,6 @@ angular
|
|||||||
// if any parents is collapsable, then confirm if it isnt
|
// if any parents is collapsable, then confirm if it isnt
|
||||||
if (canDraw)
|
if (canDraw)
|
||||||
draw();
|
draw();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
scope.$watch(attrs.dspeed, function(val) {
|
scope.$watch(attrs.dspeed, function(val) {
|
||||||
|
16
js/init.js
16
js/init.js
@ -1,18 +1,18 @@
|
|||||||
angular.module('webui', [
|
var webui = angular.module('webui', [
|
||||||
'webui.services.utils', 'webui.services.deps', 'webui.services.base64',
|
'webui.services.utils', 'webui.services.deps', 'webui.services.base64',
|
||||||
'webui.services.constants', 'webui.services.rpc',
|
'webui.services.constants', 'webui.services.rpc',
|
||||||
'webui.services.modals', 'webui.services.alerts',
|
'webui.services.modals', 'webui.services.alerts',
|
||||||
'webui.services.settings', 'webui.services.settings.filters',
|
'webui.services.settings', 'webui.services.settings.filters',
|
||||||
'webui.filters.bytes', 'webui.filters.path',
|
'webui.filters.bytes', 'webui.filters.path',
|
||||||
'webui.directives.chunkbar', 'webui.directives.dgraph', 'webui.directives.fselect',
|
'webui.directives.chunkbar', 'webui.directives.dgraph', 'webui.directives.fselect',
|
||||||
'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal', 'webui.ctrls.alert'
|
'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal', 'webui.ctrls.alert',
|
||||||
|
// external deps
|
||||||
|
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
||||||
|
'ui.bootstrap.modal', 'ui.bootstrap.alert'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/*
|
||||||
$(function() {
|
$(function() {
|
||||||
angular.bootstrap(document, [
|
angular.bootstrap(document, ['webui'])
|
||||||
// external deps
|
|
||||||
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
|
||||||
'ui.bootstrap.modal', 'ui.bootstrap.alert',
|
|
||||||
'webui'
|
|
||||||
])
|
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
@ -12,6 +12,10 @@ angular.module('webui.services.alerts', ['webui.services.deps'])
|
|||||||
},
|
},
|
||||||
addAlerter: function(cb) {
|
addAlerter: function(cb) {
|
||||||
alerters.push(cb);
|
alerters.push(cb);
|
||||||
|
},
|
||||||
|
// a simple function for debugging
|
||||||
|
log: function(msg) {
|
||||||
|
this.addAlert(msg, 'info');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
angular
|
angular
|
||||||
.module('webui.services.rpc', [
|
.module('webui.services.rpc', [
|
||||||
'webui.services.rpc.syscall', 'webui.services.constants', 'webui.services.alerts'
|
'webui.services.rpc.syscall', 'webui.services.constants', 'webui.services.alerts'
|
||||||
])
|
])
|
||||||
.factory('$rpc', ['$syscall', '$globalTimeout', '$alerts', function(syscall, time, alerts) {
|
.factory('$rpc', ['$syscall', '$globalTimeout', '$alerts',
|
||||||
|
function(syscall, time, alerts) {
|
||||||
|
|
||||||
var subscriptions = []
|
var subscriptions = []
|
||||||
, configurations = [{ host: 'localhost', port: 6800 }]
|
, configurations = [{ host: 'localhost', port: 6800 }]
|
||||||
|
, currentConf = {}
|
||||||
, timeout = null
|
, timeout = null
|
||||||
, forceNextUpdate = false;
|
, forceNextUpdate = false;
|
||||||
|
|
||||||
@ -14,11 +17,19 @@ angular
|
|||||||
// (i.e. serially) so should be private
|
// (i.e. serially) so should be private
|
||||||
// to maintain that invariant
|
// to maintain that invariant
|
||||||
var update = function() {
|
var update = function() {
|
||||||
if (!subscriptions.length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (configurations.length)
|
clearTimeout(timeout);
|
||||||
syscall.init(configurations[0]);
|
timeout = null;
|
||||||
|
|
||||||
|
if (!subscriptions.length) {
|
||||||
|
timeout = setTimeout(update, time);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configurations.length) {
|
||||||
|
currentConf = configurations.shift();
|
||||||
|
syscall.init(currentConf);
|
||||||
|
}
|
||||||
|
|
||||||
subscriptions = _.filter(subscriptions, function(e) { return !!e });
|
subscriptions = _.filter(subscriptions, function(e) { return !!e });
|
||||||
var params = _.map(subscriptions, function(s) {
|
var params = _.map(subscriptions, function(s) {
|
||||||
@ -29,16 +40,19 @@ angular
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
clearTimeout(timeout);
|
|
||||||
timeout = null;
|
|
||||||
|
|
||||||
syscall.invoke({
|
syscall.invoke({
|
||||||
name: 'system.multicall',
|
name: 'system.multicall',
|
||||||
params: [params],
|
params: [params],
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
|
||||||
// configuration worked, save it in cookie for next time!!
|
if (configurations.length) {
|
||||||
//
|
// configuration worked, save it in cookie for next time and
|
||||||
|
// delete the pipelined configurations!!
|
||||||
|
alerts.log('success alas!! saving current configuration');
|
||||||
|
configurations = [];
|
||||||
|
}
|
||||||
|
|
||||||
_.each(data.result, function(d, i) {
|
_.each(data.result, function(d, i) {
|
||||||
var handle = subscriptions[i];
|
var handle = subscriptions[i];
|
||||||
if (handle) {
|
if (handle) {
|
||||||
@ -54,15 +68,17 @@ angular
|
|||||||
|
|
||||||
if (forceNextUpdate) {
|
if (forceNextUpdate) {
|
||||||
forceNextUpdate = false;
|
forceNextUpdate = false;
|
||||||
return update();
|
timeout = setTimeout(update, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timeout = setTimeout(update, time);
|
||||||
}
|
}
|
||||||
timeout = setTimeout(update, time);
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
// If some proposed configurations are still in the pipeline then retry
|
// If some proposed configurations are still in the pipeline then retry
|
||||||
if (configurations.length) {
|
if (configurations.length) {
|
||||||
configurations.shift();
|
alerts.log('trying another configuration, last one didnt connect');
|
||||||
update();
|
timeout = setTimeout(update, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alerts.addAlert('<strong>Oh Snap!</strong> Could not connect to the aria2 server, retrying after ' + time / 1000 + ' secs', 'error');
|
alerts.addAlert('<strong>Oh Snap!</strong> Could not connect to the aria2 server, retrying after ' + time / 1000 + ' secs', 'error');
|
||||||
@ -70,7 +86,11 @@ angular
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// initiate the update loop
|
||||||
|
timeout = setTimeout(update, time);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// conf can be configuration or array of configurations,
|
// conf can be configuration or array of configurations,
|
||||||
// each one will be tried one after the other till success,
|
// each one will be tried one after the other till success,
|
||||||
@ -130,14 +150,9 @@ angular
|
|||||||
// force the global syscall update
|
// force the global syscall update
|
||||||
forceUpdate: function() {
|
forceUpdate: function() {
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = null;
|
timeout = setTimeout(update, 0);
|
||||||
|
|
||||||
update();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (configurations.length) update();
|
|
||||||
else {
|
else {
|
||||||
// a batch call is already in progress,
|
// a batch call is already in progress,
|
||||||
// wait till it returns and force the next one
|
// wait till it returns and force the next one
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
angular
|
angular
|
||||||
.module('webui.services.rpc.sockcall', [
|
.module('webui.services.rpc.sockcall', [
|
||||||
'webui.services.deps', 'webui.services.utils', 'webui.services.base64'
|
'webui.services.deps', 'webui.services.utils', 'webui.services.base64',
|
||||||
])
|
'webui.services.alerts'
|
||||||
.factory('$sockcall', ['$_', '$json', '$name', '$utils', function(_, JSON, name, utils) {
|
])
|
||||||
|
.factory('$sockcall', ['$_', '$json', '$name', '$utils', '$alerts',
|
||||||
|
function(_, JSON, name, utils, alerts) {
|
||||||
var sockRPC = {
|
var sockRPC = {
|
||||||
// true when sockrpc is ready to be used,
|
// true when sockrpc is ready to be used,
|
||||||
// false when either initializing
|
// false when either initializing
|
||||||
@ -70,11 +71,13 @@ angular
|
|||||||
|
|
||||||
// should be called initially to start using the sock rpc
|
// should be called initially to start using the sock rpc
|
||||||
init: function(conf) {
|
init: function(conf) {
|
||||||
|
sockRPC.initialized = false;
|
||||||
|
|
||||||
if (typeof WebSocket == "undefined") {
|
if (typeof WebSocket == "undefined") {
|
||||||
|
alerts.addAlert('Web sockets not supported, falling back to jsonp', 'info');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sockRPC.conf = conf || sockRPC.conf;
|
sockRPC.conf = conf || sockRPC.conf;
|
||||||
sockRPC.initialized = false;
|
|
||||||
|
|
||||||
sockRPC.scheme = sockRPC.conf.encryption ? 'wss' : 'ws';
|
sockRPC.scheme = sockRPC.conf.encryption ? 'wss' : 'ws';
|
||||||
|
|
||||||
@ -92,6 +95,7 @@ angular
|
|||||||
catch (ex) {
|
catch (ex) {
|
||||||
// ignoring IE securty exception on local ip addresses
|
// ignoring IE securty exception on local ip addresses
|
||||||
console.log('not using websocket for aria2 rpc due to: ', ex);
|
console.log('not using websocket for aria2 rpc due to: ', ex);
|
||||||
|
alerts.addAlert('Web sockets not working due to ' + ex.message, 'info');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
angular
|
angular
|
||||||
.module('webui.services.rpc.syscall', [
|
.module('webui.services.rpc.syscall', [
|
||||||
'webui.services.rpc.jsoncall', 'webui.services.rpc.sockcall',
|
'webui.services.rpc.jsoncall', 'webui.services.rpc.sockcall',
|
||||||
'webui.services.utils'
|
'webui.services.utils', 'webui.services.alerts'
|
||||||
])
|
])
|
||||||
.factory('$syscall', ['$log', '$jsoncall', '$sockcall', function(log, jsonRPC, sockRPC) {
|
.factory('$syscall', ['$log', '$jsoncall', '$sockcall', '$alerts',
|
||||||
|
function(log, jsonRPC, sockRPC, alerts) {
|
||||||
return {
|
return {
|
||||||
// called to initialize the rpc interface, call everytime configuration changes
|
// called to initialize the rpc interface, call everytime configuration changes
|
||||||
// conf has the following structure:
|
// conf has the following structure:
|
||||||
@ -16,6 +17,7 @@ angular
|
|||||||
// pass (string): password for the http authentication if enabled
|
// pass (string): password for the http authentication if enabled
|
||||||
// }
|
// }
|
||||||
init: function(conf) {
|
init: function(conf) {
|
||||||
|
|
||||||
conf = conf || {
|
conf = conf || {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 6800
|
port: 6800
|
||||||
|
Loading…
x
Reference in New Issue
Block a user