Renommage du composant 'Home' en 'Dashboard'

This commit is contained in:
Julien Gautier
2023-10-03 16:28:03 +02:00
parent 340228e698
commit 2ccc9fc858
12 changed files with 65 additions and 63 deletions
@@ -0,0 +1,136 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Data, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
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 { 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 'src/app/components/shared/dashboard-components';
@Component({
standalone: true,
imports: [
ShowAuthedDirective,
AeronefsComponent, AeronefsBarComponent,
CanopyModelsComponent, CanopySizesComponent,
DropZonesComponent, DropZonesBarComponent,
JumpsByMonthComponent
],
selector: 'huapp-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent 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<AeronefByImat>;
aeronefs!: Array<Aeronef>;
aeronefsCount = 0;
canopyAggregate!: Array<CanopyModelBySize>;
canopies!: Array<Canopy>;
canopiesCount = 0;
dropzoneAggregate!: Array<DropZoneByYear>;
dropzones!: Array<DropZone>;
dropzonesCount = 0;
constructor(
private route: ActivatedRoute,
private router: Router,
private titleService: Title,
private userService: UserService
/*
private aeronefsService: AeronefsService,
private canopiesService: CanopiesService,
private dropzonesService: DropZonesService
*/
) {
this._resetErrors();
}
ngOnInit() {
this.titleService.setTitle(this.title);
const data$: Observable<Data> = this.route.data.pipe(take(1));
this._data = data$.subscribe((data: Data) => {
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.canModify = userData.role === 'Admin';
});
});
/*
this._loadAeronefs();
this._loadCanopies();
this._loadDropzones();
*/
}
ngOnDestroy() {
this._currentUser.unsubscribe();
this._data.unsubscribe();
/*
this._aeronefs.unsubscribe();
this._canopies.unsubscribe();
this._dropzones.unsubscribe();
*/
}
private _resetErrors(): void {
this.errors = { errors: {} };
}
/*
private _loadAeronefs(): void {
const aeronefs$: Observable<Array<AeronefByImat>> = this.aeronefsService.getAllByImat();
this._aeronefs = aeronefs$.subscribe((aggregate: Array<AeronefByImat>) => {
this.aeronefAggregate = aggregate;
this.aeronefsCount = aggregate.length;
console.log(this.aeronefAggregate);
console.log(this.aeronefsCount);
});
}
private _loadCanopies(): void {
const canopies$: Observable<Array<CanopyModelBySize>> = this.canopiesService.getAllModelBySize();
this._canopies = canopies$.subscribe((aggregate: Array<CanopyModelBySize>) => {
this.canopyAggregate = aggregate;
this.canopiesCount = aggregate.length;
console.log(this.canopyAggregate);
console.log(this.canopiesCount);
});
}
private _loadDropzones(): void {
const dropzones$: Observable<Array<DropZoneByYear>> = this.dropzonesService.getAllByDate();
this._dropzones = dropzones$.subscribe((aggregate: Array<DropZoneByYear>) => {
this.dropzoneAggregate = aggregate;
this.dropzonesCount = aggregate.length;
console.log(this.dropzoneAggregate);
console.log(this.dropzonesCount);
});
}
*/
}