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

Geo Point support #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions lib/kaffy/resource_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ defmodule Kaffy.ResourceForm do
:utc_datetime_usec ->
flatpickr_datetime_usec(form, field, opts)

Geo.PostGIS.Geometry ->
value =
data
|> Map.get(field, "")
|> Kaffy.Utils.json().encode!(escape: :html_safe, pretty: true)

textarea(form, field, [value: value, rows: 4, placeholder: "JSON Content"] ++ opts)

_ ->
text_input(form, field, opts)
end
Expand Down
33 changes: 21 additions & 12 deletions lib/kaffy/resource_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,15 @@ defmodule Kaffy.ResourceSchema do
value.(schema)

is_map(value) && Map.has_key?(value, :__struct__) ->
if value.__struct__ in [NaiveDateTime, DateTime, Date, Time] do
value
else
Map.from_struct(value)
|> Map.drop([:__meta__])
|> Kaffy.Utils.json().encode!(escape: :html_safe, pretty: true)
cond do
value.__struct__ in [NaiveDateTime, DateTime, Date, Time] ->
value
value.__struct__ in [Geo.Point] ->
Kaffy.Utils.json().encode!(value, escape: :html_safe, pretty: true)
true ->
Map.from_struct(value)
|> Map.drop([:__meta__])
|> Kaffy.Utils.json().encode!(escape: :html_safe, pretty: true)
end

Kaffy.Utils.is_module(ft) && Keyword.has_key?(ft.__info__(:functions), :render_index) ->
Expand All @@ -206,12 +209,15 @@ defmodule Kaffy.ResourceSchema do
value

is_map(value) && Map.has_key?(value, :__struct__) ->
if value.__struct__ in [NaiveDateTime, DateTime, Date, Time] do
value
else
Map.from_struct(value)
|> Map.drop([:__meta__])
|> Kaffy.Utils.json().encode!(escape: :html_safe, pretty: true)
cond do
value.__struct__ in [NaiveDateTime, DateTime, Date, Time] ->
value
value.__struct__ in [Geo.Point] ->
Kaffy.Utils.json().encode!(value, escape: :html_safe, pretty: true)
true ->
Map.from_struct(value)
|> Map.drop([:__meta__])
|> Kaffy.Utils.json().encode!(escape: :html_safe, pretty: true)
end

is_map(value) ->
Expand Down Expand Up @@ -320,6 +326,9 @@ defmodule Kaffy.ResourceSchema do
{_f, %{type: {:array, _}}} ->
true

{_f, %{type: Geo.PostGIS.Geometry}} ->
true

f when is_atom(f) ->
f == :map

Expand Down