This repository has been archived on 2022-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
AriaNg/src/scripts/filters/peerOrderBy.js
2016-06-26 14:06:20 +08:00

30 lines
1.1 KiB
JavaScript

(function () {
'use strict';
angular.module('ariaNg').filter('peerOrderBy', ['$filter', 'ariaNgCommonService', function ($filter, ariaNgCommonService) {
return function (array, type) {
if (!angular.isArray(array)) {
return array;
}
var orderType = ariaNgCommonService.parseOrderType(type);
if (orderType == null) {
return array;
}
if (orderType.type == 'address') {
return $filter('orderBy')(array, ['ip', 'port'], orderType.reverse);
} else if (orderType.type == 'percent') {
return $filter('orderBy')(array, ['completePercent'], orderType.reverse);
} else if (orderType.type == 'dspeed') {
return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse);
} else if (orderType.type == 'uspeed') {
return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse);
} else {
return array;
}
}
}]);
})();