splitting date choices with a separator

This commit is contained in:
Tykayn 2021-04-30 14:15:21 +02:00 committed by tykayn
parent e405a09c78
commit 975997b767
11 changed files with 151 additions and 50 deletions

View File

@ -6,6 +6,11 @@ import { PollConfiguration } from './configuration.model';
import { Owner } from './owner.model';
import { DateChoice, TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs';
export class ChoiceGroup {
date_string: string;
choices: Choice[];
}
export class Poll {
public id = 0;
@ -42,6 +47,8 @@ export class Poll {
public choices: Choice[] = [];
public choicesDateGrouped: ChoiceGroup[] = [];
public votes = [];
public stacks = [];

View File

@ -183,19 +183,9 @@ export class ApiService {
public async getPollByCustomUrl(slug: string): Promise<Poll | undefined> {
try {
// TODO: this interceptor should be avoided if backends returns the good object
const adapterInterceptor: number = this.axiosInstance.interceptors.response.use(
(response: AxiosResponse): AxiosResponse => {
console.log('response', response);
return response;
}
);
const response: AxiosResponse<Poll> = await this.axiosInstance.get<Poll>(`${this.pollsEndpoint}/${slug}`);
console.log('fetch API : asking for poll with custom_url=' + slug, { response });
axios.interceptors.request.eject(adapterInterceptor);
return response && response.data && !Array.isArray(response.data) ? response.data : undefined;
} catch (error) {
if (error.response?.status === 404) {

View File

@ -20,7 +20,7 @@ import { TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs';
providedIn: 'root',
})
export class PollService implements Resolve<Poll> {
private _poll: BehaviorSubject<Poll | undefined> = new BehaviorSubject<Poll | undefined>(undefined);
_poll: BehaviorSubject<Poll | undefined> = new BehaviorSubject<Poll | undefined>(undefined);
public readonly poll: Observable<Poll | undefined> = this._poll.asObservable();
constructor(
@ -42,6 +42,8 @@ export class PollService implements Resolve<Poll> {
public async resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<Poll> {
const segments: string[] = state.url.split('/');
const wantedcustom_url: string = segments.includes('poll') ? segments[segments.indexOf('poll') + 1] : '';
// FIXME should be handled by routing
if (!wantedcustom_url && state.url.includes('administration')) {
// creation of new poll
const poll = new Poll(this.userService.getCurrentUser(), this.uuidService.getUUID(), '');
@ -100,7 +102,14 @@ export class PollService implements Resolve<Poll> {
}
}
/**
* update poll and parse its fields
* @param poll
*/
public updateCurrentPoll(poll: Poll): void {
if (poll.kind == 'date') {
poll.choices = this.parseDateChoices(poll.choices);
}
this.storageService.setChoicesForVoteStack(poll.choices);
this.toastService.display('sondage bien mis à jour', 'success');
@ -207,4 +216,25 @@ export class PollService implements Resolve<Poll> {
console.log('newpoll', newpoll);
return newpoll;
}
public parseDateChoices(choices: Choice[]) {
const SEPARATOR_DATE_TIME_SLICE = ' >>> ';
const parsedChoices = [];
for (const c of choices) {
const time_list = [];
const choice = { name: c.name };
if (c.name.includes(SEPARATOR_DATE_TIME_SLICE)) {
const date_string = '';
const time_slice = '';
choice.name = time_slice;
}
parsedChoices.push({
date_string: choice,
choices: c,
});
}
console.log('parsedChoices', parsedChoices);
return [];
}
}

View File

@ -39,6 +39,7 @@ export class StorageService {
setChoicesForVoteStack(choices_list: Choice[]) {
this.vote_stack.votes = [];
// text choices
for (const choice of choices_list) {
if (environment.autofill) {
this.vote_stack.votes.push(new Vote(choice.id, 'yes'));
@ -70,4 +71,10 @@ export class StorageService {
}
return false;
}
parseDateChoices(datechoices) {
const choices: Choice[] = [];
return choices;
}
}

View File

@ -3,8 +3,6 @@ import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
import { Poll } from '../../core/models/poll.model';
import { ModalService } from '../../core/services/modal.service';
import { UserService } from '../../core/services/user.service';
@Component({
selector: 'app-administration',
@ -15,7 +13,7 @@ export class AdministrationComponent implements OnInit, OnDestroy {
public poll: Poll = new Poll();
private routeSubscription: Subscription;
constructor(private route: ActivatedRoute, private userService: UserService, private modalService: ModalService) {}
constructor(private route: ActivatedRoute) {}
ngOnInit(): void {
this.routeSubscription = this.route.data.subscribe((data: { poll: Poll }) => {

View File

@ -204,34 +204,34 @@
</div>
</div>
</div>
<div class="column calendar-column">
<button class="btn" (click)="selectionKind = 'range'" [class.is-primary]="selectionKind == 'range'">
plage de jours
</button>
<!-- <div class="column calendar-column">-->
<!-- <button class="btn" (click)="selectionKind = 'range'" [class.is-primary]="selectionKind == 'range'">-->
<!-- plage de jours-->
<!-- </button>-->
<button
class="btn"
(click)="selectionKind = 'multiple'"
[class.is-primary]="selectionKind == 'multiple'"
>
jours séparés
</button>
<button class="btn" (click)="setDefaultDatesForInterval()">
réinitialiser</button
><button class="btn" (click)="dateCalendarEnum = [today]">
vider
</button>
<div class="text-center">
<br />
<p-calendar
[(ngModel)]="dateCalendarEnum"
[locale]="'calendar_widget' | translate"
[inline]="true"
[monthNavigator]="true"
[selectionMode]="selectionKind"
></p-calendar>
</div>
</div>
<!-- <button-->
<!-- class="btn"-->
<!-- (click)="selectionKind = 'multiple'"-->
<!-- [class.is-primary]="selectionKind == 'multiple'"-->
<!-- >-->
<!-- jours séparés-->
<!-- </button>-->
<!-- <button class="btn" (click)="setDefaultDatesForInterval()">-->
<!-- réinitialiser</button-->
<!-- ><button class="btn" (click)="dateCalendarEnum = [today]">-->
<!-- vider-->
<!-- </button>-->
<!-- <div class="text-center">-->
<!-- <br />-->
<!-- <p-calendar-->
<!-- [(ngModel)]="dateCalendarEnum"-->
<!-- [locale]="'calendar_widget' | translate"-->
<!-- [inline]="true"-->
<!-- [monthNavigator]="true"-->
<!-- [selectionMode]="selectionKind"-->
<!-- ></p-calendar>-->
<!-- </div>-->
<!-- </div>-->
</div>
</div>
</div>

View File

@ -1,4 +1,6 @@
<div class="admin-form padded">
<app-success [poll]="poll"></app-success>
<div class="container is-max-widescreen">
<form [formGroup]="form">
<header class="columns">

View File

@ -1,16 +1,70 @@
<section class="hero is-medium is-success">
<div class="hero-body">
<div class="container">
<h1 class="title">
Création de sondage réussie
<h1 class="title is-1">
{{ 'resume.title' | translate }}
</h1>
<h2 class="subtitle">
Bravo! partagez le lien de votre sondage. Un récapitulatif a été envoyé à votre adresse email.
{{ 'resume.admins' | translate }}
</h2>
</div>
</div>
</section>
<br />
<section class="text-center">
<img src="assets/img/undraw_group_selfie_ijc6.svg" alt="image succès" />
<section class="admin">
<h2 i18n></h2>
<p>
Votre sondage «
<strong class="poll-title">
{{ poll.title }}
</strong>
» a bien été créé !
</p>
<p>
Voici les liens daccès au sondage, conservez-les soigneusement ! (Si vous les perdez vous pourrez toujours
les recevoir par email)
</p>
<p>
Pour accéder au sondage et à tous ses paramètres :
<a href="{{ poll.custom_url }}">{{ poll.custom_url }} </a>
</p>
<app-copy-text [textToCopy]="poll.custom_url"></app-copy-text>
<a href="{{ poll.custom_url }}">
Voir le sondage coté administrateur·ice
</a>
<p class="note">
Note : Le sondage sera supprimé {{ poll.default_expiracy_days_from_now }} jours après la date de sa dernière
modification.
</p>
</section>
<section class="public">
<h2 i18n>{{ 'resume.users' | translate }}</h2>
<p>
Pour accéder au sondage :
<a href="{{ poll.custom_url }}">{{ poll.custom_url }} </a>
</p>
<app-copy-text [textToCopy]="poll.custom_url"></app-copy-text>
<a href="{{ poll.custom_url }}">
Voir le sondage
</a>
</section>
<section class="mail">
<h2 i18n>{{ 'resume.links_mail' | translate }}</h2>
<p>
Pour être sur de retrouver ces liens, nous pouvons vous les envoyer sur votre mail :
<input type="email" [(ngModel)]="mailToRecieve" placeholder="email" />
</p>
<button class="btn btn--primary" (click)="sendToEmail()">
<i class="fa fa-paper-plane" aria-hidden="true"></i>
Envoyer les liens du sondage
</button>
<a href="{{ poll.custom_url }}">
Voir le sondage
</a>
</section>
<!-- <img src="assets/img/undraw_group_selfie_ijc6.svg" alt="image succès" />-->
</section>

View File

@ -1,4 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { PollService } from '../../../core/services/poll.service';
import { Poll } from '../../../core/models/poll.model';
@Component({
selector: 'app-success',
@ -6,7 +8,14 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./success.component.scss'],
})
export class SuccessComponent implements OnInit {
constructor() {}
@Input() poll: Poll;
mailToRecieve: string;
constructor(private pollService: PollService) {}
ngOnInit(): void {}
sendToEmail() {
alert('todo');
}
}

View File

@ -96,7 +96,11 @@ export class ConsultationComponent implements OnInit, OnDestroy {
this.toastService.display('vote ajouté', 'success');
if (resp) {
this.api.getPollByCustomUrl(this.poll.custom_url);
const response: Promise<Poll | undefined> = this.api.getPollByCustomUrl(this.poll.custom_url);
response.then((res: Poll | undefined) => {
res.choices = this.pollService.parseDateChoices(res.choices);
this.pollService._poll.next(res);
});
} else {
this.toastService.display('erreur à la réception du nouveau vote', 'error');
}

View File

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