---|qcm| Mise à jour V17 et QCM
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, AfterContentChecked, OnInit, OnDestroy } from '@angular/core';
|
||||
import { trigger, state, style, animate, transition } from '@angular/animations';
|
||||
import { Component, AfterContentChecked, OnInit, OnDestroy, computed, signal, Signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatExpansionModule } from '@angular/material/expansion';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatSliderModule } from '@angular/material/slider';
|
||||
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 { Errors, Jump, JumpListConfig, User } from 'src/app/core/models';
|
||||
import { JumpAddDialogComponent } from 'src/app/components/logbook/dialogs';
|
||||
import { MenuItems, JumpTableComponent } from 'src/app/components/shared';
|
||||
import { Errors, Jump, JumpListConfig, Range, User } from 'src/app/core/models';
|
||||
import { JumpsService, JumpTableService, UserService } from 'src/app/core/services';
|
||||
import data from 'src/jumps.json';
|
||||
//import data from 'src/jumps_02.json';
|
||||
@@ -19,20 +26,35 @@ import data from 'src/jumps.json';
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule, RouterModule,
|
||||
MatButtonModule, MatCardModule, MatIconModule,
|
||||
MatMenuModule, MatDialogModule, MatSnackBarModule,
|
||||
CommonModule, RouterModule, FormsModule,
|
||||
MatButtonModule, MatCardModule, MatDividerModule, MatExpansionModule,
|
||||
MatIconModule, MatInputModule, MatMenuModule, MatDialogModule,
|
||||
MatSliderModule, MatSnackBarModule,
|
||||
JumpTableComponent
|
||||
],
|
||||
selector: 'huapp-logbook',
|
||||
selector: 'app-logbook',
|
||||
templateUrl: './logbook.component.html',
|
||||
styleUrls: ['./logbook.component.scss']
|
||||
styleUrl: './logbook.component.scss',
|
||||
animations: [
|
||||
trigger('flyInOut', [
|
||||
state('in', style({ transform: 'translateY(0)' })),
|
||||
transition('void => *', [
|
||||
style({ transform: 'translateY(-100%)' }),
|
||||
animate(200)
|
||||
]),
|
||||
transition('* => void', [
|
||||
style({ transform: 'translateY(100%)' }),
|
||||
animate(200)
|
||||
])
|
||||
])
|
||||
]
|
||||
})
|
||||
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<Jump> = new Observable();
|
||||
public jumpsCount = 0;
|
||||
public errors!: Errors;
|
||||
public title = 'Carnet de sauts';
|
||||
public jump: Jump = {} as Jump;
|
||||
@@ -45,6 +67,21 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
public isSubmitting = false;
|
||||
public tableRefresh = false;
|
||||
public jumpRefresh = false;
|
||||
public jumpsSinceHundred: Signal<number> = signal(0);
|
||||
public jumpsToHundred: Signal<number> = signal(100);
|
||||
public rangesMinMax: {
|
||||
numero: Range;
|
||||
taille: Range;
|
||||
participants: Range;
|
||||
hauteur: Range;
|
||||
year: Range;
|
||||
} = {
|
||||
numero: {start: 1, end: 100000},
|
||||
taille: {start: 1, end: 400},
|
||||
participants: {start: 1, end: 200},
|
||||
hauteur: {start: 0, end: 10000},
|
||||
year: {start: 1970, end: 2020}
|
||||
};
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@@ -59,23 +96,67 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
|
||||
ngOnInit() {
|
||||
//this.importJumps();
|
||||
const data$: Observable<any> = this.route.data;
|
||||
this._data = data$.subscribe((data: { isAuthenticated: boolean }) => {
|
||||
const data$: Observable<{isAuthenticated: boolean, lastjump: Jump}> = this.route.data as Observable<{isAuthenticated: boolean, lastjump: Jump}>;
|
||||
this._data = data$.subscribe((data: {isAuthenticated: boolean, lastjump: Jump}) => {
|
||||
this.isAuthenticated = data.isAuthenticated;
|
||||
if (!this.isAuthenticated) {
|
||||
this.router.navigateByUrl('/login');
|
||||
return;
|
||||
}
|
||||
|
||||
const currentUser$: Observable<User> = this._userService.currentUser;
|
||||
this._currentUser = currentUser$.subscribe((userData: User) => {
|
||||
this.currentUser = userData;
|
||||
this.canModify = this.currentUser.role === 'Admin';
|
||||
});
|
||||
|
||||
const currentYear: number = new Date().getFullYear();
|
||||
this.lastJump = data['lastjump'];
|
||||
this.rangesMinMax = {
|
||||
numero: {start: 1, end: data.lastjump.numero},
|
||||
taille: {start: data.lastjump.taille!, end: 230},
|
||||
participants: {start: 1, end: 20},
|
||||
hauteur: {start: 1000, end: 8000},
|
||||
year: {start: 2018, end: currentYear}
|
||||
}
|
||||
this.listConfig.filters.numeroRangeStart = this.rangesMinMax.numero.start;
|
||||
this.listConfig.filters.numeroRangeEnd = this.rangesMinMax.numero.end;
|
||||
this.listConfig.filters.tailleRangeStart = this.rangesMinMax.taille.start;
|
||||
this.listConfig.filters.tailleRangeEnd = this.rangesMinMax.taille.end;
|
||||
this.listConfig.filters.participantsRangeStart = this.rangesMinMax.participants.start;
|
||||
this.listConfig.filters.participantsRangeEnd = (this.rangesMinMax.participants.end / 2);
|
||||
this.listConfig.filters.hauteurRangeStart = this.rangesMinMax.hauteur.start;
|
||||
this.listConfig.filters.hauteurRangeEnd = this.rangesMinMax.hauteur.end;
|
||||
this.listConfig.filters.yearRangeStart = this.rangesMinMax.year.start;
|
||||
this.listConfig.filters.yearRangeEnd = this.rangesMinMax.year.end;
|
||||
this.jumpsSinceHundred = computed(() => (this.lastJump.numero % 100));
|
||||
this.jumpsToHundred = computed(() => (100 - this.jumpsSinceHundred()));
|
||||
/*
|
||||
this._lastjump$ = this._jumpsService.getLastJump();
|
||||
this._lastjump = this._lastjump$.subscribe((jump) => {
|
||||
const currentYear: number = new Date().getFullYear();
|
||||
this.lastJump = jump;
|
||||
this.rangesMinMax = {
|
||||
numero: {start: 1, end: jump.numero},
|
||||
taille: {start: jump.taille!, end: 230},
|
||||
participants: {start: 1, end: 20},
|
||||
hauteur: {start: 1000, end: 8000},
|
||||
year: {start: 2018, end: currentYear}
|
||||
}
|
||||
this.listConfig.filters.numeroRangeStart = this.rangesMinMax.numero.start;
|
||||
this.listConfig.filters.numeroRangeEnd = this.rangesMinMax.numero.end;
|
||||
this.listConfig.filters.tailleRangeStart = this.rangesMinMax.taille.start;
|
||||
this.listConfig.filters.tailleRangeEnd = this.rangesMinMax.taille.end;
|
||||
this.listConfig.filters.participantsRangeStart = this.rangesMinMax.participants.start;
|
||||
this.listConfig.filters.participantsRangeEnd = (this.rangesMinMax.participants.end / 2);
|
||||
this.listConfig.filters.hauteurRangeStart = this.rangesMinMax.hauteur.start;
|
||||
this.listConfig.filters.hauteurRangeEnd = this.rangesMinMax.hauteur.end;
|
||||
this.listConfig.filters.yearRangeStart = this.rangesMinMax.year.start;
|
||||
this.listConfig.filters.yearRangeEnd = this.rangesMinMax.year.end;
|
||||
this.jumpsSinceHundred = computed(() => (this.lastJump.numero % 100));
|
||||
this.jumpsToHundred = computed(() => (100 - this.jumpsSinceHundred()));
|
||||
});
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
@@ -107,7 +188,7 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
console.log(`Le saut n°${jump.numero} a été ajouté !`, 'OK');
|
||||
},
|
||||
error: (err) => {
|
||||
console.log(`Le saut n\'a pas été ajouté !`, 'Error', err);
|
||||
console.log(`Le saut n'a pas été ajouté !`, 'Error', err);
|
||||
this.errors = err;
|
||||
}
|
||||
});
|
||||
@@ -134,6 +215,10 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
});
|
||||
}
|
||||
|
||||
setTotalResults(value: number): void {
|
||||
this.jumpsCount = value;
|
||||
}
|
||||
|
||||
private _onEntry(jumps: Array<Jump>): void {
|
||||
const max: number = jumps.length;
|
||||
let refresh: boolean = false;
|
||||
|
||||
Reference in New Issue
Block a user