From 0c7f13932bb451f9f1cc2d5b9c81230f62d77fbb Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 30 Dec 2019 18:32:24 -0500 Subject: [PATCH] add deleted toggle to main search form --- lib/philomena/schema/search.ex | 4 ++-- lib/philomena_web/templates/search/_form.html.slime | 12 +++++++++++- lib/philomena_web/views/search_view.ex | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/philomena/schema/search.ex b/lib/philomena/schema/search.ex index 5145ca73..971f7fdb 100644 --- a/lib/philomena/schema/search.ex +++ b/lib/philomena/schema/search.ex @@ -1,10 +1,10 @@ defmodule Philomena.Schema.Search do alias Philomena.Images.Query - import Search.String + alias Search.String import Ecto.Changeset def validate_search(changeset, field, user, watched \\ false) do - query = changeset |> get_field(field) |> normalize() + query = changeset |> get_field(field) |> String.normalize() output = Query.compile(user, query, watched) case output do diff --git a/lib/philomena_web/templates/search/_form.html.slime b/lib/philomena_web/templates/search/_form.html.slime index 14651afd..a73e2d61 100644 --- a/lib/philomena_web/templates/search/_form.html.slime +++ b/lib/philomena_web/templates/search/_form.html.slime @@ -129,5 +129,15 @@ h1 Search "Ascending": :asc ] + sort_hidden = [ + "Exclude Deleted": "", + "Include Deleted/Merged": "1", + "Deleted Only": "deleted", + "Deleted/Merged Only": "only" + ] + = select f, :sf, sort_fields, class: "input input--separate-left", name: "sf", autocomplete: "off", selected: @conn.params["sf"] - = select f, :sd, sort_directions, class: "input input--separate-left", name: "sd", autocomplete: "off", selected: @conn.params["sd"] \ No newline at end of file + = select f, :sd, sort_directions, class: "input input--separate-left", name: "sd", autocomplete: "off", selected: @conn.params["sd"] + + = if hides_images?(@conn) do + = select f, :del, sort_hidden, class: "input input--separate-left", name: "del", autocomplete: "off", selected: @conn.params["del"] diff --git a/lib/philomena_web/views/search_view.ex b/lib/philomena_web/views/search_view.ex index e60028d1..fe66fbe1 100644 --- a/lib/philomena_web/views/search_view.ex +++ b/lib/philomena_web/views/search_view.ex @@ -2,4 +2,5 @@ defmodule PhilomenaWeb.SearchView do use PhilomenaWeb, :view def scope(conn), do: Philomena.ImageScope.scope(conn) + def hides_images?(conn), do: can?(conn, :hide, %Philomena.Images.Image{}) end