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 {
constructor(
public isAboutDate: boolean = false,
public isProtectedByPassword: boolean = false,
public allowComments: boolean = true,
public areResultsPublic: boolean = true,
public dateCreated: Date = new Date(Date.now()),
public password: string = '',
public isAboutDate: boolean = false,
public isAllowingtoChangeOwnAnswers: boolean = true,
public isMaybeAnswerAvailable: boolean = false,
public isProtectedByPassword: boolean = false,
public isOwnerNotifiedByEmailOnNewVote: boolean = false,
public isOwnerNotifiedByEmailOnNewComment: boolean = false,
public isMaybeAnswerAvailable: boolean = false,
public areResultsPublic: boolean = true,
public isAllowingtoChangeOwnAnswers: boolean = true,
public isZeroKnoledge: boolean = true,
public hasSeveralHours: boolean = false,
public hasMaxCountOfAnswers: boolean = false,
public whoCanChangeAnswers: string = 'everybody',
public dateCreated: Date = new Date(Date.now()),
public expiresDaysDelay: number = environment.poll.defaultConfig.expiracyInDays,
public maxCountOfAnswers: number = environment.poll.defaultConfig.maxCountOfAnswers,
public expiresDaysDelay: number = environment.poll.defaultConfig.expiresDaysDelay,
public expiracyAfterLastModificationInDays: number = environment.poll.defaultConfig
.expiracyAfterLastModificationInDays,
public expires: Date = DateService.addDaysToDate(
environment.poll.defaultConfig.expiracyInDays,
// date after creation day when people will not be able to vote anymore
public expiracyDate: Date = DateService.addDaysToDate(
environment.poll.defaultConfig.expiresDaysDelay,
new Date(Date.now())
)
) {}
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 creatorEmail?: string,
public isAboutDate?: boolean,
public isZeroKnoledge?: boolean,
public allowSeveralHours?: boolean,
public archiveNumberOfDays?: number,
public configuration: PollConfiguration = new PollConfiguration(),
public comments: Comment[] = [],
public choices: Choice[] = [],

View File

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

View File

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

View File

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

View File

@ -1,44 +1,11 @@
<div class="admin-form padded">
<form [formGroup]="form">
<div class="columns">
<header class="columns">
<div class="column">
<h1>
{{ 'creation.title' | translate }}
</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 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">
<button
class="btn is-success"
@ -49,9 +16,40 @@
Enregistrer le sondage
</button>
</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>
</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="has-background-danger" *ngIf="!form.valid">
<div class="has-background-danger" *ngIf="!form.valid && form.touched">
le formulaire est invalide
<pre>
{{ form.errors | json }}

View File

@ -20,7 +20,7 @@ export class FormComponent implements OnInit {
public poll?: Poll;
public form: FormGroup;
public advancedDisplayEnabled = true;
public advancedDisplayEnabled = false;
constructor(
private fb: FormBuilder,
@ -53,10 +53,11 @@ export class FormComponent implements OnInit {
whoModifiesAnswers: ['', [Validators.required]],
whoCanChangeAnswers: ['', [Validators.required]],
isAboutDate: [true, [Validators.required]],
isProtectedByPassword: [false, [Validators.required]],
startDateInterval: ['', [Validators.required]],
endDateInterval: ['', [Validators.required]],
isProtectedByPassword: [false, [Validators.required]],
hasMaxCountOfAnswers: [true, [Validators.required]],
hasMaxCountOfAnswers: [true, [Validators.required, Validators.min(1)]],
hasSeveralHours: [false, [Validators.required]],
allowComments: [true, [Validators.required]],
maxCountOfAnswers: [150, [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 {
this.form.patchValue({
@ -84,6 +85,7 @@ export class FormComponent implements OnInit {
creatorPseudo: 'Chuck Norris',
creatorEmail: 'chucknorris@example.com',
isAboutDate: true,
hasSeveralHours: true,
configuration: {
whoModifiesAnswers: 'everybody',
whoCanChangeAnswers: 'everybody',

View File

@ -50,7 +50,7 @@ export class StepperComponent implements OnInit {
],
areResultsPublic: [this.poll ? this.poll.configuration.areResultsPublic : true, [Validators.required]],
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],
],
});

View File

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

View File

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