|
1 |
| -import { Component, OnInit } from '@angular/core'; |
| 1 | +import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core'; |
2 | 2 | import { CommonModule } from '@angular/common';
|
3 | 3 | import { VehiclesService } from '../../../services/vehicles.service';
|
4 | 4 | import { VehicleDto } from '../../../dtos/vehicle';
|
5 | 5 | import { VehicleBrandDto } from '../../../dtos/vehicle-brand';
|
6 | 6 | import { MatDividerModule } from '@angular/material/divider';
|
7 |
| -import { MatTableModule } from '@angular/material/table'; |
| 7 | +import { MatTableDataSource, MatTableModule } from '@angular/material/table'; |
8 | 8 | import { CreateVehicleFormComponent } from '../create-vehicle-form/create-vehicle-form.component';
|
9 |
| -import { MatPaginatorModule } from '@angular/material/paginator'; |
| 9 | +import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator'; |
| 10 | +import { MatIconModule } from '@angular/material/icon'; |
| 11 | +import { MatMenuModule } from '@angular/material/menu'; |
| 12 | +import { MatIconButton } from '@angular/material/button'; |
10 | 13 |
|
11 | 14 | @Component({
|
12 | 15 | selector: 'app-vehicles-list',
|
13 | 16 | imports: [
|
14 | 17 | CommonModule,
|
15 | 18 | MatTableModule,
|
| 19 | + MatMenuModule, |
| 20 | + MatIconButton, |
| 21 | + MatIconModule, |
16 | 22 | MatPaginatorModule,
|
17 | 23 | MatDividerModule,
|
18 | 24 | CreateVehicleFormComponent,
|
19 | 25 | ],
|
20 | 26 | templateUrl: './vehicles-list.component.html',
|
21 | 27 | styleUrl: './vehicles-list.component.css',
|
22 | 28 | })
|
23 |
| -export class VehiclesListComponent implements OnInit { |
| 29 | +export class VehiclesListComponent implements OnInit, AfterViewInit { |
24 | 30 | vehicles: VehicleDto[] = [];
|
25 | 31 | vehicleBrands: VehicleBrandDto[] = [];
|
26 | 32 | displayedColumns: string[] = [
|
27 | 33 | 'brand',
|
28 | 34 | 'registrationNumber',
|
29 | 35 | 'vehicleIdentificationNumber',
|
| 36 | + 'customerEmail', |
| 37 | + 'customerAddress', |
| 38 | + 'actions', |
30 | 39 | ];
|
| 40 | + dataSource = new MatTableDataSource<VehicleDto>(this.vehicles); |
| 41 | + @ViewChild(MatPaginator) paginator!: MatPaginator; |
31 | 42 |
|
32 | 43 | constructor(private readonly vehiclesService: VehiclesService) {}
|
33 | 44 |
|
| 45 | + ngAfterViewInit(): void { |
| 46 | + this.dataSource.paginator = this.paginator; |
| 47 | + } |
| 48 | + |
34 | 49 | ngOnInit(): void {
|
35 | 50 | this.loadVehicles();
|
36 | 51 | }
|
37 | 52 |
|
| 53 | + editVehicle(vehicle: any): void { |
| 54 | + // Implement edit vehicle logic here |
| 55 | + console.log('Edit vehicle:', vehicle); |
| 56 | + } |
| 57 | + |
| 58 | + removeVehicle(vehicle: any): void { |
| 59 | + // Implement remove vehicle logic here |
| 60 | + console.log('Delete vehicle:', vehicle); |
| 61 | + } |
| 62 | + |
38 | 63 | loadVehicles(): void {
|
39 | 64 | this.vehiclesService.getVehicles().subscribe((response) => {
|
40 | 65 | this.vehicles = [...response.data];
|
|
0 commit comments