defmodule DashboardWeb.Live.UI do import Phoenix.HTML.Form import Phoenix.Component alias DashboardWeb.Live.IconSvg def db_connection_check(assigns \\ %{}) do db_url = Dashboard.Helpers.create_db_url(assigns.changeset.changes) assigns = assign(assigns, :db_url, db_url) # TODO: Maybe add loader for indicating on going db connect check ~H"""
<%= if @db_connection_established do %> CAN CONNECT TO DATABASE! <% else %> COULD NOT CONNECT TO DATABASE! <% end %>

DATABASE URL: <%= @db_url %>

""" end def popup(assigns \\ %{}) do ~H"""
""" end def config_item(assigns \\ %{}) do ~H"""
<.popup title={@tooltip} id={@id} /> <%= if assigns[:checkbox_input] do %>
<%= render_slot(@input, @form) %>
<% end %>
<%= if assigns[:required_input] do %> * <% end %> <%= @title %>
<%= if !assigns[:checkbox_input] do %>
<%= render_slot(@input, @form) %>
<% end %>
""" end def flow_card(assigns \\ %{}) do ~H"""
Infer Schema
<.popup title="Set whether to create database schema" id="insert_schema_popup" />
<%= checkbox(@form, :insert_schema, class: "form-check-input") %> <%= label(@form, :insert_schema, "Create Tables", class: "form-check-label") %>
<.popup title="Set whether to insert the CSVs into the database" id="insert_data_popup" />
<%= checkbox(@form, :insert_data, class: "form-check-input") %> <%= label(@form, :insert_data, class: "form-check-label") %>
""" end @doc """ Generates tag for inlined form input errors. """ def error_tag(form, field) do Enum.map(Keyword.get_values(form.errors, field), fn error -> Phoenix.HTML.Tag.content_tag(:span, translate_error(error), class: "invalid-feedback", phx_feedback_for: input_name(form, field) ) end) end @doc """ Translates an error message. """ def translate_error({msg, opts}) do Enum.reduce(opts, msg, fn {key, value}, acc -> String.replace(acc, "%{#{key}}", fn _ -> to_string(value) end) end) end end