sort tags on image page

This commit is contained in:
byte[] 2019-11-11 18:19:00 -05:00
parent 2cfd5d2f19
commit 5c209146a7
2 changed files with 18 additions and 2 deletions

View file

@ -35,4 +35,20 @@ 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

View file

@ -1,11 +1,11 @@
defmodule PhilomenaWeb.ImageController do
use PhilomenaWeb, :controller
alias Philomena.{Images.Image, Comments.Comment, Textile.Renderer}
alias Philomena.{Images.Image, Comments.Comment, Tags.Tag, Textile.Renderer}
alias Philomena.Repo
import Ecto.Query
plug :load_and_authorize_resource, model: Image, only: :show, preload: [:tags, :user]
plug :load_and_authorize_resource, model: Image, only: :show, preload: [:user, tags: Tag.display_order()]
def index(conn, _params) do
query = conn.assigns.compiled_filter