From 8d9487e032cf8bc1e8db48b6310620a005da3b7c Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 4 Dec 2019 09:28:17 -0500 Subject: [PATCH] renest commissions page --- lib/philomena/users/user.ex | 2 + .../controllers/commission_controller.ex | 41 -------------- .../profile/commission_controller.ex | 54 +++++++++++++++++++ lib/philomena_web/router.ex | 5 ++ .../commission/_directory_results.html.slime | 2 +- .../templates/commission/show.html.slime | 18 ------- .../commission/_listing_items.html.slime | 0 .../commission/_listing_sheet.html.slime | 0 .../commission/_listing_sidebar.html.slime | 0 .../profile/commission/show.html.slime | 18 +++++++ .../views/profile/commission_view.ex | 3 ++ 11 files changed, 83 insertions(+), 60 deletions(-) create mode 100644 lib/philomena_web/controllers/profile/commission_controller.ex delete mode 100644 lib/philomena_web/templates/commission/show.html.slime rename lib/philomena_web/templates/{ => profile}/commission/_listing_items.html.slime (100%) rename lib/philomena_web/templates/{ => profile}/commission/_listing_sheet.html.slime (100%) rename lib/philomena_web/templates/{ => profile}/commission/_listing_sidebar.html.slime (100%) create mode 100644 lib/philomena_web/templates/profile/commission/show.html.slime create mode 100644 lib/philomena_web/views/profile/commission_view.ex diff --git a/lib/philomena/users/user.ex b/lib/philomena/users/user.ex index 7fc27bfd..129225df 100644 --- a/lib/philomena/users/user.ex +++ b/lib/philomena/users/user.ex @@ -21,6 +21,7 @@ defmodule Philomena.Users.User do alias Philomena.Notifications.UnreadNotification alias Philomena.Galleries.Gallery alias Philomena.Users.User + alias Philomena.Commissions.Commission @derive {Phoenix.Param, key: :slug} @@ -32,6 +33,7 @@ defmodule Philomena.Users.User do has_many :awards, Badges.Award has_many :unread_notifications, UnreadNotification has_many :notifications, through: [:unread_notifications, :notification] + has_one :commission, Commission belongs_to :current_filter, Filter belongs_to :deleted_by_user, User diff --git a/lib/philomena_web/controllers/commission_controller.ex b/lib/philomena_web/controllers/commission_controller.ex index 5d9be124..33a7b785 100644 --- a/lib/philomena_web/controllers/commission_controller.ex +++ b/lib/philomena_web/controllers/commission_controller.ex @@ -1,14 +1,10 @@ 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, only: [:show], preload: [sheet_image: :tags, user: [awards: :badge], items: [example_image: :tags]] - def index(conn, params) do commissions = commission_search(params["commission"]) @@ -17,43 +13,6 @@ 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(conn) - - item_add_ons = - commission.items - |> Enum.map(&%{body: &1.add_ons}) - |> Renderer.render_collection(conn) - - [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} - ], - conn - ) - - 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/controllers/profile/commission_controller.ex b/lib/philomena_web/controllers/profile/commission_controller.ex new file mode 100644 index 00000000..92f36d3f --- /dev/null +++ b/lib/philomena_web/controllers/profile/commission_controller.ex @@ -0,0 +1,54 @@ +defmodule PhilomenaWeb.Profile.CommissionController do + use PhilomenaWeb, :controller + + alias Philomena.Textile.Renderer + alias Philomena.Users.User + + plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create, :edit, :update, :delete] + plug :load_resource, model: User, id_name: "profile_id", id_field: "slug", preload: [commission: [sheet_image: :tags, user: [awards: :badge], items: [example_image: :tags]]], persisted: true + plug :ensure_commission + + def show(conn, _params) do + commission = conn.assigns.user.commission + + item_descriptions = + commission.items + |> Enum.map(&%{body: &1.description}) + |> Renderer.render_collection(conn) + + item_add_ons = + commission.items + |> Enum.map(&%{body: &1.add_ons}) + |> Renderer.render_collection(conn) + + [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} + ], + conn + ) + + 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 ensure_commission(conn, _opts) do + case is_nil(conn.assigns.user.commission) do + true -> PhilomenaWeb.NotFoundPlug.call(conn) + false -> conn + end + end +end \ No newline at end of file diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 9e942f2c..79ae9e04 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -112,6 +112,10 @@ defmodule PhilomenaWeb.Router do resources "/read", Forum.ReadController, only: [:create], singleton: true end + resources "/profiles", ProfileController, only: [] do + resources "/commission", Profile.CommissionController, only: [:new, :create, :edit, :update, :delete], singleton: true + end + scope "/filters", Filter, as: :filter do resources "/spoiler_type", SpoilerTypeController, only: [:update], singleton: true end @@ -168,6 +172,7 @@ defmodule PhilomenaWeb.Router do resources "/filters", FilterController resources "/profiles", ProfileController, only: [:show] do resources "/reports", Profile.ReportController, only: [:new, :create] + resources "/commission", Profile.CommissionController, only: [:show], singleton: true end resources "/captchas", CaptchaController, only: [:create] scope "/posts", Post, as: :post do diff --git a/lib/philomena_web/templates/commission/_directory_results.html.slime b/lib/philomena_web/templates/commission/_directory_results.html.slime index c053fa9d..0d1d3981 100644 --- a/lib/philomena_web/templates/commission/_directory_results.html.slime +++ b/lib/philomena_web/templates/commission/_directory_results.html.slime @@ -49,7 +49,7 @@ elixir: p strong - = link "More information", to: Routes.commission_path(@conn, :show, c) + = link "More information", to: Routes.profile_commission_path(@conn, :show, c.user) - true -> p We couldn't find any commission listings to display. Sorry! \ 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 deleted file mode 100644 index 47bbafaa..00000000 --- a/lib/philomena_web/templates/commission/show.html.slime +++ /dev/null @@ -1,18 +0,0 @@ -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 diff --git a/lib/philomena_web/templates/commission/_listing_items.html.slime b/lib/philomena_web/templates/profile/commission/_listing_items.html.slime similarity index 100% rename from lib/philomena_web/templates/commission/_listing_items.html.slime rename to lib/philomena_web/templates/profile/commission/_listing_items.html.slime diff --git a/lib/philomena_web/templates/commission/_listing_sheet.html.slime b/lib/philomena_web/templates/profile/commission/_listing_sheet.html.slime similarity index 100% rename from lib/philomena_web/templates/commission/_listing_sheet.html.slime rename to lib/philomena_web/templates/profile/commission/_listing_sheet.html.slime diff --git a/lib/philomena_web/templates/commission/_listing_sidebar.html.slime b/lib/philomena_web/templates/profile/commission/_listing_sidebar.html.slime similarity index 100% rename from lib/philomena_web/templates/commission/_listing_sidebar.html.slime rename to lib/philomena_web/templates/profile/commission/_listing_sidebar.html.slime diff --git a/lib/philomena_web/templates/profile/commission/show.html.slime b/lib/philomena_web/templates/profile/commission/show.html.slime new file mode 100644 index 00000000..b9dbaad3 --- /dev/null +++ b/lib/philomena_web/templates/profile/commission/show.html.slime @@ -0,0 +1,18 @@ +h1 + = @commission.user.name + | 's Commisisons + +.column-layout + + / Side column + .column-layout__left + = render PhilomenaWeb.Profile.CommissionView, "_listing_sidebar.html", commission: @commission, rendered: @rendered, conn: @conn + + / Main column + .column-layout__main + + / Commission sheet block + = render PhilomenaWeb.Profile.CommissionView, "_listing_sheet.html", commission: @commission, conn: @conn + + / Types and prices block + = render PhilomenaWeb.Profile.CommissionView, "_listing_items.html", commission: @commission, items: @items, conn: @conn \ No newline at end of file diff --git a/lib/philomena_web/views/profile/commission_view.ex b/lib/philomena_web/views/profile/commission_view.ex new file mode 100644 index 00000000..5b76e2b3 --- /dev/null +++ b/lib/philomena_web/views/profile/commission_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.Profile.CommissionView do + use PhilomenaWeb, :view +end