Skip to content

Commit

Permalink
feature: adds an admin interface for HomePageImage
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinW520 committed Jan 5, 2020
1 parent bb35d56 commit e400a0e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/controllers/admin/home_page_images_controller.rb
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
22 changes: 22 additions & 0 deletions app/views/admin/home_page_images/index.html.haml
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"
48 changes: 48 additions & 0 deletions app/views/admin/home_page_images/new.html.haml
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..." }
2 changes: 2 additions & 0 deletions app/views/admin/navigation/_sidebar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@
Public Pages
%li.navigation-item
%a.navigation-link{href: root_path} Home
%li.navigation-item
%a.navigation-link{href: admin_home_page_images_path} Home Page Images
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
resources :team_members
resource :profile, controller: "profile", only: [:show, :edit, :update]
resources :users
resources :home_page_images, only: [:index, :new, :create, :destroy]
end
end

0 comments on commit e400a0e

Please sign in to comment.