mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
#77: order the gallery list in a more sensible way
This commit is contained in:
parent
3e7ee76fe2
commit
4be21fc592
4 changed files with 34 additions and 39 deletions
|
@ -10,7 +10,6 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
Images.Image,
|
Images.Image,
|
||||||
Comments.Comment,
|
Comments.Comment,
|
||||||
Galleries.Gallery,
|
Galleries.Gallery,
|
||||||
Galleries.Interaction,
|
|
||||||
Textile.Renderer
|
Textile.Renderer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +76,13 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
|
|
||||||
watching = Images.subscribed?(image, conn.assigns.current_user)
|
watching = Images.subscribed?(image, conn.assigns.current_user)
|
||||||
|
|
||||||
{user_galleries, image_galleries} = image_and_user_galleries(image, conn.assigns.current_user)
|
user_galleries = user_galleries(image, conn.assigns.current_user)
|
||||||
|
|
||||||
assigns = [
|
assigns = [
|
||||||
image: image,
|
image: image,
|
||||||
comments: comments,
|
comments: comments,
|
||||||
image_changeset: image_changeset,
|
image_changeset: image_changeset,
|
||||||
comment_changeset: comment_changeset,
|
comment_changeset: comment_changeset,
|
||||||
image_galleries: image_galleries,
|
|
||||||
user_galleries: user_galleries,
|
user_galleries: user_galleries,
|
||||||
description: description,
|
description: description,
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
|
@ -132,28 +130,23 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp image_and_user_galleries(_image, nil), do: {[], []}
|
defp user_galleries(_image, nil), do: []
|
||||||
|
|
||||||
defp image_and_user_galleries(image, user) do
|
defp user_galleries(image, user) do
|
||||||
image_galleries =
|
|
||||||
Gallery
|
Gallery
|
||||||
|> where(creator_id: ^user.id)
|
|> where(creator_id: ^user.id)
|
||||||
|> join(:inner, [g], gi in Interaction,
|
|> join(
|
||||||
on: g.id == gi.gallery_id and gi.image_id == ^image.id
|
:inner_lateral,
|
||||||
|
[g],
|
||||||
|
_ in fragment(
|
||||||
|
"SELECT EXISTS(SELECT 1 FROM gallery_interactions gi WHERE gi.image_id = ? AND gi.gallery_id = ?)",
|
||||||
|
^image.id,
|
||||||
|
g.id
|
||||||
)
|
)
|
||||||
|> order_by(desc: :created_at)
|
)
|
||||||
|
|> select([g, e], {g, e.exists})
|
||||||
|
|> order_by(desc: :updated_at)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
image_gallery_ids = Enum.map(image_galleries, & &1.id)
|
|
||||||
|
|
||||||
user_galleries =
|
|
||||||
Gallery
|
|
||||||
|> where(creator_id: ^user.id)
|
|
||||||
|> where([g], g.id not in ^image_gallery_ids)
|
|
||||||
|> order_by(desc: :created_at)
|
|
||||||
|> Repo.all()
|
|
||||||
|
|
||||||
{user_galleries, image_galleries}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp load_image(conn, _opts) do
|
defp load_image(conn, _opts) do
|
||||||
|
|
|
@ -12,21 +12,23 @@
|
||||||
i.fa.fa-table>
|
i.fa.fa-table>
|
||||||
span.hide-mobile Featured in
|
span.hide-mobile Featured in
|
||||||
|
|
||||||
= if Enum.any?(@image_galleries) or Enum.any?(@user_galleries) do
|
= if Enum.any?(@user_galleries) do
|
||||||
ul.block__list.js-gallery-list
|
ul.block__list.js-gallery-list
|
||||||
= for gallery <- @user_galleries do
|
= for {gallery, present} <- @user_galleries do
|
||||||
li id="gallery_#{gallery.id}"
|
= if present do
|
||||||
a.block__list__link.js-gallery-add data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-add" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-remove" data-method="post" data-remote="true" href=Routes.gallery_image_path(@conn, :create, gallery, image_id: @image.id)
|
/ Options to remove
|
||||||
= gallery.title
|
|
||||||
a.block__list__link.active.js-gallery-remove.hidden data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-remove" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-add" data-method="delete" data-remote="true" href=Routes.gallery_image_path(@conn, :delete, gallery, image_id: @image.id)
|
|
||||||
= gallery.title
|
|
||||||
|
|
||||||
= for gallery <- @image_galleries do
|
|
||||||
li id="gallery_#{gallery.id}"
|
li id="gallery_#{gallery.id}"
|
||||||
a.block__list__link.js-gallery-add.hidden data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-add" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-remove" data-method="post" data-remote="true" href=Routes.gallery_image_path(@conn, :create, gallery, image_id: @image.id)
|
a.block__list__link.js-gallery-add.hidden data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-add" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-remove" data-method="post" data-remote="true" href=Routes.gallery_image_path(@conn, :create, gallery, image_id: @image.id)
|
||||||
= gallery.title
|
= gallery.title
|
||||||
a.block__list__link.active.js-gallery-remove data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-remove" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-add" data-method="delete" data-remote="true" href=Routes.gallery_image_path(@conn, :delete, gallery, image_id: @image.id)
|
a.block__list__link.active.js-gallery-remove data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-remove" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-add" data-method="delete" data-remote="true" href=Routes.gallery_image_path(@conn, :delete, gallery, image_id: @image.id)
|
||||||
= gallery.title
|
= gallery.title
|
||||||
|
- else
|
||||||
|
/ Options to add
|
||||||
|
li id="gallery_#{gallery.id}"
|
||||||
|
a.block__list__link.js-gallery-add data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-add" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-remove" data-method="post" data-remote="true" href=Routes.gallery_image_path(@conn, :create, gallery, image_id: @image.id)
|
||||||
|
= gallery.title
|
||||||
|
a.block__list__link.active.js-gallery-remove.hidden data-fetchcomplete-hide="#gallery_#{gallery.id} .js-gallery-remove" data-fetchcomplete-show="#gallery_#{gallery.id} .js-gallery-add" data-method="delete" data-remote="true" href=Routes.gallery_image_path(@conn, :delete, gallery, image_id: @image.id)
|
||||||
|
= gallery.title
|
||||||
|
|
||||||
.block__list
|
.block__list
|
||||||
= if @conn.assigns.current_user do
|
= if @conn.assigns.current_user do
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
i.fa.fa-eye-slash
|
i.fa.fa-eye-slash
|
||||||
.stretched-mobile-links
|
.stretched-mobile-links
|
||||||
= render PhilomenaWeb.Image.SubscriptionView, "_subscription.html", watching: @watching, image: @image, conn: @conn
|
= render PhilomenaWeb.Image.SubscriptionView, "_subscription.html", watching: @watching, image: @image, conn: @conn
|
||||||
= render PhilomenaWeb.ImageView, "_add_to_gallery_dropdown.html", image: @image, image_galleries: @image_galleries, user_galleries: @user_galleries, conn: @conn
|
= render PhilomenaWeb.ImageView, "_add_to_gallery_dropdown.html", image: @image, user_galleries: @user_galleries, conn: @conn
|
||||||
a href=Routes.image_related_path(@conn, :index, @image) title="Related Images"
|
a href=Routes.image_related_path(@conn, :index, @image) title="Related Images"
|
||||||
i.fa.fa-sitemap>
|
i.fa.fa-sitemap>
|
||||||
span.hide-limited-desktop.hide-mobile Related
|
span.hide-limited-desktop.hide-mobile Related
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= render PhilomenaWeb.ImageView, "_image_meta.html", image: @image, watching: @watching, image_galleries: @image_galleries, user_galleries: @user_galleries, changeset: @image_changeset, conn: @conn
|
= render PhilomenaWeb.ImageView, "_image_meta.html", image: @image, watching: @watching, user_galleries: @user_galleries, changeset: @image_changeset, conn: @conn
|
||||||
= render PhilomenaWeb.ImageView, "_image_page.html", image: @image, conn: @conn
|
= render PhilomenaWeb.ImageView, "_image_page.html", image: @image, conn: @conn
|
||||||
|
|
||||||
.layout--narrow
|
.layout--narrow
|
||||||
|
|
Loading…
Reference in a new issue