From 70bbe6df817a8eda96b4212b01d3f6d3fae4a7a6 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Fri, 29 Nov 2019 14:59:55 -0500 Subject: [PATCH] add detailed descriptions to tag pages --- config/config.exs | 1 + config/prod.secret.exs | 1 + lib/philomena/tags/tag.ex | 5 ++ .../controllers/tag_controller.ex | 19 ++++- .../templates/tag/_tag_info_row.html.slime | 81 +++++++++++++++++++ .../templates/tag/show.html.slime | 1 + lib/philomena_web/views/tag_view.ex | 8 ++ 7 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 lib/philomena_web/templates/tag/_tag_info_row.html.slime diff --git a/config/config.exs b/config/config.exs index cc3f4913..71946c3d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -17,6 +17,7 @@ config :philomena, avatar_url_root: "/avatars", advert_url_root: "/spns", badge_url_root: "/media", + tag_url_root: "/media", image_file_root: "priv/static/system/images", cdn_host: "", proxy_host: nil, diff --git a/config/prod.secret.exs b/config/prod.secret.exs index 2146cdaa..87dfe95f 100644 --- a/config/prod.secret.exs +++ b/config/prod.secret.exs @@ -25,6 +25,7 @@ config :philomena, image_url_root: System.get_env("IMAGE_URL_ROOT"), badge_url_root: System.get_env("BADGE_URL_ROOT"), mailer_address: System.get_env("MAILER_ADDRESS"), + tag_url_root: System.get_env("TAG_URL_ROOT"), proxy_host: System.get_env("PROXY_HOST"), camo_host: System.get_env("CAMO_HOST"), camo_key: System.get_env("CAMO_KEY"), diff --git a/lib/philomena/tags/tag.ex b/lib/philomena/tags/tag.ex index 0522792a..2f8062ae 100644 --- a/lib/philomena/tags/tag.ex +++ b/lib/philomena/tags/tag.ex @@ -7,6 +7,9 @@ defmodule Philomena.Tags.Tag do index_name: "tags", doc_type: "tag" + alias Philomena.DnpEntries.DnpEntry + alias Philomena.UserLinks.UserLink + alias Philomena.Users.User alias Philomena.Tags.Tag alias Philomena.Slug @@ -48,6 +51,8 @@ defmodule Philomena.Tags.Tag do has_many :aliases, Tag, foreign_key: :aliased_tag_id many_to_many :implied_tags, Tag, join_through: "tags_implied_tags", join_keys: [tag_id: :id, implied_tag_id: :id] many_to_many :implied_by_tags, Tag, join_through: "tags_implied_tags", join_keys: [implied_tag_id: :id, tag_id: :id] + has_many :public_links, UserLink, where: [public: true, aasm_state: "verified"] + has_many :dnp_entries, DnpEntry, where: [aasm_state: "listed"] field :slug, :string field :name, :string diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index 01b446dc..d97c2618 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -2,7 +2,9 @@ defmodule PhilomenaWeb.TagController do use PhilomenaWeb, :controller alias Philomena.{Images.Image, Tags, Tags.Tag} + alias Philomena.Textile.Renderer alias Philomena.Interactions + alias Philomena.Repo import Ecto.Query def index(conn, params) do @@ -28,7 +30,11 @@ defmodule PhilomenaWeb.TagController do end def show(conn, %{"id" => slug}) do - tag = Tags.get_tag!(slug) + tag = + Tag + |> where(slug: ^slug) + |> preload([:aliases, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user]) + |> Repo.one() query = conn.assigns.compiled_filter user = conn.assigns.current_user @@ -51,6 +57,15 @@ defmodule PhilomenaWeb.TagController do interactions = Interactions.user_interactions(images, user) - render(conn, "show.html", tag: tag, interactions: interactions, images: images, layout_class: "layout--wide") + body = + Renderer.render_one(%{body: tag.description || ""}) + + dnp_bodies = + Renderer.render_collection(Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""})) + + dnp_entries = + Enum.zip(dnp_bodies, tag.dnp_entries) + + render(conn, "show.html", tag: tag, body: body, dnp_entries: dnp_entries, interactions: interactions, images: images, layout_class: "layout--wide") end end diff --git a/lib/philomena_web/templates/tag/_tag_info_row.html.slime b/lib/philomena_web/templates/tag/_tag_info_row.html.slime new file mode 100644 index 00000000..7e4f905f --- /dev/null +++ b/lib/philomena_web/templates/tag/_tag_info_row.html.slime @@ -0,0 +1,81 @@ +.block__content.js-imagelist-info.flex + .flex__fixed.tag-info__image.thumb-tiny-container.spacing-right + = if @tag.image do + img src=tag_image(@tag) alt="spoiler image" + - else + | no spoiler image + + .flex__grow + = render PhilomenaWeb.TagView, "_tag.html", tag: @tag + + = if @tag.short_description not in [nil, ""] do + strong> Short description: + = @tag.short_description + br + + = if Enum.any?(@tag.aliases) do + strong> Aliases: + = Enum.map_join(@tag.aliases, ", ", & &1.name) + br + + = if Enum.any?(@tag.implied_tags) do + strong> Implies: + = Enum.map_join(@tag.implied_tags, ", ", & &1.name) + br + + br + = link "Toggle details", to: "#", data: [click_toggle: ".tag-info__more"] + + .tag-info__more + hr + + = if Enum.any?(@tag.public_links) do + strong> Associated links: + + = for link <- @tag.public_links do + a> href=link.uri = link.uri + + br + + = if Enum.any?(@tag.public_links) do + strong> Associated users: + - users = Enum.map(@tag.public_links, & &1.user) |> Enum.uniq() + + = for user <- users do + => link user.name, to: Routes.profile_path(@conn, :show, user) + + br + + = if Enum.any?(@tag.implied_by_tags) do + input.toggle-box id="implied_by" type="checkbox" checked="false" + label for="implied_by" + ' Implied by (warning: unfiltered) + + .toggle-box-container + .toggle-box-container__content + = for tag <- @tag.implied_by_tags do + => link tag.name, to: Routes.tag_path(@conn, :show, tag) + + br + + = if @tag.description not in [nil, ""] do + strong> Detailed description: + br + == @body + + = if Enum.any?(@dnp_entries) do + hr + strong.comment_deleted This artist is on the Do-Not-Post List with the following restrictions: + + = for {body, entry} <- @dnp_entries do + br + ' • + + strong + => entry.dnp_type + + ==> body + + | ( + = link "more info", to: "#" + | ) \ No newline at end of file diff --git a/lib/philomena_web/templates/tag/show.html.slime b/lib/philomena_web/templates/tag/show.html.slime index 099d655e..0a3f9503 100644 --- a/lib/philomena_web/templates/tag/show.html.slime +++ b/lib/philomena_web/templates/tag/show.html.slime @@ -1 +1,2 @@ += render PhilomenaWeb.TagView, "_tag_info_row.html", tag: @tag, body: @body, dnp_entries: @dnp_entries, conn: @conn = render PhilomenaWeb.ImageView, "index.html", conn: @conn, images: @images \ No newline at end of file diff --git a/lib/philomena_web/views/tag_view.ex b/lib/philomena_web/views/tag_view.ex index 0b86f769..077445d8 100644 --- a/lib/philomena_web/views/tag_view.ex +++ b/lib/philomena_web/views/tag_view.ex @@ -6,6 +6,10 @@ defmodule PhilomenaWeb.TagView do alias Philomena.Repo import Ecto.Query + def tag_image(%{image: image}) do + tag_url_root() <> "/" <> image + end + def quick_tags(conn) do case Application.get_env(:philomena, :quick_tags) do nil -> @@ -117,4 +121,8 @@ defmodule PhilomenaWeb.TagView do Tag |> preload(:implied_tags) ) end + + defp tag_url_root do + Application.get_env(:philomena, :tag_url_root) + end end