diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index 6d42e57c..da8fca99 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -11,8 +11,12 @@ defmodule PhilomenaWeb.CommentController do conn = Map.put(conn, :params, params) user = conn.assigns.current_user - {:ok, query} = Query.compile(user, cq) + user + |> Query.compile(cq) + |> render_index(conn, user) + end + defp render_index({:ok, query}, conn, user) do comments = Comment.search_records( %{ @@ -39,6 +43,9 @@ defmodule PhilomenaWeb.CommentController do render(conn, "index.html", title: "Comments", comments: comments) end + defp render_index({:error, msg}, conn, _user) do + render(conn, "index.html", title: "Comments", error: msg, comments: []) + end defp filters(%{role: role}) when role in ["moderator", "admin"], do: [] defp filters(_user), diff --git a/lib/philomena_web/controllers/post_controller.ex b/lib/philomena_web/controllers/post_controller.ex index b2e4c0c3..c8790996 100644 --- a/lib/philomena_web/controllers/post_controller.ex +++ b/lib/philomena_web/controllers/post_controller.ex @@ -11,8 +11,12 @@ defmodule PhilomenaWeb.PostController do conn = Map.put(conn, :params, params) user = conn.assigns.current_user - {:ok, query} = Query.compile(user, pq) + user + |> Query.compile(pq) + |> render_index(conn, user) + end + defp render_index({:ok, query}, conn, user) do posts = Post.search_records( %{ @@ -28,24 +32,24 @@ defmodule PhilomenaWeb.PostController do ) rendered = - posts.entries - |> Renderer.render_collection(conn) + Renderer.render_collection(posts.entries, conn) posts = %{posts | entries: Enum.zip(rendered, posts.entries)} render(conn, "index.html", title: "Posts", posts: posts) end + defp render_index({:error, msg}, conn, _user) do + render(conn, "index.html", title: "Posts", error: msg, posts: []) + end defp filters(%{role: role}) when role in ["moderator", "admin"], do: [] - defp filters(%{role: "assistant"}) do [ %{terms: %{access_level: ["normal", "assistant"]}}, %{term: %{deleted: false}} ] end - defp filters(_user) do [ %{term: %{access_level: "normal"}}, diff --git a/lib/philomena_web/templates/tag/index.html.slime b/lib/philomena_web/templates/tag/index.html.slime index 15d33a61..640f82f8 100644 --- a/lib/philomena_web/templates/tag/index.html.slime +++ b/lib/philomena_web/templates/tag/index.html.slime @@ -3,7 +3,7 @@ h1 Tags = form_for :tags, Routes.tag_path(@conn, :index), [method: "get", class: "hform", enforce_utf8: false], fn f -> .field = text_input f, :tq, name: :tq, value: @conn.params["tq"] || "*", class: "input hform__text", placeholder: "Search tags", autocapitalize: "none" - = submit "Search", class: "hform__button button", data: [disable_with: false] + = submit "Search", class: "hform__button button" .fieldlabel ' For more information, see the @@ -165,4 +165,4 @@ table.table td Literal td Matches the slug of this tag. td - code = link "slug:-fwslash-mlp-fwslash-", to: Routes.tag_path(@conn, :index, tq: "slug:-fwslash-mlp-fwslash-") \ No newline at end of file + code = link "slug:-fwslash-mlp-fwslash-", to: Routes.tag_path(@conn, :index, tq: "slug:-fwslash-mlp-fwslash-")