mod faves page

This commit is contained in:
byte[] 2019-12-20 12:26:38 -05:00
parent 09d079e5f7
commit a7d9386af8
8 changed files with 56 additions and 23 deletions

View file

@ -0,0 +1,27 @@
defmodule PhilomenaWeb.Image.FavoriteController do
use PhilomenaWeb, :controller
alias Philomena.Images.Image
alias Philomena.Repo
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true, preload: [faves: :user]
plug :load_votes_if_authorized
def index(conn, _params) do
render(conn, "index.html", layout: false)
end
defp load_votes_if_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :hide, conn.assigns.image) do
true ->
image = Repo.preload(conn.assigns.image, upvotes: :user, downvotes: :user)
conn
|> assign(:image, image)
|> assign(:has_votes, true)
false ->
assign(conn, :has_votes, false)
end
end
end

View file

@ -1,11 +0,0 @@
defmodule PhilomenaWeb.Image.FavoritesController do
use PhilomenaWeb, :controller
alias Philomena.Images.Image
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true, preload: [faves: :user]
def index(conn, _params) do
render(conn, "index.html", layout: false, image: conn.assigns.image)
end
end

View file

@ -287,7 +287,7 @@ defmodule PhilomenaWeb.Router do
resources "/navigate", Image.NavigateController, only: [:index] resources "/navigate", Image.NavigateController, only: [:index]
resources "/reports", Image.ReportController, only: [:new, :create] resources "/reports", Image.ReportController, only: [:new, :create]
resources "/reporting", Image.ReportingController, only: [:show], singleton: true resources "/reporting", Image.ReportingController, only: [:show], singleton: true
resources "/favorites", Image.FavoritesController, only: [:index] resources "/favorites", Image.FavoriteController, only: [:index]
end end
scope "/tags", Tag, as: :tag do scope "/tags", Tag, as: :tag do
resources "/autocomplete", AutocompleteController, only: [:show], singleton: true resources "/autocomplete", AutocompleteController, only: [:show], singleton: true

View file

@ -8,7 +8,7 @@
a href="#" data-click-tab="sharing" a href="#" data-click-tab="sharing"
i.fa.fa-share> i.fa.fa-share>
| Share | Share
a href="#" data-click-tab="favoriters" data-load-tab=Routes.image_favorites_path(@conn, :index, @image) a href="#" data-click-tab="favoriters" data-load-tab=Routes.image_favorite_path(@conn, :index, @image)
i.fa.fa-star> i.fa.fa-star>
| List favoriters | List favoriters
= if display_mod_tools? do = if display_mod_tools? do

View file

@ -0,0 +1,24 @@
h5
' Faved by
=> @image.faves_count
= pluralize("user", "users", @image.faves_count)
= for fave <- Enum.sort_by(@image.faves, & &1.user.name) do
=> link fave.user.name, to: Routes.profile_path(@conn, :show, fave.user), class: "interaction-user-list-item"
= if @has_votes do
h5
' Upvoted by
=> @image.upvotes_count
= pluralize("user", "users", @image.faves_count)
= for upvote <- Enum.sort_by(@image.upvotes, & &1.user.name) do
=> link upvote.user.name, to: Routes.profile_path(@conn, :show, upvote.user), class: "interaction-user-list-item"
h5
' Downvoted by
=> @image.downvotes_count
= pluralize("user", "users", @image.downvotes_count)
= for downvote <- Enum.sort_by(@image.downvotes, & &1.user.name) do
=> link downvote.user.name, to: Routes.profile_path(@conn, :show, downvote.user), class: "interaction-user-list-item"

View file

@ -1,7 +0,0 @@
h5
' Faved by
=> @image.faves_count
= pluralize("user", "users", @image.faves_count)
= for fave <- Enum.sort_by(@image.faves, & &1.user.name) do
=> link fave.user.name, to: Routes.profile_path(@conn, :show, fave.user), class: "interaction-user-list-item"

View file

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

View file

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