-
Notifications
You must be signed in to change notification settings - Fork 33
Initial dashboard & easy mounting #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0453acc
Add base web interfaces
odarriba 155d545
WIP Dashboard interface
odarriba c3e1f1b
Router helper and use it in dev
odarriba 4ab26c8
Update route
odarriba 41b202f
Happy credo
odarriba 9856d4e
Tailwind install
odarriba 2ad8c72
Add esbuild
odarriba b51c9c8
Configure assets building
odarriba 686b6d2
Test adding a class
odarriba 69c5262
Read assets from disk and inject it on the HTML
odarriba 9f16ff7
Move to bun
odarriba 4238600
Proper render of assets
odarriba 15a9523
WIP dashboard example
odarriba cb32568
Update formatter config
odarriba 109cc36
Allow configuring socket path and transport
odarriba cf05eca
Load socket config from app config
odarriba 37b8af0
Add some documentation
odarriba 3a6c5ce
Update dev script
odarriba 2dc0784
Update README
odarriba ac02cd7
Update README
odarriba 6efbc14
Update bun version
odarriba 98f14c5
Add new task for installing deps
odarriba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter,dev,dev.*}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
import_deps: [:ecto, :ecto_sql, :plug, :phoenix] | ||
import_deps: [:ecto, :ecto_sql, :plug, :phoenix], | ||
inputs: ["{mix,.formatter,dev,dev.*}.exs", "{config,lib,test}/**/*.{heex,ex,exs}"], | ||
plugins: [Phoenix.LiveView.HTMLFormatter] | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@import "tailwindcss/base"; | ||
@import "tailwindcss/components"; | ||
@import "tailwindcss/utilities"; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Establish Phoenix Socket and LiveView configuration. | ||
import { Socket, LongPoll } from "phoenix"; | ||
import { LiveSocket } from "phoenix_live_view"; | ||
import topbar from "topbar"; | ||
|
||
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content"); | ||
let socketPath = document.querySelector("meta[name='socket-path']").getAttribute("content"); | ||
let socketTransport = document.querySelector("meta[name='socket-transport']").getAttribute("content"); | ||
let normalizedTransport = (socketTransport == "longpoll") ? LongPoll : WebSocket; | ||
|
||
let liveSocket = new LiveSocket(socketPath, Socket, { transport: normalizedTransport, params: { _csrf_token: csrfToken }}); | ||
|
||
// Show progress bar on live navigation and form submits | ||
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" }); | ||
window.addEventListener("phx:page-loading-start", (_info) => topbar.show(300)); | ||
window.addEventListener("phx:page-loading-stop", (_info) => topbar.hide()); | ||
|
||
// connect if there are any LiveViews on the page | ||
liveSocket.connect(); | ||
window.liveSocket = liveSocket; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"workspaces": [ | ||
"../deps/*" | ||
], | ||
"dependencies": { | ||
"phoenix": "workspace:*", | ||
"phoenix_live_view": "workspace:*", | ||
"topbar": "^3.0.0" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// See the Tailwind configuration guide for advanced usage | ||
// https://tailwindcss.com/docs/configuration | ||
|
||
let plugin = require('tailwindcss/plugin') | ||
|
||
module.exports = { | ||
content: [ | ||
'./js/**/*.js', | ||
'../lib/error_tracker/web.ex', | ||
'../lib/error_tracker/web/**/*.*ex' | ||
], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/forms'), | ||
plugin(({addVariant}) => addVariant('phx-no-feedback', ['&.phx-no-feedback', '.phx-no-feedback &'])), | ||
plugin(({addVariant}) => addVariant('phx-click-loading', ['&.phx-click-loading', '.phx-click-loading &'])), | ||
plugin(({addVariant}) => addVariant('phx-submit-loading', ['&.phx-submit-loading', '.phx-submit-loading &'])), | ||
plugin(({addVariant}) => addVariant('phx-change-loading', ['&.phx-change-loading', '.phx-change-loading &'])) | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
defmodule ErrorTracker.Web do | ||
@moduledoc """ | ||
ErrorTracker includes a Web UI to view and inspect errors occurred on your | ||
application and already stored on the database. | ||
|
||
In order to use it, you need to add the following to your Phoenix's ` | ||
router.ex` file: | ||
|
||
```elixir | ||
defmodule YourAppWeb.Router do | ||
use Phoenix.Router | ||
use ErrorTracker.Web, :router | ||
|
||
... | ||
|
||
error_tracker_dashboard "/errors" | ||
end | ||
``` | ||
|
||
This will add the routes needed for the ErrorTracker LiveView UI to work. | ||
|
||
## LiveView socket options | ||
|
||
By default the library expects you to have your LiveView socket at `/live` and | ||
using `websocket` transport. | ||
|
||
If that's not the case, you can configure it adding the following | ||
configuration to your app's config files: | ||
|
||
```elixir | ||
config :error_tracker, | ||
socket: [ | ||
path: "/my-custom-socket-path" | ||
transport: :longpoll # (accepted values are :longpoll or :websocket) | ||
] | ||
``` | ||
""" | ||
|
||
def html do | ||
quote do | ||
import Phoenix.Controller, only: [get_csrf_token: 0] | ||
|
||
unquote(html_helpers()) | ||
end | ||
end | ||
|
||
def live_view do | ||
quote do | ||
use Phoenix.LiveView, layout: {ErrorTracker.Web.Layouts, :live} | ||
|
||
unquote(html_helpers()) | ||
end | ||
end | ||
|
||
def live_component do | ||
quote do | ||
use Phoenix.LiveComponent | ||
|
||
unquote(html_helpers()) | ||
end | ||
end | ||
|
||
def router do | ||
quote do | ||
import ErrorTracker.Web.Router | ||
end | ||
end | ||
|
||
defp html_helpers do | ||
quote do | ||
use Phoenix.Component | ||
|
||
import Phoenix.HTML | ||
import Phoenix.LiveView.Helpers | ||
|
||
alias Phoenix.LiveView.JS | ||
end | ||
end | ||
|
||
defmacro __using__(which) when is_atom(which) do | ||
apply(__MODULE__, which, []) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule ErrorTracker.Web.Layouts do | ||
use ErrorTracker.Web, :html | ||
|
||
@css_path :code.priv_dir(:error_tracker) |> Path.join("static/app.css") | ||
@js_path :code.priv_dir(:error_tracker) |> Path.join("static/app.js") | ||
|
||
@default_docket_config %{path: "/live", transport: :websocket} | ||
|
||
embed_templates "layouts/*" | ||
|
||
def get_content(:css), do: File.read!(@css_path) | ||
def get_content(:js), do: File.read!(@js_path) | ||
|
||
def get_socket_config(key) do | ||
default = Map.get(@default_docket_config, key) | ||
config = Application.get_env(:error_tracker, :live_view_socket, []) | ||
Keyword.get(config, key, default) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<main> | ||
<%= @inner_content %> | ||
</main> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!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 name="csrf-token" content={get_csrf_token()} /> | ||
<meta name="socket-path" content={get_socket_config(:path)} /> | ||
<meta name="socket-transport" content={get_socket_config(:transport)} /> | ||
|
||
<title><%= assigns[:page_title] || "ErrorTracker" %></title> | ||
|
||
<style> | ||
<%= raw get_content(:css) %> | ||
</style> | ||
<script> | ||
<%= raw get_content(:js) %> | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<%= @inner_content %> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule ErrorTracker.Web.Live.Dashboard do | ||
@moduledoc false | ||
|
||
use ErrorTracker.Web, :live_view | ||
|
||
@impl Phoenix.LiveView | ||
def mount(_params, _session, socket) do | ||
{:ok, assign(socket, :counter, 0)} | ||
end | ||
|
||
@impl Phoenix.LiveView | ||
def handle_params(_params, _uri, socket) do | ||
{:noreply, socket} | ||
end | ||
|
||
@impl Phoenix.LiveView | ||
def handle_event("increment", _params, socket) do | ||
{:noreply, assign(socket, :counter, socket.assigns.counter + 1)} | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<p class="font-bold">Hello world!</p> | ||
<p>Number of presses: <%= @counter %></p> | ||
<button | ||
class="h-8 px-4 m-2 text-sm text-indigo-100 transition-colors duration-150 bg-indigo-700 rounded-lg focus:shadow-outline hover:bg-indigo-800" | ||
phx-click="increment" | ||
> | ||
Press me! | ||
</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule ErrorTracker.Web.Router do | ||
@moduledoc false | ||
|
||
@doc """ | ||
Creates the routes needed to use the `ErrorTracker` web interface. | ||
|
||
It requires a path in which you are going to serve the web interface. | ||
""" | ||
defmacro error_tracker_dashboard(path, opts \\ []) do | ||
{session_name, session_opts} = parse_options(opts) | ||
|
||
quote do | ||
scope unquote(path), alias: false, as: false do | ||
import Phoenix.LiveView.Router, only: [live: 4, live_session: 3] | ||
|
||
live_session unquote(session_name), unquote(session_opts) do | ||
live "/", ErrorTracker.Web.Live.Dashboard, :index, as: unquote(session_name) | ||
end | ||
end | ||
end | ||
end | ||
|
||
@doc false | ||
def parse_options(opts) do | ||
on_mount = Keyword.get(opts, :on_mount, []) | ||
session_name = Keyword.get(opts, :as, :error_tracker_dashboard) | ||
|
||
session_opts = [ | ||
on_mount: on_mount, | ||
root_layout: {ErrorTracker.Web.Layouts, :root} | ||
] | ||
|
||
{session_name, session_opts} | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.