Compare commits

..

No commits in common. "df24e33e4bf454c7eb93912693e4e1c79d793988" and "17271cee115716d6488a6ccafed32abf70756e1b" have entirely different histories.

9 changed files with 34 additions and 165 deletions

View File

@ -1,12 +0,0 @@
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><br> <label>Marque</label>
<input [(ngModel)]="vehicle.mark" type="text" pInputText /> <input [(ngModel)]="vehicle.mark" type="text" pInputText />
<br><br> <br>
<label>Modele</label><br> <label>Modele</label>
<input [(ngModel)]="vehicle.model" type="text" pInputText /> <input [(ngModel)]="vehicle.model" type="text" pInputText />
<br><br>
<label>Matricule</label><br> <label>Matricule</label>
<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 {ActivatedRoute, Router} from "@angular/router"; import {Router} from "@angular/router";
@Component({ @Component({
selector: 'app-vehicle-edit', selector: 'app-vehicle-edit',
@ -10,45 +10,16 @@ import {ActivatedRoute, 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();
}
} }
getById(): void{ save() {
this.vehicleService.getById(this.id).subscribe({ this.vehicleService.create(this.vehicle).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();
@ -56,15 +27,4 @@ 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,18 +1,6 @@
<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('0')" pButton type="button" label="Ajouter un véhicule"></button> <button (click)="edit()" 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'}">
@ -30,9 +18,9 @@
<td>{{vehicle.model}}</td> <td>{{vehicle.model}}</td>
<td>{{vehicle.matricule}}</td> <td>{{vehicle.matricule}}</td>
<td> <td>
<i (click)="edit(product._id)" class="pi pi-pencil" style="margin-right: 10px"></i> <i class="pi pi-pencil" style="margin-right: 10px"></i>
<i (click)="delete(product._id)" class="pi pi-trash" style="margin-right: 10px"></i> <i class="pi pi-trash" style="margin-right: 10px"></i>
<i (click)="view(product._id)" class="pi pi-eye" style="margin-right: 10px"></i> <i class="pi pi-eye" style="margin-right: 10px"></i>
</td> </td>
</tr> </tr>
</ng-template> </ng-template>

View File

@ -8,13 +8,6 @@ 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,
@ -22,16 +15,11 @@ export class VehicleListComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.params.search = ""; this.getServices();
this.params.fields = ["matricule", "mark", "model"];
this.params.page = 1;
this.params.limit = 5;
this.getVehicles();
} }
getVehicles() { getServices() {
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;
@ -40,27 +28,16 @@ export class VehicleListComponent implements OnInit {
}) })
} }
edit(_id: string): void { edit(): void {
this.router.navigateByUrl('/app/vehicle/edit/'+_id).then(); /*
} let vehicle : any = {};
view(_id: string): void { vehicle.model = "RangeRoger";
this.router.navigateByUrl('/app/vehicle/view/'+_id).then(); vehicle.mark = "Sport";
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,14 +1 @@
<div> <p>vehicle-view works!</p>
<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,6 +1,4 @@
import {ChangeDetectorRef, Component, OnInit} from '@angular/core'; import { 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',
@ -8,39 +6,10 @@ import {ActivatedRoute, Router} from "@angular/router";
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(private vehicleService: VehicleService, constructor() { }
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(params:any):Observable<any>{ getAll():Observable<any>{
return this.http.get<any>(apiRoute+this.url, {params}); return this.http.get<any>(apiRoute+this.url);
} }
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/:id', path: 'edit',
component: VehicleEditComponent component: VehicleEditComponent
}, },
{ {
path:'view/:id', path:'view',
component:VehicleViewComponent component:VehicleViewComponent
} }
] ]