Skip to content

Commit

Permalink
Merge pull request #1 from IvanIvanoff/apply-changes
Browse files Browse the repository at this point in the history
Apply changes
  • Loading branch information
IvanIvanoff authored May 27, 2020
2 parents 70e672e + 5d12298 commit 8d72877
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 126 deletions.
1 change: 0 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use Mix.Config
# ]
config :ex_admin,
repo: MyProject.Repo,
module: MyProject,
modules: [],
module: ExAdmin

Expand Down
2 changes: 1 addition & 1 deletion lib/ex_admin/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ defmodule ExAdmin.Filter do
end)
end

def string_selected_name(name, nil), do: "#{name}_equals"
def string_selected_name(name, nil), do: "#{name}_contains"

def string_selected_name(name, q) do
Enum.reduce(string_options(), "#{name}_eq", fn {k, _}, acc ->
Expand Down
4 changes: 3 additions & 1 deletion lib/ex_admin/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,9 @@ defmodule ExAdmin.Form do
val = Integer.to_string(x)
{val, val}
end)
_ -> value

_ ->
value
end

select "", [{:class, "form-control date-time"} | opts] do
Expand Down
1 change: 1 addition & 0 deletions lib/ex_admin/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ defmodule ExAdmin.Index do
import ExAdmin.Gettext
import Kernel, except: [div: 2, to_string: 1]
use Xain

# alias ExAdmin.Schema

@doc false
Expand Down
3 changes: 2 additions & 1 deletion lib/ex_admin/render.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Phoenix.HTML

defprotocol ExAdmin.Render do
# @fallback_to_any true
Expand All @@ -10,7 +11,7 @@ defimpl ExAdmin.Render, for: Atom do
end

defimpl ExAdmin.Render, for: BitString do
def to_string(data), do: data
def to_string(data), do: data |> html_escape |> Phoenix.HTML.safe_to_string()
end

defimpl ExAdmin.Render, for: Integer do
Expand Down
1 change: 1 addition & 0 deletions lib/ex_admin/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule ExAdmin.Schema do
end

def type(%Ecto.Query{from: %Ecto.Query.FromExpr{source: {_, mod}}}, key), do: type(mod, key)

def type(module, key) when is_atom(module) do
module.__schema__(:type, key)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/ex_admin/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule ExAdmin.Show do
import ExAdmin.Utils
import ExAdmin.ViewHelpers
_ = var!(resource)
_ = unquote(resource) # allow others downstream to not have warnings of not using
# allow others downstream to not have warnings of not using
_ = unquote(resource)

markup safe: true do
unquote(contents)
Expand Down
54 changes: 30 additions & 24 deletions lib/ex_admin/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ Code.ensure_compiled(ExAdmin.Utils)

defmodule ExAdmin.Table do
@moduledoc false
require Integer
use Xain
import ExAdmin.Helpers
import ExAdmin.Utils
import ExAdmin.Render
import ExAdmin.Theme.Helpers
import Kernel, except: [to_string: 1]

alias ExAdmin.Schema

require Integer

def attributes_table(conn, resource, schema) do
theme_module(conn, Table).theme_attributes_table(conn, resource, schema, model_name(resource))
end
Expand Down Expand Up @@ -90,8 +92,7 @@ defmodule ExAdmin.Table do
build_field(resource, conn, {f_name, Enum.into(opts, %{})}, fn contents, f_name ->
td ".td-#{parameterize(f_name)}" do
contents
|> HtmlSanitizeEx.html5()
# |> Phoenix.HTML.raw()
|> Phoenix.HTML.raw()
end
end)
end
Expand Down Expand Up @@ -122,11 +123,13 @@ defmodule ExAdmin.Table do

def do_panel(conn, columns \\ [], table_opts \\ [], output \\ [])

def do_panel(_conn, [], _table_opts, output),
do:
output
|> Enum.reverse()
|> Enum.join()
def do_panel(_conn, [] = columns, table_opts, output) do
output
|> Enum.reverse()
|> Enum.map(fn x -> x |> Phoenix.HTML.html_escape() |> Phoenix.HTML.safe_to_string() end)
|> Enum.join()
|> Phoenix.HTML.raw()
end

def do_panel(
conn,
Expand Down Expand Up @@ -156,8 +159,11 @@ defmodule ExAdmin.Table do
def do_panel(conn, [{:contents, %{contents: content}} | tail], table_opts, output) do
output = [
case content do
{:safe, _} -> Phoenix.HTML.safe_to_string(content)
content -> content
{:safe, _} ->
Phoenix.HTML.safe_to_string(content)

content ->
content
end
|> Xain.raw()
| output
Expand Down Expand Up @@ -309,8 +315,7 @@ defmodule ExAdmin.Table do
td to_class(".td-", field_name) do
contents
|> text()
|> HtmlSanitizeEx.html5()
# |> Phoenix.HTML.raw()
|> Phoenix.HTML.raw()
end
end
end
Expand All @@ -320,26 +325,27 @@ defmodule ExAdmin.Table do
end

def handle_contents(contents, field_name) when is_list(contents) do
content = contents
|> Enum.map(fn(content) ->
content
|> HtmlSanitizeEx.html5()
# |> Phoenix.HTML.raw()
end)
|> Enum.join(" ")
_res = markup do
td to_class(".td-", field_name) do
content =
contents
|> Enum.map(fn content ->
content
|> Phoenix.HTML.raw()
end)
|> Enum.join(" ")

_res =
markup do
td to_class(".td-", field_name) do
content
end
end
end
end

def handle_contents(contents, field_name) do
markup do
td to_class(".td-", field_name) do
contents
|> HtmlSanitizeEx.html5()
# |> Phoenix.HTML.raw()
|> Phoenix.HTML.raw()
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ex_admin/themes/active_admin/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ defmodule ExAdmin.Theme.ActiveAdmin.Filter do

def build_field({name, type}, q, defn)
when type in [
# Ecto.DateTime,
# Ecto.Date,
# Ecto.Time,
# Ecto.DateTime,
# Ecto.Date,
# Ecto.Time,
Date,
Time,
Timex.Ecto.DateTime,
Expand Down
2 changes: 2 additions & 0 deletions lib/ex_admin/themes/admin_lte2/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ defmodule ExAdmin.Theme.AdminLte2.Form do
case item do
bin when is_binary(bin) ->
{htmls <> bin, chgs}

{:safe, change} ->
{htmls, [change | chgs]}

{bin, change} ->
{htmls <> bin, [change | chgs]}
end
Expand Down
1 change: 1 addition & 0 deletions lib/ex_admin/view_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ defmodule ExAdmin.ViewHelpers do
],
%{}
)

# {~S(\"), ~S(\\")},

def escape_javascript(unescaped) do
Expand Down
27 changes: 16 additions & 11 deletions lib/mix/tasks/admin.gen.resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ defmodule Mix.Tasks.Admin.Gen.Resource do
defp copy_file(%Config{module: module, package_path: package_path} = config) do
filename = Path.basename(Macro.underscore(module)) <> ".ex"

web_dir = Path.wildcard("lib/*_web") |> hd # TODO: use app_web_path

dest_path = case Macro.underscore(Blog.Post) |> Path.dirname do #Path.join(~w(web admin))
"." ->
Path.join([web_dir, "admin"])
dir ->
if !File.exists? Path.join([web_dir, "admin", dir]) do
Path.join([web_dir, "admin", dir])|> File.mkdir
end
Path.join([web_dir, "admin", dir])
end
# TODO: use app_web_path
web_dir = Path.wildcard("lib/*_web") |> hd

# Path.join(~w(web admin))
dest_path =
case Macro.underscore(Blog.Post) |> Path.dirname() do
"." ->
Path.join([web_dir, "admin"])

dir ->
if !File.exists?(Path.join([web_dir, "admin", dir])) do
Path.join([web_dir, "admin", dir]) |> File.mkdir()
end

Path.join([web_dir, "admin", dir])
end

dest_file_path = Path.join(dest_path, filename)
source_file = Path.join([package_path | ~w(priv templates admin.gen.resource resource.exs)])
Expand Down
13 changes: 10 additions & 3 deletions lib/mix/tasks/admin.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ defmodule Mix.Tasks.Admin.Install do
defp copy_vendor(from_path, path, filename) do
dest = Path.join([File.cwd!(), "assets", "static", path])
File.mkdir_p(dest)
IO.puts("copying #{Path.join([get_package_path(), from_path, path, filename])} -> #{Path.join([dest, filename])}")

IO.puts(
"copying #{Path.join([get_package_path(), from_path, path, filename])} -> #{
Path.join([dest, filename])
}"
)

File.cp(
Path.join([get_package_path(), from_path, path, filename]),
Path.join([dest, filename])
Expand All @@ -292,9 +298,10 @@ defmodule Mix.Tasks.Admin.Install do
defp copy_vendor_r(base_path, path) do
dest_dir = Path.join([File.cwd!(), "assets", "static", path])
File.mkdir_p(dest_dir)

Path.join([get_package_path(), base_path, path])
|> File.ls!
|> Enum.each(fn(file) ->
|> File.ls!()
|> Enum.each(fn file ->
dest = Path.join([dest_dir, file])
IO.puts("Copying #{Path.join([get_package_path(), base_path, path, file])} -> #{dest}")
File.cp_r(Path.join([get_package_path(), base_path, path, file]), dest)
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule ExAdmin.Mixfile do
[
{:decimal, "~> 1.0"},
{:phoenix, "~> 1.4"},
{:phoenix_html, "~> 2.6"},
{:phoenix_html, "~> 2.12"},
{:ecto, "~> 3.0"},
{:phoenix_ecto, "~> 4.0"},
{:postgrex, "~> 0.14", only: :test},
Expand All @@ -69,7 +69,7 @@ defmodule ExAdmin.Mixfile do
{:plug_cowboy, "~> 2.0"},
{:inflex, "~> 1.7"},
{:scrivener_ecto, "~> 2.0"},
{:xain, "0.6.1"}, #TODO: https://github.com/smpallen99/xain/issues/20
{:xain, "0.6.2"},
{:csvlixir, "~> 1.0.0"},
{:exactor, "~> 2.2.0"},
{:ex_doc, "~> 0.16.2", only: :dev},
Expand Down
Loading

0 comments on commit 8d72877

Please sign in to comment.