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/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;
+}