Ajout des sources

This commit is contained in:
Julien Gautier
2023-09-12 21:46:56 +02:00
parent fa2288b8ed
commit 747948a422
235 changed files with 45064 additions and 0 deletions
+114
View File
@@ -0,0 +1,114 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Data, Router } from '@angular/router';
import { Observable, Observer, Subscription } from 'rxjs';
import { take } from 'rxjs/operators';
import { User, Errors, Aeronef, AeronefAggregate, AeronefList, Canopy, CanopyAggregate, DropZone, DropZoneAggregate } 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, DropZonesComponent, CanopyModelsComponent } from './dashboard-components';
//import { JumpsByMonthComponent, AeronefsComponent, AeronefsBarComponent, DropZonesComponent, DropZonesBarComponent, CanopySizesComponent, CanopyModelsComponent} from './dashboard-components';
@Component({
standalone: true,
imports: [
//AeronefsComponent, AeronefsBarComponent, DropZonesComponent, DropZonesBarComponent,
//CanopySizesComponent, CanopyModelsComponent, JumpsByMonthComponent,
AeronefsComponent, DropZonesComponent, CanopyModelsComponent, ShowAuthedDirective
],
selector: 'huapp-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit, OnDestroy {
private _currentUser: Subscription = new Subscription();
private _data: Subscription = new Subscription();
private _aeronefs: Subscription = new Subscription();
private _canopies: Subscription = new Subscription();
private _dropzones: Subscription = new Subscription();
title = 'Dashboard';
errors!: Errors;
isAuthenticated = false;
canModify = false;
aeronefAggregate!: Array<AeronefAggregate>
aeronefs!: Array<Aeronef>;
aeronefsCount = 0;
canopyAggregate!: Array<CanopyAggregate>
canopies!: Array<Canopy>;
canopiesCount = 0;
dropzoneAggregate!: Array<DropZoneAggregate>
dropzones!: Array<DropZone>;
dropzonesCount = 0;
constructor(
private route: ActivatedRoute,
private router: Router,
private titleService: Title,
private aeronefsService: AeronefsService,
private canopiesService: CanopiesService,
private dropzonesService: DropZonesService,
private userService: UserService
) {
this._resetErrors();
}
ngOnInit() {
this.titleService.setTitle(this.title);
const data$: Observable<any> = this.route.data.pipe(take(1));
this._data = data$.subscribe((data: Data) => {
//data: Partial<Observer<Data>>
this.isAuthenticated = data['isAuthenticated'];
if (!this.isAuthenticated) {
this.router.navigateByUrl('/login');
return;
}
const currentUser$: Observable<User> = this.userService.currentUser.pipe(take(1));
this._currentUser = currentUser$.subscribe((userData: User) => {
this.canModify = userData.role === 'Admin';
});
});
this.loadAeronefs();
this.loadCanopies();
this.loadDropzones();
}
loadAeronefs() {
const aeronefs$: Observable<Array<AeronefAggregate>> = this.aeronefsService.getAll();
this._aeronefs = aeronefs$.subscribe((aggregate: Array<AeronefAggregate>) => {
this.aeronefAggregate = aggregate;
this.aeronefsCount = aggregate.length;
console.log(this.aeronefs);
console.log(this.aeronefsCount);
});
}
loadCanopies() {
const canopies$: Observable<Array<CanopyAggregate>> = this.canopiesService.getAll();
this._canopies = canopies$.subscribe((aggregate: Array<CanopyAggregate>) => {
this.canopyAggregate = aggregate;
this.canopiesCount = aggregate.length;
// console.log(this.canopies);
// console.log(this.canopiesCount);
});
}
loadDropzones() {
const dropzones$: Observable<Array<DropZoneAggregate>> = this.dropzonesService.getAll();
this._dropzones = dropzones$.subscribe((aggregate: Array<DropZoneAggregate>) => {
this.dropzoneAggregate = aggregate;
this.dropzonesCount = aggregate.length;
// console.log(this.dropzones);
// console.log(this.dropzonesCount);
});
}
ngOnDestroy() {
this._aeronefs.unsubscribe();
this._canopies.unsubscribe();
this._dropzones.unsubscribe();
}
private _resetErrors(): void {
this.errors = { errors: {} };
}
}