2022-07-25 19:31:54 -04:00
|
|
|
|
defmodule MemexWeb.Components.Topbar do
|
2022-02-25 21:55:27 -05:00
|
|
|
|
@moduledoc """
|
|
|
|
|
Component that renders a topbar with user functions/links
|
|
|
|
|
"""
|
|
|
|
|
|
2022-07-25 19:31:54 -04:00
|
|
|
|
use MemexWeb, :component
|
2022-02-25 21:55:27 -05:00
|
|
|
|
|
2022-07-25 19:31:54 -04:00
|
|
|
|
alias Memex.Accounts
|
2022-11-18 22:30:33 -05:00
|
|
|
|
alias MemexWeb.HomeLive
|
2022-02-25 21:55:27 -05:00
|
|
|
|
|
|
|
|
|
def topbar(assigns) do
|
|
|
|
|
assigns =
|
|
|
|
|
%{results: [], title_content: nil, flash: nil, current_user: nil} |> Map.merge(assigns)
|
|
|
|
|
|
|
|
|
|
~H"""
|
2022-07-25 22:04:10 -04:00
|
|
|
|
<nav role="navigation" class="mb-8 px-8 py-4 w-full bg-primary-900 text-primary-400">
|
2022-02-25 21:55:27 -05:00
|
|
|
|
<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-11-16 21:11:02 -05:00
|
|
|
|
<.link
|
|
|
|
|
navigate={Routes.live_path(Endpoint, HomeLive)}
|
|
|
|
|
class="mx-2 my-1 leading-5 text-xl text-primary-400 hover:underline"
|
|
|
|
|
>
|
2022-11-26 20:36:09 -05:00
|
|
|
|
<%= gettext("memEx") %>
|
2022-11-16 21:11:02 -05:00
|
|
|
|
</.link>
|
2022-02-25 21:55:27 -05:00
|
|
|
|
|
|
|
|
|
<%= if @title_content do %>
|
|
|
|
|
<span class="mx-2 my-1">
|
|
|
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
<%= @title_content %>
|
|
|
|
|
<% end %>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<hr class="mb-2 sm:hidden hr-light" />
|
|
|
|
|
|
2022-05-05 21:07:02 -04:00
|
|
|
|
<ul class="flex flex-row flex-wrap justify-center items-center
|
2022-07-25 22:04:10 -04:00
|
|
|
|
text-lg text-primary-400 text-ellipsis">
|
2022-11-18 20:20:49 -05:00
|
|
|
|
<li class="mx-2 my-1">
|
|
|
|
|
<.link
|
|
|
|
|
navigate={Routes.note_index_path(Endpoint, :index)}
|
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline truncate"
|
|
|
|
|
>
|
|
|
|
|
<%= gettext("notes") %>
|
|
|
|
|
</.link>
|
|
|
|
|
</li>
|
2022-07-25 22:04:10 -04:00
|
|
|
|
|
2022-11-18 20:20:49 -05:00
|
|
|
|
<li class="mx-2 my-1">
|
|
|
|
|
<.link
|
|
|
|
|
navigate={Routes.context_index_path(Endpoint, :index)}
|
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline truncate"
|
|
|
|
|
>
|
|
|
|
|
<%= gettext("contexts") %>
|
|
|
|
|
</.link>
|
|
|
|
|
</li>
|
2022-07-25 22:04:10 -04:00
|
|
|
|
|
2022-11-18 20:20:49 -05:00
|
|
|
|
<li class="mx-2 my-1">
|
|
|
|
|
<.link
|
|
|
|
|
navigate={Routes.pipeline_index_path(Endpoint, :index)}
|
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline truncate"
|
|
|
|
|
>
|
|
|
|
|
<%= gettext("pipelines") %>
|
|
|
|
|
</.link>
|
|
|
|
|
</li>
|
2022-07-25 22:04:10 -04:00
|
|
|
|
|
2022-11-18 20:20:49 -05:00
|
|
|
|
<li class="mx-2 my-1 border-left border border-primary-700"></li>
|
2022-07-25 22:04:10 -04:00
|
|
|
|
|
2022-11-18 20:20:49 -05:00
|
|
|
|
<%= if @current_user do %>
|
2023-02-04 11:29:06 -05:00
|
|
|
|
<li :if={@current_user |> Accounts.is_already_admin?()} class="mx-2 my-1">
|
|
|
|
|
<.link
|
|
|
|
|
navigate={Routes.invite_index_path(Endpoint, :index)}
|
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline"
|
|
|
|
|
>
|
|
|
|
|
<%= gettext("invites") %>
|
|
|
|
|
</.link>
|
|
|
|
|
</li>
|
2022-07-25 22:04:10 -04:00
|
|
|
|
|
2022-02-25 21:55:27 -05:00
|
|
|
|
<li class="mx-2 my-1">
|
2022-11-16 21:11:02 -05:00
|
|
|
|
<.link
|
|
|
|
|
navigate={Routes.user_settings_path(Endpoint, :edit)}
|
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline truncate"
|
|
|
|
|
>
|
|
|
|
|
<%= @current_user.email %>
|
|
|
|
|
</.link>
|
2022-02-25 21:55:27 -05:00
|
|
|
|
</li>
|
|
|
|
|
<li class="mx-2 my-1">
|
2022-11-16 21:11:02 -05:00
|
|
|
|
<.link
|
|
|
|
|
href={Routes.user_session_path(Endpoint, :delete)}
|
|
|
|
|
method="delete"
|
2022-11-17 22:30:01 -05:00
|
|
|
|
data-confirm={dgettext("prompts", "are you sure you want to log out?")}
|
2022-11-16 21:11:02 -05:00
|
|
|
|
>
|
2022-02-25 21:55:27 -05:00
|
|
|
|
<i class="fas fa-sign-out-alt"></i>
|
2022-11-16 21:11:02 -05:00
|
|
|
|
</.link>
|
2022-02-25 21:55:27 -05:00
|
|
|
|
</li>
|
2023-02-04 11:29:06 -05:00
|
|
|
|
<li
|
|
|
|
|
:if={
|
|
|
|
|
@current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2)
|
|
|
|
|
}
|
|
|
|
|
class="mx-2 my-1"
|
|
|
|
|
>
|
|
|
|
|
<.link
|
|
|
|
|
navigate={Routes.live_dashboard_path(Endpoint, :home)}
|
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline"
|
|
|
|
|
>
|
|
|
|
|
<i class="fas fa-gauge"></i>
|
|
|
|
|
</.link>
|
|
|
|
|
</li>
|
2022-02-25 21:55:27 -05:00
|
|
|
|
<% else %>
|
2023-02-04 11:29:06 -05:00
|
|
|
|
<li :if={Accounts.allow_registration?()} class="mx-2 my-1">
|
|
|
|
|
<.link
|
2023-02-26 00:37:07 -05:00
|
|
|
|
href={Routes.user_registration_path(Endpoint, :new)}
|
2023-02-04 11:29:06 -05:00
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline truncate"
|
|
|
|
|
>
|
|
|
|
|
<%= dgettext("actions", "register") %>
|
|
|
|
|
</.link>
|
|
|
|
|
</li>
|
2022-07-25 22:04:10 -04:00
|
|
|
|
|
2022-02-25 21:55:27 -05:00
|
|
|
|
<li class="mx-2 my-1">
|
2022-11-16 21:11:02 -05:00
|
|
|
|
<.link
|
2023-02-26 00:37:07 -05:00
|
|
|
|
href={Routes.user_session_path(Endpoint, :new)}
|
2022-11-16 21:11:02 -05:00
|
|
|
|
class="text-primary-400 text-primary-400 hover:underline truncate"
|
|
|
|
|
>
|
2022-11-17 22:30:01 -05:00
|
|
|
|
<%= dgettext("actions", "log in") %>
|
2022-11-16 21:11:02 -05:00
|
|
|
|
</.link>
|
2022-02-25 21:55:27 -05:00
|
|
|
|
</li>
|
|
|
|
|
<% end %>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</nav>
|
|
|
|
|
"""
|
|
|
|
|
end
|
|
|
|
|
end
|