refactor code

This commit is contained in:
MaysWind 2016-08-02 01:26:10 +08:00
parent 9fa9fa8d94
commit 0623374b39
16 changed files with 81 additions and 81 deletions

View file

@ -31,13 +31,13 @@
var refresh = function () { var refresh = function () {
var newPieceStatus = aria2TaskService.getPieceStatus(scope.bitField, scope.pieceCount); 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(); redraw();
return; return;
} }
for (var i = 0; i < pieces.length; i++) { for (var i = 0; i < pieces.length; i++) {
if (currentPieceStatus[i] != newPieceStatus[i]) { if (currentPieceStatus[i] !== newPieceStatus[i]) {
if (newPieceStatus[i]) { if (newPieceStatus[i]) {
pieces[i].addClass('piece-completed'); pieces[i].addClass('piece-completed');
} else { } else {

View file

@ -80,33 +80,33 @@
showTooltip(cause, 'error', causeParams); showTooltip(cause, 'error', causeParams);
}, },
getStatusFeedbackStyle: function () { getStatusFeedbackStyle: function () {
if (value == 'success') { if (value === 'success') {
return 'has-success'; return 'has-success';
} else if (value == 'failed') { } else if (value === 'failed') {
return 'has-warning'; return 'has-warning';
} else if (value == 'error') { } else if (value === 'error') {
return 'has-error'; return 'has-error';
} else { } else {
return ''; return '';
} }
}, },
getStatusIcon: function () { getStatusIcon: function () {
if (value == 'pending') { if (value === 'pending') {
return 'fa-hourglass-start'; return 'fa-hourglass-start';
} else if (value == 'saving') { } else if (value === 'saving') {
return 'fa-spin fa-pulse fa-spinner'; return 'fa-spin fa-pulse fa-spinner';
} else if (value == 'success') { } else if (value === 'success') {
return 'fa-check'; return 'fa-check';
} else if (value == 'failed') { } else if (value === 'failed') {
return 'fa-exclamation'; return 'fa-exclamation';
} else if (value == 'error') { } else if (value === 'error') {
return 'fa-times'; return 'fa-times';
} else { } else {
return ''; return '';
} }
}, },
isShowStatusIcon: function () { isShowStatusIcon: function () {
return this.getStatusIcon() != ''; return this.getStatusIcon() !== '';
} }
}; };
})(); })();
@ -131,27 +131,27 @@
return; return;
} }
if (scope.option.required && optionValue == '') { if (scope.option.required && optionValue === '') {
scope.optionStatus.setError('Option value cannot be empty!'); scope.optionStatus.setError('Option value cannot be empty!');
return; return;
} }
if (scope.option.type == 'integer' && !/^-?\d+$/.test(optionValue)) { if (scope.option.type === 'integer' && !/^-?\d+$/.test(optionValue)) {
scope.optionStatus.setError('Input number is invalid!'); scope.optionStatus.setError('Input number is invalid!');
return; 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!'); scope.optionStatus.setError('Input number is invalid!');
return; 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; var number = optionValue;
if (scope.option.type == 'integer') { if (scope.option.type === 'integer') {
number = parseInt(optionValue); number = parseInt(optionValue);
} else if (scope.option.type == 'float') { } else if (scope.option.type === 'float') {
number = parseFloat(optionValue); number = parseFloat(optionValue);
} }

View file

@ -57,7 +57,7 @@
value = (value === true || value === 'true'); value = (value === true || value === 'true');
if (showTooltip == value) { if (showTooltip === value) {
return; return;
} }

View file

@ -9,15 +9,15 @@
var orderType = ariaNgCommonService.parseOrderType(type); var orderType = ariaNgCommonService.parseOrderType(type);
if (orderType == null) { if (orderType === null) {
return array; return array;
} }
if (orderType.type == 'name') { if (orderType.type === 'name') {
return $filter('orderBy')(array, ['fileName'], orderType.reverse); return $filter('orderBy')(array, ['fileName'], orderType.reverse);
} else if (orderType.type == 'size') { } else if (orderType.type === 'size') {
return $filter('orderBy')(array, ['length'], orderType.reverse); return $filter('orderBy')(array, ['length'], orderType.reverse);
} else if (orderType.type == 'percent') { } else if (orderType.type === 'percent') {
return $filter('orderBy')(array, ['completePercent'], orderType.reverse); return $filter('orderBy')(array, ['completePercent'], orderType.reverse);
} else { } else {
return array; return array;

View file

@ -9,19 +9,19 @@
var orderType = ariaNgCommonService.parseOrderType(type); var orderType = ariaNgCommonService.parseOrderType(type);
if (orderType == null) { if (orderType === null) {
return array; return array;
} }
if (orderType.type == 'address') { if (orderType.type === 'address') {
return $filter('orderBy')(array, ['ip', 'port'], orderType.reverse); 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); 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); return $filter('orderBy')(array, ['completePercent'], orderType.reverse);
} else if (orderType.type == 'dspeed') { } else if (orderType.type === 'dspeed') {
return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse); return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse);
} else if (orderType.type == 'uspeed') { } else if (orderType.type === 'uspeed') {
return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse); return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse);
} else { } else {
return array; return array;

View file

@ -9,21 +9,21 @@
var orderType = ariaNgCommonService.parseOrderType(type); var orderType = ariaNgCommonService.parseOrderType(type);
if (orderType == null) { if (orderType === null) {
return array; return array;
} }
if (orderType.type == 'name') { if (orderType.type === 'name') {
return $filter('orderBy')(array, ['taskName'], orderType.reverse); return $filter('orderBy')(array, ['taskName'], orderType.reverse);
} else if (orderType.type == 'size') { } else if (orderType.type === 'size') {
return $filter('orderBy')(array, ['totalLength'], orderType.reverse); return $filter('orderBy')(array, ['totalLength'], orderType.reverse);
} else if (orderType.type == 'percent') { } else if (orderType.type === 'percent') {
return $filter('orderBy')(array, ['completePercent'], orderType.reverse); 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); 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); return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse);
} else if (orderType.type == 'uspeed') { } else if (orderType.type === 'uspeed') {
return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse); return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse);
} else { } else {
return array; return array;

View file

@ -7,21 +7,21 @@
return ''; return '';
} }
if (task.status == 'active') { if (task.status === 'active') {
if (task.seeder === true || task.seeder === 'true') { if (task.seeder === true || task.seeder === 'true') {
return 'Seeding'; return 'Seeding';
} else { } else {
return 'Downloading'; return 'Downloading';
} }
} else if (task.status == 'waiting') { } else if (task.status === 'waiting') {
return 'Waiting'; return 'Waiting';
} else if (task.status == 'paused') { } else if (task.status === 'paused') {
return 'Paused'; return 'Paused';
} else if (task.status == 'complete') { } else if (task.status === 'complete') {
return 'Completed'; return 'Completed';
} else if (task.status == 'error') { } else if (task.status === 'error') {
return (task.errorCode ? 'format.task.error-occurred' : 'Error Occurred'); return (task.errorCode ? 'format.task.error-occurred' : 'Error Occurred');
} else if (task.status == 'removed') { } else if (task.status === 'removed') {
return 'Removed'; return 'Removed';
} else { } else {
return ''; return '';

View file

@ -15,7 +15,7 @@
var onBtDownloadCompleteCallbacks = []; var onBtDownloadCompleteCallbacks = [];
var checkIsSystemMethod = function (methodName) { var checkIsSystemMethod = function (methodName) {
return methodName.indexOf(aria2RpcConstants.rpcSystemServiceName + '.') == 0; return methodName.indexOf(aria2RpcConstants.rpcSystemServiceName + '.') === 0;
}; };
var getAria2MethodFullName = function (methodName) { var getAria2MethodFullName = function (methodName) {
@ -172,7 +172,7 @@
if (arguments.length > 2) { if (arguments.length > 2) {
for (var i = 2; i < arguments.length; i++) { 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]); finalParams.push(arguments[i]);
} }
} }

View file

@ -18,21 +18,21 @@
return { return {
getAvailableGlobalOptionsKeys: function (type) { getAvailableGlobalOptionsKeys: function (type) {
if (type == 'basic') { if (type === 'basic') {
return aria2GlobalAvailableOptions.basicOptions; return aria2GlobalAvailableOptions.basicOptions;
} else if (type == 'http-ftp-sftp') { } else if (type === 'http-ftp-sftp') {
return aria2GlobalAvailableOptions.httpFtpSFtpOptions; return aria2GlobalAvailableOptions.httpFtpSFtpOptions;
} else if (type == 'http') { } else if (type === 'http') {
return aria2GlobalAvailableOptions.httpOptions; return aria2GlobalAvailableOptions.httpOptions;
} else if (type == 'ftp-sftp') { } else if (type === 'ftp-sftp') {
return aria2GlobalAvailableOptions.ftpSFtpOptions; return aria2GlobalAvailableOptions.ftpSFtpOptions;
} else if (type == 'bt') { } else if (type === 'bt') {
return aria2GlobalAvailableOptions.btOptions; return aria2GlobalAvailableOptions.btOptions;
} else if (type == 'metalink') { } else if (type === 'metalink') {
return aria2GlobalAvailableOptions.metalinkOptions; return aria2GlobalAvailableOptions.metalinkOptions;
} else if (type == 'rpc') { } else if (type === 'rpc') {
return aria2GlobalAvailableOptions.rpcOptions; return aria2GlobalAvailableOptions.rpcOptions;
} else if (type == 'advanced') { } else if (type === 'advanced') {
return aria2GlobalAvailableOptions.advancedOptions; return aria2GlobalAvailableOptions.advancedOptions;
} else { } else {
return false; return false;
@ -58,7 +58,7 @@
continue; continue;
} }
if (option.activeReadonly && status == 'active') { if (option.activeReadonly && status === 'active') {
optionKey.readonly = true; optionKey.readonly = true;
} }
@ -108,7 +108,7 @@
descriptionKey: 'options.' + key + '.description' descriptionKey: 'options.' + key + '.description'
}, option); }, option);
if (option.type == 'boolean') { if (option.type === 'boolean') {
option.options = ['true', 'false']; option.options = ['true', 'false'];
} }

View file

@ -15,7 +15,7 @@
var index = path.lastIndexOf('/'); var index = path.lastIndexOf('/');
if (index <= 0 || index == path.length) { if (index <= 0 || index === path.length) {
return path; return path;
} }
@ -23,7 +23,7 @@
}; };
var calculateDownloadRemainTime = function (remainBytes, downloadSpeed) { var calculateDownloadRemainTime = function (remainBytes, downloadSpeed) {
if (downloadSpeed == 0) { if (downloadSpeed === 0) {
return 0; return 0;
} }
@ -71,7 +71,7 @@
for (var j = 1; j <= 4; j++) { for (var j = 1; j <= 4; j++) {
var bit = (1 << (4 - j)); var bit = (1 << (4 - j));
var isCompleted = (bitSet & bit) == bit; var isCompleted = (bitSet & bit) === bit;
pieces[pieceIndex++] = isCompleted; pieces[pieceIndex++] = isCompleted;
@ -91,7 +91,7 @@
for (var i = 0; i < pieces.length; i++) { for (var i = 0; i < pieces.length; i++) {
var isCompleted = pieces[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++; combinedPieces[combinedPieces.length - 1].count++;
} else { } else {
combinedPieces.push({ combinedPieces.push({
@ -126,7 +126,7 @@
task.completedPieces = ariaNgCommonService.countArray(pieceStatus, true); task.completedPieces = ariaNgCommonService.countArray(pieceStatus, true);
task.pieceLength = parseInt(task.pieceLength); task.pieceLength = parseInt(task.pieceLength);
task.idle = task.downloadSpeed == 0; task.idle = task.downloadSpeed === 0;
task.remainTime = calculateDownloadRemainTime(task.remainLength, task.downloadSpeed); task.remainTime = calculateDownloadRemainTime(task.remainLength, task.downloadSpeed);
task.seeder = (task.seeder === true || task.seeder === 'true'); task.seeder = (task.seeder === true || task.seeder === 'true');
@ -176,7 +176,7 @@
peer.uploadSpeed = downstreamFromSpeed; peer.uploadSpeed = downstreamFromSpeed;
peer.seeder = (peer.seeder === true || peer.seeder === 'true'); peer.seeder = (peer.seeder === true || peer.seeder === 'true');
if (completedPieceCount == localTaskCompletedPieceCount && peer.completePercent != localTaskCompletedPercent) { if (completedPieceCount === localTaskCompletedPieceCount && peer.completePercent !== localTaskCompletedPercent) {
peer.completePercent = localTaskCompletedPercent; peer.completePercent = localTaskCompletedPercent;
} }
@ -184,7 +184,7 @@
var peerId = ariaNgCommonService.decodePercentEncodedString(peer.peerId); var peerId = ariaNgCommonService.decodePercentEncodedString(peer.peerId);
var clientInfo = (peerId ? bittorrentPeeridService.parseClient(peerId) : null); var clientInfo = (peerId ? bittorrentPeeridService.parseClient(peerId) : null);
if (clientInfo && clientInfo.client != 'unknown') { if (clientInfo && clientInfo.client !== 'unknown') {
var client = { var client = {
name: (clientInfo.client ? clientInfo.client.trim() : ''), name: (clientInfo.client ? clientInfo.client.trim() : ''),
version: (clientInfo.version ? clientInfo.version.trim() : '') version: (clientInfo.version ? clientInfo.version.trim() : '')
@ -238,11 +238,11 @@
getTaskList: function (type, full, callback, silent) { getTaskList: function (type, full, callback, silent) {
var invokeMethod = null; var invokeMethod = null;
if (type == 'downloading') { if (type === 'downloading') {
invokeMethod = aria2RpcService.tellActive; invokeMethod = aria2RpcService.tellActive;
} else if (type == 'waiting') { } else if (type === 'waiting') {
invokeMethod = aria2RpcService.tellWaiting; invokeMethod = aria2RpcService.tellWaiting;
} else if (type == 'stopped') { } else if (type === 'stopped') {
invokeMethod = aria2RpcService.tellStopped; invokeMethod = aria2RpcService.tellStopped;
} else { } else {
return; return;
@ -410,7 +410,7 @@
var stoppedTaskGids = []; var stoppedTaskGids = [];
for (var i = 0; i < tasks.length; i++) { 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); stoppedTaskGids.push(tasks[i].gid);
} else { } else {
runningTaskGids.push(tasks[i].gid); runningTaskGids.push(tasks[i].gid);
@ -550,7 +550,7 @@
if (completedPieceCount > maxCompletedPieceCount) { if (completedPieceCount > maxCompletedPieceCount) {
maxCompletedPieceCount = completedPieceCount; maxCompletedPieceCount = completedPieceCount;
maxCompletedPercent = peer.completePercent; maxCompletedPercent = peer.completePercent;
} else if (completedPieceCount == maxCompletedPieceCount && peer.completePercent > maxCompletedPercent) { } else if (completedPieceCount === maxCompletedPieceCount && peer.completePercent > maxCompletedPercent) {
maxCompletedPercent = peer.completePercent; maxCompletedPercent = peer.completePercent;
} }
} }

View file

@ -60,7 +60,7 @@
}; };
var getSocketClient = function () { var getSocketClient = function () {
if (socketClient == null) { if (socketClient === null) {
socketClient = $websocket(rpcUrl); socketClient = $websocket(rpcUrl);
socketClient.onMessage(function (message) { socketClient.onMessage(function (message) {

View file

@ -37,7 +37,7 @@
cancelButtonText: $translate.instant('Cancel') cancelButtonText: $translate.instant('Cancel')
}; };
if (type == 'warning') { if (type === 'warning') {
options.confirmButtonColor = '#F39C12'; options.confirmButtonColor = '#F39C12';
} }
@ -68,7 +68,7 @@
for (var i = 0; i < s.length; i++) { for (var i = 0; i < s.length; i++) {
var ch = s.charAt(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); var code = s.substring(i + 1, i + 3);
ret += String.fromCharCode(parseInt(code, 16)); ret += String.fromCharCode(parseInt(code, 16));
i += 2; i += 2;
@ -80,12 +80,12 @@
return ret; return ret;
}, },
extendArray: function (sourceArray, targetArray, keyProperty) { extendArray: function (sourceArray, targetArray, keyProperty) {
if (!targetArray || !sourceArray || sourceArray.length != targetArray.length) { if (!targetArray || !sourceArray || sourceArray.length !== targetArray.length) {
return false; return false;
} }
for (var i = 0; i < targetArray.length; i++) { 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]); angular.extend(targetArray[i], sourceArray[i]);
} else { } else {
return false; return false;
@ -110,7 +110,7 @@
if (angular.isObject(fromValue) || angular.isArray(fromValue)) { if (angular.isObject(fromValue) || angular.isArray(fromValue)) {
to[name] = this.copyObjectTo(from[name], to[name]); to[name] = this.copyObjectTo(from[name], to[name]);
} else { } else {
if (fromValue != toValue) { if (fromValue !== toValue) {
to[name] = fromValue; to[name] = fromValue;
} }
} }
@ -154,7 +154,7 @@
var count = 0; var count = 0;
for (var i = 0; i < array.length; i++) { for (var i = 0; i < array.length; i++) {
count += (array[i] == value ? 1 : 0); count += (array[i] === value ? 1 : 0);
} }
return count; return count;
@ -210,16 +210,16 @@
if (time < 1000) { if (time < 1000) {
value = time; 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) { } else if (time < 1000 * 60) {
value = time / 1000; 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) { } else if (time < 1000 * 60 * 24) {
value = time / 1000 / 60; value = time / 1000 / 60;
name = (value == 1 ? 'format.time.minute' : 'format.time.minutes'); name = (value === 1 ? 'format.time.minute' : 'format.time.minutes');
} else { } else {
value = time / 1000 / 60 / 24; 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({ options.push({

View file

@ -17,7 +17,7 @@
for (var i = 0; i < fileFilters.length; i++) { for (var i = 0; i < fileFilters.length; i++) {
var extension = fileFilters[i]; var extension = fileFilters[i];
if (extension == '*.*') { if (extension === '*.*') {
extensions.push(/.+$/); extensions.push(/.+$/);
continue; continue;
} }

View file

@ -6,7 +6,7 @@
var globalStorageKey = 'global'; var globalStorageKey = 'global';
var getStorageCapacity = function (key) { var getStorageCapacity = function (key) {
if (key == globalStorageKey) { if (key === globalStorageKey) {
return ariaNgConstants.globalStatStorageCapacity; return ariaNgConstants.globalStatStorageCapacity;
} else { } else {
return ariaNgConstants.taskStatStorageCapacity; return ariaNgConstants.taskStatStorageCapacity;
@ -27,7 +27,7 @@
tooltip: { tooltip: {
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>' + $translate.instant('No Data') + '</div>';
} }

View file

@ -5,7 +5,7 @@
var isSupportBrowserNotification = $notification.isSupported; var isSupportBrowserNotification = $notification.isSupported;
var isPermissionGranted = function (permission) { var isPermissionGranted = function (permission) {
return permission == 'granted'; return permission === 'granted';
}; };
return { return {

View file

@ -175,7 +175,7 @@
protocol = this.getProtocol(); protocol = this.getProtocol();
} }
return protocol == 'ws' || protocol == 'wss'; return protocol === 'ws' || protocol === 'wss';
}, },
getSecret: function () { getSecret: function () {
var value = getOption('secret'); var value = getOption('secret');