From 6d3e79aac57b42e37e5a8ead506f320d2ffffc94 Mon Sep 17 00:00:00 2001 From: Julien Gautier Date: Tue, 3 Oct 2023 13:47:48 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20composant=20partag?= =?UTF-8?q?=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aeronefs-bar/aeronefs-bar.component.html | 0 .../aeronefs-bar/aeronefs-bar.component.scss | 0 .../aeronefs-bar.component.spec.ts | 0 .../aeronefs-bar/aeronefs-bar.component.ts | 0 .../aeronefs/aeronefs.component.html | 0 .../aeronefs/aeronefs.component.scss | 0 .../aeronefs/aeronefs.component.spec.ts | 0 .../aeronefs/aeronefs.component.ts | 0 .../canopy-models.component.html | 0 .../canopy-models.component.scss | 0 .../canopy-models.component.spec.ts | 0 .../canopy-models/canopy-models.component.ts | 0 .../canopy-sizes/canopy-sizes.component.html | 0 .../canopy-sizes/canopy-sizes.component.scss | 0 .../canopy-sizes.component.spec.ts | 0 .../canopy-sizes/canopy-sizes.component.ts | 0 .../drop-zones-bar/data.json | 0 .../drop-zones-bar.component.html | 0 .../drop-zones-bar.component.scss | 0 .../drop-zones-bar.component.spec.ts | 0 .../drop-zones-bar.component.ts | 0 .../dashboard-components/drop-zones/data.json | 0 .../drop-zones/drop-zones.component.html | 0 .../drop-zones/drop-zones.component.scss | 0 .../drop-zones/drop-zones.component.spec.ts | 0 .../drop-zones/drop-zones.component.ts | 0 .../dashboard-components/index.ts | 0 .../jumps-by-month/data.json | 0 .../jumps-by-month.component.html | 24 +- .../jumps-by-month.component.scss | 0 .../jumps-by-month.component.spec.ts | 0 .../jumps-by-month.component.ts | 9 +- .../shared/dialogs/jump-add.dialog.html | 426 +++++++++++++--- .../shared/dialogs/jump-add.dialog.ts | 478 +++++++++++++++++- .../shared/dialogs/jump-delete.dialog.html | 100 ++-- .../shared/dialogs/jump-delete.dialog.ts | 10 +- .../shared/dialogs/jump-edit.dialog.html | 218 +++++--- .../shared/dialogs/jump-edit.dialog.ts | 83 ++- .../helpers-jump/jump-table.component.html | 59 ++- .../helpers-jump/jump-table.component.ts | 265 ++++++---- 40 files changed, 1327 insertions(+), 345 deletions(-) rename src/app/components/{home => shared}/dashboard-components/aeronefs-bar/aeronefs-bar.component.html (100%) rename src/app/components/{home => shared}/dashboard-components/aeronefs-bar/aeronefs-bar.component.scss (100%) rename src/app/components/{home => shared}/dashboard-components/aeronefs-bar/aeronefs-bar.component.spec.ts (100%) rename src/app/components/{home => shared}/dashboard-components/aeronefs-bar/aeronefs-bar.component.ts (100%) rename src/app/components/{home => shared}/dashboard-components/aeronefs/aeronefs.component.html (100%) rename src/app/components/{home => shared}/dashboard-components/aeronefs/aeronefs.component.scss (100%) rename src/app/components/{home => shared}/dashboard-components/aeronefs/aeronefs.component.spec.ts (100%) rename src/app/components/{home => shared}/dashboard-components/aeronefs/aeronefs.component.ts (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-models/canopy-models.component.html (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-models/canopy-models.component.scss (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-models/canopy-models.component.spec.ts (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-models/canopy-models.component.ts (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-sizes/canopy-sizes.component.html (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-sizes/canopy-sizes.component.scss (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-sizes/canopy-sizes.component.spec.ts (100%) rename src/app/components/{home => shared}/dashboard-components/canopy-sizes/canopy-sizes.component.ts (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones-bar/data.json (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones-bar/drop-zones-bar.component.html (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones-bar/drop-zones-bar.component.scss (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones-bar/drop-zones-bar.component.spec.ts (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones-bar/drop-zones-bar.component.ts (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones/data.json (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones/drop-zones.component.html (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones/drop-zones.component.scss (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones/drop-zones.component.spec.ts (100%) rename src/app/components/{home => shared}/dashboard-components/drop-zones/drop-zones.component.ts (100%) rename src/app/components/{home => shared}/dashboard-components/index.ts (100%) rename src/app/components/{home => shared}/dashboard-components/jumps-by-month/data.json (100%) rename src/app/components/{home => shared}/dashboard-components/jumps-by-month/jumps-by-month.component.html (73%) rename src/app/components/{home => shared}/dashboard-components/jumps-by-month/jumps-by-month.component.scss (100%) rename src/app/components/{home => shared}/dashboard-components/jumps-by-month/jumps-by-month.component.spec.ts (100%) rename src/app/components/{home => shared}/dashboard-components/jumps-by-month/jumps-by-month.component.ts (90%) diff --git a/src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.html b/src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.html similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.html rename to src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.html diff --git a/src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.scss b/src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.scss similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.scss rename to src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.scss diff --git a/src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.spec.ts b/src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.spec.ts similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.spec.ts rename to src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.spec.ts diff --git a/src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.ts b/src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.ts similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs-bar/aeronefs-bar.component.ts rename to src/app/components/shared/dashboard-components/aeronefs-bar/aeronefs-bar.component.ts diff --git a/src/app/components/home/dashboard-components/aeronefs/aeronefs.component.html b/src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.html similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs/aeronefs.component.html rename to src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.html diff --git a/src/app/components/home/dashboard-components/aeronefs/aeronefs.component.scss b/src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.scss similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs/aeronefs.component.scss rename to src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.scss diff --git a/src/app/components/home/dashboard-components/aeronefs/aeronefs.component.spec.ts b/src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.spec.ts similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs/aeronefs.component.spec.ts rename to src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.spec.ts diff --git a/src/app/components/home/dashboard-components/aeronefs/aeronefs.component.ts b/src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.ts similarity index 100% rename from src/app/components/home/dashboard-components/aeronefs/aeronefs.component.ts rename to src/app/components/shared/dashboard-components/aeronefs/aeronefs.component.ts diff --git a/src/app/components/home/dashboard-components/canopy-models/canopy-models.component.html b/src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.html similarity index 100% rename from src/app/components/home/dashboard-components/canopy-models/canopy-models.component.html rename to src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.html diff --git a/src/app/components/home/dashboard-components/canopy-models/canopy-models.component.scss b/src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.scss similarity index 100% rename from src/app/components/home/dashboard-components/canopy-models/canopy-models.component.scss rename to src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.scss diff --git a/src/app/components/home/dashboard-components/canopy-models/canopy-models.component.spec.ts b/src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.spec.ts similarity index 100% rename from src/app/components/home/dashboard-components/canopy-models/canopy-models.component.spec.ts rename to src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.spec.ts diff --git a/src/app/components/home/dashboard-components/canopy-models/canopy-models.component.ts b/src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.ts similarity index 100% rename from src/app/components/home/dashboard-components/canopy-models/canopy-models.component.ts rename to src/app/components/shared/dashboard-components/canopy-models/canopy-models.component.ts diff --git a/src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.html b/src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.html similarity index 100% rename from src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.html rename to src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.html diff --git a/src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.scss b/src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.scss similarity index 100% rename from src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.scss rename to src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.scss diff --git a/src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.spec.ts b/src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.spec.ts similarity index 100% rename from src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.spec.ts rename to src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.spec.ts diff --git a/src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.ts b/src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.ts similarity index 100% rename from src/app/components/home/dashboard-components/canopy-sizes/canopy-sizes.component.ts rename to src/app/components/shared/dashboard-components/canopy-sizes/canopy-sizes.component.ts diff --git a/src/app/components/home/dashboard-components/drop-zones-bar/data.json b/src/app/components/shared/dashboard-components/drop-zones-bar/data.json similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones-bar/data.json rename to src/app/components/shared/dashboard-components/drop-zones-bar/data.json diff --git a/src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.html b/src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.html similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.html rename to src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.html diff --git a/src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.scss b/src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.scss similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.scss rename to src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.scss diff --git a/src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.spec.ts b/src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.spec.ts similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.spec.ts rename to src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.spec.ts diff --git a/src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.ts b/src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.ts similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones-bar/drop-zones-bar.component.ts rename to src/app/components/shared/dashboard-components/drop-zones-bar/drop-zones-bar.component.ts diff --git a/src/app/components/home/dashboard-components/drop-zones/data.json b/src/app/components/shared/dashboard-components/drop-zones/data.json similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones/data.json rename to src/app/components/shared/dashboard-components/drop-zones/data.json diff --git a/src/app/components/home/dashboard-components/drop-zones/drop-zones.component.html b/src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.html similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones/drop-zones.component.html rename to src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.html diff --git a/src/app/components/home/dashboard-components/drop-zones/drop-zones.component.scss b/src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.scss similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones/drop-zones.component.scss rename to src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.scss diff --git a/src/app/components/home/dashboard-components/drop-zones/drop-zones.component.spec.ts b/src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.spec.ts similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones/drop-zones.component.spec.ts rename to src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.spec.ts diff --git a/src/app/components/home/dashboard-components/drop-zones/drop-zones.component.ts b/src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.ts similarity index 100% rename from src/app/components/home/dashboard-components/drop-zones/drop-zones.component.ts rename to src/app/components/shared/dashboard-components/drop-zones/drop-zones.component.ts diff --git a/src/app/components/home/dashboard-components/index.ts b/src/app/components/shared/dashboard-components/index.ts similarity index 100% rename from src/app/components/home/dashboard-components/index.ts rename to src/app/components/shared/dashboard-components/index.ts diff --git a/src/app/components/home/dashboard-components/jumps-by-month/data.json b/src/app/components/shared/dashboard-components/jumps-by-month/data.json similarity index 100% rename from src/app/components/home/dashboard-components/jumps-by-month/data.json rename to src/app/components/shared/dashboard-components/jumps-by-month/data.json diff --git a/src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.html b/src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.html similarity index 73% rename from src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.html rename to src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.html index 0db981c..5c47422 100755 --- a/src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.html +++ b/src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.html @@ -40,28 +40,36 @@ - {{name}} + {{ name }} Total - ● {{seriesName[i]}} + ● {{ seriesName[i] }} - {{value}} - {{value}} + {{ value }} + {{ value }} - {{seriesRowTotal[i]}} + {{ seriesRowTotal[i] }} Total - {{value}} - {{value}} + {{ value }} + {{ value }} - {{grandTotal}} + {{ grandTotal }} + + + Moyenne + + {{ value }} + {{ value }} + + {{ grandAvg }} diff --git a/src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.scss b/src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.scss similarity index 100% rename from src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.scss rename to src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.scss diff --git a/src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.spec.ts b/src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.spec.ts similarity index 100% rename from src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.spec.ts rename to src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.spec.ts diff --git a/src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.ts b/src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.ts similarity index 90% rename from src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.ts rename to src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.ts index 01f80e9..070647b 100755 --- a/src/app/components/home/dashboard-components/jumps-by-month/jumps-by-month.component.ts +++ b/src/app/components/shared/dashboard-components/jumps-by-month/jumps-by-month.component.ts @@ -31,12 +31,14 @@ export class JumpsByMonthComponent implements OnInit, OnDestroy { public subtitle: string = 'Nombre total de sauts par mois'; public min = 0; public max = 0; + public grandAvg = 0; public grandTotal = 0; public seriesHeader: string[] = []; public seriesName: String[] = []; public seriesRow: any[] = []; public seriesColor: String[] = this._utilitiesService.getChartColors(); public seriesRowTotal: number[] = []; + public seriesRowAvg: number[] = []; public seriesColTotal: number[] = []; public displayCharts = false; public barChartJumps: Configuration = this._utilitiesService.getBarConfig(); @@ -83,7 +85,12 @@ export class JumpsByMonthComponent implements OnInit, OnDestroy { const total = row.reduce((partialSum, a) => partialSum + a, 0); this.seriesRowTotal.push(total); }); - this.grandTotal = this.seriesColTotal.reduce((partialSum, a) => partialSum + a, 0); + this.seriesRowTotal.forEach((row: number) => { + let value: number = (row/this.seriesName.length); + this.seriesRowAvg.push(value); + }); + this.grandAvg = this.seriesRowAvg.reduce((partialSum, accumulated) => partialSum + accumulated, 0); + this.grandTotal = this.seriesColTotal.reduce((partialSum, accumulated) => partialSum + accumulated, 0); this.barChartJumps = { type: 'Bar', data: { diff --git a/src/app/components/shared/dialogs/jump-add.dialog.html b/src/app/components/shared/dialogs/jump-add.dialog.html index 1057b87..febade4 100644 --- a/src/app/components/shared/dialogs/jump-add.dialog.html +++ b/src/app/components/shared/dialogs/jump-add.dialog.html @@ -1,91 +1,349 @@ -

Ajouter un saut

- +

+ Ajouter un saut + +

-
- -
- - Numéro - - - - Date - - - - Lieu - - - - Aeronef - - - - Hauteur - - - - Voile - - - - Taille - - - - Categorie - - - - Module - - +
+ -
- - Participants - - - - Programme - - - - Oaci - - - - Imat - - - - Accessoires - - - - Zone - - - - Dossier - - - - Video - - -
- -
-
- -
+ --> +
+
+ + Numéro ou plage de saut à ajouter + + 645 / +5 / 650-660 + + + Choisissez une date + + MM/DD/YYYY + + + + + + + + + + Utiliser les valeurs du dernier saut + +
+
+

+ Dropzone + + + +

+ + Lieu + + {{getErrorMessage('lieu')}} + + + Oaci + + {{getErrorMessage('oaci')}} + +

+ Aéronef + + + +

+ + Aéronef + + {{getErrorMessage('aeronef')}} + + + Imatriculation + + {{getErrorMessage('imat')}} + +

+ Voile + + + +

+ + Modèle + + {{getErrorMessage('voile')}} + + + Taille en ft2 + + ft2 + {{getErrorMessage('taille')}} + +
+
+

+ Altitude + + + +

+ + Hauteur de largage + + {{getErrorMessage('hauteur')}} + + + Hauteur de déploiement + + {{getErrorMessage('deploiement')}} + +

+ Discipline + + + +

+ + Categorie + + {{getErrorMessage('categorie')}} + + + Module + + {{getErrorMessage('module')}} + +

+ Divers + + + +

+ + Accessoires + + {{getErrorMessage('accessoires')}} + + + Zone + + {{getErrorMessage('zone')}} + +
+
+

+ Groupe + + + +

+ + Sautants + + + + Nombre de participants + + {{getErrorMessage('participants')}} + +
+ + + {{ sautant }} + + + + ju_solide + +
+
+
+

+ Programme + + + +

+ + Programme + + {{getErrorMessage('programme')}} + +

Vidéo

+ + Dossier + + {{getErrorMessage('dossier')}} + + + Video + + {{getErrorMessage('video')}} + + {{ filepath }}{{ filename }} +
+
+
+
+

+ Dropzone + + + +

+ + Lieu + + + + Oaci + + +

+ Aéronef + + + +

+ + Aéronef + + + + Imatriculation + + +

+ Voile + + + +

+ + Modèle + + + + Taille + + +
+
+

+ Altitude + + + +

+ + Hauteur + + + + Hauteur de déploiement + + +

+ Discipline + + + +

+ + Categorie + + FF / Solo / VR / Wingsuit + + + Module + + Chutas / Track / Trace + +

+ Divers + + + +

+ + Accessoires + + + + Zone + + +
+
+

+ Groupe + + + +

+ + Sautants + + + + Nombre de participants + + +
+ + + {{ sautant }} + + + + ju_solide + +
+
+
+

+ Programme + + + +

+ + Programme + + + {{ filepath }}{{ this.jumpForm.controls['date'].value | date: 'yyyy-MM-dd' }}_S00{{ nextJump }}.mp4 + {{ jump.dossier }}{{ jump.video }} +
- - - + + + + \ No newline at end of file diff --git a/src/app/components/shared/dialogs/jump-add.dialog.ts b/src/app/components/shared/dialogs/jump-add.dialog.ts index 39500ea..cf5ab10 100644 --- a/src/app/components/shared/dialogs/jump-add.dialog.ts +++ b/src/app/components/shared/dialogs/jump-add.dialog.ts @@ -1,32 +1,486 @@ -import { Component, Inject } from '@angular/core'; -import { FormsModule } from '@angular/forms'; +import { Component, Inject, OnDestroy } from '@angular/core'; +import { DatePipe, NgFor, NgIf } from '@angular/common'; +import { FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; import { MatButtonModule } from '@angular/material/button'; -import { MatOptionModule } from '@angular/material/core'; +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { MatDatepickerModule } from '@angular/material/datepicker'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog'; -import { MatDividerModule } from '@angular/material/divider'; +import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatOptionModule } from '@angular/material/core'; import { MatSelectModule } from '@angular/material/select'; +import { Subscription } from 'rxjs'; -import { Jump } from 'src/app/core/models'; +import { Jump, JumpAddParams } from 'src/app/core/models'; @Component({ selector: 'huapp-jump-add-dialog', templateUrl: 'jump-add.dialog.html', standalone: true, imports: [ - FormsModule, - MatDialogModule, MatFormFieldModule, MatInputModule, MatDividerModule, - MatSelectModule, MatOptionModule, MatButtonModule + DatePipe, NgFor, NgIf, FormsModule, ReactiveFormsModule, + MatButtonModule, MatCheckboxModule, MatDatepickerModule, + MatDialogModule, MatFormFieldModule, MatIconModule, + MatInputModule, MatSelectModule, MatOptionModule ] }) -export class JumpAddDialogComponent { +export class JumpAddDialogComponent implements OnDestroy { + private _formChanges: Array = []; + public tagField = new FormControl('', { nonNullable: true}); + public jumpForm: FormGroup; + public jump: Jump; + public lastJump: Jump; + public nextJump: number; + public params: JumpAddParams; + public filename: string; + public filepath: string; + public useLast: { + all: boolean; + aeronef: boolean; + altitude: boolean; + discipline: boolean; + divers: boolean; + dropzone: boolean; + groupe: boolean; + programme: boolean; + voile: boolean; + } = { + all: false, + aeronef: false, + altitude: false, + discipline: false, + divers: false, + dropzone: false, + groupe: false, + programme: false, + voile: false + }; + constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public jump: Jump - ) { } + private fb: FormBuilder, + @Inject(MAT_DIALOG_DATA) public data: {jump: Jump, lastJump: Jump} + ) { + this.jump = data.jump; + this.lastJump = data.lastJump; + this.nextJump = (this.lastJump.numero + 1); + this.params = { + numeros: this.nextJump.toString(), + date: '', + video: true + }; + this.jump.numero = this.nextJump; + let controlsConfig = { + date: ['', Validators.required], + numero: [this.nextJump, Validators.required], + lieu: ['', Validators.required], + oaci: '', + aeronef: ['', Validators.required], + imat: '', + hauteur: ['', Validators.required], + deploiement: '', + voile: '', + taille: ['', Validators.required], + categorie: '', + module: '', + participants: [1, Validators.required], + sautants: [[]], + programme: '', + accessoires: '', + zone: '', + dossier: '', + video: '' + }; + this.jumpForm = this.fb.group(controlsConfig); + this.filename = this._computeFilename(); + this.filepath = this._computeFilepath(); + this._formChanges.push( + this.jumpForm.controls['module'].valueChanges.subscribe(() => { + this.filepath = this._computeFilepath(); + }), + this.jumpForm.controls['numero'].valueChanges.subscribe(() => { + this.filename = this._computeFilename(); + }) + ); + } - onCloseDialog(): void { + ngOnDestroy() { + this._formChanges.forEach((sub: Subscription) => { + sub.unsubscribe(); + }); + } + + public onDateChange(): void { + this.filename = this._computeFilename(); + } + + private _computeFilename(numero?: string): string { + let file: string = ''; + let timestamp: number = Date.parse(this.jumpForm.controls['date'].value); + if (isNaN(timestamp) == false) { + let date: Date = new Date(timestamp); + file += `${(date.getFullYear() + '').padStart(2, '0')}-${((date.getMonth() + 1) + '').padStart(2, '0')}-${(date.getDate() + '').padStart(2, '0')}_`; + } + if (numero !== undefined) { + numero = (numero + '').padStart(5, '0'); + } else { + numero = (this.jumpForm.controls['numero'].value + '').padStart(5, '0'); + } + file += `S${numero}.mp4`; + this.jumpForm.controls['video'].setValue(file); + + return file; + } + + private _computeFilepath(): string { + let path: string = '/Volumes/Storage/Skydive/Videos/'; + if (this.jumpForm.controls['module'].value != '') { + path += `${this.jumpForm.controls['module'].value}/`; + } + this.jumpForm.controls['dossier'].setValue(path); + + return path; + } + + private _isLastForAllSections() { + return ( + this.useLast.aeronef + && this.useLast.altitude + && this.useLast.discipline + && this.useLast.divers + && this.useLast.dropzone + && this.useLast.groupe + && this.useLast.programme + && this.useLast.voile + ); + } + + private _setAllLast(checked: boolean) { + this.useLast.all = checked; + this.useLast.aeronef = checked; + this.useLast.altitude = checked; + this.useLast.discipline = checked; + this.useLast.divers = checked; + this.useLast.dropzone = checked; + this.useLast.groupe = checked; + this.useLast.programme = checked; + this.useLast.voile = checked; + } + + addSautant(): void { + this.useLast.groupe = false; + this.useLast.all = this._isLastForAllSections(); + const tag = this.tagField.value; + if (tag != null && tag.trim() !== '' && this.jump.sautants.indexOf(tag) < 0) { + this.jump.sautants.push(tag); + } + this.tagField.reset(''); + const participants = (this.jump.sautants.length + 1); + this.jumpForm.controls['participants'].setValue(participants); + } + + closeDialog(): void { + this._setAllLast(false); + //this.jump = {}; + //this.jump.numero = this.nextJump; this.dialogRef.close(); } + + getErrorMessage(name: string): string { + if (this.jumpForm.controls[name].errors !== null) { + return 'Ce champ est requis.'; + } + return ''; + } + + removeSautant(index: string): void { + this.useLast.groupe = false; + this.useLast.all = this._isLastForAllSections(); + this.jump.sautants = this.jump.sautants.filter((sautant) => sautant !== index); + const participants = (this.jump.sautants.length + 1); + this.jumpForm.controls['participants'].setValue(participants); + } + + setLastJump(checked: boolean) { + if (checked) { + this._setAllLast(true); + this.jumpForm.controls['lieu'].setValue(this.lastJump.lieu); + this.jumpForm.controls['oaci'].setValue(this.lastJump.oaci); + this.jumpForm.controls['aeronef'].setValue(this.lastJump.aeronef); + this.jumpForm.controls['imat'].setValue(this.lastJump.imat); + this.jumpForm.controls['hauteur'].setValue(this.lastJump.hauteur); + this.jumpForm.controls['deploiement'].setValue(this.lastJump.deploiement); + this.jumpForm.controls['voile'].setValue(this.lastJump.voile); + this.jumpForm.controls['taille'].setValue(this.lastJump.taille); + this.jumpForm.controls['categorie'].setValue(this.lastJump.categorie); + this.jumpForm.controls['module'].setValue(this.lastJump.module); + this.jumpForm.controls['participants'].setValue(this.lastJump.participants); + //this.jumpForm.controls['sautants'].setValue(this.lastJump.sautants); + this.jumpForm.controls['programme'].setValue(this.lastJump.programme); + this.jumpForm.controls['accessoires'].setValue(this.lastJump.accessoires); + this.jumpForm.controls['zone'].setValue(this.lastJump.zone); + this.jump.sautants = this.lastJump.sautants; + /* + Object.assign( + this.jump, + { + date: this.lastJump.date, + numero: this.lastJump.numero, + lieu: this.lastJump.lieu, + oaci: this.lastJump.oaci, + aeronef: this.lastJump.aeronef, + imat: this.lastJump.imat, + hauteur: this.lastJump.hauteur, + deploiement: this.lastJump.deploiement, + voile: this.lastJump.voile, + taille: this.lastJump.taille, + categorie: this.lastJump.categorie, + module: this.lastJump.module, + participants: this.lastJump.participants, + sautants: this.lastJump.sautants, + programme: this.lastJump.programme, + accessoires: this.lastJump.accessoires, + zone: this.lastJump.zone, + } + ); + */ + this.jump.date = ''; + } else { + this._setAllLast(false); + this.jumpForm.controls['lieu'].setValue(''); + this.jumpForm.controls['oaci'].setValue(''); + this.jumpForm.controls['aeronef'].setValue(''); + this.jumpForm.controls['imat'].setValue(''); + this.jumpForm.controls['hauteur'].setValue(''); + this.jumpForm.controls['deploiement'].setValue(''); + this.jumpForm.controls['voile'].setValue(''); + this.jumpForm.controls['taille'].setValue(''); + this.jumpForm.controls['categorie'].setValue(''); + this.jumpForm.controls['module'].setValue(''); + this.jumpForm.controls['participants'].setValue(1); + //this.jumpForm.controls['sautants'].setValue(''); + this.jumpForm.controls['programme'].setValue(''); + this.jumpForm.controls['accessoires'].setValue(''); + this.jumpForm.controls['zone'].setValue(''); + this.jump.sautants = []; + } + this.jump.numero = this.nextJump; + }; + + setLastAeronef(checked: boolean = false) { + if (checked) { + this.useLast.aeronef = true; + this.jumpForm.controls['aeronef'].setValue(this.lastJump.aeronef); + this.jumpForm.controls['imat'].setValue(this.lastJump.imat); + } else { + this.useLast.aeronef = false; + this.jumpForm.controls['aeronef'].setValue(''); + this.jumpForm.controls['imat'].setValue(''); + } + this.useLast.all = this._isLastForAllSections(); + } + + setLastAltitude(checked: boolean = false) { + if (checked) { + this.useLast.altitude = true; + this.jumpForm.controls['hauteur'].setValue(this.lastJump.hauteur); + this.jumpForm.controls['deploiement'].setValue(this.lastJump.deploiement); + } else { + this.useLast.altitude = false; + this.jumpForm.controls['hauteur'].setValue(''); + this.jumpForm.controls['deploiement'].setValue(''); + } + this.useLast.all = this._isLastForAllSections(); + } + + setLastDiscipline(checked: boolean = false) { + if (checked) { + this.useLast.discipline = true; + this.jumpForm.controls['categorie'].setValue(this.lastJump.categorie); + this.jumpForm.controls['module'].setValue(this.lastJump.module); + } else { + this.useLast.discipline = false; + this.jumpForm.controls['categorie'].setValue(''); + this.jumpForm.controls['module'].setValue(''); + } + this.useLast.all = this._isLastForAllSections(); + } + + setLastDivers(checked: boolean = false) { + if (checked) { + this.useLast.divers = true; + this.jumpForm.controls['accessoires'].setValue(this.lastJump.accessoires); + this.jumpForm.controls['zone'].setValue(this.lastJump.zone); + } else { + this.useLast.divers = false; + this.jumpForm.controls['accessoires'].setValue(''); + this.jumpForm.controls['zone'].setValue(''); + } + this.useLast.all = this._isLastForAllSections(); + } + + setLastDropzone(checked: boolean = false) { + if (checked) { + this.useLast.dropzone = true; + this.jumpForm.controls['lieu'].setValue(this.lastJump.lieu); + this.jumpForm.controls['oaci'].setValue(this.lastJump.oaci); + } else { + this.useLast.dropzone = false; + this.jumpForm.controls['lieu'].setValue(''); + this.jumpForm.controls['oaci'].setValue(''); + } + this.useLast.all = this._isLastForAllSections(); + } + + setLastGroupe(checked: boolean = false) { + if (checked) { + this.useLast.groupe = true; + this.jumpForm.controls['participants'].setValue(this.lastJump.participants); + //this.jumpForm.controls['sautants'].setValue(this.lastJump.sautants); + this.jump.sautants = this.lastJump.sautants; + } else { + this.useLast.groupe = false; + this.jumpForm.controls['participants'].setValue(1); + //this.jumpForm.controls['sautants'].setValue(''); + this.jump.sautants = []; + } + this.useLast.all = this._isLastForAllSections(); + } + + setLastProgramme(checked: boolean = false) { + if (checked) { + this.useLast.programme = true; + this.jumpForm.controls['programme'].setValue(this.lastJump.participants); + } else { + this.useLast.programme = false; + this.jumpForm.controls['programme'].setValue(''); + } + this.useLast.all = this._isLastForAllSections(); + } + + setLastVoile(checked: boolean = false) { + if (checked) { + this.useLast.voile = true; + this.jumpForm.controls['voile'].setValue(this.lastJump.voile); + this.jumpForm.controls['taille'].setValue(this.lastJump.taille); + } else { + this.useLast.voile = false; + this.jumpForm.controls['voile'].setValue(''); + this.jumpForm.controls['taille'].setValue(''); + } + this.useLast.all = this._isLastForAllSections(); + } + + submitForm(): void { + /* + * Création d'un tableau de saut contenant de 1 à n saut en fonction + * de la valeur du champ numero du formulaire jumpForm + */ + let jumps: Array = []; + let jump: Jump = {} as Jump; + let numeros: Array = []; + let date: Date; + /* Controle de la validité du champ date et conversion au format ISO */ + let timestamp: number = Date.parse(this.jumpForm.controls['date'].value); + if (isNaN(timestamp) == false) { + date = new Date(timestamp); + } else { + date = new Date(); + } + + if (isNaN(+this.jumpForm.controls['numero'].value)) { + /* + * 'numero' n'est pas un entier , il s'agit donc d'une plage, d'une quantité ou de plusieurs valeur + * decomposer la valeur 'numero' et ajouter chaque sauts au tableau retourné par la fenêtre dialog + */ + let jumpNum: number = this.lastJump.numero; + const elements: string[] = this.jumpForm.controls['numero'].value.split(';'); + elements.forEach((element: string) => { + if (element == '') { + jumpNum ++; + element = jumpNum.toString(); + } + const values: string[] = element.split('-'); + if (values.length == 2) { + const start: number = parseInt(values[0]); + const stop: number = parseInt(values[1]); + const diff: number = (stop - start); + /* Ajout de saut par plage */ + for (let index = 0; index <= diff; index++) { + jumpNum = (start + index); + numeros.push(jumpNum); + } + } else { + const quantity: string[] = values[0].split('+'); + if (quantity.length == 2) { + /* Ajout de sauts par quantité */ + const start: number = jumpNum; + for (let index = 1; index <= parseInt(quantity[1]); index++) { + jumpNum ++; + numeros.push(jumpNum); + } + } else { + /* Ajout de sauts par numero */ + jumpNum = parseInt(quantity[0]); + numeros.push(jumpNum); + } + } + }); + } else { + /* 'numero' est un entier */ + numeros.push(this.jumpForm.controls['numero'].value); + } + + /* Valeurs communes aux 1 à n saut(s) à ajouter */ + jump.date = date.toISOString(); + jump.lieu = this.jumpForm.controls['lieu'].value; + jump.oaci = this.jumpForm.controls['oaci'].value; + jump.aeronef = this.jumpForm.controls['aeronef'].value; + jump.imat = this.jumpForm.controls['imat'].value; + jump.hauteur = this.jumpForm.controls['hauteur'].value; + jump.deploiement = this.jumpForm.controls['deploiement'].value; + jump.voile = this.jumpForm.controls['voile'].value; + jump.taille = this.jumpForm.controls['taille'].value; + jump.categorie = this.jumpForm.controls['categorie'].value; + jump.module = this.jumpForm.controls['module'].value; + jump.participants = this.jumpForm.controls['participants'].value; + jump.sautants = this.jump.sautants; + //jump.sautants = this.jumpForm.controls['sautants'].value; + jump.programme = this.jumpForm.controls['programme'].value; + jump.accessoires = this.jumpForm.controls['accessoires'].value; + jump.zone = this.jumpForm.controls['zone'].value; + //jump.dossier = this.jumpForm.controls['dossier'].value; + //jump.video = this.jumpForm.controls['video'].value; + + //console.log(numeros); + /* Ajout du saut au tableau à retourner */ + numeros.forEach((numero: number) => { + let item: Jump = {} as Jump; + Object.assign(item, jump); + item.numero = numero; + item.dossier = this._computeFilepath(); + item.video = this._computeFilename(numero.toString()); + jumps.push(item); + //console.log(item); + }); + //console.log(jumps); + /* Reset all 'last jump values' booleans */ + this._setAllLast(false); + /* close the dialog with result */ + this.dialogRef.close(jumps); + + /* + // Reset all 'last jump values' booleans + this._setAllLast(false); + // update the model + this.updateJump(this.jumpForm.value); + // close the dialog with result + this.dialogRef.close(this.jump); + */ + } + + updateJump(values: NonNullable): void { + Object.assign(this.jump, values); + } } diff --git a/src/app/components/shared/dialogs/jump-delete.dialog.html b/src/app/components/shared/dialogs/jump-delete.dialog.html index 0b89239..b24abdd 100644 --- a/src/app/components/shared/dialogs/jump-delete.dialog.html +++ b/src/app/components/shared/dialogs/jump-delete.dialog.html @@ -1,50 +1,64 @@ -

Supprimer le saut n°{{jump.numero}}

- +

+ Supprimer le saut n°{{jump.numero}} + +

-

Veuillez confirmer la suppression de ce saut. Attention, cette action est irréversible.

-

Données du saut :

-
-
-
numero:
-
{{jump.numero}}
-
date:
-
{{jump.date}}
-
lieu:
-
{{jump.lieu}}
-
oaci:
-
{{jump.oaci}}
-
aeronef:
-
{{jump.aeronef}}
-
imat:
-
{{jump.imat}}
-
hauteur:
-
{{jump.hauteur}}
-
voile:
-
{{jump.voile}}
-
taille:
-
{{jump.taille}}
-
categorie:
-
{{jump.categorie}}
-
module:
-
{{jump.module}}
-
participants:
-
{{jump.participants}}
-
programme:
-
{{jump.programme}}
-
accessoires:
-
{{jump.accessoires}}
-
zone:
-
{{jump.zone}}
-
dossier:
-
{{jump.dossier}}
-
video:
-
{{jump.video}}
-
+
+
+

+ Veuillez confirmer la suppression de ce saut.
+ Attention, cette action est irréversible. +

+
+

Données du saut :

+
+
+
+
numero:
+
{{jump.numero}}
+
lieu:
+
{{jump.lieu}}
+
aeronef:
+
{{jump.aeronef}}
+
voile:
+
{{jump.voile}}
+
hauteur:
+
{{jump.hauteur}} m
+
categorie:
+
{{jump.categorie}}
+
accessoires:
+
{{jump.accessoires}}
+
dossier:
+
{{jump.dossier}}
+
programme:
+
{{jump.programme}}
+
+
+
+
+
date:
+
{{jump.date | date: 'mediumDate'}}
+
oaci:
+
{{jump.oaci}}
+
imat:
+
{{jump.imat}}
+
taille:
+
{{jump.taille}} ft2
+
participants:
+
{{jump.participants}}
+
module:
+
{{jump.module}}
+
zone:
+
{{jump.zone}}
+
video:
+
{{jump.video}}
+
+
+
-
- + diff --git a/src/app/components/shared/dialogs/jump-delete.dialog.ts b/src/app/components/shared/dialogs/jump-delete.dialog.ts index 4209d25..67c8482 100644 --- a/src/app/components/shared/dialogs/jump-delete.dialog.ts +++ b/src/app/components/shared/dialogs/jump-delete.dialog.ts @@ -1,7 +1,8 @@ import { Component, Inject } from '@angular/core'; +import { DatePipe } from '@angular/common'; import { MatButtonModule } from '@angular/material/button'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog'; -import { MatDividerModule } from '@angular/material/divider'; +import { MatIconModule } from '@angular/material/icon'; import { Jump } from 'src/app/core/models'; @@ -9,7 +10,10 @@ import { Jump } from 'src/app/core/models'; selector: 'huapp-jump-delete-dialog', templateUrl: 'jump-delete.dialog.html', standalone: true, - imports: [MatDialogModule, MatButtonModule, MatDividerModule] + imports: [ + DatePipe, + MatDialogModule, MatButtonModule, MatIconModule + ] }) export class JumpDeleteDialogComponent { constructor( @@ -17,7 +21,7 @@ export class JumpDeleteDialogComponent { @Inject(MAT_DIALOG_DATA) public jump: Jump ) { } - onCloseDialog(): void { + closeDialog(): void { this.dialogRef.close(); } } diff --git a/src/app/components/shared/dialogs/jump-edit.dialog.html b/src/app/components/shared/dialogs/jump-edit.dialog.html index 2444567..21a0cb7 100644 --- a/src/app/components/shared/dialogs/jump-edit.dialog.html +++ b/src/app/components/shared/dialogs/jump-edit.dialog.html @@ -1,85 +1,145 @@ -

Editer un saut

- +

+ Modifier un saut + +

-
- -
- - Numéro - - - - Date - - - - Lieu - - - - Aeronef - - - - Hauteur - - - - Voile - - - - Taille - - - - Categorie - - - - Module - - -
- -
- - Participants - - - - Programme - - - - Oaci - - - - Imat - - - - Accessoires - - - - Zone - - - - Dossier - - - - Video - - -
+
+
+
+ + Numéro du saut + + + + Choisissez une date + + MM/DD/YYYY + + + + + + + + +
+
+

Dropzone

+ + Lieu + + {{getErrorMessage('lieu')}} + + + Oaci + + {{getErrorMessage('oaci')}} + +

Aéronef

+ + Aéronef + + {{getErrorMessage('aeronef')}} + + + Imatriculation + + {{getErrorMessage('imat')}} + +

Voile

+ + Modèle + + {{getErrorMessage('voile')}} + + + Taille en ft2 + + ft2 + {{getErrorMessage('taille')}} + +
+
+

Altitude

+ + Hauteur de largage + + {{getErrorMessage('hauteur')}} + + + Hauteur de déploiement + + {{getErrorMessage('deploiement')}} + +

Discipline

+ + Categorie + + {{getErrorMessage('categorie')}} + + + Module + + {{getErrorMessage('module')}} + +

Divers

+ + Accessoires + + {{getErrorMessage('accessoires')}} + + + Zone + + {{getErrorMessage('zone')}} + +
+
+

Groupe

+ + Sautants + + + + Nombre de participants + + {{getErrorMessage('participants')}} + +
+ + + {{ sautant }} + + + + ju_solide + +
+
+
+

Programme

+ + Programme + + {{getErrorMessage('programme')}} + +

Vidéo

+ + Dossier + + {{getErrorMessage('dossier')}} + + + Video + + {{getErrorMessage('video')}} + +
+
- - + + diff --git a/src/app/components/shared/dialogs/jump-edit.dialog.ts b/src/app/components/shared/dialogs/jump-edit.dialog.ts index e8a0474..81b70d2 100644 --- a/src/app/components/shared/dialogs/jump-edit.dialog.ts +++ b/src/app/components/shared/dialogs/jump-edit.dialog.ts @@ -1,33 +1,98 @@ import { Component, Inject } from '@angular/core'; -import { FormsModule } from '@angular/forms'; +import { NgFor, NgIf } from '@angular/common'; +import { FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; import { MatButtonModule } from '@angular/material/button'; -import { MatOptionModule } from '@angular/material/core'; +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { MatDatepickerModule } from '@angular/material/datepicker'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog'; -import { MatDividerModule } from '@angular/material/divider'; import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatOptionModule } from '@angular/material/core'; import { MatSelectModule } from '@angular/material/select'; -import { Jump } from 'src/app/core/models'; +import { Jump, JumpForm } from 'src/app/core/models'; @Component({ selector: 'huapp-jump-edit-dialog', templateUrl: 'jump-edit.dialog.html', standalone: true, imports: [ - FormsModule, - MatDialogModule, MatFormFieldModule, MatInputModule, MatDividerModule, - MatSelectModule, MatOptionModule, MatIconModule, MatButtonModule + NgFor, NgIf, FormsModule, ReactiveFormsModule, + MatButtonModule, MatCheckboxModule, MatDatepickerModule, + MatDialogModule, MatFormFieldModule, MatIconModule, + MatInputModule, MatSelectModule, MatOptionModule ] }) export class JumpEditDialogComponent { + public tagField = new FormControl('', { nonNullable: true}); + public jumpForm: FormGroup; + constructor( public dialogRef: MatDialogRef, + private fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public jump: Jump - ) { } + ) { + let controlsConfig = { + slug: [this.jump.slug, Validators.required], + date: [this.jump.date, Validators.required], + numero: [this.jump.numero, Validators.required], + lieu: [this.jump.lieu, Validators.required], + oaci: this.jump.oaci, + aeronef: [this.jump.aeronef, Validators.required], + imat: this.jump.imat, + hauteur: [this.jump.hauteur, Validators.required], + deploiement: this.jump.deploiement, + voile: this.jump.voile, + taille: [this.jump.taille, Validators.required], + categorie: this.jump.categorie, + module: this.jump.module, + participants: [this.jump.participants, Validators.required], + programme: this.jump.programme, + accessoires: this.jump.accessoires, + zone: this.jump.zone, + dossier: this.jump.dossier, + video: this.jump.video + }; + this.jumpForm = this.fb.group(controlsConfig); + } - onCloseDialog(): void { + addSautant(): void { + const tag = this.tagField.value; + if (tag != null && tag.trim() !== '' && this.jump.sautants.indexOf(tag) < 0) { + this.jump.sautants.push(tag); + } + const participants = (this.jump.sautants.length + 1); + this.jumpForm.controls['participants'].setValue(participants); + this.tagField.reset(''); + } + + closeDialog(): void { + // close the dialog without result this.dialogRef.close(); } + + getErrorMessage(name: string): string { + if (this.jumpForm.controls[name].errors !== null) { + return `Ce champ est requis.`; + } + return ''; + } + + removeSautant(index: string): void { + this.jump.sautants = this.jump.sautants.filter((sautant) => sautant !== index); + const participants = (this.jump.sautants.length + 1); + this.jumpForm.controls['participants'].setValue(participants); + } + + submitForm(): void { + // update the model + this.updateJump(this.jumpForm.value); + // close the dialog with result + this.dialogRef.close(this.jump); + } + + updateJump(values: NonNullable): void { + Object.assign(this.jump, values); + } } diff --git a/src/app/components/shared/helpers-jump/jump-table.component.html b/src/app/components/shared/helpers-jump/jump-table.component.html index 0f76f2c..23fd3db 100644 --- a/src/app/components/shared/helpers-jump/jump-table.component.html +++ b/src/app/components/shared/helpers-jump/jump-table.component.html @@ -19,8 +19,7 @@
- +
@@ -38,7 +37,7 @@
Aucun saut à afficher pour le moment.
Date - {{element.date}} + {{element.date | date: 'mediumDate'}} @@ -238,3 +237,57 @@
+ \ No newline at end of file diff --git a/src/app/components/shared/helpers-jump/jump-table.component.ts b/src/app/components/shared/helpers-jump/jump-table.component.ts index 2270c44..3477bae 100644 --- a/src/app/components/shared/helpers-jump/jump-table.component.ts +++ b/src/app/components/shared/helpers-jump/jump-table.component.ts @@ -1,5 +1,5 @@ -import { Component, Input, ViewChild, OnChanges, OnDestroy, computed, Signal, WritableSignal } from '@angular/core'; -import { NgIf, DecimalPipe, DatePipe } from '@angular/common'; +import { Component, AfterContentChecked, Input, ViewChild, OnChanges, OnDestroy, computed, Signal, WritableSignal } from '@angular/core'; +import { CommonModule, DecimalPipe, DatePipe } from '@angular/common'; import { UntypedFormBuilder, UntypedFormGroup, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { Router, RouterLink } from '@angular/router'; import { MatButtonModule } from '@angular/material/button'; @@ -9,61 +9,67 @@ import { MatFormFieldModule } from '@angular/material/form-field'; import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; import { MatMenuModule } from '@angular/material/menu'; +import { MatNativeDateModule } from '@angular/material/core'; import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MatSort, MatSortModule } from '@angular/material/sort'; import { MatTableDataSource, MatTableModule } from '@angular/material/table'; import { MatSnackBar, MatSnackBarHorizontalPosition, MatSnackBarModule, MatSnackBarVerticalPosition } from '@angular/material/snack-bar'; -import { Observable, Subscription } from 'rxjs'; +import { Observable, Subject, Subscription } from 'rxjs'; import { take } from 'rxjs/operators'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; -import { Errors, Jump, JumpList, JumpListConfig } from 'src/app/core/models'; -import { JumpsService, BackendService } from 'src/app/core/services'; +import { ColumnDefinition, Errors, Jump, JumpList, JumpListConfig, jumpColumns } from 'src/app/core/models'; +import { JumpsService, JumpTableService } from 'src/app/core/services'; import { JumpAddDialogComponent, JumpDeleteDialogComponent, JumpEditDialogComponent } from 'src/app/components/shared/dialogs' @Component({ standalone: true, imports: [ - NgIf, DecimalPipe, DatePipe, RouterLink, FormsModule, ReactiveFormsModule, NgxSkeletonLoaderModule, - MatFormFieldModule, MatInputModule, - MatProgressSpinnerModule, MatButtonModule, MatCardModule, MatIconModule, MatMenuModule, - MatPaginatorModule, MatTableModule, MatSortModule, MatSnackBarModule, MatDialogModule, + CommonModule, DecimalPipe, DatePipe, RouterLink, FormsModule, ReactiveFormsModule, NgxSkeletonLoaderModule, + MatButtonModule, MatCardModule, MatDialogModule, + MatFormFieldModule, MatIconModule, MatInputModule, MatNativeDateModule, MatMenuModule, + MatPaginatorModule, MatProgressSpinnerModule, MatSnackBarModule, MatSortModule, MatTableModule, JumpAddDialogComponent, JumpDeleteDialogComponent, JumpEditDialogComponent ], selector: 'huapp-jump-table', styleUrls: ['./jump-table.component.scss'], templateUrl: './jump-table.component.html' }) -export class JumpTableComponent implements OnChanges, OnDestroy { +export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChecked { + private _subject: Subject = new Subject(); private _jumps: Subscription = new Subscription(); - private _lastjump: Subscription = new Subscription(); - errors!: Errors; - query: JumpListConfig = { type: 'all', filters: {} }; - jump: Jump = {} as Jump; - jumps!: MatTableDataSource; - lastjump: Jump = {} as Jump; - jumpsCount = 0; - currentPage = 1; - displayedColumns: string[] = [ + private _jump: Subscription = new Subscription(); + private _query: JumpListConfig = { type: 'all', filters: {} }; + private _lastjump: Jump = {} as Jump; + private _currentPage = 1; + public errors!: Errors; + public jump: Jump = {} as Jump; + public jumps!: MatTableDataSource; + public jumpsCount = 0; + public displayedColumns: string[] = [ 'numero', 'date', 'lieu', 'oaci', 'aeronef', 'imat', 'hauteur', 'voile', 'taille', 'categorie', 'module', 'participants', 'programme', 'accessoires', 'zone', 'video', 'actions' ]; - lastUpdate: Date = new Date(); - loading = false; - isSubmitting = false; - isDeleting = false; - searchForm: UntypedFormGroup; + //public displayedColumns: string[] = jumpColumns.map((col) => col.key) + public columnsSchema: Array = jumpColumns; + public loading = false; + public isSubmitting = false; + public isDeleting = false; + public searchForm: UntypedFormGroup; + public valid: any = {}; + public tableRefresh = false; + public jumpRefresh = false; @ViewChild(MatSort) sort!: MatSort; @ViewChild(MatPaginator) paginator!: MatPaginator; - + constructor( private router: Router, - private jumpsService: JumpsService, - private _dataService: BackendService, + private _jumpsService: JumpsService, + private _jumpTableService: JumpTableService, private dialog: MatDialog, private fb: UntypedFormBuilder, private snackBar: MatSnackBar @@ -75,49 +81,64 @@ export class JumpTableComponent implements OnChanges, OnDestroy { }); } - @Input() limit = 0; - @Input() refresh = 30000; @Input() title = ''; + @Input() limit = 0; + @Input() refresh = false; @Input() showAdd = false; @Input() isUser = false; @Input() set config(config: JumpListConfig) { if (config) { - this.query = config; - this.currentPage = 1; + this._query = config; + this._currentPage = 1; } } get config(): JumpListConfig { - return this.query; + return this._query; } ngOnChanges() { this.loading = true; - this.query = this.config; + this._query = this.config; this.runQuery(); + //this.refresh = false; + console.log('ngOnChanges event in jump-table component'); } ngOnDestroy() { this._jumps.unsubscribe(); - this._lastjump.unsubscribe(); + this._jump.unsubscribe(); + } + + ngAfterContentChecked() { + //console.log('jump-table ngAfterContentChecked', this.tableRefresh, this._jumpTableService.tableRefresh); + /*if (this.tableRefresh != this._jumpTableService.tableRefresh) { + this.tableRefresh = this._jumpTableService.tableRefresh; + console.log('refresh table', this.tableRefresh, this._jumpTableService.tableRefresh); + }*/ + if (this.jumpRefresh != this._jumpTableService.jumpRefresh) { + this.jumpRefresh = this._jumpTableService.jumpRefresh; + this.runQuery(); + console.log('table has been refreshed in jump-table component'); + } } runQuery() { - const lastjump$: Observable = this.jumpsService.getLastJump(); - this._lastjump = lastjump$.subscribe((jump) => { - this.lastjump = jump; + const jump$: Observable = this._jumpsService.getLastJump(); + this._jump = jump$.subscribe((jump) => { + this._lastjump = jump; }); if (this.limit) { - this.query.filters.limit = this.limit; - this.query.filters.offset = (this.limit * (this.currentPage - 1)); + this._query.filters.limit = this.limit; + this._query.filters.offset = (this.limit * (this._currentPage - 1)); } else { - this.query.filters.limit = 0; - this.query.filters.offset = 0; + this._query.filters.limit = 0; + this._query.filters.offset = 0; } - const jumps$: Observable = this.jumpsService.query(this.query); + const jumps$: Observable = this._jumpsService.query(this._query); this._jumps = jumps$.subscribe({ next: (data: JumpList) => { this.loading = false; @@ -127,6 +148,8 @@ export class JumpTableComponent implements OnChanges, OnDestroy { this.jumps.paginator = this.paginator; this.jumps.sort = this.sort; this._resetErrors(); + //this.tableRefresh = !this.tableRefresh; + //this._jumpTableService.updateJumpRefresh(this.tableRefresh); }, error: (err) => { this.errors = err; @@ -136,49 +159,49 @@ export class JumpTableComponent implements OnChanges, OnDestroy { deleteJump(slug: string) { this.isDeleting = true; - this.jumpsService.destroy(slug).pipe(take(1)) - .subscribe(() => { - this.router.navigateByUrl('/'); - }); + this._jumpsService.destroy(slug).pipe(take(1)) + .subscribe(() => { + this.router.navigateByUrl('/'); + }); } openAddDialog(): void { const dialogRef = this.dialog.open(JumpAddDialogComponent, { - width: '60vw', + width: '70vw', data: this.jump }); dialogRef.afterClosed().pipe(take(1)) - .subscribe(result => { - if (result != undefined) { - this._onEntry(result); - } - }); + .subscribe(result => { + if (result != undefined) { + this._onEntry(result); + } + }); } openDeleteDialog(jump: Jump): void { const dialogRef = this.dialog.open(JumpDeleteDialogComponent, { - width: '40vw', + width: '60vw', data: jump }); dialogRef.afterClosed().pipe(take(1)) - .subscribe(result => { - if (result != undefined) { - this._onDelete(result.slug); - } - }); + .subscribe(result => { + if (result != undefined) { + this._onDelete(result.slug); + } + }); } openEditDialog(jump: Jump): void { const dialogRef = this.dialog.open(JumpEditDialogComponent, { - width: '50vw', + width: '70vw', data: jump }); dialogRef.afterClosed().pipe(take(1)) - .subscribe(result => { - if (result != undefined) { - this._onEdit(result); - } - }); + .subscribe(result => { + if (result != undefined) { + this._onEdit(result); + } + }); } getErrorMessage() { @@ -190,7 +213,7 @@ export class JumpTableComponent implements OnChanges, OnDestroy { submitForm() { if (this.searchForm.valid) { - this.query.filters.numero = this.searchForm.value.numero; + this._query.filters.numero = this.searchForm.value.numero; this._resetErrors(); this.runQuery(); } @@ -199,18 +222,20 @@ export class JumpTableComponent implements OnChanges, OnDestroy { private _onDelete(slug: string): void { try { this.isDeleting = true; - this.jumpsService.destroy(slug) - .pipe(take(1)) - .subscribe({ - next: () => { - this._resetErrors(); - this._openSnackBar(`Le saut a été supprimé !`, 'OK'); - this.runQuery(); - }, - error: (err) => { - this.errors = err; - } - }); + this._jumpsService.destroy(slug) + .pipe(take(1)) + .subscribe({ + next: () => { + this._resetErrors(); + this._openSnackBar(`Le saut a été supprimé !`, 'OK'); + this.runQuery(); + this.tableRefresh = !this.tableRefresh; + this._jumpTableService.updateTableRefresh(this.tableRefresh); + }, + error: (err) => { + this.errors = err; + } + }); } catch (error) { console.error(error); } @@ -219,19 +244,22 @@ export class JumpTableComponent implements OnChanges, OnDestroy { private _onEdit(jump: Jump): void { try { this.isSubmitting = true; - this.jumpsService.update(jump) - .pipe(take(1)) - .subscribe({ - next: (jump) => { - this._resetErrors(); - this._openSnackBar(`Le saut n°${jump.numero} a été mis à jour !`, 'OK'); - this.runQuery(); - }, - error: (err) => { - this.errors = err; - this.isSubmitting = false; - } - }); + console.log(jump); + this._jumpsService.update(jump) + .pipe(take(1)) + .subscribe({ + next: (jump) => { + this._resetErrors(); + this._openSnackBar(`Le saut n°${jump.numero} a été mis à jour !`, 'OK'); + this.runQuery(); + this.tableRefresh = !this.tableRefresh; + this._jumpTableService.updateTableRefresh(this.tableRefresh); + }, + error: (err) => { + this.errors = err; + this.isSubmitting = false; + } + }); } catch (error) { console.error(error); } @@ -241,19 +269,19 @@ export class JumpTableComponent implements OnChanges, OnDestroy { try { this.isSubmitting = true; Object.assign(this.jump, entry); - this.jumpsService.save(this.jump) - .pipe(take(1)) - .subscribe({ - next: (jump) => { - this._openSnackBar(`Le saut n°${jump.numero} a été ajouté !`, 'OK'); - this._resetErrors(); - this.runQuery(); - }, - error: (err) => { - this.errors = err; - this.isSubmitting = false; - } - }); + this._jumpsService.save(this.jump) + .pipe(take(1)) + .subscribe({ + next: (jump) => { + this._openSnackBar(`Le saut n°${jump.numero} a été ajouté !`, 'OK'); + this._resetErrors(); + this.runQuery(); + }, + error: (err) => { + this.errors = err; + this.isSubmitting = false; + } + }); } catch (error) { console.error(error); } @@ -271,4 +299,35 @@ export class JumpTableComponent implements OnChanges, OnDestroy { this.errors = { errors: {} }; } + inputHandler(e: any, id: number, key: string) { + if (!this.valid[id]) { + this.valid[id] = {} + } + this.valid[id][key] = e.target.validity.valid + } + + disableSubmit(id: number) { + if (this.valid[id]) { + return Object.values(this.valid[id]).some((item) => item === false) + } + return false + } + + /* + isAllSelected() { + return this.jumps.data.every((item) => item.isSelected) + } + + isAnySelected() { + return this.jumps.data.some((item) => item.isSelected) + } + + selectAll(event: any) { + this.jumps.data = this.jumps.data.map((item) => ({ + ...item, + isSelected: event.checked, + })) + } + */ + }