2020-04-14 11:28:33 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { ConfigService } from '../../services/config.service';
|
2020-04-17 15:52:09 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
2021-04-29 10:45:22 +02:00
|
|
|
import { PollUtilitiesService } from '../../../../src/app/core/services/poll.utilities.service';
|
2021-04-29 10:41:47 +02:00
|
|
|
import { environment } from '../../../../src/environments/environment';
|
2020-01-22 11:18:55 +01:00
|
|
|
|
2019-11-18 19:32:14 +01:00
|
|
|
@Component({
|
2020-04-22 12:56:18 +02:00
|
|
|
selector: 'app-admin',
|
2020-04-17 13:10:21 +02:00
|
|
|
templateUrl: './admin.component.html',
|
|
|
|
styleUrls: ['./admin.component.scss'],
|
2019-11-18 19:32:14 +01:00
|
|
|
})
|
|
|
|
export class AdminComponent implements OnInit {
|
2020-04-17 15:52:09 +02:00
|
|
|
public tokenForAdministration = '';
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
public config: ConfigService,
|
|
|
|
public router: Router,
|
2021-04-29 10:45:22 +02:00
|
|
|
private utils: PollUtilitiesService,
|
2020-04-17 15:52:09 +02:00
|
|
|
public http: HttpClient,
|
|
|
|
public activeRoute: ActivatedRoute
|
|
|
|
) {}
|
2019-11-18 19:32:14 +01:00
|
|
|
|
2020-05-01 19:10:17 +02:00
|
|
|
ngOnInit(): void {
|
2020-04-17 15:52:09 +02:00
|
|
|
this.activeRoute.paramMap.subscribe((params) => {
|
|
|
|
console.log('params', params);
|
|
|
|
this.tokenForAdministration = params.get('token');
|
|
|
|
// redirect to home if no token provided
|
|
|
|
if (!this.tokenForAdministration) {
|
|
|
|
alert('pas de token pour administrer un sondage, mauvaise URL.');
|
|
|
|
this.router.navigate(['/home']);
|
|
|
|
}
|
|
|
|
if (!this.config.loading) {
|
|
|
|
// get token paarameter from route
|
|
|
|
// fetch admin version of the poll
|
|
|
|
// then, populate UI.
|
|
|
|
this.fetchPoll();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-30 10:59:46 +02:00
|
|
|
// fetch poll with its ID or custom_url.
|
2020-04-17 15:52:09 +02:00
|
|
|
fetchPoll() {
|
|
|
|
const token = this.tokenForAdministration;
|
|
|
|
const headers = this.utils.makeHeaders({ token: token });
|
|
|
|
this.config.loading = true;
|
|
|
|
// store it in the poll property here
|
2020-04-25 12:54:56 +02:00
|
|
|
// this.http.get(`${environment.baseApiHref}/admin/${token}`, headers).subscribe(
|
|
|
|
// (res: any) => {
|
|
|
|
// console.log('res', res);
|
|
|
|
// this.config.updateCurrentPollFromResponse(res);
|
|
|
|
// this.config.loading = false;
|
|
|
|
// },
|
|
|
|
// (e) => {
|
|
|
|
// // handle need for a password
|
|
|
|
// console.log('e', e);
|
|
|
|
// this.config.handleError(e);
|
|
|
|
// }
|
|
|
|
// );
|
2020-04-17 13:10:21 +02:00
|
|
|
}
|
2019-11-18 19:32:14 +01:00
|
|
|
}
|