merging sources, fix ui bugs, more icons

This commit is contained in:
Luna D 2023-05-28 18:12:53 +02:00
parent 516b35f2fd
commit b70c0a11f6
No known key found for this signature in database
GPG key ID: 4B1C63448394F688
5 changed files with 110 additions and 28 deletions

View file

@ -1,5 +1,7 @@
// DOM Utils // DOM Utils
type PhilomenaInputElements = HTMLTextAreaElement | HTMLInputElement | HTMLButtonElement;
/** /**
* Get the first matching element * Get the first matching element
*/ */
@ -34,13 +36,13 @@ export function clearEl<E extends HTMLElement>(...elements: E[] | ConcatArray<E>
}); });
} }
export function disableEl<E extends HTMLInputElement>(...elements: E[] | ConcatArray<E>[]) { export function disableEl<E extends PhilomenaInputElements>(...elements: E[] | ConcatArray<E>[]) {
([] as E[]).concat(...elements).forEach(el => { ([] as E[]).concat(...elements).forEach(el => {
el.disabled = true; el.disabled = true;
}); });
} }
export function enableEl<E extends HTMLInputElement>(...elements: E[] | ConcatArray<E>[]) { export function enableEl<E extends PhilomenaInputElements>(...elements: E[] | ConcatArray<E>[]) {
([] as E[]).concat(...elements).forEach(el => { ([] as E[]).concat(...elements).forEach(el => {
el.disabled = false; el.disabled = false;
}); });

View file

@ -548,6 +548,13 @@ defmodule Philomena.Images do
|> Multi.run(:copy_tags, fn _, %{} -> |> Multi.run(:copy_tags, fn _, %{} ->
{:ok, Tags.copy_tags(image, duplicate_of_image)} {:ok, Tags.copy_tags(image, duplicate_of_image)}
end) end)
|> Multi.run(:migrate_sources, fn repo, %{} ->
{:ok,
migrate_sources(
repo.preload(image, [:sources]),
repo.preload(duplicate_of_image, [:sources])
)}
end)
|> Multi.run(:migrate_comments, fn _, %{} -> |> Multi.run(:migrate_comments, fn _, %{} ->
{:ok, Comments.migrate_comments(image, duplicate_of_image)} {:ok, Comments.migrate_comments(image, duplicate_of_image)}
end) end)
@ -920,6 +927,17 @@ defmodule Philomena.Images do
{:ok, count} {:ok, count}
end end
def migrate_sources(source, target) do
sources =
(source.sources ++ target.sources)
|> Enum.uniq()
|> Enum.take(10)
target
|> Image.sources_changeset(sources)
|> Repo.update()
end
def notify_merge(source, target) do def notify_merge(source, target) do
Exq.enqueue(Exq, "notifications", NotificationWorker, ["Images", [source.id, target.id]]) Exq.enqueue(Exq, "notifications", NotificationWorker, ["Images", [source.id, target.id]])
end end

View file

@ -214,6 +214,11 @@ defmodule Philomena.Images.Image do
|> SourceDiffer.diff_input(old_sources, new_sources) |> SourceDiffer.diff_input(old_sources, new_sources)
end end
def sources_changeset(image, new_sources) do
change(image)
|> put_assoc(:sources, new_sources)
end
def tag_changeset(image, attrs, old_tags, new_tags, excluded_tags \\ []) do def tag_changeset(image, attrs, old_tags, new_tags, excluded_tags \\ []) do
image image
|> cast(attrs, []) |> cast(attrs, [])

View file

@ -38,8 +38,8 @@
p p
' You can't edit the source on this image. ' You can't edit the source on this image.
.flex.flex--wrap.flex--centered#image-source .flex.flex--wrap.flex--column#image-source
p .flex
a.button.button--separate-right#edit-source data-click-focus=".js-image-source" data-click-hide="#image-source" data-click-show="#source-form" title="Edit source" accessKey="s" a.button.button--separate-right#edit-source data-click-focus=".js-image-source" data-click-hide="#image-source" data-click-show="#source-form" title="Edit source" accessKey="s"
i.fas.fa-edit> i.fas.fa-edit>
= if !has_sources || length(@image.sources) == 1 do = if !has_sources || length(@image.sources) == 1 do
@ -58,22 +58,22 @@
button.button.button--state-danger.button--separate-left type="submit" data-confirm="Are you really, really sure?" title="Wipe sources" button.button.button--state-danger.button--separate-left type="submit" data-confirm="Are you really, really sure?" title="Wipe sources"
i.fas.fa-eraser> i.fas.fa-eraser>
' Wipe ' Wipe
.image_sources .image_sources
= if has_sources do = if has_sources do
- [first_source | sources] = @image.sources - [first_source | sources] = @image.sources
.image_source__icon
i class=image_source_icon(first_source.source)
.image_source__link
a.js-source-link href=first_source.source
strong = first_source.source
= for source <- sources do
.image_source__icon .image_source__icon
i class=image_source_icon(source.source) i class=image_source_icon(first_source.source)
.image_source__link .image_source__link
a href=source.source a.js-source-link href=first_source.source
strong = source.source strong = first_source.source
- else = for source <- sources do
.image_source__icon .image_source__icon
i.fa.fa-unlink i class=image_source_icon(source.source)
.image_source__link .image_source__link
em> not provided yet a href=source.source
strong = source.source
- else
.image_source__icon
i.fa.fa-unlink
.image_source__link
em> not provided yet

View file

@ -308,18 +308,75 @@ defmodule PhilomenaWeb.ImageView do
u when u in ["cdn.discordapp.com", "discordapp.com", "discord.com"] -> u when u in ["cdn.discordapp.com", "discordapp.com", "discord.com"] ->
"fab fa-discord" "fab fa-discord"
u when u in ["youtube.com", "www.youtube.com"] ->
"fab fa-youtube"
u when u in ["pillowfort.social", "www.pillowfort.social"] ->
"fa fa-bed"
u when u in ["vk.com", "vk.ru"] ->
"fab fa-vk"
u when u in ["pixiv.net", "www.pixiv.net", "artfight.net", "www.artfight.net"] ->
"fa fa-paintbrush"
u when u in ["patreon.com", "www.patreon.com"] ->
"fab fa-patreon"
u when u in ["ych.art", "ych.commishes.com", "commishes.com"] ->
"fa fa-palette"
u when u in ["artstation.com", "www.artstation.com"] ->
"fab fa-artstation"
u when u in ["instagram.com", "www.instagram.com"] ->
"fab fa-instagram"
u when u in ["reddit.com", "www.reddit.com"] ->
"fab fa-reddit"
u when u in ["facebook.com", "www.facebook.com", "fb.me", "www.fb.me"] ->
"fab fa-facebook"
u when u in ["tiktok.com", "www.tiktok.com"] ->
"fab fa-tiktok"
u u
when u in [ when u in [
"derpibooru.org", "furaffinity.net",
"www.derpibooru.org", "www.furaffinity.net",
"trixiebooru.org", "furbooru.org",
"www.trixiebooru.org", "inkbunny.net",
"derpicdn.net" "e621.net",
"e926.net"
] -> ] ->
"fab fa-phoenix-framework" "fa fa-paw"
u
when u in [
"awoo.space",
"bark.lgbt",
"equestria.social",
"foxy.social",
"mastodon.art",
"mastodon.social",
"meow.social",
"pawoo.net",
"pettingzoo.co",
"pony.social",
"vulpine.club",
"yiff.life"
] ->
"fab fa-mastodon"
link -> link ->
if Enum.member?(site_domains, link), do: "favicon-home", else: "fa fa-link" cond do
Enum.member?(site_domains, link) -> "favicon-home"
String.contains?(link, "tumblr") -> "fab fa-tumblr"
String.contains?(link, "deviantart") -> "fab fa-deviantart"
String.contains?(link, "sofurry") -> "fa fa-paw"
true -> "fa fa-link"
end
end end
end end
end end