118 lines
3.1 KiB
TypeScript
118 lines
3.1 KiB
TypeScript
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { Subscription } from 'rxjs';
|
|
import { Poll } from '../../core/models/poll.model';
|
|
import { ModalService } from '../../core/services/modal.service';
|
|
import { PollService } from '../../core/services/poll.service';
|
|
import { DateService } from '../../core/services/date.service';
|
|
import { PollUtilitiesService } from '../../core/services/poll.utilities.service';
|
|
import { StorageService } from '../../core/services/storage.service';
|
|
import { ApiService } from '../../core/services/api.service';
|
|
import { Stack } from '../../core/models/stack.model';
|
|
import { environment } from '../../../environments/environment';
|
|
import { ToastService } from '../../core/services/toast.service';
|
|
|
|
@Component({
|
|
selector: 'app-consultation',
|
|
templateUrl: './consultation.component.html',
|
|
styleUrls: ['./consultation.component.scss'],
|
|
})
|
|
export class ConsultationComponent implements OnInit, OnDestroy {
|
|
public isCompactMode = true;
|
|
public poll: Poll;
|
|
public pollSlug: string;
|
|
public passHash: string;
|
|
public fetching = true;
|
|
public isArchived: boolean;
|
|
|
|
public myVoteStack: any = {
|
|
id: '',
|
|
};
|
|
public myTempVoteStack: any = {
|
|
id: '',
|
|
};
|
|
private routeSubscription: Subscription;
|
|
|
|
constructor(
|
|
private router: Router,
|
|
private utils: PollUtilitiesService,
|
|
private _Activatedroute: ActivatedRoute,
|
|
public storageService: StorageService,
|
|
public api: ApiService,
|
|
public pollService: PollService,
|
|
public dateService: DateService,
|
|
public toastService: ToastService
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
console.log('constultation de poll');
|
|
this.pollService.poll.subscribe((newpoll: Poll) => {
|
|
this.poll = newpoll;
|
|
if (newpoll) {
|
|
this.isArchived = new Date(newpoll.expiracy_date) < new Date();
|
|
this.poll.is_archived = this.isArchived;
|
|
|
|
if (!environment.production) {
|
|
this.addVoteStack();
|
|
}
|
|
}
|
|
});
|
|
|
|
this._Activatedroute.paramMap.subscribe((params) => {
|
|
console.log('params', params);
|
|
this.pollSlug = params.get('slug');
|
|
this.passHash = params.get('hash');
|
|
|
|
if (this.passHash) {
|
|
this.pollService.loadPollBySlugWithPasswordHash(this.pollSlug, this.passHash);
|
|
} else {
|
|
this.pollService.loadPollBySlug(this.pollSlug).then((resp) => {
|
|
console.log('resp', resp);
|
|
this.fetching = false;
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
if (this.routeSubscription) {
|
|
this.routeSubscription.unsubscribe();
|
|
}
|
|
}
|
|
|
|
updateVote(votestack: Stack) {
|
|
alert('TODO');
|
|
}
|
|
|
|
addVoteStack() {
|
|
this.api.sendVoteStackOfPoll(this.poll, this.storageService.vote_stack).subscribe((resp) => {
|
|
console.log('sendVoteStackOfPoll resp', resp);
|
|
|
|
if (resp) {
|
|
this.api.getPollBySlug(this.poll.custom_url);
|
|
} else {
|
|
this.toastService.display('erreur à la réception du nouveau vote', 'error');
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* export all the poll data available to the public as a CSV single file
|
|
*/
|
|
exportCSV() {
|
|
this.utils.exportCSV(this.poll);
|
|
}
|
|
|
|
exportJson() {
|
|
this.utils.download('export_poll_' + this.pollSlug + '.json', JSON.stringify(this.poll));
|
|
}
|
|
|
|
duplicate() {
|
|
alert('TODO');
|
|
}
|
|
|
|
print() {
|
|
alert('TODO');
|
|
}
|
|
}
|