Skip to content

Commit b86c6d4

Browse files
committed
Poll service implementation
1 parent 9b577ba commit b86c6d4

File tree

3 files changed

+61
-14
lines changed

3 files changed

+61
-14
lines changed

src/app/master/master.component.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IssueSource } from './issue-source';
66
import { DefaultSourceComponent } from './default-source/default-source.component';
77
import { Statistic } from '../statistic';
88
import { Topic } from '../topic';
9+
import { PollService } from '../poll.service';
910

1011
@Component({
1112
selector: 'app-master',
@@ -29,22 +30,21 @@ export class MasterComponent implements OnInit, AfterViewInit {
2930
flipped: boolean;
3031

3132
constructor(
32-
private route: ActivatedRoute) {
33+
private route: ActivatedRoute,
34+
private pollService: PollService) {
3335

3436
}
3537

3638
ngOnInit() {
37-
// TODO: Read from service
38-
var session = new Session();
39-
session.id = +this.route.snapshot.paramMap.get('id');
40-
session.name = "Hi";
41-
this.session = session;
42-
43-
this.flipped = true;
44-
this.votes = [
45-
{id: 1, value: '1', active: false,name: 'Thomas',confirmed: true,placed: true, canDelete: true},
46-
{id: 1, value: '3', active: false,name: 'Sandra',confirmed: true,placed: true, canDelete: true},
47-
];
39+
this.session.id = +this.route.snapshot.paramMap.get('id');
40+
this.pollService.currentPoll(this.session).subscribe(pr => {
41+
this.session.name = pr.name;
42+
this.flipped = pr.flipped;
43+
this.votes = pr.votes;
44+
if (pr.topic === '')
45+
return;
46+
this.teamComplete = true;
47+
});
4848
this.statistics = [
4949
{ name: "Test", value: "123", enabled: true}
5050
]

src/app/poll.service.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
11
import { Injectable } from '@angular/core';
2+
import { HttpClient } from '@angular/common/http';
3+
import { Session } from './session';
4+
import { MemberVote } from './card';
5+
import { Observable, of } from 'rxjs';
6+
import { Topic } from './topic';
7+
import { Member } from './member';
8+
9+
export class PollResponse {
10+
name: string;
11+
timestamp: number;
12+
13+
topic: string;
14+
description: string;
15+
url: string;
16+
17+
flipped: boolean;
18+
consensus: boolean;
19+
20+
votes: MemberVote[];
21+
}
222

323
@Injectable({
424
providedIn: 'root'
525
})
626
export class PollService {
727

8-
constructor() { }
28+
constructor(private http: HttpClient) { }
29+
30+
currentPoll(session: Session) : Observable<PollResponse> {
31+
return this.http.get<PollResponse>('/api/poll/current/' + session.id);
32+
}
33+
34+
getTopic(session: Session) : Observable<Topic> {
35+
return this.http.get<Topic>('/api/poll/topic/' + session.id);
36+
}
37+
38+
setTopic(session: Session, topic: Topic) {
39+
this.http.post('/api/poll/topic/' + session.id, topic)
40+
}
41+
42+
placeVote(session: Session, member: Member, vote: string) {
43+
var wrapper = {
44+
vote: vote
45+
};
46+
var url = '/api/poll/vote/' + session.id + '/' + member.id;
47+
this.http.post(url, wrapper);
48+
}
49+
50+
retractVote(session: Session, member: Member, vote: string) {
51+
var url = '/api/poll/vote/' + session.id + '/' + member.id;
52+
this.http.delete(url);
53+
}
954
}

src/app/topic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
export class Topic {
22
id: number;
33

4-
name: string;
4+
topic: string;
55

66
description: string;
77

88
url: string;
99

10+
votable: boolean;
11+
1012
constructor() {
1113

1214
}

0 commit comments

Comments
 (0)