diff --git a/app/assets/stylesheets/_layout.sass b/app/assets/stylesheets/_layout.sass index 4215b3f4..f67dce5b 100644 --- a/app/assets/stylesheets/_layout.sass +++ b/app/assets/stylesheets/_layout.sass @@ -74,7 +74,7 @@ $container_width: 800px input, button, select, label 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 background: #fff border: 1px solid $input-border-color diff --git a/app/assets/stylesheets/alt_styles/edit.sass b/app/assets/stylesheets/alt_styles/edit.sass new file mode 100644 index 00000000..0a138cf2 --- /dev/null +++ b/app/assets/stylesheets/alt_styles/edit.sass @@ -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 diff --git a/app/controllers/alt_styles_controller.rb b/app/controllers/alt_styles_controller.rb index d9f49495..5d75d12a 100644 --- a/app/controllers/alt_styles_controller.rb +++ b/app/controllers/alt_styles_controller.rb @@ -1,4 +1,6 @@ class AltStylesController < ApplicationController + before_action :support_staff_only, except: [:index] + def index @all_alt_styles = AltStyle.includes(:species, :color). order(:species_id, :color_id) @@ -39,8 +41,27 @@ class AltStylesController < ApplicationController 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 + def alt_style_params + params.require(:alt_style).permit(:series_name, :thumbnail_url) + end + def find_color if params[:color] Color.find_by(name: params[:color]) diff --git a/app/helpers/alt_styles_helper.rb b/app/helpers/alt_styles_helper.rb new file mode 100644 index 00000000..e5aa2600 --- /dev/null +++ b/app/helpers/alt_styles_helper.rb @@ -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 diff --git a/app/models/alt_style.rb b/app/models/alt_style.rb index 703b1501..da53243d 100644 --- a/app/models/alt_style.rb +++ b/app/models/alt_style.rb @@ -9,6 +9,8 @@ class AltStyle < ApplicationRecord has_many :contributions, as: :contributed, inverse_of: :contributed 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_thumbnail_url @@ -42,6 +44,10 @@ class AltStyle < ApplicationRecord "#{series_name} #{color.human_name}" end + def full_name + "#{series_name} #{name}" + end + def preview_image_url swf_asset = swf_assets.first return nil if swf_asset.nil? diff --git a/app/views/alt_styles/_alt_style.html.haml b/app/views/alt_styles/_alt_style.html.haml index 4fef2246..518a6a1d 100644 --- a/app/views/alt_styles/_alt_style.html.haml +++ b/app/views/alt_styles/_alt_style.html.haml @@ -1,4 +1,4 @@ %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" .name= alt_style.name \ No newline at end of file diff --git a/app/views/alt_styles/edit.html.haml b/app/views/alt_styles/edit.html.haml new file mode 100644 index 00000000..aa6e09b7 --- /dev/null +++ b/app/views/alt_styles/edit.html.haml @@ -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" diff --git a/config/routes.rb b/config/routes.rb index 9c6e8c3a..466ddd71 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,7 +35,7 @@ OpenneoImpressItems::Application.routes.draw do end resources :alt_styles, path: 'alt-styles', only: [:index] 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 :pet_types, path: 'rainbow-pool', param: "name", only: [:index, :show] do