forked from tykayn/funky-framadate-front
⚡ really fetch a poll by id
This commit is contained in:
parent
ff5c11e79c
commit
123a0b1c80
@ -24,7 +24,7 @@ export class PollConfig {
|
|||||||
description: string = 'ma description';
|
description: string = 'ma description';
|
||||||
myName: string = 'mon pseudo';
|
myName: string = 'mon pseudo';
|
||||||
myComment: string = 'wouah trop bien framadate!';
|
myComment: string = 'wouah trop bien framadate!';
|
||||||
isAdmin: boolean = false;
|
isAdmin: boolean = true;
|
||||||
myEmail: string = "tktest@tktest.com";
|
myEmail: string = "tktest@tktest.com";
|
||||||
myPolls: any = mockMyPolls;// list of retrieved polls from the backend api
|
myPolls: any = mockMyPolls;// list of retrieved polls from the backend api
|
||||||
// date specific poll, we have the choice to setup different hours (timeList) for all possible dates (dateList), or use the same hours for all dates
|
// date specific poll, we have the choice to setup different hours (timeList) for all possible dates (dateList), or use the same hours for all dates
|
||||||
|
@ -3,6 +3,7 @@ import {BaseComponent} from "../base-page/base.component";
|
|||||||
import {ConfigService} from "../../services/config.service";
|
import {ConfigService} from "../../services/config.service";
|
||||||
import {mockPoll3} from "../../config/mocks/mock-poll3";
|
import {mockPoll3} from "../../config/mocks/mock-poll3";
|
||||||
import {mockComments} from "../../config/mocks/mock-comments";
|
import {mockComments} from "../../config/mocks/mock-comments";
|
||||||
|
import {ActivatedRoute} from "@angular/router";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'framadate-poll-display',
|
selector: 'framadate-poll-display',
|
||||||
@ -14,13 +15,28 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
|
|||||||
private pollConfigFetched = mockPoll3;
|
private pollConfigFetched = mockPoll3;
|
||||||
private comments = mockComments;
|
private comments = mockComments;
|
||||||
|
|
||||||
constructor(public config: ConfigService) {
|
constructor(public config: ConfigService,
|
||||||
|
public activeRoute: ActivatedRoute) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// fetch poll with its ID or slug.
|
// fetch poll with its ID or slug.
|
||||||
// store it in the poll property here
|
const id = this.activeRoute.snapshot.params.poll;
|
||||||
|
if (id) {
|
||||||
|
this.config.pollId = id;
|
||||||
|
// store it in the poll property here
|
||||||
|
this.config.getPollById(id).subscribe(
|
||||||
|
(res: any) => {
|
||||||
|
this.pollConfigFetched = res;
|
||||||
|
}, (e) => {
|
||||||
|
// handle need for a password
|
||||||
|
this.config.handleError(e)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -219,18 +219,12 @@ export class ConfigService extends PollConfig {
|
|||||||
* api/v1/poll/{id}
|
* api/v1/poll/{id}
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
getPollById(id: string, password: string) {
|
getPollById(id: string, password?: string) {
|
||||||
|
|
||||||
this.http
|
return this.http
|
||||||
.get(`${this.baseHref}/poll/${id}`,
|
.get(`${this.baseHref}/poll/${id}`,
|
||||||
this.makeHeaders({body: password}))
|
this.makeHeaders({body: password}))
|
||||||
.subscribe(
|
|
||||||
(res: any) => {
|
|
||||||
this.myPolls = res.data;
|
|
||||||
}, (e) => {
|
|
||||||
this.handleError(e)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -277,7 +271,7 @@ export class ConfigService extends PollConfig {
|
|||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
createPollFromConfig(config: any) {
|
createPollFromConfig(config: any) {
|
||||||
this.loading= true;
|
this.loading = true;
|
||||||
return this.http.post(`${this.baseHref}/poll`,
|
return this.http.post(`${this.baseHref}/poll`,
|
||||||
this.makeHeaders({config: config}))
|
this.makeHeaders({config: config}))
|
||||||
.subscribe((res: any) => {
|
.subscribe((res: any) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user