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,
# which you should run after static files are built and
# before starting your production server.
config :cannery, CanneryWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json"
config :cannery, CanneryWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
config :cannery, Cannery.Repo,
url: "ecto://postgres:postgres@localhost/cannery",

View File

@ -1,18 +1,18 @@
defmodule Cannery.Repo.Migrator do
use GenServer
require Logger
def start_link(_) do
GenServer.start_link(__MODULE__, [], [])
end
def init(_) do
migrate!()
{:ok, nil}
end
def migrate! do
path = Application.app_dir(:cannery, "priv/repo/migrations")
Ecto.Migrator.run(Cannery.Repo, path, :up, all: true)
end
end
end

View File

@ -23,9 +23,7 @@ defmodule Cannery.Tags do
end
def list_tags(user_id) do
Repo.all(
from t in Tag, where: t.user_id == ^user_id
)
Repo.all(from t in Tag, where: t.user_id == ^user_id)
end
@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-start items-center space-x-2">
<%= 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 %>
<%= if @title_content do %>
<span>|</span>
<%= @title_content %>
<% end %>
</div>
<ul class="flex flex-row flex-wrap justify-center items-center
space-x-4 text-lg text-white">
<%# user settings %>
<%= if @current_user do %>
<li>
<%= link "Tags", class: "hover:underline",
to: Routes.tag_index_path(CanneryWeb.Endpoint, :index) %>
<%= link("Tags",
class: "hover:underline",
to: Routes.tag_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<li>
<%= link "Containers", class: "hover:underline",
to: Routes.container_index_path(CanneryWeb.Endpoint, :index) %>
<%= link("Containers",
class: "hover:underline",
to: Routes.container_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<li>
<%= link "Ammo", class: "hover:underline",
to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index) %>
<%= link("Ammo",
class: "hover:underline",
to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<li>
<%= link "Manage", class: "hover:underline",
to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index) %>
<%= link("Manage",
class: "hover:underline",
to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<%= if @current_user.role == :admin do %>
<li>
<%= link "Invites", class: "hover:underline",
to: Routes.invite_index_path(CanneryWeb.Endpoint, :index) %>
<%= link("Invites",
class: "hover:underline",
to: Routes.invite_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<% 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>
<%= link @current_user.email, class: "hover:underline",
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit) %>
<%= link(@current_user.email,
class: "hover:underline",
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit)
) %>
</li>
<li>
<%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete), method: :delete,
data: [confirm: "Are you sure you want to log out?"] do %>
<i class="fas fa-sign-out-alt"></i>
<%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete),
method: :delete,
data: [confirm: "Are you sure you want to log out?"] do %>
<i class="fas fa-sign-out-alt">
</i>
<% end %>
</li>
<%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %>
<li>
<%= 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 %>
</li>
<% end %>
<% else %>
<%= if Accounts.allow_registration?() do %>
<li>
<%= link "Register", class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new) %>
<%= link("Register",
class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
) %>
</li>
<% end %>
<li>
<%= link "Log in", class: "hover:underline",
to: Routes.user_session_path(CanneryWeb.Endpoint, :new) %>
<%= link("Log in",
class: "hover:underline",
to: Routes.user_session_path(CanneryWeb.Endpoint, :new)
) %>
</li>
<% end %>
</ul>
</div>
</nav>
<%= if @flash && @flash |> Map.has_key?(:info) do %>
<p class="alert alert-info" role="alert"
phx-click="lv:clear-flash" phx-value-key="info">
<p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
<%= live_flash(@flash, :info) %>
</p>
<% end %>
<%= if @flash && @flash |> Map.has_key?(:error) do %>
<p class="alert alert-danger" role="alert"
phx-click="lv:clear-flash" phx-value-key="error">
<p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
<%= live_flash(@flash, :error) %>
</p>
<% end %>

View File

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

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ defmodule CanneryWeb.LiveHelpers do
Accounts.get_user_by_session_token(user_token)
end)
end
def assign_defaults(socket, _session) do
socket
end

View File

@ -4,7 +4,9 @@ defmodule CanneryWeb.ModalComponent do
@impl true
def render(assigns) do
~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
p-8 flex flex-col justify-center items-center"
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-key="escape"
phx-target={"#{@id}"}
phx-page-loading>
phx-page-loading
>
<div class="w-full max-w-4xl relative
p-8 flex flex-col justify-start items-center
bg-white border-2 rounded-lg">
<%# close button %>
<%= live_patch to: @return_to,
class: "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>
class:
"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>
<% end %>
<%# modal content %>
<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>

View File

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

View File

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

View File

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

View File

@ -1,13 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<%= csrf_meta_tag() %>
<%= live_title_tag assigns[:page_title] || "Cannery", suffix: "" %>
<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>
<%= live_title_tag(assigns[:page_title] || "Cannery", suffix: "") %>
<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>
</head>
<body class="m-0 p-0 min-w-full min-h-full">
<%= @inner_content %>

View File

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