Add pipeline stage reordering
This commit is contained in:
parent
fc2b8f6036
commit
5f81d8dfe4
|
@ -47,6 +47,30 @@ defmodule FrenzyWeb.EditPipelineLive do
|
||||||
{:noreply, assign(socket, pipeline: pipeline)}
|
{:noreply, assign(socket, pipeline: pipeline)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event(event, %{"index" => index}, socket) when event in ["move_up", "move_down"] do
|
||||||
|
index = String.to_integer(index)
|
||||||
|
|
||||||
|
offset =
|
||||||
|
case event do
|
||||||
|
"move_up" -> -1
|
||||||
|
"move_down" -> 1
|
||||||
|
end
|
||||||
|
|
||||||
|
pipeline = socket.assigns.pipeline
|
||||||
|
stage = Enum.at(pipeline.stages, index)
|
||||||
|
|
||||||
|
changeset =
|
||||||
|
Pipeline.changeset(pipeline, %{
|
||||||
|
stages:
|
||||||
|
pipeline.stages
|
||||||
|
|> List.delete_at(index)
|
||||||
|
|> List.insert_at(index + offset, stage)
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, pipeline} = Repo.update(changeset)
|
||||||
|
{:noreply, assign(socket, pipeline: pipeline)}
|
||||||
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:update_stage_opts, index, new_opts}, socket) do
|
def handle_info({:update_stage_opts, index, new_opts}, socket) do
|
||||||
pipeline = socket.assigns.pipeline
|
pipeline = socket.assigns.pipeline
|
||||||
|
|
|
@ -8,13 +8,15 @@
|
||||||
<h4 class="m-0"><%= stage["module_name"] %></h4>
|
<h4 class="m-0"><%= stage["module_name"] %></h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="col text-right">
|
<div class="col text-right">
|
||||||
|
<%= content_tag :button, "Move Up", [phx_click: :move_up, phx_value_index: index, disabled: index == 0] %>
|
||||||
|
|
||||||
|
<%= content_tag :button, "Move Down", [phx_click: :move_down, phx_value_index: index, disabled: index == length(@pipeline.stages) - 1] %>
|
||||||
|
|
||||||
<button phx-click="delete_stage" phx-value-index="<%= index %>">Delete</button>
|
<button phx-click="delete_stage" phx-value-index="<%= index %>">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<%# <pre><%= Jason.encode!(stage["options"], pretty: true) %1></pre> %>
|
|
||||||
<%# <%= live_component(@socket, ) %1> %>
|
|
||||||
<%= component_for(@socket, stage, index) %>
|
<%= component_for(@socket, stage, index) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue