code refactor

This commit is contained in:
MaysWind 2018-08-12 20:26:26 +08:00
parent 0c678a18eb
commit 0a5b049bfd
21 changed files with 179 additions and 108 deletions

View file

@ -394,6 +394,7 @@
<script src="scripts/services/ariaNgSettingService.js"></script>
<script src="scripts/services/ariaNgTitleService.js"></script>
<script src="scripts/services/ariaNgLogService.js"></script>
<script src="scripts/services/ariaNgLocalizationService.js"></script>
<script src="scripts/services/aria2HttpRpcService.js"></script>
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
<script src="scripts/services/aria2RpcService.js"></script>

View file

@ -1,13 +1,13 @@
(function () {
'use strict';
angular.module('ariaNg').run(['moment', 'ariaNgSettingService', function (moment, ariaNgSettingService) {
angular.module('ariaNg').run(['moment', 'ariaNgLocalizationService', 'ariaNgSettingService', function (moment, ariaNgLocalizationService, ariaNgSettingService) {
var language = ariaNgSettingService.getLanguage();
moment.updateLocale('zh-cn', {
week: null
});
ariaNgSettingService.applyLanguage(language);
ariaNgLocalizationService.applyLanguage(language);
}]);
}());

View file

@ -1,14 +1,14 @@
(function () {
'use strict';
angular.module('ariaNg').controller('CommandController', ['$rootScope', '$window', '$location', '$routeParams', 'ariaNgDefaultOptions', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2SettingService', 'aria2TaskService', 'ariaNgLogService', function ($rootScope, $window, $location, $routeParams, ariaNgDefaultOptions, ariaNgCommonService, ariaNgSettingService, aria2SettingService, aria2TaskService, ariaNgLogService) {
angular.module('ariaNg').controller('CommandController', ['$rootScope', '$window', '$location', '$routeParams', 'ariaNgDefaultOptions', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $window, $location, $routeParams, ariaNgDefaultOptions, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService, aria2SettingService) {
var path = $location.path();
var doNewTaskCommand = function (url, params) {
try {
url = ariaNgCommonService.base64UrlDecode(url);
} catch (ex) {
ariaNgCommonService.showError('URL is not base64 encoded!');
ariaNgLocalizationService.showError('URL is not base64 encoded!');
return false;
}
@ -59,12 +59,12 @@
ariaNgLogService.info('[CommandController] set rpc: ' + rpcProtocol + '://' + rpcHost + ':' + rpcPort + '/' + rpcInterface + ', secret: ' + secret);
if (!rpcProtocol || (rpcProtocol !== 'http' && rpcProtocol !== 'https' && rpcProtocol !== 'ws' && rpcProtocol !== 'wss')) {
ariaNgCommonService.showError('Protocol is invalid!');
ariaNgLocalizationService.showError('Protocol is invalid!');
return false;
}
if (!rpcHost) {
ariaNgCommonService.showError('RPC host cannot be empty!');
ariaNgLocalizationService.showError('RPC host cannot be empty!');
return false;
}
@ -72,7 +72,7 @@
try {
secret = ariaNgCommonService.base64UrlDecode(secret);
} catch (ex) {
ariaNgCommonService.showError('RPC secret is not base64 encoded!');
ariaNgLocalizationService.showError('RPC secret is not base64 encoded!');
return false;
}
}
@ -108,7 +108,7 @@
} else if (path.indexOf('/settings/rpc/set') === 0) {
return doSetRpcCommand(params.protocol, params.host, params.port, params.interface, params.secret);
} else {
ariaNgCommonService.showError('Parameter is invalid!');
ariaNgLocalizationService.showError('Parameter is invalid!');
return false;
}
};

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').controller('AriaNgDebugController', ['$rootScope', '$scope', '$location', '$timeout', 'ariaNgConstants', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgLogService', function ($rootScope, $scope, $location, $timeout, ariaNgConstants, ariaNgCommonService, ariaNgSettingService, ariaNgLogService) {
angular.module('ariaNg').controller('AriaNgDebugController', ['$rootScope', '$scope', '$location', '$timeout', 'ariaNgConstants', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', function ($rootScope, $scope, $location, $timeout, ariaNgConstants, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService) {
$scope.logMaxCount = ariaNgConstants.cachedDebugLogsLimit;
$scope.currentLog = null;
@ -24,7 +24,7 @@
$rootScope.loadPromise = $timeout(function () {
if (!ariaNgSettingService.isEnableDebugMode()) {
ariaNgCommonService.showError('Access Denied!', function () {
ariaNgLocalizationService.showError('Access Denied!', function () {
if (!ariaNgSettingService.isEnableDebugMode()) {
$location.path('/settings/ariang');
}

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$window', '$location', '$document', '$interval', 'clipboard', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgTitleService', 'ariaNgMonitorService', 'ariaNgNotificationService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $window, $location, $document, $interval, clipboard, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, ariaNgTitleService, ariaNgMonitorService, ariaNgNotificationService, aria2TaskService, aria2SettingService) {
angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$window', '$location', '$document', '$interval', 'clipboard', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgNotificationService', 'ariaNgLocalizationService', 'ariaNgSettingService', 'ariaNgMonitorService', 'ariaNgTitleService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $window, $location, $document, $interval, clipboard, aria2RpcErrors, ariaNgCommonService, ariaNgNotificationService, ariaNgLocalizationService, ariaNgSettingService, ariaNgMonitorService, ariaNgTitleService, aria2TaskService, aria2SettingService) {
var pageTitleRefreshPromise = null;
var globalStatRefreshPromise = null;
@ -113,7 +113,7 @@
$rootScope.loadPromise = invoke(gids, function (response) {
if (response.hasError && gids.length > 1) {
ariaNgCommonService.showError('Failed to change some tasks state.');
ariaNgLocalizationService.showError('Failed to change some tasks state.');
}
if (!response.hasSuccess) {
@ -139,10 +139,10 @@
};
$scope.restart = function (task) {
ariaNgCommonService.confirm('Confirm Restart', 'Are you sure you want to restart this task? AriaNg will create a same task after clicking OK.', 'info', function () {
ariaNgLocalizationService.confirm('Confirm Restart', 'Are you sure you want to restart this task? AriaNg will create a same task after clicking OK.', 'info', function () {
$rootScope.loadPromise = aria2TaskService.restartTask(task.gid, function (response) {
if (!response.success) {
ariaNgCommonService.showError('Failed to restart this task.');
ariaNgLocalizationService.showError('Failed to restart this task.');
return;
}
@ -166,10 +166,10 @@
return;
}
ariaNgCommonService.confirm('Confirm Remove', 'Are you sure you want to remove the selected task?', 'warning', function () {
ariaNgLocalizationService.confirm('Confirm Remove', 'Are you sure you want to remove the selected task?', 'warning', function () {
$rootScope.loadPromise = aria2TaskService.removeTasks(tasks, function (response) {
if (response.hasError && tasks.length > 1) {
ariaNgCommonService.showError('Failed to remove some task(s).');
ariaNgLocalizationService.showError('Failed to remove some task(s).');
}
if (!response.hasSuccess) {
@ -190,7 +190,7 @@
};
$scope.clearStoppedTasks = function () {
ariaNgCommonService.confirm('Confirm Clear', 'Are you sure you want to clear stopped tasks?', 'warning', function () {
ariaNgLocalizationService.confirm('Confirm Clear', 'Are you sure you want to clear stopped tasks?', 'warning', function () {
$rootScope.loadPromise = aria2TaskService.clearStoppedTasks(function (response) {
if (!response.success) {
return;

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'ariaNgCommonService', 'ariaNgLogService', 'ariaNgSettingService', 'ariaNgFileService', 'aria2SettingService', 'aria2TaskService', function ($rootScope, $scope, $location, $timeout, ariaNgCommonService, ariaNgLogService, ariaNgSettingService, ariaNgFileService, aria2SettingService, aria2TaskService) {
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgFileService', 'ariaNgSettingService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $location, $timeout, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgFileService, ariaNgSettingService, aria2TaskService, aria2SettingService) {
var tabOrders = ['links', 'options'];
var parameters = $location.search();
@ -133,7 +133,7 @@
$scope.context.taskType = 'torrent';
$scope.changeTab('options');
}, function (error) {
ariaNgCommonService.showError(error);
ariaNgLocalizationService.showError(error);
}, angular.element('#file-holder'));
};
@ -143,7 +143,7 @@
$scope.context.taskType = 'metalink';
$scope.changeTab('options');
}, function (error) {
ariaNgCommonService.showError(error);
ariaNgLocalizationService.showError(error);
}, angular.element('#file-holder'));
};

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').controller('Aria2SettingsController', ['$rootScope', '$scope', '$location', 'ariaNgConstants', 'ariaNgCommonService', 'aria2SettingService', function ($rootScope, $scope, $location, ariaNgConstants, ariaNgCommonService, aria2SettingService) {
angular.module('ariaNg').controller('Aria2SettingsController', ['$rootScope', '$scope', '$location', 'ariaNgConstants', 'ariaNgLocalizationService', 'aria2SettingService', function ($rootScope, $scope, $location, ariaNgConstants, ariaNgLocalizationService, aria2SettingService) {
var location = $location.path().substring($location.path().lastIndexOf('/') + 1);
$scope.context = {
@ -9,7 +9,7 @@
var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type);
if (!keys) {
ariaNgCommonService.showError('Type is illegal!');
ariaNgLocalizationService.showError('Type is illegal!');
return;
}

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$routeParams', '$window', '$interval', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'aria2SettingService', 'ariaNgSettingService', 'ariaNgMonitorService', 'ariaNgNotificationService', 'ariaNgTitleService', function ($rootScope, $scope, $routeParams, $window, $interval, $timeout, ariaNgLanguages, ariaNgCommonService, aria2SettingService, ariaNgSettingService, ariaNgMonitorService, ariaNgNotificationService, ariaNgTitleService) {
angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$routeParams', '$window', '$interval', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgNotificationService', 'ariaNgLocalizationService', 'ariaNgSettingService', 'ariaNgMonitorService', 'ariaNgTitleService', 'aria2SettingService', function ($rootScope, $scope, $routeParams, $window, $interval, $timeout, ariaNgLanguages, ariaNgCommonService, ariaNgNotificationService, ariaNgLocalizationService, ariaNgSettingService, ariaNgMonitorService, ariaNgTitleService, aria2SettingService) {
var extendType = $routeParams.extendType;
var lastRefreshPageNotification = null;
@ -20,7 +20,7 @@
$window.location.reload();
};
lastRefreshPageNotification = ariaNgNotificationService.notifyInPage('', 'Configuration has been modified, please reload the page for the changes to take effect.', {
lastRefreshPageNotification = ariaNgLocalizationService.notifyInPage('', 'Configuration has been modified, please reload the page for the changes to take effect.', {
delay: false,
type: 'info',
templateUrl: 'setting-changed-notification.html',
@ -100,7 +100,10 @@
};
$scope.setLanguage = function (value) {
ariaNgSettingService.setLanguage(value);
if (ariaNgSettingService.setLanguage(value)) {
ariaNgLocalizationService.applyLanguage(value);
}
$scope.updateTitlePreview();
};
@ -137,7 +140,7 @@
ariaNgNotificationService.requestBrowserPermission(function (permission) {
if (!ariaNgNotificationService.isPermissionGranted(permission)) {
$scope.context.settings.browserNotification = false;
ariaNgCommonService.showError('You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.');
ariaNgLocalizationService.showError('You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.');
}
});
}
@ -170,7 +173,7 @@
$scope.removeRpcSetting = function (setting) {
var rpcName = (setting.rpcAlias ? setting.rpcAlias : setting.rpcHost + ':' + setting.rpcPort);
ariaNgCommonService.confirm('Confirm Remove', 'Are you sure you want to remove rpc setting "{{rpcName}}"?', 'warning', function () {
ariaNgLocalizationService.confirm('Confirm Remove', 'Are you sure you want to remove rpc setting "{{rpcName}}"?', 'warning', function () {
setNeedRefreshPage();
var index = $scope.context.rpcSettings.indexOf(setting);
@ -197,14 +200,14 @@
};
$scope.resetSettings = function () {
ariaNgCommonService.confirm('Confirm Reset', 'Are you sure you want to reset all settings?', 'warning', function () {
ariaNgLocalizationService.confirm('Confirm Reset', 'Are you sure you want to reset all settings?', 'warning', function () {
ariaNgSettingService.resetSettings();
$window.location.reload();
});
};
$scope.clearHistory = function () {
ariaNgCommonService.confirm('Confirm Clear', 'Are you sure you want to clear all settings history?', 'warning', function () {
ariaNgLocalizationService.confirm('Confirm Clear', 'Are you sure you want to clear all settings history?', 'warning', function () {
aria2SettingService.clearSettingsHistorys();
$window.location.reload();
});

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').controller('Aria2StatusController', ['$rootScope', '$scope', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2SettingService', function ($rootScope, $scope, ariaNgCommonService, ariaNgSettingService, aria2SettingService) {
angular.module('ariaNg').controller('Aria2StatusController', ['$rootScope', '$scope', 'ariaNgLocalizationService', 'ariaNgSettingService', 'aria2SettingService', function ($rootScope, $scope, ariaNgLocalizationService, ariaNgSettingService, aria2SettingService) {
$scope.context = {
host: ariaNgSettingService.getCurrentRpcUrl(),
status: 'Connecting',
@ -11,16 +11,16 @@
$scope.saveSession = function () {
return aria2SettingService.saveSession(function (response) {
if (response.success && response.data === 'OK') {
ariaNgCommonService.showOperationSucceeded('Session has been saved successfully.');
ariaNgLocalizationService.showOperationSucceeded('Session has been saved successfully.');
}
});
};
$scope.shutdown = function () {
ariaNgCommonService.confirm('Confirm Shutdown', 'Are you sure you want to shutdown aria2?', 'warning', function (status) {
ariaNgLocalizationService.confirm('Confirm Shutdown', 'Are you sure you want to shutdown aria2?', 'warning', function (status) {
return aria2SettingService.shutdown(function (response) {
if (response.success && response.data === 'OK') {
ariaNgCommonService.showOperationSucceeded('Aria2 has been shutdown successfully.');
ariaNgLocalizationService.showOperationSucceeded('Aria2 has been shutdown successfully.');
}
});
}, true);

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').run(['$rootScope', '$location', '$document', 'ariaNgCommonService', 'ariaNgNotificationService', 'ariaNgSettingService', 'ariaNgLogService', 'aria2TaskService', function ($rootScope, $location, $document, ariaNgCommonService, ariaNgNotificationService, ariaNgSettingService, ariaNgLogService, aria2TaskService) {
angular.module('ariaNg').run(['$rootScope', '$location', '$document', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $location, $document, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService) {
var isUrlMatchUrl2 = function (url, url2) {
if (url === url2) {
return true;
@ -38,7 +38,7 @@
angular.element('.main-sidebar').addClass('blur');
angular.element('.navbar').addClass('blur');
angular.element('.content-body').addClass('blur');
ariaNgNotificationService.notifyInPage('', 'You cannot use AriaNg because this browser does not support data storage.', {
ariaNgLocalizationService.notifyInPage('', 'You cannot use AriaNg because this browser does not support data storage.', {
type: 'error',
delay: false
});
@ -181,7 +181,7 @@
};
ariaNgSettingService.onFirstAccess(function () {
ariaNgNotificationService.notifyInPage('', 'Tap to configure and get started with AriaNg.', {
ariaNgLocalizationService.notifyInPage('', 'Tap to configure and get started with AriaNg.', {
delay: false,
onClose: function () {
$location.path('/settings/ariang');
@ -190,7 +190,7 @@
});
aria2TaskService.onFirstSuccess(function (event) {
ariaNgNotificationService.notifyInPage('', '{{name}} is connected', {
ariaNgLocalizationService.notifyInPage('', '{{name}} is connected', {
type: 'success',
contentParams: {
name: event.rpcName
@ -207,15 +207,15 @@
});
aria2TaskService.onTaskCompleted(function (event) {
ariaNgNotificationService.notifyTaskComplete(event.task);
ariaNgLocalizationService.notifyTaskComplete(event.task);
});
aria2TaskService.onBtTaskCompleted(function (event) {
ariaNgNotificationService.notifyBtTaskComplete(event.task);
ariaNgLocalizationService.notifyBtTaskComplete(event.task);
});
aria2TaskService.onTaskErrorOccur(function (event) {
ariaNgNotificationService.notifyTaskError(event.task);
ariaNgLocalizationService.notifyTaskError(event.task);
});
$rootScope.$on('$locationChangeStart', function (event) {

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').directive('ngSetting', ['$timeout', '$q', '$translate', 'ariaNgConstants', 'aria2SettingService', function ($timeout, $q, $translate, ariaNgConstants, aria2SettingService) {
angular.module('ariaNg').directive('ngSetting', ['$timeout', '$q', 'ariaNgConstants', 'ariaNgLocalizationService', 'aria2SettingService', function ($timeout, $q, ariaNgConstants, ariaNgLocalizationService, aria2SettingService) {
return {
restrict: 'E',
templateUrl: 'views/setting.html',
@ -47,7 +47,7 @@
}
angular.element(element).tooltip({
title: $translate.instant(cause, causeParams),
title: ariaNgLocalizationService.getLocalizedText(cause, causeParams),
trigger: 'focus',
placement: 'auto top',
container: element,

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').directive('ngSettingDialog', ['ariaNgCommonService', 'aria2SettingService', function (ariaNgCommonService, aria2SettingService) {
angular.module('ariaNg').directive('ngSettingDialog', ['ariaNgLocalizationService', 'aria2SettingService', function (ariaNgLocalizationService, aria2SettingService) {
return {
restrict: 'E',
templateUrl: 'views/setting-dialog.html',
@ -30,7 +30,7 @@
var keys = aria2SettingService.getAria2QuickSettingsAvailableOptions(type);
if (!keys) {
ariaNgCommonService.showError('Type is illegal!');
ariaNgLocalizationService.showError('Type is illegal!');
return;
}

View file

@ -1,10 +1,10 @@
(function () {
'use strict';
angular.module('ariaNg').filter('longDate', ['$translate', 'moment', function ($translate, moment) {
angular.module('ariaNg').filter('longDate', ['ariaNgCommonService', 'ariaNgLocalizationService', function (ariaNgCommonService, ariaNgLocalizationService) {
return function (time) {
var format = $translate.instant('format.longdate');
return moment(time).format(format);
var format = ariaNgLocalizationService.getLongDateFormat();
return ariaNgCommonService.formatDateTime(time, format);
};
}]);
}());

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('aria2RpcService', ['$q', 'aria2RpcConstants', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgLogService', 'aria2HttpRpcService', 'aria2WebSocketRpcService', function ($q, aria2RpcConstants, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, ariaNgLogService, aria2HttpRpcService, aria2WebSocketRpcService) {
angular.module('ariaNg').factory('aria2RpcService', ['$q', 'aria2RpcConstants', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2HttpRpcService', 'aria2WebSocketRpcService', function ($q, aria2RpcConstants, aria2RpcErrors, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2HttpRpcService, aria2WebSocketRpcService) {
var rpcImplementService = ariaNgSettingService.isCurrentRpcUseWebSocket() ? aria2WebSocketRpcService : aria2HttpRpcService;
var isConnected = false;
var secret = ariaNgSettingService.getCurrentRpcSecret();
@ -115,10 +115,10 @@
ariaNgLogService.error('[aria2RpcService.processError] ' + error.message, error);
if (aria2RpcErrors[error.message] && aria2RpcErrors[error.message].tipTextKey) {
ariaNgCommonService.showError(aria2RpcErrors[error.message].tipTextKey);
ariaNgLocalizationService.showError(aria2RpcErrors[error.message].tipTextKey);
return true;
} else {
ariaNgCommonService.showError(error.message);
ariaNgLocalizationService.showError(error.message);
return true;
}
};

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('aria2TaskService', ['$q', '$translate', 'bittorrentPeeridService', 'aria2Errors', 'aria2RpcService', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgLogService', function ($q, $translate, bittorrentPeeridService, aria2Errors, aria2RpcService, ariaNgCommonService, ariaNgSettingService, ariaNgLogService) {
angular.module('ariaNg').factory('aria2TaskService', ['$q', 'bittorrentPeeridService', 'aria2Errors', 'aria2RpcService', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', function ($q, bittorrentPeeridService, aria2Errors, aria2RpcService, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService) {
var getFileName = function (file) {
if (!file) {
ariaNgLogService.warn('[aria2TaskService.getFileName] file is null');
@ -44,7 +44,7 @@
}
if (!taskName) {
taskName = $translate.instant('Unknown');
taskName = ariaNgLocalizationService.getLocalizedText('Unknown');
success = false;
}

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgCommonService', ['$location', '$timeout', 'base64', 'moment', 'SweetAlert', '$translate', 'ariaNgConstants', function ($location, $timeout, base64, moment, SweetAlert, $translate, ariaNgConstants) {
angular.module('ariaNg').factory('ariaNgCommonService', ['$location', '$timeout', 'base64', 'moment', 'SweetAlert', 'ariaNgConstants', function ($location, $timeout, base64, moment, SweetAlert, ariaNgConstants) {
return {
base64Encode: function (value) {
return base64.encode(value);
@ -18,13 +18,13 @@
return hashedId;
},
showDialog: function (title, text, type, callback) {
showDialog: function (title, text, type, callback, options) {
$timeout(function () {
SweetAlert.swal({
title: $translate.instant(title),
text: $translate.instant(text),
title: title,
text: text,
type: type,
confirmButtonText: $translate.instant('OK')
confirmButtonText: options && options.confirmButtonText || null
}, function () {
if (callback) {
callback();
@ -32,22 +32,16 @@
});
}, 100);
},
showError: function (text, callback) {
this.showDialog('Error', text, 'error', callback);
},
showOperationSucceeded: function (text, callback) {
this.showDialog('Operation Succeeded', text, 'success', callback);
},
confirm: function (title, text, type, callback, notClose, extendSettings) {
var options = {
title: $translate.instant(title),
text: $translate.instant(text, (angular.isObject(extendSettings) ? extendSettings.textParams : null)),
title: title,
text: text,
type: type,
showCancelButton: true,
showLoaderOnConfirm: !!notClose,
closeOnConfirm: !notClose,
confirmButtonText: $translate.instant('OK'),
cancelButtonText: $translate.instant('Cancel')
confirmButtonText: extendSettings && extendSettings.confirmButtonText || null,
cancelButtonText: extendSettings && extendSettings.cancelButtonText || null
};
if (type === 'warning') {
@ -230,6 +224,9 @@
getLongTimeFromUnixTime: function (unixTime) {
return moment(unixTime, 'X').format('HH:mm:ss');
},
formatDateTime: function (datetime, format) {
return moment(datetime).format(format);
},
getTimeOptions: function (timeList, withDisabled) {
var options = [];

View file

@ -0,0 +1,94 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgLocalizationService', ['$translate', 'amMoment', 'ariaNgCommonService', 'ariaNgNotificationService', function ($translate, amMoment, ariaNgCommonService, ariaNgNotificationService) {
return {
applyLanguage: function (lang) {
$translate.use(lang);
amMoment.changeLocale(lang);
return true;
},
getLocalizedText: function (text, params) {
return $translate.instant(text, params);
},
getLongDateFormat: function () {
return this.getLocalizedText('format.longdate');
},
showDialog: function (title, text, type, callback) {
if (title) {
title = this.getLocalizedText(title);
}
if (text) {
text = this.getLocalizedText(text);
}
var options = {
confirmButtonText: this.getLocalizedText('OK')
};
ariaNgCommonService.showDialog(title, text, type, callback, options);
},
showError: function (text, callback) {
this.showDialog('Error', text, 'error', callback);
},
showOperationSucceeded: function (text, callback) {
this.showDialog('Operation Succeeded', text, 'success', callback);
},
confirm: function (title, text, type, callback, notClose, extendSettings) {
if (!extendSettings) {
extendSettings = {};
}
if (title) {
title = this.getLocalizedText(title);
}
if (text) {
text = this.getLocalizedText(text, extendSettings.textParams);
}
extendSettings.confirmButtonText = this.getLocalizedText('OK');
extendSettings.cancelButtonText = this.getLocalizedText('Cancel');
ariaNgCommonService.confirm(title, text, type, callback, notClose, extendSettings);
},
notifyViaBrowser: function (title, content) {
if (title) {
title = this.getLocalizedText(title);
}
if (content) {
content = this.getLocalizedText(content);
}
return ariaNgNotificationService.notifyViaBrowser(title, content);
},
notifyInPage: function (title, content, options) {
if (!options) {
options = {};
}
if (title) {
title = this.getLocalizedText(title, options.titleParams);
}
if (content) {
content = this.getLocalizedText(content, options.contentParams);
}
return ariaNgNotificationService.notifyInPage(title, content, options);
},
notifyTaskComplete: function (task) {
this.notifyViaBrowser('Download Completed', (task && task.taskName ? task.taskName : ''));
},
notifyBtTaskComplete: function (task) {
this.notifyViaBrowser('BT Download Completed', (task && task.taskName ? task.taskName : ''));
},
notifyTaskError: function (task) {
this.notifyViaBrowser('Download Error', (task && task.taskName ? task.taskName : ''));
}
};
}]);
}());

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgMonitorService', ['$filter', '$translate', 'ariaNgConstants', 'ariaNgCommonService', function ($filter, $translate, ariaNgConstants, ariaNgCommonService) {
angular.module('ariaNg').factory('ariaNgMonitorService', ['$filter', 'ariaNgConstants', 'ariaNgCommonService', 'ariaNgLocalizationService', function ($filter, ariaNgConstants, ariaNgCommonService, ariaNgLocalizationService) {
var currentGlobalStat = {};
var storagesInMemory = {};
var globalStorageKey = 'global';
@ -29,7 +29,7 @@
show: true,
formatter: function (params) {
if (params[0].name === '') {
return '<div>' + $translate.instant('No Data') + '</div>';
return '<div>' + ariaNgLocalizationService.getLocalizedText('No Data') + '</div>';
}
var time = ariaNgCommonService.getLongTimeFromUnixTime(params[0].name);

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgNotificationService', ['$notification', '$translate', 'Notification', 'ariaNgSettingService', function ($notification, $translate, Notification, ariaNgSettingService) {
angular.module('ariaNg').factory('ariaNgNotificationService', ['$notification', 'Notification', 'ariaNgSettingService', function ($notification, Notification, ariaNgSettingService) {
var isSupportBrowserNotification = $notification.isSupported;
var isPermissionGranted = function (permission) {
@ -39,8 +39,8 @@
},
notifyViaBrowser: function (title, content) {
if (isSupportBrowserNotification && ariaNgSettingService.getBrowserNotification()) {
$notification($translate.instant(title), {
body: $translate.instant(content)
$notification(title, {
body: content
});
}
},
@ -49,14 +49,6 @@
options = {};
}
if (title) {
title = $translate.instant(title, options.titleParams);
}
if (content) {
content = $translate.instant(content, options.contentParams);
}
if (!content) {
options.message = title;
} else {
@ -70,15 +62,6 @@
return Notification[options.type](options);
},
notifyTaskComplete: function (task) {
this.notifyViaBrowser('Download Completed', (task && task.taskName ? task.taskName : ''));
},
notifyBtTaskComplete: function (task) {
this.notifyViaBrowser('BT Download Completed', (task && task.taskName ? task.taskName : ''));
},
notifyTaskError: function (task) {
this.notifyViaBrowser('Download Error', (task && task.taskName ? task.taskName : ''));
},
clearNotificationInPage: function () {
Notification.clearAll();
}

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', function ($window, $location, $filter, $translate, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService) {
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', function ($window, $location, $filter, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService) {
var browserFeatures = (function () {
var supportLocalStroage = localStorageService.isSupported;
var supportCookies = $window.navigator.cookieEnabled;
@ -247,23 +247,16 @@
isInsecureProtocolDisabled: function () {
return isInsecureProtocolDisabled();
},
applyLanguage: function (lang) {
if (!ariaNgLanguages[lang]) {
return false;
}
$translate.use(lang);
amMoment.changeLocale(lang);
return true;
},
getLanguage: function () {
return getOption('language');
},
setLanguage: function (value) {
if (this.applyLanguage(value)) {
setOption('language', value);
if (!ariaNgLanguages[value]) {
return false;
}
setOption('language', value);
return true;
},
isEnableDebugMode: function () {
return sessionSettings.debugMode;

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgTitleService', ['$filter', '$translate', 'ariaNgConstants', 'ariaNgSettingService', function ($filter, $translate, ariaNgConstants, ariaNgSettingService) {
angular.module('ariaNg').factory('ariaNgTitleService', ['$filter', 'ariaNgConstants', 'ariaNgLocalizationService', 'ariaNgSettingService', function ($filter, ariaNgConstants, ariaNgLocalizationService, ariaNgSettingService) {
var parseSettings = function (placeholder) {
if (!placeholder) {
return {};
@ -63,28 +63,28 @@
var replaceDownloadingCount = function (title, value) {
return replacePlaceholders(title, 'downloading', {
prefix: $translate.instant('Downloading') + ': ',
prefix: ariaNgLocalizationService.getLocalizedText('Downloading') + ': ',
value: value
});
};
var replaceWaitingCount = function (title, value) {
return replacePlaceholders(title, 'waiting', {
prefix: $translate.instant('Waiting') + ': ',
prefix: ariaNgLocalizationService.getLocalizedText('Waiting') + ': ',
value: value
});
};
var replaceStoppedCount = function (title, value) {
return replacePlaceholders(title, 'stopped', {
prefix: $translate.instant('Finished / Stopped') + ': ',
prefix: ariaNgLocalizationService.getLocalizedText('Finished / Stopped') + ': ',
value: value
});
};
var replaceDownloadSpeed = function (title, value) {
return replacePlaceholders(title, 'downspeed', {
prefix: $translate.instant('Download') + ': ',
prefix: ariaNgLocalizationService.getLocalizedText('Download') + ': ',
value: value,
type: 'volume',
suffix: '/s'
@ -93,7 +93,7 @@
var replaceUploadSpeed = function (title, value) {
return replacePlaceholders(title, 'upspeed', {
prefix: $translate.instant('Upload') + ': ',
prefix: ariaNgLocalizationService.getLocalizedText('Upload') + ': ',
value: value,
type: 'volume',
suffix: '/s'