From 3a5e837842dbb3551daf732c826a1861ee95aa9b Mon Sep 17 00:00:00 2001 From: Julien Gautier Date: Tue, 3 Oct 2023 13:48:26 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20composants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/components/auth/auth.component.ts | 18 +- .../calculator/calculator.component.html | 10 +- .../calculator/calculator.component.scss | 13 - .../calculator/calculator.component.ts | 317 +++++------------- src/app/components/home/home.component.ts | 7 +- .../components/logbook/logbook.component.html | 8 +- .../components/logbook/logbook.component.ts | 112 ++++--- .../components/settings/settings.component.ts | 5 +- 8 files changed, 190 insertions(+), 300 deletions(-) diff --git a/src/app/components/auth/auth.component.ts b/src/app/components/auth/auth.component.ts index 78c10bb..df59e88 100644 --- a/src/app/components/auth/auth.component.ts +++ b/src/app/components/auth/auth.component.ts @@ -44,7 +44,7 @@ export class AuthComponent implements OnInit, OnDestroy { ) { this._resetErrors(); // use FormBuilder to create a form group - this.authForm = this.fb.group({ + let controlsConfig = { email: ['', [Validators.required, Validators.email]], username: '', firstname: '', @@ -54,7 +54,8 @@ export class AuthComponent implements OnInit, OnDestroy { poids: '', password: ['', Validators.required], confirmPassword: '' - }, { validators: this.checkPasswords }); + }; + this.authForm = this.fb.group(controlsConfig, { validators: this.checkPasswords }); } ngOnInit() { @@ -98,13 +99,12 @@ export class AuthComponent implements OnInit, OnDestroy { const credentials = this.authForm.value; const user$ = this.userService.attemptAuth(this.authType, credentials).pipe(take(1)); this._user = user$.subscribe({ - next: () => this.router.navigateByUrl('/'), - error: (err) => { - console.log(err); - this.errors = err; - this.isSubmitting = false; - } - }); + next: () => this.router.navigateByUrl('/'), + error: (err) => { + this.errors = err; + this.isSubmitting = false; + } + }); } } diff --git a/src/app/components/calculator/calculator.component.html b/src/app/components/calculator/calculator.component.html index cc4d3bf..2a3ce29 100644 --- a/src/app/components/calculator/calculator.component.html +++ b/src/app/components/calculator/calculator.component.html @@ -7,7 +7,7 @@
Nombre de sauts - + Poids nu @@ -106,11 +106,11 @@ Taille de voile en ft2 - {{ value }} + {{ value }} Abbattement 11% - {{ value }} + {{ value }} Charge alaire @@ -118,7 +118,7 @@ Taille de voile en m2 - {{ value | number : '1.2-2' }} + {{ value | number : '1.2-2' }} @@ -177,7 +177,7 @@ {{tableHeader[9].name}} {{element.ranges[8].value}} - +
diff --git a/src/app/components/calculator/calculator.component.scss b/src/app/components/calculator/calculator.component.scss index baf40ae..6a1843b 100644 --- a/src/app/components/calculator/calculator.component.scss +++ b/src/app/components/calculator/calculator.component.scss @@ -25,19 +25,6 @@ justify-content: center; width: 120px; } - /* Chrome, Safari, Edge, Opera */ - input::-webkit-outer-spin-button, - input::-webkit-inner-spin-button { - appearance: none; - -webkit-appearance: none; - margin: 0; - } - - /* Firefox */ - input[type=number] { - appearance: textfield; - -moz-appearance: textfield; - } th { &.first { width: 180px; diff --git a/src/app/components/calculator/calculator.component.ts b/src/app/components/calculator/calculator.component.ts index d7d0cd0..388377d 100644 --- a/src/app/components/calculator/calculator.component.ts +++ b/src/app/components/calculator/calculator.component.ts @@ -16,8 +16,8 @@ import { NgChartsModule } from 'ng2-charts'; import { Observable, Subscription } from 'rxjs'; import { MenuItems } from 'src/app/components/shared'; -import { CalculatorInfo, CalculatorResult, InputParams, Jump, LineConfig, Range, TableHeader, User, WeightSize, weightSizes } from 'src/app/core/models'; -import { JumpsService, UserService, UtilitiesService } from 'src/app/core/services'; +import { CalculatorInfo, CalculatorResult, CalculatorState, InputParams, Jump, LineConfig, Range, TableHeader, User, WeightSize, weightSizes } from 'src/app/core/models'; +import { CalculatorService, JumpsService, UserService, UtilitiesService } from 'src/app/core/services'; @Component({ standalone: true, @@ -33,46 +33,33 @@ import { JumpsService, UserService, UtilitiesService } from 'src/app/core/servic templateUrl: './calculator.component.html' }) export class CalculatorComponent implements OnInit, OnDestroy { - private _lastjump: Subscription = new Subscription(); - private _currentUser: Subscription = new Subscription(); + //private _lastjump!: Subscription; // = new Subscription(); + //private _currentUser!: Subscription; // = new Subscription(); + private _subscriptions: Array = []; public title = 'Calcul de taille de voile'; public subtitle = 'DT48 - 13 mars 2020'; public lastjump: Jump = {} as Jump; public currentUser: User = {} as User; - public displayedColumns: string[] = ['weight']; - public tableHeader: TableHeader[] = [{name: 'Poids nu en kg', active: ''}]; - public sizesHeader: TableHeader[] = []; - public sizesValues: number[] = []; - public sizesMinValues: number[] = []; - public sizesCharges: number[] = []; - public sizesValuesM: number[] = []; + public displayedColumns: Array = ['weight']; + public tableHeader: Array = [{name: 'Poids nu en kg', active: ''}]; + public sizesHeader: Array = []; + public sizesValuesFeet: Array = []; + public sizesMinValuesFeet: Array = []; + public sizesCharges: Array = []; + public sizesValuesMeter: Array = []; public displayCharts = false; public chartConfig: LineConfig = this._utilitiesService.getLineChartConfig(); - public info: CalculatorInfo = { - charges: { - current: 0, - min: 0, - min11: 0 - }, - sizesFeet: { - current: 0, - min: 0, - min11: 0 - }, - sizesMeter: { - current: 0, - min: 0, - min11: 0 - }, - state: { - color: 'danger' - } - } public coeffKgLbs: number = this._utilitiesService.getCoeffKgLbs(); public coeffFtM: number = this._utilitiesService.getCoeffFtM(); + public info: CalculatorInfo = { + charges: { current: 0, min: 0, min11: 0 }, + sizesFeet: { current: 0, min: 0, min11: 0 }, + sizesMeter: { current: 0, min: 0, min11: 0 }, + state: { color: 'danger' } + } @Input() canopy_size_table!: MatTableDataSource; - @Input() inputs: InputParams = { + @Input() inputs: InputParams = { jumps: 0, weight: 60, gear: 10, @@ -83,159 +70,67 @@ export class CalculatorComponent implements OnInit, OnDestroy { @ViewChild(MatPaginator) paginator!: MatPaginator; constructor( - private jumpsService: JumpsService, - private userService: UserService, + private _calculatorService: CalculatorService, + private _jumpsService: JumpsService, + private _userService: UserService, private _utilitiesService: UtilitiesService, public menuItems: MenuItems ) { } ngOnInit() { - const currentUser$: Observable = this.userService.currentUser; - const lastjump$: Observable = this.jumpsService.getLastJump(); - this._currentUser = currentUser$.subscribe((userData: User) => { - this.currentUser = userData; - weightSizes[0].ranges.forEach((range: Range) => { - let header: TableHeader = {name: range.label, active: range.active}; - this.tableHeader.push(header) - this.sizesHeader.push(header); - this.displayedColumns.push(range.name); - }); - this._lastjump = lastjump$.subscribe((jump) => { - this.lastjump = jump; - this.inputs.jumps = jump.numero; - this.inputs.weight = this.currentUser.poids!; - this.inputs.current = jump.taille!; - this.canopy_size_table = new MatTableDataSource(weightSizes); - this.refresh(); - }); + const currentUser$: Observable = this._userService.currentUser; + const lastjump$: Observable = this._jumpsService.getLastJump(); + + weightSizes[0].ranges.forEach((range: Range) => { + let header: TableHeader = {name: range.label, active: range.active}; + this.tableHeader.push(header) + this.sizesHeader.push(header); + this.displayedColumns.push(range.name); }); + this.chartConfig.lineChartData.labels = [...this.sizesHeader.map( + (data: TableHeader): string => data.name + )]; + this.chartConfig.lineChartData.datasets = [ + { + label: 'Tailles min -11%', + data: this.sizesMinValuesFeet, + fill: true, + stepped: true, + pointStyle: false, + borderColor: 'rgba(241, 80, 80, 1)', + backgroundColor: 'rgba(241, 80, 80, 0.3)' + }, + { + label: 'Tailles min', + data: this.sizesValuesFeet, + fill: true, + stepped: true, + pointStyle: false, + borderColor: 'rgba(32, 182, 252, 1)', + backgroundColor: 'rgba(32, 182, 252, 0.3)' + } + ]; + this._subscriptions.push( + currentUser$.subscribe((userData: User) => { + this.currentUser = userData; + this._subscriptions.push( + lastjump$.subscribe((jump) => { + this.lastjump = jump; + this.inputs.jumps = jump.numero; + this.inputs.weight = this.currentUser.poids!; + this.inputs.current = jump.taille!; + this.canopy_size_table = new MatTableDataSource(weightSizes); + this.refresh(); + }) + ); + }) + ); } ngOnDestroy() { - this._currentUser.unsubscribe(); - this._lastjump.unsubscribe(); - } - - private _canopySizeCalc(weight: number, jumps: number): CalculatorResult { - let result: CalculatorResult = { - min: 0, - min11: 0 - }; - if (jumps > 2000) { - this.info.error = '2000Jumps'; - return result; - } - let index: number = (this._getTableLine(weight) - this._getTableLine(0)); - result.min = weightSizes[index].ranges[this._getTableColumn(jumps)].value; - result.min11 = this._reduceLimit(result.min, 11); - - return result; - } - - private _getCanopyMinSize(weight: number, jumps: number, reduce: number = 0): number { - var result: CalculatorResult = this._canopySizeCalc(weight, jumps); - let size: number = 0; - switch (reduce) { - case 11: - size = result.min11; - break; - case 0: - default: - size = result.min; - break; - } - return size; - } - - private _getCanopySizes(weight: number, eleven = false): number[] { - var data: number[] = []; - if (weight < 60) { - weight = 60; - } - if (weight > 110) { - weight = 110; - } - if (weight >= 60 && weight <= 110) { - const line = (weight - this._getTableLine(0)); - let data = weightSizes[line]; - if (eleven) { - return data.ranges.map((range: Range) => { - return Math.ceil(range.value * (100 - 11) / 100); - }); - } else { - return data.ranges.map((range: Range) => { - return range.value; - }); - } - } - return data; - } - - private _getCharge(canopySize: number, nakedWeight: number, equipementWeight: number): number { - return (((nakedWeight + equipementWeight) * this.coeffKgLbs) / canopySize); - } - - private _getRangeNum(): number { - let data: Range[] = weightSizes[0].ranges; - let num: number = 1; - data.some((range: Range) => { - if (range.start <= this.inputs.jumps && range.end >= this.inputs.jumps) { - num = range.num; - return true; - } - return false; + this._subscriptions.forEach((sub: Subscription) => { + sub.unsubscribe(); }); - return num; - } - - private _getTableColumn(jumps: number): number { - let column = 0; - if (jumps < 100) { - column = 0; - } else if (jumps < 250) { - column = 1; - } else if (jumps < 400) { - column = 2; - } else if (jumps < 600) { - column = 3; - } else if (jumps < 800) { - column = 4; - } else if (jumps < 1000) { - column = 5; - } else if (jumps < 1400) { - column = 6; - } else if (jumps < 1800) { - column = 7; - } else { - column = 8; - } - return column; - } - - private _getTableLine(weight: number): number { - let line; - let min = 60; - let max = 110; - if (weight < min) { - line = min; - } else if (weight > max) { - line = max; - } else { - line = weight; - } - return line; - } - - private _convertFeet2Meters(size: number): number { - return (size * this._utilitiesService.getCoeffFtM()); - } - - private _isInRange(nb: number, range: Range): boolean { - return (nb >= range.start && nb < range.end); - } - - private _reduceLimit(surface: number, percentOff: number) { - return Math.ceil(surface * (100 - percentOff) / 100); } public refresh():void { @@ -257,7 +152,7 @@ export class CalculatorComponent implements OnInit, OnDestroy { weightSizes[(this.inputs.weight - 60)].active = 'active'; } if (this.inputs.jumps >= 0) { - var num = this._getRangeNum(); + var num = this._calculatorService.getRangeNum(this.inputs.jumps); this.tableHeader[num].active = 'active'; weightSizes.forEach(element => { element.ranges[(num-1)].active = 'active'; @@ -265,66 +160,32 @@ export class CalculatorComponent implements OnInit, OnDestroy { } } - private _getStateColor(current: number, min: number, min11: number): string { - let color: string = 'danger'; - if (current >= min11 && current < min) { - color = 'warning'; - } - if (current >= min) { - color = 'success'; - } - - return color; - } private _refreshSizes(): void { - this.sizesValues = this._getCanopySizes(this.inputs.weight, false); - this.sizesMinValues = this._getCanopySizes(this.inputs.weight, true); - this.sizesValues.forEach((value: number, index: number) => { - this.sizesCharges[index] = this._getCharge(value, this.inputs.weight, this.inputs.gear); - this.sizesValuesM[index] = this._convertFeet2Meters(value); + if (this.inputs.jumps > 2000) { + this.info.state.error = '2K+ Jumps'; + } + this.sizesValuesFeet = this._calculatorService.getCanopySizes(this.inputs.weight); + this.sizesMinValuesFeet = this._calculatorService.getCanopySizes(this.inputs.weight, true); + this.sizesValuesMeter = this.sizesValuesFeet.map((value: number, index: number) => { + this.sizesCharges[index] = this._calculatorService.getCharge(value, this.inputs.weight, this.inputs.gear); + return this._calculatorService.convertFeet2Meters(value); }); - this.info.sizesFeet = this._canopySizeCalc(this.inputs.weight, this.inputs.jumps); + this.info.sizesFeet = this._calculatorService.canopySizeCalc(this.inputs.weight, this.inputs.jumps); this.info.sizesFeet.current = this.inputs.current; this.info.sizesMeter = { - current: this._convertFeet2Meters(this.inputs.current), - min: this._convertFeet2Meters(this.info.sizesFeet.min), - min11: this._convertFeet2Meters(this.info.sizesFeet.min11) + current: this._calculatorService.convertFeet2Meters(this.inputs.current), + min: this._calculatorService.convertFeet2Meters(this.info.sizesFeet.min), + min11: this._calculatorService.convertFeet2Meters(this.info.sizesFeet.min11) } this.info.charges = { - current: this._getCharge(this.inputs.current, this.inputs.weight, this.inputs.gear), - min: this._getCharge(this.info.sizesFeet.min, this.inputs.weight, this.inputs.gear), - min11: this._getCharge(this.info.sizesFeet.min11, this.inputs.weight, this.inputs.gear) + current: this._calculatorService.getCharge(this.inputs.current, this.inputs.weight, this.inputs.gear), + min: this._calculatorService.getCharge(this.info.sizesFeet.min, this.inputs.weight, this.inputs.gear), + min11: this._calculatorService.getCharge(this.info.sizesFeet.min11, this.inputs.weight, this.inputs.gear) } - this.info.state.color = this._getStateColor(this.info.sizesFeet.current, this.info.sizesFeet.min, this.info.sizesFeet.min11); + this.info.state.color = this._calculatorService.getStateColor(this.info.sizesFeet); - this.chartConfig.lineChartData.labels = [...this.sizesHeader.map(( - data: { - name: string; - active: string; - } - ): string => { - return data.name; - })]; - this.chartConfig.lineChartData.datasets = [ - { - label: 'Tailles min -11%', - data: this.sizesMinValues, - fill: true, - stepped: true, - pointStyle: false, - borderColor: 'rgba(241, 80, 80, 1)', - backgroundColor: 'rgba(241, 80, 80, 0.3)' - }, - { - label: 'Tailles min', - data: this.sizesValues, - fill: true, - stepped: true, - pointStyle: false, - borderColor: 'rgba(32, 182, 252, 1)', - backgroundColor: 'rgba(32, 182, 252, 0.3)' - } - ]; + this.chartConfig.lineChartData.datasets[0].data = this.sizesMinValuesFeet; + this.chartConfig.lineChartData.datasets[1].data = this.sizesValuesFeet; this.displayCharts = true; } diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index 83432ed..7c27490 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -8,7 +8,12 @@ import { take } from 'rxjs/operators'; import { User, Errors, Aeronef, AeronefByImat, Canopy, CanopyModelBySize, DropZone, DropZoneByYear } from 'src/app/core/models'; import { AeronefsService, CanopiesService, DropZonesService, UserService } from 'src/app/core/services'; import { ShowAuthedDirective } from 'src/app/components/shared/show-authed.directive'; -import { AeronefsComponent, AeronefsBarComponent, CanopyModelsComponent, CanopySizesComponent, DropZonesComponent, DropZonesBarComponent, JumpsByMonthComponent } from './dashboard-components'; +import { + AeronefsComponent, AeronefsBarComponent, + CanopyModelsComponent, CanopySizesComponent, + DropZonesComponent, DropZonesBarComponent, + JumpsByMonthComponent +} from 'src/app/components/shared/dashboard-components'; @Component({ standalone: true, diff --git a/src/app/components/logbook/logbook.component.html b/src/app/components/logbook/logbook.component.html index 8285a5d..48e1831 100644 --- a/src/app/components/logbook/logbook.component.html +++ b/src/app/components/logbook/logbook.component.html @@ -2,11 +2,11 @@ - {{ title }} ({{ lastjump.numero }}) + {{ title }} ({{ lastJump.numero }}) - - Dernier saut enregistré : # {{ lastjump.numero }} le {{ lastjump.date | date: 'dd/MM/yyyy' }} à {{ lastjump.lieu }} + + Dernier saut enregistré : # {{ lastJump.numero }} le {{ lastJump.date | date: 'dd/MM/yyyy' }} à {{ lastJump.lieu }} @@ -30,7 +30,7 @@ - + diff --git a/src/app/components/logbook/logbook.component.ts b/src/app/components/logbook/logbook.component.ts index dd6d2c2..a6dc913 100644 --- a/src/app/components/logbook/logbook.component.ts +++ b/src/app/components/logbook/logbook.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, AfterContentChecked, OnInit, OnDestroy } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ActivatedRoute, Router, RouterLink, RouterModule } from '@angular/router'; import { MatButtonModule } from '@angular/material/button'; @@ -6,16 +6,17 @@ import { MatCardModule } from '@angular/material/card'; import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { MatIconModule } from '@angular/material/icon'; import { MatMenuModule } from '@angular/material/menu'; -import { MatSnackBar, MatSnackBarHorizontalPosition, MatSnackBarModule, MatSnackBarVerticalPosition } from '@angular/material/snack-bar'; +import { MatSnackBar, MatSnackBarConfig, MatSnackBarHorizontalPosition, MatSnackBarModule, MatSnackBarVerticalPosition } from '@angular/material/snack-bar'; import { Observable, Subscription } from 'rxjs'; import { take } from 'rxjs/operators'; import { MenuItems, JumpAddDialogComponent, JumpTableComponent } from 'src/app/components/shared'; //import { JumpTableComponent } from 'src/app/components/shared/helpers-jump'; -import { Errors, Jump, JumpListConfig, User } from 'src/app/core/models'; -import { JumpsService, UserService } from 'src/app/core/services'; +import { Errors, Jump, JumpAddParams, JumpListConfig, User } from 'src/app/core/models'; +import { JumpsService, JumpTableService, UserService } from 'src/app/core/services'; import { environment } from 'src/environments/environment'; import data from 'src/jumps.json'; +//import data from 'src/jumps_02.json'; @Component({ standalone: true, @@ -29,29 +30,33 @@ import data from 'src/jumps.json'; templateUrl: './logbook.component.html', styleUrls: ['./logbook.component.scss'] }) -export class LogbookComponent implements OnInit, OnDestroy { +export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked { private _currentUser: Subscription = new Subscription(); private _data: Subscription = new Subscription(); private _lastjump: Subscription = new Subscription(); + private _lastjump$: Observable = new Observable(); public errors!: Errors; public title = 'Carnet de sauts'; public jump: Jump = {} as Jump; - public lastjump: Jump = {} as Jump; + public lastJump: Jump = {} as Jump; public currentUser: User = {} as User; public listConfig: JumpListConfig = { type: 'all', filters: {} }; - public refreshInterval: number = environment.refresh_interval; + public refresh: boolean = false; public isAuthenticated = false; public isUser = true; public canModify = false; public isSubmitting = false; + public tableRefresh = false; + public jumpRefresh = false; constructor( private route: ActivatedRoute, private router: Router, private dialog: MatDialog, private snackBar: MatSnackBar, - private jumpsService: JumpsService, - private userService: UserService, + private _jumpsService: JumpsService, + private _jumpTableService: JumpTableService, + private _userService: UserService, public menuItems: MenuItems ) { } @@ -64,15 +69,15 @@ export class LogbookComponent implements OnInit, OnDestroy { this.router.navigateByUrl('/login'); return; } - const currentUser$: Observable = this.userService.currentUser; + const currentUser$: Observable = this._userService.currentUser; this._currentUser = currentUser$.subscribe((userData: User) => { this.currentUser = userData; this.canModify = this.currentUser.role === 'Admin'; }); - const lastjump$: Observable = this.jumpsService.getLastJump(); - this._lastjump = lastjump$.subscribe((jump) => { - this.lastjump = jump; + this._lastjump$ = this._jumpsService.getLastJump(); + this._lastjump = this._lastjump$.subscribe((jump) => { + this.lastJump = jump; }); }); } @@ -83,12 +88,23 @@ export class LogbookComponent implements OnInit, OnDestroy { this._lastjump.unsubscribe(); } + ngAfterContentChecked() { + if (this.tableRefresh != this._jumpTableService.tableRefresh) { + this.tableRefresh = this._jumpTableService.tableRefresh; + this._lastjump$ = this._jumpsService.getLastJump(); + this._lastjump = this._lastjump$.subscribe((jump) => { + this.lastJump = jump; + }); + console.log('lastjump has been updated in logbook component'); + } + } + importJumps() { try { data.forEach((entry) => { Object.assign(this.jump, entry); //console.log(this.jump); - this.jumpsService.save(this.jump) + this._jumpsService.save(this.jump) .pipe(take(1)) .subscribe({ next: (jump) => { @@ -106,9 +122,13 @@ export class LogbookComponent implements OnInit, OnDestroy { } openAddDialog(): void { + this.jump = {}; + this.jump.numero = (this.lastJump.numero + 1); + this.jump.sautants = []; + this.jump.participants = 1; const dialogRef = this.dialog.open(JumpAddDialogComponent, { - width: '60vw', - data: this.jump + width: '70vw', + data: {jump: this.jump, lastJump: this.lastJump} }); dialogRef.afterClosed().pipe(take(1)) .subscribe(result => { @@ -118,35 +138,51 @@ export class LogbookComponent implements OnInit, OnDestroy { }); } + private _onEntry(jumps: Array): void { + const max: number = jumps.length; + let refresh: boolean = false; + jumps.forEach((jump: Jump, index: number) => { + console.log('Ajout du saut', jump.numero); + Object.assign(this.jump, jump); + if (max == index+1) { + refresh = true; + } + this._saveJump(jump, refresh); + }); + } - private _onEntry(entry: NonNullable): void { - 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; + private _saveJump(jump: Jump, refresh: boolean) { + //console.log(jump); + this._jumpsService.save(jump) + .pipe(take(1)) + .subscribe({ + next: (jump) => { + this._openSnackBar(`Le saut n°${jump.numero} a été ajouté !`, 'Annuler'); + this._resetErrors(); + if (refresh) { + this.jumpRefresh = !this.jumpRefresh; + this._jumpTableService.updateJumpRefresh(this.jumpRefresh); + //this.refresh = !this.refresh; + this._lastjump$ = this._jumpsService.getLastJump(); + this._lastjump = this._lastjump$.subscribe((jump) => { + this.lastJump = jump; + }); } - }); - } catch (error) { - console.error(error); - } + }, + error: (err) => { + this.errors = err; + this.isSubmitting = false; + } + }); } private _openSnackBar(content: string, title: string) { - this.snackBar.open(content, title, { + const config: MatSnackBarConfig = { horizontalPosition: 'end', verticalPosition: 'bottom', - duration: 4000, - }); + duration: 4000 + }; + this.snackBar.open(content, title, config); } private _resetErrors(): void { diff --git a/src/app/components/settings/settings.component.ts b/src/app/components/settings/settings.component.ts index a7a7c86..714367b 100644 --- a/src/app/components/settings/settings.component.ts +++ b/src/app/components/settings/settings.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; -import { UntypedFormBuilder, UntypedFormGroup, AbstractControl, Validators, ValidatorFn, ValidationErrors, FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { AbstractControl, FormsModule, ReactiveFormsModule, UntypedFormBuilder, UntypedFormGroup, Validators, ValidatorFn, ValidationErrors } from '@angular/forms'; import { Router, RouterLink } from '@angular/router'; import { Title } from '@angular/platform-browser'; import { MatButtonModule } from '@angular/material/button'; @@ -57,7 +57,8 @@ export class SettingsComponent implements OnInit, OnDestroy { image: '', bg_image: '' }, { validators: this.checkPasswords }); - // Optional: subscribe to changes on the form : this.settingsForm.valueChanges.pipe(this._scavenger.collect()).subscribe(values => this.updateUser(values)); + // Optional: subscribe to changes on the form : + // this.settingsForm.valueChanges.pipe(this._scavenger.collect()).subscribe(values => this.updateUser(values)); } get f() {