forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatchessearch.js
More file actions
142 lines (121 loc) · 3.95 KB
/
matchessearch.js
File metadata and controls
142 lines (121 loc) · 3.95 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
gg.directive('matchessearch', ['Match', function(Match) {
return {
restrict: 'E',
template: JST['angular/templates/matches/search'](),
transclude: true,
replace: true,
scope: {
matches: '=collection',
identity: '=',
haveReplay: '@',
paginate: '@'
},
controller: ['$scope', '$element', '$http', '$urlFilter', '$timeout', 'Match', '$rootScope',
function($scope, $element, $http, $urlFilter, $timeout, Match, $rootScope) {
$rootScope.$watch('user', function(v) { $scope.user = v; })
$scope.refreshes = 0;
$scope.filter = $urlFilter;
$scope.filter.defaults = {
average_league: '',
game_type: '',
map_name: '',
identity_id: '',
race: '',
vs_race: '',
one_wins: '',
two_wins: '',
unit_one: '',
time_one: '',
unit_two: '',
time_two: '',
gateway: '',
category: ''
}
$scope.filter.hidden.push('identity_id');
$scope.filter.hidden.push('game_type');
// These are set via attributes, but just to be safe, let's hide them
$scope.filter.hidden.push('stats');
$scope.filter.hidden.push('replay');
$scope.filter.onChange = function(){
$scope.filter.apply($scope);
$scope.refresh();
}
// sets location to show the given match very bluntly
$scope.go = function(id) {
window.location = '/matches/' + id;
}
// bind our identity bind to urlFilter
$scope.$watch('identity', function(v) {
if(v)
$scope.filter.params.identity_id = v.id;
});
// The timeout here makes sure requests aren't being made too rapidly.
$scope.refresh = function(params) {
$timeout.cancel($scope.refresh_timer);
$scope.refresh_timer = $timeout(function() {
params = {
stats: $scope.stats,
replay: $scope.haveReplay ? true : false,
paginate: $scope.paginate ? true : false,
game_type: '1v1'
}
if($scope.identity)
params['identity_id'] = $scope.identity.id
$scope._matches = Match
.all($.extend($scope.filter.cleanParams(), params))
.then(function(result) {
$scope.matches = $scope.collection = result;
}); // then
// register pageview, only if it's not the initial refresh
$scope.refreshes = $scope.refreshes + 1;
if($scope.refreshes > 1)
gg.analytics.pageview();
// :(
// FIXME: https://github.com/angular/angular.js/issues/734
$timeout(function() {
$('.tooltipped').tipsy();
}, 500);
}, 300, true);
}
$.each($scope.filter.defaults, function(k,v) {
$scope.$watch(k, function(_v) {
$scope.filter.params.page = 1;
$scope.filter.params[k] = _v;
})
});
$scope.$watch('one_wins', function(v) {
if (v) {
delete $scope.filter.params.two_wins;
}
});
$scope.$watch('two_wins', function(v) {
if (v) {
delete $scope.filter.params.one_wins;
}
});
}],
link: function(scope, element, attrs) {
// pre-defined keywords for stats, giving us a way better picture of what
// we're actually requesting..
switch(attrs.stats) {
case 'player':
iid = scope.identity.id;
scope.stats = [
'apm(avg:[<'+iid+'])',
'apm(mavg:[<'+iid+'])',
'wpm(avg:[<'+iid+'])',
'wpm(mavg:[<'+iid+',E4])',
'spending_skill(avg:[<'+iid+'])',
'spending_skill(mavg:[<'+iid+'])',
'win(mavg:[<'+iid+'])',
'win(count:[<'+iid+'])',
'loss(count:[<'+iid+'])',
]
scope.stats = scope.stats.join(',');
break;
default:
scope.stats = attrs.stats;
}
}
}
}]);