Add edit pipeline as JSON option
This commit is contained in:
parent
a10f1bea30
commit
6c9247873f
|
@ -3,6 +3,7 @@ defmodule FrenzyWeb.PipelineController do
|
|||
alias Frenzy.{Repo, Pipeline}
|
||||
alias FrenzyWeb.Endpoint
|
||||
import Ecto.Query
|
||||
import Phoenix.LiveView.Controller
|
||||
|
||||
plug :user_owns_pipeline
|
||||
|
||||
|
@ -77,7 +78,7 @@ defmodule FrenzyWeb.PipelineController do
|
|||
redirect(conn, to: Routes.pipeline_path(Endpoint, :index))
|
||||
end
|
||||
|
||||
def edit(conn, _params) do
|
||||
def edit(conn, %{"json" => _}) do
|
||||
pipeline = conn.assigns[:pipeline]
|
||||
|
||||
{:ok, stages_json} = Jason.encode(pipeline.stages, pretty: true)
|
||||
|
@ -89,6 +90,11 @@ defmodule FrenzyWeb.PipelineController do
|
|||
})
|
||||
end
|
||||
|
||||
def edit(conn, _params) do
|
||||
pipeline = conn.assigns[:pipeline]
|
||||
live_render(conn, FrenzyWeb.EditPipelineLive, session: %{"pipeline_id" => pipeline.id})
|
||||
end
|
||||
|
||||
def update(conn, %{"pipeline" => %{"name" => name, "stages" => stages_json}}) do
|
||||
pipeline = conn.assigns[:pipeline]
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ defmodule FrenzyWeb.EditPipelineLive do
|
|||
def stages, do: @stages
|
||||
|
||||
@impl true
|
||||
def mount(%{"id" => pipeline_id}, _session, socket) do
|
||||
def mount(_, %{"pipeline_id" => pipeline_id}, socket) do
|
||||
pipeline = Repo.get(Pipeline, pipeline_id)
|
||||
|
||||
{:ok,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<h1>Edit <%= @pipeline.name %></h1>
|
||||
|
||||
<a href="<%= Routes.pipeline_path(FrenzyWeb.Endpoint, :edit, @pipeline.id, json: "") %>" class="btn btn-primary">Edit as JSON</a>
|
||||
|
||||
<%= for {stage, index} <- Enum.with_index(@pipeline.stages) do %>
|
||||
<div class="card mt-4">
|
||||
<div class="card-header container-fluid">
|
||||
|
@ -22,7 +24,7 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= f = form_for :stage, "#", [class: "mt-4", phx_submit: :add_stage] %>
|
||||
<%= f = form_for :stage, "#", [class: "mt-4 mb-4", phx_submit: :add_stage] %>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label" for="module_name">Module</label>
|
||||
<div class="col-sm-10">
|
||||
|
|
|
@ -54,8 +54,7 @@ defmodule FrenzyWeb.Router do
|
|||
resources "/feeds", FeedController, except: [:index, :new]
|
||||
post "/feeds/:id/refresh", FeedController, :refresh
|
||||
|
||||
resources "/pipelines", PipelineController, except: [:edit]
|
||||
live "/pipelines/:id/edit", EditPipelineLive
|
||||
resources "/pipelines", PipelineController
|
||||
|
||||
resources "/items", ItemController, only: [:show]
|
||||
post "/items/:id/read", ItemController, :read
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<h1>Edit Pipeline</h1>
|
||||
|
||||
<a href="<%= Routes.pipeline_path(@conn, :edit, @pipeline.id) %>" class="btn btn-primary">Edit UI</a>
|
||||
|
||||
<%= form_tag Routes.pipeline_path(@conn, :update, @pipeline.id), method: :put do %>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label" for="name">Name</label>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<h1><%= @pipeline.name %></h1>
|
||||
<h2>Stages: <%= @pipeline.stages |> Enum.count() %></h2>
|
||||
|
||||
<a href="<%= Routes.live_path(@conn, FrenzyWeb.EditPipelineLive, @pipeline.id) %>" class="btn btn-primary">Edit Pipeline</a>
|
||||
<a href="<%= Routes.pipeline_path(@conn, :edit, @pipeline.id) %>" class="btn btn-primary">Edit Pipeline</a>
|
||||
<%= form_tag Routes.pipeline_path(@conn, :delete, @pipeline.id), method: :delete do %>
|
||||
<%= submit "Delete Pipeline", class: "btn btn-danger mt-2" %>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue