add rpc status in sidebar menu

This commit is contained in:
MaysWind 2017-03-19 17:39:38 +08:00
parent 250202811d
commit 874d8a0ad0
4 changed files with 52 additions and 10 deletions

View file

@ -215,7 +215,7 @@
</ul> </ul>
</li> </li>
<li data-href-match="/status"> <li data-href-match="/status">
<a href="#/status"><i class="fa fa-server"></i> <span translate>Aria2 Status</span></a> <a href="#/status"><i class="fa fa-server"></i> <span translate>Aria2 Status</span> <span class="label pull-right" ng-if="globalStatusContext.isEnabled" ng-class="{'label-primary': taskContext.rpcStatus === 'Connecting', 'label-success': taskContext.rpcStatus === 'Connected', 'label-danger': taskContext.rpcStatus === 'Not Connected'}" ng-bind="taskContext.rpcStatus | translate"></span></a>
</li> </li>
</ul> </ul>
</section> </section>

View file

@ -70,6 +70,7 @@
}; };
$rootScope.taskContext = { $rootScope.taskContext = {
rpcStatus: 'Connecting',
list: [], list: [],
selected: {}, selected: {},
enableSelectAll: false, enableSelectAll: false,
@ -169,6 +170,14 @@
}); });
}); });
aria2TaskService.onConnectSuccess(function () {
$rootScope.taskContext.rpcStatus = 'Connected';
});
aria2TaskService.onConnectError(function () {
$rootScope.taskContext.rpcStatus = 'Not Connected';
});
aria2TaskService.onTaskCompleted(function (event) { aria2TaskService.onTaskCompleted(function (event) {
ariaNgNotificationService.notifyTaskComplete(event.task); ariaNgNotificationService.notifyTaskComplete(event.task);
}); });

View file

@ -7,6 +7,8 @@
var secret = ariaNgSettingService.getSecret(); var secret = ariaNgSettingService.getSecret();
var onFirstSuccessCallbacks = []; var onFirstSuccessCallbacks = [];
var onConnectSuccessCallbacks = [];
var onConnectErrorCallbacks = [];
var onDownloadStartCallbacks = []; var onDownloadStartCallbacks = [];
var onDownloadPauseCallbacks = []; var onDownloadPauseCallbacks = [];
var onDownloadStopCallbacks = []; var onDownloadStopCallbacks = [];
@ -65,13 +67,13 @@
}); });
}; };
var fireFirstSuccessEvent = function () { var fireCustomEvent = function (callbacks) {
if (!angular.isArray(onFirstSuccessCallbacks) || onFirstSuccessCallbacks.length < 1) { if (!angular.isArray(callbacks) || callbacks.length < 1) {
return; return;
} }
for (var i = 0; i < onFirstSuccessCallbacks.length; i++) { for (var i = 0; i < callbacks.length; i++) {
var callback = onFirstSuccessCallbacks[i]; var callback = callbacks[i];
callback(); callback();
} }
}; };
@ -136,11 +138,6 @@
var innerContext = arguments[1]; var innerContext = arguments[1];
context.successCallback = function (id, result) { context.successCallback = function (id, result) {
if (!isConnected) {
isConnected = true;
fireFirstSuccessEvent();
}
if (innerContext.callback) { if (innerContext.callback) {
innerContext.callback({ innerContext.callback({
id: id, id: id,
@ -149,6 +146,13 @@
context: innerContext context: innerContext
}); });
} }
fireCustomEvent(onConnectSuccessCallbacks);
if (!isConnected) {
isConnected = true;
fireCustomEvent(onFirstSuccessCallbacks);
}
}; };
context.errorCallback = function (id, error) { context.errorCallback = function (id, error) {
@ -167,6 +171,8 @@
context: innerContext context: innerContext
}); });
} }
fireCustomEvent(onConnectErrorCallbacks);
}; };
} }
@ -419,6 +425,12 @@
onFirstSuccess: function (context) { onFirstSuccess: function (context) {
onFirstSuccessCallbacks.push(context.callback); onFirstSuccessCallbacks.push(context.callback);
}, },
onConnectSuccess: function (context) {
onConnectSuccessCallbacks.push(context.callback);
},
onConnectError: function (context) {
onConnectErrorCallbacks.push(context.callback);
},
onDownloadStart: function (context) { onDownloadStart: function (context) {
onDownloadStartCallbacks.push(context.callback); onDownloadStartCallbacks.push(context.callback);
}, },

View file

@ -601,6 +601,27 @@
callback: callback callback: callback
}); });
}, },
onConnectSuccess: function (callback) {
if (!callback) {
ariaNgLogService.warn('[aria2TaskService.onConnectSuccess] callback is null');
return;
}
aria2RpcService.onConnectSuccess({
callback: callback
});
},
onConnectError: function (callback) {
if (!callback) {
ariaNgLogService.warn('[aria2TaskService.onConnectError] callback is null');
return;
}
aria2RpcService.onConnectError({
callback: callback
});
},
onTaskCompleted: function (callback) { onTaskCompleted: function (callback) {
if (!callback) { if (!callback) {
ariaNgLogService.warn('[aria2TaskService.onTaskCompleted] callback is null'); ariaNgLogService.warn('[aria2TaskService.onTaskCompleted] callback is null');