-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.js
65 lines (50 loc) · 1.57 KB
/
controllers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
/* Controllers */
var userApp = angular.module('userApp', ['ngRoute']);
userApp.config(['$locationProvider', function($locationProvider){}]);
userApp.filter('limitFromTo', function(){
return function(input, from, to){
return (input != undefined)? input.slice(from, to) : '';
}
});
userApp.controller('UsersListCtrl',['$scope', '$http', '$location', function($scope, $http, $location) {
var url = 'http://api.randomuser.me/?results=100';
$scope.from = 0;
$scope.to = 25;
$http.get(url).success(function(data, status, headers, config) {
$scope.users = data['results'];
$scope.range = [];
for(var i = 0; i < $scope.users.length/25; i++){
$scope.range.push(i);
};
});
$scope.sortField = undefined;
$scope.reverse = false;
$scope.sort = function(fieldName){
if($scope.sortField === fieldName){
$scope.reverse = !$scope.reverse;
} else {
$scope.sortField = fieldName;
$scope.reverse = false;
}
};
$scope.isSortUp = function(fieldName){
return $scope.sortField === fieldName && !$scope.reverse;
};
$scope.isSortDown = function(fieldName){
return $scope.sortField === fieldName && $scope.reverse;
};
$scope.setPage = function(page){
if(page === 0){
$scope.from = 25 * page;
}else{
$scope.from = 25 * page + 1;
}
if(page === 0){
$scope.to = $scope.from + 25;
}else{
$scope.to = $scope.from + 25 -1;
}
$scope.currentPage = page;
}
}]);