agent and tpe save done

This commit is contained in:
OnlyPapy98
2026-01-06 14:07:09 +01:00
parent 95095016d2
commit 0ae7fa316e
33 changed files with 1910 additions and 525 deletions

View File

@@ -26,6 +26,7 @@ import { AgentFullForm } from '@shared/forms/agent-full-form/agent-full-form';
import { forkJoin, of } from 'rxjs';
import { switchMap, catchError } from 'rxjs/operators';
import { toast } from 'ngx-sonner';
import { AgentForm } from '@shared/forms/agent-form/agent-form';
@Component({
standalone: true,
@@ -43,7 +44,7 @@ import { toast } from 'ngx-sonner';
ZardSelectComponent,
ZardSelectItemComponent,
ZardFormModule,
AgentFullForm,
AgentForm
],
})
export class AgentsPage {
@@ -111,7 +112,7 @@ export class AgentsPage {
) {
// Preload TPE maps for display
this.tpeSvc
.list({ page: 1, size: 200, search: '', sortKey: 'imei', sortDir: 'asc' } as any)
.list({ page: 1, size: 200, search: '', sortKey: 'id', sortDir: 'asc' } as any)
.subscribe((res) => {
const tpes = res.content as TpeDevice[];
this.rebuildTpeMaps(tpes);
@@ -138,6 +139,7 @@ export class AgentsPage {
this.loading.set(true);
this.api.list(params).subscribe({
next: (res) => {
console.log(res.content);
this.rows.set(res.content);
this.total.set(res.pageable.total);
this.loading.set(false);
@@ -166,7 +168,7 @@ export class AgentsPage {
this.agentTpesMap.clear();
tpes.forEach((t) => {
this.tpeMap.set(t.id, t);
const agentId = t.agent?.id;
const agentId = t.agentConnecteId;
if (agentId) {
const list = this.agentTpesMap.get(agentId) || [];
list.push(t);
@@ -417,14 +419,14 @@ export class AgentsPage {
const agentTpeIds = new Set(currentAgentTpes.map((t) => t.id));
// Load available TPEs (DISPONIBLE or VALIDE status)
forkJoin([this.tpeSvc.getByStatut('DISPONIBLE'), this.tpeSvc.getByStatut('VALIDE')]).subscribe({
forkJoin([this.tpeSvc.getByStatut('ACTIF'), this.tpeSvc.getByStatut('ACTIF')]).subscribe({
next: ([disponibleTpes, valideTpes]) => {
// Combine and filter: only show TPEs that are not assigned to any agent AND not already assigned to this agent
const allTpes = [...disponibleTpes, ...valideTpes];
const available = allTpes.filter(
(t) =>
!t.assigne &&
(t.statut === 'DISPONIBLE' || t.statut === 'VALIDE') &&
!t.agentConnecteId &&
(t.statut === 'ACTIF') &&
!agentTpeIds.has(t.id)
);
// Remove duplicates