:feature: Trip: multi-days item creation
This commit is contained in:
parent
1bee9113dc
commit
e5ffaffa42
@ -413,6 +413,7 @@ export class TripComponent implements AfterViewInit {
|
|||||||
this.map?.removeLayer(this.tripMapTemporaryMarker);
|
this.map?.removeLayer(this.tripMapTemporaryMarker);
|
||||||
this.tripMapTemporaryMarker = undefined;
|
this.tripMapTemporaryMarker = undefined;
|
||||||
}
|
}
|
||||||
|
this.resetMapBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
placeHighlightMarker(lat: number, lng: number) {
|
placeHighlightMarker(lat: number, lng: number) {
|
||||||
@ -961,27 +962,40 @@ export class TripComponent implements AfterViewInit {
|
|||||||
);
|
);
|
||||||
|
|
||||||
modal.onClose.pipe(take(1)).subscribe({
|
modal.onClose.pipe(take(1)).subscribe({
|
||||||
next: (item: TripItem | null) => {
|
next: (item: (TripItem & { day_id: number[] }) | null) => {
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
this.apiService
|
const obs$ = item.day_id.map((day_id) =>
|
||||||
.postTripDayItem(item, this.trip!.id!, item.day_id)
|
this.apiService.postTripDayItem(
|
||||||
|
{ ...item, day_id },
|
||||||
|
this.trip!.id!,
|
||||||
|
day_id,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
forkJoin(obs$)
|
||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (resp) => {
|
next: (items: TripItem[]) => {
|
||||||
const idx = this.trip!.days.findIndex((d) => d.id == item.day_id);
|
items.forEach((item) => {
|
||||||
|
const idx = this.trip!.days.findIndex(
|
||||||
|
(d) => d.id == item.day_id,
|
||||||
|
);
|
||||||
if (idx === -1) return;
|
if (idx === -1) return;
|
||||||
|
|
||||||
const td: TripDay = this.trip!.days[idx];
|
const td: TripDay = this.trip!.days[idx];
|
||||||
td.items.push(resp);
|
td.items.push(item);
|
||||||
this.flattenTripDayItems();
|
|
||||||
|
|
||||||
this.dayStatsCache.delete(resp.day_id);
|
this.dayStatsCache.delete(item.day_id);
|
||||||
if (resp.price) this.updateTotalPrice(resp.price);
|
if (item.price) this.updateTotalPrice(item.price);
|
||||||
if (resp.place?.id) {
|
if (item.place?.id) {
|
||||||
this.placesUsedInTable.add(resp.place.id);
|
this.placesUsedInTable.add(item.place.id);
|
||||||
this.setPlacesAndMarkers();
|
this.setPlacesAndMarkers();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.flattenTripDayItems();
|
||||||
|
this.setPlacesAndMarkers();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,15 +1,25 @@
|
|||||||
<section>
|
<section>
|
||||||
<div [formGroup]="itemForm">
|
<div [formGroup]="itemForm">
|
||||||
<div class="grid md:grid-cols-5 gap-4">
|
<div class="grid md:grid-cols-5 gap-4">
|
||||||
<p-floatlabel variant="in">
|
@if (itemForm.get('id')?.value !== -1) {
|
||||||
|
<p-floatlabel variant="in" class="min-w-0">
|
||||||
<p-select [options]="days" optionValue="id" optionLabel="label" inputId="day_id" id="day_id"
|
<p-select [options]="days" optionValue="id" optionLabel="label" inputId="day_id" id="day_id"
|
||||||
formControlName="day_id" [checkmark]="true" class="capitalize" fluid>
|
formControlName="day_id" [checkmark]="true" fluid>
|
||||||
<ng-template let-day #item>
|
<ng-template let-day #item>
|
||||||
<div class="whitespace-normal">{{ day.label }}</div>
|
<div class="whitespace-normal">{{ day.label }}</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</p-select>
|
</p-select>
|
||||||
<label for="day_id">Day</label>
|
<label for="day_id">Day</label>
|
||||||
</p-floatlabel>
|
</p-floatlabel>
|
||||||
|
} @else {
|
||||||
|
<p-multiselect [options]="days" optionValue="id" optionLabel="label" formControlName="day_id" placeholder="Days"
|
||||||
|
[filter]="false" [showToggleAll]="false" display="chip" styleClass="flex items-center"
|
||||||
|
selectedItemsLabel="{0} days selected" fluid>
|
||||||
|
<ng-template let-day #item>
|
||||||
|
<div class="whitespace-normal">{{ day.label }}</div>
|
||||||
|
</ng-template>
|
||||||
|
</p-multiselect>
|
||||||
|
}
|
||||||
|
|
||||||
<p-floatlabel variant="in" class="w-full">
|
<p-floatlabel variant="in" class="w-full">
|
||||||
<p-inputmask id="time" formControlName="time" mask="99?:99" fluid styleClass="w-full" />
|
<p-inputmask id="time" formControlName="time" mask="99?:99" fluid styleClass="w-full" />
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import { UtilsService } from "../../services/utils.service";
|
|||||||
import { checkAndParseLatLng, formatLatLng } from "../../shared/latlng-parser";
|
import { checkAndParseLatLng, formatLatLng } from "../../shared/latlng-parser";
|
||||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||||
import { InputNumberModule } from "primeng/inputnumber";
|
import { InputNumberModule } from "primeng/inputnumber";
|
||||||
|
import { MultiSelectModule } from "primeng/multiselect";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-trip-create-day-item-modal",
|
selector: "app-trip-create-day-item-modal",
|
||||||
@ -34,6 +35,7 @@ import { InputNumberModule } from "primeng/inputnumber";
|
|||||||
ButtonModule,
|
ButtonModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
InputMaskModule,
|
InputMaskModule,
|
||||||
|
MultiSelectModule,
|
||||||
],
|
],
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: "./trip-create-day-item-modal.component.html",
|
templateUrl: "./trip-create-day-item-modal.component.html",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user