diff --git a/src/app/core/interfaces/tpe.ts b/src/app/core/interfaces/tpe.ts index d0325b8..0d38959 100644 --- a/src/app/core/interfaces/tpe.ts +++ b/src/app/core/interfaces/tpe.ts @@ -16,6 +16,7 @@ export interface TpeDevice { versionOs: string; adresseIp: string; adresseMac: string; + assigned: boolean; agentConnecteId: string; derniereConnexionAgent: string; derniereDeconnexionAgent: string; diff --git a/src/app/core/services/agent.ts b/src/app/core/services/agent.ts index f28d7d0..e07d230 100644 --- a/src/app/core/services/agent.ts +++ b/src/app/core/services/agent.ts @@ -229,9 +229,14 @@ export class AgentService { - assigner(tpeId: string, agentId:string):Observable{ - return this.http.post(`${this.apiUrl}/${agentId}/terminaux/${tpeId}`, - {Headers: this.getNgrokHeaders()}).pipe(map(res=> res), + assigner(tpeIds: string[], agentId:string):Observable{ + const payload = { + terminalIds: [ + ...tpeIds + ] + } + return this.http.put(`${this.apiUrl}/${agentId}/terminaux`, + payload, {headers: this.getNgrokHeaders()}).pipe(map(res=> res), catchError((err)=>{ console.error(err); return of(undefined); diff --git a/src/app/dashboard/pages/agents/agents.html b/src/app/dashboard/pages/agents/agents.html index 4c012be..24dba88 100644 --- a/src/app/dashboard/pages/agents/agents.html +++ b/src/app/dashboard/pages/agents/agents.html @@ -370,7 +370,7 @@
Annuler -
diff --git a/src/app/dashboard/pages/agents/agents.ts b/src/app/dashboard/pages/agents/agents.ts index be68cbf..b77c6a5 100644 --- a/src/app/dashboard/pages/agents/agents.ts +++ b/src/app/dashboard/pages/agents/agents.ts @@ -458,25 +458,45 @@ export class AgentsPage { confirmAssignTpe() { const agent = this.assigningAgent(); - const tpeId = this.selectedTpeId(); - if (!agent || tpeId.length === 0) { - alert('Veuillez sélectionner un TPE'); + const tpeId = this.selectedTpeId().map(id=> id); + if (!agent) { + toast.error('Veuillez sélectionner un TPE'); return; } - forkJoin(this.selectedTpeId().map(id=> this.api.assigner(id, agent.id))).subscribe( - { - next:()=>{ - this.assignTpeModalOpen.set(false); - this.assigningAgent.set(undefined); - this.selectedTpeId.set([]); - toast.success(`Tpe affecté à l'agent avec succès1`) - }, - error: (err)=>{ - console.error(err); - } + this.api.assigner(tpeId, agent.id).subscribe({ + next:()=>{ + this.assignTpeModalOpen.set(false); + this.assigningAgent.set(undefined); + this.selectedTpeId.set([]); + toast.success("Termiaux affectés avec succès!"); + const params = { + page: this.page(), + size: this.size(), + search: this.search(), + sortKey: this.sort().key, + sortDir: this.sort().dir as SortDir, + }; + this.fetch(params); + }, + error:()=>{ + console.error("Une érreur s'est produite") } - ) + }) + + // forkJoin(this.selectedTpeId().map(id=> this.api.assigner(id, agent.id))).subscribe( + // { + // next:()=>{ + // this.assignTpeModalOpen.set(false); + // this.assigningAgent.set(undefined); + // this.selectedTpeId.set([]); + // toast.success(`Tpe affecté à l'agent avec succès1`) + // }, + // error: (err)=>{ + // console.error(err); + // } + // } + // ) // // Assign TPE to agent // this.tpeSvc.assigner(tpeId, agent.id).subscribe({ diff --git a/src/app/dashboard/pages/courses/courses.ts b/src/app/dashboard/pages/courses/courses.ts index aeb3060..18aec51 100644 --- a/src/app/dashboard/pages/courses/courses.ts +++ b/src/app/dashboard/pages/courses/courses.ts @@ -497,8 +497,8 @@ export class Course { onResultatConfirm() { const c = this.selectedCourseForResultat(); if (!c) return; - const resultat = this.resultatsMap().get(c.id); + if (!resultat) { toast.error('Aucun résultat à confirmer'); return; diff --git a/src/app/dashboard/pages/tpe-select/tpe-select.ts b/src/app/dashboard/pages/tpe-select/tpe-select.ts index d4230b8..500bf28 100644 --- a/src/app/dashboard/pages/tpe-select/tpe-select.ts +++ b/src/app/dashboard/pages/tpe-select/tpe-select.ts @@ -67,8 +67,6 @@ export class TpeSelect { ngOnInit() { // Initialiser les TPE sélectionnés si fournis this.selectedIds.set(new Set(this.selected)); - - } private loadTpes(params:ListParams) { @@ -77,11 +75,11 @@ export class TpeSelect { next: (res) => { // Filtrer : TPE non assignés ou déjà assignés à cet agent // console.log(res.content); - // const available = res.content.filter( - // (t) => - // !t.agentConnecteId || t.agentConnecteId === this.agent?.id - // ); - this.tpes.set(res.content); + const available = res.content.filter( + (t) => + !t.assigned || t.agentConnecteId === this.agent?.id + ); + this.tpes.set(available); this.total.set(res.pageable.total); this.loading.set(false); }, @@ -94,10 +92,10 @@ export class TpeSelect { toggleTpe(tpe: TpeDevice) { const current = new Set(this.selectedIds()); - if (current.has(tpe.id)) { - current.delete(tpe.id); + if (current.has(String(tpe.id))) { + current.delete(String(tpe.id)); } else { - current.add(tpe.id); + current.add(String(tpe.id)); } this.selectedIds.set(current); this.selectionChange.emit(Array.from(current)); diff --git a/src/app/dashboard/pages/tpe/tpe.html b/src/app/dashboard/pages/tpe/tpe.html index fed2f12..572a239 100644 --- a/src/app/dashboard/pages/tpe/tpe.html +++ b/src/app/dashboard/pages/tpe/tpe.html @@ -137,7 +137,7 @@ [total]="total()" [page]="page()" [perPage]="perPage()" - (pageChange)="page.set($event)" + (pageChange)="page.set($event - 1)" (perPageChange)="perPage.set($event)" > diff --git a/src/app/dashboard/pages/tpe/tpe.ts b/src/app/dashboard/pages/tpe/tpe.ts index 56d344b..e9f4a66 100644 --- a/src/app/dashboard/pages/tpe/tpe.ts +++ b/src/app/dashboard/pages/tpe/tpe.ts @@ -28,6 +28,7 @@ import { forkJoin, Subject } from 'rxjs'; import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; import { toast } from 'ngx-sonner'; import { PointsVenteService } from 'src/app/core/services/points-vente'; +import { PointVente } from 'src/app/core/interfaces/points-ventes'; @Component({ standalone: true, @@ -76,6 +77,8 @@ export class TpePage implements OnInit { assignmentStats = signal({ total: 0, assignes: 0, disponibles: 0 }); statsLoading = signal(false); + pointDeVenteMap = signal>(new Map()); + // Live search private searchSubject = new Subject(); @@ -102,21 +105,10 @@ export class TpePage implements OnInit { key: 'pointDeVenteId', label: 'Point de vente', sortable: true, - cell:(p) => { - let pointVente = signal(''); - this.pointVenteService.getById(p.pointDeVenteId).subscribe({ - next: (pdv)=>{ - if(!pdv || pdv === undefined){ - pointVente.set("Aucun point") - return; - }; - pointVente.set(`${pdv.ville}/${pdv.adresse}`) - }, - error:(err)=>{ - pointVente.set('Aucun point') - } - }) - return pointVente(); + cell: (t) => { + const pdv = this.pointDeVenteMap().get(String(t.pointDeVenteId)); + if (!pdv) return 'Pas de point de vente'; + return `${pdv.ville}/${pdv.adresse}`; }, }, { key: 'versionLogicielle', label: 'Version', sortable: true }, @@ -127,7 +119,7 @@ export class TpePage implements OnInit { key: 'assigne', label: 'Assigné à', cell: (d) => { - if (!d.agentConnecteId) { + if (!d.assigned) { return 'Non assigné'; } // a rectifier apres avec les données des agents! @@ -296,10 +288,32 @@ export class TpePage implements OnInit { }); } else { // Normal list with pagination + const map: Map = new Map(); this.api.list(params).subscribe({ next: (res) => { this.rows.set(res.content); this.total.set(res.pageable.total); + const requests = res.content + .filter((t) => t.pointDeVenteId) + .map((t) => this.pointVenteService.getById(t.pointDeVenteId!)); + forkJoin(requests).subscribe({ + next: (pdvs) => { + res.content.forEach((t) => { + if (!t.pointDeVenteId) return; + + const pdv = pdvs.find((p) => p?.id === t.pointDeVenteId); + if (!pdv) return; + + map.set(String(t.pointDeVenteId), pdv); + }); + // ✅ SET ICI seulement + this.pointDeVenteMap.set(map); + this.loading.set(false); + }, + error: () => this.loading.set(false), + }); + + this.pointDeVenteMap.set(map); this.loading.set(false); }, error: () => { diff --git a/src/app/shared/forms/course-form/course-form.html b/src/app/shared/forms/course-form/course-form.html index 26585c7..a48ff34 100644 --- a/src/app/shared/forms/course-form/course-form.html +++ b/src/app/shared/forms/course-form/course-form.html @@ -25,6 +25,7 @@ >
Statut - + @for (s of courseStatus; track s.value) { {{ s.label }} } @@ -281,6 +291,7 @@ > Enregistrer - + -->
diff --git a/src/app/shared/forms/resultat-form/resultat-form.ts b/src/app/shared/forms/resultat-form/resultat-form.ts index fa63816..87289ba 100644 --- a/src/app/shared/forms/resultat-form/resultat-form.ts +++ b/src/app/shared/forms/resultat-form/resultat-form.ts @@ -5,7 +5,7 @@ import { ZardFormModule } from '@shared/components/form/form.module'; import { ZardSelectComponent } from '@shared/components/select/select.component'; import { ZardSelectItemComponent } from '@shared/components/select/select-item.component'; import { Course, CourseType } from 'src/app/core/interfaces/course'; -import { Resultat } from 'src/app/core/interfaces/resultat'; +import { Resultat, ResultatStatut } from 'src/app/core/interfaces/resultat'; type PlaceRow = { picks: FormArray> }; type ResultatShape = { places: FormArray> }; @@ -65,12 +65,12 @@ export class ResultatForm { return this.resultat ? 'PROVISOIRE' : 'EN_ATTENTE'; }); - canValidate(): boolean { - return this.statut() === 'EN_ATTENTE'; - } + // canValidate(): boolean { + // return this.statut() === 'PROVISOIRE'; + // } canConfirm(): boolean { - return this.statut() === 'PROVISOIRE'; + return this.statut() === 'PROVISOIRE' || this.statut() === 'OFFICIEL'; } // Helper methods for template @@ -228,6 +228,7 @@ export class ResultatForm { }); ngOnInit() { + this.seed(); // Watch for changes to auto-populate places when ex-aequo is detected this.setupAutoPopulate(); @@ -549,6 +550,10 @@ export class ResultatForm { } } + if(this.statut()==='OFFICIEL'){ + return false; + } + return true; } diff --git a/src/environments/environment.development.ts b/src/environments/environment.development.ts index 79ead1f..0a134e1 100644 --- a/src/environments/environment.development.ts +++ b/src/environments/environment.development.ts @@ -1,5 +1,5 @@ export const environment = { production: false, - apiBaseUrl: 'http://192.168.40.204:8080', + apiBaseUrl: 'http://192.168.40.212:8080', depouillementBaseUrl: 'http://192.168.1.235:8383' };