From 7e12d9d34f33116cfdcdf501471d3dc98607cd15 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 20 May 2021 10:54:28 +0200 Subject: [PATCH] style for adding time --- src/app/core/models/dateChoice.model.ts | 9 +++ .../date/list/day/day-list.component.html | 15 +++-- .../date/list/day/day-list.component.scss | 4 ++ .../form/date/list/day/day-list.component.ts | 16 ++--- .../date/list/time/time-list.component.html | 11 +++- .../date/list/time/time-list.component.ts | 59 ++++++++++++++++++- src/styles/partials/_forms.scss | 9 +-- src/styles/partials/_typo.scss | 7 +++ 8 files changed, 107 insertions(+), 23 deletions(-) create mode 100644 src/app/core/models/dateChoice.model.ts diff --git a/src/app/core/models/dateChoice.model.ts b/src/app/core/models/dateChoice.model.ts new file mode 100644 index 00000000..32ba99f9 --- /dev/null +++ b/src/app/core/models/dateChoice.model.ts @@ -0,0 +1,9 @@ +export interface DateChoice { + literal: string; + timeSlices: TimeSlices[]; + date_object: Date; +} + +export interface TimeSlices { + literal: string; +} diff --git a/src/app/features/administration/form/date/list/day/day-list.component.html b/src/app/features/administration/form/date/list/day/day-list.component.html index e6c08f48..ab153626 100644 --- a/src/app/features/administration/form/date/list/day/day-list.component.html +++ b/src/app/features/administration/form/date/list/day/day-list.component.html @@ -45,6 +45,7 @@ - +
+

- + +
+ +
diff --git a/src/app/features/administration/form/date/list/day/day-list.component.scss b/src/app/features/administration/form/date/list/day/day-list.component.scss index bf6ae1de..9c5f784d 100644 --- a/src/app/features/administration/form/date/list/day/day-list.component.scss +++ b/src/app/features/administration/form/date/list/day/day-list.component.scss @@ -6,8 +6,12 @@ } .icon { margin-right: 1ch; + margin-left: 1ch; display: inline-block; } .several-times { padding-left: 2em; } +.date-choice-item { + width: 75%; +} 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 ae45af5c..249e6a03 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 @@ -1,12 +1,12 @@ import { ChangeDetectorRef, Component, Inject, Input } from '@angular/core'; import { moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop'; -import { DateChoice } from '../../../../../../../../mocks/old-stuff/config/defaultConfigs'; import { DOCUMENT } from '@angular/common'; import { FormGroup } from '@angular/forms'; import { ToastService } from '../../../../../../core/services/toast.service'; import { StorageService } from '../../../../../../core/services/storage.service'; import { MatDialog } from '@angular/material/dialog'; import { ShortcutsHelpComponent } from '../../../../../shared/components/ui/shortcuts-help/shortcuts-help.component'; +import { DateChoice } from '../../../../../../core/models/dateChoice.model'; @Component({ selector: 'app-day-list', @@ -64,19 +64,21 @@ export class DayListComponent { * @param choice DateChoice * @param id number */ - addTimeToDate(choice: DateChoice, id: number) { + addTimeToDate(choice: DateChoice, id: number): void { if (!choice.timeSlices) { choice.timeSlices = []; } choice.timeSlices.push({ literal: '', }); - const selector = - '[ng-reflect-choice_label="dateTime_' + id + '_ dateList_' + (choice.timeSlices.length - 1) + '"]'; + // focus on created field this.cd.detectChanges(); - const elem = this.document.querySelector(selector); - if (elem) { - elem.focus(); + const selector = '#choice_' + id + '_timeChoices_' + (choice.timeSlices.length - 1); + const firstField = this.document.querySelector(selector); + if (firstField) { + firstField.focus(); + } else { + console.log('no last time choice found'); } } diff --git a/src/app/features/administration/form/date/list/time/time-list.component.html b/src/app/features/administration/form/date/list/time/time-list.component.html index 80d93964..903a516e 100644 --- a/src/app/features/administration/form/date/list/time/time-list.component.html +++ b/src/app/features/administration/form/date/list/time/time-list.component.html @@ -1,16 +1,21 @@
-
diff --git a/src/app/features/administration/form/date/list/time/time-list.component.ts b/src/app/features/administration/form/date/list/time/time-list.component.ts index 0a3a26cb..8f097114 100644 --- a/src/app/features/administration/form/date/list/time/time-list.component.ts +++ b/src/app/features/administration/form/date/list/time/time-list.component.ts @@ -1,6 +1,8 @@ -import { Component, Input, OnInit } from '@angular/core'; -import { TimeSlices } from '../../../../../../../../mocks/old-stuff/config/defaultConfigs'; +import { ChangeDetectorRef, Component, Inject, Input, OnInit } from '@angular/core'; + import { moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop'; +import { DOCUMENT } from '@angular/common'; +import { TimeSlices } from '../../../../../../core/models/dateChoice.model'; @Component({ selector: 'app-time-list', @@ -10,7 +12,10 @@ import { moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop'; export class TimeListComponent implements OnInit { @Input() public timeSlices: TimeSlices[]; - constructor() {} + @Input() + public prefix_choice_id = ''; + + constructor(@Inject(DOCUMENT) private document: any, private cd: ChangeDetectorRef) {} ngOnInit(): void {} @@ -27,4 +32,52 @@ export class TimeListComponent implements OnInit { ); } } + + removeTime(id: number) { + this.timeSlices.splice(id, 1); + this.focusOnLastField(); + } + + focusOnFieldNumber(fieldId: number) { + console.log('focus on fieldId', fieldId); + const selector = '#choice_' + this.prefix_choice_id + '_timeChoices_' + fieldId; + const firstField = this.document.querySelector(selector); + if (firstField) { + console.log('found', firstField); + firstField.focus(); + } + return firstField; + } + + focusOnNextField(currentId: number) { + const fieldFound = this.focusOnFieldNumber(currentId + 1); + if (!fieldFound) { + console.log('pas trouvé de field avec id', currentId + 1); + this.createNewField(); + } + } + + focusOnLastField() { + this.cd.detectChanges(); + if (!this.focusOnFieldNumber(this.timeSlices.length - 1)) { + console.log('no last time choice found'); + this.createNewField(); + this.focusOnLastField(); + } + } + + removeTimeIfEmpty(timeLiteral, id) { + if (timeLiteral === '') { + this.removeTime(id); + this.focusOnFieldNumber(0); + } + } + + createNewField() { + // create new field + this.timeSlices.push({ + literal: '', + }); + this.cd.detectChanges(); + } } diff --git a/src/styles/partials/_forms.scss b/src/styles/partials/_forms.scss index a70abccc..1e7f2a8c 100644 --- a/src/styles/partials/_forms.scss +++ b/src/styles/partials/_forms.scss @@ -133,9 +133,9 @@ mat-checkbox { .cdk-drag { cursor: pointer; - border-left: 3px white solid; + //border-left: 3px white solid; &:hover { - border-left: 3px #ccc solid; + background: #fefefe; } } .admin-form { @@ -191,7 +191,7 @@ mat-checkbox { padding: 1em; height: 4em; width: 100%; - background: white; + background: $primary; } .cdk-drag-animating { @@ -219,9 +219,6 @@ mat-checkbox { border-left: $success 3px solid; padding-left: 1em; } -.btn { - margin: 0.5em; -} .bar-nav-admin { //position:fixed; diff --git a/src/styles/partials/_typo.scss b/src/styles/partials/_typo.scss index 5d72988b..3763314b 100644 --- a/src/styles/partials/_typo.scss +++ b/src/styles/partials/_typo.scss @@ -31,3 +31,10 @@ h4 { .nobold { font-weight: normal; } + +.text-right { + text-align: right; +} +.text-center { + text-align: center; +}