From c206236716d68087f92486a5f060d9863fdeb6b8 Mon Sep 17 00:00:00 2001 From: Chris Dinger Date: Wed, 16 Jun 2021 11:07:41 -0500 Subject: [PATCH 1/3] Alphabetize admin trial params This reduces git churn when we add/change parameters. [SF-112] --- app/controllers/admin/trials_controller.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/trials_controller.rb b/app/controllers/admin/trials_controller.rb index 2d8cff2..6210800 100644 --- a/app/controllers/admin/trials_controller.rb +++ b/app/controllers/admin/trials_controller.rb @@ -108,10 +108,24 @@ def update private def trial_params params.require(:trial).permit( - :simple_description, :visible, - :featured, :recruiting, :contact_override, :cancer_yn, :healthy_volunteers_override, - :contact_override_first_name, :contact_override_last_name, :pi_name, :pi_id, :recruitment_url, :contact_url_override, - :reviewed, :irb_number, site_ids: [], disease_site_ids: []) + :cancer_yn, + :contact_override, + :contact_override_first_name, + :contact_override_last_name, + :contact_url_override, + :featured, + :healthy_volunteers_override, + :irb_number, + :pi_id, + :pi_name, + :recruiting, + :recruitment_url, + :reviewed, + :simple_description, + :visible, + disease_site_ids: [], + site_ids: [] + ) end end From 407df7a1f63645b4618a69148c38abcf1d5c381f Mon Sep 17 00:00:00 2001 From: Chris Dinger Date: Wed, 16 Jun 2021 11:08:33 -0500 Subject: [PATCH 2/3] Add customizable study photos This allows admins to upload a custom study photo for a trial. This photo will replace the generic photo on the study show page. [SF-112] --- app/assets/stylesheets/pages/studies.css.scss | 4 ++++ app/controllers/admin/trials_controller.rb | 7 ++++++- app/controllers/studies_controller.rb | 1 + app/models/trial.rb | 2 ++ app/views/admin/trials/edit.html.erb | 14 ++++++++++++++ app/views/studies/show.html.erb | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/pages/studies.css.scss b/app/assets/stylesheets/pages/studies.css.scss index a239f00..3891ecb 100644 --- a/app/assets/stylesheets/pages/studies.css.scss +++ b/app/assets/stylesheets/pages/studies.css.scss @@ -250,3 +250,7 @@ .button-holder { margin-top: 1.5em; } + +.study-photo { + max-width: 500px; +} diff --git a/app/controllers/admin/trials_controller.rb b/app/controllers/admin/trials_controller.rb index 6210800..948415a 100644 --- a/app/controllers/admin/trials_controller.rb +++ b/app/controllers/admin/trials_controller.rb @@ -97,7 +97,11 @@ def edit def update @trial = Trial.find_by(system_id: params[:id]) - + + if params[:delete_photo] + @trial.photo.purge + end + if @trial.update(trial_params) redirect_to edit_admin_trial_path(params[:id]), flash: { success: 'Trial updated successfully' } else @@ -116,6 +120,7 @@ def trial_params :featured, :healthy_volunteers_override, :irb_number, + :photo, :pi_id, :pi_name, :recruiting, diff --git a/app/controllers/studies_controller.rb b/app/controllers/studies_controller.rb index ce898c6..dd05f28 100644 --- a/app/controllers/studies_controller.rb +++ b/app/controllers/studies_controller.rb @@ -20,6 +20,7 @@ def index def show @study = Trial.find(params[:id]) @attribute_settings = TrialAttributeSetting.where(system_info_id: @system_info.id) + @study_photo = @study.photo.attached? ? @study.photo : "flag.jpg" respond_to do |format| format.html do diff --git a/app/models/trial.rb b/app/models/trial.rb index de9f308..dd2ce27 100644 --- a/app/models/trial.rb +++ b/app/models/trial.rb @@ -30,6 +30,8 @@ class Trial < ApplicationRecord has_many :trial_mesh_terms + has_one_attached :photo + scope :recent_as, ->(duration){ where('updated_at > ?', Time.zone.today - duration ).order('updated_at DESC') } def self.import_from_file(file) diff --git a/app/views/admin/trials/edit.html.erb b/app/views/admin/trials/edit.html.erb index 57526d9..19c3199 100644 --- a/app/views/admin/trials/edit.html.erb +++ b/app/views/admin/trials/edit.html.erb @@ -62,6 +62,20 @@ <%= f.association :sites, label_method: :site_name, value_method: :id, input_html: { class: 'select2' } %> <%= f.association :disease_sites, label_method: :disease_site_label, value_method: :id, input_html: { class: 'select2' } %> + <%= f.input :photo, label: "Custom study image", input_html: { class: "form-control" } %> + + <% if @trial.photo.attached? %> +
+

Current image:

+ <%= image_tag @trial.photo, class: "img-fluid" %> + +
+ + +
+
+ <% end %> + <%= f.submit 'Update Trial', class: 'btn btn-school' %> <%= link_to 'Back to trials admin', admin_trials_path, class: 'btn btn-outline-secondary' %> <% end %> diff --git a/app/views/studies/show.html.erb b/app/views/studies/show.html.erb index f5a44dc..80243d6 100644 --- a/app/views/studies/show.html.erb +++ b/app/views/studies/show.html.erb @@ -4,7 +4,7 @@

<%= @study.brief_title %>

- <%= image_tag 'flag.jpg', class: 'bordered float-lg-right ml-4 mb-4' %> + <%= image_tag @study_photo, class: 'bordered float-lg-right ml-4 mb-4 study-photo' %> <%= render_attribute(@attribute_settings, 'overall_status', 'show', @study.overall_status) %> <%= render "description", study: @study, settings: @attribute_settings %> From 036695162145444111cfdbe1d3c50be9ea22ecf7 Mon Sep 17 00:00:00 2001 From: Chris Dinger Date: Wed, 16 Jun 2021 11:29:16 -0500 Subject: [PATCH 3/3] Add help text for custom study photos --- app/views/admin/trials/edit.html.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/admin/trials/edit.html.erb b/app/views/admin/trials/edit.html.erb index 19c3199..5883e94 100644 --- a/app/views/admin/trials/edit.html.erb +++ b/app/views/admin/trials/edit.html.erb @@ -63,6 +63,7 @@ <%= f.association :disease_sites, label_method: :disease_site_label, value_method: :id, input_html: { class: 'select2' } %> <%= f.input :photo, label: "Custom study image", input_html: { class: "form-control" } %> + Please upload web-optimized images with a maximum width of 500px. <% if @trial.photo.attached? %>
@@ -76,7 +77,9 @@
<% end %> - <%= f.submit 'Update Trial', class: 'btn btn-school' %> - <%= link_to 'Back to trials admin', admin_trials_path, class: 'btn btn-outline-secondary' %> +
+ <%= f.submit 'Update Trial', class: 'btn btn-school' %> + <%= link_to 'Back to trials admin', admin_trials_path, class: 'btn btn-outline-secondary' %> +
<% end %>
\ No newline at end of file