Page MenuHomec4science

jury.component.ts
No OneTemporary

File Metadata

Created
Sat, May 4, 14:07

jury.component.ts

import {Component, OnInit, ViewChild} from '@angular/core';
import {AuthenticationService} from '../_services';
import {Router} from '@angular/router';
import {PilotsService} from '../_services/pilots.service';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
import {animate, state, style, transition, trigger} from '@angular/animations';
@Component({
selector: 'app-jury',
templateUrl: './jury.component.html',
styleUrls: ['./jury.component.css'],
animations: [
trigger('detailExpand', [
state('collapsed', style({height: '0px', minHeight: '0'})),
state('expanded', style({height: '*'})),
transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
]),
],
})
export class JuryComponent implements OnInit {
columnsToDisplay = ['pilotId', 'nickname', 'seat', 'run', 'race']
expandedElement: any | null;
dataSource: MatTableDataSource<any>;
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
@ViewChild(MatSort, {static: true}) sort: MatSort;
ngOnInit() {
if (this.authenticationService.currentUserValue.role != 'jury' && this.authenticationService.currentUserValue.role != 'admin') {
this.router.navigate(['home']);
} else {
if (this.pilotService.passedPilots == undefined) {
this.pilotService.getPassedPilots().subscribe(data => {
this.pilotService.passedPilots = data;
this.updateMatTableDataSource();
});
} else {
this.updateMatTableDataSource();
}
}
}
constructor(private router: Router, private authenticationService: AuthenticationService, private pilotService: PilotsService) {
}
/**
* Update the data source for passed pilots table
*/
updateMatTableDataSource() {
this.dataSource = new MatTableDataSource(this.pilotService.passedPilots);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
/**
* Apply a filter for passed pilots table
* @param filterValue
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}
/**
* charge next run from API
*/
nextRun() {
this.pilotService.updateNewPilots();
}
}

Event Timeline