From 7c68e5d033ccdd5da415180d3dc92ad8c3676ab4 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 17 Nov 2019 19:59:00 -0500 Subject: [PATCH] add show view --- lib/philomena/textile/renderer.ex | 2 +- .../controllers/commission_controller.ex | 37 +++++++- .../commission/_listing_items.html.slime | 35 +++++++ .../commission/_listing_sheet.html.slime | 6 ++ .../commission/_listing_sidebar.html.slime | 91 +++++++++++++++++++ .../templates/commission/show.html.slime | 18 ++++ 6 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 lib/philomena_web/templates/commission/_listing_items.html.slime create mode 100644 lib/philomena_web/templates/commission/_listing_sheet.html.slime create mode 100644 lib/philomena_web/templates/commission/_listing_sidebar.html.slime create mode 100644 lib/philomena_web/templates/commission/show.html.slime diff --git a/lib/philomena/textile/renderer.ex b/lib/philomena/textile/renderer.ex index 933230a2..475f75ba 100644 --- a/lib/philomena/textile/renderer.ex +++ b/lib/philomena/textile/renderer.ex @@ -18,7 +18,7 @@ defmodule Philomena.Textile.Renderer do parsed = posts |> Enum.map(fn post -> - Parser.parse(@parser, post.body) + Parser.parse(@parser, post[:body]) end) images = diff --git a/lib/philomena_web/controllers/commission_controller.ex b/lib/philomena_web/controllers/commission_controller.ex index a2155f44..fa450472 100644 --- a/lib/philomena_web/controllers/commission_controller.ex +++ b/lib/philomena_web/controllers/commission_controller.ex @@ -1,12 +1,13 @@ defmodule PhilomenaWeb.CommissionController do use PhilomenaWeb, :controller + alias Philomena.Textile.Renderer alias Philomena.Commissions.{Item, Commission} alias Philomena.Repo import Ecto.Query plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create, :edit, :update, :destroy] - plug :load_and_authorize_resource, model: Commission + plug :load_and_authorize_resource, model: Commission, preload: [sheet_image: :tags, user: [awards: :badge], items: [example_image: :tags]] def index(conn, params) do commissions = @@ -16,6 +17,40 @@ defmodule PhilomenaWeb.CommissionController do render(conn, "index.html", commissions: commissions, layout_class: "layout--wide") end + def show(conn, _params) do + commission = conn.assigns.commission + + item_descriptions = + commission.items + |> Enum.map(&[body: &1.description]) + |> Renderer.render_collection() + + item_add_ons = + commission.items + |> Enum.map(&[body: &1.add_ons]) + |> Renderer.render_collection() + + [information, contact, will_create, will_not_create] = + Renderer.render_collection([ + [body: commission.information], + [body: commission.contact], + [body: commission.will_create], + [body: commission.will_not_create] + ]) + + rendered = + %{ + information: information, + contact: contact, + will_create: will_create, + will_not_create: will_not_create + } + + items = Enum.zip([item_descriptions, item_add_ons, commission.items]) + + render(conn, "show.html", rendered: rendered, commission: conn.assigns.commission, items: items, layout_class: "layout--wide") + end + defp commission_search(attrs) when is_map(attrs) do item_type = presence(attrs["item_type"]) categories = presence(attrs["category"]) diff --git a/lib/philomena_web/templates/commission/_listing_items.html.slime b/lib/philomena_web/templates/commission/_listing_items.html.slime new file mode 100644 index 00000000..93fa76d3 --- /dev/null +++ b/lib/philomena_web/templates/commission/_listing_items.html.slime @@ -0,0 +1,35 @@ +.block + .block__header + span.block__header__title Available Items and Prices + + .block__content + table.table + thead + tr + th Example + th Description + th Base Price + th Add-Ons + tbody + = for {description, add_ons, item} <- @items do + tr + td + = if item.example_image do + = render PhilomenaWeb.ImageView, "_image_container.html", image: item.example_image, size: :thumb_small, conn: @conn + - else + | (No example) + + td + strong + = item.item_type + + br + br + + == description + td + | $ + = Decimal.round(item.base_price, 2) + + td + == add_ons \ No newline at end of file diff --git a/lib/philomena_web/templates/commission/_listing_sheet.html.slime b/lib/philomena_web/templates/commission/_listing_sheet.html.slime new file mode 100644 index 00000000..ce980cf6 --- /dev/null +++ b/lib/philomena_web/templates/commission/_listing_sheet.html.slime @@ -0,0 +1,6 @@ += if @commission.sheet_image do + .block + .block__header + span.block__header__title Commissions Sheet + .block__content.center + = render PhilomenaWeb.ImageView, "_image_container.html", image: @commission.sheet_image, size: :tall, conn: @conn diff --git a/lib/philomena_web/templates/commission/_listing_sidebar.html.slime b/lib/philomena_web/templates/commission/_listing_sidebar.html.slime new file mode 100644 index 00000000..7d1e974b --- /dev/null +++ b/lib/philomena_web/templates/commission/_listing_sidebar.html.slime @@ -0,0 +1,91 @@ +/ General information block +.block + .block__header + span.block__header__title General information + .block__content.commission__block_body + strong> Profile: + = render PhilomenaWeb.UserAttributionView, "_user.html", object: @commission + br + + strong> Status: + = if @commission.open, do: "Open", else: "Closed" + + br + + strong> Price Range: + - {min, max} = Enum.min_max_by(@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 + br + + == @rendered.information + +/ Contact information block +.block + .block__header + span.block__header__title Contact information + .block__content.commission__block_body + == @rendered.contact + +/ Categories block +.block + .block__header + span.block__header__title Art Categories + .block__content + = for cat <- @commission.categories do + span.commission__category + = cat + +/ Will create block += if @user.commission.will_create not in [nil, ""] do + .block + .block__header + span.block__header__title Will draw/create + .block__content.commission__block_body + == @rendered.will_create + +/ Will not create block += if @user.commission.will_not_create not in [nil, ""] do + .block + .block__header + span.block__header__title Will not draw/create + .block__content.commission__block_body + == @rendered.will_not_create + +/ User link block +/.block + .block__header: span.block__header__title User Links + - is_current = (current_user && current_user.id == @user.id) + - if @links.present? || is_current + = render partial: 'profiles/user_link_area' + +/ Options block +/.block + .block__header + span.block__header__title Options + .block__content + - if can? :edit, @user.commission + = link_to 'Edit this listing', edit_commission_path(@user.commission) + br + = link_to 'Delete this listing', commission_path(@user.commission), data: { confirm: t('commissions.confirm_delete_listing') }, method: :delete + br + = link_to 'Report this listing', new_report_path(reportable_class: 'commission', reportable_id: @user.commission.id) + +/ Share block +.block + .block__header + span.block__header__title Share this listing + .block__content + - url = Routes.commission_url(@conn, :show, @commission) + + .field + label> for="commission_url" URL + a href="#" data-click-copy="#commission_url" + i.fa.fa-clipboard> + ' Copy + = text_input :commission_url, url, class: "input input--wide input--separate-top", readonly: true \ No newline at end of file diff --git a/lib/philomena_web/templates/commission/show.html.slime b/lib/philomena_web/templates/commission/show.html.slime new file mode 100644 index 00000000..47bbafaa --- /dev/null +++ b/lib/philomena_web/templates/commission/show.html.slime @@ -0,0 +1,18 @@ +h1 + = @commission.user.name + | 's Commisisons + +.column-layout + + / Side column + .column-layout__left + = render PhilomenaWeb.CommissionView, "_listing_sidebar.html", commission: @commission, rendered: @rendered, conn: @conn + + / Main column + .column-layout__main + + / Commission sheet block + = render PhilomenaWeb.CommissionView, "_listing_sheet.html", commission: @commission, conn: @conn + + / Types and prices block + = render PhilomenaWeb.CommissionView, "_listing_items.html", commission: @commission, items: @items, conn: @conn \ No newline at end of file