add profile source changes

This commit is contained in:
byte[] 2019-12-04 17:56:13 -05:00
parent 015abf068b
commit 022b1008ab
8 changed files with 81 additions and 38 deletions

View file

@ -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

View file

@ -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

View file

@ -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
' &#x2713;
.block__header
= pagination
= render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination

View file

@ -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

View file

@ -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

View file

@ -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
' &#x2713;
.block__header
= @pagination

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.Profile.SourceChangeView do
use PhilomenaWeb, :view
end

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.SourceChangeView do
use PhilomenaWeb, :view
end