65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { BackendService } from '../../../../services/backend/backend.service';
|
|
import { Scheduler, Horaire } from '../../../../models/scheduler.model';
|
|
import { ToastrService } from 'ngx-toastr';
|
|
import { Observable, throwError } from 'rxjs';
|
|
import { catchError, map, startWith } from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'app-hours',
|
|
templateUrl: './hours.component.html',
|
|
styleUrls: ['./hours.component.css']
|
|
})
|
|
export class HoursComponent implements OnInit {
|
|
schedule:Scheduler[];
|
|
isProcessing:boolean = true;
|
|
schedCols:number = 0;
|
|
schedRows:number = 0;
|
|
colorFlag:string = 'red';
|
|
|
|
constructor( private bs:BackendService,
|
|
private router:Router,
|
|
private toast:ToastrService ) { }
|
|
|
|
ngOnInit(): void {
|
|
this.bs.retreiveSchedulers().subscribe(
|
|
(datas:Scheduler[]) => {
|
|
this.schedule = datas;
|
|
this.schedCols = Object.keys(datas).length;
|
|
this.schedRows = Object.keys(datas[0].horaires).length;
|
|
this.isProcessing = false;
|
|
}, err => {
|
|
if(err.status == 401) {
|
|
this.router.navigateByUrl("/login");
|
|
} else {
|
|
this.toast.error(err.error.description);
|
|
}
|
|
this.isProcessing = false;
|
|
}
|
|
);
|
|
}
|
|
|
|
onUpdate(): void {
|
|
this.bs.updateSchedulers(this.schedule).subscribe(
|
|
data => {
|
|
this.toast.success("Mise à jour des horaires réussie");
|
|
}, err => {
|
|
if(err.status == 401) {
|
|
this.router.navigateByUrl("/login");
|
|
} else {
|
|
this.toast.error(err.error.description);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
updateCell(col: number, row: number): void {
|
|
if(this.schedule[col].horaires[row].state == 1) {
|
|
this.schedule[col].horaires[row].state = 0;
|
|
} else {
|
|
this.schedule[col].horaires[row].state = 1;
|
|
}
|
|
}
|
|
}
|