display primeng calendar multiselector

This commit is contained in:
Tykayn 2021-10-27 12:21:25 +02:00 committed by tykayn
parent dfb3e98159
commit 0932f110f7
11 changed files with 272 additions and 171 deletions

View File

@ -40,6 +40,7 @@ export class PollService implements Resolve<Poll> {
public showDateInterval = false; public showDateInterval = false;
public allowSeveralHours = false; public allowSeveralHours = false;
public richTextMode = false; public richTextMode = false;
public calendar: any;
constructor( constructor(
private http: HttpClient, private http: HttpClient,
@ -56,6 +57,8 @@ export class PollService implements Resolve<Poll> {
this.createFormGroup(); this.createFormGroup();
if (environment.poll.autoFillDemo) { if (environment.poll.autoFillDemo) {
this.setDemoValues(); this.setDemoValues();
} else {
this.calendar = [new Date()];
} }
} }
@ -67,6 +70,11 @@ export class PollService implements Resolve<Poll> {
this.addChoice('raisin'); this.addChoice('raisin');
this.addChoice('abricot'); this.addChoice('abricot');
this.calendar = [
this.dateUtilities.addDaysToDate(1, new Date()),
this.dateUtilities.addDaysToDate(2, new Date()),
this.dateUtilities.addDaysToDate(3, new Date()),
];
this.form.patchValue({ this.form.patchValue({
title: 'mon titre', title: 'mon titre',
description: 'répondez SVP <3 ! *-* ', description: 'répondez SVP <3 ! *-* ',

View File

@ -16,6 +16,8 @@ import { StepThreeComponent } from './form/step-three/step-three.component';
import { StepFourComponent } from './form/step-four/step-four.component'; import { StepFourComponent } from './form/step-four/step-four.component';
import { StepFiveComponent } from './form/step-five/step-five.component'; import { StepFiveComponent } from './form/step-five/step-five.component';
import { DevMenuComponent } from './dev-menu/dev-menu.component'; import { DevMenuComponent } from './dev-menu/dev-menu.component';
import { CalendarModule } from 'primeng/calendar';
import { DateViewsComponent } from './form/date-views/date-views.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -29,10 +31,12 @@ import { DevMenuComponent } from './dev-menu/dev-menu.component';
StepFourComponent, StepFourComponent,
StepFiveComponent, StepFiveComponent,
DevMenuComponent, DevMenuComponent,
DateViewsComponent,
], ],
imports: [ imports: [
AdministrationRoutingModule, AdministrationRoutingModule,
CommonModule, CommonModule,
CalendarModule,
ReactiveFormsModule, ReactiveFormsModule,
SharedModule, SharedModule,
TranslateModule.forChild({ extend: true }), TranslateModule.forChild({ extend: true }),

View File

@ -0,0 +1,76 @@
<button class="btn btn--primary" (click)="pollService.addChoice()">
{{ 'dates.add' | translate }}
</button>
<div *ngFor="let choice of pollService.dateList; index as id" class="date-choice">
<input
[(ngModel)]="choice.date_object"
name="dateChoices_{{ id }}"
id="dateChoices_{{ id }}"
useValueAsDate
type="date"
/>
<button (click)="pollService.dateList.splice(id, 1)" class="btn btn-warning">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
<button
(click)="pollService.addTimeToDate(choice, id)"
*ngIf="'true' === pollService.allowSeveralHours"
class="btn btn--primary"
>
{{ 'dates.add_time' | translate }}
</button>
<div *ngIf="'true' === pollService.allowSeveralHours" class="several-times">
<div *ngFor="let timeItem of choice.timeList; index as idTime" class="time-choice">
<input
[(ngModel)]="timeItem.literal"
name="dateTime_{{ id }}_Choices_{{ idTime }}"
id="dateTime_{{ id }}_Choices_{{ idTime }}"
type="text"
/>
<button (click)="choice.timeList.splice(idTime, 1)" class="btn btn-warning">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>
</div>
<button
(click)="pollService.showDateInterval = !pollService.showDateInterval"
[ngClass]="{ active: pollService.showDateInterval }"
class="btn btn--primary"
id="toggle_interval_button"
>
<i class="fa fa-clock-o" aria-hidden="true"></i>
{{ 'dates.add_interval' | translate }}
</button>
<section *ngIf="pollService.showDateInterval" class="date-interval form-row">
<h2>{{ 'dates.add_interval' | translate }}</h2>
<div class="columns">
<div class="column">
{{ 'dates.interval_propose' | translate }}
</div>
<div class="column">
<label for="start_interval" class="hidden">start</label>
<input
id="start_interval"
(change)="pollService.countDays()"
formControlName="startDateInterval"
type="date"
/>
</div>
</div>
<div class="columns">
<div class="column">
{{ 'dates.interval_span' | translate }}
</div>
<div class="column">
<label for="end_interval" class="hidden">end</label>
<input id="end_interval" formControlName="endDateInterval" type="date" />
</div>
</div>
<button (click)="pollService.addIntervalOfDates()" class="btn btn-block btn--primary">
<i class="fa fa-plus" aria-hidden="true"></i>
{{ 'dates.interval_button' | translate }}
{{ pollService.intervalDays }}
{{ 'dates.interval_button_dates' | translate }}
</button>
</section>

View File

@ -0,0 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DateViewsComponent } from './date-views.component';
describe('DateViewsComponent', () => {
let component: DateViewsComponent;
let fixture: ComponentFixture<DateViewsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DateViewsComponent],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DateViewsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { PollService } from '../../../../core/services/poll.service';
@Component({
selector: 'app-date-views',
templateUrl: './date-views.component.html',
styleUrls: ['./date-views.component.scss'],
})
export class DateViewsComponent implements OnInit {
constructor(public pollService: PollService) {}
ngOnInit(): void {}
}

View File

@ -1,99 +1,127 @@
<app-stepper [step_current]="4" [step_max]="5"></app-stepper> <div class="step">
<div class="min-height">
<form action="#" [formGroup]="pollService.form">
<app-stepper [step_current]="4" [step_max]="5"></app-stepper>
<div class="creator-infos"> <div class="creator-infos">
<label class="" for="creatorEmail"> <label class="" for="creatorEmail">
<span> <span>
{{ 'creation.name' | translate }} {{ 'creation.name' | translate }}
</span> </span>
</label> </label>
<label class="hidden" for="creatorPseudo"> <input
<span> #title
{{ 'creation.email' | translate }} matInput
</span> placeholder="pseudo"
</label> formControlName="creatorPseudo"
<input #title matInput placeholder="pseudo" formControlName="creatorPseudo" id="creatorPseudo" required /> id="creatorPseudo"
<input required
#title />
matInput <label class="hidden" for="creatorPseudo">
placeholder="mon-email@example.com" <span>
formControlName="creatorEmail" {{ 'creation.email' | translate }}
id="creatorEmail" </span>
required </label>
/> <input
</div> #title
matInput
placeholder="mon-email@example.com"
formControlName="creatorEmail"
id="creatorEmail"
required
/>
</div>
<fieldset class="advanced-config"> <fieldset class="advanced-config">
<button class="btn is-info" (click)="advancedDisplayEnabled = !advancedDisplayEnabled"> <button class="btn is-info" (click)="advancedDisplayEnabled = !advancedDisplayEnabled">
<i class="fa fa-save"></i> <i class="fa fa-save"></i>
{{ 'creation.advanced' | translate }} {{ 'creation.advanced' | translate }}
</button> </button>
<fieldset class="complete well" *ngIf="advancedDisplayEnabled"> <fieldset class="complete well" *ngIf="advancedDisplayEnabled">
<h2>{{ 'creation.advanced' | translate }}</h2> <h2>{{ 'creation.advanced' | translate }}</h2>
<br /> <br />
<label for="slug">Url pour les participants </label> <label for="slug">Url pour les participants </label>
<br /> <br />
<span <span
>{{ urlPrefix }} <strong> {{ form.controls.custom_url.value }} </strong> >{{ urlPrefix }} <strong> {{ pollService.form.controls.custom_url.value }} </strong>
</span> </span>
<app-copy-text [textToCopy]="urlPrefix + form.controls.custom_url.value"></app-copy-text> <app-copy-text
[textToCopy]="urlPrefix + pollService.form.controls.custom_url.value"
></app-copy-text>
<button <button
mat-button mat-button
*ngIf="form.controls.custom_url.value" *ngIf="form.controls.custom_url.value"
matSuffix matSuffix
mat-icon-button mat-icon-button
aria-label="Clear" aria-label="Clear"
(click)="slug.value = ''" (click)="slug.value = ''"
></button> ></button>
<input #slug matInput id="slug" placeholder="Url" formControlName="slug" required /> <input #slug matInput id="slug" placeholder="Url" formControlName="slug" required />
<br /> <br />
<div appearance="outline" class="is-not-flex"> <div appearance="outline" class="is-not-flex">
<mat-label>Nombre de jours avant expiration</mat-label> <mat-label>Nombre de jours avant expiration</mat-label>
<input <input
#expiracy #expiracy
id="expiracy" id="expiracy"
matInput matInput
type="number" type="number"
placeholder="Nombre de jours avant expiration" placeholder="Nombre de jours avant expiration"
formControlName="expiracyNumberOfDays" formControlName="expiracyNumberOfDays"
required required
/> />
<button <button
mat-button mat-button
*ngIf="expiracy.value" *ngIf="expiracy.value"
matSuffix matSuffix
mat-icon-button mat-icon-button
aria-label="Clear" aria-label="Clear"
(click)="expiracy.value = ''" (click)="expiracy.value = ''"
> >
<i class="fa fa-close"></i> <i class="fa fa-close"></i>
</button>
</div>
<br />
<mat-checkbox class="is-not-flex" formControlName="areResultsPublic">
Les participants pourront consulter les résultats
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isAboutDate">
Les choix possibles concerneront des dates
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isProtectedByPassword">
Le sondage sera protégé par un mot de passe
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isOwnerNotifiedByEmailOnNewVote">
Vous recevrez un mail à chaque nouvelle participation
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isOwnerNotifiedByEmailOnNewComment">
Vous recevrez un mail à chaque nouveau commentaire
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isMaybeAnswerAvailable">
La réponse « peut-être » sera disponible
</mat-checkbox>
</fieldset>
</fieldset>
</form>
</div>
<div class="columns">
<div class="column">
<button class="button is-secondary is-fullwidth" [routerLink]="['/administration/step/4']">
précédent
</button> </button>
</div> </div>
<br /> <div class="column">
<mat-checkbox class="is-not-flex" formControlName="areResultsPublic"> <!-- [disabled]="form.invalid"-->
Les participants pourront consulter les résultats <button class="button is-primary is-fullwidth" [routerLink]="['/administration/step/5']">
</mat-checkbox> suivant
<br /> </button>
<mat-checkbox class="is-not-flex" formControlName="isAboutDate"> </div>
Les choix possibles concerneront des dates </div>
</mat-checkbox> </div>
<br />
<mat-checkbox class="is-not-flex" formControlName="isProtectedByPassword">
Le sondage sera protégé par un mot de passe
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isOwnerNotifiedByEmailOnNewVote">
Vous recevrez un mail à chaque nouvelle participation
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isOwnerNotifiedByEmailOnNewComment">
Vous recevrez un mail à chaque nouveau commentaire
</mat-checkbox>
<br />
<mat-checkbox class="is-not-flex" formControlName="isMaybeAnswerAvailable">
La réponse « peut-être » sera disponible
</mat-checkbox>
</fieldset>
</fieldset>

View File

@ -1,4 +1,5 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { PollService } from '../../../../core/services/poll.service';
@Component({ @Component({
selector: 'app-step-four', selector: 'app-step-four',
@ -12,7 +13,7 @@ export class StepFourComponent implements OnInit {
step_max: any; step_max: any;
@Input() @Input()
form: any; form: any;
constructor() {} constructor(public pollService: PollService) {}
ngOnInit(): void {} ngOnInit(): void {}
} }

View File

@ -62,89 +62,27 @@
</div> </div>
<hr /> <hr />
<span class="count-dates title"> <span class="count-dates title">
{{ pollService.dateList.length }} {{ pollService.calendar.length }}
</span> </span>
<span> <span>
{{ 'dates.count_dates' | translate }} {{ 'dates.count_dates' | translate }}
</span> </span>
<button class="btn btn--primary" (click)="pollService.addChoice()"> <div class="calendar">
{{ 'dates.add' | translate }} <p-calendar
</button> [(ngModel)]="pollService.calendar"
<div *ngFor="let choice of pollService.dateList; index as id" class="date-choice"> firstDayOfWeek="5"
<input selectionMode="multiple"
[(ngModel)]="choice.date_object" inputId="multiple"
name="dateChoices_{{ id }}" showButtonBar="true"
id="dateChoices_{{ id }}" [inline]="true"
useValueAsDate [showWeek]="true"
type="date" ></p-calendar>
/>
<button (click)="pollService.dateList.splice(id, 1)" class="btn btn-warning">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
<button
(click)="pollService.addTimeToDate(choice, id)"
*ngIf="'true' === pollService.allowSeveralHours"
class="btn btn--primary"
>
{{ 'dates.add_time' | translate }}
</button>
<div *ngIf="'true' === pollService.allowSeveralHours" class="several-times">
<div *ngFor="let timeItem of choice.timeList; index as idTime" class="time-choice">
<input
[(ngModel)]="timeItem.literal"
name="dateTime_{{ id }}_Choices_{{ idTime }}"
id="dateTime_{{ id }}_Choices_{{ idTime }}"
type="text"
/>
<button (click)="choice.timeList.splice(idTime, 1)" class="btn btn-warning">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>
</div> </div>
</div>
<button <!-- <div class="debug">-->
(click)="pollService.showDateInterval = !pollService.showDateInterval" <!-- <pre>{{pollService.calendar |json}}</pre>-->
[ngClass]="{ active: pollService.showDateInterval }" <!-- </div>-->
class="btn btn--primary" </div>
id="toggle_interval_button"
>
<i class="fa fa-clock-o" aria-hidden="true"></i>
{{ 'dates.add_interval' | translate }}
</button>
<section *ngIf="pollService.showDateInterval" class="date-interval form-row">
<h2>{{ 'dates.add_interval' | translate }}</h2>
<div class="columns">
<div class="column">
{{ 'dates.interval_propose' | translate }}
</div>
<div class="column">
<label for="start_interval" class="hidden">start</label>
<input
id="start_interval"
(change)="pollService.countDays()"
formControlName="startDateInterval"
type="date"
/>
</div>
</div>
<div class="columns">
<div class="column">
{{ 'dates.interval_span' | translate }}
</div>
<div class="column">
<label for="end_interval" class="hidden">end</label>
<input id="end_interval" formControlName="endDateInterval" type="date" />
</div>
</div>
<button (click)="pollService.addIntervalOfDates()" class="btn btn-block btn--primary">
<i class="fa fa-plus" aria-hidden="true"></i>
{{ 'dates.interval_button' | translate }}
{{ pollService.intervalDays }}
{{ 'dates.interval_button_dates' | translate }}
</button>
</section>
</div> </div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">

View File

@ -0,0 +1,9 @@
@import '../../../../../styles/variables';
.ui-datepicker table td.ui-datepicker-today > a.ui-state-active,
.ui-datepicker table td.ui-datepicker-today > span.ui-state-active {
background-color: $primary-color !important;
}
.calendar {
margin-top: 1em;
}

View File

@ -27,7 +27,7 @@
}, },
"creation": { "creation": {
"title": "Créer un sondage", "title": "Créer un sondage",
"want": "Je veux créer un sondage", "want": "Choisissez le type de sondage",
"advanced": "Options avancées", "advanced": "Options avancées",
"kind": { "kind": {
"classic": "Textes", "classic": "Textes",