-
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.
Merge pull request #70 from yamat47/hero-image-uploadable
Hero image uploadable
- Loading branch information
Showing
30 changed files
with
383 additions
and
23 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.admin-fields { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
gap: 2.0rem; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ | |
|
||
&:hover { | ||
text-decoration: none; | ||
cursor: pointer; | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
app/app/controllers/admin/media_page_settings/media_hero_images_controller.rb
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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
module MediaPageSettings | ||
class MediaHeroImagesController < Admin::ApplicationController | ||
def new | ||
@media_hero_image = MediaHeroImage.new | ||
end | ||
|
||
def edit | ||
@media_hero_image = MediaHeroImage.find(params[:id]) | ||
end | ||
|
||
def create | ||
@media_hero_image = MediaHeroImage.new(media_hero_image_params) | ||
|
||
if @media_hero_image.save | ||
redirect_to admin_media_page_setting_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
@media_hero_image = MediaHeroImage.find(params[:id]) | ||
|
||
if @media_hero_image.update(media_hero_image_params) | ||
redirect_to admin_media_page_setting_path | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@media_hero_image = MediaHeroImage.find(params[:id]) | ||
|
||
@media_hero_image.destroy | ||
|
||
redirect_to admin_media_page_setting_path | ||
end | ||
|
||
private | ||
|
||
def media_hero_image_params | ||
params.require(:media_hero_image).permit(:image) | ||
end | ||
end | ||
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class MediaPageSettingsController < ApplicationController | ||
def show | ||
@media_hero_images = MediaHeroImage.sort_order_ordered | ||
end | ||
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
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 @@ | ||
# frozen_string_literal: true | ||
|
||
class MediaHeroImage < ApplicationRecord | ||
include UniversalId | ||
|
||
setup_universal_id('mhi') | ||
has_one_attached(:image) | ||
|
||
validates :sort_order, presence: true, uniqueness: true, numericality: { only_integer: true, greater_than: 0 } | ||
|
||
before_validation :set_sort_order, on: :create | ||
|
||
scope :sort_order_ordered, -> { order(:sort_order) } | ||
|
||
private | ||
|
||
def set_sort_order | ||
return if sort_order.present? | ||
|
||
self.sort_order = MediaHeroImage.maximum(:sort_order).to_i + 1 | ||
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
23 changes: 23 additions & 0 deletions
23
app/app/views/admin/media_page_settings/media_hero_images/_form.html.haml
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,23 @@ | ||
= form_with model: media_hero_image, url:, local: true do |form| | ||
.admin-fields | ||
.admin-fields__field | ||
.admin-field | ||
.admin-field__label | ||
= MediaHeroImage.human_attribute_name(:image) | ||
.admin-field__value | ||
.admin-form-file_field__wrapper | ||
= form.file_field :image, class: 'admin-form-file_field__field', accept: 'image/*', required: true | ||
= image_tag media_hero_image.image.url, class: 'admin-field-value-image' if media_hero_image.image.attached? | ||
- if media_hero_image.errors.any? | ||
.admin-fields__field | ||
.admin-form-errors | ||
%ul.admin-form-error-list | ||
- media_hero_image.errors.full_messages.each do |message| | ||
%li.admin-form-error-list__item | ||
= message | ||
.admin-fields__field | ||
.admin-form-action_buttons | ||
.admin-form-action_buttons__action | ||
= form.submit t('view.admin.button.save'), class: 'admin-form-action_button' | ||
.admin-form-action_buttons__action | ||
= link_to t('view.admin.button.cancel'), cancel_path, class: 'admin-form-action_button is-cancel' |
17 changes: 17 additions & 0 deletions
17
app/app/views/admin/media_page_settings/media_hero_images/edit.html.haml
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,17 @@ | ||
:ruby | ||
add_breadcrumb t('view.admin.breadcrumbs.media_page_settings.show'), admin_media_page_setting_path | ||
add_breadcrumb t('view.admin.breadcrumbs.media_page_settings.media_hero_images.edit') | ||
|
||
.admin-content | ||
.admin-content__title | ||
.admin-title | ||
.admin-title__image | ||
= image_tag 'icon-setting.png', class: 'admin-title-image' | ||
.admin-title__text | ||
%h1.admin-title_text | ||
ヒーロー画像 | ||
|
||
.admin-content__fields | ||
= render 'form', media_hero_image: @media_hero_image, | ||
url: admin_media_page_setting_media_hero_image_path(@media_hero_image), | ||
cancel_path: admin_media_page_setting_path |
17 changes: 17 additions & 0 deletions
17
app/app/views/admin/media_page_settings/media_hero_images/new.html.haml
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,17 @@ | ||
:ruby | ||
add_breadcrumb t('view.admin.breadcrumbs.media_page_settings.show'), admin_media_page_setting_path | ||
add_breadcrumb t('view.admin.breadcrumbs.media_page_settings.media_hero_images.new') | ||
|
||
.admin-content | ||
.admin-content__title | ||
.admin-title | ||
.admin-title__image | ||
= image_tag 'icon-setting.png', class: 'admin-title-image' | ||
.admin-title__text | ||
%h1.admin-title_text | ||
ヒーロー画像 | ||
|
||
.admin-content__fields | ||
= render 'form', media_hero_image: @media_hero_image, | ||
url: admin_media_page_setting_media_hero_images_path, | ||
cancel_path: admin_media_page_setting_path |
Oops, something went wrong.