harmonizing poll default properties with payload and advanced config

This commit is contained in:
Tykayn 2021-02-05 23:03:49 +01:00 committed by tykayn
parent 237984c040
commit 2a4219e149
10 changed files with 206 additions and 195 deletions

View File

@ -3,26 +3,32 @@ import { DateService } from '../services/date.service';
export class PollConfiguration { export class PollConfiguration {
constructor( constructor(
public isAboutDate: boolean = false, public allowComments: boolean = true,
public isProtectedByPassword: boolean = false, public areResultsPublic: boolean = true,
public dateCreated: Date = new Date(Date.now()),
public password: string = '', public password: string = '',
public isAboutDate: boolean = false,
public isAllowingtoChangeOwnAnswers: boolean = true,
public isMaybeAnswerAvailable: boolean = false,
public isProtectedByPassword: boolean = false,
public isOwnerNotifiedByEmailOnNewVote: boolean = false, public isOwnerNotifiedByEmailOnNewVote: boolean = false,
public isOwnerNotifiedByEmailOnNewComment: boolean = false, public isOwnerNotifiedByEmailOnNewComment: boolean = false,
public isMaybeAnswerAvailable: boolean = false, public isZeroKnoledge: boolean = true,
public areResultsPublic: boolean = true, public hasSeveralHours: boolean = false,
public isAllowingtoChangeOwnAnswers: boolean = true, public hasMaxCountOfAnswers: boolean = false,
public whoCanChangeAnswers: string = 'everybody', public whoCanChangeAnswers: string = 'everybody',
public dateCreated: Date = new Date(Date.now()), public maxCountOfAnswers: number = environment.poll.defaultConfig.maxCountOfAnswers,
public expiresDaysDelay: number = environment.poll.defaultConfig.expiracyInDays, public expiresDaysDelay: number = environment.poll.defaultConfig.expiresDaysDelay,
public expiracyAfterLastModificationInDays: number = environment.poll.defaultConfig public expiracyAfterLastModificationInDays: number = environment.poll.defaultConfig
.expiracyAfterLastModificationInDays, .expiracyAfterLastModificationInDays,
public expires: Date = DateService.addDaysToDate( // date after creation day when people will not be able to vote anymore
environment.poll.defaultConfig.expiracyInDays, public expiracyDate: Date = DateService.addDaysToDate(
environment.poll.defaultConfig.expiresDaysDelay,
new Date(Date.now()) new Date(Date.now())
) )
) {} ) {}
public static isArchived(configuration: PollConfiguration): boolean { public static isArchived(configuration: PollConfiguration): boolean {
return configuration.expires ? DateService.isDateInPast(configuration.expires) : undefined; return configuration.expiracyDate ? DateService.isDateInPast(configuration.expiracyDate) : undefined;
} }
} }

View File

@ -14,6 +14,9 @@ export class Poll {
public creatorPseudo?: string, public creatorPseudo?: string,
public creatorEmail?: string, public creatorEmail?: string,
public isAboutDate?: boolean, public isAboutDate?: boolean,
public isZeroKnoledge?: boolean,
public allowSeveralHours?: boolean,
public archiveNumberOfDays?: number,
public configuration: PollConfiguration = new PollConfiguration(), public configuration: PollConfiguration = new PollConfiguration(),
public comments: Comment[] = [], public comments: Comment[] = [],
public choices: Choice[] = [], public choices: Choice[] = [],

View File

@ -64,7 +64,7 @@ export class PollService implements Resolve<Poll> {
console.log('getAllAvailablePolls res', res); console.log('getAllAvailablePolls res', res);
}); });
} catch (e) { } catch (e) {
console.log('getAllAvailablePolls e', e); console.error('getAllAvailablePolls e', e);
} }
} }

View File

@ -52,8 +52,8 @@
consultable</mat-label consultable</mat-label
> >
<input <input
#expiracy #expiresDaysDelay
id="expiracy" id="expiresDaysDelay"
matInput matInput
type="number" type="number"
placeholder="Nombre de jours avant fin des votes" placeholder="Nombre de jours avant fin des votes"
@ -62,11 +62,11 @@
/> />
<button <button
mat-button mat-button
*ngIf="expiracy.value" *ngIf="expiresDaysDelay.value"
matSuffix matSuffix
mat-icon-button mat-icon-button
aria-label="Clear" aria-label="Clear"
(click)="expiracy.value = ''" (click)="expiresDaysDelay.value = ''"
> >
<i class="fa fa-close"></i> <i class="fa fa-close"></i>
</button> </button>
@ -149,8 +149,8 @@
</mat-checkbox> </mat-checkbox>
<input <input
*ngIf="form.value.hasMaxCountOfAnswers" *ngIf="form.value.hasMaxCountOfAnswers"
#limitCount #maxCountOfAnswers
id="limitCount" id="maxCountOfAnswers"
matInput matInput
type="number" type="number"
placeholder="Nombre de réponses max" placeholder="Nombre de réponses max"

View File

@ -1,5 +1,5 @@
<div class="date-selection"> <div class="date-selection">
<form [formGroup]="form"> <!-- <form [formGroup]="form">-->
<!-- interval--> <!-- interval-->
<!-- <section *ngIf="showDateInterval" class="date-interval form-row">--> <!-- <section *ngIf="showDateInterval" class="date-interval form-row">-->
@ -39,6 +39,7 @@
<!-- </button>--> <!-- </button>-->
<!-- </section>--> <!-- </section>-->
<!-- </form>-->
<div class="dates-list"> <div class="dates-list">
<div class="title"> <div class="title">
<span class="count-dates"> <span class="count-dates">
@ -50,9 +51,14 @@
</span> </span>
</div> </div>
<div class="actions"> <div class="actions">
<pre class="debug padded warning">
form.value.hasSeveralHours :
{{ form.value.hasSeveralHours | json }}
</pre
>
<button <button
(click)="addTime()" (click)="addTime()"
*ngIf="'false' === allowSeveralHours" *ngIf="!form.value.hasSeveralHours"
class="btn btn--primary" class="btn btn--primary"
id="add_time_button" id="add_time_button"
> >
@ -79,24 +85,24 @@
</button> </button>
</div> </div>
<div *ngIf="'false' === allowSeveralHours" class="identical-dates"> <!-- <div *ngIf="'false' === allowSeveralHours" class="identical-dates">-->
<div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)"> <!-- <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">-->
<div *ngFor="let time of timeList; index as id" class="time-choice" cdkDrag> <!-- <div *ngFor="let time of timeList; index as id" class="time-choice" cdkDrag>-->
<label for="timeChoices_{{ id }}"> <!-- <label for="timeChoices_{{ id }}">-->
<i class="fa fa-clock-o" aria-hidden="true"></i> <!-- <i class="fa fa-clock-o" aria-hidden="true"></i>-->
</label> <!-- </label>-->
<input <!-- <input-->
[(ngModel)]="time.literal" <!-- [(ngModel)]="time.literal"-->
name="timeChoices_{{ id }}" <!-- name="timeChoices_{{ id }}"-->
type="text" <!-- type="text"-->
id="timeChoices_{{ id }}" <!-- id="timeChoices_{{ id }}"-->
/> <!-- />-->
<button (click)="time.timeList.splice(id, 1)" class="btn btn-warning"> <!-- <button (click)="time.timeList.splice(id, 1)" class="btn btn-warning">-->
<i class="fa fa-times" aria-hidden="true"></i> <!-- <i class="fa fa-times" aria-hidden="true"></i>-->
</button> <!-- </button>-->
</div> <!-- </div>-->
</div> <!-- </div>-->
</div> <!-- </div>-->
<hr /> <hr />
<span class="count-dates title"> <span class="count-dates title">
{{ dateList.length }} {{ dateList.length }}
@ -119,11 +125,7 @@
<button (click)="dateList.splice(id, 1)" class="btn btn-warning"> <button (click)="dateList.splice(id, 1)" class="btn btn-warning">
<i class="fa fa-times" aria-hidden="true"></i> <i class="fa fa-times" aria-hidden="true"></i>
</button> </button>
<button <button (click)="addTimeToDate(choice, id)" *ngIf="'true' === allowSeveralHours" class="btn btn--primary">
(click)="addTimeToDate(choice, id)"
*ngIf="'true' === allowSeveralHours"
class="btn btn--primary"
>
{{ 'dates.add_time' | translate }} {{ 'dates.add_time' | translate }}
</button> </button>
<div *ngIf="'true' === allowSeveralHours" class="several-times"> <div *ngIf="'true' === allowSeveralHours" class="several-times">
@ -141,5 +143,4 @@
</div> </div>
</div> </div>
</div> </div>
</form>
</div> </div>

View File

@ -1,44 +1,11 @@
<div class="admin-form padded"> <div class="admin-form padded">
<form [formGroup]="form"> <form [formGroup]="form">
<div class="columns"> <header class="columns">
<div class="column"> <div class="column">
<h1> <h1>
{{ 'creation.title' | translate }} {{ 'creation.title' | translate }}
</h1> </h1>
<p class="subtitle">
{{ 'creation.want' | translate }}
</p>
<app-kind-select [form]="form"></app-kind-select>
<app-date-select ng-if="form.value.isAboutDate" [form]="form"></app-date-select>
<app-text-select ng-if="!form.value.isAboutDate" [form]="form"></app-text-select>
<app-base-config [form]="form"></app-base-config>
</div> </div>
</div>
<div class="column">
<pre class="debug padded warning">
form values :
{{ form.value | json }}
</pre
>
<pre class="debug padded warning">
poll initial values :
{{ poll | json }}
</pre
>
</div>
<!-- choix spécialement pour les dates-->
<button class="btn is-info" (click)="advancedDisplayEnabled = !advancedDisplayEnabled">
<i class="fa fa-save"></i>
{{ 'creation.advanced' | translate }}
</button>
<app-advanced-config [poll]="poll" [form]="form" *ngIf="advancedDisplayEnabled"></app-advanced-config>
<hr />
<div class="columns">
<div class="column"></div>
<div class="column"> <div class="column">
<button <button
class="btn is-success" class="btn is-success"
@ -49,9 +16,40 @@
Enregistrer le sondage Enregistrer le sondage
</button> </button>
</div> </div>
</header>
<main class="columns">
<div class="column">
<p class="subtitle">
{{ 'creation.want' | translate }}
</p>
<!-- <app-kind-select [form]="form"></app-kind-select>-->
<app-date-select ng-if="form.value.isAboutDate" [form]="form"></app-date-select>
<!-- <app-text-select ng-if="!form.value.isAboutDate" [form]="form"></app-text-select>-->
<!-- <app-base-config [form]="form"></app-base-config>-->
<button class="btn is-info" (click)="advancedDisplayEnabled = !advancedDisplayEnabled">
<i class="fa fa-save"></i>
{{ 'creation.advanced' | translate }}
</button>
<app-advanced-config [poll]="poll" [form]="form" *ngIf="advancedDisplayEnabled"></app-advanced-config>
</div> </div>
</main>
<footer class="column">
<pre class="debug padded warning">
form values :
{{ form.value | json }}
</pre
>
<pre class="debug padded warning">
poll initial values :
{{ poll | json }}
</pre
>
</footer>
<hr />
<div class="validation"> <div class="validation">
<div class="has-background-danger" *ngIf="!form.valid"> <div class="has-background-danger" *ngIf="!form.valid && form.touched">
le formulaire est invalide le formulaire est invalide
<pre> <pre>
{{ form.errors | json }} {{ form.errors | json }}

View File

@ -20,7 +20,7 @@ export class FormComponent implements OnInit {
public poll?: Poll; public poll?: Poll;
public form: FormGroup; public form: FormGroup;
public advancedDisplayEnabled = true; public advancedDisplayEnabled = false;
constructor( constructor(
private fb: FormBuilder, private fb: FormBuilder,
@ -53,10 +53,11 @@ export class FormComponent implements OnInit {
whoModifiesAnswers: ['', [Validators.required]], whoModifiesAnswers: ['', [Validators.required]],
whoCanChangeAnswers: ['', [Validators.required]], whoCanChangeAnswers: ['', [Validators.required]],
isAboutDate: [true, [Validators.required]], isAboutDate: [true, [Validators.required]],
isProtectedByPassword: [false, [Validators.required]],
startDateInterval: ['', [Validators.required]], startDateInterval: ['', [Validators.required]],
endDateInterval: ['', [Validators.required]], endDateInterval: ['', [Validators.required]],
isProtectedByPassword: [false, [Validators.required]], hasMaxCountOfAnswers: [true, [Validators.required, Validators.min(1)]],
hasMaxCountOfAnswers: [true, [Validators.required]], hasSeveralHours: [false, [Validators.required]],
allowComments: [true, [Validators.required]], allowComments: [true, [Validators.required]],
maxCountOfAnswers: [150, [Validators.required]], maxCountOfAnswers: [150, [Validators.required]],
isOwnerNotifiedByEmailOnNewVote: [false, [Validators.required]], isOwnerNotifiedByEmailOnNewVote: [false, [Validators.required]],
@ -74,7 +75,7 @@ export class FormComponent implements OnInit {
} }
/** /**
* add example values to the form * add example values to the form, overrides defaults of PollConfiguration
*/ */
setDemoValues(): void { setDemoValues(): void {
this.form.patchValue({ this.form.patchValue({
@ -84,6 +85,7 @@ export class FormComponent implements OnInit {
creatorPseudo: 'Chuck Norris', creatorPseudo: 'Chuck Norris',
creatorEmail: 'chucknorris@example.com', creatorEmail: 'chucknorris@example.com',
isAboutDate: true, isAboutDate: true,
hasSeveralHours: true,
configuration: { configuration: {
whoModifiesAnswers: 'everybody', whoModifiesAnswers: 'everybody',
whoCanChangeAnswers: 'everybody', whoCanChangeAnswers: 'everybody',

View File

@ -50,7 +50,7 @@ export class StepperComponent implements OnInit {
], ],
areResultsPublic: [this.poll ? this.poll.configuration.areResultsPublic : true, [Validators.required]], areResultsPublic: [this.poll ? this.poll.configuration.areResultsPublic : true, [Validators.required]],
expiracyNumberOfDays: [ expiracyNumberOfDays: [
this.poll ? DateService.diffInDays(new Date(), this.poll.configuration.expires) : 60, this.poll ? DateService.diffInDays(new Date(), this.poll.configuration.expiracyDate) : 60,
[Validators.required], [Validators.required],
], ],
}); });

View File

@ -39,7 +39,7 @@ export const environment = {
}, },
poll: { poll: {
defaultConfig: { defaultConfig: {
expiracyInDays: 60, expiresDaysDelay: 60,
expiracyAfterLastModificationInDays: 180, expiracyAfterLastModificationInDays: 180,
}, },
}, },

View File

@ -54,7 +54,8 @@ export const environment = {
}, },
poll: { poll: {
defaultConfig: { defaultConfig: {
expiracyInDays: 60, maxCountOfAnswers: 150,
expiresDaysDelay: 60,
expiracyAfterLastModificationInDays: 180, expiracyAfterLastModificationInDays: 180,
}, },
}, },