mix format

This commit is contained in:
shibao 2022-01-22 17:21:10 -05:00
parent 421badbb90
commit 16018ae111
15 changed files with 122 additions and 127 deletions

View File

@ -9,8 +9,7 @@ import Config
# manifest is generated by the `mix phx.digest` task, # manifest is generated by the `mix phx.digest` task,
# which you should run after static files are built and # which you should run after static files are built and
# before starting your production server. # before starting your production server.
config :cannery, CanneryWeb.Endpoint, config :cannery, CanneryWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
cache_static_manifest: "priv/static/cache_manifest.json"
config :cannery, Cannery.Repo, config :cannery, Cannery.Repo,
url: "ecto://postgres:postgres@localhost/cannery", url: "ecto://postgres:postgres@localhost/cannery",

View File

@ -23,9 +23,7 @@ defmodule Cannery.Tags do
end end
def list_tags(user_id) do def list_tags(user_id) do
Repo.all( Repo.all(from t in Tag, where: t.user_id == ^user_id)
from t in Tag, where: t.user_id == ^user_id
)
end end
@doc """ @doc """

View File

@ -14,104 +14,98 @@ defmodule CanneryWeb.Component.Topbar do
<div class="flex flex-row justify-between items-center space-x-4"> <div class="flex flex-row justify-between items-center space-x-4">
<div class="flex flex-row justify-start items-center space-x-2"> <div class="flex flex-row justify-start items-center space-x-2">
<%= link to: Routes.live_path(CanneryWeb.Endpoint, HomeLive) do %> <%= link to: Routes.live_path(CanneryWeb.Endpoint, HomeLive) do %>
<h1 class="leading-5 text-xl text-white hover:underline">Cannery</h1> <h1 class="leading-5 text-xl text-white hover:underline">
Cannery
</h1>
<% end %> <% end %>
<%= if @title_content do %> <%= if @title_content do %>
<span>|</span> <span>|</span>
<%= @title_content %> <%= @title_content %>
<% end %> <% end %>
</div> </div>
<ul class="flex flex-row flex-wrap justify-center items-center <ul class="flex flex-row flex-wrap justify-center items-center
space-x-4 text-lg text-white"> space-x-4 text-lg text-white">
<%# user settings %>
<%= if @current_user do %> <%= if @current_user do %>
<li> <li>
<%= link "Tags", class: "hover:underline", <%= link("Tags",
to: Routes.tag_index_path(CanneryWeb.Endpoint, :index) %> class: "hover:underline",
to: Routes.tag_index_path(CanneryWeb.Endpoint, :index)
) %>
</li> </li>
<li> <li>
<%= link "Containers", class: "hover:underline", <%= link("Containers",
to: Routes.container_index_path(CanneryWeb.Endpoint, :index) %> class: "hover:underline",
to: Routes.container_index_path(CanneryWeb.Endpoint, :index)
) %>
</li> </li>
<li> <li>
<%= link "Ammo", class: "hover:underline", <%= link("Ammo",
to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index) %> class: "hover:underline",
to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index)
) %>
</li> </li>
<li> <li>
<%= link "Manage", class: "hover:underline", <%= link("Manage",
to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index) %> class: "hover:underline",
to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index)
) %>
</li> </li>
<%= if @current_user.role == :admin do %> <%= if @current_user.role == :admin do %>
<li> <li>
<%= link "Invites", class: "hover:underline", <%= link("Invites",
to: Routes.invite_index_path(CanneryWeb.Endpoint, :index) %> class: "hover:underline",
to: Routes.invite_index_path(CanneryWeb.Endpoint, :index)
) %>
</li> </li>
<% end %> <% end %>
<%# search %>
<%#
<form phx-change="suggest" phx-submit="search" phx-target="<%= @myself %#>">
<input type="text" name="q" class="input input-primary"
placeholder="Search" list="results" autocomplete="off"/>
<datalist id="results">
<%= for {app, _vsn} <- @results do %#>
<option value={app}><%= app %#></option>
<% end %#>
</datalist>
</form>
%>
<li> <li>
<%= link @current_user.email, class: "hover:underline", <%= link(@current_user.email,
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit) %> class: "hover:underline",
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit)
) %>
</li> </li>
<li> <li>
<%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete), method: :delete, <%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete),
data: [confirm: "Are you sure you want to log out?"] do %> method: :delete,
<i class="fas fa-sign-out-alt"></i> data: [confirm: "Are you sure you want to log out?"] do %>
<i class="fas fa-sign-out-alt">
</i>
<% end %> <% end %>
</li> </li>
<%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %> <%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %>
<li> <li>
<%= link to: Routes.live_dashboard_path(CanneryWeb.Endpoint, :home) do %> <%= link to: Routes.live_dashboard_path(CanneryWeb.Endpoint, :home) do %>
<i class="fas fa-tachometer-alt"></i> <i class="fas fa-tachometer-alt">
</i>
<% end %> <% end %>
</li> </li>
<% end %> <% end %>
<% else %> <% else %>
<%= if Accounts.allow_registration?() do %> <%= if Accounts.allow_registration?() do %>
<li> <li>
<%= link "Register", class: "hover:underline", <%= link("Register",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new) %> class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
) %>
</li> </li>
<% end %> <% end %>
<li> <li>
<%= link "Log in", class: "hover:underline", <%= link("Log in",
to: Routes.user_session_path(CanneryWeb.Endpoint, :new) %> class: "hover:underline",
to: Routes.user_session_path(CanneryWeb.Endpoint, :new)
) %>
</li> </li>
<% end %> <% end %>
</ul> </ul>
</div> </div>
</nav> </nav>
<%= if @flash && @flash |> Map.has_key?(:info) do %> <%= if @flash && @flash |> Map.has_key?(:info) do %>
<p class="alert alert-info" role="alert" <p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
phx-click="lv:clear-flash" phx-value-key="info">
<%= live_flash(@flash, :info) %> <%= live_flash(@flash, :info) %>
</p> </p>
<% end %> <% end %>
<%= if @flash && @flash |> Map.has_key?(:error) do %> <%= if @flash && @flash |> Map.has_key?(:error) do %>
<p class="alert alert-danger" role="alert" <p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
phx-click="lv:clear-flash" phx-value-key="error">
<%= live_flash(@flash, :error) %> <%= live_flash(@flash, :error) %>
</p> </p>
<% end %> <% end %>

View File

@ -31,9 +31,13 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
def render(assigns) do def render(assigns) do
~H""" ~H"""
<div> <div>
<h2><%= @title %></h2> <h2>
<%= @title %>
<.form let={f} for={@changeset}, </h2>
<.form
let={f}
for={@changeset}
,
id="ammo_group-form" id="ammo_group-form"
phx-target={@myself} phx-target={@myself}
phx-change="validate" phx-change="validate"

View File

@ -31,9 +31,12 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
def render(assigns) do def render(assigns) do
~H""" ~H"""
<div> <div>
<h2><%= @title %></h2> <h2>
<%= @title %>
<.form let={f} for={@changeset} </h2>
<.form
let={f}
for={@changeset}
id="ammo_type-form" id="ammo_type-form"
phx-target={@myself} phx-target={@myself}
phx-change="validate" phx-change="validate"

View File

@ -31,9 +31,12 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
def render(assigns) do def render(assigns) do
~H""" ~H"""
<div> <div>
<h2><%= @title %></h2> <h2>
<%= @title %>
<.form let={f} for={@changeset} </h2>
<.form
let={f}
for={@changeset}
id="container-form" id="container-form"
phx-target={@myself} phx-target={@myself}
phx-change="validate" phx-change="validate"

View File

@ -34,8 +34,9 @@ defmodule CanneryWeb.InviteLive.FormComponent do
<h2 class="title text-xl text-primary-500"> <h2 class="title text-xl text-primary-500">
<%= @title %> <%= @title %>
</h2> </h2>
<.form
<.form let={f} for={@changeset} let={f}
for={@changeset}
id="invite-form" id="invite-form"
class="grid grid-cols-3 justify-center items-center space-y-4" class="grid grid-cols-3 justify-center items-center space-y-4"
phx-target={@myself} phx-target={@myself}
@ -45,17 +46,17 @@ defmodule CanneryWeb.InviteLive.FormComponent do
<%= label f, :name, class: "title text-lg text-primary-500" %> <%= label f, :name, class: "title text-lg text-primary-500" %>
<%= text_input f, :name, class: "input input-primary col-span-2" %> <%= text_input f, :name, class: "input input-primary col-span-2" %>
<span class="col-span-3"> <span class="col-span-3">
<%= error_tag f, :name %> <%= error_tag(f, :name) %>
</span> </span>
<%= label(f, :uses_left, class: "title text-lg text-primary-500") %>
<%= label f, :uses_left, class: "title text-lg text-primary-500" %> <%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %>
<%= number_input f, :uses_left, min: 0, class: "input input-primary col-span-2" %>
<span class="col-span-3"> <span class="col-span-3">
<%= error_tag f, :uses_left %> <%= error_tag(f, :uses_left) %>
</span> </span>
<%= submit("Save",
<%= submit "Save", class: "mx-auto btn btn-primary col-span-3", class: "mx-auto btn btn-primary col-span-3",
phx_disable_with: "Saving..." %> phx_disable_with: "Saving..."
) %>
</.form> </.form>
</div> </div>
""" """
@ -71,7 +72,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)} {:noreply, assign(socket, :changeset, changeset)}
end end
end end
defp save_invite(socket, :new, invite_params) do defp save_invite(socket, :new, invite_params) do

View File

@ -4,7 +4,9 @@ defmodule CanneryWeb.ModalComponent do
@impl true @impl true
def render(assigns) do def render(assigns) do
~H""" ~H"""
<div id={@id} class="fixed z-10 left-0 top-0 <div
id={@id}
class="fixed z-10 left-0 top-0
w-full h-full overflow-hidden w-full h-full overflow-hidden
p-8 flex flex-col justify-center items-center" p-8 flex flex-col justify-center items-center"
style="opacity: 1 !important; background-color: rgba(0,0,0,0.4);" style="opacity: 1 !important; background-color: rgba(0,0,0,0.4);"
@ -12,21 +14,19 @@ defmodule CanneryWeb.ModalComponent do
phx-window-keydown="close" phx-window-keydown="close"
phx-key="escape" phx-key="escape"
phx-target={"#{@id}"} phx-target={"#{@id}"}
phx-page-loading> phx-page-loading
>
<div class="w-full max-w-4xl relative <div class="w-full max-w-4xl relative
p-8 flex flex-col justify-start items-center p-8 flex flex-col justify-start items-center
bg-white border-2 rounded-lg"> bg-white border-2 rounded-lg">
<%# close button %>
<%= live_patch to: @return_to, <%= live_patch to: @return_to,
class: "absolute top-8 right-10 text-gray-500 hover:text-gray-800 class:
transition-all duration-500 ease-in-out" do %> "absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out" do %>
<i class="fa-fw fa-lg fas fa-times"></i> <i class="fa-fw fa-lg fas fa-times">
</i>
<% end %> <% end %>
<%# modal content %>
<div class="w-full flex flex-col space-y-4 justify-center items-center"> <div class="w-full flex flex-col space-y-4 justify-center items-center">
<%= live_component @component, @opts %> <%= live_component(@component, @opts) %>
</div> </div>
</div> </div>
</div> </div>

View File

@ -37,8 +37,9 @@ defmodule CanneryWeb.TagLive.FormComponent do
<h2 class="title text-xl text-primary-500"> <h2 class="title text-xl text-primary-500">
<%= @title %> <%= @title %>
</h2> </h2>
<.form
<.form let={f} for={@changeset} let={f}
for={@changeset}
id="tag-form" id="tag-form"
class="grid grid-cols-3 justify-center items-center space-y-4" class="grid grid-cols-3 justify-center items-center space-y-4"
phx-target={@myself} phx-target={@myself}
@ -48,27 +49,26 @@ defmodule CanneryWeb.TagLive.FormComponent do
<%= label f, :name, class: "title text-lg text-primary-500" %> <%= label f, :name, class: "title text-lg text-primary-500" %>
<%= text_input f, :name, class: "input input-primary col-span-2" %> <%= text_input f, :name, class: "input input-primary col-span-2" %>
<span class="col-span-3"> <span class="col-span-3">
<%= error_tag f, :name %> <%= error_tag(f, :name) %>
</span> </span>
<%= label(f, :bg_color, class: "title text-lg text-primary-500") %>
<%= label f, :bg_color, class: "title text-lg text-primary-500" %>
<span class="mx-auto col-span-2" phx-update="ignore"> <span class="mx-auto col-span-2" phx-update="ignore">
<%= color_input f, :bg_color, value: random_color() %> <%= color_input(f, :bg_color, value: random_color()) %>
</span> </span>
<span class="col-span-3"> <span class="col-span-3">
<%= error_tag f, :bg_color %> <%= error_tag(f, :bg_color) %>
</span> </span>
<%= label(f, :text_color, class: "title text-lg text-primary-500") %>
<%= label f, :text_color, class: "title text-lg text-primary-500" %>
<span class="mx-auto col-span-2" phx-update="ignore"> <span class="mx-auto col-span-2" phx-update="ignore">
<%= color_input f, :text_color, value: "#ffffff" %> <%= color_input(f, :text_color, value: "#ffffff") %>
</span> </span>
<span class="col-span-3"> <span class="col-span-3">
<%= error_tag f, :text_color %> <%= error_tag(f, :text_color) %>
</span> </span>
<%= submit("Save",
<%= submit "Save", class: "mx-auto btn btn-primary col-span-3", class: "mx-auto btn btn-primary col-span-3",
phx_disable_with: "Saving..." %> phx_disable_with: "Saving..."
) %>
</.form> </.form>
</div> </div>
""" """

View File

@ -1,21 +1,18 @@
<main role="main" class="container min-h-full min-w-full"> <main role="main" class="container min-h-full min-w-full">
<header class="mb-4 px-8 py-4 w-full bg-primary-400"> <header class="mb-4 px-8 py-4 w-full bg-primary-400">
<%= render "topbar.html", assigns %> <%= render("topbar.html", assigns) %>
</header> </header>
<div class="mx-8 my-2 flex flex-col space-y-4 text-center"> <div class="mx-8 my-2 flex flex-col space-y-4 text-center">
<%= if get_flash(@conn, :info) do %> <%= if get_flash(@conn, :info) do %>
<p class="alert alert-info" role="alert"> <p class="alert alert-info" role="alert">
<%= get_flash(@conn, :info) %> <%= get_flash(@conn, :info) %>
</p> </p>
<% end %> <% end %>
<%= if get_flash(@conn, :error) do %> <%= if get_flash(@conn, :error) do %>
<p class="alert alert-danger" role="alert"> <p class="alert alert-danger" role="alert">
<%= get_flash(@conn, :error) %> <%= get_flash(@conn, :error) %>
</p> </p>
<% end %> <% end %>
</div> </div>
<%= @inner_content %> <%= @inner_content %>
</main> </main>

View File

@ -1,28 +1,19 @@
<main class="container min-w-full min-h-full"> <main class="container min-w-full min-h-full">
<header> <header>
<CanneryWeb.Component.Topbar.topbar <CanneryWeb.Component.Topbar.topbar current_user={assigns[:current_user]}>
current_user={assigns[:current_user]}>
</CanneryWeb.Component.Topbar.topbar> </CanneryWeb.Component.Topbar.topbar>
<div class="mx-8 my-2 flex flex-col space-y-4 text-center"> <div class="mx-8 my-2 flex flex-col space-y-4 text-center">
<%= if @flash && @flash |> Map.has_key?(:info) do %> <%= if @flash && @flash |> Map.has_key?(:info) do %>
<p class="alert alert-info" role="alert" <p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
phx-click="lv:clear-flash"
phx-value-key="info">
<%= live_flash(@flash, :info) %> <%= live_flash(@flash, :info) %>
</p> </p>
<% end %> <% end %>
<%= if @flash && @flash |> Map.has_key?(:error) do %> <%= if @flash && @flash |> Map.has_key?(:error) do %>
<p class="alert alert-danger" role="alert" <p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
phx-click="lv:clear-flash"
phx-value-key="error">
<%= live_flash(@flash, :error) %> <%= live_flash(@flash, :error) %>
</p> </p>
<% end %> <% end %>
</div> </div>
</header> </header>
<%= @inner_content %> <%= @inner_content %>
</main> </main>

View File

@ -1,13 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<%= csrf_meta_tag() %> <%= csrf_meta_tag() %>
<%= live_title_tag assigns[:page_title] || "Cannery", suffix: "" %> <%= live_title_tag(assigns[:page_title] || "Cannery", suffix: "") %>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")}/> <link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")} />
<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/js/app.js")}></script> <script
defer
phx-track-static
type="text/javascript"
src={Routes.static_path(@conn, "/js/app.js")}
>
</script>
</head> </head>
<body class="m-0 p-0 min-w-full min-h-full"> <body class="m-0 p-0 min-w-full min-h-full">
<%= @inner_content %> <%= @inner_content %>

View File

@ -13,6 +13,5 @@ defmodule Cannery.Repo.Migrations.CreateAmmoTypes do
timestamps() timestamps()
end end
end end
end end