copy and customize filters

This commit is contained in:
byte[] 2020-01-11 14:24:30 -05:00
parent 858ddcc8ec
commit d184ee0817
4 changed files with 31 additions and 4 deletions

View file

@ -58,6 +58,30 @@ defmodule PhilomenaWeb.FilterController do
) )
end end
def new(conn, %{"based_on" => filter_id}) do
# The last line here is a hack to get Ecto to save a new
# model instead of trying to update the existing one.
filter =
Filter
|> where(id: ^filter_id)
|> where(
[f],
f.system == true or f.public == true or f.user_id == ^conn.assigns.current_user.id
)
|> Repo.one()
|> Kernel.||(%Filter{})
|> TagList.assign_tag_list(:spoilered_tag_ids, :spoilered_tag_list)
|> TagList.assign_tag_list(:hidden_tag_ids, :hidden_tag_list)
|> Map.put(:__meta__, %Ecto.Schema.Metadata{
state: :built,
source: "filters",
schema: Filter
})
changeset = Filters.change_filter(filter)
render(conn, "new.html", title: "New Filter", changeset: %{changeset | action: nil})
end
def new(conn, _params) do def new(conn, _params) do
changeset = Filters.change_filter(%Filter{}) changeset = Filters.change_filter(%Filter{})
render(conn, "new.html", title: "New Filter", changeset: changeset) render(conn, "new.html", title: "New Filter", changeset: changeset)

View file

@ -21,6 +21,8 @@
li li
= link "View this filter", to: Routes.filter_path(@conn, :show, @filter), class: "button" = link "View this filter", to: Routes.filter_path(@conn, :show, @filter), class: "button"
li
= link "Copy and Customize", to: Routes.filter_path(@conn, :new, based_on: @filter), class: "button"
= if can?(@conn, :edit, @filter) do = if can?(@conn, :edit, @filter) do
li li

View file

@ -1,5 +1,6 @@
.form .form
= form_for @filter, @route, fn f -> = form_for @filter, @route, fn f ->
- IO.inspect @filter.data
= if @filter.action do = if @filter.action do
#error_explanation #error_explanation
' Oops, something went wrong! Please check the errors below. ' Oops, something went wrong! Please check the errors below.

View file

@ -9,9 +9,9 @@
strong> Price Range: strong> Price Range:
- {min, max} = Enum.min_max_by(@user.commission.items, & &1.base_price) - {min, max} = Enum.min_max_by(@user.commission.items, & &1.base_price)
| $ | $
=> Decimal.round(min.base_price, 2) |> Decimal.to_string() => Decimal.round(min.base_price || 0, 2) |> Decimal.to_string()
| - $ | - $
=> Decimal.round(max.base_price, 2) |> Decimal.to_string() => Decimal.round(max.base_price || 0, 2) |> Decimal.to_string()
' USD ' USD
br br