Start pipeline UI
This commit is contained in:
parent
0a1909dbc4
commit
7f3ff17925
|
@ -53,9 +53,13 @@ defmodule FrenzyWeb.FeedController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit(conn, _params) do
|
def edit(conn, _params) do
|
||||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
feed = conn.assigns[:feed] |> Repo.preload([:filter, :pipeline_stages])
|
||||||
changeset = Feed.changeset(feed, %{})
|
stages = Enum.sort_by(feed.pipeline_stages, fn stage -> stage.index end)
|
||||||
render(conn, "edit.html", changeset: changeset)
|
|
||||||
|
render(conn, "edit.html", %{
|
||||||
|
feed: feed,
|
||||||
|
stages: stages
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(conn, %{"feed" => feed_params}) do
|
def update(conn, %{"feed" => feed_params}) do
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
defmodule FrenzyWeb.PipelineController do
|
||||||
|
use FrenzyWeb, :controller
|
||||||
|
alias Frenzy.{Repo, Feed, PipelineStage}
|
||||||
|
alias FrenzyWeb.Router.Helpers, as: Routes
|
||||||
|
alias FrenzyWeb.Endpoint
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
plug :user_owns_feed
|
||||||
|
plug :user_owns_stage
|
||||||
|
|
||||||
|
defp user_owns_feed(%Plug.Conn{path_params: %{"feed_id" => feed_id}} = conn, _opts) do
|
||||||
|
user = conn.assigns[:user]
|
||||||
|
|
||||||
|
feed = Repo.get(Feed, feed_id) |> Repo.preload(:pipeline_stages)
|
||||||
|
|
||||||
|
if Enum.any?(user.groups, fn g -> g.id == feed.group_id end) do
|
||||||
|
conn
|
||||||
|
|> assign(:feed, feed)
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "You do not have permission to access that resource.")
|
||||||
|
|> redirect(to: Routes.group_path(Endpoint, :index))
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp user_owns_feed(conn, _opts), do: conn
|
||||||
|
|
||||||
|
defp user_owns_stage(%Plug.Conn{path_params: %{"stage_id" => stage_id}} = conn, _opts) do
|
||||||
|
feed = conn.assigns[:feed]
|
||||||
|
|
||||||
|
stage = Repo.get(PipelineStage, stage_id)
|
||||||
|
|
||||||
|
if stage.feed_id == feed.id do
|
||||||
|
conn
|
||||||
|
|> assign(:stage, stage)
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "You do not have permission to access that resource.")
|
||||||
|
|> redirect(to: Routes.group_path(Endpoint, :index))
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp user_owns_stage(conn, _opts), do: conn
|
||||||
|
|
||||||
|
def edit(conn, %{"stage_id" => stage_id}) do
|
||||||
|
feed = conn.assigns[:feed]
|
||||||
|
stage = conn.assigns[:stage]
|
||||||
|
{:ok, options_json} = Jason.encode(stage.options, pretty: true)
|
||||||
|
|
||||||
|
render(conn, "edit.html", %{
|
||||||
|
feed: feed,
|
||||||
|
stage: stage,
|
||||||
|
options: options_json
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
def update(conn, %{"options" => options_json}) do
|
||||||
|
feed = conn.assigns[:feed]
|
||||||
|
stage = conn.assigns[:stage]
|
||||||
|
{:ok, options} = Jason.decode(options_json)
|
||||||
|
changeset = PipelineStage.changeset(stage, %{options: options})
|
||||||
|
{:ok, _stage} = Repo.update(changeset)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Pipeline Stage updated")
|
||||||
|
|> redirect(to: Routes.feed_path(Endpoint, :edit, feed.id))
|
||||||
|
end
|
||||||
|
|
||||||
|
def new(conn, _params) do
|
||||||
|
changeset = PipelineStage.changeset(%PipelineStage{}, %{})
|
||||||
|
|
||||||
|
render(conn, "new.html", %{
|
||||||
|
feed: conn.assigns[:feed],
|
||||||
|
changeset: changeset
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
def create(conn, %{
|
||||||
|
"pipeline_stage" => %{
|
||||||
|
"index" => index,
|
||||||
|
"module_name" => module_name,
|
||||||
|
"options" => options_json
|
||||||
|
}
|
||||||
|
}) do
|
||||||
|
feed = conn.assigns[:feed]
|
||||||
|
{index, _} = Integer.parse(index)
|
||||||
|
{:ok, options} = Jason.decode(options_json)
|
||||||
|
|
||||||
|
changeset =
|
||||||
|
Ecto.build_assoc(feed, :pipeline_stages, %{
|
||||||
|
index: index,
|
||||||
|
module_name: module_name,
|
||||||
|
options: options
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, _stage} = Repo.insert(changeset)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Pipeline Stage created")
|
||||||
|
|> redirect(to: Routes.feed_path(Endpoint, :edit, feed.id))
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete(conn, _params) do
|
||||||
|
feed = conn.assigns[:feed]
|
||||||
|
stage = conn.assigns[:stage]
|
||||||
|
{:ok, _stage} = Repo.delete(stage)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Pipeline Stage deleted")
|
||||||
|
|> redirect(to: Routes.feed_path(Endpoint, :edit, feed.id))
|
||||||
|
end
|
||||||
|
end
|
|
@ -49,8 +49,14 @@ defmodule FrenzyWeb.Router do
|
||||||
|
|
||||||
resources "/feeds", FeedController, except: [:index, :new]
|
resources "/feeds", FeedController, except: [:index, :new]
|
||||||
post "/feeds/:id/refresh", FeedController, :refresh
|
post "/feeds/:id/refresh", FeedController, :refresh
|
||||||
#post "/feeds/:id/enable_filter", FeedController, :enable_filter
|
|
||||||
#post "/feeds/:id/disable_filter", FeedController, :disable_filter
|
# resources "/pipelines", PipelineController, only: [:edit, :update, :new, :create]
|
||||||
|
|
||||||
|
get "/feeds/:feed_id/pipelines/:stage_id/edit", PipelineController, :edit
|
||||||
|
post "/feeds/:feed_id/pipelines/:stage_id/update", PipelineController, :update
|
||||||
|
delete "/feeds/:feed_id/pipelines/:stage_id/delete", PipelineController, :delete
|
||||||
|
get "/feeds/:feed_id/pipelines/new", PipelineController, :new
|
||||||
|
post "/feeds/:feed_id/pipelines/create", PipelineController, :create
|
||||||
|
|
||||||
resources "/filters", FilterController, only: [:edit, :update]
|
resources "/filters", FilterController, only: [:edit, :update]
|
||||||
post "/filters/:id/add_rule", FilterController, :add_rule
|
post "/filters/:id/add_rule", FilterController, :add_rule
|
||||||
|
|
|
@ -1,25 +1,29 @@
|
||||||
<h2>Feed</h2>
|
<h2>Feed Pipeline</h2>
|
||||||
<%= form_tag Routes.filter_path(@conn, :edit, @changeset.data.filter.id), method: :get, class: "d-inline" do %>
|
|
||||||
<%= submit "Edit Filter", class: "btn btn-secondary" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= form_for @changeset, Routes.feed_path(@conn, :update, @changeset.data.id), fn form -> %>
|
<table class="table table-striped mt-4">
|
||||||
<div class="form-group row">
|
<thead>
|
||||||
<label class="col-sm-3 col-form-label" for="filter_enabled">Filter Enabled</label>
|
<tr>
|
||||||
<div class="col-sm-9">
|
<th>Module</th>
|
||||||
<%= checkbox form, :filter_enabled %>
|
<th></th>
|
||||||
</div>
|
</tr>
|
||||||
</div>
|
</thead>
|
||||||
<div class="form-group row">
|
<tbody>
|
||||||
<label class="col-sm-3 col-form-label" for="scrape_remote_content">Scrape Remote Content</label>
|
<%= for stage <- @stages do %>
|
||||||
<div class="col-sm-9">
|
<tr>
|
||||||
<%= checkbox form, :scrape_remote_content %>
|
<td>
|
||||||
</div>
|
<code><%= stage.module_name %></code>
|
||||||
</div>
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="<%= Routes.pipeline_path(@conn, :edit, @feed.id, stage.id) %>" class="btn btn-primary btn-sm">
|
||||||
|
Edit
|
||||||
|
</a>
|
||||||
|
<%= form_for @conn, Routes.pipeline_path(@conn, :delete, @feed.id, stage.id), [method: :delete, style: "display: inline-block;"], fn f -> %>
|
||||||
|
<%= submit "Delete", class: "btn btn-danger btn-sm" %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
<div class="form-group row">
|
<a href="<%= Routes.pipeline_path(@conn, :new, @feed.id) %>" class="btn btn-primary">Add Stage</a>
|
||||||
<div class="col-sm-10">
|
|
||||||
<%= submit "Update Feed", class: "btn btn-primary" %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<h2>Pipeline Stage</h2>
|
||||||
|
<h3>Feed: <%= @feed.title %></h3>
|
||||||
|
<h3>Module: <code><%= @stage.module_name %></code></h3>
|
||||||
|
|
||||||
|
<%= form_for @conn, Routes.pipeline_path(@conn, :update, @feed.id, @stage.id), fn f -> %>
|
||||||
|
<%= textarea f, :options, value: @options, class: "form-control", rows: 15, style: "font-family: monospace;" %>
|
||||||
|
<%= submit "Update", class: "btn btn-primary mt-2" %>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<h2>Feed Pipeline</h2>
|
||||||
|
|
||||||
|
<%= form_for @changeset, Routes.pipeline_path(@conn, :create, @feed.id), fn f -> %>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-2 col-form-label" for="module_name">Module Name</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<%= text_input f, :module_name, placeholder: "Frenzy.Pipeline.FilterStage", class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-2 col-form-label" for="index">Index</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<%= number_input f, :index, value: "#{@feed.pipeline_stages |> Enum.count()}", class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-2 col-form-label" for="options">Options</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<%= textarea f, :options, value: "{}", class: "form-control", rows: 15, style: "font-family: monospace;" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<%= submit "Create Stage", class: "btn btn-primary" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule FrenzyWeb.PipelineView do
|
||||||
|
use FrenzyWeb, :view
|
||||||
|
end
|
Loading…
Reference in New Issue