forked from itinora/worldcup2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatches.svc.js
48 lines (41 loc) · 1.57 KB
/
matches.svc.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
angular.module('worldcup2015')
.service('MatchesSvc', ['_', 'moment', '$http', function(_, moment, $http) {
this.matches = null;
this.setMatches = function(matches) {
this.matches = matches;
}
this.getAllMatches = function() {
var params = {
'itinora': new Date().getTime()
};
var config = {
params: params
};
return $http.get("/static/data/matches.json", config);
};
this.getAllVenues = function() {
return _.unique(_.map(this.matches, function(match){
return {'city': match.city, 'stadium': match.stadium, selected: false};
}), false, function(v){
return v.city;
});
};
this.getAllMatchDates = function() {
return _.unique(_.sortBy(_.map(this.matches, function(match){
return {'date': match.match_date, selected: false, 'pool': match.pool};
}), 'date'), false, function(v){
return v.date;
});
}
this.getMatchesForDate = function(date) {
return _.where(this.matches, {match_date : date});
}
this.getMatchesForTeam = function(team) {
return _.filter(this.matches, function(match) {
return match.team_one_long === team.name || match.team_two_long === team.name;
});
}
this.getMatchesForVenue = function(venue) {
return _.where(this.matches, {city : venue.city});
}
}]);