Compare commits

..

2 Commits

Author SHA1 Message Date
Smile df24e33e4b Merge remote-tracking branch 'origin/master' 2024-08-20 18:13:39 +01:00
Smile d692e969b7 commit 2024-08-20 18:12:50 +01:00
9 changed files with 165 additions and 34 deletions

View File

@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class ErrorModule { }

View File

@ -1,15 +1,15 @@
<div> <div>
<div> <div>
<label>Marque</label> <label>Marque</label><br>
<input [(ngModel)]="vehicle.mark" type="text" pInputText /> <input [(ngModel)]="vehicle.mark" type="text" pInputText />
<br> <br><br>
<label>Modele</label> <label>Modele</label><br>
<input [(ngModel)]="vehicle.model" type="text" pInputText /> <input [(ngModel)]="vehicle.model" type="text" pInputText />
<br><br>
<label>Matricule</label> <label>Matricule</label><br>
<input [(ngModel)]="vehicle.matricule" type="text" pInputText /> <input [(ngModel)]="vehicle.matricule" type="text" pInputText />
</div> </div>
<br><br>
<button (click)="save()" pButton type="button" label="Enregistrer"></button> <button (click)="save()" pButton type="button" label="Enregistrer"></button>
</div> </div>

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {VehicleService} from "../../service/vehicle.service"; import {VehicleService} from "../../service/vehicle.service";
import {Router} from "@angular/router"; import {ActivatedRoute, Router} from "@angular/router";
@Component({ @Component({
selector: 'app-vehicle-edit', selector: 'app-vehicle-edit',
@ -10,16 +10,45 @@ import {Router} from "@angular/router";
export class VehicleEditComponent implements OnInit { export class VehicleEditComponent implements OnInit {
vehicle : any = {}; vehicle : any = {};
id: string = "0";
constructor(private vehicleService: VehicleService, constructor(private vehicleService: VehicleService,
private activatedRoute : ActivatedRoute,
private router: Router) { } private router: Router) { }
ngOnInit(): void { ngOnInit(): void {
this.id = this.activatedRoute.snapshot.params['id'];
if(this.id && this.id != "0"){
this.getById();
}
} }
save() { getById(): void{
this.vehicleService.create(this.vehicle).subscribe( { this.vehicleService.getById(this.id).subscribe({
next :(res)=>{
if(res.success){
this.vehicle = res.data;
}
},
error:(err)=>{
}
})
}
save(): void {
if(this.id == "0"){
this.create(this.vehicle);
}else {
this.update(this.vehicle);
}
}
create(vehicle: any): void{
this.vehicleService.create(vehicle).subscribe( {
next: (res)=>{ next: (res)=>{
if(res.success){ if(res.success){
this.router.navigateByUrl("/app/vehicle").then(); this.router.navigateByUrl("/app/vehicle").then();
@ -27,4 +56,15 @@ export class VehicleEditComponent implements OnInit {
} }
}) })
} }
update(vehicle: any): void {
this.vehicleService.update(vehicle).subscribe( {
next: (res)=>{
if(res.success){
this.router.navigateByUrl("/app/vehicle").then();
}
}
})
}
} }

View File

@ -1,6 +1,18 @@
<div>
<div style="display: inline-flex">
<div style="">
Recherche <br>
<input type="text" pInputText [(ngModel)]="searchTerm" (ngModelChange)="search()" />
</div>
<div style="margin-left: 10px">Filtre pard ta</div>
</div>
</div>
<div style="text-align: right; margin-bottom :10px"> <div style="text-align: right; margin-bottom :10px">
<button (click)="edit()" pButton type="button" label="Ajouter un véhicule"></button> <button (click)="edit('0')" pButton type="button" label="Ajouter un véhicule"></button>
</div> </div>
<p-table [value]="vehicles" [tableStyle]="{'min-width': '50rem'}"> <p-table [value]="vehicles" [tableStyle]="{'min-width': '50rem'}">
@ -18,9 +30,9 @@
<td>{{vehicle.model}}</td> <td>{{vehicle.model}}</td>
<td>{{vehicle.matricule}}</td> <td>{{vehicle.matricule}}</td>
<td> <td>
<i class="pi pi-pencil" style="margin-right: 10px"></i> <i (click)="edit(product._id)" class="pi pi-pencil" style="margin-right: 10px"></i>
<i class="pi pi-trash" style="margin-right: 10px"></i> <i (click)="delete(product._id)" class="pi pi-trash" style="margin-right: 10px"></i>
<i class="pi pi-eye" style="margin-right: 10px"></i> <i (click)="view(product._id)" class="pi pi-eye" style="margin-right: 10px"></i>
</td> </td>
</tr> </tr>
</ng-template> </ng-template>

View File

@ -8,6 +8,13 @@ import {VehicleService} from "../../service/vehicle.service";
styleUrls: ['./vehicle-list.component.scss'] styleUrls: ['./vehicle-list.component.scss']
}) })
export class VehicleListComponent implements OnInit { export class VehicleListComponent implements OnInit {
//1. filter
searchTerm : string = "";
params : any = {};
//2. table
vehicles: any[] = []; vehicles: any[] = [];
constructor(private router: Router, constructor(private router: Router,
@ -15,11 +22,16 @@ export class VehicleListComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.getServices(); this.params.search = "";
this.params.fields = ["matricule", "mark", "model"];
this.params.page = 1;
this.params.limit = 5;
this.getVehicles();
} }
getServices() { getVehicles() {
this.vehicleService.getAll().subscribe({
this.vehicleService.getAll(this.params).subscribe({
next: (res) => { next: (res) => {
if (res.success) { if (res.success) {
this.vehicles = res.data; this.vehicles = res.data;
@ -28,16 +40,27 @@ export class VehicleListComponent implements OnInit {
}) })
} }
edit(): void { edit(_id: string): void {
/* this.router.navigateByUrl('/app/vehicle/edit/'+_id).then();
let vehicle : any = {}; }
vehicle.model = "RangeRoger"; view(_id: string): void {
vehicle.mark = "Sport"; this.router.navigateByUrl('/app/vehicle/view/'+_id).then();
vehicle.matricule = "535353";
this.vehicles.push(vehicle);
*/
this.router.navigateByUrl('/app/vehicle/edit').then();
} }
protected readonly visualViewport = visualViewport;
delete(_id: string): void {
this.vehicleService.delete(_id).subscribe({
next: (res)=>{
if(res.success){
this.getVehicles();
}
}
})
}
search() {
this.params.search = this.searchTerm;
this.getVehicles()
}
} }

View File

@ -1 +1,14 @@
<p>vehicle-view works!</p> <div>
<div>
<label>Marque</label><br>
<strong>{{vehicle.mark }}</strong>
<br><br>
<label>Modele</label><br>
{{vehicle.model}}
<br><br>
<label>Matricule</label><br>
{{vehicle.matricule}}
</div>
<br><br>
</div>

View File

@ -1,4 +1,6 @@
import { Component, OnInit } from '@angular/core'; import {ChangeDetectorRef, Component, OnInit} from '@angular/core';
import {VehicleService} from "../../service/vehicle.service";
import {ActivatedRoute, Router} from "@angular/router";
@Component({ @Component({
selector: 'app-vehicle-view', selector: 'app-vehicle-view',
@ -6,10 +8,39 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./vehicle-view.component.scss'] styleUrls: ['./vehicle-view.component.scss']
}) })
export class VehicleViewComponent implements OnInit { export class VehicleViewComponent implements OnInit {
vehicle : any = {};
id: string = "0";
constructor() { } constructor(private vehicleService: VehicleService,
private activatedRoute : ActivatedRoute,
private cdr: ChangeDetectorRef,
private router: Router) { }
ngOnInit(): void { ngOnInit(): void {
this.id = this.activatedRoute.snapshot.params['id'];
if(this.id && this.id != "0"){
this.getById();
} }
}
getById(): void{
this.vehicleService.getById(this.id).subscribe({
next :(res)=>{
if(res.success){
this.vehicle = res.data;
this.cdr.detectChanges();
}
},
error:(err)=>{
}
})
}
} }

View File

@ -10,8 +10,8 @@ export class VehicleService {
url: string = "vehicle" url: string = "vehicle"
constructor(private http: HttpClient) { } constructor(private http: HttpClient) { }
getAll():Observable<any>{ getAll(params:any):Observable<any>{
return this.http.get<any>(apiRoute+this.url); return this.http.get<any>(apiRoute+this.url, {params});
} }
getById(id: string):Observable<any> { getById(id: string):Observable<any> {
@ -23,7 +23,7 @@ export class VehicleService {
} }
update(vehicle: any):Observable<any>{ update(vehicle: any):Observable<any>{
return this.http.put<any>(apiRoute+this.url+ "/"+vehicle.id,vehicle); return this.http.put<any>(apiRoute+this.url+ "/"+vehicle._id,vehicle);
} }
delete(id: string):Observable<any>{ delete(id: string):Observable<any>{

View File

@ -15,11 +15,11 @@ const routes: Routes = [
component: VehicleListComponent component: VehicleListComponent
}, },
{ {
path: 'edit', path: 'edit/:id',
component: VehicleEditComponent component: VehicleEditComponent
}, },
{ {
path:'view', path:'view/:id',
component:VehicleViewComponent component:VehicleViewComponent
} }
] ]