From e313460917a524a2a9cf9dfaecd622c4733c2923 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 11 Nov 2019 12:57:02 -0500 Subject: [PATCH] fix 'go to post' links --- lib/philomena_web/controllers/topic_controller.ex | 12 +++++++++++- lib/philomena_web/templates/forum/index.html.slime | 2 +- lib/philomena_web/templates/forum/show.html.slime | 2 +- .../templates/post/_post_options.html.slime | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/philomena_web/controllers/topic_controller.ex b/lib/philomena_web/controllers/topic_controller.ex index b89dda7a..3a23fef4 100644 --- a/lib/philomena_web/controllers/topic_controller.ex +++ b/lib/philomena_web/controllers/topic_controller.ex @@ -7,7 +7,7 @@ defmodule PhilomenaWeb.TopicController do plug :load_and_authorize_resource, model: Forum, id_name: "forum_id", id_field: "short_name", persisted: true - def show(conn, %{"id" => slug}) do + def show(conn, %{"id" => slug} = params) do forum = conn.assigns.forum topic = Topic @@ -18,6 +18,16 @@ defmodule PhilomenaWeb.TopicController do conn = conn |> assign(:topic, topic) %{page_number: page} = conn.assigns.pagination + page = + with {post_id, _extra} <- Integer.parse(params["post_id"] || ""), + [post] <- Post |> where(id: ^post_id) |> Repo.all() + do + div(post.topic_position, 25) + 1 + else + _ -> + page + end + posts = Post |> where(topic_id: ^conn.assigns.topic.id) diff --git a/lib/philomena_web/templates/forum/index.html.slime b/lib/philomena_web/templates/forum/index.html.slime index fbc47f51..00e1dba7 100644 --- a/lib/philomena_web/templates/forum/index.html.slime +++ b/lib/philomena_web/templates/forum/index.html.slime @@ -26,7 +26,7 @@ h1 Discussion Forums strong => link(forum.last_post.topic.title, to: Routes.forum_topic_path(@conn, :show, forum, forum.last_post.topic)) br - => link("Go to post", to: Routes.forum_topic_path(@conn, :show, forum, forum.last_post.topic, post_id: forum.last_post.id)) + => link("Go to post", to: Routes.forum_topic_path(@conn, :show, forum, forum.last_post.topic, post_id: forum.last_post.id) <> "#post_#{forum.last_post.id}") ' by => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: forum.last_post br diff --git a/lib/philomena_web/templates/forum/show.html.slime b/lib/philomena_web/templates/forum/show.html.slime index 84e7a7c4..391eb759 100644 --- a/lib/philomena_web/templates/forum/show.html.slime +++ b/lib/philomena_web/templates/forum/show.html.slime @@ -46,7 +46,7 @@ h1 = @forum.name td.table--communication-list__stats.hide-mobile = topic.post_count td.table--communication-list__last-post = if topic.last_post do - => link("Go to post", to: Routes.forum_topic_path(@conn, :show, @forum, topic, post_id: topic.last_post) <> "post_#{topic.last_post.id}") + => link("Go to post", to: Routes.forum_topic_path(@conn, :show, @forum, topic, post_id: topic.last_post) <> "#post_#{topic.last_post.id}") ' by = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: topic.last_post br diff --git a/lib/philomena_web/templates/post/_post_options.html.slime b/lib/philomena_web/templates/post/_post_options.html.slime index ff6befba..0eafa4b9 100644 --- a/lib/philomena_web/templates/post/_post_options.html.slime +++ b/lib/philomena_web/templates/post/_post_options.html.slime @@ -13,7 +13,7 @@ div / | because: / =<> post.edit_reason div - - link_path = Routes.forum_topic_path(@conn, :show, @post.topic.forum, @post.topic, post_id: @post.id) <> "post_#{@post.id}" + - link_path = Routes.forum_topic_path(@conn, :show, @post.topic.forum, @post.topic, post_id: @post.id) <> "#post_#{@post.id}" a.communication__interaction title="Link to post" href=link_path i.fa.fa-link> ' Link