-
Notifications
You must be signed in to change notification settings - Fork 2
/
team.service.ts
63 lines (50 loc) 路 1.35 KB
/
team.service.ts
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
import {Injectable, EventEmitter, Output} from '@angular/core';
import 'rxjs/add/operator/map';
import {Http} from "@angular/http";
@Injectable()
export class TeamService {
currentTeam: string; // The team name
teamSentimentData: Object; // The corresponding data
@Output()
sentimentDataUpdated: EventEmitter<any> = new EventEmitter();
constructor(
private http: Http
) { }
/**
* Set the currently selected team locally
* @param currentTeam
*/
setTeam(currentTeam){
this.currentTeam = currentTeam;
this.fetchTeamSentimentData();
}
/**
* Get the currently selected local team
* @returns {string}
*/
getTeam(){
return this.currentTeam;
}
/**
* Returns team sentiment data
* (which will have already been fetched, when team was set)
* @returns {Object}
*/
getTeamSentimentData(){
return this.teamSentimentData;
}
/**
* Request to the API
* Called whenever team changes
* Fetches sentiment data for any given team
*/
fetchTeamSentimentData(){
this.http.get('/api/team-sentiment/'+this.currentTeam)
.map(res => res.json())
.subscribe(teamSentimentData => {
this.teamSentimentData = teamSentimentData;
this.sentimentDataUpdated.emit(this.teamSentimentData);
}
);
}
}