neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
direct access to the realtime
13a07de · gmorell · 2025-09-13 17:59
Files changed
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_query_live/show.ex
+25
−1
@@ -1,5 +1,6 @@
| 1 | 1 | defmodule RoomSanctumWeb.QueryLive.Show do |
| 2 | 2 | use RoomSanctumWeb, :live_view_a |
| 3 | + import RoomSanctumWeb.LivePreview | |
| 3 | 4 | |
| 4 | 5 | alias RoomSanctum.Configuration |
| 5 | 6 |
@@ -7,7 +8,7 @@ defmodule RoomSanctumWeb.QueryLive.Show do
| 7 | 8 | def mount(_params, _session, socket) do |
| 8 | 9 | if connected?(socket), do: Process.send_after(self(), :update_sec, 200) |
| 9 | 10 | if connected?(socket), do: Process.send_after(self(), :update, 1000) |
| 10 | − {:ok, socket |> assign(:preview, [])} | |
| 11 | + {:ok, socket |> assign(:preview, []) |> assign(:preview_mode, :basic)} | |
| 11 | 12 | end |
| 12 | 13 | |
| 13 | 14 | @impl true |
@@ -110,9 +111,32 @@ defmodule RoomSanctumWeb.QueryLive.Show do
| 110 | 111 | {:noreply, socket |> assign(:avail_sel, !socket.assigns.avail_sel)} |
| 111 | 112 | end |
| 112 | 113 | |
| 114 | + def handle_event("toggle-preview-mode", _params, socket) do | |
| 115 | + {:noreply, socket |> assign(:preview_mode, do_toggle(socket.assigns.preview_mode))} | |
| 116 | + end | |
| 117 | + | |
| 113 | 118 | defp page_title(:show), do: "Query Detail" |
| 114 | 119 | defp page_title(:edit), do: "Modify Query" |
| 115 | 120 | |
| 121 | + defp do_toggle(state) do | |
| 122 | + case state do | |
| 123 | + :basic -> :raw | |
| 124 | + :raw -> :basic | |
| 125 | + end | |
| 126 | + end | |
| 127 | + | |
| 128 | + defp condense(data, {id, type}) do | |
| 129 | + RoomSanctum.Condenser.BasicMQTT.condense({id, type}, data) | |
| 130 | + end | |
| 131 | + | |
| 132 | + defp get_icon(type) do | |
| 133 | + RoomSanctumWeb.IconHelpers.icon(type) | |
| 134 | + end | |
| 135 | + | |
| 136 | + def preview(condensed, {id, type}) do | |
| 137 | + %{data: condensed, id: id, type: type} | |
| 138 | + end | |
| 139 | + | |
| 116 | 140 | defp package_icon(carrier) do |
| 117 | 141 | case carrier do |
| 118 | 142 | :ups -> "fa-brands fa-ups fa-fw" |
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_query_live/show.html.heex
+34
−39
@@ -61,47 +61,42 @@
| 61 | 61 | <div class="flex"> |
| 62 | 62 | <div class="card card-compact w-1/2 bg-base-100 shadow-xl m-2"> |
| 63 | 63 | <div class="card-body"> |
| 64 | − <h3 class="card-title">Quick Data Preview</h3> | |
| 65 | − <p> | |
| 66 | − <%= for x <- @preview do %> | |
| 64 | + <div class="flex"> | |
| 65 | + <div class="flex-auto basis-4/5"> | |
| 66 | + <h3 class="card-title w-full">Quick Data Preview</h3> | |
| 67 | + </div> | |
| 68 | + <div class="flex-1 w-3/4"> | |
| 69 | + | |
| 70 | + </div> | |
| 71 | + <div class="flex-none w-20"> | |
| 72 | + <button class="btn btn-secondary btn-sm" phx-click="toggle-preview-mode"><%= @preview_mode %></button> | |
| 73 | + </div> | |
| 74 | + </div> | |
| 75 | + <%= case @preview_mode do %> | |
| 76 | + <%= :basic -> %> | |
| 67 | 77 | <%= case @type do %> |
| 68 | − <%= :gtfs -> %> | |
| 69 | − <%= x.trip.route_id %> <i class="fas fa-arrow-right"></i> <%= x.trip.trip_headsign %> @ <%= x.arrival_time %> | |
| 70 | − <% :gbfs -> %> | |
| 71 | − <%= x.num_bikes_available %> / | |
| 72 | − <%= x.capacity %> | |
| 73 | − <% :tidal -> %> | |
| 74 | − @<%= x.t %> <%= x.type %> <%= x.v %> Meters | |
| 75 | − <% :weather -> %> | |
| 76 | − <%= x.main.temp %>° & <%= x.weather |> List.first |> Map.get(:main)%> | |
| 77 | − <% :aqi -> %> | |
| 78 | − <%= if x.pm25_measured do %> PM2.5@ <%= x.pm25_aqi %><br /> <% end %> | |
| 79 | − <%= if x.pm10_measured do %> PM10@ <%= x.pm10_aqi %> <br /> <% end %> | |
| 80 | − <%= if x.ozone_measured do %> O3@ <%= x.ozone_aqi %> <br /> <% end %> | |
| 81 | − <%= if x.no2_measured do %> NO2@ <%= x.no2_aqi %> <br /> <% end %> | |
| 82 | − <% :ephem -> %> | |
| 83 | − <%= if x |> Map.has_key?(:period) do %> | |
| 84 | − <%= x.period %> @ <%= x.result %> | |
| 85 | − <%= else %> | |
| 86 | − <%= x.name %> | |
| 87 | − <% end %> | |
| 88 | − <% :calendar -> %> | |
| 89 | − <%= x.date_start %> <%= x.blob["description"] %> | |
| 90 | − <% :cronos -> %> | |
| 91 | − <%= x.name %> <strong><%= x.value %></strong> | |
| 92 | − <% :gitlab -> %> | |
| 93 | − <strong><%= x["commit"]["title"] %></strong> <%= x["duration"] %> seconds elapsed | |
| 94 | − <% :packages -> %> | |
| 95 | − <i class={package_icon(x.type)}></i> <%= x.number %> | |
| 96 | − <%= if x.entries != [] do %> | |
| 97 | − <%= x.entries |> List.last |> Map.get("activityStatus", %{}) |> Map.get("description") %> | |
| 98 | − <% else %> | |
| 99 | − No Tracking Data, Yet | |
| 100 | − <% end %> | |
| 101 | − <% end %> | |
| 102 | − <br /> | |
| 78 | + <%= :gtfs -> %> <.p_gtfs entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_gtfs> | |
| 79 | + <% :gbfs -> %> <.p_gbfs entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_gbfs> | |
| 80 | + <% :tidal -> %> <.p_tidal entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_tidal> | |
| 81 | + <% :weather -> %> <.p_weather entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_weather> | |
| 82 | + <% :aqi -> %> <.p_aqi entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_aqi> | |
| 83 | + <% :ephem -> %> <.p_ephem entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_ephem> | |
| 84 | + <% :calendar -> %> <.p_calendar entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_calendar> | |
| 85 | + <% :cronos -> %> <.p_cronos entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_cronos> | |
| 86 | + <% :gitlab -> %> <.p_gitlab entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_gitlab> | |
| 87 | + <% :packages -> %> <.p_packages entries={preview(condense(@preview, {@query.id, @type}), {@query.id, @type})}> </.p_packages> | |
| 103 | 88 | <% end %> |
| 104 | − </p> | |
| 89 | + <% :raw -> %> | |
| 90 | + <div class="flex"> | |
| 91 | + <div class="w-16"> | |
| 92 | + <i class={"fas fa-fw fa-2xl #{get_icon(@type)}"}></i> | |
| 93 | + </div> | |
| 94 | + <div class="w-7/8"> | |
| 95 | + <span class="text-secondary font-bold"><%= @query.name %></span> | |
| 96 | + <pre><%= condense(@preview, {@query.id, @type}) |> Poison.encode!(pretty: true)%></pre> | |
| 97 | + </div> | |
| 98 | + </div> | |
| 99 | + <% end %> | |
| 105 | 100 | </div> |
| 106 | 101 | </div> |
| 107 | 102 | <div class="card card-compact w-1/2 bg-base-100 shadow-xl m-2"> |
Parents: 17909df