diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index 7162f49c..7a6e1302 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -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 diff --git a/lib/philomena_web/templates/profile/_commission.html.slime b/lib/philomena_web/templates/profile/_commission.html.slime new file mode 100644 index 00000000..0c8cc427 --- /dev/null +++ b/lib/philomena_web/templates/profile/_commission.html.slime @@ -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 -> \ 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 ff7ca784..0752003e 100644 --- a/lib/philomena_web/templates/profile/show.html.slime +++ b/lib/philomena_web/templates/profile/show.html.slime @@ -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 diff --git a/lib/philomena_web/views/profile_view.ex b/lib/philomena_web/views/profile_view.ex index 9feadcce..2fb4ebf4 100644 --- a/lib/philomena_web/views/profile_view.ex +++ b/lib/philomena_web/views/profile_view.ex @@ -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)