Skip to content
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

Phoenix html 4 compatibility #147

Closed
wants to merge 16 commits into from
Closed
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ExqUI

#This is a complete fork from akira/exq_ui
#it's a temporary measure to support phoenix_html 4 +, when they are able to bump their side, this repo will be closed
[![Hex.pm](https://img.shields.io/hexpm/v/exq_ui.svg)](https://hex.pm/packages/exq_ui)

ExqUI provides a UI dashboard for [Exq](https://github.com/akira/exq), a job processing library
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ config :exq,
port: 6379,
namespace: "exq"

config :exq_ui,
config :exq_ui_fork,
api_name: Exq.Api,
exq_scheduler_name: ExqScheduler

Expand Down
4 changes: 2 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Config

# Print only warnings and errors during test
config :logger, level: :warn
config :logger, level: :warning
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specifically deals with the warning

warning: :logger :level has been set to :warn in config files, please use :warning instead
  (logger 1.16.1) lib/logger/app.ex:102: Logger.App.default_level/0
  (logger 1.16.1) lib/logger/app.ex:35: Logger.App.start/2
  (kernel 9.2) application_master.erl:293: :application_master.start_it_old/4


config :exq_ui, DemoWeb.Endpoint,
config :exq_ui_fork, DemoWeb.Endpoint,
secret_key_base: "JUrii8hEdYZjAo/LHUziUO1xx0ViDK+I1yYDVvNrLpcYWH93l4kSBvWsbfGwJRu5",
live_view: [signing_salt: "jhwmDSe0"],
pubsub_server: ExqUI.PubSub
4 changes: 2 additions & 2 deletions dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Logger.configure(level: :debug)
Application.ensure_all_started(:exq_scheduler)

# Configures the endpoint
Application.put_env(:exq_ui, DemoWeb.Endpoint,
Application.put_env(:exq_ui_fork, DemoWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "JUrii8hEdYZjAo/LHUziUO1xx0ViDK+I1yYDVvNrLpcYWH93l4kSBvWsbfGwJRu5",
live_view: [signing_salt: "jhwmDSe0"],
Expand Down Expand Up @@ -47,7 +47,7 @@ defmodule DemoWeb.Router do
end

defmodule DemoWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :exq_ui
use Phoenix.Endpoint, otp_app: :exq_ui_fork

@session_options [
store: :cookie,
Expand Down
2 changes: 1 addition & 1 deletion lib/exq_ui/queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ defmodule ExqUI.Queue do
end

def api do
Application.get_env(:exq_ui, :api_name, Exq.Api)
Application.get_env(:exq_ui_fork, :api_name, Exq.Api)
end
end
4 changes: 3 additions & 1 deletion lib/exq_ui_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ defmodule ExqUIWeb do
defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers
Comment on lines -58 to +60
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to provide backwards compability with phoenix_html 3.3 through the helpers package
{:phoenix_html_helpers, "~> 1.0"}, as the built in recommendation in upgrading


import Phoenix.Component
# Import LiveView helpers (live_render, live_component, live_patch, etc)
Expand Down
49 changes: 34 additions & 15 deletions lib/exq_ui_web/live/busy_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
<tr>
<td>
<div class="d-flex align-items-center">
<span class="me-2"><%= node.identity %></span>
<%= form_for :signal, "#", [id: "node-#{node.identity}", phx_auto_recover: :ignore, phx_change: :signal, class: "mb-0 form-check form-switch form-check-inline"], fn f -> %>
<span class="me-2">
<%= node.identity %>
</span>
<%= form_for :signal, "#" , [id: "node-#{node.identity}" , phx_auto_recover: :ignore, phx_change: :signal,
class: "mb-0 form-check form-switch form-check-inline" ], fn f -> %>
<%= hidden_input(f, :name, value: "TSTP") %>
<%= hidden_input(f, :node_id, value: node.identity) %>
<%= checkbox(f, :quiet,
Expand All @@ -26,10 +29,15 @@
) %>
<% end %>
</div>
<span><b>Queues: </b><%= Enum.join(node.queues, ", ") %></span>
<span><b>Queues: </b>
<%= Enum.join(node.queues, ", ") %></span>
</td>
<td>
<%= human_time(node.started_at) %>
</td>
<td>
<%= node.busy %>
</td>
<td><%= human_time(node.started_at) %></td>
<td><%= node.busy %></td>
</tr>
<% end %>
</tbody>
Expand All @@ -50,18 +58,29 @@
<tbody>
<%= for job <- @jobs do %>
<tr>
<td><%= job.host %></td>
<td><%= job.pid %></td>
<td><%= job.payload.jid %></td>
<td>
<%= live_redirect(job.queue,
class: "nounderline",
to: Routes.queue_show_path(@socket, job.queue)
) %>
<%= job.host %>
</td>
<td>
<%= job.pid %>
</td>
<td>
<%= job.payload.jid %>
</td>
<td>
<.link navigate={Routes.queue_show_path(@socket, job.queue)} class="nounderline">
<%= job.queue %>
</.link>
Comment on lines +70 to +73
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of the warning to that live_redirect is deprecated

</td>
<td>
<%= job.payload.class %>
</td>
<td>
<%= inspect(job.payload.args) %>
</td>
<td>
<%= human_time(job.run_at) %>
</td>
<td><%= job.payload.class %></td>
<td><%= inspect(job.payload.args) %></td>
<td><%= human_time(job.run_at) %></td>
</tr>
<% end %>
</tbody>
Expand Down
51 changes: 43 additions & 8 deletions lib/exq_ui_web/live/components/nav_bar_component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,61 @@
<div class="collapse navbar-collapse">
<ul class="navbar-nav me-auto mb-lg-0">
<li class="nav-item">
<%= nav_link(@socket, "Dashboard", Routes.dashboard_path(@socket)) %>
<.link
navigate={Routes.dashboard_path(@socket)}
class={nav_link_class(@socket, "Dashboard")}
>
Dashboard
</.link>
</li>
<li class="nav-item">
<%= nav_link(@socket, "Busy", Routes.busy_index_path(@socket)) %>
<.link
navigate={Routes.busy_index_path(@socket)}
class={nav_link_class(@socket, "Busy")}
>
Busy
</.link>
</li>
<li class="nav-item">
<%= nav_link(@socket, "Queues", Routes.queue_index_path(@socket)) %>
<.link
navigate={Routes.queue_index_path(@socket)}
class={nav_link_class(@socket, "Queues")}
>
Queues
</.link>
</li>
<li class="nav-item">
<%= nav_link(@socket, "Retries", Routes.retry_index_path(@socket)) %>
<.link
navigate={Routes.retry_index_path(@socket)}
class={nav_link_class(@socket, "Retries")}
>
Retries
</.link>
</li>
<li class="nav-item">
<%= nav_link(@socket, "Scheduled", Routes.scheduled_index_path(@socket)) %>
<.link
navigate={Routes.scheduled_index_path(@socket)}
class={nav_link_class(@socket, "Scheduled")}
>
Scheduled
</.link>
</li>
<li class="nav-item">
<%= nav_link(@socket, "Dead", Routes.dead_index_path(@socket)) %>
<.link
navigate={Routes.dead_index_path(@socket)}
class={nav_link_class(@socket, "Dead")}
>
Dead
</.link>
</li>
<%= if Application.get_env(:exq_ui, :exq_scheduler_name) do %>
<%= if Application.get_env(:exq_ui_fork, :exq_scheduler_name) do %>
<li class="nav-item">
<%= nav_link(@socket, "Recurring", Routes.recurring_index_path(@socket)) %>
<.link
navigate={Routes.recurring_index_path(@socket)}
class={nav_link_class(@socket, "Recurring")}
>
Recurring
</.link>
</li>
<% end %>
</ul>
Expand Down
21 changes: 17 additions & 4 deletions lib/exq_ui_web/live/components/table_component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
<div class="row">
<div class="col-12">
<%= form_for :table, "#", [phx_submit: :action], fn f -> %>
<%= form_for :table, "#" , [phx_submit: :action], fn f -> %>
<button type="submit" class="btn btn-primary js-submit-button" style="display:none">
Submit
</button>
Expand All @@ -31,7 +31,9 @@
<input class="form-check-input js-select-all-rows" type="checkbox" value="" />
</th>
<%= for %{header: header} <- @columns do %>
<th scope="col"><%= header %></th>
<th scope="col">
<%= header %>
</th>
<% end %>
</tr>
</thead>
Expand All @@ -45,8 +47,19 @@
class: "form-check-input js-select-row"
) %>
</td>
<%= for %{accessor: accessor} = column <- @columns do %>
<td class={column[:text_break] && "text-break"}><%= accessor.(item) %></td>
<%= for column <- @columns do %>
<td class={column[:text_break] && "text-break"}>
<%= if column[:link] do %>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the nav_link approach before, to cator for the least amount of changes, I allowed colums to provide an optional field :link to determind whether it is one.
There are other more invasive/workflow changing ones, I felt that this way was the least disruptive. I'm happy to consider the other approaches

<.link
navigate={column.accessor.(item)[:link]}
class={column.accessor.(item)[:class]}
>
<%= column.accessor.(item)[:text] %>
</.link>
<% else %>
<%= column.accessor.(item) %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
Expand Down
8 changes: 5 additions & 3 deletions lib/exq_ui_web/live/dead_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ defmodule ExqUIWeb.DeadLive.Index do
assign(socket, :columns, [
%{
header: "Last Failed",
link: true,
accessor: fn item ->
live_redirect(human_time(item.scheduled_at),
to: Routes.dead_show_path(socket, item.score, item.id),
%{
text: human_time(item.scheduled_at),
link: Routes.dead_show_path(socket, item.score, item.id),
class: "nounderline"
)
}
end
},
%{header: "Retry Count", accessor: fn item -> item.job.retry_count end},
Expand Down
27 changes: 15 additions & 12 deletions lib/exq_ui_web/live/queue_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
<tr>
<td>
<span>
<%= live_redirect(queue.name,
class: "nounderline",
to: Routes.queue_show_path(@socket, queue.name)
) %>
<.link navigate={Routes.queue_show_path(@socket, queue.name)} class="nounderline">
<%= queue.name %>
</.link>
</span>
</td>
<td><%= queue.count %></td>
<td>
<%= queue.count %>
</td>
<td>
<span>
<%= link("Delete",
class: "btn btn-danger btn-sm",
to: "#",
phx_click: "delete",
phx_value_name: queue.name,
data: [confirm: "Are you sure?"]
) %>
<.link
navigate="#"
phx-click="delete"
phx-value-name={queue.name}
data-confirm="Are you sure?"
class="btn btn-danger btn-sm"
>
Delete
</.link>
</span>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion lib/exq_ui_web/live/recurring_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ defmodule ExqUIWeb.RecurringLive.Index do
end

defp scheduler do
Application.get_env(:exq_ui, :exq_scheduler_name, ExqScheduler)
Application.get_env(:exq_ui_fork, :exq_scheduler_name, ExqScheduler)
end
end
8 changes: 5 additions & 3 deletions lib/exq_ui_web/live/retry_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ defmodule ExqUIWeb.RetryLive.Index do
assign(socket, :columns, [
%{
header: "Next Retry",
link: true,
accessor: fn item ->
live_redirect(human_time(item.scheduled_at),
to: Routes.retry_show_path(socket, item.score, item.id),
%{
text: human_time(item.scheduled_at),
link: Routes.retry_show_path(socket, item.score, item.id),
class: "nounderline"
)
}
end
},
%{header: "Retry Count", accessor: fn item -> item.job.retry_count end},
Expand Down
8 changes: 5 additions & 3 deletions lib/exq_ui_web/live/scheduled_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ defmodule ExqUIWeb.ScheduledLive.Index do
assign(socket, :columns, [
%{
header: "When",
link: true,
accessor: fn item ->
live_redirect(human_time(item.scheduled_at),
to: Routes.scheduled_show_path(socket, item.score, item.id),
%{
text: human_time(item.scheduled_at),
link: Routes.scheduled_show_path(socket, item.score, item.id),
class: "nounderline"
)
}
end
},
%{header: "Queue", accessor: fn item -> item.job.queue end},
Expand Down
8 changes: 4 additions & 4 deletions lib/exq_ui_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule ExqUIWeb.Router do

## Options

* live_session_name - Name of the live_session. Defaults to `:exq_ui`
* live_session_name - Name of the live_session. Defaults to `:exq_ui_fork`
* live_socket_path - Should match the value used for `socket "/live", Phoenix.LiveView.Socket`. Defaults to `/live`
* live_session_on_mount - Declares an optional module callback to be invoked on the LiveView's mount
"""
Expand All @@ -30,7 +30,7 @@ defmodule ExqUIWeb.Router do
live "/scheduled", ExqUIWeb.ScheduledLive.Index, :index, route_opts
live "/scheduled/:score/:jid", ExqUIWeb.ScheduledLive.Show, :index, route_opts

if Application.compile_env(:exq_ui, :exq_scheduler_name) do
if Application.compile_env(:exq_ui_fork, :exq_scheduler_name) do
live "/recurring", ExqUIWeb.RecurringLive.Index, :index, route_opts
end
end
Expand All @@ -54,7 +54,7 @@ defmodule ExqUIWeb.Router do

@doc false
def __options__(options) do
session_name = options[:live_session_name] || :exq_ui
session_name = options[:live_session_name] || :exq_ui_fork

session_opts = [
session: {__MODULE__, :__session__, []},
Expand All @@ -72,7 +72,7 @@ defmodule ExqUIWeb.Router do

route_opts = [
private: %{live_socket_path: Keyword.get(options, :live_socket_path, "/live")},
as: :exq_ui
as: :exq_ui_fork
]

{session_name, session_opts, route_opts}
Expand Down
Loading
Loading