funky-framadate-front/src/app/features/consultation/consultation.component.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

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
2020-10-29 18:43:19 +01:00
import { PollConfiguration } from '../../core/models/configuration.model';
2020-05-12 19:16:23 +02:00
import { Poll } from '../../core/models/poll.model';
import { ModalService } from '../../core/services/modal.service';
import { UserService } from '../../core/services/user.service';
import { SettingsComponent } from '../../shared/components/settings/settings.component';
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 {
2020-05-12 19:16:23 +02:00
public isCompactMode = true;
2020-06-18 16:15:26 +02:00
public poll: Poll;
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,
private activatedRoute: ActivatedRoute,
2020-05-12 19:16:23 +02:00
private userService: UserService,
private modalService: ModalService
) {}
ngOnInit(): void {
if (!this.userService.isCurrentUserIdentifiable()) {
this.modalService.openModal(SettingsComponent);
2020-05-12 19:16:23 +02:00
}
2020-06-18 16:15:26 +02:00
this.routeSubscription = this.activatedRoute.data.subscribe((data: { poll: Poll }) => {
if (data.poll) {
this.poll = data.poll;
2020-10-29 18:43:19 +01:00
this.isArchived = PollConfiguration.isArchived(data.poll.configuration);
2020-06-18 16:15:26 +02:00
} 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
}
}