Add pipeline stage reordering

This commit is contained in:
Shadowfacts 2020-06-08 23:27:40 -04:00
parent fc2b8f6036
commit 5f81d8dfe4
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 28 additions and 2 deletions

View File

@ -47,6 +47,30 @@ defmodule FrenzyWeb.EditPipelineLive do
{:noreply, assign(socket, pipeline: pipeline)}
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
def handle_info({:update_stage_opts, index, new_opts}, socket) do
pipeline = socket.assigns.pipeline

View File

@ -8,13 +8,15 @@
<h4 class="m-0"><%= stage["module_name"] %></h4>
</div>
<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>
</div>
</div>
</div>
<div class="card-body">
<%# <pre><%= Jason.encode!(stage["options"], pretty: true) %1></pre> %>
<%# <%= live_component(@socket, ) %1> %>
<%= component_for(@socket, stage, index) %>
</div>
</div>