Skip to content

Commit cadc15f

Browse files
authored
Initial dashboard & easy mounting (#12)
This change adds the basic structure to be able to build up a live view dashboard, which is a helper to add live routes and the basic layout that reads compiled JS and CSS from disk to inject it on the site. Documentation has been updated too.
1 parent 640d073 commit cadc15f

File tree

19 files changed

+312
-4
lines changed

19 files changed

+312
-4
lines changed

.formatter.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Used by "mix format"
22
[
3-
inputs: ["{mix,.formatter,dev,dev.*}.exs", "{config,lib,test}/**/*.{ex,exs}"],
4-
import_deps: [:ecto, :ecto_sql, :plug, :phoenix]
3+
import_deps: [:ecto, :ecto_sql, :plug, :phoenix],
4+
inputs: ["{mix,.formatter,dev,dev.*}.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
5+
plugins: [Phoenix.LiveView.HTMLFormatter]
56
]

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ error_tracker-*.tar
2525
# Temporary files, for example, from tests.
2626
/tmp/
2727

28+
/assets/node_modules
29+
30+
/priv/static/app.js
31+
/priv/static/app.css
32+
2833
dev.local.exs

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,42 @@ defmodule MyApp.Endpoint do
2424
use ErrorTracker.Integrations.Plug
2525
end
2626
```
27+
28+
## Development
29+
30+
### Development server
31+
32+
We have a `dev.exs` script that starts a development server.
33+
34+
To run it together with an `IEx` console you can do:
35+
36+
```
37+
iex -S mix dev
38+
```
39+
40+
### Assets
41+
42+
In ortder to participate in the development of this library, you may need to
43+
know how to compile the assets needed to use the Web UI.
44+
45+
To do so, you need to first make a clean build:
46+
47+
```
48+
mix do assets.install, assets.build
49+
```
50+
51+
That task will build the JS and CSS of the project.
52+
53+
The JS is not expected to change too much because we rely in LiveView, but if
54+
you make any change just execute that command again and you are good to go.
55+
56+
In the case of CSS, as it is automatically generated by Tailwind, you need to
57+
start the watcher when your intention is to modify the classes used.
58+
59+
To do so you can execute this task in a separate terminal:
60+
61+
```
62+
mix assets.watch
63+
```
64+
65+

assets/bun.lockb

4.03 KB
Binary file not shown.

assets/css/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@import "tailwindcss/base";
2+
@import "tailwindcss/components";
3+
@import "tailwindcss/utilities";
4+

assets/js/app.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Establish Phoenix Socket and LiveView configuration.
2+
import { Socket, LongPoll } from "phoenix";
3+
import { LiveSocket } from "phoenix_live_view";
4+
import topbar from "topbar";
5+
6+
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
7+
let socketPath = document.querySelector("meta[name='socket-path']").getAttribute("content");
8+
let socketTransport = document.querySelector("meta[name='socket-transport']").getAttribute("content");
9+
let normalizedTransport = (socketTransport == "longpoll") ? LongPoll : WebSocket;
10+
11+
let liveSocket = new LiveSocket(socketPath, Socket, { transport: normalizedTransport, params: { _csrf_token: csrfToken }});
12+
13+
// Show progress bar on live navigation and form submits
14+
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" });
15+
window.addEventListener("phx:page-loading-start", (_info) => topbar.show(300));
16+
window.addEventListener("phx:page-loading-stop", (_info) => topbar.hide());
17+
18+
// connect if there are any LiveViews on the page
19+
liveSocket.connect();
20+
window.liveSocket = liveSocket;

assets/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"workspaces": [
3+
"../deps/*"
4+
],
5+
"dependencies": {
6+
"phoenix": "workspace:*",
7+
"phoenix_live_view": "workspace:*",
8+
"topbar": "^3.0.0"
9+
}
10+
}

assets/tailwind.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// See the Tailwind configuration guide for advanced usage
2+
// https://tailwindcss.com/docs/configuration
3+
4+
let plugin = require('tailwindcss/plugin')
5+
6+
module.exports = {
7+
content: [
8+
'./js/**/*.js',
9+
'../lib/error_tracker/web.ex',
10+
'../lib/error_tracker/web/**/*.*ex'
11+
],
12+
theme: {
13+
extend: {},
14+
},
15+
plugins: [
16+
require('@tailwindcss/forms'),
17+
plugin(({addVariant}) => addVariant('phx-no-feedback', ['&.phx-no-feedback', '.phx-no-feedback &'])),
18+
plugin(({addVariant}) => addVariant('phx-click-loading', ['&.phx-click-loading', '.phx-click-loading &'])),
19+
plugin(({addVariant}) => addVariant('phx-submit-loading', ['&.phx-submit-loading', '.phx-submit-loading &'])),
20+
plugin(({addVariant}) => addVariant('phx-change-loading', ['&.phx-change-loading', '.phx-change-loading &']))
21+
]
22+
}

config/config.exs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ if config_env() == :dev do
77
args: ~w(
88
--config=tailwind.config.js
99
--input=css/app.css
10-
--output=../priv/static/assets/app.css
10+
--output=../priv/static/app.css
1111
),
1212
cd: Path.expand("../assets", __DIR__)
1313
]
14+
15+
config :bun,
16+
version: "1.1.18",
17+
default: [
18+
args: ~w(build app.js --outdir=../../priv/static),
19+
cd: Path.expand("../assets/js", __DIR__),
20+
env: %{}
21+
]
1422
end

dev.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ end
9494

9595
defmodule ErrorTrackerDevWeb.Router do
9696
use Phoenix.Router
97+
use ErrorTracker.Web, :router
9798

9899
pipeline :browser do
99100
plug :fetch_session
@@ -106,6 +107,8 @@ defmodule ErrorTrackerDevWeb.Router do
106107
get "/noroute", ErrorTrackerDevWeb.PageController, :noroute
107108
get "/exception", ErrorTrackerDevWeb.PageController, :exception
108109
get "/exit", ErrorTrackerDevWeb.PageController, :exit
110+
111+
error_tracker_dashboard("/errors")
109112
end
110113
end
111114

0 commit comments

Comments
 (0)