forked from hiway/freedive
Add enable/disable service commands
This commit is contained in:
parent
10295acdc6
commit
c0da209cac
2 changed files with 47 additions and 3 deletions
|
@ -34,6 +34,14 @@ defmodule Freedive.Api.Service do
|
||||||
GenServer.call(__MODULE__, {:list})
|
GenServer.call(__MODULE__, {:list})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enable(name) do
|
||||||
|
GenServer.cast(__MODULE__, {:command, name, "enable"})
|
||||||
|
end
|
||||||
|
|
||||||
|
def disable(name) do
|
||||||
|
GenServer.cast(__MODULE__, {:command, name, "disable"})
|
||||||
|
end
|
||||||
|
|
||||||
def start(name) do
|
def start(name) do
|
||||||
GenServer.cast(__MODULE__, {:command, name, "start"})
|
GenServer.cast(__MODULE__, {:command, name, "start"})
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,8 +51,10 @@ defmodule FreediveWeb.ServiceLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("action:" <> action, %{"name" => service_name}, socket)
|
def handle_event("action:" <> action, %{"name" => service_name}, socket)
|
||||||
when action in ["start", "stop", "restart"] do
|
when action in ["enable", "disable", "start", "stop", "restart"] do
|
||||||
case action do
|
case action do
|
||||||
|
"enable" -> Service.enable(service_name)
|
||||||
|
"disable" -> Service.disable(service_name)
|
||||||
"start" -> Service.start(service_name)
|
"start" -> Service.start(service_name)
|
||||||
"stop" -> Service.stop(service_name)
|
"stop" -> Service.stop(service_name)
|
||||||
"restart" -> Service.restart(service_name)
|
"restart" -> Service.restart(service_name)
|
||||||
|
@ -160,8 +162,9 @@ defmodule FreediveWeb.ServiceLive.Components do
|
||||||
<.back_link selected_item={@selected_item} />
|
<.back_link selected_item={@selected_item} />
|
||||||
<.service_header selected_item={@selected_item} />
|
<.service_header selected_item={@selected_item} />
|
||||||
<.std_log selected_item={@selected_item} />
|
<.std_log selected_item={@selected_item} />
|
||||||
<.basic_commands selected_item={@selected_item} />
|
|
||||||
<.extra_commands selected_item={@selected_item} />
|
<.extra_commands selected_item={@selected_item} />
|
||||||
|
<.start_stop_commands selected_item={@selected_item} />
|
||||||
|
<.enable_disable_commands selected_item={@selected_item} />
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -228,7 +231,40 @@ defmodule FreediveWeb.ServiceLive.Components do
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
def basic_commands(assigns) do
|
def enable_disable_commands(assigns) do
|
||||||
|
~H"""
|
||||||
|
<.panel_block_div>
|
||||||
|
<%= if @selected_item.enabled do %>
|
||||||
|
<.icon_raw for="enabled" color="lightgreen" size="1.5rem" class="ml-2 mr-5" aria-hidden="true" />
|
||||||
|
<% else %>
|
||||||
|
<.icon_raw for="disabled" color="gray" size="1.5rem" class="ml-2 mr-5" aria-hidden="true" />
|
||||||
|
<% end %>
|
||||||
|
<div class="columns is-fullwidth mr-4">
|
||||||
|
<%= if @selected_item.enabled do %>
|
||||||
|
<button
|
||||||
|
class="button is-danger column is-2 m-2 is-fullwidth"
|
||||||
|
phx-click="action:disable"
|
||||||
|
phx-value-name={@selected_item.name}
|
||||||
|
{if @selected_item.busy, do: [disabled: true], else: []}
|
||||||
|
>
|
||||||
|
Disable
|
||||||
|
</button>
|
||||||
|
<% else %>
|
||||||
|
<button
|
||||||
|
class="button is-success column is-2 m-2 is-fullwidth"
|
||||||
|
phx-click="action:enable"
|
||||||
|
phx-value-name={@selected_item.name}
|
||||||
|
{if @selected_item.busy, do: [disabled: true], else: []}
|
||||||
|
>
|
||||||
|
Enable
|
||||||
|
</button>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</.panel_block_div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_stop_commands(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.panel_block_div>
|
<.panel_block_div>
|
||||||
<%= if @selected_item.running do %>
|
<%= if @selected_item.running do %>
|
||||||
|
|
Loading…
Reference in a new issue