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 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 {

View file

@ -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);
}

View file

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

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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 '';

View file

@ -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]);
}
}

View file

@ -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'];
}

View file

@ -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;
}
}

View file

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

View file

@ -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({

View file

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

View file

@ -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 '<div>' + $translate.instant('No Data') + '</div>';
}

View file

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

View file

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