regroupement du calendrier avec le paramètre mode des opérations

This commit is contained in:
Vincent BENOIT
2022-12-01 11:41:07 +01:00
parent 14c8111867
commit b20e9bf059
3 changed files with 23 additions and 62 deletions

View File

@@ -1,7 +1,7 @@
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 { Scheduler, Horaire, Day } from '../../../../models/scheduler.model';
import { Parameters } from '../../../../models/parameters.model';
import { ToastrService } from 'ngx-toastr';
import { Observable, throwError } from 'rxjs';
@@ -13,48 +13,25 @@ import { catchError, map, startWith } from 'rxjs/operators';
styleUrls: ['./hours.component.css']
})
export class HoursComponent implements OnInit {
schedule:Scheduler[];
schedule:Day[];
isProcessing:boolean = true;
schedCols:number = 0;
schedRows:number = 0;
colorFlag:string = 'red';
defaultOp:string = 'Manuel ON';
operations:string[] = ['Manuel ON', 'Manuel OFF', 'Horaires'];
num_auto:string = "";
tone_duration:number = 0;
dtmf_code:string = "";
dtmf_duration:number = 0;
pinChecked:boolean = false;
pinNumber:string = "";
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;
}, err => {
if(err.status == 401) {
this.router.navigateByUrl("/login");
} else {
this.toast.error(err.error.description);
}
this.isProcessing = false;
}
);
this.bs.retreiveParams().subscribe(
(data:Parameters) => {
this.num_auto = data.num_autorized;
this.tone_duration = data.tone_duration;
this.dtmf_code = data.dtmf_code;
this.dtmf_duration = data.dtmf_duration;
this.defaultOp = data.operation;
this.pinChecked = data.pin_actif;
this.pinNumber = data.code_pin;
this.bs.retreiveScheduler().subscribe(
(datas:Scheduler) => {
this.schedule = datas.days;
this.defaultOp = datas.mode;
this.schedCols = Object.keys(datas.days).length;
this.schedRows = Object.keys(datas.days[0].horaires).length;
this.isProcessing = false;
}, err => {
if(err.status == 401) {
@@ -68,23 +45,11 @@ export class HoursComponent implements OnInit {
}
onUpdate(): void {
let params:Parameters = {operation:'',
pin_actif:false,
code_pin:'',
num_autorized:'',
tone_duration:0,
dtmf_code:'',
dtmf_duration:0};
params.operation = this.defaultOp;
params.pin_actif = this.pinChecked;
params.code_pin = this.pinNumber;
params.num_autorized = this.num_auto;
params.tone_duration = this.tone_duration;
params.dtmf_code = this.dtmf_code;
params.dtmf_duration = this.dtmf_duration;
this.bs.updateParams(params).subscribe(
data => {
this.bs.updateSchedulers(this.schedule).subscribe(
let sched:Scheduler = {
mode:this.defaultOp,
days:this.schedule
};
this.bs.updateScheduler(sched).subscribe(
data => {
this.toast.success("Mise à jour des horaires réussie");
}, err => {
@@ -95,14 +60,6 @@ export class HoursComponent implements OnInit {
}
}
);
}, err => {
if(err.status == 401) {
this.router.navigateByUrl("/login");
} else {
this.toast.error(err.error.description);
}
}
);
}
updateCell(col: number, row: number): void {

View File

@@ -3,7 +3,12 @@ export interface Horaire {
state:number;
}
export interface Scheduler {
export interface Day {
name:string;
horaires:Horaire[];
}
export interface Scheduler {
mode:string;
days:Day[];
}

View File

@@ -95,7 +95,7 @@ export class BackendService {
return this.http.post<any>(host+"/api/configurateur/update_params", val, options);
}
retreiveSchedulers():Observable<Scheduler[]> {
retreiveScheduler():Observable<Scheduler> {
let host=environment.host;
const options = {
headers: new HttpHeaders({
@@ -103,10 +103,10 @@ export class BackendService {
}),
withCredentials: true
};
return this.http.get<Scheduler[]>(host+"/api/configurateur/scheduler", options);
return this.http.get<Scheduler>(host+"/api/configurateur/scheduler", options);
}
updateSchedulers(val:Scheduler[]):Observable<any> {
updateScheduler(val:Scheduler):Observable<any> {
let host=environment.host;
const options = {
headers: new HttpHeaders({
@@ -114,7 +114,6 @@ export class BackendService {
}),
withCredentials: true
};
return this.http.post<any>(host+"/api/configurateur/update_schedulers", val, options);
}