2022-02-11 22:47:33 -05:00
|
|
|
defmodule CanneryWeb.Components.Topbar do
|
2022-01-22 21:40:29 -05:00
|
|
|
@moduledoc """
|
|
|
|
Component that renders a topbar with user functions/links
|
|
|
|
"""
|
|
|
|
|
2022-01-22 15:15:23 -05:00
|
|
|
use CanneryWeb, :component
|
|
|
|
|
2022-01-22 21:40:29 -05:00
|
|
|
alias Cannery.Accounts
|
2022-02-13 21:18:34 -05:00
|
|
|
alias CanneryWeb.{Endpoint, HomeLive}
|
2022-01-22 15:15:23 -05:00
|
|
|
|
|
|
|
def topbar(assigns) do
|
|
|
|
assigns =
|
|
|
|
%{results: [], title_content: nil, flash: nil, current_user: nil} |> Map.merge(assigns)
|
|
|
|
|
|
|
|
~H"""
|
2022-02-15 23:52:44 -05:00
|
|
|
<nav role="navigation" class="mb-8 px-8 py-4 w-full bg-primary-400">
|
|
|
|
<div class="flex flex-col sm:flex-row justify-between items-center">
|
|
|
|
<div class="mb-4 sm:mb-0 sm:mr-8 flex flex-row justify-start items-center space-x-2">
|
2022-07-04 20:19:03 -04:00
|
|
|
<%= live_redirect to: Routes.live_path(Endpoint, HomeLive),
|
|
|
|
class: "inline mx-2 my-1 leading-5 text-xl text-white"
|
|
|
|
do %>
|
|
|
|
<img
|
|
|
|
src={Routes.static_path(Endpoint, "/images/cannery.svg")}
|
|
|
|
alt={gettext("Cannery logo")}
|
|
|
|
class="inline-block h-8 mx-1"
|
|
|
|
/>
|
|
|
|
<h1 class="inline hover:underline">Cannery</h1>
|
|
|
|
<% end %>
|
2022-01-31 22:40:07 -05:00
|
|
|
|
2022-02-15 23:52:44 -05:00
|
|
|
<%= if @title_content do %>
|
|
|
|
<span class="mx-2 my-1">
|
|
|
|
|
|
|
|
|
</span>
|
|
|
|
<%= @title_content %>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
|
2022-02-17 21:24:59 -05:00
|
|
|
<hr class="mb-2 sm:hidden hr-light" />
|
2022-02-15 23:52:44 -05:00
|
|
|
|
2022-04-19 20:08:12 -04:00
|
|
|
<ul class="flex flex-row flex-wrap justify-center items-center
|
|
|
|
text-lg text-white text-ellipsis">
|
2022-02-15 23:52:44 -05:00
|
|
|
<%= if @current_user do %>
|
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect(gettext("Tags"),
|
|
|
|
to: Routes.tag_index_path(Endpoint, :index),
|
|
|
|
class: "text-primary-600 text-white hover:underline"
|
2022-02-15 23:52:44 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect(gettext("Containers"),
|
|
|
|
to: Routes.container_index_path(Endpoint, :index),
|
|
|
|
class: "text-primary-600 text-white hover:underline"
|
2022-02-15 23:52:44 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<li class="mx-2 my-1">
|
2022-07-01 00:20:50 -04:00
|
|
|
<%= live_redirect(gettext("Catalog"),
|
2022-02-18 17:43:51 -05:00
|
|
|
to: Routes.ammo_type_index_path(Endpoint, :index),
|
|
|
|
class: "text-primary-600 text-white hover:underline"
|
2022-02-15 23:52:44 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<li class="mx-2 my-1">
|
2022-07-01 00:20:50 -04:00
|
|
|
<%= live_redirect(gettext("Ammo"),
|
2022-02-18 17:43:51 -05:00
|
|
|
to: Routes.ammo_group_index_path(Endpoint, :index),
|
|
|
|
class: "text-primary-600 text-white hover:underline"
|
2022-02-15 23:52:44 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect(gettext("Range"),
|
|
|
|
to: Routes.range_index_path(Endpoint, :index),
|
|
|
|
class: "text-primary-600 text-white hover:underline"
|
2022-02-15 23:52:44 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<%= if @current_user.role == :admin do %>
|
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect(gettext("Invites"),
|
|
|
|
to: Routes.invite_index_path(Endpoint, :index),
|
|
|
|
class: "text-primary-600 text-white hover:underline"
|
2022-02-15 17:33:45 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
2022-02-15 23:52:44 -05:00
|
|
|
<% end %>
|
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect(@current_user.email,
|
|
|
|
to: Routes.user_settings_path(Endpoint, :edit),
|
|
|
|
class: "text-primary-600 text-white hover:underline truncate"
|
2022-02-15 23:52:44 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<li class="mx-2 my-1">
|
|
|
|
<%= link to: Routes.user_session_path(Endpoint, :delete),
|
|
|
|
method: :delete,
|
|
|
|
data: [confirm: dgettext("prompts", "Are you sure you want to log out?")] do %>
|
|
|
|
<i class="fas fa-sign-out-alt"></i>
|
2022-01-22 15:15:23 -05:00
|
|
|
<% end %>
|
2022-02-15 23:52:44 -05:00
|
|
|
</li>
|
|
|
|
<%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %>
|
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect to: Routes.live_dashboard_path(Endpoint, :home),
|
|
|
|
class: "text-primary-600 text-white hover:underline" do %>
|
2022-05-06 23:35:50 -04:00
|
|
|
<i class="fas fa-gauge"></i>
|
2022-01-22 15:15:23 -05:00
|
|
|
<% end %>
|
|
|
|
</li>
|
2022-02-15 23:52:44 -05:00
|
|
|
<% end %>
|
|
|
|
<% else %>
|
|
|
|
<%= if Accounts.allow_registration?() do %>
|
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect(dgettext("actions", "Register"),
|
|
|
|
to: Routes.user_registration_path(Endpoint, :new),
|
|
|
|
class: "text-primary-600 text-white hover:underline truncate"
|
2022-01-22 17:21:10 -05:00
|
|
|
) %>
|
2022-01-22 15:15:23 -05:00
|
|
|
</li>
|
|
|
|
<% end %>
|
2022-02-15 23:52:44 -05:00
|
|
|
<li class="mx-2 my-1">
|
2022-02-18 17:43:51 -05:00
|
|
|
<%= live_redirect(dgettext("actions", "Log in"),
|
|
|
|
to: Routes.user_session_path(Endpoint, :new),
|
|
|
|
class: "text-primary-600 text-white hover:underline truncate"
|
2022-02-15 23:52:44 -05:00
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2022-01-22 15:15:23 -05:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|