galleries fixes

This commit is contained in:
byte[] 2019-12-21 17:15:16 -05:00
parent 878b923a20
commit a3b3a38fef
3 changed files with 21 additions and 2 deletions

View file

@ -90,7 +90,22 @@ defmodule Philomena.Galleries do
"""
def delete_gallery(%Gallery{} = gallery) do
images =
Interaction
|> where(gallery_id: ^gallery.id)
|> select([i], i.image_id)
|> Repo.all()
Repo.delete(gallery)
|> case do
{:ok, gallery} ->
Images.reindex_images(images)
{:ok, gallery}
error ->
error
end
end
@doc """

View file

@ -34,8 +34,8 @@ defmodule PhilomenaWeb.GalleryController do
gallery = conn.assigns.gallery
user = conn.assigns.current_user
query = "gallery_id:#{gallery.id}"
params = Map.put(conn.params, "q", query)
sort = ImageSorter.parse_sort(%{"sf" => "gallery_id:#{gallery.id}", "sd" => position_order(gallery)})
params = Map.merge(conn.params, %{"q" => query, "sf" => "gallery_id:#{gallery.id}", "sd" => position_order(gallery)})
sort = ImageSorter.parse_sort(params)
{:ok, {images, _tags}} = ImageLoader.search_string(conn, query, queries: sort.queries, sorts: sort.sorts)
interactions = Interactions.user_interactions(images, user)

View file

@ -34,6 +34,10 @@ elixir:
i.fa.fa-check>
' Save
a href=Routes.gallery_path(@conn, :delete, @gallery) data-method="delete" data-confirm="Are you really, really sure?"
i.fa.fa-trash>
span.hide-mobile Delete
= if show_subscription_link?(@gallery.creator, @conn.assigns.current_user) do
= render PhilomenaWeb.Gallery.SubscriptionView, "_subscription.html", watching: @watching, gallery: @gallery, conn: @conn