commission section on profile page

This commit is contained in:
byte[] 2019-12-05 18:11:15 -05:00
parent 19174a31ba
commit 463d86af5c
4 changed files with 51 additions and 1 deletions

View file

@ -12,7 +12,9 @@ defmodule PhilomenaWeb.ProfileController do
alias Philomena.Repo
import Ecto.Query
plug :load_and_authorize_resource, model: User, only: :show, id_field: "slug", preload: [awards: :badge, public_links: :tag]
plug :load_and_authorize_resource, model: User, only: :show, id_field: "slug", preload: [
awards: :badge, public_links: :tag, commission: [sheet_image: :tags, items: [example_image: :tags]]
]
def show(conn, _params) do
current_user = conn.assigns.current_user
@ -79,6 +81,9 @@ defmodule PhilomenaWeb.ProfileController do
about_me =
Renderer.render_one(%{body: user.description || ""}, conn)
commission_information =
commission_info(user.commission, conn)
recent_galleries =
Gallery
|> where(creator_id: ^user.id)
@ -96,6 +101,7 @@ defmodule PhilomenaWeb.ProfileController do
"show.html",
user: user,
interactions: interactions,
commission_information: commission_information,
recent_uploads: recent_uploads,
recent_faves: recent_faves,
recent_comments: recent_comments,
@ -136,4 +142,8 @@ defmodule PhilomenaWeb.ProfileController do
defp map_fetch(nil, _field_name), do: nil
defp map_fetch(map, field_name), do: Map.get(map, field_name)
defp commission_info(%{information: info}, conn) when info not in [nil, ""],
do: Renderer.render_one(%{body: info}, conn)
defp commission_info(_commission, _conn), do: ""
end

View file

@ -0,0 +1,32 @@
.block__content.profile
= cond do
- @user.commission ->
strong> Status:
= commission_status(@user.commission)
br
= if Enum.any?(@user.commission.items) do
strong> Price Range:
- {min, max} = Enum.min_max_by(@user.commission.items, & &1.base_price)
| $
=> Decimal.round(min.base_price, 2) |> Decimal.to_string()
| - $
=> Decimal.round(max.base_price, 2) |> Decimal.to_string()
' USD
br
/ Lotta space here
br
== @commission_information
br
br
= link "More information", to: Routes.profile_commission_path(@conn, :show, @user)
- current?(@user, @conn.assigns.current_user) ->
em
' You don't have any commission information listed yet.
=> link "Click here", to: Routes.profile_commission_path(@conn, :new, @user)
' to set it up.
- true ->

View file

@ -31,6 +31,11 @@
.column-layout
.column-layout__left
.block
.block__header
span.block__header__title Commissions
= render PhilomenaWeb.ProfileView, "_commission.html", user: @user, commission_information: @commission_information, conn: @conn
.block
.block__header
span.block__header__title User Links

View file

@ -20,6 +20,9 @@ defmodule PhilomenaWeb.ProfileView do
def award_title(award),
do: award.badge_name
def commission_status(%{open: true}), do: "Open"
def commission_status(_commission), do: "Closed"
def sparkline_data(data) do
# Normalize range
{min, max} = Enum.min_max(data)