forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayers.js
More file actions
65 lines (55 loc) · 1.85 KB
/
players.js
File metadata and controls
65 lines (55 loc) · 1.85 KB
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
64
65
gg.directive('players', ['Player', function(Player) {
return {
restrict: 'E',
template: JST['angular/templates/players/index'](),
transclude: true,
replace: true,
scope: {},
controller: ['$scope', '$element', '$http', '$location', '$urlFilter', '$timeout',
function($scope, $element, $http, $location, $urlFilter, $timeout) {
$scope.refreshes = 0;
$scope.filter = $urlFilter;
$scope.filter.defaults = {
name: '',
race: '',
current_highest_league: '',
game_type: '',
gateway: ''
}
$scope.filter.onChange = function(){
$scope.filter.apply($scope);
$scope.refresh();
}
// sets location to show the given player very bluntly
$scope.go = function(id) {
window.location = '/players/' + id;
}
$scope.refresh = function(params) {
$timeout.cancel($scope.refresh_timer);
$scope.refresh_timer = $timeout(function() {
$scope._players = Player
.all($scope.filter.cleanParams())
.then(function(result) {
$scope.players = $scope.collection = result;
});
// register pageview, only if it's not the initial refresh
$scope.refreshes = $scope.refreshes + 1;
if($scope.refreshes > 1)
gg.analytics.pageview();
}, 300, true);
}
// To implement Issue #16 the most obvious and simple way, albeit "dirty"
// we don't ng-model directly on filter.params anymore and instead
// ..do this (and apply these values above, on onChange too)
$.each($scope.filter.defaults, function(k,v) {
$scope.$watch(k, function(_v) {
$scope.filter.params.page = 1;
$scope.filter.params[k] = _v;
})
});
}],
link: function(scope) {
scope.refresh();
}
}
}]);