From 6496fd30fae1660beb5e1e0b6bcfcd39ab24ade3 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 2 Nov 2019 09:28:54 -0400 Subject: [PATCH] fix validations --- assets/css/common/forms.scss | 5 +++++ lib/philomena/filters/filter.ex | 18 +++++++----------- lib/philomena/search/parser.ex | 10 +++++----- .../templates/filter/_form.html.slime | 9 +++++++++ .../templates/filter/show.html.slime | 4 ---- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/assets/css/common/forms.scss b/assets/css/common/forms.scss index 9ffd3661..f8fe30cd 100644 --- a/assets/css/common/forms.scss +++ b/assets/css/common/forms.scss @@ -86,6 +86,11 @@ textarea { background: $danger_color; } +span.help-block { + background: $danger_color; + display: block; +} + /* hform is used for 30em inline 2-element textinput/button forms */ .hform .field { display: flex; diff --git a/lib/philomena/filters/filter.ex b/lib/philomena/filters/filter.ex index 4025262b..ab5118ff 100644 --- a/lib/philomena/filters/filter.ex +++ b/lib/philomena/filters/filter.ex @@ -105,19 +105,15 @@ defmodule Philomena.Filters.Filter do defp validate_search(changeset, field) do user_id = get_field(changeset, :user_id) + user = if user_id, do: User |> Repo.get!(user_id) - if user_id do - user = User |> Repo.get!(user_id) - output = Query.user_parser(user, get_field(changeset, field)) + output = Query.compile(user, get_field(changeset, field)) - case output do - {:ok, _} -> changeset - _ -> - changeset - |> add_error(field, "is invalid") - end - else - changeset + case output do + {:ok, _} -> changeset + _ -> + changeset + |> add_error(field, "is invalid") end end diff --git a/lib/philomena/search/parser.ex b/lib/philomena/search/parser.ex index 13489420..70b8a931 100644 --- a/lib/philomena/search/parser.ex +++ b/lib/philomena/search/parser.ex @@ -23,12 +23,12 @@ defmodule Philomena.Search.Parser do {tree, []} = unquote(:"#{name}_top")(ctx, tokens) {:ok, tree} - # rescue - # e in ArgumentError -> - # {:error, e.message} + rescue + e in ArgumentError -> + {:error, e.message} - # _ -> - # {:error, "Parsing error."} + _ -> + {:error, "Parsing error."} end # diff --git a/lib/philomena_web/templates/filter/_form.html.slime b/lib/philomena_web/templates/filter/_form.html.slime index b8e64ff3..9f9b4585 100644 --- a/lib/philomena_web/templates/filter/_form.html.slime +++ b/lib/philomena_web/templates/filter/_form.html.slime @@ -1,7 +1,12 @@ .form = form_for @filter, @route, fn f -> + = if @filter.action do + #error_explanation + ' Oops, something went wrong! Please check the errors below. + .field = text_input f, :name, class: "input input--wide", placeholder: "Name" + = error_tag f, :name .fieldlabel ' This is a friendly name for this filter - it should be short and descriptive. .field @@ -20,6 +25,8 @@ = label f, :spoilered_complex_str, "Complex Spoiler Filter" br = textarea f, :spoilered_complex_str, class: "input input--wide", autocapitalize: "none" + br + = error_tag f, :spoilered_complex_str .fieldlabel p ' Use the search syntax here to specify an additional filter. @@ -42,6 +49,8 @@ = label f, :hidden_complex_str, "Complex Hide Filter" br = textarea f, :hidden_complex_str, class: "input input--wide", autocapitalize: "none" + br + = error_tag f, :hidden_complex_str .fieldlabel p ' Use the search syntax here to specify an additional filter. diff --git a/lib/philomena_web/templates/filter/show.html.slime b/lib/philomena_web/templates/filter/show.html.slime index 40daf982..278ced72 100644 --- a/lib/philomena_web/templates/filter/show.html.slime +++ b/lib/philomena_web/templates/filter/show.html.slime @@ -41,8 +41,6 @@ h1 = for tag <- @spoilered_tags do = render PhilomenaWeb.TagView, "_tag.html", tag: tag - - p Complex filter: pre.spoiler-filter-code = @filter.spoilered_complex_str @@ -55,8 +53,6 @@ h1 = for tag <- @hidden_tags do = render PhilomenaWeb.TagView, "_tag.html", tag: tag - - p Complex filter: pre.spoiler-filter-code = @filter.hidden_complex_str