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/ariaNgSettingService.js"></script>
<script src="scripts/services/ariaNgTitleService.js"></script> <script src="scripts/services/ariaNgTitleService.js"></script>
<script src="scripts/services/ariaNgLogService.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/aria2HttpRpcService.js"></script>
<script src="scripts/services/aria2WebSocketRpcService.js"></script> <script src="scripts/services/aria2WebSocketRpcService.js"></script>
<script src="scripts/services/aria2RpcService.js"></script> <script src="scripts/services/aria2RpcService.js"></script>

View file

@ -1,13 +1,13 @@
(function () { (function () {
'use strict'; '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(); var language = ariaNgSettingService.getLanguage();
moment.updateLocale('zh-cn', { moment.updateLocale('zh-cn', {
week: null week: null
}); });
ariaNgSettingService.applyLanguage(language); ariaNgLocalizationService.applyLanguage(language);
}]); }]);
}()); }());

View file

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

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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.logMaxCount = ariaNgConstants.cachedDebugLogsLimit;
$scope.currentLog = null; $scope.currentLog = null;
@ -24,7 +24,7 @@
$rootScope.loadPromise = $timeout(function () { $rootScope.loadPromise = $timeout(function () {
if (!ariaNgSettingService.isEnableDebugMode()) { if (!ariaNgSettingService.isEnableDebugMode()) {
ariaNgCommonService.showError('Access Denied!', function () { ariaNgLocalizationService.showError('Access Denied!', function () {
if (!ariaNgSettingService.isEnableDebugMode()) { if (!ariaNgSettingService.isEnableDebugMode()) {
$location.path('/settings/ariang'); $location.path('/settings/ariang');
} }

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 pageTitleRefreshPromise = null;
var globalStatRefreshPromise = null; var globalStatRefreshPromise = null;
@ -113,7 +113,7 @@
$rootScope.loadPromise = invoke(gids, function (response) { $rootScope.loadPromise = invoke(gids, function (response) {
if (response.hasError && gids.length > 1) { 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) { if (!response.hasSuccess) {
@ -139,10 +139,10 @@
}; };
$scope.restart = function (task) { $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) { $rootScope.loadPromise = aria2TaskService.restartTask(task.gid, function (response) {
if (!response.success) { if (!response.success) {
ariaNgCommonService.showError('Failed to restart this task.'); ariaNgLocalizationService.showError('Failed to restart this task.');
return; return;
} }
@ -166,10 +166,10 @@
return; 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) { $rootScope.loadPromise = aria2TaskService.removeTasks(tasks, function (response) {
if (response.hasError && tasks.length > 1) { 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) { if (!response.hasSuccess) {
@ -190,7 +190,7 @@
}; };
$scope.clearStoppedTasks = function () { $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) { $rootScope.loadPromise = aria2TaskService.clearStoppedTasks(function (response) {
if (!response.success) { if (!response.success) {
return; return;

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 tabOrders = ['links', 'options'];
var parameters = $location.search(); var parameters = $location.search();
@ -133,7 +133,7 @@
$scope.context.taskType = 'torrent'; $scope.context.taskType = 'torrent';
$scope.changeTab('options'); $scope.changeTab('options');
}, function (error) { }, function (error) {
ariaNgCommonService.showError(error); ariaNgLocalizationService.showError(error);
}, angular.element('#file-holder')); }, angular.element('#file-holder'));
}; };
@ -143,7 +143,7 @@
$scope.context.taskType = 'metalink'; $scope.context.taskType = 'metalink';
$scope.changeTab('options'); $scope.changeTab('options');
}, function (error) { }, function (error) {
ariaNgCommonService.showError(error); ariaNgLocalizationService.showError(error);
}, angular.element('#file-holder')); }, angular.element('#file-holder'));
}; };

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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); var location = $location.path().substring($location.path().lastIndexOf('/') + 1);
$scope.context = { $scope.context = {
@ -9,7 +9,7 @@
var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type); var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type);
if (!keys) { if (!keys) {
ariaNgCommonService.showError('Type is illegal!'); ariaNgLocalizationService.showError('Type is illegal!');
return; return;
} }

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 extendType = $routeParams.extendType;
var lastRefreshPageNotification = null; var lastRefreshPageNotification = null;
@ -20,7 +20,7 @@
$window.location.reload(); $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, delay: false,
type: 'info', type: 'info',
templateUrl: 'setting-changed-notification.html', templateUrl: 'setting-changed-notification.html',
@ -100,7 +100,10 @@
}; };
$scope.setLanguage = function (value) { $scope.setLanguage = function (value) {
ariaNgSettingService.setLanguage(value); if (ariaNgSettingService.setLanguage(value)) {
ariaNgLocalizationService.applyLanguage(value);
}
$scope.updateTitlePreview(); $scope.updateTitlePreview();
}; };
@ -137,7 +140,7 @@
ariaNgNotificationService.requestBrowserPermission(function (permission) { ariaNgNotificationService.requestBrowserPermission(function (permission) {
if (!ariaNgNotificationService.isPermissionGranted(permission)) { if (!ariaNgNotificationService.isPermissionGranted(permission)) {
$scope.context.settings.browserNotification = false; $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) { $scope.removeRpcSetting = function (setting) {
var rpcName = (setting.rpcAlias ? setting.rpcAlias : setting.rpcHost + ':' + setting.rpcPort); 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(); setNeedRefreshPage();
var index = $scope.context.rpcSettings.indexOf(setting); var index = $scope.context.rpcSettings.indexOf(setting);
@ -197,14 +200,14 @@
}; };
$scope.resetSettings = function () { $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(); ariaNgSettingService.resetSettings();
$window.location.reload(); $window.location.reload();
}); });
}; };
$scope.clearHistory = function () { $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(); aria2SettingService.clearSettingsHistorys();
$window.location.reload(); $window.location.reload();
}); });

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 = { $scope.context = {
host: ariaNgSettingService.getCurrentRpcUrl(), host: ariaNgSettingService.getCurrentRpcUrl(),
status: 'Connecting', status: 'Connecting',
@ -11,16 +11,16 @@
$scope.saveSession = function () { $scope.saveSession = function () {
return aria2SettingService.saveSession(function (response) { return aria2SettingService.saveSession(function (response) {
if (response.success && response.data === 'OK') { if (response.success && response.data === 'OK') {
ariaNgCommonService.showOperationSucceeded('Session has been saved successfully.'); ariaNgLocalizationService.showOperationSucceeded('Session has been saved successfully.');
} }
}); });
}; };
$scope.shutdown = function () { $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) { return aria2SettingService.shutdown(function (response) {
if (response.success && response.data === 'OK') { if (response.success && response.data === 'OK') {
ariaNgCommonService.showOperationSucceeded('Aria2 has been shutdown successfully.'); ariaNgLocalizationService.showOperationSucceeded('Aria2 has been shutdown successfully.');
} }
}); });
}, true); }, true);

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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) { var isUrlMatchUrl2 = function (url, url2) {
if (url === url2) { if (url === url2) {
return true; return true;
@ -38,7 +38,7 @@
angular.element('.main-sidebar').addClass('blur'); angular.element('.main-sidebar').addClass('blur');
angular.element('.navbar').addClass('blur'); angular.element('.navbar').addClass('blur');
angular.element('.content-body').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', type: 'error',
delay: false delay: false
}); });
@ -181,7 +181,7 @@
}; };
ariaNgSettingService.onFirstAccess(function () { 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, delay: false,
onClose: function () { onClose: function () {
$location.path('/settings/ariang'); $location.path('/settings/ariang');
@ -190,7 +190,7 @@
}); });
aria2TaskService.onFirstSuccess(function (event) { aria2TaskService.onFirstSuccess(function (event) {
ariaNgNotificationService.notifyInPage('', '{{name}} is connected', { ariaNgLocalizationService.notifyInPage('', '{{name}} is connected', {
type: 'success', type: 'success',
contentParams: { contentParams: {
name: event.rpcName name: event.rpcName
@ -207,15 +207,15 @@
}); });
aria2TaskService.onTaskCompleted(function (event) { aria2TaskService.onTaskCompleted(function (event) {
ariaNgNotificationService.notifyTaskComplete(event.task); ariaNgLocalizationService.notifyTaskComplete(event.task);
}); });
aria2TaskService.onBtTaskCompleted(function (event) { aria2TaskService.onBtTaskCompleted(function (event) {
ariaNgNotificationService.notifyBtTaskComplete(event.task); ariaNgLocalizationService.notifyBtTaskComplete(event.task);
}); });
aria2TaskService.onTaskErrorOccur(function (event) { aria2TaskService.onTaskErrorOccur(function (event) {
ariaNgNotificationService.notifyTaskError(event.task); ariaNgLocalizationService.notifyTaskError(event.task);
}); });
$rootScope.$on('$locationChangeStart', function (event) { $rootScope.$on('$locationChangeStart', function (event) {

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 { return {
restrict: 'E', restrict: 'E',
templateUrl: 'views/setting.html', templateUrl: 'views/setting.html',
@ -47,7 +47,7 @@
} }
angular.element(element).tooltip({ angular.element(element).tooltip({
title: $translate.instant(cause, causeParams), title: ariaNgLocalizationService.getLocalizedText(cause, causeParams),
trigger: 'focus', trigger: 'focus',
placement: 'auto top', placement: 'auto top',
container: element, container: element,

View file

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

View file

@ -1,10 +1,10 @@
(function () { (function () {
'use strict'; '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) { return function (time) {
var format = $translate.instant('format.longdate'); var format = ariaNgLocalizationService.getLongDateFormat();
return moment(time).format(format); return ariaNgCommonService.formatDateTime(time, format);
}; };
}]); }]);
}()); }());

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 rpcImplementService = ariaNgSettingService.isCurrentRpcUseWebSocket() ? aria2WebSocketRpcService : aria2HttpRpcService;
var isConnected = false; var isConnected = false;
var secret = ariaNgSettingService.getCurrentRpcSecret(); var secret = ariaNgSettingService.getCurrentRpcSecret();
@ -115,10 +115,10 @@
ariaNgLogService.error('[aria2RpcService.processError] ' + error.message, error); ariaNgLogService.error('[aria2RpcService.processError] ' + error.message, error);
if (aria2RpcErrors[error.message] && aria2RpcErrors[error.message].tipTextKey) { if (aria2RpcErrors[error.message] && aria2RpcErrors[error.message].tipTextKey) {
ariaNgCommonService.showError(aria2RpcErrors[error.message].tipTextKey); ariaNgLocalizationService.showError(aria2RpcErrors[error.message].tipTextKey);
return true; return true;
} else { } else {
ariaNgCommonService.showError(error.message); ariaNgLocalizationService.showError(error.message);
return true; return true;
} }
}; };

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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) { var getFileName = function (file) {
if (!file) { if (!file) {
ariaNgLogService.warn('[aria2TaskService.getFileName] file is null'); ariaNgLogService.warn('[aria2TaskService.getFileName] file is null');
@ -44,7 +44,7 @@
} }
if (!taskName) { if (!taskName) {
taskName = $translate.instant('Unknown'); taskName = ariaNgLocalizationService.getLocalizedText('Unknown');
success = false; success = false;
} }

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 { return {
base64Encode: function (value) { base64Encode: function (value) {
return base64.encode(value); return base64.encode(value);
@ -18,13 +18,13 @@
return hashedId; return hashedId;
}, },
showDialog: function (title, text, type, callback) { showDialog: function (title, text, type, callback, options) {
$timeout(function () { $timeout(function () {
SweetAlert.swal({ SweetAlert.swal({
title: $translate.instant(title), title: title,
text: $translate.instant(text), text: text,
type: type, type: type,
confirmButtonText: $translate.instant('OK') confirmButtonText: options && options.confirmButtonText || null
}, function () { }, function () {
if (callback) { if (callback) {
callback(); callback();
@ -32,22 +32,16 @@
}); });
}, 100); }, 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) { confirm: function (title, text, type, callback, notClose, extendSettings) {
var options = { var options = {
title: $translate.instant(title), title: title,
text: $translate.instant(text, (angular.isObject(extendSettings) ? extendSettings.textParams : null)), text: text,
type: type, type: type,
showCancelButton: true, showCancelButton: true,
showLoaderOnConfirm: !!notClose, showLoaderOnConfirm: !!notClose,
closeOnConfirm: !notClose, closeOnConfirm: !notClose,
confirmButtonText: $translate.instant('OK'), confirmButtonText: extendSettings && extendSettings.confirmButtonText || null,
cancelButtonText: $translate.instant('Cancel') cancelButtonText: extendSettings && extendSettings.cancelButtonText || null
}; };
if (type === 'warning') { if (type === 'warning') {
@ -230,6 +224,9 @@
getLongTimeFromUnixTime: function (unixTime) { getLongTimeFromUnixTime: function (unixTime) {
return moment(unixTime, 'X').format('HH:mm:ss'); return moment(unixTime, 'X').format('HH:mm:ss');
}, },
formatDateTime: function (datetime, format) {
return moment(datetime).format(format);
},
getTimeOptions: function (timeList, withDisabled) { getTimeOptions: function (timeList, withDisabled) {
var options = []; 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 () { (function () {
'use strict'; '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 currentGlobalStat = {};
var storagesInMemory = {}; var storagesInMemory = {};
var globalStorageKey = 'global'; var globalStorageKey = 'global';
@ -29,7 +29,7 @@
show: true, show: true,
formatter: function (params) { formatter: function (params) {
if (params[0].name === '') { 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); var time = ariaNgCommonService.getLongTimeFromUnixTime(params[0].name);

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 isSupportBrowserNotification = $notification.isSupported;
var isPermissionGranted = function (permission) { var isPermissionGranted = function (permission) {
@ -39,8 +39,8 @@
}, },
notifyViaBrowser: function (title, content) { notifyViaBrowser: function (title, content) {
if (isSupportBrowserNotification && ariaNgSettingService.getBrowserNotification()) { if (isSupportBrowserNotification && ariaNgSettingService.getBrowserNotification()) {
$notification($translate.instant(title), { $notification(title, {
body: $translate.instant(content) body: content
}); });
} }
}, },
@ -49,14 +49,6 @@
options = {}; options = {};
} }
if (title) {
title = $translate.instant(title, options.titleParams);
}
if (content) {
content = $translate.instant(content, options.contentParams);
}
if (!content) { if (!content) {
options.message = title; options.message = title;
} else { } else {
@ -70,15 +62,6 @@
return Notification[options.type](options); 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 () { clearNotificationInPage: function () {
Notification.clearAll(); Notification.clearAll();
} }

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 browserFeatures = (function () {
var supportLocalStroage = localStorageService.isSupported; var supportLocalStroage = localStorageService.isSupported;
var supportCookies = $window.navigator.cookieEnabled; var supportCookies = $window.navigator.cookieEnabled;
@ -247,23 +247,16 @@
isInsecureProtocolDisabled: function () { isInsecureProtocolDisabled: function () {
return isInsecureProtocolDisabled(); return isInsecureProtocolDisabled();
}, },
applyLanguage: function (lang) {
if (!ariaNgLanguages[lang]) {
return false;
}
$translate.use(lang);
amMoment.changeLocale(lang);
return true;
},
getLanguage: function () { getLanguage: function () {
return getOption('language'); return getOption('language');
}, },
setLanguage: function (value) { setLanguage: function (value) {
if (this.applyLanguage(value)) { if (!ariaNgLanguages[value]) {
setOption('language', value); return false;
} }
setOption('language', value);
return true;
}, },
isEnableDebugMode: function () { isEnableDebugMode: function () {
return sessionSettings.debugMode; return sessionSettings.debugMode;

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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) { var parseSettings = function (placeholder) {
if (!placeholder) { if (!placeholder) {
return {}; return {};
@ -63,28 +63,28 @@
var replaceDownloadingCount = function (title, value) { var replaceDownloadingCount = function (title, value) {
return replacePlaceholders(title, 'downloading', { return replacePlaceholders(title, 'downloading', {
prefix: $translate.instant('Downloading') + ': ', prefix: ariaNgLocalizationService.getLocalizedText('Downloading') + ': ',
value: value value: value
}); });
}; };
var replaceWaitingCount = function (title, value) { var replaceWaitingCount = function (title, value) {
return replacePlaceholders(title, 'waiting', { return replacePlaceholders(title, 'waiting', {
prefix: $translate.instant('Waiting') + ': ', prefix: ariaNgLocalizationService.getLocalizedText('Waiting') + ': ',
value: value value: value
}); });
}; };
var replaceStoppedCount = function (title, value) { var replaceStoppedCount = function (title, value) {
return replacePlaceholders(title, 'stopped', { return replacePlaceholders(title, 'stopped', {
prefix: $translate.instant('Finished / Stopped') + ': ', prefix: ariaNgLocalizationService.getLocalizedText('Finished / Stopped') + ': ',
value: value value: value
}); });
}; };
var replaceDownloadSpeed = function (title, value) { var replaceDownloadSpeed = function (title, value) {
return replacePlaceholders(title, 'downspeed', { return replacePlaceholders(title, 'downspeed', {
prefix: $translate.instant('Download') + ': ', prefix: ariaNgLocalizationService.getLocalizedText('Download') + ': ',
value: value, value: value,
type: 'volume', type: 'volume',
suffix: '/s' suffix: '/s'
@ -93,7 +93,7 @@
var replaceUploadSpeed = function (title, value) { var replaceUploadSpeed = function (title, value) {
return replacePlaceholders(title, 'upspeed', { return replacePlaceholders(title, 'upspeed', {
prefix: $translate.instant('Upload') + ': ', prefix: ariaNgLocalizationService.getLocalizedText('Upload') + ': ',
value: value, value: value,
type: 'volume', type: 'volume',
suffix: '/s' suffix: '/s'