mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +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
|
end
|
||||||
|
|
||||||
def feature_image(featurer, %Image{} = image) do
|
def feature_image(featurer, %Image{} = image) do
|
||||||
image = Repo.preload(image, :tags)
|
%ImageFeature{user_id: featurer.id, image_id: image.id}
|
||||||
[featured] = Tags.get_or_create_tags("featured image")
|
|> ImageFeature.changeset(%{})
|
||||||
|
|> Repo.insert()
|
||||||
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()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_image(%Image{} = image) do
|
def destroy_image(%Image{} = image) do
|
||||||
|
|
|
@ -3,15 +3,16 @@ defmodule PhilomenaWeb.Image.FeatureController do
|
||||||
|
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
alias Philomena.Images
|
alias Philomena.Images
|
||||||
alias Philomena.Tags
|
|
||||||
|
|
||||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide
|
plug PhilomenaWeb.CanaryMapPlug, create: :hide
|
||||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||||
plug :verify_not_deleted
|
plug :verify_not_deleted
|
||||||
|
|
||||||
def create(conn, _params) do
|
def create(conn, _params) do
|
||||||
{:ok, %{image: image}} = Images.feature_image(conn.assigns.current_user, conn.assigns.image)
|
user = conn.assigns.current_user
|
||||||
Tags.reindex_tags(image.added_tags)
|
image = conn.assigns.image
|
||||||
|
|
||||||
|
{:ok, _feature} = Images.feature_image(user, image)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Image marked as featured image.")
|
|> put_flash(:info, "Image marked as featured image.")
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
= if not @image.hidden_from_users do
|
= if not @image.hidden_from_users do
|
||||||
= form_for @changeset, Routes.image_feature_path(@conn, :create, @image), [method: "post"], fn _f ->
|
= form_for @changeset, Routes.image_feature_path(@conn, :create, @image), [method: "post"], fn _f ->
|
||||||
.field
|
.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"
|
= submit "Feature", data: [confirm: "Are you really, really sure?"], class: "button button--state-success"
|
||||||
- else
|
- else
|
||||||
= button_to "Restore", Routes.image_delete_path(@conn, :delete, @image), method: "delete", class: "button button--state-success"
|
= button_to "Restore", Routes.image_delete_path(@conn, :delete, @image), method: "delete", class: "button button--state-success"
|
||||||
|
|
Loading…
Reference in a new issue