From 422090e997e0c883fa4a618195c4d5de1618b1e8 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 18 May 2021 11:46:35 +0200 Subject: [PATCH] next lang select on click on icon --- .../form/date/list/day/day-list.component.ts | 1 - .../administration/form/form.component.ts | 7 +----- .../form/errors-list/errors-list.component.ts | 12 ++-------- .../language-selector.component.html | 3 ++- .../language-selector.component.ts | 22 +++++++++++++++++-- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/app/features/administration/form/date/list/day/day-list.component.ts b/src/app/features/administration/form/date/list/day/day-list.component.ts index 701c9266..0d19be8b 100644 --- a/src/app/features/administration/form/date/list/day/day-list.component.ts +++ b/src/app/features/administration/form/date/list/day/day-list.component.ts @@ -124,7 +124,6 @@ export class DayListComponent { }); // this.cd.detectChanges(); - console.log('this.choices.length', this.storageService.dateList.length); this.focusOnChoice(this.storageService.dateList.length - 1); } diff --git a/src/app/features/administration/form/form.component.ts b/src/app/features/administration/form/form.component.ts index 4c4a61a0..9df2827a 100644 --- a/src/app/features/administration/form/form.component.ts +++ b/src/app/features/administration/form/form.component.ts @@ -81,7 +81,6 @@ export class FormComponent implements OnInit { startDateInterval: ['', [Validators.required]], endDateInterval: ['', [Validators.required]], }); - console.log('this.form ', this.form); // take back values from pollservice this.form.patchValue(this.pollService.poll); @@ -140,8 +139,6 @@ export class FormComponent implements OnInit { const dateStart = this.dateUtils.formateDateToInputStringNg(new Date()); const dateEnd = this.dateUtils.formateDateToInputStringNg(this.dateUtils.addDaysToDate(5, new Date())); - console.log('dateStart', dateStart); - this.form.patchValue({ title: title, custom_url: this.pollUtilitiesService.makeSlugFromString(title), @@ -156,7 +153,6 @@ export class FormComponent implements OnInit { } goNextStep() { - console.log('this.steps', this.steps); let indexCurrentStep = this.steps.indexOf(this.currentStep); indexCurrentStep += 1; this.currentStep = this.steps[indexCurrentStep]; @@ -164,7 +160,6 @@ export class FormComponent implements OnInit { } public createPoll(): void { - console.log('this.form', this.form); const newpoll = this.pollService.newPollFromForm(this.form); console.log('newpoll', newpoll); const router = this.router; @@ -180,7 +175,7 @@ export class FormComponent implements OnInit { router.navigate(['success']); }, (err) => { - this.toastService.display('erreur lors de la sauvegarde'); + this.toastService.display('erreur lors de la sauvegarde ' + err.message); } ); } else { diff --git a/src/app/features/shared/components/ui/form/errors-list/errors-list.component.ts b/src/app/features/shared/components/ui/form/errors-list/errors-list.component.ts index 42b24390..c8936a8c 100644 --- a/src/app/features/shared/components/ui/form/errors-list/errors-list.component.ts +++ b/src/app/features/shared/components/ui/form/errors-list/errors-list.component.ts @@ -23,7 +23,7 @@ export class ErrorsListComponent implements OnInit { } getFormValidationErrors(): void { - console.log('%c ==>> Validation Errors: ', 'color: red; font-weight: bold; font-size:22px;'); + // console.log('%c ==>> Validation Errors: ', 'color: red; font-weight: bold; font-size:22px;'); let totalErrors = 0; this.messages = []; @@ -37,22 +37,16 @@ export class ErrorsListComponent implements OnInit { if (!firstErrorId) { firstErrorId = key; } - // totalErrors++; - // this.messages.push('' + key + ' est invalide'); } const controlErrors: ValidationErrors = theKey.errors; if (controlErrors != null) { - console.log('controlErrors', controlErrors); totalErrors++; Object.keys(controlErrors).forEach((keyError) => { if (!firstErrorId) { firstErrorId = key; } const message = '' + key + ', ' + keyError + ''; - console.log( - 'Key control: ' + key + ', keyError: ' + keyError + ', err value: ' + controlErrors[keyError] - ); this.messages.push(message); }); @@ -62,11 +56,10 @@ export class ErrorsListComponent implements OnInit { this.firstErrorId = firstErrorId; if (totalErrors) { - console.log('Number of errors: ', totalErrors); } } - scrollToFirstError() { + scrollToFirstError(): void { if (this.firstErrorId) { const foundErrorField = this.document.querySelector('#' + this.firstErrorId); if (foundErrorField) { @@ -77,7 +70,6 @@ export class ErrorsListComponent implements OnInit { behavior: 'smooth', }); } - console.log('foundErrorField', foundErrorField); } } } diff --git a/src/app/shared/components/selectors/language-selector/language-selector.component.html b/src/app/shared/components/selectors/language-selector/language-selector.component.html index 99337c7d..66a46b50 100644 --- a/src/app/shared/components/selectors/language-selector/language-selector.component.html +++ b/src/app/shared/components/selectors/language-selector/language-selector.component.html @@ -4,7 +4,8 @@ diff --git a/src/app/shared/components/selectors/language-selector/language-selector.component.ts b/src/app/shared/components/selectors/language-selector/language-selector.component.ts index fcddb40b..9260dd35 100644 --- a/src/app/shared/components/selectors/language-selector/language-selector.component.ts +++ b/src/app/shared/components/selectors/language-selector/language-selector.component.ts @@ -11,7 +11,7 @@ import { StorageService } from '../../../../core/services/storage.service'; }) export class LanguageSelectorComponent implements OnInit { public currentLang: Language; - public availableLanguages: string[] = []; + public availableLanguages: any = []; constructor(private languageService: LanguageService, private storageService: StorageService) {} @@ -19,7 +19,6 @@ export class LanguageSelectorComponent implements OnInit { this.availableLanguages = this.languageService.getAvailableLanguages(); this.currentLang = this.languageService.getLangage(); - this.nextLang(); } setLang(): void { @@ -27,7 +26,26 @@ export class LanguageSelectorComponent implements OnInit { } nextLang(): void { + const index = this.availableLanguages.indexOf(this.currentLang); + console.log('this.currentLang ', this.currentLang, 'index', index); + + if (index !== -1) { + // on passe au language suivant si il existe, sinon on revient au numéro 0 + const nextlang = console.log('this.availableLanguages[index + 1]', this.availableLanguages[index + 1]); + console.log('nextlang', nextlang); + + if (this.availableLanguages[index + 1]) { + console.log('lang suivante', this.availableLanguages[index + 1]); + this.currentLang = this.availableLanguages[index + 1]; + } else { + console.log('retour à la langue 0'); + this.currentLang = this.availableLanguages[0]; + } + this.setLang(); + } console.log('this.currentLang ', this.currentLang); + + console.log('this.availableLanguages', this.availableLanguages); console.log('TODO'); } }