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
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { BackendService } from '../../../../services/backend/backend.service'; 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 { Parameters } from '../../../../models/parameters.model';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
@@ -13,48 +13,25 @@ import { catchError, map, startWith } from 'rxjs/operators';
styleUrls: ['./hours.component.css'] styleUrls: ['./hours.component.css']
}) })
export class HoursComponent implements OnInit { export class HoursComponent implements OnInit {
schedule:Scheduler[]; schedule:Day[];
isProcessing:boolean = true; isProcessing:boolean = true;
schedCols:number = 0; schedCols:number = 0;
schedRows:number = 0; schedRows:number = 0;
colorFlag:string = 'red'; colorFlag:string = 'red';
defaultOp:string = 'Manuel ON'; defaultOp:string = 'Manuel ON';
operations:string[] = ['Manuel ON', 'Manuel OFF', 'Horaires']; 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, constructor( private bs:BackendService,
private router:Router, private router:Router,
private toast:ToastrService ) { } private toast:ToastrService ) { }
ngOnInit(): void { ngOnInit(): void {
this.bs.retreiveSchedulers().subscribe( this.bs.retreiveScheduler().subscribe(
(datas:Scheduler[]) => { (datas:Scheduler) => {
this.schedule = datas; this.schedule = datas.days;
this.schedCols = Object.keys(datas).length; this.defaultOp = datas.mode;
this.schedRows = Object.keys(datas[0].horaires).length; this.schedCols = Object.keys(datas.days).length;
}, err => { this.schedRows = Object.keys(datas.days[0].horaires).length;
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.isProcessing = false; this.isProcessing = false;
}, err => { }, err => {
if(err.status == 401) { if(err.status == 401) {
@@ -68,33 +45,13 @@ export class HoursComponent implements OnInit {
} }
onUpdate(): void { onUpdate(): void {
let params:Parameters = {operation:'', let sched:Scheduler = {
pin_actif:false, mode:this.defaultOp,
code_pin:'', days:this.schedule
num_autorized:'', };
tone_duration:0, this.bs.updateScheduler(sched).subscribe(
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 => { data => {
this.bs.updateSchedulers(this.schedule).subscribe( this.toast.success("Mise à jour des horaires réussie");
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);
}
}
);
}, err => { }, err => {
if(err.status == 401) { if(err.status == 401) {
this.router.navigateByUrl("/login"); this.router.navigateByUrl("/login");
+6 -1
View File
@@ -3,7 +3,12 @@ export interface Horaire {
state:number; state:number;
} }
export interface Scheduler { export interface Day {
name:string; name:string;
horaires:Horaire[]; horaires:Horaire[];
} }
export interface Scheduler {
mode:string;
days:Day[];
}
+3 -4
View File
@@ -95,7 +95,7 @@ export class BackendService {
return this.http.post<any>(host+"/api/configurateur/update_params", val, options); return this.http.post<any>(host+"/api/configurateur/update_params", val, options);
} }
retreiveSchedulers():Observable<Scheduler[]> { retreiveScheduler():Observable<Scheduler> {
let host=environment.host; let host=environment.host;
const options = { const options = {
headers: new HttpHeaders({ headers: new HttpHeaders({
@@ -103,10 +103,10 @@ export class BackendService {
}), }),
withCredentials: true 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; let host=environment.host;
const options = { const options = {
headers: new HttpHeaders({ headers: new HttpHeaders({
@@ -114,7 +114,6 @@ export class BackendService {
}), }),
withCredentials: true withCredentials: true
}; };
return this.http.post<any>(host+"/api/configurateur/update_schedulers", val, options); return this.http.post<any>(host+"/api/configurateur/update_schedulers", val, options);
} }