From 5178c1c3f91e0aba617fbba2cc2fffaa85216c92 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 2 Aug 2024 22:32:25 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=81=20Allow=20admins=20to=20upload=20m?= =?UTF-8?q?ultiple=20banners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit allows the admin to upload multiple banners to the homepage through the dashboard. The homepage will randomly select a banner and then cycle through the uploaded banners. Ref: - https://github.com/scientist-softserv/utk-hyku/issues/657 --- .../stylesheets/themes/dc_repository.scss | 10 +++++- app/helpers/hyrax_helper.rb | 4 +-- .../appearances/_banner_image_form.html.erb | 32 ++++++++++++------- .../dc_repository/layouts/homepage.html.erb | 23 +++++++++++-- spec/helpers/hyrax_helper_spec.rb | 6 ++-- .../admin/appearances/show.html.erb_spec.rb | 6 ++-- 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/themes/dc_repository.scss b/app/assets/stylesheets/themes/dc_repository.scss index 98cc23f0..22f7fe7a 100644 --- a/app/assets/stylesheets/themes/dc_repository.scss +++ b/app/assets/stylesheets/themes/dc_repository.scss @@ -234,9 +234,17 @@ body.dc_repository { } .background-container { - height: 90%; + height: 100%; z-index: 0; align-self: flex-end; + background-size: cover; + background-position: center; + opacity: 0; + transition: opacity 2s ease-in-out; + } + + .background-container.active { + opacity: 1; } .circle-container { diff --git a/app/helpers/hyrax_helper.rb b/app/helpers/hyrax_helper.rb index 1fa738b9..7131a5bf 100644 --- a/app/helpers/hyrax_helper.rb +++ b/app/helpers/hyrax_helper.rb @@ -23,8 +23,8 @@ def institution_name_full Site.institution_name_full || super end - def banner_image - Site.instance.banner_image? ? Site.instance.banner_image.url : super + def banner_images + Site.instance.banner_images.any? ? Site.instance.banner_images.map(&:url) : [banner_image] end def logo_image diff --git a/app/views/hyrax/admin/appearances/_banner_image_form.html.erb b/app/views/hyrax/admin/appearances/_banner_image_form.html.erb index c92d3b4c..6d904627 100644 --- a/app/views/hyrax/admin/appearances/_banner_image_form.html.erb +++ b/app/views/hyrax/admin/appearances/_banner_image_form.html.erb @@ -1,19 +1,29 @@ <%= simple_form_for @form, url: admin_appearance_path do |f| %>
- <% require_image = @form.banner_image? ? false : true %> - <%# Upload Banner Image %> - <%= f.input :banner_image, as: :file, wrapper: :vertical_file_input, required: require_image, hint: t('hyrax.admin.appearances.show.forms.banner_image.hint') %> + <% require_image = @form.banner_images.any? ? false : true %> + <%# Upload Banner Images %> + <%= f.input :banner_images, + as: :file, + wrapper: :vertical_file_input, + required: require_image, + hint: t('hyrax.admin.appearances.show.forms.banner_image.hint'), + input_html: { multiple: true, accept: 'image/*' } %> <%= f.input :banner_image_text, required: true, as: :text, label: 'Banner image alt text' %> - <%= image_tag @form.banner_image.url, class: "img-responsive" if @form.banner_image? %>
<% end %> -<% if @form.banner_image? %> - -<% end %> \ No newline at end of file + +<% if @form.banner_images.any? %> + <% @form.banner_images.each_with_index do |banner_image, index| %> + + <% end %> +<% end %> diff --git a/app/views/themes/dc_repository/layouts/homepage.html.erb b/app/views/themes/dc_repository/layouts/homepage.html.erb index cbd63fc2..d915e8c2 100644 --- a/app/views/themes/dc_repository/layouts/homepage.html.erb +++ b/app/views/themes/dc_repository/layouts/homepage.html.erb @@ -2,8 +2,9 @@ <% content_for(:navbar) do %>
- -
+ <% banner_images.shuffle.each_with_index do |image, index| %> +
+ <% end %> <% # OVERRIDE: Hyrax v3.4.1 - remove background-container-gradient %> <% # OVERRIDE: Hyrax v3.4.1 - remove site-title-container %> <% # OVERRIDE: Hyrax v3.4.1 - add divs and classes for custom styles %> @@ -45,3 +46,21 @@ <% end %> <%= render template: 'layouts/hyrax' %> + +<% if banner_images.size > 1 %> + +<% end %> diff --git a/spec/helpers/hyrax_helper_spec.rb b/spec/helpers/hyrax_helper_spec.rb index 8b9d6db9..fc0a934f 100644 --- a/spec/helpers/hyrax_helper_spec.rb +++ b/spec/helpers/hyrax_helper_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true RSpec.describe HyraxHelper, type: :helper do - describe "#banner_image" do + describe "#banner_images" do context "with uploaded banner image" do before do f = fixture_file_upload('/images/nypl-hydra-of-lerna.jpg', 'image/jpg') - Site.instance.update(banner_image: f) + Site.instance.update(banner_images: [f]) end it "returns the uploaded banner image" do - expect(helper.banner_image).to eq(Site.instance.banner_image.url) + expect(helper.banner_images.first).to eq(Site.instance.banner_images.first.url) end end diff --git a/spec/views/hyrax/admin/appearances/show.html.erb_spec.rb b/spec/views/hyrax/admin/appearances/show.html.erb_spec.rb index e569df8d..995acb83 100644 --- a/spec/views/hyrax/admin/appearances/show.html.erb_spec.rb +++ b/spec/views/hyrax/admin/appearances/show.html.erb_spec.rb @@ -43,8 +43,10 @@ # logo tab assert_select "input#admin_appearance_logo_image[name=?]", "admin_appearance[logo_image]" # banner image tab - assert_select "input#admin_appearance_banner_image[name=?]", "admin_appearance[banner_image]" - assert_select "input#admin_appearance_banner_image[type=?]", "file" + assert_select "input#admin_appearance_banner_images[name=?]", "admin_appearance[banner_images][]" + assert_select "input#admin_appearance_banner_images[type=?]", "file" + assert_select "input#admin_appearance_banner_images[multiple=?]", "multiple" + assert_select "input#admin_appearance_banner_images[accept=?]", "image/*" # directory image assert_select "input#admin_appearance_directory_image[name=?]", "admin_appearance[directory_image]" # default collection image