mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
renest commissions page
This commit is contained in:
parent
846c99e563
commit
8d9487e032
11 changed files with 83 additions and 60 deletions
|
@ -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
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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!
|
|
@ -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
|
|
@ -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
|
3
lib/philomena_web/views/profile/commission_view.ex
Normal file
3
lib/philomena_web/views/profile/commission_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
|||
defmodule PhilomenaWeb.Profile.CommissionView do
|
||||
use PhilomenaWeb, :view
|
||||
end
|
Loading…
Reference in a new issue