From a3b3a38fef199fcd491494b7b4c5595f09200317 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 21 Dec 2019 17:15:16 -0500 Subject: [PATCH] galleries fixes --- lib/philomena/galleries.ex | 15 +++++++++++++++ .../controllers/gallery_controller.ex | 4 ++-- .../templates/gallery/show.html.slime | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/philomena/galleries.ex b/lib/philomena/galleries.ex index f2b0d075..ade3cdc3 100644 --- a/lib/philomena/galleries.ex +++ b/lib/philomena/galleries.ex @@ -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 """ diff --git a/lib/philomena_web/controllers/gallery_controller.ex b/lib/philomena_web/controllers/gallery_controller.ex index 92bb6844..aa0f0a91 100644 --- a/lib/philomena_web/controllers/gallery_controller.ex +++ b/lib/philomena_web/controllers/gallery_controller.ex @@ -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) diff --git a/lib/philomena_web/templates/gallery/show.html.slime b/lib/philomena_web/templates/gallery/show.html.slime index b6a1d393..a5825df5 100644 --- a/lib/philomena_web/templates/gallery/show.html.slime +++ b/lib/philomena_web/templates/gallery/show.html.slime @@ -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