-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayouts.ex
113 lines (95 loc) · 3.03 KB
/
layouts.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
defmodule Observer.Web.Layouts do
@moduledoc """
This module provides layouts
## References:
* https://github.com/oban-bg/oban_web/blob/main/lib/oban/web/components/layouts.ex
"""
use Observer.Web, :html
alias Observer.Web.Components.Icons
@static_path Application.app_dir(:observer_web, ["priv", "static"])
@external_resource Path.join(@static_path, "app.css")
@external_resource Path.join(@static_path, "app.js")
@css @static_path
|> Path.join("app.css")
|> File.read!()
@js @static_path
|> Path.join("app.js")
|> File.read!()
def render("app.css"), do: @css
def render("app.js"), do: @js
embed_templates "layouts/*"
def logo(assigns) do
~H"""
<a href={observer_path(:tracing, @params)} class="flex" title="Observer Web">
<div>
<Icons.content name={:logo} />
</div>
<h3 class="class ml-2 items-center tracking-tight text-gray-900">
<span class="block text-4xl font-oswald">
Observer
<span class="text-transparent text-4xl font-bold bg-clip-text bg-gradient-to-tr to-cyan-500 from-blue-600">
WEB
</span>
</span>
</h3>
</a>
"""
end
def nav(assigns) do
~H"""
<nav class="flex space-x-1">
<.link
:for={page <- list_pages_by_params(@params)}
class={link_class(@page, page)}
data-shortcut={JS.navigate(observer_path(page, @params))}
id={"nav-#{page}"}
navigate={observer_path(page, @params)}
title={"Navigate to #{String.capitalize(to_string(page))}"}
>
<Icons.content name={page} />
{String.upcase(to_string(page))}
</.link>
</nav>
"""
end
def footer(assigns) do
assigns =
assign(assigns,
oss_version: Application.spec(:observer_web, :vsn)
)
~H"""
<footer class="flex flex-col px-3 py-6 text-sm justify-center items-center md:flex-row">
<.version name="Observer Web" version={@oss_version} />
<span class="text-gray-800 dark:text-gray-200 font-semibold">
Made by
<a
href="https://www.linkedin.com/in/thiago-cesar-calori-esteves-972368115/"
class="font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline"
>
Thiago Esteves
</a>
</span>
</footer>
"""
end
attr :name, :string
attr :version, :string
defp version(assigns) do
~H"""
<span class="text-gray-600 dark:text-gray-400 tabular mr-0 mb-1 md:mr-3 md:mb-0">
{@name} {if @version, do: "v#{@version}", else: "–"}
</span>
"""
end
defp link_class(curr, page) do
base =
"flex items-center px-4 py-2.5 text-sm font-bold transition-all duration-200 text-gray-900 rounded-lg group"
if curr == page do
base <> " bg-gray-100"
else
base <> " hover:text-white hover:bg-indigo-500"
end
end
defp list_pages_by_params(%{"iframe" => "true"}), do: [:tracing, :applications, :metrics]
defp list_pages_by_params(_params), do: [:root, :tracing, :applications, :metrics]
end