mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
don't automatically tag 'featured image' (furbooru/philomena#33)
This commit is contained in:
parent
504b1d5b82
commit
7736cb041f
3 changed files with 8 additions and 28 deletions
|
@ -110,30 +110,9 @@ defmodule Philomena.Images do
|
|||
end
|
||||
|
||||
def feature_image(featurer, %Image{} = image) do
|
||||
image = Repo.preload(image, :tags)
|
||||
[featured] = Tags.get_or_create_tags("featured image")
|
||||
|
||||
feature =
|
||||
%ImageFeature{user_id: featurer.id, image_id: image.id}
|
||||
|> ImageFeature.changeset(%{})
|
||||
|
||||
image =
|
||||
image
|
||||
|> Image.tag_changeset(%{}, image.tags, [featured | image.tags])
|
||||
|> Image.cache_changeset()
|
||||
|
||||
Multi.new()
|
||||
|> Multi.insert(:feature, feature)
|
||||
|> Multi.update(:image, image)
|
||||
|> Multi.run(:added_tag_count, fn repo, %{image: image} ->
|
||||
tag_ids = image.added_tags |> Enum.map(& &1.id)
|
||||
tags = Tag |> where([t], t.id in ^tag_ids)
|
||||
|
||||
{count, nil} = repo.update_all(tags, inc: [images_count: 1])
|
||||
|
||||
{:ok, count}
|
||||
end)
|
||||
|> Repo.transaction()
|
||||
%ImageFeature{user_id: featurer.id, image_id: image.id}
|
||||
|> ImageFeature.changeset(%{})
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
def destroy_image(%Image{} = image) do
|
||||
|
|
|
@ -3,15 +3,16 @@ defmodule PhilomenaWeb.Image.FeatureController do
|
|||
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.Images
|
||||
alias Philomena.Tags
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide
|
||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||
plug :verify_not_deleted
|
||||
|
||||
def create(conn, _params) do
|
||||
{:ok, %{image: image}} = Images.feature_image(conn.assigns.current_user, conn.assigns.image)
|
||||
Tags.reindex_tags(image.added_tags)
|
||||
user = conn.assigns.current_user
|
||||
image = conn.assigns.image
|
||||
|
||||
{:ok, _feature} = Images.feature_image(user, image)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Image marked as featured image.")
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
= if not @image.hidden_from_users do
|
||||
= form_for @changeset, Routes.image_feature_path(@conn, :create, @image), [method: "post"], fn _f ->
|
||||
.field
|
||||
p Automatically tags 'featured image'
|
||||
p Marks the image as featured
|
||||
= submit "Feature", data: [confirm: "Are you really, really sure?"], class: "button button--state-success"
|
||||
- else
|
||||
= button_to "Restore", Routes.image_delete_path(@conn, :delete, @image), method: "delete", class: "button button--state-success"
|
||||
|
|
Loading…
Reference in a new issue