2023-03-22 23:17:24 +01:00
|
|
|
defmodule ChiyaWeb.AdminComponents do
|
2023-03-31 17:00:09 +02:00
|
|
|
use Phoenix.Component
|
2023-03-22 23:17:24 +01:00
|
|
|
|
|
|
|
use Phoenix.VerifiedRoutes,
|
|
|
|
endpoint: ChiyaWeb.Endpoint,
|
|
|
|
router: ChiyaWeb.Router,
|
|
|
|
statics: ChiyaWeb.static_paths()
|
|
|
|
|
|
|
|
import ChiyaWeb.CoreComponents
|
|
|
|
|
2023-03-31 17:00:09 +02:00
|
|
|
@doc """
|
|
|
|
Renders a horizontal line
|
|
|
|
"""
|
|
|
|
def line(assigns) do
|
|
|
|
~H"""
|
|
|
|
<hr class="my-6 dark:border-gray-700" />
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2023-03-22 23:17:24 +01:00
|
|
|
@doc """
|
|
|
|
Renders a UI for uploading files
|
|
|
|
"""
|
|
|
|
|
|
|
|
attr :upload, :map, required: true
|
|
|
|
attr :cancel_upload, :string, default: "cancel-upload"
|
|
|
|
|
|
|
|
def live_upload(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div>
|
|
|
|
<.live_file_input upload={@upload} class="dark:text-gray-300" />
|
|
|
|
|
|
|
|
<section phx-drop-target={@upload.ref}>
|
|
|
|
<%= for entry <- @upload.entries do %>
|
|
|
|
<article class="upload-entry">
|
|
|
|
<figure>
|
|
|
|
<.live_img_preview entry={entry} />
|
2023-04-01 12:09:58 +02:00
|
|
|
<figcaption class="dark:text-gray-100"><%= entry.client_name %></figcaption>
|
2023-03-22 23:17:24 +01:00
|
|
|
</figure>
|
|
|
|
|
2023-04-01 12:09:58 +02:00
|
|
|
<div class="flex">
|
|
|
|
<%!-- entry.progress will update automatically for in-flight entries --%>
|
|
|
|
<progress value={entry.progress} max="100" class="w-full">
|
|
|
|
<%= entry.progress %>%
|
|
|
|
</progress>
|
2023-03-22 23:17:24 +01:00
|
|
|
|
2023-04-01 12:09:58 +02:00
|
|
|
<%!-- a regular click event whose handler will invoke Phoenix.LiveView.cancel_upload/3 --%>
|
|
|
|
<button
|
|
|
|
class="px-2 dark:text-white"
|
|
|
|
type="button"
|
|
|
|
phx-click="cancel-upload"
|
|
|
|
phx-value-ref={entry.ref}
|
|
|
|
aria-label="cancel"
|
|
|
|
>
|
|
|
|
×
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-03-22 23:17:24 +01:00
|
|
|
|
|
|
|
<%!-- Phoenix.Component.upload_errors/2 returns a list of error atoms --%>
|
|
|
|
<%= for err <- upload_errors(@upload, entry) do %>
|
|
|
|
<p class="alert alert-danger"><%= upload_error_to_string(err) %></p>
|
|
|
|
<% end %>
|
|
|
|
</article>
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
<%!-- Phoenix.Component.upload_errors/1 returns a list of error atoms --%>
|
|
|
|
<%= for err <- upload_errors(@upload) do %>
|
|
|
|
<p class="alert alert-danger"><%= upload_error_to_string(err) %></p>
|
|
|
|
<% end %>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Renders the admin menu bar
|
|
|
|
"""
|
|
|
|
|
|
|
|
attr :current_user, :map, required: true
|
|
|
|
|
|
|
|
def admin_bar(assigns) do
|
|
|
|
~H"""
|
2023-03-30 22:56:06 +02:00
|
|
|
<ul class="relative z-10 flex items-center gap-4 py-1 px-4 sm:px-6 lg:px-8 bg-black">
|
|
|
|
<li>
|
|
|
|
<.link
|
|
|
|
href={~p"/"}
|
|
|
|
class="flex gap-3 text-sm leading-6 text-gray-100 font-semibold hover:text-gray-300"
|
|
|
|
>
|
|
|
|
<span>Chiya</span>
|
2023-03-30 23:09:39 +02:00
|
|
|
<p class="rounded-full bg-theme-primary/10 px-2 text-[0.8125rem] font-medium leading-6 text-theme-primary">
|
2023-03-30 22:56:06 +02:00
|
|
|
v<%= Application.spec(:chiya, :vsn) %>
|
|
|
|
</p>
|
|
|
|
</.link>
|
|
|
|
</li>
|
|
|
|
<li class="flex-1"></li>
|
2023-03-22 23:17:24 +01:00
|
|
|
<%= if @current_user do %>
|
2023-03-30 13:07:37 +02:00
|
|
|
<li>
|
|
|
|
<.link
|
|
|
|
href="#"
|
|
|
|
id="dark-mode-toggle"
|
|
|
|
class="text-xs leading-6 text-gray-100 font-semibold hover:text-gray-300"
|
|
|
|
>
|
|
|
|
<.icon name="hero-sun-mini" class="h-4 w-4" />
|
|
|
|
</.link>
|
|
|
|
</li>
|
2023-03-22 23:17:24 +01:00
|
|
|
<li>
|
|
|
|
<.link
|
|
|
|
href={~p"/user"}
|
|
|
|
class="text-xs leading-6 text-gray-100 font-semibold hover:text-gray-300"
|
|
|
|
>
|
|
|
|
Profile
|
|
|
|
</.link>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<.link
|
|
|
|
href={~p"/admin"}
|
|
|
|
class="text-xs leading-6 text-gray-100 font-semibold hover:text-gray-300"
|
|
|
|
>
|
|
|
|
Admin
|
|
|
|
</.link>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<.link
|
|
|
|
href={~p"/user/log_out"}
|
|
|
|
method="delete"
|
|
|
|
class="text-xs leading-6 text-gray-100 font-semibold hover:text-gray-300"
|
|
|
|
>
|
|
|
|
Log out
|
|
|
|
</.link>
|
|
|
|
</li>
|
|
|
|
<% else %>
|
|
|
|
<li>
|
|
|
|
<.link
|
2023-03-29 18:47:45 +02:00
|
|
|
href="#"
|
|
|
|
id="dark-mode-toggle"
|
2023-03-22 23:17:24 +01:00
|
|
|
class="text-xs leading-6 text-gray-100 font-semibold hover:text-gray-300"
|
|
|
|
>
|
2023-03-29 18:47:45 +02:00
|
|
|
<.icon name="hero-sun-mini" class="h-4 w-4" />
|
2023-03-22 23:17:24 +01:00
|
|
|
</.link>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<.link
|
|
|
|
href={~p"/user/log_in"}
|
|
|
|
class="text-xs leading-6 text-gray-100 font-semibold hover:text-gray-300"
|
|
|
|
>
|
|
|
|
Log in
|
|
|
|
</.link>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
</ul>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
defp upload_error_to_string(:too_large), do: "Too large"
|
|
|
|
defp upload_error_to_string(:too_many_files), do: "You have selected too many files"
|
|
|
|
defp upload_error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
|
2023-03-31 16:58:10 +02:00
|
|
|
end
|