mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
ok ecto
This commit is contained in:
parent
5c209146a7
commit
657c038854
5 changed files with 18 additions and 19 deletions
2
.iex.exs
2
.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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue