added alerts servive and perf improvements in angular
This commit is contained in:
parent
30ae20260f
commit
bff6694f05
18
angular.html
18
angular.html
|
@ -25,7 +25,6 @@
|
|||
|
||||
<script src="js/libs/angular.js"></script>
|
||||
|
||||
<script src="js/libs/bootstrap.js"></script>
|
||||
<script src="js/libs/angularui-bootstrap.js"></script>
|
||||
|
||||
|
||||
|
@ -49,6 +48,7 @@
|
|||
<script src="js/services/base64.js"></script>
|
||||
<script src="js/services/utils.js"></script>
|
||||
<script src="js/services/modals.js"></script>
|
||||
<script src="js/services/alerts.js"></script>
|
||||
|
||||
<script src="js/services/settings/settings.js"></script>
|
||||
<script src="js/services/settings/filters.js"></script>
|
||||
|
@ -63,6 +63,7 @@
|
|||
<script src="js/ctrls/modal.js"></script>
|
||||
<script src="js/ctrls/nav.js"></script>
|
||||
<script src="js/ctrls/download.js"></script>
|
||||
<script src="js/ctrls/alert.js"></script>
|
||||
|
||||
|
||||
</head>
|
||||
|
@ -158,9 +159,19 @@
|
|||
</div>
|
||||
<!-- }}} -->
|
||||
|
||||
<!-- {{{ downloads -->
|
||||
|
||||
<div role="main" class="container" ng-controller="DownloadCtrl">
|
||||
|
||||
<!-- {{{ alerts -->
|
||||
<div ng-controller="AlertCtrl">
|
||||
<div class="alert alert-{{alert.type}}" ng-repeat="alert in pendingAlerts">
|
||||
<span ng-bind-html-unsafe="alert.msg"></span>
|
||||
<button type="button" class="close" ng-click="removeAlert($index)">x</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- }}} -->
|
||||
|
||||
<!-- {{{ downloads -->
|
||||
<div ng-show="!getDownloads().length" class="hero-unit">
|
||||
<h3>Currently no downloads in line to display, use the Add download button to start downloading files!</h3>
|
||||
</div>
|
||||
|
@ -295,8 +306,9 @@
|
|||
</table>
|
||||
<!-- }}} -->
|
||||
|
||||
<!-- }}} -->
|
||||
|
||||
</div>
|
||||
<!-- }}} -->
|
||||
|
||||
<!-- {{{ modals -->
|
||||
<div ng-controller="ModalCtrl">
|
||||
|
|
18
js/ctrls/alert.js
Normal file
18
js/ctrls/alert.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
angular.module('webui.ctrls.alert', [
|
||||
'webui.services.alerts'
|
||||
])
|
||||
.controller('AlertCtrl', ['$scope', '$alerts', function(scope, alerts) {
|
||||
scope.pendingAlerts = [];
|
||||
|
||||
scope.removeAlert = function(ind) {
|
||||
this.pendingAlerts.splice(ind, 1);
|
||||
};
|
||||
|
||||
alerts.addAlerter(function(msg, type) {
|
||||
type = type || 'warning';
|
||||
scope.pendingAlerts.push({ msg: msg, type: type });
|
||||
scope.$digest();
|
||||
});
|
||||
|
||||
|
||||
}]);
|
|
@ -1,9 +1,10 @@
|
|||
angular
|
||||
.module('webui.ctrls.download', [
|
||||
'webui.services.utils', 'webui.services.rpc', 'webui.services.settings'
|
||||
'webui.services.utils', 'webui.services.rpc', 'webui.services.settings',
|
||||
'webui.services.alerts'
|
||||
])
|
||||
.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils', '$settings',
|
||||
function(scope, rpc, utils, sett) {
|
||||
.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils', '$settings', '$alerts',
|
||||
function(scope, rpc, utils, sett, alerts) {
|
||||
console.log(sett);
|
||||
scope.active = [], scope.waiting = [], scope.stopped = [];
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
angular.module('webui', [
|
||||
'webui.services.utils', 'webui.services.deps', 'webui.services.base64',
|
||||
'webui.services.constants', 'webui.services.rpc', 'webui.services.modals',
|
||||
'webui.services.constants', 'webui.services.rpc',
|
||||
'webui.services.modals', 'webui.services.alerts',
|
||||
'webui.services.settings', 'webui.services.settings.filters',
|
||||
'webui.filters.bytes', 'webui.filters.path',
|
||||
'webui.directives.chunkbar', 'webui.directives.dgraph', 'webui.directives.fselect',
|
||||
'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal'
|
||||
'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal', 'webui.ctrls.alert'
|
||||
]);
|
||||
|
||||
$(function() {
|
||||
angular.bootstrap(document, [
|
||||
// external deps
|
||||
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
||||
'ui.bootstrap.modal',
|
||||
'ui.bootstrap.modal', 'ui.bootstrap.alert',
|
||||
'webui'
|
||||
])
|
||||
});
|
||||
|
|
17
js/services/alerts.js
Normal file
17
js/services/alerts.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
angular.module('webui.services.alerts', ['webui.services.deps'])
|
||||
.factory('$alerts', ['$_', function(_) {
|
||||
var alerters = [];
|
||||
return {
|
||||
addAlert: function() {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
setTimeout(function() {
|
||||
_.each(alerters, function(alt) {
|
||||
alt.apply({}, args);
|
||||
});
|
||||
}, 0);
|
||||
},
|
||||
addAlerter: function(cb) {
|
||||
alerters.push(cb);
|
||||
}
|
||||
};
|
||||
}]);
|
|
@ -1,8 +1,8 @@
|
|||
angular
|
||||
.module('webui.services.rpc', [
|
||||
'webui.services.rpc.syscall', 'webui.services.constants'
|
||||
'webui.services.rpc.syscall', 'webui.services.constants', 'webui.services.alerts'
|
||||
])
|
||||
.factory('$rpc', ['$syscall', '$globalTimeout', function(syscall, time) {
|
||||
.factory('$rpc', ['$syscall', '$globalTimeout', '$alerts', function(syscall, time, alerts) {
|
||||
var subscriptions = []
|
||||
, configurations = [{ host: 'localhost', port: 6800 }]
|
||||
, timeout = null
|
||||
|
@ -28,6 +28,10 @@ angular
|
|||
};
|
||||
});
|
||||
|
||||
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
|
||||
syscall.invoke({
|
||||
name: 'system.multicall',
|
||||
params: [params],
|
||||
|
@ -54,7 +58,7 @@ angular
|
|||
// If some proposed configurations are still in the pipeline then retry
|
||||
if (configurations.length) update();
|
||||
else {
|
||||
console.log('cannot connect!!!');
|
||||
alerts.addAlert('<strong>Oh Snap!</strong> Could not connect to the aria2 server, retrying after ' + time / 1000 + ' secs', 'error');
|
||||
timeout = setTimeout(update, time);
|
||||
}
|
||||
}
|
||||
|
@ -119,13 +123,14 @@ angular
|
|||
// force the global syscall update
|
||||
forceUpdate: function() {
|
||||
if (timeout) {
|
||||
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
|
||||
update();
|
||||
|
||||
}
|
||||
else if (subscriptions.length) {
|
||||
update();
|
||||
}
|
||||
else if (configurations.length) update();
|
||||
else {
|
||||
// a batch call is already in progress,
|
||||
// wait till it returns and force the next one
|
||||
|
|
Loading…
Reference in New Issue
Block a user