mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
copy and customize filters
This commit is contained in:
parent
858ddcc8ec
commit
d184ee0817
4 changed files with 31 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue