-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: adds an admin interface for HomePageImage
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class Admin::HomePageImagesController < Admin::BaseController | ||
def index | ||
@home_page_images = HomePageImage.rank(:display_order).all | ||
end | ||
|
||
def new | ||
@home_page_image = HomePageImage.new | ||
end | ||
|
||
def create | ||
@home_page_image = HomePageImage.new(home_page_image_params) | ||
|
||
if @home_page_image.save | ||
flash[:success] = "Home Page Image successfully created." | ||
redirect_to admin_home_page_images_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def destroy | ||
@home_page_image = HomePageImage.find(params[:id]) | ||
|
||
if @home_page_image.destroy | ||
flash[:success] = "Successfully removed Home Page Image" | ||
redirect_to admin_home_page_images_path | ||
else | ||
flash[:error] = "Could not destroy this Home Page Image" | ||
redirect_to admin_home_page_images_path | ||
end | ||
end | ||
|
||
private | ||
|
||
def home_page_image_params | ||
params.require(:home_page_image).permit! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
= content_for :admin_area_title do | ||
Home Page Images | ||
.row | ||
.col-12 | ||
- @home_page_images.in_groups_of(4, false).each do |home_page_image_group| | ||
.row | ||
- home_page_image_group.each do |home_page_image| | ||
.col-sm-12.col-md-3 | ||
= image_tag home_page_image.image, class: "img-fluid img-thumbnail" | ||
.float-left | ||
%span.text-muted= home_page_image.display_order | ||
.float-right | ||
= link_to admin_home_page_image_path(home_page_image), method: :delete, data: { confirm: "Are you sure?" } do | ||
%i.fa.fa-times.text-danger | ||
Destroy | ||
%hr | ||
.row | ||
.col-12 | ||
.float-right | ||
= link_to "Add New Home Page Image", | ||
new_admin_home_page_image_path, | ||
class: "btn btn-sm btn-success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-# frozen_string_literal: true | ||
.row | ||
.col | ||
%h1 New Home Page Image | ||
%p Home page images are loaded in a responsive, browsable photo gallery. | ||
|
||
.row | ||
.col | ||
= simple_form_for([:admin, @home_page_image], multipart: true) do |f| | ||
= f.error_notification | ||
- if f.object.errors[:base].present? | ||
= f.error_notification message: f.object.errors[:base].to_sentence | ||
.form-inputs | ||
%fieldset | ||
= f.input :short_name | ||
= f.input :display_order, | ||
hint: "Guides display order. Responsive styling may override." | ||
= f.input :hidden | ||
%fieldset | ||
%legend Image | ||
%strong.text-danger It is extremely important that you OPTIMIZE the image BEFORE uploading it for the sake of page load speed. | ||
%p Landscape images will look the best, generally speaking, especially on mobile. | ||
.form-row | ||
= f.file_field :image, | ||
direct_upload: true, | ||
class: "custom-input-file", | ||
type: 'file', | ||
"data-multiple-caption" => "{count} files selected" | ||
= f.label :image do | ||
%i.fa.fa-upload | ||
%span Select Web Optimized Image | ||
- if f.object.image.attached? | ||
.attachment-wrapper{id: "attachment-wrapper-#{f.object.image.id}"} | ||
= image_tag f.object.image, | ||
class: "img img-fluid img-thumbnail" | ||
= link_to attachment_path(id: f.object.image.id), method: :delete, remote: true, class: "text-danger" do | ||
%i.fa.fa-times | ||
%br | ||
.form-actions | ||
= link_to admin_home_page_images_path, | ||
class: "btn btn-md btn-outline-secondary mr-2", | ||
data: { confirm: "Careful! You will lose any progress you made on this form."} do | ||
%i.fas.fa-arrow-left | ||
Go Back | ||
= f.button :submit, | ||
class: "btn btn-md btn-outline-success", | ||
data: { disable_with: "Submitting..." } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters