From 0623374b3958e5d24c24b33e9511de219bfdb6a3 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Tue, 2 Aug 2016 01:26:10 +0800 Subject: [PATCH] refactor code --- src/scripts/directives/pieceMap.js | 4 +-- src/scripts/directives/setting.js | 30 +++++++++---------- src/scripts/directives/tooltip.js | 2 +- src/scripts/filters/fileOrderBy.js | 8 ++--- src/scripts/filters/peerOrderBy.js | 12 ++++---- src/scripts/filters/taskOrderBy.js | 14 ++++----- src/scripts/filters/taskStatus.js | 12 ++++---- src/scripts/services/aria2RpcService.js | 4 +-- src/scripts/services/aria2SettingService.js | 20 ++++++------- src/scripts/services/aria2TaskService.js | 24 +++++++-------- .../services/aria2WebSocketRpcService.js | 2 +- src/scripts/services/ariaNgCommonService.js | 20 ++++++------- src/scripts/services/ariaNgFileService.js | 2 +- src/scripts/services/ariaNgMonitorService.js | 4 +-- .../services/ariaNgNotificationService.js | 2 +- src/scripts/services/ariaNgSettingService.js | 2 +- 16 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/scripts/directives/pieceMap.js b/src/scripts/directives/pieceMap.js index 433a166..8527dda 100644 --- a/src/scripts/directives/pieceMap.js +++ b/src/scripts/directives/pieceMap.js @@ -31,13 +31,13 @@ var refresh = function () { var newPieceStatus = aria2TaskService.getPieceStatus(scope.bitField, scope.pieceCount); - if (!currentPieceStatus || !newPieceStatus || currentPieceStatus.length != newPieceStatus.length || newPieceStatus.length != pieces.length) { + if (!currentPieceStatus || !newPieceStatus || currentPieceStatus.length !== newPieceStatus.length || newPieceStatus.length !== pieces.length) { redraw(); return; } for (var i = 0; i < pieces.length; i++) { - if (currentPieceStatus[i] != newPieceStatus[i]) { + if (currentPieceStatus[i] !== newPieceStatus[i]) { if (newPieceStatus[i]) { pieces[i].addClass('piece-completed'); } else { diff --git a/src/scripts/directives/setting.js b/src/scripts/directives/setting.js index c5b823a..4bc6fc6 100644 --- a/src/scripts/directives/setting.js +++ b/src/scripts/directives/setting.js @@ -80,33 +80,33 @@ showTooltip(cause, 'error', causeParams); }, getStatusFeedbackStyle: function () { - if (value == 'success') { + if (value === 'success') { return 'has-success'; - } else if (value == 'failed') { + } else if (value === 'failed') { return 'has-warning'; - } else if (value == 'error') { + } else if (value === 'error') { return 'has-error'; } else { return ''; } }, getStatusIcon: function () { - if (value == 'pending') { + if (value === 'pending') { return 'fa-hourglass-start'; - } else if (value == 'saving') { + } else if (value === 'saving') { return 'fa-spin fa-pulse fa-spinner'; - } else if (value == 'success') { + } else if (value === 'success') { return 'fa-check'; - } else if (value == 'failed') { + } else if (value === 'failed') { return 'fa-exclamation'; - } else if (value == 'error') { + } else if (value === 'error') { return 'fa-times'; } else { return ''; } }, isShowStatusIcon: function () { - return this.getStatusIcon() != ''; + return this.getStatusIcon() !== ''; } }; })(); @@ -131,27 +131,27 @@ return; } - if (scope.option.required && optionValue == '') { + if (scope.option.required && optionValue === '') { scope.optionStatus.setError('Option value cannot be empty!'); return; } - if (scope.option.type == 'integer' && !/^-?\d+$/.test(optionValue)) { + if (scope.option.type === 'integer' && !/^-?\d+$/.test(optionValue)) { scope.optionStatus.setError('Input number is invalid!'); return; } - if (scope.option.type == 'float' && !/^-?(\d*\.)?\d+$/.test(optionValue)) { + if (scope.option.type === 'float' && !/^-?(\d*\.)?\d+$/.test(optionValue)) { scope.optionStatus.setError('Input number is invalid!'); return; } - if ((scope.option.type == 'integer' || scope.option.type == 'float') && (angular.isDefined(scope.option.min) || angular.isDefined(scope.option.max))) { + if ((scope.option.type === 'integer' || scope.option.type === 'float') && (angular.isDefined(scope.option.min) || angular.isDefined(scope.option.max))) { var number = optionValue; - if (scope.option.type == 'integer') { + if (scope.option.type === 'integer') { number = parseInt(optionValue); - } else if (scope.option.type == 'float') { + } else if (scope.option.type === 'float') { number = parseFloat(optionValue); } diff --git a/src/scripts/directives/tooltip.js b/src/scripts/directives/tooltip.js index 5a9d2f4..b6f490a 100644 --- a/src/scripts/directives/tooltip.js +++ b/src/scripts/directives/tooltip.js @@ -57,7 +57,7 @@ value = (value === true || value === 'true'); - if (showTooltip == value) { + if (showTooltip === value) { return; } diff --git a/src/scripts/filters/fileOrderBy.js b/src/scripts/filters/fileOrderBy.js index e7a335d..f4941f9 100644 --- a/src/scripts/filters/fileOrderBy.js +++ b/src/scripts/filters/fileOrderBy.js @@ -9,15 +9,15 @@ var orderType = ariaNgCommonService.parseOrderType(type); - if (orderType == null) { + if (orderType === null) { return array; } - if (orderType.type == 'name') { + if (orderType.type === 'name') { return $filter('orderBy')(array, ['fileName'], orderType.reverse); - } else if (orderType.type == 'size') { + } else if (orderType.type === 'size') { return $filter('orderBy')(array, ['length'], orderType.reverse); - } else if (orderType.type == 'percent') { + } else if (orderType.type === 'percent') { return $filter('orderBy')(array, ['completePercent'], orderType.reverse); } else { return array; diff --git a/src/scripts/filters/peerOrderBy.js b/src/scripts/filters/peerOrderBy.js index 903b564..3ce2b7f 100644 --- a/src/scripts/filters/peerOrderBy.js +++ b/src/scripts/filters/peerOrderBy.js @@ -9,19 +9,19 @@ var orderType = ariaNgCommonService.parseOrderType(type); - if (orderType == null) { + if (orderType === null) { return array; } - if (orderType.type == 'address') { + if (orderType.type === 'address') { return $filter('orderBy')(array, ['ip', 'port'], orderType.reverse); - } else if (orderType.type == 'client') { + } else if (orderType.type === 'client') { return $filter('orderBy')(array, ['client.name', 'client.version'], orderType.reverse); - } else if (orderType.type == 'percent') { + } else if (orderType.type === 'percent') { return $filter('orderBy')(array, ['completePercent'], orderType.reverse); - } else if (orderType.type == 'dspeed') { + } else if (orderType.type === 'dspeed') { return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse); - } else if (orderType.type == 'uspeed') { + } else if (orderType.type === 'uspeed') { return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse); } else { return array; diff --git a/src/scripts/filters/taskOrderBy.js b/src/scripts/filters/taskOrderBy.js index 6a514dc..61ac3f6 100644 --- a/src/scripts/filters/taskOrderBy.js +++ b/src/scripts/filters/taskOrderBy.js @@ -9,21 +9,21 @@ var orderType = ariaNgCommonService.parseOrderType(type); - if (orderType == null) { + if (orderType === null) { return array; } - if (orderType.type == 'name') { + if (orderType.type === 'name') { return $filter('orderBy')(array, ['taskName'], orderType.reverse); - } else if (orderType.type == 'size') { + } else if (orderType.type === 'size') { return $filter('orderBy')(array, ['totalLength'], orderType.reverse); - } else if (orderType.type == 'percent') { + } else if (orderType.type === 'percent') { return $filter('orderBy')(array, ['completePercent'], orderType.reverse); - } else if (orderType.type == 'remain') { + } else if (orderType.type === 'remain') { return $filter('orderBy')(array, ['idle', 'remainTime', 'remainLength'], orderType.reverse); - } else if (orderType.type == 'dspeed') { + } else if (orderType.type === 'dspeed') { return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse); - } else if (orderType.type == 'uspeed') { + } else if (orderType.type === 'uspeed') { return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse); } else { return array; diff --git a/src/scripts/filters/taskStatus.js b/src/scripts/filters/taskStatus.js index fe1405a..fcbe1d6 100644 --- a/src/scripts/filters/taskStatus.js +++ b/src/scripts/filters/taskStatus.js @@ -7,21 +7,21 @@ return ''; } - if (task.status == 'active') { + if (task.status === 'active') { if (task.seeder === true || task.seeder === 'true') { return 'Seeding'; } else { return 'Downloading'; } - } else if (task.status == 'waiting') { + } else if (task.status === 'waiting') { return 'Waiting'; - } else if (task.status == 'paused') { + } else if (task.status === 'paused') { return 'Paused'; - } else if (task.status == 'complete') { + } else if (task.status === 'complete') { return 'Completed'; - } else if (task.status == 'error') { + } else if (task.status === 'error') { return (task.errorCode ? 'format.task.error-occurred' : 'Error Occurred'); - } else if (task.status == 'removed') { + } else if (task.status === 'removed') { return 'Removed'; } else { return ''; diff --git a/src/scripts/services/aria2RpcService.js b/src/scripts/services/aria2RpcService.js index 3dbef92..fa78e33 100644 --- a/src/scripts/services/aria2RpcService.js +++ b/src/scripts/services/aria2RpcService.js @@ -15,7 +15,7 @@ var onBtDownloadCompleteCallbacks = []; var checkIsSystemMethod = function (methodName) { - return methodName.indexOf(aria2RpcConstants.rpcSystemServiceName + '.') == 0; + return methodName.indexOf(aria2RpcConstants.rpcSystemServiceName + '.') === 0; }; var getAria2MethodFullName = function (methodName) { @@ -172,7 +172,7 @@ if (arguments.length > 2) { for (var i = 2; i < arguments.length; i++) { - if (arguments[i] != null && angular.isDefined(arguments[i])) { + if (arguments[i] !== null && angular.isDefined(arguments[i])) { finalParams.push(arguments[i]); } } diff --git a/src/scripts/services/aria2SettingService.js b/src/scripts/services/aria2SettingService.js index 0765539..17cc367 100644 --- a/src/scripts/services/aria2SettingService.js +++ b/src/scripts/services/aria2SettingService.js @@ -18,21 +18,21 @@ return { getAvailableGlobalOptionsKeys: function (type) { - if (type == 'basic') { + if (type === 'basic') { return aria2GlobalAvailableOptions.basicOptions; - } else if (type == 'http-ftp-sftp') { + } else if (type === 'http-ftp-sftp') { return aria2GlobalAvailableOptions.httpFtpSFtpOptions; - } else if (type == 'http') { + } else if (type === 'http') { return aria2GlobalAvailableOptions.httpOptions; - } else if (type == 'ftp-sftp') { + } else if (type === 'ftp-sftp') { return aria2GlobalAvailableOptions.ftpSFtpOptions; - } else if (type == 'bt') { + } else if (type === 'bt') { return aria2GlobalAvailableOptions.btOptions; - } else if (type == 'metalink') { + } else if (type === 'metalink') { return aria2GlobalAvailableOptions.metalinkOptions; - } else if (type == 'rpc') { + } else if (type === 'rpc') { return aria2GlobalAvailableOptions.rpcOptions; - } else if (type == 'advanced') { + } else if (type === 'advanced') { return aria2GlobalAvailableOptions.advancedOptions; } else { return false; @@ -58,7 +58,7 @@ continue; } - if (option.activeReadonly && status == 'active') { + if (option.activeReadonly && status === 'active') { optionKey.readonly = true; } @@ -108,7 +108,7 @@ descriptionKey: 'options.' + key + '.description' }, option); - if (option.type == 'boolean') { + if (option.type === 'boolean') { option.options = ['true', 'false']; } diff --git a/src/scripts/services/aria2TaskService.js b/src/scripts/services/aria2TaskService.js index a47a8e3..4c33479 100644 --- a/src/scripts/services/aria2TaskService.js +++ b/src/scripts/services/aria2TaskService.js @@ -15,7 +15,7 @@ var index = path.lastIndexOf('/'); - if (index <= 0 || index == path.length) { + if (index <= 0 || index === path.length) { return path; } @@ -23,7 +23,7 @@ }; var calculateDownloadRemainTime = function (remainBytes, downloadSpeed) { - if (downloadSpeed == 0) { + if (downloadSpeed === 0) { return 0; } @@ -71,7 +71,7 @@ for (var j = 1; j <= 4; j++) { var bit = (1 << (4 - j)); - var isCompleted = (bitSet & bit) == bit; + var isCompleted = (bitSet & bit) === bit; pieces[pieceIndex++] = isCompleted; @@ -91,7 +91,7 @@ for (var i = 0; i < pieces.length; i++) { var isCompleted = pieces[i]; - if (combinedPieces.length > 0 && combinedPieces[combinedPieces.length - 1].isCompleted == isCompleted) { + if (combinedPieces.length > 0 && combinedPieces[combinedPieces.length - 1].isCompleted === isCompleted) { combinedPieces[combinedPieces.length - 1].count++; } else { combinedPieces.push({ @@ -126,7 +126,7 @@ task.completedPieces = ariaNgCommonService.countArray(pieceStatus, true); task.pieceLength = parseInt(task.pieceLength); - task.idle = task.downloadSpeed == 0; + task.idle = task.downloadSpeed === 0; task.remainTime = calculateDownloadRemainTime(task.remainLength, task.downloadSpeed); task.seeder = (task.seeder === true || task.seeder === 'true'); @@ -176,7 +176,7 @@ peer.uploadSpeed = downstreamFromSpeed; peer.seeder = (peer.seeder === true || peer.seeder === 'true'); - if (completedPieceCount == localTaskCompletedPieceCount && peer.completePercent != localTaskCompletedPercent) { + if (completedPieceCount === localTaskCompletedPieceCount && peer.completePercent !== localTaskCompletedPercent) { peer.completePercent = localTaskCompletedPercent; } @@ -184,7 +184,7 @@ var peerId = ariaNgCommonService.decodePercentEncodedString(peer.peerId); var clientInfo = (peerId ? bittorrentPeeridService.parseClient(peerId) : null); - if (clientInfo && clientInfo.client != 'unknown') { + if (clientInfo && clientInfo.client !== 'unknown') { var client = { name: (clientInfo.client ? clientInfo.client.trim() : ''), version: (clientInfo.version ? clientInfo.version.trim() : '') @@ -238,11 +238,11 @@ getTaskList: function (type, full, callback, silent) { var invokeMethod = null; - if (type == 'downloading') { + if (type === 'downloading') { invokeMethod = aria2RpcService.tellActive; - } else if (type == 'waiting') { + } else if (type === 'waiting') { invokeMethod = aria2RpcService.tellWaiting; - } else if (type == 'stopped') { + } else if (type === 'stopped') { invokeMethod = aria2RpcService.tellStopped; } else { return; @@ -410,7 +410,7 @@ var stoppedTaskGids = []; for (var i = 0; i < tasks.length; i++) { - if (tasks[i].status == 'complete' || tasks[i].status == 'error' || tasks[i].status == 'removed') { + if (tasks[i].status === 'complete' || tasks[i].status === 'error' || tasks[i].status === 'removed') { stoppedTaskGids.push(tasks[i].gid); } else { runningTaskGids.push(tasks[i].gid); @@ -550,7 +550,7 @@ if (completedPieceCount > maxCompletedPieceCount) { maxCompletedPieceCount = completedPieceCount; maxCompletedPercent = peer.completePercent; - } else if (completedPieceCount == maxCompletedPieceCount && peer.completePercent > maxCompletedPercent) { + } else if (completedPieceCount === maxCompletedPieceCount && peer.completePercent > maxCompletedPercent) { maxCompletedPercent = peer.completePercent; } } diff --git a/src/scripts/services/aria2WebSocketRpcService.js b/src/scripts/services/aria2WebSocketRpcService.js index 5100258..d99063c 100644 --- a/src/scripts/services/aria2WebSocketRpcService.js +++ b/src/scripts/services/aria2WebSocketRpcService.js @@ -60,7 +60,7 @@ }; var getSocketClient = function () { - if (socketClient == null) { + if (socketClient === null) { socketClient = $websocket(rpcUrl); socketClient.onMessage(function (message) { diff --git a/src/scripts/services/ariaNgCommonService.js b/src/scripts/services/ariaNgCommonService.js index 9d462e3..6c840dd 100644 --- a/src/scripts/services/ariaNgCommonService.js +++ b/src/scripts/services/ariaNgCommonService.js @@ -37,7 +37,7 @@ cancelButtonText: $translate.instant('Cancel') }; - if (type == 'warning') { + if (type === 'warning') { options.confirmButtonColor = '#F39C12'; } @@ -68,7 +68,7 @@ for (var i = 0; i < s.length; i++) { var ch = s.charAt(i); - if (ch == '%' && i < s.length - 2) { + if (ch === '%' && i < s.length - 2) { var code = s.substring(i + 1, i + 3); ret += String.fromCharCode(parseInt(code, 16)); i += 2; @@ -80,12 +80,12 @@ return ret; }, extendArray: function (sourceArray, targetArray, keyProperty) { - if (!targetArray || !sourceArray || sourceArray.length != targetArray.length) { + if (!targetArray || !sourceArray || sourceArray.length !== targetArray.length) { return false; } for (var i = 0; i < targetArray.length; i++) { - if (targetArray[i][keyProperty] == sourceArray[i][keyProperty]) { + if (targetArray[i][keyProperty] === sourceArray[i][keyProperty]) { angular.extend(targetArray[i], sourceArray[i]); } else { return false; @@ -110,7 +110,7 @@ if (angular.isObject(fromValue) || angular.isArray(fromValue)) { to[name] = this.copyObjectTo(from[name], to[name]); } else { - if (fromValue != toValue) { + if (fromValue !== toValue) { to[name] = fromValue; } } @@ -154,7 +154,7 @@ var count = 0; for (var i = 0; i < array.length; i++) { - count += (array[i] == value ? 1 : 0); + count += (array[i] === value ? 1 : 0); } return count; @@ -210,16 +210,16 @@ if (time < 1000) { value = time; - name = (value == 1 ? 'format.time.millisecond' : 'format.time.milliseconds'); + name = (value === 1 ? 'format.time.millisecond' : 'format.time.milliseconds'); } else if (time < 1000 * 60) { value = time / 1000; - name = (value == 1 ? 'format.time.second' : 'format.time.seconds'); + name = (value === 1 ? 'format.time.second' : 'format.time.seconds'); } else if (time < 1000 * 60 * 24) { value = time / 1000 / 60; - name = (value == 1 ? 'format.time.minute' : 'format.time.minutes'); + name = (value === 1 ? 'format.time.minute' : 'format.time.minutes'); } else { value = time / 1000 / 60 / 24; - name = (value == 1 ? 'format.time.hour' : 'format.time.hours'); + name = (value === 1 ? 'format.time.hour' : 'format.time.hours'); } options.push({ diff --git a/src/scripts/services/ariaNgFileService.js b/src/scripts/services/ariaNgFileService.js index 276b6cc..da902a0 100644 --- a/src/scripts/services/ariaNgFileService.js +++ b/src/scripts/services/ariaNgFileService.js @@ -17,7 +17,7 @@ for (var i = 0; i < fileFilters.length; i++) { var extension = fileFilters[i]; - if (extension == '*.*') { + if (extension === '*.*') { extensions.push(/.+$/); continue; } diff --git a/src/scripts/services/ariaNgMonitorService.js b/src/scripts/services/ariaNgMonitorService.js index 8d67628..3e99780 100644 --- a/src/scripts/services/ariaNgMonitorService.js +++ b/src/scripts/services/ariaNgMonitorService.js @@ -6,7 +6,7 @@ var globalStorageKey = 'global'; var getStorageCapacity = function (key) { - if (key == globalStorageKey) { + if (key === globalStorageKey) { return ariaNgConstants.globalStatStorageCapacity; } else { return ariaNgConstants.taskStatStorageCapacity; @@ -27,7 +27,7 @@ tooltip: { show: true, formatter: function (params) { - if (params[0].name == '') { + if (params[0].name === '') { return '
' + $translate.instant('No Data') + '
'; } diff --git a/src/scripts/services/ariaNgNotificationService.js b/src/scripts/services/ariaNgNotificationService.js index a659e62..e1c73d6 100644 --- a/src/scripts/services/ariaNgNotificationService.js +++ b/src/scripts/services/ariaNgNotificationService.js @@ -5,7 +5,7 @@ var isSupportBrowserNotification = $notification.isSupported; var isPermissionGranted = function (permission) { - return permission == 'granted'; + return permission === 'granted'; }; return { diff --git a/src/scripts/services/ariaNgSettingService.js b/src/scripts/services/ariaNgSettingService.js index 5b192b6..2a27fef 100644 --- a/src/scripts/services/ariaNgSettingService.js +++ b/src/scripts/services/ariaNgSettingService.js @@ -175,7 +175,7 @@ protocol = this.getProtocol(); } - return protocol == 'ws' || protocol == 'wss'; + return protocol === 'ws' || protocol === 'wss'; }, getSecret: function () { var value = getOption('secret');