manage consultation path

This commit is contained in:
Tykayn 2021-04-21 12:43:05 +02:00 committed by tykayn
parent 3850f3811c
commit 6cb32cb2e1
5 changed files with 94 additions and 50 deletions

View File

@ -13,6 +13,28 @@
| translate | translate
}} }}
</blockquote> </blockquote>
<div class="demo" *ngIf="!env.production">
Environnement de développement: voici des liens de démonstration issus des fixtures Doctrine de
date-poll-api.
<button class="btn is-primary" [routerLink]="['/poll/aujourdhui-ou-demain/consultation']">
consulter le sondage
<strong>
aujourdhui-ou-demain
</strong>
</button>
<button
class="btn is-primary"
routerLink="/poll/citron/consultation/9199bdd9e0d4b29deafbf3463c0727fc"
>
consulter le sondage
<strong>
citron
</strong>
avec son hash md5 de mot de passe intégré
</button>
</div>
<img src="assets/img/undraw_group_selfie_ijc6.svg" alt="image WIP" /> <img src="assets/img/undraw_group_selfie_ijc6.svg" alt="image WIP" />
</div> </div>
<div class="columns"> <div class="columns">

View File

@ -4,7 +4,8 @@ import { RouterModule, Routes } from '@angular/router';
import { ConsultationComponent } from './consultation.component'; import { ConsultationComponent } from './consultation.component';
const routes: Routes = [ const routes: Routes = [
{ path: '', component: ConsultationComponent } { path: '', component: ConsultationComponent },
{ path: '/:hash', component: ConsultationComponent },
]; ];
@NgModule({ @NgModule({

View File

@ -1,45 +1,47 @@
<div class="columns"> <div class="columns">
<div class="column has-text-centered"> <div class="column has-text-centered">
<h1>Consultation</h1> <h1>Consultation de {{ pollSlug }}</h1>
</div> </div>
</div> </div>
<section class="loading_poll" *ngIf="fetching"></section>
<div class="columns"> <section class="poll_loaded" *ngIf="!fetching && poll">
<div class="column"> <div class="columns">
<div class="card"> <div class="column">
<header class="card-header"> <div class="card">
<p class="card-header-title">{{ poll.title }}</p> <header class="card-header">
<!-- <p class="card-header-icon">author : {{ poll.owner?.pseudo }}</p>--> <p class="card-header-title">{{ poll.title }}</p>
</header> <!-- <p class="card-header-icon">author : {{ poll.owner?.pseudo }}</p>-->
<div class="card-content"> </header>
<div class="content"> <div class="card-content">
<p>{{ poll.description }}</p> <div class="content">
<div class="buttons has-addons is-small is-right"> <p>{{ poll.description }}</p>
<button class="button" [class.is-active]="isCompactMode" (click)="isCompactMode = true"> <div class="buttons has-addons is-small is-right">
Compact <button class="button" [class.is-active]="isCompactMode" (click)="isCompactMode = true">
</button> Compact
<button class="button" [class.is-active]="!isCompactMode" (click)="isCompactMode = false"> </button>
Detailed <button class="button" [class.is-active]="!isCompactMode" (click)="isCompactMode = false">
</button> Detailed
</button>
</div>
<app-poll-results-compact *ngIf="isCompactMode" [poll]="poll"></app-poll-results-compact>
<app-poll-results-detailed *ngIf="!isCompactMode" [poll]="poll"></app-poll-results-detailed>
</div> </div>
<app-poll-results-compact *ngIf="isCompactMode" [poll]="poll"></app-poll-results-compact>
<app-poll-results-detailed *ngIf="!isCompactMode" [poll]="poll"></app-poll-results-detailed>
</div> </div>
<footer class="card-footer" *ngIf="!isArchived">
<a routerLink="{{ '../../../poll/' + poll.slug + '/participation' }}" class="card-footer-item">
Participer
</a>
<a routerLink="{{ '../../../poll/' + poll.slug + '/administration' }}" class="card-footer-item">
Administrer
</a>
</footer>
</div> </div>
<footer class="card-footer" *ngIf="!isArchived">
<a routerLink="{{ '../../../poll/' + poll.slug + '/participation' }}" class="card-footer-item">
Participer
</a>
<a routerLink="{{ '../../../poll/' + poll.slug + '/administration' }}" class="card-footer-item">
Administrer
</a>
</footer>
</div> </div>
</div> </div>
</div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<app-comments></app-comments> <app-comments></app-comments>
</div>
</div> </div>
</div> </section>

View File

@ -1,12 +1,9 @@
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { PollConfiguration } from '../../core/models/configuration.model';
import { Poll } from '../../core/models/poll.model'; import { Poll } from '../../core/models/poll.model';
import { ModalService } from '../../core/services/modal.service'; import { ModalService } from '../../core/services/modal.service';
import { UserService } from '../../core/services/user.service'; import { PollService } from '../../core/services/poll.service';
import { SettingsComponent } from '../../shared/components/settings/settings.component';
@Component({ @Component({
selector: 'app-consultation', selector: 'app-consultation',
@ -16,28 +13,50 @@ import { SettingsComponent } from '../../shared/components/settings/settings.com
export class ConsultationComponent implements OnInit, OnDestroy { export class ConsultationComponent implements OnInit, OnDestroy {
public isCompactMode = true; public isCompactMode = true;
public poll: Poll; public poll: Poll;
public pollSlug: string;
public passHash: string;
public fetching: boolean = true;
public isArchived: boolean; public isArchived: boolean;
private routeSubscription: Subscription; private routeSubscription: Subscription;
constructor( constructor(
private router: Router, private router: Router,
private activatedRoute: ActivatedRoute, private _Activatedroute: ActivatedRoute,
private userService: UserService, public pollService: PollService,
private modalService: ModalService private modalService: ModalService
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
if (!this.userService.isCurrentUserIdentifiable()) { console.log('constultation de poll');
this.modalService.openModal(SettingsComponent); this.pollService.poll.subscribe((newpoll: Poll) => {
} this.poll = newpoll;
this.routeSubscription = this.activatedRoute.data.subscribe((data: { poll: Poll }) => { });
if (data.poll) {
this.poll = data.poll; this._Activatedroute.paramMap.subscribe((params) => {
this.isArchived = PollConfiguration.isArchived(data.poll.configuration); 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 { } else {
this.router.navigate(['/page-not-found']); this.pollService.loadPollBySlug(this.pollSlug).then((resp) => {
console.log('resp', resp);
this.fetching = false;
});
} }
}); });
// 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']);
// }
// });
} }
ngOnDestroy(): void { ngOnDestroy(): void {

View File

@ -30,7 +30,7 @@ export const routes: Routes = [
{ {
path: 'poll/:slug/consultation', path: 'poll/:slug/consultation',
loadChildren: () => import('./features/consultation/consultation.module').then((m) => m.ConsultationModule), loadChildren: () => import('./features/consultation/consultation.module').then((m) => m.ConsultationModule),
resolve: { poll: PollService }, // resolve: { poll: PollService },
}, },
{ {
path: 'poll/:slug/participation', path: 'poll/:slug/participation',