From c918e4f7abfc37398cb1a710602fce90b5ec91a0 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 4 Dec 2019 19:53:31 -0500 Subject: [PATCH] gallery show page --- lib/philomena/galleries/gallery.ex | 2 +- .../controllers/gallery_controller.ex | 4 +- .../templates/gallery/edit.html.slime | 3 + .../templates/gallery/new.html.slime | 1 + .../templates/gallery/show.html.slime | 76 +++++++++++++++++++ lib/philomena_web/views/gallery_view.ex | 7 ++ 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 lib/philomena_web/templates/gallery/edit.html.slime create mode 100644 lib/philomena_web/templates/gallery/show.html.slime diff --git a/lib/philomena/galleries/gallery.ex b/lib/philomena/galleries/gallery.ex index 41fe7333..3b0215f6 100644 --- a/lib/philomena/galleries/gallery.ex +++ b/lib/philomena/galleries/gallery.ex @@ -29,7 +29,7 @@ defmodule Philomena.Galleries.Gallery do def changeset(gallery, attrs) do gallery |> cast(attrs, [:thumbnail_id, :title, :spoiler_warning, :description, :order_position_asc]) - |> validate_required([:title]) + |> validate_required([:title, :thumbnail_id]) |> validate_length(:title, max: 100, count: :bytes) |> validate_length(:spoiler_warning, max: 20, count: :bytes) |> validate_length(:description, max: 10_000, count: :bytes) diff --git a/lib/philomena_web/controllers/gallery_controller.ex b/lib/philomena_web/controllers/gallery_controller.ex index ad3a14f6..efb3e021 100644 --- a/lib/philomena_web/controllers/gallery_controller.ex +++ b/lib/philomena_web/controllers/gallery_controller.ex @@ -9,7 +9,7 @@ defmodule PhilomenaWeb.GalleryController do import Ecto.Query plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create, :edit, :update, :delete] - plug :load_and_authorize_resource, model: Gallery, except: [:index] + plug :load_and_authorize_resource, model: Gallery, except: [:index], preload: [:creator, thumbnail: :tags] def index(conn, params) do galleries = @@ -40,7 +40,7 @@ defmodule PhilomenaWeb.GalleryController do conn |> Map.put(:params, params) - |> render("show.html", gallery: gallery, images: images, interactions: interactions) + |> render("show.html", layout_class: "layout--wide", gallery: gallery, images: images, interactions: interactions) end def new(conn, _params) do diff --git a/lib/philomena_web/templates/gallery/edit.html.slime b/lib/philomena_web/templates/gallery/edit.html.slime new file mode 100644 index 00000000..fe0fc4af --- /dev/null +++ b/lib/philomena_web/templates/gallery/edit.html.slime @@ -0,0 +1,3 @@ +h1 Editing Gallery + += render PhilomenaWeb.GalleryView, "_form.html", conn: @conn, changeset: @changeset, action: Routes.gallery_path(@conn, :update, @gallery) \ No newline at end of file diff --git a/lib/philomena_web/templates/gallery/new.html.slime b/lib/philomena_web/templates/gallery/new.html.slime index 9eb3dadc..7a555f67 100644 --- a/lib/philomena_web/templates/gallery/new.html.slime +++ b/lib/philomena_web/templates/gallery/new.html.slime @@ -1,2 +1,3 @@ h1 Create a Gallery + = render PhilomenaWeb.GalleryView, "_form.html", conn: @conn, changeset: @changeset, action: Routes.gallery_path(@conn, :create) \ No newline at end of file diff --git a/lib/philomena_web/templates/gallery/show.html.slime b/lib/philomena_web/templates/gallery/show.html.slime new file mode 100644 index 00000000..23d04a7c --- /dev/null +++ b/lib/philomena_web/templates/gallery/show.html.slime @@ -0,0 +1,76 @@ +elixir: + scope = scope(@conn) + image_url = fn image -> Routes.image_path(@conn, :show, image, scope) end + route = fn p -> Routes.gallery_path(@conn, :show, @gallery, p) end + pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @images, route: route, params: scope + info = render PhilomenaWeb.PaginationView, "_pagination_info.html", page: @images + +#sortable + .block#imagelist-container + section.block__header.flex + h1.block__header__title.hide-mobile + ' Viewing gallery + strong> + = @gallery.title + + = pagination + + .flex__right + a href="#" + i.fa.fa-exclamation-triangle> + span.hide-mobile Report + + = if can?(@conn, :edit, @gallery) do + a href=Routes.gallery_path(@conn, :edit, @gallery) + i.fa.fa-pencil> + span.hide-mobile Edit + + = if can?(@conn, :edit, @gallery) do + a.rearrange-button.js-rearrange href='#' data-click-hide='.js-rearrange' data-click-show='.js-save,#gallery-rearrange-info' + i.fa.fa-sort> + ' Rearrange + /data-reorder-path=gallery_order_path(@gallery) + a.rearrange-button.js-save.hidden href='#' data-click-hide='.js-save,#gallery-rearrange-info' data-click-show='.js-rearrange' + i.fa.fa-check> + ' Save + + = if show_subscription_link?(@gallery.creator, @conn.assigns.current_user) do + /= subscription_link(@gallery, current_user) + + .block__header.block__header--light.block__header--sub + span.block__header__title A gallery by + + => link @gallery.creator.name, to: Routes.profile_path(@conn, :show, @gallery.creator) + ' with + => @gallery.image_count + = pluralize("image", "images", @gallery.image_count) + ' , last updated + = pretty_time(@gallery.updated_at) + + .block__content.flex.js-imagelist-info + .flex__fixed.thumb-tiny-container.spacing-right + = render PhilomenaWeb.ImageView, "_image_container.html", image: @gallery.thumbnail, size: :thumb_tiny, conn: @conn + + .flex__grow + = if @gallery.spoiler_warning not in [nil, ""] do + strong> Warning: + = @gallery.spoiler_warning + + = if @gallery.description not in [nil, ""] do + p = @gallery.description + + .block__content.hidden#gallery-rearrange-info + .block.block--fixed.block--primary + | Click the image and drag. + br + strong Note that you may have to wait a couple of seconds before the order is applied. + + .block__content.js-resizable-media-container + = for image <- @images do + = render PhilomenaWeb.ImageView, "_image_box.html", image: image, link: image_url.(image), size: :thumb, conn: @conn + + .block__header.block__header--light.flex + = pagination + + span.block__header__title + = info \ No newline at end of file diff --git a/lib/philomena_web/views/gallery_view.ex b/lib/philomena_web/views/gallery_view.ex index 20bce357..231cbdc9 100644 --- a/lib/philomena_web/views/gallery_view.ex +++ b/lib/philomena_web/views/gallery_view.ex @@ -1,3 +1,10 @@ defmodule PhilomenaWeb.GalleryView do use PhilomenaWeb, :view + + alias Philomena.ImageScope + + def scope(conn), do: ImageScope.scope(conn) + + def show_subscription_link?(%{id: id}, %{id: id}), do: false + def show_subscription_link?(_user1, _user2), do: true end