From 022b1008ab54e3df0df4e2a7dbaf6dce2692b3df Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 4 Dec 2019 17:56:13 -0500 Subject: [PATCH] add profile source changes --- .../profile/source_change_controller.ex | 26 +++++++++++++ lib/philomena_web/router.ex | 1 + .../image/source_change/index.html.slime | 38 +------------------ .../templates/profile/show.html.slime | 2 +- .../profile/source_change/index.html.slime | 9 +++++ .../templates/source_change/index.html.slime | 37 ++++++++++++++++++ .../views/profile/source_change_view.ex | 3 ++ lib/philomena_web/views/source_change_view.ex | 3 ++ 8 files changed, 81 insertions(+), 38 deletions(-) create mode 100644 lib/philomena_web/controllers/profile/source_change_controller.ex create mode 100644 lib/philomena_web/templates/profile/source_change/index.html.slime create mode 100644 lib/philomena_web/templates/source_change/index.html.slime create mode 100644 lib/philomena_web/views/profile/source_change_view.ex create mode 100644 lib/philomena_web/views/source_change_view.ex diff --git a/lib/philomena_web/controllers/profile/source_change_controller.ex b/lib/philomena_web/controllers/profile/source_change_controller.ex new file mode 100644 index 00000000..3467614a --- /dev/null +++ b/lib/philomena_web/controllers/profile/source_change_controller.ex @@ -0,0 +1,26 @@ +defmodule PhilomenaWeb.Profile.SourceChangeController do + use PhilomenaWeb, :controller + + alias Philomena.Users.User + alias Philomena.Images.Image + alias Philomena.SourceChanges.SourceChange + alias Philomena.Repo + import Ecto.Query + + plug PhilomenaWeb.CanaryMapPlug, index: :show + plug :load_and_authorize_resource, model: User, id_name: "profile_id", id_field: "slug", persisted: true + + def index(conn, _params) do + user = conn.assigns.user + + source_changes = + SourceChange + |> join(:inner, [sc], i in Image, on: sc.image_id == i.id) + |> where([sc, i], sc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)) + |> preload([:user, image: [:user, :tags]]) + |> order_by(desc: :created_at) + |> Repo.paginate(conn.assigns.scrivener) + + render(conn, "index.html", user: user, source_changes: source_changes) + end +end \ No newline at end of file diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 48c64554..719c5085 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -179,6 +179,7 @@ defmodule PhilomenaWeb.Router do resources "/reports", Profile.ReportController, only: [:new, :create] resources "/commission", Profile.CommissionController, only: [:show], singleton: true resources "/tag_changes", Profile.TagChangeController, only: [:index] + resources "/source_changes", Profile.SourceChangeController, only: [:index] end resources "/captchas", CaptchaController, only: [:create] scope "/posts", Post, as: :post do diff --git a/lib/philomena_web/templates/image/source_change/index.html.slime b/lib/philomena_web/templates/image/source_change/index.html.slime index 4cedd025..712f434a 100644 --- a/lib/philomena_web/templates/image/source_change/index.html.slime +++ b/lib/philomena_web/templates/image/source_change/index.html.slime @@ -7,40 +7,4 @@ h1 - route = fn p -> Routes.image_source_change_path(@conn, :index, @image, p) end - pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn -.block - .block__header - = pagination - - .block__content - table.table - thead - tr - th colspan=2 Image - th New Source - th Timestamp - th User - th Initial? - - tbody - = for source_change <- @source_changes do - tr - td.center - = link source_change.image_id, to: Routes.image_path(@conn, :show, source_change.image) - td.center - = render PhilomenaWeb.ImageView, "_image_container.html", image: source_change.image, size: :thumb_tiny, conn: @conn - - td - = source_change.new_value - - td - = pretty_time(source_change.created_at) - - td - = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: source_change, conn: @conn - - td - = if source_change.initial do - ' ✓ - - .block__header - = pagination \ No newline at end of file += render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination \ No newline at end of file diff --git a/lib/philomena_web/templates/profile/show.html.slime b/lib/philomena_web/templates/profile/show.html.slime index f9380cb3..6b58e3e5 100644 --- a/lib/philomena_web/templates/profile/show.html.slime +++ b/lib/philomena_web/templates/profile/show.html.slime @@ -24,7 +24,7 @@ ul.profile-top__options__column li = link("Favorites", to: Routes.search_path(@conn, :index, q: "faved_by_id:#{@user.id}")) li = link("Tag changes", to: Routes.profile_tag_change_path(@conn, :index, @user)) - li = link("Source changes", to: "#") + li = link("Source changes", to: Routes.profile_source_change_path(@conn, :index, @user)) .column-layout .column-layout__left diff --git a/lib/philomena_web/templates/profile/source_change/index.html.slime b/lib/philomena_web/templates/profile/source_change/index.html.slime new file mode 100644 index 00000000..f51afef1 --- /dev/null +++ b/lib/philomena_web/templates/profile/source_change/index.html.slime @@ -0,0 +1,9 @@ +h1 + ' Source changes by + a href=Routes.profile_path(@conn, :show, @user) + = @user.name + +- route = fn p -> Routes.profile_source_change_path(@conn, :index, @image, p) end +- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn + += render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination \ No newline at end of file diff --git a/lib/philomena_web/templates/source_change/index.html.slime b/lib/philomena_web/templates/source_change/index.html.slime new file mode 100644 index 00000000..ff7ee287 --- /dev/null +++ b/lib/philomena_web/templates/source_change/index.html.slime @@ -0,0 +1,37 @@ +.block + .block__header + = @pagination + + .block__content + table.table + thead + tr + th colspan=2 Image + th New Source + th Timestamp + th User + th Initial? + + tbody + = for source_change <- @source_changes do + tr + td.center + = link source_change.image_id, to: Routes.image_path(@conn, :show, source_change.image) + td.center + = render PhilomenaWeb.ImageView, "_image_container.html", image: source_change.image, size: :thumb_tiny, conn: @conn + + td + = source_change.new_value + + td + = pretty_time(source_change.created_at) + + td + = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: source_change, conn: @conn + + td + = if source_change.initial do + ' ✓ + + .block__header + = @pagination \ No newline at end of file diff --git a/lib/philomena_web/views/profile/source_change_view.ex b/lib/philomena_web/views/profile/source_change_view.ex new file mode 100644 index 00000000..a0b4d549 --- /dev/null +++ b/lib/philomena_web/views/profile/source_change_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.Profile.SourceChangeView do + use PhilomenaWeb, :view +end diff --git a/lib/philomena_web/views/source_change_view.ex b/lib/philomena_web/views/source_change_view.ex new file mode 100644 index 00000000..ec0da593 --- /dev/null +++ b/lib/philomena_web/views/source_change_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.SourceChangeView do + use PhilomenaWeb, :view +end