mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {BaseComponent} from "../base-page/base.component";
|
|
import {ConfigService} from "../../services/config.service";
|
|
import {mockComments} from "../../config/mocks/mock-comments";
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
import {environment} from "../../../environments/environment";
|
|
import {mockPoll3} from "../../config/mocks/mock-poll3";
|
|
|
|
@Component({
|
|
selector: 'framadate-poll-display',
|
|
templateUrl: './poll-display.component.html',
|
|
styleUrls: ['./poll-display.component.scss']
|
|
})
|
|
export class PollDisplayComponent extends BaseComponent implements OnInit {
|
|
|
|
comments = mockComments;
|
|
|
|
constructor(public config: ConfigService,
|
|
private router: Router,
|
|
public activeRoute: ActivatedRoute) {
|
|
super(config);
|
|
this.activeRoute.paramMap.subscribe(params => {
|
|
console.log('params', params)
|
|
this.config.pollId = params.get('poll');
|
|
this.config.pollSlug = params.get('pollSlug');
|
|
if (!this.config.loading) {
|
|
this.fetchPoll();
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
}
|
|
|
|
|
|
// fetch poll with its ID or slug.
|
|
fetchPoll() {
|
|
const id = this.activeRoute.snapshot.params.poll;
|
|
const pollSlug = this.activeRoute.snapshot.params.pollSlug;
|
|
|
|
if (!environment.production) {
|
|
console.log('mockPoll3', mockPoll3)
|
|
this.config.currentPoll = mockPoll3;
|
|
return;
|
|
}
|
|
if (id) {
|
|
this.config.loading = true;
|
|
this.config.pollId = id;
|
|
// store it in the poll property here
|
|
this.config.getPollById(id).subscribe(
|
|
(res: any) => {
|
|
console.log('res', res);
|
|
|
|
|
|
this.config.currentPoll = res;
|
|
this.config.loading = false;
|
|
}, (e) => {
|
|
// handle need for a password
|
|
console.log('e', e)
|
|
this.config.handleError(e)
|
|
}
|
|
);
|
|
} else if (pollSlug) {
|
|
this.config.loading = true;
|
|
this.config.getPollByURL(pollSlug).subscribe(
|
|
(res: any) => {
|
|
console.log('res', res)
|
|
this.config.pollId = res.id;
|
|
this.config.currentPoll = res;
|
|
this.config.loading = false;
|
|
}, (e) => {
|
|
// handle need for a password
|
|
this.config.handleError(e)
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|