Merge #68 by cjbueloMP: Trip creation use daterange input
This commit is contained in:
commit
4f7b320841
@ -11,8 +11,7 @@ import { DatePipe } from '@angular/common';
|
|||||||
import { DialogModule } from 'primeng/dialog';
|
import { DialogModule } from 'primeng/dialog';
|
||||||
|
|
||||||
interface TripBaseWithDates extends TripBase {
|
interface TripBaseWithDates extends TripBase {
|
||||||
from?: Date;
|
daterange?: Date[];
|
||||||
to?: Date;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -81,8 +80,8 @@ export class TripsComponent implements OnInit {
|
|||||||
next: (new_trip: TripBase) => {
|
next: (new_trip: TripBase) => {
|
||||||
let dayCount = 0;
|
let dayCount = 0;
|
||||||
|
|
||||||
if (trip.from && trip.to) {
|
if (trip.daterange && trip.daterange.length === 2) {
|
||||||
const obs$ = this.generateDaysLabel(trip.from!, trip.to!).map((label) =>
|
const obs$ = this.generateDaysLabel(trip.daterange).map((label) =>
|
||||||
this.apiService.postTripDay({ id: -1, label: label, items: [] }, new_trip.id),
|
this.apiService.postTripDay({ id: -1, label: label, items: [] }, new_trip.id),
|
||||||
);
|
);
|
||||||
dayCount = obs$.length;
|
dayCount = obs$.length;
|
||||||
@ -107,7 +106,9 @@ export class TripsComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generateDaysLabel(from: Date, to: Date): string[] {
|
generateDaysLabel(daterange: Date[]): string[] {
|
||||||
|
const from = daterange[0];
|
||||||
|
const to = daterange[1];
|
||||||
const labels: string[] = [];
|
const labels: string[] = [];
|
||||||
const sameMonth = from.getFullYear() === to.getFullYear() && from.getMonth() === to.getMonth();
|
const sameMonth = from.getFullYear() === to.getFullYear() && from.getMonth() === to.getMonth();
|
||||||
|
|
||||||
|
|||||||
@ -10,15 +10,10 @@
|
|||||||
</p-floatlabel>
|
</p-floatlabel>
|
||||||
|
|
||||||
@if (tripForm.get("id")?.value === -1) {
|
@if (tripForm.get("id")?.value === -1) {
|
||||||
<div class="grid md:col-span-4 grid-cols-2 gap-2">
|
<div class="md:col-span-full">
|
||||||
<p-floatlabel variant="in">
|
<p-floatlabel variant="in">
|
||||||
<p-datepicker id="from" formControlName="from" [iconDisplay]="'input'" [showIcon]="true" appendTo="body" fluid />
|
<p-datepicker id="daterange" formControlName="daterange" [iconDisplay]="'input'" [showIcon]="true" selectionMode="range" appendTo="body" fluid />
|
||||||
<label for="from">From</label>
|
<label for="daterange">Date Range</label>
|
||||||
</p-floatlabel>
|
|
||||||
|
|
||||||
<p-floatlabel variant="in">
|
|
||||||
<p-datepicker id="to" formControlName="to" [iconDisplay]="'input'" [showIcon]="true" appendTo="body" fluid />
|
|
||||||
<label for="to">To</label>
|
|
||||||
</p-floatlabel>
|
</p-floatlabel>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@ -61,4 +56,4 @@
|
|||||||
<div class="mt-4 text-right">
|
<div class="mt-4 text-right">
|
||||||
<p-button (click)="closeDialog()" [disabled]="!tripForm.dirty || !tripForm.valid">{{ tripForm.get("id")?.value
|
<p-button (click)="closeDialog()" [disabled]="!tripForm.dirty || !tripForm.valid">{{ tripForm.get("id")?.value
|
||||||
!== -1 ? "Update" : "Create" }}</p-button>
|
!== -1 ? "Update" : "Create" }}</p-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -33,8 +33,7 @@ export class TripCreateModalComponent {
|
|||||||
image: '',
|
image: '',
|
||||||
currency: null,
|
currency: null,
|
||||||
image_id: null,
|
image_id: null,
|
||||||
from: null,
|
daterange: null,
|
||||||
to: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const patchValue = this.config.data?.trip;
|
const patchValue = this.config.data?.trip;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user