refactor code

This commit is contained in:
MaysWind 2016-06-26 14:06:20 +08:00
parent 79246e0d78
commit 8966750ac8
6 changed files with 24 additions and 24 deletions

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').filter('fileOrderBy', ['orderByFilter', 'ariaNgCommonService', function (orderByFilter, ariaNgCommonService) {
angular.module('ariaNg').filter('fileOrderBy', ['$filter', 'ariaNgCommonService', function ($filter, ariaNgCommonService) {
return function (array, type) {
if (!angular.isArray(array)) {
return array;
@ -14,11 +14,11 @@
}
if (orderType.type == 'name') {
return orderByFilter(array, ['fileName'], orderType.reverse);
return $filter('orderBy')(array, ['fileName'], orderType.reverse);
} else if (orderType.type == 'size') {
return orderByFilter(array, ['length'], orderType.reverse);
return $filter('orderBy')(array, ['length'], orderType.reverse);
} else if (orderType.type == 'percent') {
return orderByFilter(array, ['completePercent'], orderType.reverse);
return $filter('orderBy')(array, ['completePercent'], orderType.reverse);
} else {
return array;
}

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').filter('peerOrderBy', ['orderByFilter', 'ariaNgCommonService', function (orderByFilter, ariaNgCommonService) {
angular.module('ariaNg').filter('peerOrderBy', ['$filter', 'ariaNgCommonService', function ($filter, ariaNgCommonService) {
return function (array, type) {
if (!angular.isArray(array)) {
return array;
@ -14,13 +14,13 @@
}
if (orderType.type == 'address') {
return orderByFilter(array, ['ip', 'port'], orderType.reverse);
return $filter('orderBy')(array, ['ip', 'port'], orderType.reverse);
} else if (orderType.type == 'percent') {
return orderByFilter(array, ['completePercent'], orderType.reverse);
return $filter('orderBy')(array, ['completePercent'], orderType.reverse);
} else if (orderType.type == 'dspeed') {
return orderByFilter(array, ['downloadSpeed'], orderType.reverse);
return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse);
} else if (orderType.type == 'uspeed') {
return orderByFilter(array, ['uploadSpeed'], orderType.reverse);
return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse);
} else {
return array;
}

View file

@ -1,12 +1,12 @@
(function () {
'use strict';
angular.module('ariaNg').filter('percent', ['numberFilter', function (numberFilter) {
angular.module('ariaNg').filter('percent', ['$filter', function ($filter) {
return function (value, precision) {
var ratio = Math.pow(10, precision);
var result = parseInt(value * ratio) / ratio;
return numberFilter(result, precision);
return $filter('number')(result, precision);
}
}]);
})();

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').filter('taskOrderBy', ['orderByFilter', 'ariaNgCommonService', function (orderByFilter, ariaNgCommonService) {
angular.module('ariaNg').filter('taskOrderBy', ['$filter', 'ariaNgCommonService', function ($filter, ariaNgCommonService) {
return function (array, type) {
if (!angular.isArray(array)) {
return array;
@ -14,17 +14,17 @@
}
if (orderType.type == 'name') {
return orderByFilter(array, ['taskName'], orderType.reverse);
return $filter('orderBy')(array, ['taskName'], orderType.reverse);
} else if (orderType.type == 'size') {
return orderByFilter(array, ['totalLength'], orderType.reverse);
return $filter('orderBy')(array, ['totalLength'], orderType.reverse);
} else if (orderType.type == 'percent') {
return orderByFilter(array, ['completePercent'], orderType.reverse);
return $filter('orderBy')(array, ['completePercent'], orderType.reverse);
} else if (orderType.type == 'remain') {
return orderByFilter(array, ['idle', 'remainTime', 'remainLength'], orderType.reverse);
return $filter('orderBy')(array, ['idle', 'remainTime', 'remainLength'], orderType.reverse);
} else if (orderType.type == 'dspeed') {
return orderByFilter(array, ['downloadSpeed'], orderType.reverse);
return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse);
} else if (orderType.type == 'uspeed') {
return orderByFilter(array, ['uploadSpeed'], orderType.reverse);
return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse);
} else {
return array;
}

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').filter('readableVolumn', ['numberFilter', function (numberFilter) {
angular.module('ariaNg').filter('readableVolumn', ['$filter', function ($filter) {
var units = [ 'B', 'KB', 'MB', 'GB' ];
var defaultFractionSize = 2;
@ -29,7 +29,7 @@
}
}
value = numberFilter(value, fractionSize);
value = $filter('number')(value, fractionSize);
return value + ' ' + unit;
}

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgMonitorService', ['$translate', 'moment', 'ariaNgConstants', 'readableVolumnFilter', function ($translate, moment, ariaNgConstants, readableVolumnFilter) {
angular.module('ariaNg').factory('ariaNgMonitorService', ['$filter', '$translate', 'moment', 'ariaNgConstants', function ($filter, $translate, moment, ariaNgConstants) {
var storagesInMemory = {};
var globalStorageKey = 'global';
@ -32,8 +32,8 @@
}
var time = moment(params[0].name, 'X').format('HH:mm:ss');
var uploadSpeed = readableVolumnFilter(params[0].value) + '/s';
var downloadSpeed = readableVolumnFilter(params[1].value) + '/s';
var uploadSpeed = $filter('readableVolumn')(params[0].value) + '/s';
var downloadSpeed = $filter('readableVolumn')(params[1].value) + '/s';
return '<div>' + time + '</div>'
+ '<div><i class="icon-download fa fa-arrow-down"></i> ' + downloadSpeed +'</div>'
@ -52,7 +52,7 @@
type: 'value',
axisLabel: {
formatter: function (value) {
return readableVolumnFilter(value, 0);
return $filter('readableVolumn')(value, 0);
}
}
},