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
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
changeset = Filters.change_filter(%Filter{})
render(conn, "new.html", title: "New Filter", changeset: changeset)

View file

@ -21,6 +21,8 @@
li
= 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
li

View file

@ -1,5 +1,6 @@
.form
= form_for @filter, @route, fn f ->
- IO.inspect @filter.data
= if @filter.action do
#error_explanation
' Oops, something went wrong! Please check the errors below.
@ -65,4 +66,4 @@
strong> WARNING:
' This filter is applied along with your tag filters. Tag filters may hide images that you mean to filter more precisely here. Double-check to make sure they don't interfere.
= submit "Save Filter", class: "button"
= submit "Save Filter", class: "button"

View file

@ -9,9 +9,9 @@
strong> Price Range:
- {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
br
@ -29,4 +29,4 @@
=> link "Click here", to: Routes.profile_commission_path(@conn, :new, @user)
' to set it up.
- true ->
- true ->