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/angular.js"></script>
|
||||||
|
|
||||||
<script src="js/libs/bootstrap.js"></script>
|
|
||||||
<script src="js/libs/angularui-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/base64.js"></script>
|
||||||
<script src="js/services/utils.js"></script>
|
<script src="js/services/utils.js"></script>
|
||||||
<script src="js/services/modals.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/settings.js"></script>
|
||||||
<script src="js/services/settings/filters.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/modal.js"></script>
|
||||||
<script src="js/ctrls/nav.js"></script>
|
<script src="js/ctrls/nav.js"></script>
|
||||||
<script src="js/ctrls/download.js"></script>
|
<script src="js/ctrls/download.js"></script>
|
||||||
|
<script src="js/ctrls/alert.js"></script>
|
||||||
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
@ -158,9 +159,19 @@
|
||||||
</div>
|
</div>
|
||||||
<!-- }}} -->
|
<!-- }}} -->
|
||||||
|
|
||||||
<!-- {{{ downloads -->
|
|
||||||
<div role="main" class="container" ng-controller="DownloadCtrl">
|
<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">
|
<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>
|
<h3>Currently no downloads in line to display, use the Add download button to start downloading files!</h3>
|
||||||
</div>
|
</div>
|
||||||
|
@ -295,9 +306,10 @@
|
||||||
</table>
|
</table>
|
||||||
<!-- }}} -->
|
<!-- }}} -->
|
||||||
|
|
||||||
</div>
|
|
||||||
<!-- }}} -->
|
<!-- }}} -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- {{{ modals -->
|
<!-- {{{ modals -->
|
||||||
<div ng-controller="ModalCtrl">
|
<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
|
angular
|
||||||
.module('webui.ctrls.download', [
|
.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',
|
.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils', '$settings', '$alerts',
|
||||||
function(scope, rpc, utils, sett) {
|
function(scope, rpc, utils, sett, alerts) {
|
||||||
console.log(sett);
|
console.log(sett);
|
||||||
scope.active = [], scope.waiting = [], scope.stopped = [];
|
scope.active = [], scope.waiting = [], scope.stopped = [];
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
angular.module('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.modals',
|
'webui.services.constants', 'webui.services.rpc',
|
||||||
|
'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.download', 'webui.ctrls.nav', 'webui.ctrls.modal', 'webui.ctrls.alert'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
angular.bootstrap(document, [
|
angular.bootstrap(document, [
|
||||||
// external deps
|
// external deps
|
||||||
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
||||||
'ui.bootstrap.modal',
|
'ui.bootstrap.modal', 'ui.bootstrap.alert',
|
||||||
'webui'
|
'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
|
angular
|
||||||
.module('webui.services.rpc', [
|
.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 = []
|
var subscriptions = []
|
||||||
, configurations = [{ host: 'localhost', port: 6800 }]
|
, configurations = [{ host: 'localhost', port: 6800 }]
|
||||||
, timeout = null
|
, timeout = null
|
||||||
|
@ -28,6 +28,10 @@ angular
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = null;
|
||||||
|
|
||||||
syscall.invoke({
|
syscall.invoke({
|
||||||
name: 'system.multicall',
|
name: 'system.multicall',
|
||||||
params: [params],
|
params: [params],
|
||||||
|
@ -54,7 +58,7 @@ angular
|
||||||
// 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) update();
|
if (configurations.length) update();
|
||||||
else {
|
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);
|
timeout = setTimeout(update, time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,13 +123,14 @@ 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 = null;
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (subscriptions.length) {
|
else if (configurations.length) update();
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user