Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharp 9 #488

Open
wants to merge 899 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
899 commits
Select commit Hold shift + click to select a range
4a086f8
wip POC autocomplete endpoint / closure
Oct 30, 2024
00739ef
wip POC autocomplete endpoint / closure
Oct 31, 2024
071e715
Unit tests
dvlpp Oct 31, 2024
3ee7650
more autocomplete front
Oct 31, 2024
f9c4bae
Remove localization of select, tags, autocomplete fields
dvlpp Nov 4, 2024
ca36edd
allow to get data of the form as second argument
Nov 4, 2024
6fb5cf6
Merge remote-tracking branch 'origin/poc-autocomplete-closure' into p…
dvlpp Nov 4, 2024
3aefe4a
Add tests for ApiFormAutocompleteController
dvlpp Nov 4, 2024
0f90ef6
Fix tests
dvlpp Nov 4, 2024
ae515c3
Fix demo
dvlpp Nov 4, 2024
3842afc
Documentation
dvlpp Nov 4, 2024
f71b637
improve autocomplete front
Nov 4, 2024
c129140
Merge remote-tracking branch 'origin/poc-autocomplete-closure' into p…
Nov 4, 2024
ba7bcc5
add allowEmptySearch
Nov 4, 2024
909fbe5
Merge pull request #556 from code16/poc-autocomplete-closure
Nov 4, 2024
444af63
improve upload
Nov 4, 2024
b2c922b
Remove list collapsed item template
Nov 4, 2024
cee0e1e
group 9.0 migration guide in sub-sections
Nov 4, 2024
c46cd84
Add collapsed item removal mention in migration guide
Nov 4, 2024
633a044
wip refactor html fields templates
Nov 4, 2024
61f4b99
cleanup + fix tests
Nov 5, 2024
fec7314
cleanup
Nov 5, 2024
3df5ac1
docs
Nov 5, 2024
f7f23bf
Merge pull request #557 from code16/refactor-html-fields-templates
Nov 5, 2024
f511add
Merge branch 'main' into 9.0
Nov 5, 2024
2018f4e
CS fix
aguingand Nov 5, 2024
b723403
Drop SelectFilter template
Nov 5, 2024
eba29ff
fix embed autocomplete
Nov 5, 2024
488c4ed
wip refactor embed templates
Nov 5, 2024
df16dc1
wip refactor embed templates
Nov 5, 2024
f129f4a
fix tests / embed modal
Nov 6, 2024
d2f6b51
Merge pull request #558 from code16/refactor-embeds-templates
Nov 6, 2024
d7b03c2
Update vitepress
Nov 6, 2024
669086c
Update embed / 9 migration docs
Nov 6, 2024
ddd6b1d
cleanup
Nov 6, 2024
eca7e82
Handle remote autocomplete in embed form
Nov 6, 2024
fc17c84
Add test for autocomplete in embed
dvlpp Nov 6, 2024
7d31d94
demo
dvlpp Nov 7, 2024
9c3c0d1
CS
dvlpp Nov 7, 2024
055571b
Update v9 migration docs titles
Nov 7, 2024
c812f16
Merge remote-tracking branch 'origin/9.0' into 9.0
Nov 7, 2024
b170c01
Fix typo
PatrickePatate Nov 7, 2024
7fd7e4d
Fix typos
PatrickePatate Nov 7, 2024
6441fe6
wip tags field
Nov 7, 2024
ab91744
Merge remote-tracking branch 'origin/9.0' into 9.0
Nov 7, 2024
674f717
use placeholder trait instead
Nov 7, 2024
09c74ee
Fix tests
dvlpp Nov 7, 2024
736152f
Merge remote-tracking branch 'origin/9.0' into 9.0
dvlpp Nov 7, 2024
e35e2e9
Tags improvements + some other form improvements
Nov 7, 2024
273ed30
Merge remote-tracking branch 'origin/9.0' into 9.0
Nov 7, 2024
aaeee45
Merge branch 'main' into 9.0
dvlpp Nov 8, 2024
4311393
Merge back handling order in BelongsToManyRelationUpdater
dvlpp Nov 8, 2024
9e546de
wip date field
Nov 8, 2024
3a2bacc
Merge remote-tracking branch 'origin/9.0' into 9.0
Nov 8, 2024
a7a4d48
wip date
Nov 12, 2024
2e1ee18
wip editor
Nov 14, 2024
6d554ec
Migrate to reka-ui
Nov 14, 2024
331d7e1
fix remote autocomplete in list
Nov 14, 2024
4d375fe
Fixes in demo
dvlpp Nov 14, 2024
fb3be76
wip
Nov 15, 2024
510e132
update lang
Nov 15, 2024
0e0ae76
Handle EL createButtonLabel & Show editButtonLabel
Nov 15, 2024
7985883
wip upload
Nov 15, 2024
b248d91
remove Serializable
Nov 16, 2024
1d7d00a
update progress color
Nov 16, 2024
40d415e
improvements
Nov 16, 2024
727ab84
wip upload
aguingand Nov 18, 2024
f807507
wip editor
aguingand Nov 19, 2024
bea6295
handle GlobalSelectFilter::authorize()
aguingand Nov 19, 2024
b0c14d1
Doc
dvlpp Nov 19, 2024
1489c16
wip sidebar
aguingand Nov 19, 2024
29ea7ad
wip search + other things
aguingand Nov 20, 2024
f410769
Assets
aguingand Nov 20, 2024
9f9c601
Version
aguingand Nov 20, 2024
20b5c51
Fix composer.json
dvlpp Nov 20, 2024
72da296
Fix guide
dvlpp Nov 20, 2024
a6d0b52
Commend view panel + multiple improvements
aguingand Nov 20, 2024
f6f20b9
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Nov 20, 2024
9acd0ec
fix EL dropdown separators
aguingand Nov 20, 2024
e655787
Improvements + cleanup
aguingand Nov 20, 2024
4ae3797
Handle Api exception in a modal
aguingand Nov 21, 2024
5bfa6e7
Assets
aguingand Nov 21, 2024
e0d27a8
always format show pageTitleField
aguingand Nov 21, 2024
6675819
Assets
aguingand Nov 21, 2024
59fb76a
fixes
aguingand Nov 21, 2024
d293df4
fix collection conversion to string
aguingand Nov 21, 2024
d8dfa87
fix list meta
aguingand Nov 21, 2024
c2add51
improve select filter
aguingand Nov 21, 2024
41ece8f
Fix create authorization
dvlpp Nov 21, 2024
c0b23c9
Handle remote autocomplete in command form
aguingand Nov 21, 2024
efca248
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Nov 21, 2024
27a06c3
Improve dialogs
aguingand Nov 21, 2024
ce76921
Fix command modal not closing
aguingand Nov 21, 2024
50d7cc4
Fix grid rows
aguingand Nov 21, 2024
9e25ff4
Add tests
dvlpp Nov 22, 2024
13e8f20
Fix show instance command call
dvlpp Nov 22, 2024
76f2422
Fix class
dvlpp Nov 22, 2024
1dc96ea
Fix ShowFileFieldData
dvlpp Nov 22, 2024
75dc586
Fix autocomplete list fails on format
aguingand Nov 22, 2024
b1406ab
Multiple fixes + handle read-only fields
aguingand Nov 22, 2024
206b750
disable reorder and hide filters (#559)
dvlpp Nov 22, 2024
32ea4f0
Improve sidebar
aguingand Nov 22, 2024
ecf6f8c
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Nov 22, 2024
1712412
Fix internal
dvlpp Nov 22, 2024
15bbda3
Merge remote-tracking branch 'origin/9.0' into 9.0
dvlpp Nov 22, 2024
e762d09
Fix tests
dvlpp Nov 22, 2024
66e62c0
multiple improvements
aguingand Nov 22, 2024
4e1696d
Handle showResetLinkInLoginForm config
aguingand Nov 25, 2024
a070500
Doc
dvlpp Nov 25, 2024
9f85f06
improvements
aguingand Nov 25, 2024
886ab0e
Doc
dvlpp Nov 25, 2024
c0ac338
remove sizeXS in data
aguingand Nov 25, 2024
623bbe5
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Nov 25, 2024
5d01785
responsive
aguingand Nov 25, 2024
a43aa98
Doc
dvlpp Nov 26, 2024
ffd5672
Merge remote-tracking branch 'origin/9.0' into 9.0
dvlpp Nov 26, 2024
029dd9c
Fix tests
dvlpp Nov 26, 2024
907a047
Fix auto layout, allow new variadic layout API
dvlpp Nov 26, 2024
f3d4f55
responsive
aguingand Nov 26, 2024
7710525
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Nov 26, 2024
843459a
responsive
aguingand Nov 26, 2024
26c136d
Fix menu
dvlpp Nov 27, 2024
cea5986
Fix magic file attribute of SharpUploadModel
dvlpp Nov 27, 2024
29fad3a
dashboard responsive
aguingand Nov 27, 2024
76a996a
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Nov 27, 2024
24a6c08
Fix EL scrollbar
aguingand Nov 28, 2024
9b3901d
New assets configuration
aguingand Nov 28, 2024
7cc48b8
Create and delete authorizations are always false for single shows
dvlpp Nov 28, 2024
ffc544b
Fix scrolling when opening autocomplete in dialog
aguingand Nov 28, 2024
d4b7e6c
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Nov 28, 2024
68abf92
wip
aguingand Nov 29, 2024
7dbd32c
Remove date displayFormat + date range start end back formatting
aguingand Dec 2, 2024
d8821fd
Fix date field start of week
aguingand Dec 2, 2024
715246c
Wip e2e
aguingand Dec 2, 2024
678d7f9
Update stubs
aguingand Dec 3, 2024
0126745
Handle undefined fields + localize date range presets
aguingand Dec 3, 2024
a8273d0
wip E2E
aguingand Dec 3, 2024
f114459
Fix test documentation
dvlpp Dec 4, 2024
6d811c1
wip e2e
aguingand Dec 4, 2024
25be4ac
update to Pest 3
aguingand Dec 4, 2024
d5bcde6
Fix SharpException HTTP status + only show renderer page in 500 + debug
aguingand Dec 4, 2024
dbf0fd8
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Dec 4, 2024
1ee12a5
Only show API exception modal on 500
aguingand Dec 4, 2024
6991cc2
Improve Autocomplete a11y
aguingand Dec 4, 2024
4579339
Fix tests
aguingand Dec 4, 2024
c8bffec
[demo] Fix null
dvlpp Dec 4, 2024
cc1cbc4
Merge branch '9.0' into e2e
aguingand Dec 4, 2024
468bc7f
wip e2e
aguingand Dec 4, 2024
ea8bdf1
Mark all Data class internal
aguingand Dec 5, 2024
c4555c8
define only specific HttpException
aguingand Dec 5, 2024
ad74a7b
wip e2e
aguingand Dec 5, 2024
1064a17
define only specific HttpException
aguingand Dec 5, 2024
7875d34
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Dec 5, 2024
47c353e
fix form label layout
aguingand Dec 5, 2024
b274f85
Improve readability
aguingand Dec 5, 2024
f02df78
Improve field select
aguingand Dec 5, 2024
5a454c3
Improve applicative exception on form post
aguingand Dec 6, 2024
1b1e782
Merge branch '9.0' into e2e
aguingand Dec 6, 2024
193b29e
Handle get form
dvlpp Dec 6, 2024
16cc7af
Fix tests
dvlpp Dec 6, 2024
ec184bb
Handle post
dvlpp Dec 6, 2024
17a6916
Fix test
dvlpp Dec 6, 2024
ab2b840
Add quick creation case in demo
dvlpp Dec 6, 2024
572a108
rewrite remote autocomplete endpoint controller
aguingand Dec 6, 2024
c1e2673
improve UI
aguingand Dec 6, 2024
8ebf7c0
add ray in e2e
aguingand Dec 6, 2024
39a6cf4
Fix tests
dvlpp Dec 6, 2024
3c77dda
update demo laravel/framework
aguingand Dec 6, 2024
57bd4da
fix multiform + list max / reorder button
aguingand Dec 6, 2024
1bdaf15
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Dec 6, 2024
30234ca
cleanup
aguingand Dec 6, 2024
9179adc
Revert "Fix tests"
aguingand Dec 9, 2024
13c9874
Revert "rewrite remote autocomplete endpoint controller"
aguingand Dec 9, 2024
49f01f2
rollback to app()->handle for autocomplete remote
aguingand Dec 9, 2024
6bd5dab
cleanup rollback
aguingand Dec 9, 2024
c4d9149
Improve error dialog
aguingand Dec 9, 2024
6fe021c
Update reka + wip e2e
aguingand Dec 9, 2024
41b19c3
Merge branch '9.0' into quick-create
aguingand Dec 9, 2024
523273f
Always send all fields default data as null in commands
aguingand Dec 9, 2024
b585668
Allow to scroll when popover overflowing in dialog
aguingand Dec 9, 2024
ab2f4f5
Fix command locales
aguingand Dec 9, 2024
25d2179
Improve locale select in command form
aguingand Dec 9, 2024
b6dd0eb
Handle Quick creation front
aguingand Dec 9, 2024
173e415
Always send all fields default data as null in commands
aguingand Dec 9, 2024
feae691
Allow to scroll when popover overflowing in dialog
aguingand Dec 9, 2024
889d82d
Fix command locales
aguingand Dec 9, 2024
b0ce369
Improve locale select in command form
aguingand Dec 9, 2024
9866a58
Build form config
aguingand Dec 9, 2024
e162af3
Add DateRangeFilterValue
dvlpp Dec 10, 2024
bc126ba
Work on demo
dvlpp Dec 10, 2024
1143296
Work on demo
dvlpp Dec 10, 2024
5269846
Test on php 8.4
dvlpp Dec 10, 2024
0d5a50b
allow php 8.4
dvlpp Dec 10, 2024
4bd14a2
Quick creation front
aguingand Dec 10, 2024
7bb9586
Merge branch '9.0' into quick-create
dvlpp Dec 10, 2024
a577c5c
Fix tests
dvlpp Dec 10, 2024
8f1c99f
Add test
dvlpp Dec 10, 2024
3a0388e
demo
dvlpp Dec 10, 2024
f89de4d
Doc
dvlpp Dec 10, 2024
8cb1607
Menu
dvlpp Dec 10, 2024
f7ad1bd
Fix doc
dvlpp Dec 10, 2024
aaee033
demo
dvlpp Dec 11, 2024
80214d0
Improve / fix quick creation
aguingand Dec 11, 2024
2798fc3
Work on doc homepage
dvlpp Dec 11, 2024
425585f
wip improve link dropdown
aguingand Dec 11, 2024
1426ae6
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Dec 11, 2024
6f356d4
fix demo home
aguingand Dec 11, 2024
0b5b26c
Better screenshots
dvlpp Dec 11, 2024
6b9439e
Better tests
dvlpp Dec 11, 2024
5fadc9f
Merge pull request #560 from code16/quick-create
dvlpp Dec 11, 2024
594cc6c
Fix screenshots in doc
dvlpp Dec 11, 2024
8365b10
Demo
dvlpp Dec 11, 2024
0a1d1f9
better Screen
dvlpp Dec 11, 2024
431984d
improve docs home
aguingand Dec 11, 2024
9b29bb2
update visual
aguingand Dec 11, 2024
ed21f51
Text
dvlpp Dec 11, 2024
39ee394
Demo CU
dvlpp Dec 11, 2024
e71c5e5
Improve link dropdown
aguingand Dec 11, 2024
c8b0107
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Dec 11, 2024
6192a00
Fix screenshots (doc)
dvlpp Dec 12, 2024
45501e3
disable bubble menu for now
aguingand Dec 12, 2024
6e05cee
Assets
aguingand Dec 12, 2024
e228f2c
Version
aguingand Dec 12, 2024
acb5624
Add closures phpdoc
aguingand Dec 12, 2024
ee1db27
CS fix
aguingand Dec 12, 2024
7d4791b
Fix install command
dvlpp Dec 13, 2024
dabbd71
Fix input type password + confirm command before posting form
aguingand Dec 13, 2024
b57bbe5
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Dec 13, 2024
613417f
Doc
dvlpp Dec 13, 2024
654fc01
Upgrade ziggy to v2
dvlpp Dec 13, 2024
864235f
Build ziggy from vendor
aguingand Dec 13, 2024
93d36fe
docs: fix function with namespace arg
aguingand Dec 16, 2024
6ecf7a1
Fix laravel/prompts dep
dvlpp Dec 16, 2024
a599661
Fix laravel/prompts dep
dvlpp Dec 16, 2024
676c067
Install script
dvlpp Dec 16, 2024
a50e4c8
Update inertia
Dec 17, 2024
717ad61
Assets
Dec 17, 2024
4634845
Version
Dec 17, 2024
d5dd861
Disable PHP Unit method casing
aguingand Dec 18, 2024
447992f
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Dec 18, 2024
3c0d351
Fix stubs
PatrickePatate Dec 20, 2024
bcaded5
wip e2e
Jan 2, 2025
abad0a5
Remove DataCollection
Jan 2, 2025
92eb695
Update generated TS
Jan 2, 2025
97aeb6c
Fix code16/sharp-dev#343
dvlpp Jan 3, 2025
0aa6a71
Update reka-ui
aguingand Jan 3, 2025
6d48697
throw exception if editor value is an array and not localized
aguingand Jan 3, 2025
82a9721
Allow command item to not be focused on render
aguingand Jan 3, 2025
54721ab
WIP e2e
aguingand Jan 3, 2025
43a7b69
Merge remote-tracking branch 'origin/9.0' into 9.0
aguingand Jan 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
wip geolocation
  • Loading branch information
antoine committed Oct 29, 2024
commit 4399112f4fc179dc05bb77a31da7b9d5900e6ef7
7 changes: 5 additions & 2 deletions demo/app/Sharp/TestForm/TestForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ public function buildFormFields(FieldsContainer $formFields): void
SharpFormGeolocationField::make('geolocation')
->setLabel('Geolocation')
->setApiKey(env('GMAPS_KEY'))
->setMapsProvider('osm')
->setGeocodingProvider('osm')
->setGoogleMapsMapId(env('GMAPS_MAP_ID'))
// ->setMapsProvider('osm')
// ->setGeocodingProvider('osm')
->setMapsProvider('gmaps')
->setGeocodingProvider('gmaps')
// ->setDisplayUnitDecimalDegrees()
->setDisplayUnitDegreesMinutesSeconds()
->setGeocoding()
Expand Down
3 changes: 3 additions & 0 deletions docs/guide/form-fields/geolocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ This method will set the API key for geocoding only.

This method will set the API key for maps only.

### `setGoogleMapsMapId(string $mapId)`

Google Maps API now requires a [Map ID](https://developers.google.com/maps/documentation/get-map-id) to use markers. It must be defined if maps provider is set to "gmaps".

## Formatter

Expand Down
23 changes: 17 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"@fawmi/vue-google-maps": "^0.9.79",
"@fortawesome/fontawesome-free": "^6.4.0",
"@googlemaps/js-api-loader": "^1.16.8",
"@headlessui/vue": "^1.7.19",
"@heroicons/vue": "^2.0.18",
"@inertiajs/vue3": "^1.2.0",
Expand Down
8 changes: 6 additions & 2 deletions resources/js/components/PageAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
</script>

<template>
<Alert :variant="pageAlert.level === 'danger' ? 'destructive' : 'default'">
<Alert :variant="
pageAlert.level === 'danger' ? 'destructive'
: pageAlert.level === 'primary' ? 'primary'
: 'default'
">
<template v-if="pageAlert.level === 'danger'">
<CircleAlert class="w-4 h-4"/>
</template>
<template v-else-if="pageAlert.level === 'warning'">
<TriangleAlert class="w-4 h-4" />
<TriangleAlert class="w-4 h-4 text-destructive" />
</template>
<template v-else>
<Info class="w-4 h-4" />
Expand Down
6 changes: 3 additions & 3 deletions resources/js/components/ui/alert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export { default as AlertTitle } from './AlertTitle.vue'
export { default as AlertDescription } from './AlertDescription.vue'

export const alertVariants = cva(
'relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg:has(+div)]:mt-0.5 [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground',
'relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg:has(+div)]:mt-0.5 [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4',
{
variants: {
variant: {
default: 'bg-background text-foreground',
destructive:
'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive',
primary: 'bg-background text-accent-foreground border-primary/30',
destructive: 'border-destructive/50 text-destructive dark:border-destructive',
},
},
defaultVariants: {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/form/components/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'check': Check,
// 'date': DateInput,
'editor': Editor,
// 'geolocation': Geolocation,
'geolocation': Geolocation,
'html': Html,
'list': List,
// 'number': NumberInput,
Expand Down
4 changes: 2 additions & 2 deletions resources/js/form/components/fields/Html.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import FormFieldLayout from "@/form/components/FormFieldLayout.vue";
import { FormFieldProps } from "@/form/types";

defineProps<FormFieldProps<FormHtmlFieldData>>();
const props = defineProps<FormFieldProps<FormHtmlFieldData>>();
</script>

<template>
<FormFieldLayout v-bind="$props">
<FormFieldLayout v-bind="props">
<div class="text-sm">
<TemplateRenderer
:template="field.template"
Expand Down
205 changes: 154 additions & 51 deletions resources/js/form/components/fields/geolocation/Geolocation.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { __ } from "@/utils/i18n";
import { Button } from '@/components/ui/button';
import { Modal } from "@/components/ui";
import { Loading, Modal } from "@/components/ui";
import GeolocationEdit from './GeolocationEdit.vue';
import { FormGeolocationFieldData } from "@/types";
import type { Component } from "vue";
Expand All @@ -10,6 +10,22 @@
import { onMounted, ref } from "vue";
import { dd2dms, triggerResize } from "./utils";
import { loadGmaps } from "./gmaps/load";
import {
Dialog,
DialogClose,
DialogFooter,
DialogHeader,
DialogScrollContent,
DialogTitle
} from "@/components/ui/dialog";
import {
EditableMapComponentProps,
GeocodeParams, LatLng,
MapComponentProps
} from "@/form/components/fields/geolocation/types";
import { Input } from "@/components/ui/input";
import gmapsGeocode from "@/form/components/fields/geolocation/gmaps/geocode";
import osmGeocode from "@/form/components/fields/geolocation/osm/geocode";

const props = defineProps<{
field: FormGeolocationFieldData,
Expand All @@ -24,9 +40,56 @@
};

const ready = ref(false);
const modalVisible = ref(false);
const modalOpen = ref(false);
const modalLoading = ref(false);
const modalMessage = ref('');
const modalSearch = ref('');
const modalMapBounds = ref(null);
const modalMarkerPosition = ref(props.value);

function geocode(params: GeocodeParams) {
if(props.field.geocodingProvider.name === 'gmaps') {
return gmapsGeocode(params);
}
return osmGeocode(params);
}

function onModalSearchSubmit() {
const address = modalSearch.value;
modalMessage.value = '';
modalLoading.value = true;
geocode({ address: modalSearch.value })
.then(results => {
if(results.length > 0) {
modalMapBounds.value = results[0].bounds;
modalMarkerPosition.value = results[0].location;
} else {
modalMessage.value = __('sharp::form.geolocation.modal.geocode_input.message.no_results', { query: address ?? '' });
}
})
.catch(status => {
modalMessage.value = `${__(`sharp::form.geolocation.modal.geocode_input.message.error`)}${status?` (${status})`:''}`;
})
.finally(() => {
modalLoading.value = false;
});
}

function onModalMarkerPositionChange(position: LatLng) {
if(props.field.geocoding) {
modalLoading.value = true;
geocode({ latLng: position })
.then(results => {
if(results.length > 0) {
modalSearch.value = results[0].address;
}
})
.finally(() => {
modalLoading.value = false;
});
}
}

function onModalSubmit() {
emit('input', modalMarkerPosition.value);
}
Expand All @@ -50,68 +113,108 @@
</script>

<template>
<div class="SharpGeolocation">
<div>
<template v-if="!ready">
{{ __('sharp::form.geolocation.loading') }}
</template>
<template v-else-if="!value">
<Button variant="secondary" class="w-full" @click="modalVisible = true">
<Button variant="secondary" class="w-full" @click="modalOpen = true">
{{ __('sharp::form.geolocation.browse_button') }}
</Button>
</template>
<template v-else>
<div class="card card-body form-control">
<div class="row">
<div class="col-7">
<component
:is="components[field.mapsProvider.name]"
class="max-w-full pb-[80%]"
:marker-position="value"
:center="value"
:zoom="field.zoomLevel"
:max-bounds="field.boundaries ? [field.boundaries.sw, field.boundaries.ne] : null"
:tiles-url="field.mapsProvider.name === 'osm' ? field.mapsProvider.options.tilesUrl : null"
/>
<div class="bg-background border border-input flex rounded-md p-4">
<div class="w-[40%]">
<component
:is="components[field.mapsProvider.name]"
class="max-w-full pb-[80%]"
:marker-position="value"
:center="value"
:zoom="field.zoomLevel"
:max-bounds="field.boundaries ? [field.boundaries.sw, field.boundaries.ne] : null"
:tiles-url="field.mapsProvider.name === 'osm' ? field.mapsProvider.options.tilesUrl : null"
/>
</div>
<div class="d-flex flex-column justify-content-between h-100">
<div>
<div><small>Latitude : {{ field.displayUnit === 'DMS' ? dd2dms(value.lat) : value.lat }}</small></div>
<div><small>Longitude : {{ field.displayUnit === 'DMS' ? dd2dms(value.lng, true) : value.lng }}</small></div>
</div>
<div class="col-5 pl-0">
<div class="d-flex flex-column justify-content-between h-100">
<div>
<div><small>Latitude : {{ field.displayUnit === 'DMS' ? dd2dms(value.lat) : value.lat }}</small></div>
<div><small>Longitude : {{ field.displayUnit === 'DMS' ? dd2dms(value.lng, true) : value.lng }}</small></div>
</div>
<div>
<Button variant="destructive" size="sm" :disabled="field.readOnly"
@click="$emit('input', null)"
>
{{ __('sharp::form.geolocation.remove_button') }}
</Button>
<Button variant="outline" size="sm" :disabled="field.readOnly" @click="modalVisible = true">
{{ __('sharp::form.geolocation.edit_button') }}
</Button>
</div>
</div>
<div>
<Button variant="destructive" size="sm" :disabled="field.readOnly"
@click="$emit('input', null)"
>
{{ __('sharp::form.geolocation.remove_button') }}
</Button>
<Button variant="outline" size="sm" :disabled="field.readOnly" @click="modalOpen = true">
{{ __('sharp::form.geolocation.edit_button') }}
</Button>
</div>
</div>
</div>
</template>
<Modal
v-model:visible="modalVisible"
no-close-on-backdrop
@ok="onModalSubmit"
<Dialog
v-model:open="modalOpen"
>
<template #title>
<template v-if="field.geocoding">
{{ __('sharp::form.geolocation.modal.title') }}
</template>
<template v-else>
{{__('sharp::form.geolocation.modal.title-no-geocoding') }}
</template>
</template>
<GeolocationEdit
:field="field"
:value="value"
v-model:marker-position="modalMarkerPosition"
/>
</Modal>
<DialogScrollContent class="gap-6" @pointer-down-outside.prevent>
<DialogHeader>
<DialogTitle>
<template v-if="field.geocoding">
{{ __('sharp::form.geolocation.modal.title') }}
</template>
<template v-else>
{{__('sharp::form.geolocation.modal.title-no-geocoding') }}
</template>
</DialogTitle>
</DialogHeader>

<div>
<template v-if="field.geocoding">
<div class="mb-2">
<form @submit.prevent="onModalSearchSubmit">
<div class="flex">
<Input class="flex-1" v-model="modalSearch"
:placeholder="__('sharp::form.geolocation.modal.geocode_input.placeholder')"
/>
<Button class="ml-2" variant="outline" :disabled="modalLoading">
{{ __('sharp::form.geolocation.modal.search_button') }}
</Button>
</div>
</form>

<template v-if="modalMessage">
<small>{{ modalMessage }}</small>
</template>
</div>
</template>

<component
:is="components[field.mapsProvider.name]"
class="aspect-[1/1]"
v-bind="{
field,
markerPosition: modalMarkerPosition,
bounds: modalMapBounds,
maxBounds: field.boundaries ? [field.boundaries.sw, field.boundaries.ne] : null,
center: value ?? field.initialPosition ?? { lat:48.5838961, lng:7.7421826 },
zoom: field.zoomLevel,
editable: true,
} satisfies MapComponentProps"
@change="onModalMarkerPositionChange"
/>
</div>

<DialogFooter>
<DialogClose as-child>
<Button variant="outline">
{{ __('sharp::modals.cancel_button') }}
</Button>
</DialogClose>
<Button @click="onModalSubmit">
{{ __('sharp::modals.command.submit_button') }}
</Button>
</DialogFooter>
</DialogScrollContent>
</Dialog>
</div>
</template>
Loading
Loading