mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ConfigService } from '../../services/config.service';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { PollUtilitiesService } from '../../../../src/app/core/services/poll.utilities.service';
|
|
import { environment } from '../../../../src/environments/environment';
|
|
|
|
@Component({
|
|
selector: 'app-admin',
|
|
templateUrl: './admin.component.html',
|
|
styleUrls: ['./admin.component.scss'],
|
|
})
|
|
export class AdminComponent implements OnInit {
|
|
public tokenForAdministration = '';
|
|
|
|
constructor(
|
|
public config: ConfigService,
|
|
public router: Router,
|
|
private utils: PollUtilitiesService,
|
|
public http: HttpClient,
|
|
public activeRoute: ActivatedRoute
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
|
|
// fetch poll with its ID or custom_url.
|
|
fetchPoll() {
|
|
const token = this.tokenForAdministration;
|
|
const headers = this.utils.makeHeaders({ token: token });
|
|
this.config.loading = true;
|
|
// store it in the poll property here
|
|
// 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);
|
|
// }
|
|
// );
|
|
}
|
|
}
|