#77: order the gallery list in a more sensible way

This commit is contained in:
byte[] 2020-05-01 14:09:57 -04:00
parent 3e7ee76fe2
commit 4be21fc592
4 changed files with 34 additions and 39 deletions

View file

@ -10,7 +10,6 @@ defmodule PhilomenaWeb.ImageController do
Images.Image,
Comments.Comment,
Galleries.Gallery,
Galleries.Interaction,
Textile.Renderer
}
@ -77,14 +76,13 @@ defmodule PhilomenaWeb.ImageController do
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 = [
image: image,
comments: comments,
image_changeset: image_changeset,
comment_changeset: comment_changeset,
image_galleries: image_galleries,
user_galleries: user_galleries,
description: description,
interactions: interactions,
@ -132,28 +130,23 @@ defmodule PhilomenaWeb.ImageController do
end
end
defp image_and_user_galleries(_image, nil), do: {[], []}
defp user_galleries(_image, nil), do: []
defp image_and_user_galleries(image, user) do
image_galleries =
defp user_galleries(image, user) do
Gallery
|> where(creator_id: ^user.id)
|> join(:inner, [g], gi in Interaction,
on: g.id == gi.gallery_id and gi.image_id == ^image.id
|> join(
: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()
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
defp load_image(conn, _opts) do

View file

@ -12,21 +12,23 @@
i.fa.fa-table>
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
= for gallery <- @user_galleries do
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
= for gallery <- @image_galleries do
= for {gallery, present} <- @user_galleries do
= if present do
/ Options to remove
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)
= 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)
= 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
= if @conn.assigns.current_user do

View file

@ -33,7 +33,7 @@
i.fa.fa-eye-slash
.stretched-mobile-links
= 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"
i.fa.fa-sitemap>
span.hide-limited-desktop.hide-mobile Related

View file

@ -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
.layout--narrow