mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +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
|
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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue