Add edit form for Alt Styles, for Support staff only
We'll need this to fix up the series names and thumbnails for the new prismatic styles!
This commit is contained in:
parent
86e1f31231
commit
0b72b5568c
8 changed files with 117 additions and 3 deletions
|
@ -74,7 +74,7 @@ $container_width: 800px
|
||||||
input, button, select, label
|
input, button, select, label
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
|
|
||||||
input[type=text], input[type=password], input[type=search], input[type=number], input[type=email], select, textarea
|
input[type=text], input[type=password], input[type=search], input[type=number], input[type=email], input[type=url], select, textarea
|
||||||
border-radius: 3px
|
border-radius: 3px
|
||||||
background: #fff
|
background: #fff
|
||||||
border: 1px solid $input-border-color
|
border: 1px solid $input-border-color
|
||||||
|
|
43
app/assets/stylesheets/alt_styles/edit.sass
Normal file
43
app/assets/stylesheets/alt_styles/edit.sass
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
.alt-style-preview
|
||||||
|
width: 300px
|
||||||
|
height: 300px
|
||||||
|
margin: 0 auto
|
||||||
|
|
||||||
|
.alt-style-form
|
||||||
|
display: flex
|
||||||
|
flex-direction: column
|
||||||
|
gap: 1em
|
||||||
|
align-items: flex-start
|
||||||
|
|
||||||
|
fieldset
|
||||||
|
width: 100%
|
||||||
|
display: grid
|
||||||
|
grid-template-columns: auto 1fr
|
||||||
|
align-items: center
|
||||||
|
gap: 1em
|
||||||
|
|
||||||
|
> *:nth-child(2n)
|
||||||
|
width: 40rch
|
||||||
|
max-width: 100%
|
||||||
|
box-sizing: border-box
|
||||||
|
|
||||||
|
input[type=url]
|
||||||
|
font-size: .85em
|
||||||
|
|
||||||
|
label
|
||||||
|
font-weight: bold
|
||||||
|
|
||||||
|
.thumbnail-field
|
||||||
|
display: flex
|
||||||
|
align-items: center
|
||||||
|
gap: .25em
|
||||||
|
|
||||||
|
img
|
||||||
|
width: 40px
|
||||||
|
height: 40px
|
||||||
|
|
||||||
|
input
|
||||||
|
flex: 1 0 20ch
|
||||||
|
|
||||||
|
.field_with_errors
|
||||||
|
display: contents
|
|
@ -1,4 +1,6 @@
|
||||||
class AltStylesController < ApplicationController
|
class AltStylesController < ApplicationController
|
||||||
|
before_action :support_staff_only, except: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@all_alt_styles = AltStyle.includes(:species, :color).
|
@all_alt_styles = AltStyle.includes(:species, :color).
|
||||||
order(:species_id, :color_id)
|
order(:species_id, :color_id)
|
||||||
|
@ -39,8 +41,27 @@ class AltStylesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@alt_style = AltStyle.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@alt_style = AltStyle.find params[:id]
|
||||||
|
|
||||||
|
if @alt_style.update(alt_style_params)
|
||||||
|
flash[:notice] = "\"#{@alt_style.full_name}\" successfully saved!"
|
||||||
|
redirect_to alt_styles_path
|
||||||
|
else
|
||||||
|
render action: :edit, status: :bad_request
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def alt_style_params
|
||||||
|
params.require(:alt_style).permit(:series_name, :thumbnail_url)
|
||||||
|
end
|
||||||
|
|
||||||
def find_color
|
def find_color
|
||||||
if params[:color]
|
if params[:color]
|
||||||
Color.find_by(name: params[:color])
|
Color.find_by(name: params[:color])
|
||||||
|
|
9
app/helpers/alt_styles_helper.rb
Normal file
9
app/helpers/alt_styles_helper.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module AltStylesHelper
|
||||||
|
def view_or_edit_alt_style_url(alt_style)
|
||||||
|
if support_staff?
|
||||||
|
edit_alt_style_path alt_style
|
||||||
|
else
|
||||||
|
alt_style.preview_image_url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,6 +9,8 @@ class AltStyle < ApplicationRecord
|
||||||
has_many :contributions, as: :contributed, inverse_of: :contributed
|
has_many :contributions, as: :contributed, inverse_of: :contributed
|
||||||
|
|
||||||
validates :body_id, presence: true
|
validates :body_id, presence: true
|
||||||
|
validates :series_name, presence: true, allow_nil: true
|
||||||
|
validates :thumbnail_url, presence: true
|
||||||
|
|
||||||
before_create :infer_series_name
|
before_create :infer_series_name
|
||||||
before_create :infer_thumbnail_url
|
before_create :infer_thumbnail_url
|
||||||
|
@ -42,6 +44,10 @@ class AltStyle < ApplicationRecord
|
||||||
"#{series_name} #{color.human_name}"
|
"#{series_name} #{color.human_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def full_name
|
||||||
|
"#{series_name} #{name}"
|
||||||
|
end
|
||||||
|
|
||||||
def preview_image_url
|
def preview_image_url
|
||||||
swf_asset = swf_assets.first
|
swf_asset = swf_assets.first
|
||||||
return nil if swf_asset.nil?
|
return nil if swf_asset.nil?
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
%li
|
%li
|
||||||
= link_to alt_style.preview_image_url do
|
= link_to view_or_edit_alt_style_url(alt_style) do
|
||||||
= image_tag alt_style.preview_image_url, class: "preview", loading: "lazy"
|
= image_tag alt_style.preview_image_url, class: "preview", loading: "lazy"
|
||||||
.name= alt_style.name
|
.name= alt_style.name
|
35
app/views/alt_styles/edit.html.haml
Normal file
35
app/views/alt_styles/edit.html.haml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
- title @alt_style.full_name
|
||||||
|
- use_responsive_design
|
||||||
|
|
||||||
|
%ol.breadcrumbs
|
||||||
|
%li= link_to "Alt Styles", alt_styles_path
|
||||||
|
%li
|
||||||
|
= link_to @alt_style.color.human_name,
|
||||||
|
alt_styles_path(color: @alt_style.color.human_name)
|
||||||
|
%li{"data-relation-to-prev": "sibling"}
|
||||||
|
= link_to @alt_style.species.human_name,
|
||||||
|
alt_styles_path(species: @alt_style.species.human_name)
|
||||||
|
%li= @alt_style.series_name
|
||||||
|
|
||||||
|
= image_tag @alt_style.preview_image_url, class: "alt-style-preview"
|
||||||
|
|
||||||
|
= form_with model: @alt_style, class: "alt-style-form" do |f|
|
||||||
|
- if @alt_style.errors.any?
|
||||||
|
%p
|
||||||
|
Could not save:
|
||||||
|
%ul.errors
|
||||||
|
- @alt_style.errors.each do |error|
|
||||||
|
%li= error.full_message
|
||||||
|
%fieldset
|
||||||
|
= f.label :series_name, "Series"
|
||||||
|
= f.text_field :series_name
|
||||||
|
= f.label :thumbnail_url, "Thumbnail"
|
||||||
|
.thumbnail-field
|
||||||
|
- if @alt_style.thumbnail_url?
|
||||||
|
= image_tag @alt_style.thumbnail_url
|
||||||
|
= f.url_field :thumbnail_url
|
||||||
|
= f.submit "Save changes"
|
||||||
|
|
||||||
|
- content_for :stylesheets do
|
||||||
|
= stylesheet_link_tag "application/breadcrumbs"
|
||||||
|
= page_stylesheet_link_tag "alt_styles/edit"
|
|
@ -35,7 +35,7 @@ OpenneoImpressItems::Application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :alt_styles, path: 'alt-styles', only: [:index]
|
resources :alt_styles, path: 'alt-styles', only: [:index]
|
||||||
end
|
end
|
||||||
resources :alt_styles, path: 'alt-styles', only: [:index]
|
resources :alt_styles, path: 'alt-styles', only: [:index, :edit, :update]
|
||||||
resources :swf_assets, path: 'swf-assets', only: [:show]
|
resources :swf_assets, path: 'swf-assets', only: [:show]
|
||||||
resources :pet_types, path: 'rainbow-pool', param: "name",
|
resources :pet_types, path: 'rainbow-pool', param: "name",
|
||||||
only: [:index, :show] do
|
only: [:index, :show] do
|
||||||
|
|
Loading…
Reference in a new issue