From ae446afb0a421a71ba8fcd4a1aff5c86de5bb347 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Wed, 13 Dec 2023 13:42:55 +0100 Subject: [PATCH 01/16] remove unused logic and change hours to input v3 --- .../hour-picker/hour-picker.component.html | 65 ++++++----- .../hour-picker/hour-picker.component.scss | 37 +++---- .../hour-picker/hour-picker.component.ts | 101 ++++++++---------- .../v3/switch/switch.component.scss | 4 + 4 files changed, 96 insertions(+), 111 deletions(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html index 23edf282a..746f4a6c4 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.html +++ b/src/app/shared/components/hour-picker/hour-picker.component.html @@ -7,10 +7,7 @@ (click)="activateDay(day)" (keyup.enter)="activateDay(day)" > - <div - class="header-container sub-text" - [ngClass]="modifiedFields && modifiedFields.hours && modifiedFields.hours[day.name] ? 'modified' : ''" - > + <div class="header-container sub-text"> <app-switch checkedText="Ouvert" uncheckedText="Fermé" @@ -22,44 +19,46 @@ <div *ngIf="day.open" class="row-container"> <div *ngIf="day.active" class="active"> - <div *ngFor="let hour of day.hours; let i = index" class="hour"> - <div>de</div> - - <div class="input-container"> - <input type="time" [(ngModel)]="hour.start" (change)="submitForm()" /> - </div> - - <div>à </div> - - <div class="input-container"> - <input type="time" [(ngModel)]="hour.end" (change)="submitForm()" (blur)="onBlur()" (focus)="onFocus()" /> - </div> + <div *ngFor="let hour of day.hours; let index = index" class="hour"> + <app-input + [id]="day.name + 'from'" + [type]="'time'" + [label]="'De :'" + [size]="'large'" + [status]="getStatus(hour)" + [statusText]="getStatusText(hour)" + [(value)]="hour.start" + (appClickOutside)="submitForm()" + /> - <div> - <div *ngIf="hour.error === 'wrong' || hour.error === 'incomplete'" class="error-message"> - <app-svg-icon [iconClass]="'icon-32'" [type]="'ico'" [icon]="'nok'" /> - </div> - <div *ngIf="hour.error === null" class="error-message"> - <app-svg-icon [iconClass]="'icon-32'" [type]="'ico'" [icon]="'ok'" /> - </div> - </div> - </div> - <div *ngIf="day.hours.length === 1" class="extraAction"> - <app-v3-button - [variant]="buttonTypeEnumV3.PrimaryBlack" - [label]="'Ajouter un horaire'" - [wide]="true" - (action)="addHours(day)" + <app-input + [id]="day.name + 'to'" + [type]="'time'" + [label]="'Jusqu’à :'" + [size]="'large'" + [status]="getStatus(hour)" + [statusText]="getStatusText(hour)" + [(value)]="hour.end" + (appClickOutside)="submitForm()" /> - </div> - <div *ngIf="day.hours.length === 2" class="extraAction"> + <app-v3-button + *ngIf="day.hours.length === 2 && index === 1" + style="margin-top: 3px" [variant]="buttonTypeEnumV3.Secondary" [label]="'Supprimer'" [iconName]="'deleteV3'" (action)="this.removeHours(day, 1)" /> </div> + + <app-v3-button + *ngIf="day.hours.length === 1" + [variant]="buttonTypeEnumV3.PrimaryBlack" + [label]="'Ajouter un horaire'" + [wide]="true" + (action)="addHours(day)" + /> </div> </div> </div> diff --git a/src/app/shared/components/hour-picker/hour-picker.component.scss b/src/app/shared/components/hour-picker/hour-picker.component.scss index c9fa42903..c25bd3ea3 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.scss +++ b/src/app/shared/components/hour-picker/hour-picker.component.scss @@ -14,20 +14,20 @@ gap: 12px; align-self: stretch; border-radius: 4px; - border: 1px solid var(--grey-6, #dedede); + border: 1px solid $grey-6; .row-container { - display: flex; + border-top: 1px solid $grey-6; + width: 100%; padding-top: 12px; - flex-direction: column; - align-items: flex-start; - gap: 16px; - align-self: stretch; - border-top: 1px solid var(--grey-6, #dedede); + padding-inline: 16px; + box-sizing: border-box; } .active { display: flex; + flex-direction: column; flex-wrap: wrap; + gap: 16px; max-width: 400px; @media #{$large-phone} { grid-template-columns: unset; @@ -35,19 +35,15 @@ grid-row-gap: 20px; } } - .extraAction { - display: grid; - align-items: center; - } .hour { - height: 40px; - display: grid; - // grid-template-columns: auto 70px auto 70px 30px 80px 1fr; - grid-template-columns: auto 52px auto 61px 30px 0px; - column-gap: 10px; + display: flex; + gap: 24px; align-items: center; - justify-items: center; + + ::ng-deep input { + max-width: 150px; + } } } } @@ -94,13 +90,6 @@ img { } } -.modified { - border-left: 3px solid red; - padding-left: 8px; - margin-left: -11px; - border-radius: 3px; -} - .warning-message, .error-message { font-weight: bold; diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts index b44a921a3..9a97347d2 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.ts +++ b/src/app/shared/components/hour-picker/hour-picker.component.ts @@ -6,27 +6,34 @@ import { WeekDayEnum } from '../../enum/weekDay.enum'; import { CheckHours } from '../../validator/form'; import { ButtonTypeV3 } from '../v3/button/button-type.enum'; +interface DayHour { + name: WeekDayEnum; + hours: { + start: string; + end: string; + error: string; + }[]; + open: boolean; + active: boolean; +} + @Component({ selector: 'app-hour-picker', templateUrl: './hour-picker.component.html', styleUrls: ['./hour-picker.component.scss'], }) export class HourPickerComponent implements OnChanges, OnDestroy { - @Input() modifiedFields: any; @Input() structureInput: UntypedFormGroup; @Output() updateFormError = new EventEmitter<any>(); @Output() updateForm = new EventEmitter<UntypedFormGroup>(); public buttonTypeEnumV3 = ButtonTypeV3; - public error = false; - private copiedDay: any; private isInputSelected = false; - public copiedDayName = ''; public structure = { hours: this.initHoursDefault(), }; - public structureHoursDefault: any[] = this.initHoursDefault(); + public structureHoursDefault: DayHour[] = this.initHoursDefault(); ngOnChanges(): void { this.formatHoursForEdition(); @@ -40,46 +47,46 @@ export class HourPickerComponent implements OnChanges, OnDestroy { return this.structureInput.get(nameControl); } - private initHoursDefault(): any { + private initHoursDefault(): DayHour[] { return [ { - name: 'Lundi', + name: WeekDayEnum.monday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, active: false, }, { - name: 'Mardi', + name: WeekDayEnum.tuesday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, active: false, }, { - name: 'Mercredi', + name: WeekDayEnum.wednesday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, active: false, }, { - name: 'Jeudi', + name: WeekDayEnum.thursday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, active: false, }, { - name: 'Vendredi', + name: WeekDayEnum.friday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, active: false, }, { - name: 'Samedi', + name: WeekDayEnum.saturday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, active: false, }, { - name: 'Dimanche', + name: WeekDayEnum.sunday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, active: false, @@ -87,9 +94,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { ]; } - /** - * Convert data from form to component structure - */ + /** Convert data from to component structure */ private parseFormToHours(day: Day, key: string): void { this.structureHoursDefault.forEach((element) => { if (element.name.toLowerCase() === key) { @@ -189,11 +194,11 @@ export class HourPickerComponent implements OnChanges, OnDestroy { } } - public activateDay(day: any): void { + public activateDay(day: DayHour): void { day.active = true; } - public toggleOpenDay(day: any, checked: boolean): void { + public toggleOpenDay(day: DayHour, checked: boolean): void { day.open = checked; if (!checked) { day.hours = []; @@ -201,10 +206,8 @@ export class HourPickerComponent implements OnChanges, OnDestroy { this.submitForm(); } - /** - * Ajouter une ligne d'horaires à un jour - */ - public addHours(day: any): void { + /** Ajouter une ligne d'horaires à un jour */ + public addHours(day: DayHour): void { if (day.hours.length >= 5) { return; } @@ -217,43 +220,17 @@ export class HourPickerComponent implements OnChanges, OnDestroy { this.submitForm(); } - /** - * Supprimer la dernière ligne d'horaires d'un jour - */ - public removeHours(day: any, index: number): void { + /** Supprimer la dernière ligne d'horaires d'un jour */ + public removeHours(day: DayHour, index: number): void { + console.log('remove hours'); + console.log('🚀 ~ file: hour-picker.component.ts:225 ~ HourPickerComponent ~ removeHours ~ day:', day); if (index > -1) { day.hours.splice(index, 1); this.submitForm(); } } - /** - * Copier les horaires d'un jour pour les coller par dessus les horaires d'un autre jour - */ - public copy(day): void { - this.copiedDayName = day.name; - this.copiedDay = day; - } - - /** - * Remplacer les horaires d'un jour par les horaires copiés précédemment - */ - public paste(day): void { - day.hours = JSON.parse(JSON.stringify(this.copiedDay.hours)); - day.open = this.copiedDay.open; - } - - /** - * Annuler la copie des horaires - */ - public cancelCopy(): void { - this.copiedDayName = ''; - this.copiedDay = null; - } - - /** - * Vérifier que le format des horaires est correct - */ + /** Vérifier que le format des horaires est correct */ public checkHoursValid(): boolean { let error = false; for (const day of this.structure.hours) { @@ -301,7 +278,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { private createDay(day: Day): UntypedFormGroup { return new UntypedFormGroup({ open: new UntypedFormControl(day.open, Validators.required), - time: new UntypedFormArray(day.time.map((oneTime) => this.createTime(oneTime))) as UntypedFormArray, + time: new UntypedFormArray(day.time.map((oneTime) => this.createTime(oneTime))), }); } @@ -311,4 +288,20 @@ export class HourPickerComponent implements OnChanges, OnDestroy { closing: new UntypedFormControl(time.closing, [Validators.required, CheckHours(time.opening)]), }); } + + getStatus(hour: { start: string; end: string; error: string }): 'error' | 'success' | null { + if (hour.error === 'wrong' || hour.error === 'incomplete') { + return 'error'; + } else if (hour.error === null) { + return 'success'; + } + } + + getStatusText(hour: { start: string; end: string; error: string }): 'Horaire invalide' | 'Horaire valide' { + if (hour.error === 'wrong' || hour.error === 'incomplete') { + return 'Horaire invalide'; + } else if (hour.error === null) { + return 'Horaire valide'; + } + } } diff --git a/src/app/shared/components/v3/switch/switch.component.scss b/src/app/shared/components/v3/switch/switch.component.scss index 1ab25c23c..d2791762b 100644 --- a/src/app/shared/components/v3/switch/switch.component.scss +++ b/src/app/shared/components/v3/switch/switch.component.scss @@ -28,4 +28,8 @@ @include font-regular-12; } } + + span { + text-transform: capitalize; + } } -- GitLab From db33f48140184ad1d7534f48ac5e977c749bb453 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Wed, 13 Dec 2023 13:55:51 +0100 Subject: [PATCH 02/16] cleanup styles --- .../hour-picker/hour-picker.component.html | 85 ++++++++---------- .../hour-picker/hour-picker.component.scss | 89 ++++--------------- .../hour-picker/hour-picker.component.ts | 2 + 3 files changed, 56 insertions(+), 120 deletions(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html index 746f4a6c4..8f81f1cb5 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.html +++ b/src/app/shared/components/hour-picker/hour-picker.component.html @@ -1,13 +1,6 @@ <div class="days"> - <div - *ngFor="let day of structure.hours" - class="day" - tabindex="0" - [ngClass]="{ active: day.active }" - (click)="activateDay(day)" - (keyup.enter)="activateDay(day)" - > - <div class="header-container sub-text"> + <div *ngFor="let day of structure.hours" class="day"> + <div class="dayHeader"> <app-switch checkedText="Ouvert" uncheckedText="Fermé" @@ -17,49 +10,47 @@ /> </div> - <div *ngIf="day.open" class="row-container"> - <div *ngIf="day.active" class="active"> - <div *ngFor="let hour of day.hours; let index = index" class="hour"> - <app-input - [id]="day.name + 'from'" - [type]="'time'" - [label]="'De :'" - [size]="'large'" - [status]="getStatus(hour)" - [statusText]="getStatusText(hour)" - [(value)]="hour.start" - (appClickOutside)="submitForm()" - /> - - <app-input - [id]="day.name + 'to'" - [type]="'time'" - [label]="'Jusqu’à :'" - [size]="'large'" - [status]="getStatus(hour)" - [statusText]="getStatusText(hour)" - [(value)]="hour.end" - (appClickOutside)="submitForm()" - /> + <div *ngIf="day.open" class="dayContent"> + <div *ngFor="let hour of day.hours; let index = index" class="hour"> + <app-input + [id]="day.name + 'from'" + [type]="'time'" + [label]="'De :'" + [size]="'large'" + [status]="getStatus(hour)" + [statusText]="getStatusText(hour)" + [(value)]="hour.start" + (appClickOutside)="submitForm()" + /> - <app-v3-button - *ngIf="day.hours.length === 2 && index === 1" - style="margin-top: 3px" - [variant]="buttonTypeEnumV3.Secondary" - [label]="'Supprimer'" - [iconName]="'deleteV3'" - (action)="this.removeHours(day, 1)" - /> - </div> + <app-input + [id]="day.name + 'to'" + [type]="'time'" + [label]="'Jusqu’à :'" + [size]="'large'" + [status]="getStatus(hour)" + [statusText]="getStatusText(hour)" + [(value)]="hour.end" + (appClickOutside)="submitForm()" + /> <app-v3-button - *ngIf="day.hours.length === 1" - [variant]="buttonTypeEnumV3.PrimaryBlack" - [label]="'Ajouter un horaire'" - [wide]="true" - (action)="addHours(day)" + *ngIf="day.hours.length === 2 && index === 1" + style="margin-top: 3px" + [variant]="buttonTypeEnumV3.Secondary" + [label]="'Supprimer'" + [iconName]="'deleteV3'" + (action)="this.removeHours(day, 1)" /> </div> + + <app-v3-button + *ngIf="day.hours.length === 1" + [variant]="buttonTypeEnumV3.PrimaryBlack" + [label]="'Ajouter un horaire'" + [wide]="true" + (action)="addHours(day)" + /> </div> </div> </div> diff --git a/src/app/shared/components/hour-picker/hour-picker.component.scss b/src/app/shared/components/hour-picker/hour-picker.component.scss index c25bd3ea3..2c0086399 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.scss +++ b/src/app/shared/components/hour-picker/hour-picker.component.scss @@ -16,89 +16,32 @@ border-radius: 4px; border: 1px solid $grey-6; - .row-container { + .dayHeader { + padding-inline: 8px; + } + + .dayContent { border-top: 1px solid $grey-6; width: 100%; padding-top: 12px; padding-inline: 16px; box-sizing: border-box; - } - .active { display: flex; flex-direction: column; - flex-wrap: wrap; gap: 16px; - max-width: 400px; - @media #{$large-phone} { - grid-template-columns: unset; - grid-template-rows: 1fr 1fr; - grid-row-gap: 20px; - } - } - - .hour { - display: flex; - gap: 24px; - align-items: center; - ::ng-deep input { - max-width: 150px; + .hour { + display: flex; + gap: 24px; + align-items: center; + + ::ng-deep input { + width: 150px; + @media #{$tablet} { + width: unset; + } + } } } } } - -.grey-rounded-border { - border: 1px solid $grey-5; - box-sizing: border-box; - border-radius: 22px; - @include font-regular-14; - color: $grey-2; - display: flex; - justify-content: center; -} - -.grid-center { - display: grid; - align-items: center; -} - -input { - background: $grey-9; - border: 1px solid $grey-5; - box-sizing: border-box; - border-radius: 4px; - height: 36px; - margin-top: 0; - @include font-regular-14; - min-width: 56px; - text-align: center; - outline: none; -} - -p { - margin-top: 0px; -} - -img { - cursor: pointer; - height: 15px; - width: 15px; - &.add { - height: 20px; - width: 20px; - } -} - -.warning-message, -.error-message { - font-weight: bold; - font-size: 1em; - display: grid; - align-items: center; -} - -input[type='time']::-webkit-calendar-picker-indicator { - background: none; - display: none; -} diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts index 9a97347d2..37f5be575 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.ts +++ b/src/app/shared/components/hour-picker/hour-picker.component.ts @@ -14,6 +14,7 @@ interface DayHour { error: string; }[]; open: boolean; + /** can be removed */ active: boolean; } @@ -200,6 +201,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { public toggleOpenDay(day: DayHour, checked: boolean): void { day.open = checked; + day.active = checked; if (!checked) { day.hours = []; } -- GitLab From 2f5ac70e75bf35057aacf34e3ecd7e85e20a112b Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Wed, 13 Dec 2023 13:57:45 +0100 Subject: [PATCH 03/16] remove property active --- .../hour-picker/hour-picker.component.ts | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts index 37f5be575..5634da6ce 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.ts +++ b/src/app/shared/components/hour-picker/hour-picker.component.ts @@ -14,8 +14,6 @@ interface DayHour { error: string; }[]; open: boolean; - /** can be removed */ - active: boolean; } @Component({ @@ -54,43 +52,36 @@ export class HourPickerComponent implements OnChanges, OnDestroy { name: WeekDayEnum.monday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, }, { name: WeekDayEnum.tuesday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, }, { name: WeekDayEnum.wednesday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, }, { name: WeekDayEnum.thursday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, }, { name: WeekDayEnum.friday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, }, { name: WeekDayEnum.saturday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, }, { name: WeekDayEnum.sunday, hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, }, ]; } @@ -100,7 +91,6 @@ export class HourPickerComponent implements OnChanges, OnDestroy { this.structureHoursDefault.forEach((element) => { if (element.name.toLowerCase() === key) { element.open = day.open; - element.active = day.open; element.hours = day.time.map((hour: Time) => { if (hour.opening && hour.closing) { return { @@ -130,12 +120,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { this.structure.hours = this.structureHoursDefault; } - private parseToDay(data: { - name: string; - hours: { start: string; end: string }[]; - open: boolean; - active: boolean; - }): Day { + private parseToDay(data: DayHour): Day { return new Day({ open: data.open, time: data.hours.map( @@ -188,20 +173,16 @@ export class HourPickerComponent implements OnChanges, OnDestroy { for (const day of this.structure.hours) { delete day.open; - delete day.active; + for (const hour of day.hours) { delete hour.error; } } } - public activateDay(day: DayHour): void { - day.active = true; - } - public toggleOpenDay(day: DayHour, checked: boolean): void { day.open = checked; - day.active = checked; + if (!checked) { day.hours = []; } -- GitLab From ac98ef6e34b8225ebd029b18acaed79000725235 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Wed, 13 Dec 2023 14:16:11 +0100 Subject: [PATCH 04/16] remove stylesheet --- .../structure-hours/structure-hours.component.html | 2 +- .../structure-hours/structure-hours.component.scss | 3 --- .../structure-hours/structure-hours.component.ts | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 src/app/form/form-view/structure-form/structure-hours/structure-hours.component.scss diff --git a/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.html b/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.html index 68b8ddeb0..2b19ccac6 100644 --- a/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.html +++ b/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.html @@ -11,7 +11,7 @@ (updateFormError)="setHoursError()" /> - <div class="title secondTitle"> + <div class="title"> <h3>Avez-vous des précisions à apporter sur les horaires ?</h3> <p>Facultatif</p> </div> diff --git a/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.scss b/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.scss deleted file mode 100644 index f28ea0cf8..000000000 --- a/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.scss +++ /dev/null @@ -1,3 +0,0 @@ -.secondTitle { - margin-top: 28px; -} diff --git a/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.ts b/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.ts index 3be5fa8d9..98fd4d6aa 100644 --- a/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.ts +++ b/src/app/form/form-view/structure-form/structure-hours/structure-hours.component.ts @@ -4,7 +4,6 @@ import { UntypedFormGroup } from '@angular/forms'; @Component({ selector: 'app-structure-hours', templateUrl: './structure-hours.component.html', - styleUrls: ['./structure-hours.component.scss'], }) export class StructureHoursComponent implements OnInit { @Input() structureForm: UntypedFormGroup; -- GitLab From 4eac600cc1863fd43e556904c33d93b1f1d5a605 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Wed, 13 Dec 2023 14:20:34 +0100 Subject: [PATCH 05/16] refactor input --- src/app/profile/edit/edit.component.html | 6 +++--- .../shared/components/v3/input/input.component.html | 4 ++-- .../shared/components/v3/input/input.component.ts | 12 +++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/app/profile/edit/edit.component.html b/src/app/profile/edit/edit.component.html index 5cdc80797..ae297e26c 100644 --- a/src/app/profile/edit/edit.component.html +++ b/src/app/profile/edit/edit.component.html @@ -76,21 +76,21 @@ [label]="'Prénom'" [size]="'large'" [status]="getStatus(nameValid())" - [(ngModelValue)]="userProfile.name" + [(value)]="userProfile.name" /> <app-input [id]="'surname'" [label]="'Nom'" [size]="'large'" [status]="getStatus(surnameValid())" - [(ngModelValue)]="userProfile.surname" + [(value)]="userProfile.surname" /> <app-input [id]="'phone'" [label]="'Téléphone'" [size]="'large'" [status]="getStatus(phoneValid())" - [(ngModelValue)]="userProfile.phone" + [(value)]="userProfile.phone" /> </div> diff --git a/src/app/shared/components/v3/input/input.component.html b/src/app/shared/components/v3/input/input.component.html index bf6dccfc1..d86d94450 100644 --- a/src/app/shared/components/v3/input/input.component.html +++ b/src/app/shared/components/v3/input/input.component.html @@ -7,8 +7,8 @@ [id]="id" [disabled]="disabled" [ngClass]="classes" - [ngModel]="ngModelValue" - (ngModelChange)="ngModelValueChange.emit($event)" + [(ngModel)]="value" + (change)="onChange($event)" /> <div *ngIf="status && getStatusText()" class="status" [ngClass]="status"> <img *ngIf="status === 'error'" src="assets/ico/error-rounded.svg" alt="" /> diff --git a/src/app/shared/components/v3/input/input.component.ts b/src/app/shared/components/v3/input/input.component.ts index 6aebd93ed..773b339cd 100644 --- a/src/app/shared/components/v3/input/input.component.ts +++ b/src/app/shared/components/v3/input/input.component.ts @@ -9,7 +9,7 @@ export class InputV3Component { /** HTML id associated with for */ @Input() id: string; - @Input() type: 'text' | 'password' = 'text'; + @Input() type: 'text' | 'password' | 'time' = 'text'; @Input() disabled = false; @@ -27,14 +27,20 @@ export class InputV3Component { /** Additional text to display */ @Input() statusText?: string; - @Input() ngModelValue: string; + @Input() value: string; - @Output() ngModelValueChange = new EventEmitter<string>(); + /** Triggers when input changes */ + @Output() valueChange = new EventEmitter<string>(); public get classes(): string { return [this.size, this.status].join(' '); } + public onChange(event: Event): void { + this.value = (event.target as HTMLInputElement).value; + this.valueChange.emit(this.value); + } + getStatusText(): string { if (this.statusText) return this.statusText; -- GitLab From 0ce36caee6cd904b92364bd99df5830fe996bd36 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Wed, 13 Dec 2023 14:31:08 +0100 Subject: [PATCH 06/16] merge week models --- src/app/models/day.model.ts | 12 ----- src/app/models/structure.model.ts | 3 +- src/app/models/time.model.ts | 20 --------- src/app/models/week.model.ts | 44 ++++++++++++++++++- .../hour-picker/hour-picker.component.ts | 4 +- src/app/shared/enum/weekDay.enum.ts | 9 ---- src/app/shared/pipes/day.pipe.ts | 2 +- src/app/utils/formUtils.ts | 4 +- 8 files changed, 46 insertions(+), 52 deletions(-) delete mode 100644 src/app/models/day.model.ts delete mode 100644 src/app/models/time.model.ts diff --git a/src/app/models/day.model.ts b/src/app/models/day.model.ts deleted file mode 100644 index 988336f4b..000000000 --- a/src/app/models/day.model.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Time } from './time.model'; - -export class Day { - open = false; - time: Time[]; - - constructor(obj?: any) { - Object.assign(this, obj, { - time: obj?.time ? obj.time.map((time) => new Time(time)) : [], - }); - } -} diff --git a/src/app/models/structure.model.ts b/src/app/models/structure.model.ts index cb2ee1526..a862d9f77 100644 --- a/src/app/models/structure.model.ts +++ b/src/app/models/structure.model.ts @@ -3,11 +3,10 @@ import { StructureCategoryIconEnum } from '../shared/enum/structureCategoryIcon. import { Equipment } from '../structure-list/enum/equipment.enum'; import { Weekday } from '../structure-list/enum/weekday.enum'; import { Address } from './address.model'; -import { Day } from './day.model'; import { OpeningDay } from './openingDay.model'; import { PersonalOffer } from './personalOffer.model'; import { StructureType } from './structureType.model'; -import { Week } from './week.model'; +import { Day, Week } from './week.model'; export class Structure { public _id: string = null; diff --git a/src/app/models/time.model.ts b/src/app/models/time.model.ts deleted file mode 100644 index 7db99ae8b..000000000 --- a/src/app/models/time.model.ts +++ /dev/null @@ -1,20 +0,0 @@ -export class Time { - opening: string; - closing: string; - - constructor(obj?: any) { - Object.assign(this, obj); - } - - public formatOpeningDate(): string { - return this.formatDate(this.opening); - } - - public formatClosingDate(): string { - return this.formatDate(this.closing); - } - - private formatDate(n: string): string { - return n.replace(':', 'h'); - } -} diff --git a/src/app/models/week.model.ts b/src/app/models/week.model.ts index 94e35a67c..f61a32bf6 100644 --- a/src/app/models/week.model.ts +++ b/src/app/models/week.model.ts @@ -1,7 +1,47 @@ -import { Day } from './day.model'; - type dayType = 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday'; +export enum WeekDayEnum { + monday = 'lundi', + tuesday = 'mardi', + wednesday = 'mercredi', + thursday = 'jeudi', + friday = 'vendredi', + saturday = 'samedi', + sunday = 'dimanche', +} + +export class Time { + opening: string; + closing: string; + + constructor(obj?: any) { + Object.assign(this, obj); + } + + public formatOpeningDate(): string { + return this.formatDate(this.opening); + } + + public formatClosingDate(): string { + return this.formatDate(this.closing); + } + + private formatDate(n: string): string { + return n.replace(':', 'h'); + } +} + +export class Day { + open = false; + time: Time[]; + + constructor(obj?: any) { + Object.assign(this, obj, { + time: obj?.time ? obj.time.map((time) => new Time(time)) : [], + }); + } +} + export class Week { monday: Day; tuesday: Day; diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts index 5634da6ce..33bd385e8 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.ts +++ b/src/app/shared/components/hour-picker/hour-picker.component.ts @@ -1,8 +1,6 @@ import { Component, EventEmitter, Input, OnChanges, OnDestroy, Output } from '@angular/core'; import { AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; -import { Day } from '../../../models/day.model'; -import { Time } from '../../../models/time.model'; -import { WeekDayEnum } from '../../enum/weekDay.enum'; +import { Day, Time, WeekDayEnum } from '../../../models/week.model'; import { CheckHours } from '../../validator/form'; import { ButtonTypeV3 } from '../v3/button/button-type.enum'; diff --git a/src/app/shared/enum/weekDay.enum.ts b/src/app/shared/enum/weekDay.enum.ts index 6935e53db..e69de29bb 100644 --- a/src/app/shared/enum/weekDay.enum.ts +++ b/src/app/shared/enum/weekDay.enum.ts @@ -1,9 +0,0 @@ -export enum WeekDayEnum { - monday = 'lundi', - tuesday = 'mardi', - wednesday = 'mercredi', - thursday = 'jeudi', - friday = 'vendredi', - saturday = 'samedi', - sunday = 'dimanche', -} diff --git a/src/app/shared/pipes/day.pipe.ts b/src/app/shared/pipes/day.pipe.ts index f8a64598e..d722ceeb0 100644 --- a/src/app/shared/pipes/day.pipe.ts +++ b/src/app/shared/pipes/day.pipe.ts @@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'day', pure: false }) export class DayPipe implements PipeTransform { - transform(day: string): any { + transform(day: string): 'lundi' | 'mardi' | 'jeudi' | 'mercredi' | 'vendredi' | 'samedi' | 'dimanche' { switch (day) { case 'monday': return 'lundi'; diff --git a/src/app/utils/formUtils.ts b/src/app/utils/formUtils.ts index 139a03a11..70f1cf016 100644 --- a/src/app/utils/formUtils.ts +++ b/src/app/utils/formUtils.ts @@ -1,9 +1,7 @@ import { UntypedFormArray, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; import { structureFormStep } from '../form/form-view/structure-form/structureFormStep.enum'; -import { Day } from '../models/day.model'; import { Structure } from '../models/structure.model'; -import { Time } from '../models/time.model'; -import { Week } from '../models/week.model'; +import { Day, Time, Week } from '../models/week.model'; import { CustomRegExp } from './CustomRegExp'; import { FormValidators } from './formValidators'; -- GitLab From 4c20a9b2ba9bb61d0ea99875e7fa00ec5f6cb470 Mon Sep 17 00:00:00 2001 From: Pierre Ecarlat <pecarlat@grandlyon.com> Date: Mon, 18 Dec 2023 09:06:15 +0000 Subject: [PATCH 07/16] Apply 1 suggestion(s) to 1 file(s) --- .../shared/components/hour-picker/hour-picker.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html index 8f81f1cb5..90d4b0f6b 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.html +++ b/src/app/shared/components/hour-picker/hour-picker.component.html @@ -40,7 +40,7 @@ [variant]="buttonTypeEnumV3.Secondary" [label]="'Supprimer'" [iconName]="'deleteV3'" - (action)="this.removeHours(day, 1)" + (action)="removeHours(day, 1)" /> </div> -- GitLab From 73b82882842a258e1610147c13193e68cf3ebf02 Mon Sep 17 00:00:00 2001 From: Pierre Ecarlat <pecarlat@grandlyon.com> Date: Mon, 18 Dec 2023 09:06:44 +0000 Subject: [PATCH 08/16] Apply 1 suggestion(s) to 1 file(s) --- src/app/models/week.model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/models/week.model.ts b/src/app/models/week.model.ts index f61a32bf6..4e7a1321d 100644 --- a/src/app/models/week.model.ts +++ b/src/app/models/week.model.ts @@ -35,7 +35,7 @@ export class Day { open = false; time: Time[]; - constructor(obj?: any) { + constructor(obj?: Day) { Object.assign(this, obj, { time: obj?.time ? obj.time.map((time) => new Time(time)) : [], }); -- GitLab From 8414fdab847234d4fc9d785069dee76ba3b3e2a7 Mon Sep 17 00:00:00 2001 From: Pierre Ecarlat <pecarlat@grandlyon.com> Date: Mon, 18 Dec 2023 09:07:00 +0000 Subject: [PATCH 09/16] Apply 1 suggestion(s) to 1 file(s) --- .../shared/components/hour-picker/hour-picker.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html index 90d4b0f6b..6a0b3747f 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.html +++ b/src/app/shared/components/hour-picker/hour-picker.component.html @@ -13,7 +13,7 @@ <div *ngIf="day.open" class="dayContent"> <div *ngFor="let hour of day.hours; let index = index" class="hour"> <app-input - [id]="day.name + 'from'" + [id]="day.name + 'From'" [type]="'time'" [label]="'De :'" [size]="'large'" -- GitLab From f25686ccf6f00b463f86c6884a0a3cb19138c1b1 Mon Sep 17 00:00:00 2001 From: Pierre Ecarlat <pecarlat@grandlyon.com> Date: Mon, 18 Dec 2023 09:07:07 +0000 Subject: [PATCH 10/16] Apply 1 suggestion(s) to 1 file(s) --- .../shared/components/hour-picker/hour-picker.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html index 6a0b3747f..b3d2ebd88 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.html +++ b/src/app/shared/components/hour-picker/hour-picker.component.html @@ -24,7 +24,7 @@ /> <app-input - [id]="day.name + 'to'" + [id]="day.name + 'To'" [type]="'time'" [label]="'Jusqu’à :'" [size]="'large'" -- GitLab From 79549ce4f8b9e85c35e038ecb8b0023372c4f6b5 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Mon, 18 Dec 2023 10:08:54 +0100 Subject: [PATCH 11/16] remove log --- src/app/shared/components/hour-picker/hour-picker.component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts index 33bd385e8..a302f8d70 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.ts +++ b/src/app/shared/components/hour-picker/hour-picker.component.ts @@ -203,8 +203,6 @@ export class HourPickerComponent implements OnChanges, OnDestroy { /** Supprimer la dernière ligne d'horaires d'un jour */ public removeHours(day: DayHour, index: number): void { - console.log('remove hours'); - console.log('🚀 ~ file: hour-picker.component.ts:225 ~ HourPickerComponent ~ removeHours ~ day:', day); if (index > -1) { day.hours.splice(index, 1); this.submitForm(); -- GitLab From 8024ac3e5dcc758c3fbf75949a55009872d28c95 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Mon, 18 Dec 2023 10:20:27 +0100 Subject: [PATCH 12/16] only capitalize header --- .../shared/components/hour-picker/hour-picker.component.scss | 4 ++++ src/app/shared/components/v3/switch/switch.component.scss | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.scss b/src/app/shared/components/hour-picker/hour-picker.component.scss index 2c0086399..a782a72ab 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.scss +++ b/src/app/shared/components/hour-picker/hour-picker.component.scss @@ -18,6 +18,10 @@ .dayHeader { padding-inline: 8px; + + ::ng-deep app-switch span { + text-transform: capitalize; + } } .dayContent { diff --git a/src/app/shared/components/v3/switch/switch.component.scss b/src/app/shared/components/v3/switch/switch.component.scss index d2791762b..1ab25c23c 100644 --- a/src/app/shared/components/v3/switch/switch.component.scss +++ b/src/app/shared/components/v3/switch/switch.component.scss @@ -28,8 +28,4 @@ @include font-regular-12; } } - - span { - text-transform: capitalize; - } } -- GitLab From dcef00e1e5abd941485c8e0e16563ced11362d99 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Mon, 18 Dec 2023 10:31:33 +0100 Subject: [PATCH 13/16] update constructors --- src/app/models/week.model.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/models/week.model.ts b/src/app/models/week.model.ts index 4e7a1321d..cfc2edb18 100644 --- a/src/app/models/week.model.ts +++ b/src/app/models/week.model.ts @@ -14,7 +14,7 @@ export class Time { opening: string; closing: string; - constructor(obj?: any) { + constructor(obj?: { opening: string; closing: string }) { Object.assign(this, obj); } @@ -33,6 +33,10 @@ export class Time { export class Day { open = false; + /** + * A day can have two opening times + * @example 10:00 - 12:00 & 16:00 - 18:00 + */ time: Time[]; constructor(obj?: Day) { @@ -51,7 +55,7 @@ export class Week { saturday: Day; sunday: Day; - constructor(obj?: any) { + constructor(obj?: Week) { Object.assign(this, obj, { monday: obj?.monday ? new Day(obj.monday) : new Day(), tuesday: obj?.tuesday ? new Day(obj.tuesday) : new Day(), -- GitLab From f35fc435646dac9b4aa27886b77b154bde6872ea Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Mon, 18 Dec 2023 10:34:35 +0100 Subject: [PATCH 14/16] remove getDayTranslation --- src/app/models/week.model.ts | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/app/models/week.model.ts b/src/app/models/week.model.ts index cfc2edb18..320c4522c 100644 --- a/src/app/models/week.model.ts +++ b/src/app/models/week.model.ts @@ -85,27 +85,6 @@ export class Week { yield { key: 'sunday', value: this.sunday }; } - public getDayTranslation(day: dayType): string { - switch (day) { - case 'monday': - return 'lundi'; - case 'tuesday': - return 'mardi'; - case 'thursday': - return 'jeudi'; - case 'wednesday': - return 'mercredi'; - case 'friday': - return 'vendredi'; - case 'saturday': - return 'samedi'; - case 'sunday': - return 'dimanche'; - default: - return null; - } - } - public hasData(): boolean { if ( this.monday.time.length === 0 && -- GitLab From 5a8c32ff0b403670781bc96e6b2a971fae92fc22 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Mon, 18 Dec 2023 10:57:51 +0100 Subject: [PATCH 15/16] add finish event --- .../components/hour-picker/hour-picker.component.html | 4 ++-- src/app/shared/components/v3/input/input.component.html | 2 ++ src/app/shared/components/v3/input/input.component.ts | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html index b3d2ebd88..2e4785db7 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.html +++ b/src/app/shared/components/hour-picker/hour-picker.component.html @@ -20,7 +20,7 @@ [status]="getStatus(hour)" [statusText]="getStatusText(hour)" [(value)]="hour.start" - (appClickOutside)="submitForm()" + (finishedEditing)="submitForm()" /> <app-input @@ -31,7 +31,7 @@ [status]="getStatus(hour)" [statusText]="getStatusText(hour)" [(value)]="hour.end" - (appClickOutside)="submitForm()" + (finishedEditing)="submitForm()" /> <app-v3-button diff --git a/src/app/shared/components/v3/input/input.component.html b/src/app/shared/components/v3/input/input.component.html index d86d94450..03e1f6877 100644 --- a/src/app/shared/components/v3/input/input.component.html +++ b/src/app/shared/components/v3/input/input.component.html @@ -9,6 +9,8 @@ [ngClass]="classes" [(ngModel)]="value" (change)="onChange($event)" + (blur)="onFinishedEditing()" + (keyup.enter)="onFinishedEditing()" /> <div *ngIf="status && getStatusText()" class="status" [ngClass]="status"> <img *ngIf="status === 'error'" src="assets/ico/error-rounded.svg" alt="" /> diff --git a/src/app/shared/components/v3/input/input.component.ts b/src/app/shared/components/v3/input/input.component.ts index 773b339cd..6d353998a 100644 --- a/src/app/shared/components/v3/input/input.component.ts +++ b/src/app/shared/components/v3/input/input.component.ts @@ -32,6 +32,8 @@ export class InputV3Component { /** Triggers when input changes */ @Output() valueChange = new EventEmitter<string>(); + @Output() finishedEditing = new EventEmitter<string>(); + public get classes(): string { return [this.size, this.status].join(' '); } @@ -41,6 +43,10 @@ export class InputV3Component { this.valueChange.emit(this.value); } + public onFinishedEditing(): void { + this.finishedEditing.emit(this.value); + } + getStatusText(): string { if (this.statusText) return this.statusText; -- GitLab From c907662512e8d3c6b0c28c065db1ee4e8047aff8 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Mon, 18 Dec 2023 15:25:22 +0100 Subject: [PATCH 16/16] remove unused methods --- .../components/hour-picker/hour-picker.component.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts index a302f8d70..72c41d9d1 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.ts +++ b/src/app/shared/components/hour-picker/hour-picker.component.ts @@ -26,7 +26,6 @@ export class HourPickerComponent implements OnChanges, OnDestroy { @Output() updateForm = new EventEmitter<UntypedFormGroup>(); public buttonTypeEnumV3 = ButtonTypeV3; - private isInputSelected = false; public structure = { hours: this.initHoursDefault(), }; @@ -237,17 +236,8 @@ export class HourPickerComponent implements OnChanges, OnDestroy { return !error; } - public onFocus(): void { - this.isInputSelected = true; - } - - public onBlur(): void { - this.isInputSelected = false; - this.submitForm(); - } - public submitForm(): void { - if (this.checkHoursValid() && this.isInputSelected === false) { + if (this.checkHoursValid()) { this.updateForm.emit(this.parseHoursToForm()); } else { this.updateFormError.emit(); -- GitLab