mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
splitting date choices with a separator
This commit is contained in:
parent
e405a09c78
commit
975997b767
@ -6,6 +6,11 @@ import { PollConfiguration } from './configuration.model';
|
|||||||
import { Owner } from './owner.model';
|
import { Owner } from './owner.model';
|
||||||
import { DateChoice, TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs';
|
import { DateChoice, TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs';
|
||||||
|
|
||||||
|
export class ChoiceGroup {
|
||||||
|
date_string: string;
|
||||||
|
choices: Choice[];
|
||||||
|
}
|
||||||
|
|
||||||
export class Poll {
|
export class Poll {
|
||||||
public id = 0;
|
public id = 0;
|
||||||
|
|
||||||
@ -42,6 +47,8 @@ export class Poll {
|
|||||||
|
|
||||||
public choices: Choice[] = [];
|
public choices: Choice[] = [];
|
||||||
|
|
||||||
|
public choicesDateGrouped: ChoiceGroup[] = [];
|
||||||
|
|
||||||
public votes = [];
|
public votes = [];
|
||||||
|
|
||||||
public stacks = [];
|
public stacks = [];
|
||||||
|
@ -183,19 +183,9 @@ export class ApiService {
|
|||||||
|
|
||||||
public async getPollByCustomUrl(slug: string): Promise<Poll | undefined> {
|
public async getPollByCustomUrl(slug: string): Promise<Poll | undefined> {
|
||||||
try {
|
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}`);
|
const response: AxiosResponse<Poll> = await this.axiosInstance.get<Poll>(`${this.pollsEndpoint}/${slug}`);
|
||||||
console.log('fetch API : asking for poll with custom_url=' + slug, { response });
|
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;
|
return response && response.data && !Array.isArray(response.data) ? response.data : undefined;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response?.status === 404) {
|
if (error.response?.status === 404) {
|
||||||
|
@ -20,7 +20,7 @@ import { TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs';
|
|||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class PollService implements Resolve<Poll> {
|
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();
|
public readonly poll: Observable<Poll | undefined> = this._poll.asObservable();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -42,6 +42,8 @@ export class PollService implements Resolve<Poll> {
|
|||||||
public async resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<Poll> {
|
public async resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<Poll> {
|
||||||
const segments: string[] = state.url.split('/');
|
const segments: string[] = state.url.split('/');
|
||||||
const wantedcustom_url: string = segments.includes('poll') ? segments[segments.indexOf('poll') + 1] : '';
|
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')) {
|
if (!wantedcustom_url && state.url.includes('administration')) {
|
||||||
// creation of new poll
|
// creation of new poll
|
||||||
const poll = new Poll(this.userService.getCurrentUser(), this.uuidService.getUUID(), '');
|
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 {
|
public updateCurrentPoll(poll: Poll): void {
|
||||||
|
if (poll.kind == 'date') {
|
||||||
|
poll.choices = this.parseDateChoices(poll.choices);
|
||||||
|
}
|
||||||
this.storageService.setChoicesForVoteStack(poll.choices);
|
this.storageService.setChoicesForVoteStack(poll.choices);
|
||||||
|
|
||||||
this.toastService.display('sondage bien mis à jour', 'success');
|
this.toastService.display('sondage bien mis à jour', 'success');
|
||||||
@ -207,4 +216,25 @@ export class PollService implements Resolve<Poll> {
|
|||||||
console.log('newpoll', newpoll);
|
console.log('newpoll', newpoll);
|
||||||
return 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 [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ export class StorageService {
|
|||||||
setChoicesForVoteStack(choices_list: Choice[]) {
|
setChoicesForVoteStack(choices_list: Choice[]) {
|
||||||
this.vote_stack.votes = [];
|
this.vote_stack.votes = [];
|
||||||
|
|
||||||
|
// text choices
|
||||||
for (const choice of choices_list) {
|
for (const choice of choices_list) {
|
||||||
if (environment.autofill) {
|
if (environment.autofill) {
|
||||||
this.vote_stack.votes.push(new Vote(choice.id, 'yes'));
|
this.vote_stack.votes.push(new Vote(choice.id, 'yes'));
|
||||||
@ -70,4 +71,10 @@ export class StorageService {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseDateChoices(datechoices) {
|
||||||
|
const choices: Choice[] = [];
|
||||||
|
|
||||||
|
return choices;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ import { ActivatedRoute } from '@angular/router';
|
|||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
import { Poll } from '../../core/models/poll.model';
|
import { Poll } from '../../core/models/poll.model';
|
||||||
import { ModalService } from '../../core/services/modal.service';
|
|
||||||
import { UserService } from '../../core/services/user.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-administration',
|
selector: 'app-administration',
|
||||||
@ -15,7 +13,7 @@ export class AdministrationComponent implements OnInit, OnDestroy {
|
|||||||
public poll: Poll = new Poll();
|
public poll: Poll = new Poll();
|
||||||
private routeSubscription: Subscription;
|
private routeSubscription: Subscription;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private userService: UserService, private modalService: ModalService) {}
|
constructor(private route: ActivatedRoute) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.routeSubscription = this.route.data.subscribe((data: { poll: Poll }) => {
|
this.routeSubscription = this.route.data.subscribe((data: { poll: Poll }) => {
|
||||||
|
@ -204,34 +204,34 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column calendar-column">
|
<!-- <div class="column calendar-column">-->
|
||||||
<button class="btn" (click)="selectionKind = 'range'" [class.is-primary]="selectionKind == 'range'">
|
<!-- <button class="btn" (click)="selectionKind = 'range'" [class.is-primary]="selectionKind == 'range'">-->
|
||||||
plage de jours
|
<!-- plage de jours-->
|
||||||
</button>
|
<!-- </button>-->
|
||||||
|
|
||||||
<button
|
<!-- <button-->
|
||||||
class="btn"
|
<!-- class="btn"-->
|
||||||
(click)="selectionKind = 'multiple'"
|
<!-- (click)="selectionKind = 'multiple'"-->
|
||||||
[class.is-primary]="selectionKind == 'multiple'"
|
<!-- [class.is-primary]="selectionKind == 'multiple'"-->
|
||||||
>
|
<!-- >-->
|
||||||
jours séparés
|
<!-- jours séparés-->
|
||||||
</button>
|
<!-- </button>-->
|
||||||
<button class="btn" (click)="setDefaultDatesForInterval()">
|
<!-- <button class="btn" (click)="setDefaultDatesForInterval()">-->
|
||||||
réinitialiser</button
|
<!-- réinitialiser</button-->
|
||||||
><button class="btn" (click)="dateCalendarEnum = [today]">
|
<!-- ><button class="btn" (click)="dateCalendarEnum = [today]">-->
|
||||||
vider
|
<!-- vider-->
|
||||||
</button>
|
<!-- </button>-->
|
||||||
<div class="text-center">
|
<!-- <div class="text-center">-->
|
||||||
<br />
|
<!-- <br />-->
|
||||||
<p-calendar
|
<!-- <p-calendar-->
|
||||||
[(ngModel)]="dateCalendarEnum"
|
<!-- [(ngModel)]="dateCalendarEnum"-->
|
||||||
[locale]="'calendar_widget' | translate"
|
<!-- [locale]="'calendar_widget' | translate"-->
|
||||||
[inline]="true"
|
<!-- [inline]="true"-->
|
||||||
[monthNavigator]="true"
|
<!-- [monthNavigator]="true"-->
|
||||||
[selectionMode]="selectionKind"
|
<!-- [selectionMode]="selectionKind"-->
|
||||||
></p-calendar>
|
<!-- ></p-calendar>-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<div class="admin-form padded">
|
<div class="admin-form padded">
|
||||||
|
<app-success [poll]="poll"></app-success>
|
||||||
|
|
||||||
<div class="container is-max-widescreen">
|
<div class="container is-max-widescreen">
|
||||||
<form [formGroup]="form">
|
<form [formGroup]="form">
|
||||||
<header class="columns">
|
<header class="columns">
|
||||||
|
@ -1,16 +1,70 @@
|
|||||||
<section class="hero is-medium is-success">
|
<section class="hero is-medium is-success">
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="title">
|
<h1 class="title is-1">
|
||||||
Création de sondage réussie
|
{{ 'resume.title' | translate }}
|
||||||
</h1>
|
</h1>
|
||||||
<h2 class="subtitle">
|
<h2 class="subtitle">
|
||||||
Bravo! partagez le lien de votre sondage. Un récapitulatif a été envoyé à votre adresse email.
|
{{ 'resume.admins' | translate }}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<br />
|
<br />
|
||||||
<section class="text-center">
|
<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 d’accè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>
|
</section>
|
||||||
|
@ -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({
|
@Component({
|
||||||
selector: 'app-success',
|
selector: 'app-success',
|
||||||
@ -6,7 +8,14 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
styleUrls: ['./success.component.scss'],
|
styleUrls: ['./success.component.scss'],
|
||||||
})
|
})
|
||||||
export class SuccessComponent implements OnInit {
|
export class SuccessComponent implements OnInit {
|
||||||
constructor() {}
|
@Input() poll: Poll;
|
||||||
|
mailToRecieve: string;
|
||||||
|
|
||||||
|
constructor(private pollService: PollService) {}
|
||||||
|
|
||||||
ngOnInit(): void {}
|
ngOnInit(): void {}
|
||||||
|
|
||||||
|
sendToEmail() {
|
||||||
|
alert('todo');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,11 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
|||||||
this.toastService.display('vote ajouté', 'success');
|
this.toastService.display('vote ajouté', 'success');
|
||||||
|
|
||||||
if (resp) {
|
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 {
|
} else {
|
||||||
this.toastService.display('erreur à la réception du nouveau vote', 'error');
|
this.toastService.display('erreur à la réception du nouveau vote', 'error');
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ export const routes: Routes = [
|
|||||||
{
|
{
|
||||||
path: 'poll/:custom_url/consultation',
|
path: 'poll/:custom_url/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/:custom_url/participation',
|
path: 'poll/:custom_url/participation',
|
||||||
|
Loading…
Reference in New Issue
Block a user