peerOrderBy.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. (function () {
  2. 'use strict';
  3. angular.module('ariaNg').filter('peerOrderBy', ['$filter', 'ariaNgCommonService', function ($filter, ariaNgCommonService) {
  4. return function (array, type) {
  5. if (!angular.isArray(array)) {
  6. return array;
  7. }
  8. var orderType = ariaNgCommonService.parseOrderType(type);
  9. if (orderType === null) {
  10. return array;
  11. }
  12. if (orderType.type === 'address') {
  13. return $filter('orderBy')(array, ['ip', 'port'], orderType.reverse);
  14. } else if (orderType.type === 'client') {
  15. return $filter('orderBy')(array, ['client.name', 'client.version'], orderType.reverse);
  16. } else if (orderType.type === 'percent') {
  17. return $filter('orderBy')(array, ['completePercent'], orderType.reverse);
  18. } else if (orderType.type === 'dspeed') {
  19. return $filter('orderBy')(array, ['downloadSpeed'], orderType.reverse);
  20. } else if (orderType.type === 'uspeed') {
  21. return $filter('orderBy')(array, ['uploadSpeed'], orderType.reverse);
  22. } else {
  23. return array;
  24. }
  25. };
  26. }]);
  27. }());