2020-06-18 16:15:26 +02:00
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { Subscription } from 'rxjs';
|
2020-05-12 19:16:23 +02:00
|
|
|
import { Poll } from '../../core/models/poll.model';
|
|
|
|
import { ModalService } from '../../core/services/modal.service';
|
2021-04-21 12:43:05 +02:00
|
|
|
import { PollService } from '../../core/services/poll.service';
|
2020-05-12 19:16:23 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-consultation',
|
|
|
|
templateUrl: './consultation.component.html',
|
|
|
|
styleUrls: ['./consultation.component.scss'],
|
|
|
|
})
|
2020-06-18 16:15:26 +02:00
|
|
|
export class ConsultationComponent implements OnInit, OnDestroy {
|
2021-04-24 13:04:21 +02:00
|
|
|
public isCompactMode = true;
|
2020-06-18 16:15:26 +02:00
|
|
|
public poll: Poll;
|
2021-04-21 12:43:05 +02:00
|
|
|
public pollSlug: string;
|
|
|
|
public passHash: string;
|
|
|
|
public fetching: boolean = true;
|
2020-06-18 16:15:26 +02:00
|
|
|
public isArchived: boolean;
|
|
|
|
private routeSubscription: Subscription;
|
2020-05-12 19:16:23 +02:00
|
|
|
|
|
|
|
constructor(
|
2020-06-18 16:15:26 +02:00
|
|
|
private router: Router,
|
2021-04-21 12:43:05 +02:00
|
|
|
private _Activatedroute: ActivatedRoute,
|
|
|
|
public pollService: PollService,
|
2020-05-12 19:16:23 +02:00
|
|
|
private modalService: ModalService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-04-21 12:43:05 +02:00
|
|
|
console.log('constultation de poll');
|
|
|
|
this.pollService.poll.subscribe((newpoll: Poll) => {
|
|
|
|
this.poll = newpoll;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._Activatedroute.paramMap.subscribe((params) => {
|
|
|
|
console.log('params', params);
|
|
|
|
this.pollSlug = params.get('slug');
|
|
|
|
this.passHash = params.get('hash');
|
2021-04-24 12:31:34 +02:00
|
|
|
console.log('hash, slug', this.passHash, this.pollSlug);
|
2021-04-21 12:43:05 +02:00
|
|
|
if (this.passHash) {
|
|
|
|
this.pollService.loadPollBySlugWithPasswordHash(this.pollSlug, this.passHash);
|
2020-06-18 16:15:26 +02:00
|
|
|
} else {
|
2021-04-21 12:43:05 +02:00
|
|
|
this.pollService.loadPollBySlug(this.pollSlug).then((resp) => {
|
|
|
|
console.log('resp', resp);
|
|
|
|
this.fetching = false;
|
|
|
|
});
|
2020-06-18 16:15:26 +02:00
|
|
|
}
|
|
|
|
});
|
2021-04-21 12:43:05 +02:00
|
|
|
|
|
|
|
// if (!this.userService.isCurrentUserIdentifiable()) {
|
|
|
|
// this.modalService.openModal(SettingsComponent);
|
|
|
|
// }
|
|
|
|
// this.routeSubscription = this.activatedRoute.data.subscribe((data: { poll: Poll }) => {
|
|
|
|
// if (data.poll) {
|
|
|
|
// this.poll = data.poll;
|
|
|
|
// this.isArchived = PollConfiguration.isArchived(data.poll.configuration);
|
|
|
|
// } else {
|
|
|
|
// this.router.navigate(['/page-not-found']);
|
|
|
|
// }
|
|
|
|
// });
|
2020-05-12 19:16:23 +02:00
|
|
|
}
|
|
|
|
|
2020-06-18 16:15:26 +02:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (this.routeSubscription) {
|
|
|
|
this.routeSubscription.unsubscribe();
|
|
|
|
}
|
2020-05-12 19:16:23 +02:00
|
|
|
}
|
|
|
|
}
|