From 4908f8a355951628e3fc91912bb17b37c7059d3b Mon Sep 17 00:00:00 2001 From: Adam Mohammed Date: Sat, 23 Sep 2023 13:22:54 -0400 Subject: [PATCH] moar --- lib/streamview/datasources/sample.ex | 22 ++ .../components/layouts/app.html.heex | 23 +- .../components/layouts/root.html.heex | 2 +- .../controllers/page_controller.ex | 11 + lib/streamview_web/controllers/page_html.ex | 6 + .../controllers/page_html/home.html.heex | 210 +----------------- .../controllers/page_html/timeline.html.heex | 18 ++ lib/streamview_web/router.ex | 1 + mix.lock | 7 + 9 files changed, 80 insertions(+), 220 deletions(-) create mode 100644 lib/streamview/datasources/sample.ex create mode 100644 lib/streamview_web/controllers/page_html/timeline.html.heex diff --git a/lib/streamview/datasources/sample.ex b/lib/streamview/datasources/sample.ex new file mode 100644 index 0000000..7c0e313 --- /dev/null +++ b/lib/streamview/datasources/sample.ex @@ -0,0 +1,22 @@ +defmodule Streamview.Datasources.Sample do + def call(_opts) do + generate_sample_data() + end + + defp generate_sample_data() do + [ + %{session_key: "apple", queue_name: "serialized_1", created_at: DateTime.utc_now(), event_type: "session created"}, + %{session_key: "apple", queue_name: "serialized_1", created_at: DateTime.utc_now(), event_type: "job queued"}, + %{session_key: "apple", queue_name: "serialized_1", created_at: DateTime.utc_now(), event_type: "job queued"}, + %{session_key: "apple", queue_name: "serialized_1", created_at: DateTime.utc_now(), event_type: "job completed"}, + %{session_key: "apple", queue_name: "serialized_1", created_at: DateTime.utc_now(), event_type: "job completed"}, + %{session_key: "apple", queue_name: "serialized_1", created_at: DateTime.utc_now(), event_type: "session destroyed"}, + %{session_key: "banana", queue_name: "serialized_2", created_at: DateTime.utc_now(), event_type: "session created"}, + %{session_key: "banana", queue_name: "serialized_2", created_at: DateTime.utc_now(), event_type: "job queued"}, + %{session_key: "banana", queue_name: "serialized_2", created_at: DateTime.utc_now(), event_type: "job queued"}, + %{session_key: "banana", queue_name: "serialized_2", created_at: DateTime.utc_now(), event_type: "job completed"}, + %{session_key: "banana", queue_name: "serialized_2", created_at: DateTime.utc_now(), event_type: "job completed"}, + %{session_key: "banana", queue_name: "serialized_2", created_at: DateTime.utc_now(), event_type: "session destroyed"}, + ] + end +end diff --git a/lib/streamview_web/components/layouts/app.html.heex b/lib/streamview_web/components/layouts/app.html.heex index e23bfc8..0b77295 100644 --- a/lib/streamview_web/components/layouts/app.html.heex +++ b/lib/streamview_web/components/layouts/app.html.heex @@ -1,25 +1,16 @@ -
-
+
+
-

- v<%= Application.spec(:phoenix, :vsn) %> +

+ StreamView

- diff --git a/lib/streamview_web/components/layouts/root.html.heex b/lib/streamview_web/components/layouts/root.html.heex index bb91cfb..be16e50 100644 --- a/lib/streamview_web/components/layouts/root.html.heex +++ b/lib/streamview_web/components/layouts/root.html.heex @@ -11,7 +11,7 @@ - + <%= @inner_content %> diff --git a/lib/streamview_web/controllers/page_controller.ex b/lib/streamview_web/controllers/page_controller.ex index 02a9d47..fa95601 100644 --- a/lib/streamview_web/controllers/page_controller.ex +++ b/lib/streamview_web/controllers/page_controller.ex @@ -1,9 +1,20 @@ defmodule StreamviewWeb.PageController do use StreamviewWeb, :controller + alias Streamview.Datasources.Sample, as: Source + def home(conn, _params) do # The home page is often custom made, # so skip the default app layout. render(conn, :home, layout: false) end + + def timeline(conn, _params) do + render(conn, :timeline, event_data: event_queues()) + end + + defp event_queues do + Source.call({}) + |> Enum.group_by(fn item -> item.queue_name end) + end end diff --git a/lib/streamview_web/controllers/page_html.ex b/lib/streamview_web/controllers/page_html.ex index a236aee..0fb5b23 100644 --- a/lib/streamview_web/controllers/page_html.ex +++ b/lib/streamview_web/controllers/page_html.ex @@ -2,4 +2,10 @@ defmodule StreamviewWeb.PageHTML do use StreamviewWeb, :html embed_templates "page_html/*" + + defp format_queue_name(name) do + name + |> String.replace("_", " ") + |> String.capitalize + end end diff --git a/lib/streamview_web/controllers/page_html/home.html.heex b/lib/streamview_web/controllers/page_html/home.html.heex index e9fc48d..11f4d02 100644 --- a/lib/streamview_web/controllers/page_html/home.html.heex +++ b/lib/streamview_web/controllers/page_html/home.html.heex @@ -1,51 +1,11 @@ <.flash_group flash={@flash} /> - -
+
- +
+

+ StreamView +

+

Phoenix Framework @@ -53,169 +13,13 @@

- Peace of mind from prototype to production. + Timeline of Worker Sessions

Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale.

diff --git a/lib/streamview_web/controllers/page_html/timeline.html.heex b/lib/streamview_web/controllers/page_html/timeline.html.heex new file mode 100644 index 0000000..f4f4230 --- /dev/null +++ b/lib/streamview_web/controllers/page_html/timeline.html.heex @@ -0,0 +1,18 @@ +
+

+ Timeline +

+
+ <%= for {q_name, events} <- @event_data do %> +
+

<%= format_queue_name(q_name) %>

+ <%= for event <- events do %> +
+

Session ID: <%= event.session_key %>

+

<%= String.upcase(event.event_type) %>

+
+ <% end %> +
+ <% end %> +
+
diff --git a/lib/streamview_web/router.ex b/lib/streamview_web/router.ex index 3c67fae..ac5938c 100644 --- a/lib/streamview_web/router.ex +++ b/lib/streamview_web/router.ex @@ -18,6 +18,7 @@ defmodule StreamviewWeb.Router do pipe_through :browser get "/", PageController, :home + get "/timeline", PageController, :timeline end # Other scopes may use custom stacks. diff --git a/mix.lock b/mix.lock index 502e55a..936fa0f 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,11 @@ %{ + "amqp": {:hex, :amqp, "3.3.0", "056d9f4bac96c3ab5a904b321e70e78b91ba594766a1fc2f32afd9c016d9f43b", [:mix], [{:amqp_client, "~> 3.9", [hex: :amqp_client, repo: "hexpm", optional: false]}], "hexpm", "8d3ae139d2646c630d674a1b8d68c7f85134f9e8b2a1c3dd5621616994b10a8b"}, + "amqp_client": {:hex, :amqp_client, "3.12.4", "dd60a4ce4282f2cc91f0668d0d6190b1ab3c609f2dcead255136de69247dfd85", [:make, :rebar3], [{:credentials_obfuscation, "3.4.0", [hex: :credentials_obfuscation, repo: "hexpm", optional: false]}, {:rabbit_common, "3.12.4", [hex: :rabbit_common, repo: "hexpm", optional: false]}], "hexpm", "30c8d8dacba4d1c93c84b3b4daf6991f0e7e25b47e0b21993b20472659401298"}, "castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"}, "cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"}, + "credentials_obfuscation": {:hex, :credentials_obfuscation, "3.4.0", "34e18b126b3aefd6e8143776fbe1ceceea6792307c99ac5ee8687911f048cfd7", [:rebar3], [], "hexpm", "738ace0ed5545d2710d3f7383906fc6f6b582d019036e5269c4dbd85dbced566"}, "db_connection": {:hex, :db_connection, "2.5.0", "bb6d4f30d35ded97b29fe80d8bd6f928a1912ca1ff110831edcd238a1973652c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c92d5ba26cd69ead1ff7582dbb860adeedfff39774105a4f1c92cbb654b55aa2"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "ecto": {:hex, :ecto, "3.10.3", "eb2ae2eecd210b4eb8bece1217b297ad4ff824b4384c0e3fdd28aaf96edd6135", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "44bec74e2364d491d70f7e42cd0d690922659d329f6465e89feb8a34e8cd3433"}, @@ -31,12 +34,16 @@ "plug_cowboy": {:hex, :plug_cowboy, "2.6.1", "9a3bbfceeb65eff5f39dab529e5cd79137ac36e913c02067dba3963a26efe9b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "de36e1a21f451a18b790f37765db198075c25875c64834bcc82d90b309eb6613"}, "plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"}, "postgrex": {:hex, :postgrex, "0.17.3", "c92cda8de2033a7585dae8c61b1d420a1a1322421df84da9a82a6764580c503d", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "946cf46935a4fdca7a81448be76ba3503cff082df42c6ec1ff16a4bdfbfb098d"}, + "rabbit_common": {:hex, :rabbit_common, "3.12.4", "20fb8c871bd6d0553c5bfdba870483962cc42e4425586cfbfdf29bad33fb84eb", [:make, :rebar3], [{:credentials_obfuscation, "3.4.0", [hex: :credentials_obfuscation, repo: "hexpm", optional: false]}, {:recon, "2.5.3", [hex: :recon, repo: "hexpm", optional: false]}, {:thoas, "1.0.0", [hex: :thoas, repo: "hexpm", optional: false]}], "hexpm", "56af4ec8b0dc694737993a7723367d9e2d89e8331668c9c18daa692d43e25744"}, + "rabbitmq_stream": {:hex, :rabbitmq_stream, "0.1.0", "a88ad50e9adae3c449df1289560442c6e8f35183b101550ca5838059e2b0a848", [:mix], [], "hexpm", "1a45452728f33722fe38eeb8c2637b8a596c65ae2970a1920f9c435fd103b14d"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "recon": {:hex, :recon, "2.5.3", "739107b9050ea683c30e96de050bc59248fd27ec147696f79a8797ff9fa17153", [:mix, :rebar3], [], "hexpm", "6c6683f46fd4a1dfd98404b9f78dcabc7fcd8826613a89dcb984727a8c3099d7"}, "swoosh": {:hex, :swoosh, "1.11.6", "7093531c12a537839c7b0777276aaad9f38a887e61c1d517f3b6a8dc6e9040d9", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7fbb7bd0b674e344dbd3a15c33ca787357663ef534dde2cc5ee74d00f7427fd5"}, "tailwind": {:hex, :tailwind, "0.2.1", "83d8eadbe71a8e8f67861fe7f8d51658ecfb258387123afe4d9dc194eddc36b0", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "e8a13f6107c95f73e58ed1b4221744e1eb5a093cd1da244432067e19c8c9a277"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, + "thoas": {:hex, :thoas, "1.0.0", "567c03902920827a18a89f05b79a37b5bf93553154b883e0131801600cf02ce0", [:rebar3], [], "hexpm", "fc763185b932ecb32a554fb735ee03c3b6b1b31366077a2427d2a97f3bd26735"}, "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, "websock_adapter": {:hex, :websock_adapter, "0.5.4", "7af8408e7ed9d56578539594d1ee7d8461e2dd5c3f57b0f2a5352d610ddde757", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "d2c238c79c52cbe223fcdae22ca0bb5007a735b9e933870e241fce66afb4f4ab"}, }