forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplays.js
More file actions
61 lines (52 loc) · 1.81 KB
/
replays.js
File metadata and controls
61 lines (52 loc) · 1.81 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
gg.directive('replays', ['Replay', function(Replay) {
return {
restrict: 'E',
template: JST['angular/templates/replays/index'](),
transclude: true,
replace: true,
scope: {},
controller: ['$scope', '$element', '$http', '$location', '$urlFilter', '$timeout', '$rootScope',
function($scope, $element, $http, $location, $urlFilter, $timeout, $rootScope) {
$scope.refreshes = 0;
$scope.filter = $urlFilter;
$scope.filter.defaults = {
}
$scope.filter.onChange = function(){
$scope.filter.apply($scope);
$scope.refresh();
}
// sets location to show the given player very bluntly
$scope.go = function(state, id) {
if (state == "done") {
window.location = '/matches/' + id;
}
}
$scope.refresh = function(params) {
$timeout.cancel($scope.refresh_timer);
$scope.refresh_timer = $timeout(function() {
$scope._players = Replay
.all($scope.filter.cleanParams())
.then(function(result) {
$scope.replays = $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();
}, 200, 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();
}
}
}]);