add rpc status in sidebar menu
This commit is contained in:
parent
250202811d
commit
874d8a0ad0
|
@ -215,7 +215,7 @@
|
|||
</ul>
|
||||
</li>
|
||||
<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>
|
||||
</ul>
|
||||
</section>
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
};
|
||||
|
||||
$rootScope.taskContext = {
|
||||
rpcStatus: 'Connecting',
|
||||
list: [],
|
||||
selected: {},
|
||||
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) {
|
||||
ariaNgNotificationService.notifyTaskComplete(event.task);
|
||||
});
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
var secret = ariaNgSettingService.getSecret();
|
||||
|
||||
var onFirstSuccessCallbacks = [];
|
||||
var onConnectSuccessCallbacks = [];
|
||||
var onConnectErrorCallbacks = [];
|
||||
var onDownloadStartCallbacks = [];
|
||||
var onDownloadPauseCallbacks = [];
|
||||
var onDownloadStopCallbacks = [];
|
||||
|
@ -65,13 +67,13 @@
|
|||
});
|
||||
};
|
||||
|
||||
var fireFirstSuccessEvent = function () {
|
||||
if (!angular.isArray(onFirstSuccessCallbacks) || onFirstSuccessCallbacks.length < 1) {
|
||||
var fireCustomEvent = function (callbacks) {
|
||||
if (!angular.isArray(callbacks) || callbacks.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < onFirstSuccessCallbacks.length; i++) {
|
||||
var callback = onFirstSuccessCallbacks[i];
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
var callback = callbacks[i];
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
@ -136,11 +138,6 @@
|
|||
var innerContext = arguments[1];
|
||||
|
||||
context.successCallback = function (id, result) {
|
||||
if (!isConnected) {
|
||||
isConnected = true;
|
||||
fireFirstSuccessEvent();
|
||||
}
|
||||
|
||||
if (innerContext.callback) {
|
||||
innerContext.callback({
|
||||
id: id,
|
||||
|
@ -149,6 +146,13 @@
|
|||
context: innerContext
|
||||
});
|
||||
}
|
||||
|
||||
fireCustomEvent(onConnectSuccessCallbacks);
|
||||
|
||||
if (!isConnected) {
|
||||
isConnected = true;
|
||||
fireCustomEvent(onFirstSuccessCallbacks);
|
||||
}
|
||||
};
|
||||
|
||||
context.errorCallback = function (id, error) {
|
||||
|
@ -167,6 +171,8 @@
|
|||
context: innerContext
|
||||
});
|
||||
}
|
||||
|
||||
fireCustomEvent(onConnectErrorCallbacks);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -419,6 +425,12 @@
|
|||
onFirstSuccess: function (context) {
|
||||
onFirstSuccessCallbacks.push(context.callback);
|
||||
},
|
||||
onConnectSuccess: function (context) {
|
||||
onConnectSuccessCallbacks.push(context.callback);
|
||||
},
|
||||
onConnectError: function (context) {
|
||||
onConnectErrorCallbacks.push(context.callback);
|
||||
},
|
||||
onDownloadStart: function (context) {
|
||||
onDownloadStartCallbacks.push(context.callback);
|
||||
},
|
||||
|
|
|
@ -601,6 +601,27 @@
|
|||
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) {
|
||||
if (!callback) {
|
||||
ariaNgLogService.warn('[aria2TaskService.onTaskCompleted] callback is null');
|
||||
|
|
Reference in a new issue