This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
<p-scrollTop />
|
<p-scrollTop />
|
||||||
<div class="mb-4 flex gap-2 md:justify-between">
|
<div class="mb-4 flex gap-2 md:justify-between">
|
||||||
<div class="basis-full lg:basis-1/4 md:basis-1/2 p-0">
|
<div class="basis-full lg:basis-1/4 md:basis-1/2 p-0">
|
||||||
<!-- <p-select styleClass="w-full" [formControl]="selectedRabbit" placeholder="Kaninchen" [showClear]="true"
|
<p-select styleClass="w-full" [formControl]="selectedCar" placeholder="Auto" [showClear]="true"
|
||||||
[options]="(rabbits$ | async)!" optionLabel="name" /> -->
|
[options]="(cars$ | async)!" optionLabel="name" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p-button label="Erstellen" routerLink="/entries/create">
|
<p-button label="Erstellen" routerLink="/entries/create">
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
import { AsyncPipe, CommonModule } from '@angular/common';
|
import { AsyncPipe, CommonModule } from '@angular/common';
|
||||||
import { Component, inject } from '@angular/core';
|
import { Component, inject } from '@angular/core';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { RouterLink } from '@angular/router';
|
import { RouterLink } from '@angular/router';
|
||||||
import { CarClient } from '@vegasco-web/api/cars/car-client';
|
import { CarClient } from '@vegasco-web/api/cars/car-client';
|
||||||
import { ConsumptionClient } from '@vegasco-web/api/consumptions/consumption-client';
|
import { ConsumptionClient } from '@vegasco-web/api/consumptions/consumption-client';
|
||||||
|
import { MessageService } from 'primeng/api';
|
||||||
import { ButtonModule } from 'primeng/button';
|
import { ButtonModule } from 'primeng/button';
|
||||||
import { DataViewModule } from 'primeng/dataview';
|
import { DataViewModule } from 'primeng/dataview';
|
||||||
import { ScrollTopModule } from 'primeng/scrolltop';
|
import { ScrollTopModule } from 'primeng/scrolltop';
|
||||||
import { SelectModule } from 'primeng/select';
|
import { SelectModule } from 'primeng/select';
|
||||||
import { SkeletonModule } from 'primeng/skeleton';
|
import { SkeletonModule } from 'primeng/skeleton';
|
||||||
import {
|
import {
|
||||||
|
BehaviorSubject,
|
||||||
|
combineLatest,
|
||||||
map,
|
map,
|
||||||
Observable,
|
Observable,
|
||||||
|
startWith,
|
||||||
tap
|
tap
|
||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
|
|
||||||
@@ -35,29 +39,57 @@ import {
|
|||||||
export class EntriesComponent {
|
export class EntriesComponent {
|
||||||
private readonly consumptionClient = inject(ConsumptionClient);
|
private readonly consumptionClient = inject(ConsumptionClient);
|
||||||
private readonly carClient = inject(CarClient);
|
private readonly carClient = inject(CarClient);
|
||||||
|
private readonly messageService = inject(MessageService);
|
||||||
|
|
||||||
protected readonly consumptionEntries$: Observable<ConsumptionEntry[]>;
|
protected readonly consumptionEntries$: Observable<ConsumptionEntry[]>;
|
||||||
protected readonly cars$: Observable<Car[]>;
|
protected readonly cars$: Observable<Car[]>;
|
||||||
|
|
||||||
protected readonly skeletonsIterationSource = Array(10).fill(0);
|
protected readonly skeletonsIterationSource = Array(10).fill(0);
|
||||||
|
|
||||||
|
protected readonly selectedCar = new FormControl<Car | null | undefined>(null);
|
||||||
|
|
||||||
|
private readonly deletedEntries$ = new BehaviorSubject(<string[]>[]);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.consumptionEntries$ = this.consumptionClient.getAll()
|
const consumptionEntries = this.consumptionClient.getAll()
|
||||||
|
.pipe(
|
||||||
|
map(response => response.consumptions)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.consumptionEntries$ = combineLatest([
|
||||||
|
consumptionEntries,
|
||||||
|
this.selectedCar.valueChanges.pipe(startWith(null)),
|
||||||
|
this.deletedEntries$,
|
||||||
|
])
|
||||||
.pipe(
|
.pipe(
|
||||||
takeUntilDestroyed(),
|
takeUntilDestroyed(),
|
||||||
tap((response) => {
|
map(([entries, selectedCar, deletedEntries]) => {
|
||||||
console.log('Entries response:', response);
|
const nonDeletedEntries =
|
||||||
}),
|
deletedEntries.length === 0
|
||||||
map(response => response.consumptions)
|
? entries
|
||||||
|
: entries.filter(entry => !deletedEntries.includes(entry.id));
|
||||||
|
|
||||||
|
if (!selectedCar) {
|
||||||
|
return nonDeletedEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nonDeletedEntries.filter(entry => entry.carId === selectedCar.id);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.cars$ = this.carClient.getAll()
|
this.cars$ = this.carClient.getAll()
|
||||||
.pipe(
|
.pipe(
|
||||||
takeUntilDestroyed(),
|
takeUntilDestroyed(),
|
||||||
tap((response) => {
|
|
||||||
console.log('Cars response:', response);
|
|
||||||
}),
|
|
||||||
map(response => response.cars)
|
map(response => response.cars)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onEntryDeleted(entry: ConsumptionEntry): void {
|
||||||
|
this.deletedEntries$.next([...this.deletedEntries$.value, entry.id]);
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Eintrag gelöscht',
|
||||||
|
detail: 'Der Eintrag wurde erfolgreich gelöscht.',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user