From 7be7ca830383fc629e60e393a60a35188c1d1674 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 2 Dec 2019 09:37:01 -0500 Subject: [PATCH] update query param in conn --- lib/philomena_web/controllers/comment_controller.ex | 3 +++ lib/philomena_web/controllers/post_controller.ex | 7 +++++-- lib/philomena_web/templates/comment/index.html.slime | 2 +- lib/philomena_web/templates/post/index.html.slime | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index 024478d5..b665fb3a 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -7,6 +7,9 @@ defmodule PhilomenaWeb.CommentController do def index(conn, params) do cq = params["cq"] || "created_at.gte:1 week ago" + params = Map.put(conn.params, "cq", cq) + conn = Map.put(conn, :params, params) + {:ok, query} = Query.compile(conn.assigns.current_user, cq) comments = diff --git a/lib/philomena_web/controllers/post_controller.ex b/lib/philomena_web/controllers/post_controller.ex index dfee7786..fccd2c6e 100644 --- a/lib/philomena_web/controllers/post_controller.ex +++ b/lib/philomena_web/controllers/post_controller.ex @@ -5,9 +5,12 @@ defmodule PhilomenaWeb.PostController do import Ecto.Query def index(conn, params) do - cq = params["pq"] || "created_at.gte:1 week ago" + pq = params["pq"] || "created_at.gte:1 week ago" - {:ok, query} = Query.compile(conn.assigns.current_user, cq) + params = Map.put(conn.params, "pq", pq) + conn = Map.put(conn, :params, params) + + {:ok, query} = Query.compile(conn.assigns.current_user, pq) posts = Post.search_records( diff --git a/lib/philomena_web/templates/comment/index.html.slime b/lib/philomena_web/templates/comment/index.html.slime index 111a4726..3a51e9f7 100644 --- a/lib/philomena_web/templates/comment/index.html.slime +++ b/lib/philomena_web/templates/comment/index.html.slime @@ -2,7 +2,7 @@ h1 Comments = form_for :comments, Routes.comment_path(@conn, :index), [method: "get", class: "hform", enforce_utf8: false], fn f -> .field - = text_input f, :cq, name: :cq, value: @conn.params["cq"] || "created_at.gte:1 week ago", class: "input hform__text", placeholder: "Search comments", autocapitalize: "none" + = text_input f, :cq, name: :cq, value: @conn.params["cq"], class: "input hform__text", placeholder: "Search comments", autocapitalize: "none" = submit "Search", class: "hform__button button", data: [disable_with: false] .fieldlabel diff --git a/lib/philomena_web/templates/post/index.html.slime b/lib/philomena_web/templates/post/index.html.slime index ff7d00c6..717f8418 100644 --- a/lib/philomena_web/templates/post/index.html.slime +++ b/lib/philomena_web/templates/post/index.html.slime @@ -2,7 +2,7 @@ h1 Posts = form_for :posts, Routes.post_path(@conn, :index), [method: "get", class: "hform", enforce_utf8: false], fn f -> .field - = text_input f, :pq, name: :pq, value: @conn.params["pq"] || "created_at.gte:1 week ago", class: "input hform__text", placeholder: "Search posts", autocapitalize: "none" + = text_input f, :pq, name: :pq, value: @conn.params["pq"], class: "input hform__text", placeholder: "Search posts", autocapitalize: "none" = submit "Search", class: "hform__button button", data: [disable_with: false] .fieldlabel