diff --git a/.iex.exs b/.iex.exs index 826000ae..2bbf4dd0 100644 --- a/.iex.exs +++ b/.iex.exs @@ -1,2 +1,2 @@ -alias Philomena.{Repo, Users.User} +alias Philomena.{Repo, Comments.Comment, Posts.Post, Images.Image, Tags.Tag, Users.User} import Ecto.Query \ No newline at end of file diff --git a/lib/philomena/tags/tag.ex b/lib/philomena/tags/tag.ex index 90e40c67..6e764a56 100644 --- a/lib/philomena/tags/tag.ex +++ b/lib/philomena/tags/tag.ex @@ -35,20 +35,4 @@ defmodule Philomena.Tags.Tag do |> cast(attrs, []) |> validate_required([]) end - - def display_order do - Philomena.Tags.Tag - |> order_by( - [t], - asc: t.category == "spoiler", - asc: t.category == "content-official", - asc: t.category == "content-fanmade", - asc: t.category == "species", - asc: t.category == "oc", - asc: t.category == "character", - asc: t.category == "origin", - asc: t.category == "rating", - asc: t.name - ) - end end diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 02302363..f80ca5ac 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -5,7 +5,7 @@ defmodule PhilomenaWeb.ImageController do alias Philomena.Repo import Ecto.Query - plug :load_and_authorize_resource, model: Image, only: :show, preload: [:user, tags: Tag.display_order()] + plug :load_and_authorize_resource, model: Image, only: :show, preload: [:user, :tags] def index(conn, _params) do query = conn.assigns.compiled_filter diff --git a/lib/philomena_web/templates/image/show.html.slime b/lib/philomena_web/templates/image/show.html.slime index 9a601522..084dcaae 100644 --- a/lib/philomena_web/templates/image/show.html.slime +++ b/lib/philomena_web/templates/image/show.html.slime @@ -10,7 +10,7 @@ == @description .js-tagsauce id="image_tags_and_source_#{@image.id}" .tagsauce - = render PhilomenaWeb.TagView, "_tag_list.html", tags: @image.tags + = render PhilomenaWeb.TagView, "_tag_list.html", tags: display_order(@image.tags) .block .flex.flex--wrap#image-source = if !!@image.source_url and @image.source_url != "" do diff --git a/lib/philomena_web/views/image_view.ex b/lib/philomena_web/views/image_view.ex index cd0598c0..7e444601 100644 --- a/lib/philomena_web/views/image_view.ex +++ b/lib/philomena_web/views/image_view.ex @@ -64,4 +64,19 @@ defmodule PhilomenaWeb.ImageView do content_tag(:div, block.(), class: "image-container #{size}", data: data) end + + def display_order(tags) do + tags + |> Enum.sort_by(&{ + &1.category != "spoiler", + &1.category != "content-official", + &1.category != "content-fanmade", + &1.category != "species", + &1.category != "oc", + &1.category != "character", + &1.category != "origin", + &1.category != "rating", + &1.name + }) + end end