From 6e5d81191d97dfa2fb88453ce2e5ae2849fad5fe Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Thu, 3 Oct 2019 21:03:33 -0400 Subject: [PATCH] add basic user attribution --- lib/philomena_web/controllers/image_controller.ex | 4 ++-- lib/philomena_web/controllers/tag_controller.ex | 2 +- lib/philomena_web/templates/image/_image_meta.html.slime | 6 ++++-- .../templates/user_attribution/_anon_user.html.slime | 5 +++++ .../templates/user_attribution/_user.html.slime | 2 ++ 5 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 lib/philomena_web/templates/user_attribution/_anon_user.html.slime diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 29606749..43143d4c 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -5,7 +5,7 @@ defmodule PhilomenaWeb.ImageController do import Ecto.Query plug ImageFilter - plug :load_and_authorize_resource, model: Image, only: :show, preload: :tags + plug :load_and_authorize_resource, model: Image, only: :show, preload: [:tags, :user] def index(conn, _params) do query = conn.assigns.compiled_filter @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.ImageController do query: %{bool: %{must_not: query}}, sort: %{created_at: :desc} }, - Image |> preload(:tags) + Image |> preload([:tags, :user]) ) render(conn, "index.html", images: images) diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index ece119fb..f5297db4 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -38,7 +38,7 @@ defmodule PhilomenaWeb.TagController do }, sort: %{created_at: :desc} }, - Image |> preload(:tags) + Image |> preload([:tags, :user]) ) render(conn, "show.html", tag: tag, images: images) diff --git a/lib/philomena_web/templates/image/_image_meta.html.slime b/lib/philomena_web/templates/image/_image_meta.html.slime index ddde9e7e..70401bb9 100644 --- a/lib/philomena_web/templates/image/_image_meta.html.slime +++ b/lib/philomena_web/templates/image/_image_meta.html.slime @@ -48,8 +48,10 @@ | DS .image-metabar.flex.flex--wrap.block__header--user-credit.center--layout#extrameta div - | Uploaded - =<> pretty_time(@image.created_at) + ' Uploaded + => pretty_time(@image.created_at) + ' by + => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @image span.image-size |   = @image.image_width diff --git a/lib/philomena_web/templates/user_attribution/_anon_user.html.slime b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime new file mode 100644 index 00000000..e752214b --- /dev/null +++ b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime @@ -0,0 +1,5 @@ += if !!@object.user and !@object.anonymous do + strong<> = @object.user.name +- else + strong<> + ' Background Pony \ No newline at end of file diff --git a/lib/philomena_web/templates/user_attribution/_user.html.slime b/lib/philomena_web/templates/user_attribution/_user.html.slime index e69de29b..875af5fe 100644 --- a/lib/philomena_web/templates/user_attribution/_user.html.slime +++ b/lib/philomena_web/templates/user_attribution/_user.html.slime @@ -0,0 +1,2 @@ += if !!@object.user do + strong<>= @object.user.name \ No newline at end of file