Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hardcoded homepage content #1008

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
11 changes: 10 additions & 1 deletion app/admin/homepage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
config.sort_order = 'published_desc'

# Customizing the action items (buttons) on the show page
action_item :publish, priority: 0, only: :show do
action_item :publish, priority: 1, only: :show do
publish_action_str = resource.published? ? 'Unpublish' : 'Publish'
link_to publish_action_str, publish_admin_homepage_path(resource), method: :post
end
action_item :preview, priority: 0, only: :show do
link_to "Preview", preview_admin_homepage_path(resource), method: :get
end

member_action :publish, priority: 0, method: :post do
title = resource.internal_title.present? ? resource.internal_title : "Homepage #{resource.id}"
Expand All @@ -51,6 +54,11 @@
redirect_back fallback_location: root_path, notice: message
end

member_action :preview, method: :get do
homepage_id = resource.id
redirect_to "/homepages/#{homepage_id}/preview"
end

index do
id_column
column :internal_title
Expand All @@ -59,6 +67,7 @@
actions do |homepage|
publish_action_str = homepage.published ? "Unpublish" : "Publish"
item publish_action_str, publish_admin_homepage_path(homepage), method: :post
item "Preview", preview_admin_homepage_path(homepage), method: :get
end
end

Expand Down
32 changes: 29 additions & 3 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,35 @@ def index
@homepage = Homepage.where(published: true)&.first
if @homepage
current_features = @homepage&.homepage_features
@section_one_features = current_features&.where(section_id: 1).first(3)
@section_two_features = current_features&.where(section_id: 2).first(3)
@section_three_features = current_features&.where(section_id: 3).first(3)
@section_one_features = current_features&.where(section_id: 1)&.first(3)
@section_two_features = current_features&.where(section_id: 2)&.first(3)
@section_three_features = current_features&.where(section_id: 3)&.first(3)
end
end

def preview
if current_user&.has_role?(:admin)
@@dropdown_categories = nil
@dropdown_communities = nil
@homepage = nil
begin
@homepage = Homepage.find(params[:id])
rescue ActiveRecord::RecordNotFound
warning = "That homepage does not exist"
flash[:warning] = warning
redirect_to admin_homepages_path, warning: warning
return
end
current_features = @homepage&.homepage_features
if current_features
@section_one_features = current_features&.where(section_id: 1)&.first(3)
@section_two_features = current_features&.where(section_id: 2)&.first(3)
@section_three_features = current_features&.where(section_id: 3)&.first(3)
end
flash.now[:notice] = "This is a preview of unpublished content"
render 'index'
else
redirect_to root_path
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def private_path? # https://github.com/digital-analytics-program/gov-wide-code#a
params["controller"] == "admin" || # all admin pages
(params["controller"] == "page" && !@page&.published?) || # unpublished PageBuilder pages
(params["controller"] == "practices" && !["show", "index", "search"].include?(params["action"])) || # practice editor pages
(params["controller"] == "practices" && params["action"] == "show" && [email protected]_public) # internal or unpublished practices
(params["controller"] == "practices" && params["action"] == "show" && [email protected]_public) || # internal or unpublished practices
params["controller"] == "home" && params["action"] == "preview" # homepage previews
end
end
2 changes: 1 addition & 1 deletion app/models/homepage_feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def image_s3_presigned_url(style = nil)
end

def self.column_size(item_count = 3)
if item_count >= 3
if item_count == nil || item_count >= 3
'three-column-layout'
else # update this later to deal with incoming designs
'two-column-layout'
Expand Down
146 changes: 33 additions & 113 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
style="display: none;"
>

<% if @dropdown_practices.present? && @dropdown_categories.present? && @dropdown_communities.present? %>
<div class="dropdown-content margin-4">
<div class="result-section" data-type="innovation">
<h3 class="search-header usa-prose-h3 margin-bottom-0">Innovations</h3>
Expand Down Expand Up @@ -81,6 +82,7 @@
<a class="browse-all-link text-bold" href="<%= search_path %>?all_communities=true">Browse all Community Innovations</a>
</div>
</div>
<% end %>
</div>
<button id="dm-homepage-search-button" class="usa-button height-5 margin-right-0" type="submit">
<span class="usa-search__submit-text">Search</span>
Expand All @@ -90,128 +92,46 @@
</section>
<div class="grid-container">
<section id="homepage-section-1" class="homepage-section">
<% if @homepage.blank? %>
<h2 class="section-title">Featured Innovations</h2>
<div class="grid-row grid-gap">
<div id="section-1-feature-1" class="homepage-feature three-column-layout">
<%= image_tag("homepage/innovation-CREW.jpg", alt: "Two people preparing vegetables at a cutting board",class: "homepage-featured-image") %>
<h3 id="section-1-feature-1-title" class="feature-title">CREW: Carbohydrate Reduction Empowering Wellness (formerly Therapeutic Carbohydrate Reduction (TCR) Aspire)</h3>
<p class="usa-prose-body margin-bottom-5">
CREW is a 16-week lifestyle program that uses goal setting and whole health coaching to support Veterans with Type 2 Diabetes and other metabolic health conditions.
</p>
<a href="/innovations/therapeutic-carbohydrate-restricted-tcr-aspire" aria-describedby="section-1-feature-1-title" class="usa-link">View Innovation</a>
</div>
<div id="section-1-feature-2" class="homepage-feature three-column-layout">
<%= image_tag("homepage/innovation-PRIDE.jpg", alt: "Rainbow flag and trans flag patterned identification tags encircled by a stethoscope", class: "homepage-featured-image") %>
<h3 id="section-1-feature-2-title" class="feature-title">PRIDE In All Who Served</h3>
<p class="usa-prose-body margin-bottom-5">
PRIDE In All Who Served is a health promotion group for LGBTQIA+ Veterans that fosters support and improves health literacy. Veterans have praised the program for significantly enhancing their well-being and communication with healthcare providers.
</p>
<a href="/innovations/pride-in-all-who-served-reducing-healthcare-disparities-for-lgbt-veterans" aria-describedby="section-1-feature-2-title" class="usa-link">View Innovation</a>
</div>
<div id="section-1-feature-3" class="homepage-feature three-column-layout">
<%= image_tag("homepage/innovation-Close-to-Me.jpg", alt: "Doctor and patient discuss cancer test results", class: "homepage-featured-image") %>
<h3 id="section-1-feature-3-title" class="feature-title">Close to Me Cancer Care</h3>
<p class="usa-prose-body margin-bottom-5">
Close to Me Cancer Care, sponsored by the VHA National Oncology Program Office, provides anti-cancer therapy services at Community Based Outpatients Clinics (CBOCs) to increase access points to care for Veterans.
</p>
<a href="/innovations/close-to-me-infusion-service" aria-describedby="section-1-feature-3-title" class="usa-link">View Innovation</a>
</div>
</div>
<% else %>
<h2 class="section-title"><%= @homepage&.section_title_one %> </h2>
<div class="grid-row grid-gap">
<% column_classes = HomepageFeature.column_size(@section_one_features.count) %>
<% @section_one_features.each_with_index do |hf, index| %>
<div id="section-1-feature-<%= index + 1 %>" class="homepage-feature <%= column_classes %>">
<%= image_tag "#{hf&.image_s3_presigned_url}", alt: hf&.image_alt_text, class: 'homepage-featured-image' if hf.featured_image.exists? %>
<%= tag.h3 hf.title, id: "section-1-feature-#{index + 1}-title", class: 'feature-title' if hf.title.present? %>
<%= tag.p hf.description, class: 'usa-prose-body margin-bottom-5' if hf.description.present? %>
<%= link_to hf&.cta_text, hf.url, class: 'usa-link', 'aria-describedby': "section-1-feature-#{index + 1}-title" if hf.url.present? %>
</div>
<% end %>
<h2 class="section-title"><%= @homepage&.section_title_one %> </h2>
<div class="grid-row grid-gap">
<% column_classes = HomepageFeature.column_size(@section_one_features&.count) %>
<% @section_one_features&.each_with_index do |hf, index| %>
<div id="section-1-feature-<%= index + 1 %>" class="homepage-feature <%= column_classes %>">
<%= image_tag "#{hf&.image_s3_presigned_url}", alt: hf&.image_alt_text, class: 'homepage-featured-image' if hf.featured_image.exists? %>
<%= tag.h3 hf.title, id: "section-1-feature-#{index + 1}-title", class: 'feature-title' if hf.title.present? %>
<%= tag.p hf.description, class: 'usa-prose-body margin-bottom-5' if hf.description.present? %>
<%= link_to hf&.cta_text, hf.url, class: 'usa-link', 'aria-describedby': "section-1-feature-#{index + 1}-title" if hf.url.present? %>
</div>
<% end %>
</div>
</section>
<section id="homepage-section-2" class="homepage-section">
<% if @homepage.blank? %>
<h2 class="section-title">Trending Tags</h2>
<div class="grid-row grid-gap">
<div id="section-2-feature-1" class="homepage-feature three-column-layout">
<%= image_tag("homepage/tag-suicide-prevention.jpg", alt: "VA Secretary Denis McDonough greeting a volunteer at a VA clinic", class: "homepage-featured-image") %>
<h3 id="section-2-feature-1-title" class="feature-title">Suicide Prevention</h3>
<p class="usa-prose-body margin-bottom-5">
Discover our range of innovations focused on suicide prevention, ensuring Veterans receive the essential mental health care they deserve.
</p>
<a href="/search?category=Suicide%20Prevention" aria-describedby="section-2-feature-1-title" class="usa-link">Learn More</a>
</div>
<div id="section-2-feature-2" class="homepage-feature three-column-layout">
<%= image_tag("homepage/tag-homeheatlh.jpg", alt: "a miniature house in glove hands of a medical staff member", class: "homepage-featured-image") %>
<h3 id="section-2-feature-2-title" class="feature-title">Home Health</h3>
<p class="usa-prose-body margin-bottom-5">
Explore cutting-edge home health innovations, providing Veterans with personalized and accessible care in the comfort of their own homes
</p>
<a href="/search?category=Home%20Health" aria-describedby="section-2-feature-2-title" class="usa-link">Learn More</a>
</div>
<div id="section-2-feature-3" class="homepage-feature three-column-layout">
<%= image_tag("homepage/tag-specialty-care.jpg", alt: "a man attached to a blood pressure monitor", class: "homepage-featured-image") %>
<h3 id="section-2-feature-3-title" class="feature-title">Specialty Care</h3>
<p class="usa-prose-body margin-bottom-5">
Access the latest innovations in specialty care, dedicated to providing advanced medical treatments and personalized care tailored to Veterans' unique health needs.
</p>
<a href="/search?category=Specialty%20Care" aria-describedby="section-2-feature-3-title" class="usa-link">Learn More</a>
<h2 class="section-title"><%= @homepage&.section_title_two %></h2>
<div class="grid-row grid-gap">
<% column_classes = HomepageFeature.column_size(@section_two_features&.count) %>
<% @section_two_features&.each_with_index do |hf, index| %>
<div id="section-2-feature-<%= index + 1 %>" class="homepage-feature <%= column_classes %>">
<%= image_tag "#{hf&.image_s3_presigned_url}", alt: hf&.image_alt_text, class: 'homepage-featured-image' if hf.featured_image.exists? %>
<%= tag.h3 hf.title, id: "section-2-feature-#{index + 1}-title", class: 'feature-title' if hf.title.present? %>
<%= tag.p hf.description, class: 'usa-prose-body margin-bottom-5' if hf.description.present? %>
<%= link_to hf&.cta_text, hf.url, class: 'usa-link', 'aria-describedby': "section-2-feature-#{index + 1}-title" if hf.url.present? %>
</div>
</div>
<% else %>
<h2 class="section-title"><%= @homepage&.section_title_two %></h2>
<div class="grid-row grid-gap">
<% column_classes = HomepageFeature.column_size(@section_two_features.count) %>
<% @section_two_features.each_with_index do |hf, index| %>
<div id="section-2-feature-<%= index + 1 %>" class="homepage-feature <%= column_classes %>">
<%= image_tag "#{hf&.image_s3_presigned_url}", alt: hf&.image_alt_text, class: 'homepage-featured-image' if hf.featured_image.exists? %>
<%= tag.h3 hf.title, id: "section-2-feature-#{index + 1}-title", class: 'feature-title' if hf.title.present? %>
<%= tag.p hf.description, class: 'usa-prose-body margin-bottom-5' if hf.description.present? %>
<%= link_to hf&.cta_text, hf.url, class: 'usa-link', 'aria-describedby': "section-2-feature-#{index + 1}-title" if hf.url.present? %>
</div>
<% end %>
</div>
<% end %>
<% end %>
</div>
</section>
<section id="homepage-section-3" class="homepage-section">
<% if @homepage.blank? %>
<h2 class="section-title">Innovation Communities</h2>
<div class="grid-row grid-gap">
<div id="section-3-feature-1" class="homepage-feature two-column-layout">
<%= image_tag("homepage/community-age-friendly.jpg", alt: 'doctor and patient looking at a tablet together', class: "homepage-featured-image") %>
<h3 id="section-3-feature-1-title" class="feature-title">Age-Friendly</h3>
<p class="usa-prose-body margin-bottom-5">
Reimagining the landscape of healthcare for our aging Veteran population.
</p>
<%= link_to 'View Community', '/communities/age-friendly', class: 'usa-link', 'aria-describedby': 'section-3-feature-1-title' %>
</div>
<div id="section-3-feature-2" class="homepage-feature two-column-layout">
<%= image_tag("homepage/community-vr.jpg", alt: "a person wearing a VR headset, weraing a mask, and a Veterans Affairs lanyard", class: "homepage-featured-image") %>
<h3 id="section-3-feature-2-title" class="feature-title">VA Immersive</h3>
<p class="usa-prose-body margin-bottom-5">
We help improve care delivery and experiences by leveraging immersive technology for falls risk assessment, neurological risk assessment, pain management, anxiety, addiction recovery, physical therapy, recreation therapy, PTSD, employee education, and more.
</p>
<%= link_to 'View Community', '/communities/va-immersive', class: 'usa-link', 'aria-describedby': 'section-3-feature-2-title' %>
</div>
</div>
<% else %>
<h2 class="section-title"><%= @homepage&.section_title_three %></h2>
<div class="grid-row grid-gap">
<% column_classes = HomepageFeature.column_size(@section_three_features.count) %>
<% @section_three_features.each_with_index do |hf, index| %>
<div id="section-3-feature-<%= index + 1 %>" class="homepage-feature <%= column_classes %>">
<%= image_tag "#{hf&.image_s3_presigned_url}", alt: hf&.image_alt_text, class: 'homepage-featured-image' if hf.featured_image.exists? %>
<%= tag.h3 hf.title, id: "section-3-feature-#{index + 1}-title", class: 'feature-title' if hf.title.present? %>
<%= tag.p hf.description, class: 'usa-prose-body margin-bottom-5' if hf.description.present? %>
<%= link_to hf&.cta_text, hf.url, class: 'usa-link', 'aria-describedby': "section-3-feature-#{index + 1}-title" if hf.url.present? %>
</div>
<% end %>
<h2 class="section-title"><%= @homepage&.section_title_three %></h2>
<div class="grid-row grid-gap">
<% column_classes = HomepageFeature.column_size(@section_three_features&.count) %>
<% @section_three_features&.each_with_index do |hf, index| %>
<div id="section-3-feature-<%= index + 1 %>" class="homepage-feature <%= column_classes %>">
<%= image_tag "#{hf&.image_s3_presigned_url}", alt: hf&.image_alt_text, class: 'homepage-featured-image' if hf.featured_image.exists? %>
<%= tag.h3 hf.title, id: "section-3-feature-#{index + 1}-title", class: 'feature-title' if hf.title.present? %>
<%= tag.p hf.description, class: 'usa-prose-body margin-bottom-5' if hf.description.present? %>
<%= link_to hf&.cta_text, hf.url, class: 'usa-link', 'aria-describedby': "section-3-feature-#{index + 1}-title" if hf.url.present? %>
</div>
<% end %>
</div>
</section>
<section id="feature-nominate-innovation" class="">
<div class="grid-row grid-gap">
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
end

root 'home#index'
get '/homepages/:id/preview', controller: 'home', action: 'preview'
resources :clinical_resource_hubs, path: :crh, param: :number
get '/practices' => 'practices#index'
get '/partners' => 'practice_partners#index'
Expand Down
26 changes: 26 additions & 0 deletions spec/features/admin/admin_homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@
end
end

describe 'Preview' do
it 'lets admins preview homepage' do
Homepage.create(internal_title: 'current', published: true, section_title_one: 'Old homepage')
Homepage.create(internal_title: 'next month', published: false, section_title_one: 'Next month homepage')
visit root_path
expect(page).to have_content('Old homepage')
visit admin_homepages_path
within('#homepage_2') do
expect(page).to have_content('Publish')
click_link('Preview')
end
expect(page).to have_current_path('/homepages/2/preview')
expect(page).to have_content('This is a preview of unpublished content')
expect(page).to have_content('Next month homepage')
end

it 'hides previews from non-admins' do
@non_admin = create(:user, email: '[email protected]')
login_as(@non_admin, scope: :user, run_callbacks: false)
Homepage.create(internal_title: 'next month', published: false, section_title_one: 'Next month homepage')
visit '/homepages/1/preview'
expect(page).to have_current_path(root_path)
end

end

def save_page
find('input[type="submit"]', match: :first).click
end
Expand Down
Loading