Place creation: GMaps autocomplete Image and Category, Shift+Enter and Ctrl+Enter shortcuts
This commit is contained in:
parent
bfeb66f04f
commit
789a3937a6
@ -2,7 +2,8 @@
|
||||
<div pFocusTrap class="grid grid-cols-2 md:grid-cols-4 gap-4" [formGroup]="placeForm">
|
||||
<div class="relative col-span-2">
|
||||
<p-floatlabel variant="in">
|
||||
<input id="name" formControlName="name" pInputText autofocus fluid />
|
||||
<input id="name" formControlName="name" pInputText autofocus fluid (keydown.shift.enter)="gmapsSearchText()"
|
||||
(keydown.control.enter)="closeDialog()" />
|
||||
<label for="name">Name</label>
|
||||
</p-floatlabel>
|
||||
<p-button icon="pi pi-sparkles" variant="text" [disabled]="!placeForm.get('name')!.value"
|
||||
|
||||
@ -206,15 +206,31 @@ export class PlaceCreateModalComponent {
|
||||
this.placeForm.get('gpx')?.markAsDirty();
|
||||
}
|
||||
|
||||
gmapsToForm(r: GooglePlaceResult) {
|
||||
this.placeForm.patchValue({ ...r, lat: formatLatLng(r.lat), lng: formatLatLng(r.lng), place: r.name || '' });
|
||||
this.placeForm.get('category')?.markAsDirty();
|
||||
|
||||
if (r.category) {
|
||||
this.categories$?.pipe(take(1)).subscribe({next: categories => {
|
||||
const category: Category | undefined = categories.find(c => c.name == r.category);
|
||||
if (!category) return;
|
||||
this.placeForm.get('category')?.setValue(category.id);
|
||||
}})
|
||||
}
|
||||
}
|
||||
|
||||
gmapsSearchText() {
|
||||
const query = this.placeForm.get('name')?.value;
|
||||
if (!query) return;
|
||||
this.apiService.gmapsSearchText(query).subscribe({
|
||||
next: (results) => {
|
||||
if (!results.length) {
|
||||
this.utilsService.toast('warn', 'No result', 'No result available for this autocompletion');
|
||||
return;
|
||||
}
|
||||
|
||||
if (results.length == 1) {
|
||||
const r = results[0];
|
||||
this.placeForm.patchValue({ ...r, lat: formatLatLng(r.lat), lng: formatLatLng(r.lng), place: r.name || '' });
|
||||
this.placeForm.get('category')?.markAsDirty();
|
||||
this.gmapsToForm(results[0])
|
||||
return;
|
||||
}
|
||||
|
||||
@ -235,14 +251,7 @@ export class PlaceCreateModalComponent {
|
||||
modal.onClose.pipe(take(1)).subscribe({
|
||||
next: (result: GooglePlaceResult | null) => {
|
||||
if (!result) return;
|
||||
const r = result;
|
||||
this.placeForm.patchValue({
|
||||
...r,
|
||||
lat: formatLatLng(r.lat),
|
||||
lng: formatLatLng(r.lng),
|
||||
place: r.name || '',
|
||||
});
|
||||
this.placeForm.get('category')?.markAsDirty();
|
||||
this.gmapsToForm(result);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user