Ajout des sources
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
|
||||
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 { environment } from 'src/environments/environment';
|
||||
import data from 'src/jumps.json';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [JumpTableComponent],
|
||||
selector: 'huapp-logbook',
|
||||
templateUrl: './logbook.component.html',
|
||||
styleUrls: ['./logbook.component.scss']
|
||||
})
|
||||
export class LogbookComponent implements OnInit, OnDestroy {
|
||||
private _currentUser: Subscription = new Subscription();
|
||||
private _data: Subscription = new Subscription();
|
||||
errors!: Errors;
|
||||
title = 'Carnet de saut';
|
||||
listTitle = 'Liste des sauts';
|
||||
listConfig: JumpListConfig = { type: 'all', filters: {} };
|
||||
refreshInterval: number = environment.refresh_interval;
|
||||
isAuthenticated = false;
|
||||
isUser = true;
|
||||
canModify = false;
|
||||
jump: Jump = {} as Jump;
|
||||
currentUser: User = {} as User;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private jumpsService: JumpsService,
|
||||
private userService: UserService
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
//this.importJumps();
|
||||
const data$: Observable<any> = this.route.data;
|
||||
this._data = data$.subscribe((data: { isAuthenticated: boolean }) => {
|
||||
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';
|
||||
});
|
||||
});
|
||||
}
|
||||
importJumps() {
|
||||
try {
|
||||
data.forEach((entry) => {
|
||||
Object.assign(this.jump, entry);
|
||||
//console.log(this.jump);
|
||||
this.jumpsService.save(this.jump)
|
||||
.pipe(take(1))
|
||||
.subscribe({
|
||||
next: (jump) => {
|
||||
console.log(`Le saut n°${jump.numero} a été ajouté !`, 'OK');
|
||||
},
|
||||
error: (err) => {
|
||||
console.log(`Le saut n\'a pas été ajouté !`, 'Error', err);
|
||||
this.errors = err;
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this._currentUser.unsubscribe();
|
||||
this._data.unsubscribe();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user