mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
mod faves page
This commit is contained in:
parent
09d079e5f7
commit
a7d9386af8
8 changed files with 56 additions and 23 deletions
27
lib/philomena_web/controllers/image/favorite_controller.ex
Normal file
27
lib/philomena_web/controllers/image/favorite_controller.ex
Normal 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
|
|
@ -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
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
24
lib/philomena_web/templates/image/favorite/index.html.slime
Normal file
24
lib/philomena_web/templates/image/favorite/index.html.slime
Normal 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"
|
|
@ -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"
|
|
3
lib/philomena_web/views/image/favorite_view.ex
Normal file
3
lib/philomena_web/views/image/favorite_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule PhilomenaWeb.Image.FavoriteView do
|
||||||
|
use PhilomenaWeb, :view
|
||||||
|
end
|
|
@ -1,3 +0,0 @@
|
||||||
defmodule PhilomenaWeb.Image.FavoritesView do
|
|
||||||
use PhilomenaWeb, :view
|
|
||||||
end
|
|
Loading…
Reference in a new issue