agent done

This commit is contained in:
OnlyPapy98
2026-01-07 16:06:54 +01:00
parent 0ae7fa316e
commit d7bcbce50d
16 changed files with 658 additions and 425 deletions

View File

@@ -27,6 +27,7 @@ import { ZardFormModule } from '@shared/components/form/form.module';
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';
@Component({
standalone: true,
@@ -53,10 +54,10 @@ export class TpePage implements OnInit {
total = signal(0);
loading = signal(false);
page = signal(1);
page = signal(0);
perPage = signal(10);
search = signal('');
sort = signal<SortState>({ key: 'imei', dir: 'asc' });
sort = signal<SortState>({ key: 'id', dir: 'asc' });
selectedStatut = signal<TpeStatus | null>(null);
modalOpen = signal(false);
@@ -96,11 +97,31 @@ export class TpePage implements OnInit {
}
cols: TableColumn<TpeDevice>[] = [
{ key: 'imei', label: 'IMEI', sortable: true },
{ key: 'serial', label: 'N° de Série', sortable: true },
{ key: 'type', label: 'Type', sortable: true },
{ key: 'marque', label: 'Marque', sortable: true },
{ key: 'modele', label: 'Modèle', sortable: true },
{ key: 'numeroSerie', label: 'Numéro de série', sortable: true },
{
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();
},
},
{ key: 'versionLogicielle', label: 'Version', sortable: true },
{ key: 'typeTerminal', label: 'Type', sortable: true },
{ key: 'systemeExploitation', label: 'Sytème', sortable: true },
{ key: 'statut', label: 'Statut', sortable: true, cell: (d) => this.formatStatut(d.statut) },
{
key: 'assigne',
@@ -136,12 +157,13 @@ export class TpePage implements OnInit {
},
];
allStatuses: TpeStatus[] = [
'ACTIF',
'HORS_SERVICE'
];
allStatuses: TpeStatus[] = ['ACTIF', 'HORS_SERVICE'];
constructor(private api: TpeService, private agentService: AgentService) {
constructor(
private api: TpeService,
private agentService: AgentService,
private pointVenteService: PointsVenteService
) {
effect(() => {
// Only trigger fetch when page, perPage, or sort changes (not search - handled by searchSubject)
const searchValue = this.search();
@@ -321,7 +343,8 @@ export class TpePage implements OnInit {
}
onUpdateStatut(row: TpeDevice, newStatut: TpeStatus) {
if (!confirm(`Changer le statut de ${row.numeroSerie} vers ${this.formatStatut(newStatut)} ?`)) return;
if (!confirm(`Changer le statut de ${row.numeroSerie} vers ${this.formatStatut(newStatut)} ?`))
return;
this.api.updateStatut(row.id, newStatut).subscribe({
next: () => {
this.fetch({
@@ -435,7 +458,7 @@ export class TpePage implements OnInit {
: this.api.create(payload as Omit<TpeDevice, 'id'>);
req$.subscribe({
next: (result) => {
toast.success('Tpe créé avec succès!')
toast.success('Tpe créé avec succès!');
// For update, check if result is valid (update can return undefined on error)
if (current?.id && !result) {
console.error('Update failed - result is undefined');