diff --git a/config/test.exs b/config/test.exs index 67467d7..bae8c17 100644 --- a/config/test.exs +++ b/config/test.exs @@ -8,8 +8,8 @@ config :alkemist, ecto_repos: [Alkemist.Repo] config :alkemist, Alkemist.Repo, adapter: Ecto.Adapters.Postgres, - username: System.get_env("PG_USER"), - password: System.get_env("PG_PASSWORD"), + username: System.get_env("PG_USER") || "postgres", + password: System.get_env("PG_PASSWORD") || "postgres", database: "alkemist_test", hostname: "localhost", pool: Ecto.Adapters.SQL.Sandbox diff --git a/lib/alkemist/assign.ex b/lib/alkemist/assign.ex index 5d5f5ab..3f3ba44 100644 --- a/lib/alkemist/assign.ex +++ b/lib/alkemist/assign.ex @@ -561,11 +561,6 @@ defmodule Alkemist.Assign do {scope, opts, callback} end - defp map_scope({scope, opts}, query, repo), - do: map_scope({scope, opts, fn q -> q end}, query, params, repo) - - defp map_scope(scope, query, repo), do: map_scope({scope, []}, query, params, repo) - # Merges the scope callback into the query defp scope(query, scopes) do current = Enum.find(scopes, fn {_s, opts, _cb} -> opts[:active] == true end) diff --git a/lib/alkemist/controller.ex b/lib/alkemist/controller.ex index 90e9dc4..36e2f87 100644 --- a/lib/alkemist/controller.ex +++ b/lib/alkemist/controller.ex @@ -127,7 +127,7 @@ defmodule Alkemist.Controller do default is `:string`. If the type is `:select`, a collection to build the select must be passed (see `Phoenix.HTMl.Form.select/4`) """ @type filter :: atom() | keyword() - @type field :: atom() | {atom(), map()} | %{title: string(), fields: [{atom(), map()}]} + @type field :: atom() | {atom(), map()} | %{title: String.t(), fields: [{atom(), map()}]} Module.register_attribute __MODULE__, :menu_items, accumulate: true, persist: true diff --git a/lib/alkemist/menu_registry.ex b/lib/alkemist/menu_registry.ex index 9b91123..adbcfbd 100644 --- a/lib/alkemist/menu_registry.ex +++ b/lib/alkemist/menu_registry.ex @@ -91,8 +91,11 @@ defmodule Alkemist.MenuRegistry do end end - defp cache_path(path \\ nil) do - if is_nil(path), do: path = Alkemist.Config.get(:web_interface) + defp cache_path do + cache_path(Alkemist.Config.get(:web_interface)) + end + + defp cache_path(path) do Path.join([System.tmp_dir!(), "#{path}", "alkemist"]) end @@ -160,11 +163,19 @@ defmodule Alkemist.MenuRegistry do defp build_tree([], results), do: results + defp ensure_setup, do: do_ensure_setup(cache_path()) + + defp ensure_setup(module) do + module + |> to_string() + |> app_from_module() + |> cache_path() + |> do_ensure_setup() + end - defp ensure_setup(module \\ nil) do - unless is_nil(module), do: module = app_from_module(to_string(module)) - unless File.exists?(cache_path(module)) do - File.mkdir_p(cache_path(module)) + defp do_ensure_setup(cache_path) do + unless File.exists?(cache_path) do + File.mkdir_p(cache_path) end end end diff --git a/lib/alkemist/query/paginate.ex b/lib/alkemist/query/paginate.ex index 22f6b1c..dffb3e7 100644 --- a/lib/alkemist/query/paginate.ex +++ b/lib/alkemist/query/paginate.ex @@ -15,7 +15,7 @@ defmodule Alkemist.Query.Paginate do """ def run(query, params, opts \\ []) do - query = Turbo.Ecto.paginateq(query, params) + query = Turbo.Ecto.Builder.run(query, params) pagination = Turbo.Ecto.Hooks.Paginate.get_paginate(query, params, opts) {query, pagination} diff --git a/lib/alkemist/query/search.ex b/lib/alkemist/query/search.ex index 3dda801..a157af7 100644 --- a/lib/alkemist/query/search.ex +++ b/lib/alkemist/query/search.ex @@ -7,7 +7,7 @@ defmodule Alkemist.Query.Search do @empty_values [nil, [], {}, [""], "", %{}] def run(query, params) do - searchq(query, params) |> Turbo.Ecto.sortq(params) + searchq(query, params) |> Turbo.Ecto.Builder.run(params) end def searchq(query, params) do @@ -15,11 +15,11 @@ defmodule Alkemist.Query.Search do params |> prepare_params(query) - Turbo.Ecto.searchq(query, params) + Turbo.Ecto.Builder.run(query, params) end def sortq(query, params) do - Turbo.Ecto.sortq(query, params) + Turbo.Ecto.Builder.run(query, params) end @doc """ @@ -27,7 +27,7 @@ defmodule Alkemist.Query.Search do right now this works not on associations """ def prepare_params(params, query) do - queryable = Turbo.Ecto.Utils.schema_from_query(query) + queryable = Turbo.Ecto.Builder.extract_schema(query) search_params = params diff --git a/lib/alkemist/templates/index.html.eex b/lib/alkemist/templates/index.html.eex index d541838..bd6ab5b 100644 --- a/lib/alkemist/templates/index.html.eex +++ b/lib/alkemist/templates/index.html.eex @@ -29,7 +29,7 @@ <%= if any?(@batch_actions) do %>
@@ -69,7 +69,7 @@ | - <%= else %> + <% else %> | <%= if Map.has_key?(opts, :action) and not is_nil(opts.action) and not is_nil(Map.get(row, opts.assoc)) do %> <%= string_value(cb, row) %> diff --git a/lib/alkemist/views/form_view.ex b/lib/alkemist/views/form_view.ex index 2ec5b17..1257360 100644 --- a/lib/alkemist/views/form_view.ex +++ b/lib/alkemist/views/form_view.ex @@ -326,8 +326,7 @@ defmodule Alkemist.FormView do defp build_empty_form_template(type, form, {key, _opts} = field) do assoc = case type do :association -> Alkemist.Utils.get_association(form.data, key) - :embed -> - assoc = Alkemist.Utils.get_embed(form.data, key) + :embed -> Alkemist.Utils.get_embed(form.data, key) end case assoc do %{cardinality: :many, queryable: queryable} -> @@ -360,14 +359,6 @@ defmodule Alkemist.FormView do |> String.replace("#{key}_0", "#{key}_$index") |> String.replace("[#{key}][0]", "[#{key}][$index]") - %{cardinality: :many, related: related} -> - source = form.source - - source = Map.put(source, :changes, Map.put(%{}, key, related.__struct__)) - form = Map.put(form, :source, source) - - Phoenix.HTML.safe_to_string(render_has_one_inputs(form, field, true)) - _ -> "" end diff --git a/lib/alkemist/views/search_view.ex b/lib/alkemist/views/search_view.ex index 192f172..31fa845 100644 --- a/lib/alkemist/views/search_view.ex +++ b/lib/alkemist/views/search_view.ex @@ -73,7 +73,7 @@ defmodule Alkemist.SearchView do select(form, field, collection, class: "form-control form-control-sm", prompt: "Choose...") end - def input_field(form, field, :date, opts) do + def input_field(form, field, :date, _opts) do to_field = String.replace(Atom.to_string(field), "gteq", "lteq") |> String.to_atom() [ text_input(form, field, class: "form-control form-control-sm datepicker", placeholder: "From"), diff --git a/lib/alkemist/views/view.ex b/lib/alkemist/views/view.ex index aaaf9bf..0fcf907 100644 --- a/lib/alkemist/views/view.ex +++ b/lib/alkemist/views/view.ex @@ -69,7 +69,7 @@ defmodule AlkemistView do @doc """ Create a link to the export action """ - def export_action(conn, struct, assigns \\ []) do + def export_action(conn, struct, _assigns \\ []) do query_params = get_default_link_params(conn) diff --git a/mix.exs b/mix.exs index dfb5835..ce651ea 100644 --- a/mix.exs +++ b/mix.exs @@ -12,6 +12,7 @@ defmodule Alkemist.MixProject do start_permanent: Mix.env() == :prod, build_embedded: Mix.env() == :prod, deps: deps(), + aliases: aliases(), # Hex description: description(), @@ -57,14 +58,14 @@ defmodule Alkemist.MixProject do defp deps do [ {:phoenix, "~> 1.3 or ~> 1.4"}, - {:phoenix_ecto, "~> 3.6"}, + {:phoenix_ecto, "~> 4.0"}, {:phoenix_html, "~> 2.10"}, - {:ecto, "~> 2.2"}, + {:ecto, "~> 3.0"}, {:inflex, "~> 1.10.0"}, {:atomic_map, "~> 0.9.3"}, {:csv, "~> 2.0"}, - {:turbo_ecto, "~> 0.1.7"}, - {:phoenix_mtm, "~> 0.5.1"}, + {:turbo_ecto, git: "git@github.com:zven21/turbo_ecto.git"}, + {:phoenix_mtm, "~> 1.0.0"}, # Test and dev {:credo, "~> 0.10.0", only: [:dev, :test], runtime: false}, {:excoveralls, "~> 0.10.0", only: :test}, @@ -98,4 +99,10 @@ defmodule Alkemist.MixProject do Provides some helper methods to build manager and admin applications quicker """ end + + defp aliases do + [ + test: ["ecto.create --quiet", "test"] + ] + end end diff --git a/mix.lock b/mix.lock index e3309db..1706fe3 100644 --- a/mix.lock +++ b/mix.lock @@ -5,10 +5,11 @@ "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "credo": {:hex, :credo, "0.10.2", "03ad3a1eff79a16664ed42fc2975b5e5d0ce243d69318060c626c34720a49512", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, "csv": {:hex, :csv, "2.1.1", "a4c1a7c30d2151b6e4976cb2f52c0a1d49ec965afb737ed84a684bc4284d1627", [:mix], [{:parallel_stream, "~> 1.0.4", [hex: :parallel_stream, repo: "hexpm", optional: false]}], "hexpm"}, - "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, - "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, + "db_connection": {:hex, :db_connection, "2.0.3", "b4e8aa43c100e16f122ccd6798cd51c48c79fd391c39d411f42b3cd765daccb0", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, + "decimal": {:hex, :decimal, "1.6.0", "bfd84d90ff966e1f5d4370bdd3943432d8f65f07d3bab48001aebd7030590dcc", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"}, - "ecto": {:hex, :ecto, "2.2.11", "4bb8f11718b72ba97a2696f65d247a379e739a0ecabf6a13ad1face79844791c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, + "ecto": {:hex, :ecto, "3.0.5", "bf9329b56f781a67fdb19e92e6d9ed79c5c8b31d41653b79dafb7ceddfbe87e0", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, + "ecto_sql": {:hex, :ecto_sql, "3.0.3", "dd17f2401a69bb2ec91d5564bd259ad0bc63ee32c2cb2e616d04f1559801dba6", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.4", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.2.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "excoveralls": {:hex, :excoveralls, "0.10.2", "fb4abd5b8a1b9d52d35e1162e7e2ea8bfb84b47ae07c38d39aa8ce64be0b0794", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, "gettext": {:hex, :gettext, "0.16.0", "4a7e90408cef5f1bf57c5a39e2db8c372a906031cc9b1466e963101cb927dafc", [:mix], [], "hexpm"}, @@ -19,23 +20,24 @@ "inflex": {:hex, :inflex, "1.10.0", "8366a7696e70e1813aca102e61274addf85d99f4a072b2f9c7984054ea1b9d29", [:mix], [], "hexpm"}, "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, - "mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"}, + "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, "mochiweb": {:hex, :mochiweb, "2.18.0", "eb55f1db3e6e960fac4e6db4e2db9ec3602cc9f30b86cd1481d56545c3145d2e", [:rebar3], [], "hexpm"}, "parallel_stream": {:hex, :parallel_stream, "1.0.6", "b967be2b23f0f6787fab7ed681b4c45a215a81481fb62b01a5b750fa8f30f76c", [:mix], [], "hexpm"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, "phoenix": {:hex, :phoenix, "1.3.4", "aaa1b55e5523083a877bcbe9886d9ee180bf2c8754905323493c2ac325903dc5", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, - "phoenix_ecto": {:hex, :phoenix_ecto, "3.6.0", "d65dbcedd6af568d8582dcd7da516c3051016bad51f9953e5337fea40bcd8a9d", [:mix], [{:ecto, "~> 2.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, - "phoenix_html": {:hex, :phoenix_html, "2.12.0", "1fb3c2e48b4b66d75564d8d63df6d53655469216d6b553e7e14ced2b46f97622", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, - "phoenix_mtm": {:hex, :phoenix_mtm, "0.5.1", "22a9b4ee16e3455bcef32e7408d2fa64d4f2b6d0c020c1e1efc896d09ce9a335", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"}, + "phoenix_ecto": {:hex, :phoenix_ecto, "4.0.0", "c43117a136e7399ea04ecaac73f8f23ee0ffe3e07acfcb8062fe5f4c9f0f6531", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_html": {:hex, :phoenix_html, "2.13.0", "3bad10de5efb6c590f7aa5b316ad0d3faa054715414c9b562c410de4ffb885c5", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_mtm": {:hex, :phoenix_mtm, "1.0.0", "36a2292f84f0712aa4fa029cb6618d9388371d70951b0269bdf372df576aab56", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"}, "plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"}, "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, - "postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"}, + "postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, - "turbo_ecto": {:hex, :turbo_ecto, "0.1.7", "5265b20c0899a3b95713bcdc3111fb27a136ffed9e3829832f707a1fb76cd087", [:mix], [{:ecto, "~> 2.2", [hex: :ecto, repo: "hexpm", optional: false]}], "hexpm"}, + "telemetry": {:hex, :telemetry, "0.2.0", "5b40caa3efe4deb30fb12d7cd8ed4f556f6d6bd15c374c2366772161311ce377", [:mix], [], "hexpm"}, + "turbo_ecto": {:git, "git@github.com:zven21/turbo_ecto.git", "17b9933f6e7976590660bf92c8668fe01d245646", []}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, } diff --git a/test/support/repo.ex b/test/support/repo.ex index bff7f84..4f3a75b 100644 --- a/test/support/repo.ex +++ b/test/support/repo.ex @@ -1,3 +1,3 @@ defmodule Alkemist.Repo do - use Ecto.Repo, otp_app: :alkemist + use Ecto.Repo, otp_app: :alkemist, adapter: Ecto.Adapters.Postgres end |
---|