From 8d85ad3f40f85ed12af95844d4a48a43c08baeb4 Mon Sep 17 00:00:00 2001 From: stephanie-warmenhoven Date: Wed, 6 May 2020 16:57:34 -0700 Subject: [PATCH] [#1737] Toggle works for moment new and edit --- app/controllers/concerns/moments_concern.rb | 4 ++++ app/controllers/moments_controller.rb | 3 ++- app/helpers/moments_form_helper.rb | 6 ++--- app/models/moment.rb | 2 ++ app/views/moments/show.html.erb | 22 ++++++++++--------- config/locales/en.yml | 1 + ...add_resource_recommendations_to_moments.rb | 2 +- db/schema.rb | 2 +- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/controllers/concerns/moments_concern.rb b/app/controllers/concerns/moments_concern.rb index 152283c6de..824d2b8c14 100644 --- a/app/controllers/concerns/moments_concern.rb +++ b/app/controllers/concerns/moments_concern.rb @@ -11,6 +11,10 @@ def publishing? params[:publishing] == '1' end + def display? + params[:display] == true + end + def saving_as_draft? !publishing? end diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index 8ded8b5592..c14f540a8f 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -27,6 +27,7 @@ def show show_with_comments(@moment) @resources = ResourceRecommendations.new(@moment).call @resources_tags = resources_url_tags(@moment) + @moment.resource_recommendations? end # GET /moments/new @@ -99,7 +100,7 @@ def set_moment def moment_params params.require(:moment).permit(:name, :why, :fix, :comment, :draft, - :bookmarked, + :bookmarked, :resource_recommendations, category: [], mood: [], viewers: [], strategy: []) end diff --git a/app/helpers/moments_form_helper.rb b/app/helpers/moments_form_helper.rb index 8b908c08ba..8705e30478 100644 --- a/app/helpers/moments_form_helper.rb +++ b/app/helpers/moments_form_helper.rb @@ -88,10 +88,10 @@ def moment_bookmarked end def moment_display_resources - moment_input_props('comment', 'switch', 'comment.allow_comments') + moment_input_props('resource_recommendations', 'switch', 'moments.resource_recommendations') .merge(value: true, - uncheckedValue: false, checked: @moment.comment, - info: t('comment.hint'), dark: true) + uncheckedValue: false, checked: @moment.resource_recommendations, + dark: true) end def moment_form_inputs diff --git a/app/models/moment.rb b/app/models/moment.rb index 5e22e5ffbb..04df3f41ae 100644 --- a/app/models/moment.rb +++ b/app/models/moment.rb @@ -17,6 +17,7 @@ # secret_share_expires_at :datetime # published_at :datetime # bookmarked :boolean +# resource_recommendations :boolean # class Moment < ApplicationRecord @@ -48,6 +49,7 @@ class Moment < ApplicationRecord validates :why, length: { minimum: 1 } validates :secret_share_expires_at, presence: true, if: :secret_share_identifier? + validates :resource_recommendations, inclusion: [true, false] scope :published, -> { where.not(published_at: nil) } scope :recent, -> { order('created_at DESC') } diff --git a/app/views/moments/show.html.erb b/app/views/moments/show.html.erb index 7fda5e03a1..077ac1eae1 100644 --- a/app/views/moments/show.html.erb +++ b/app/views/moments/show.html.erb @@ -43,16 +43,18 @@ <% end %> -<% if @resources.any? %> -
-
<%= label_tag t('moments.show.resources') %>
- -
+<% if @moment.resource_recommendations? %> + <% if @resources.any? %> +
+
<%= label_tag t('moments.show.resources') %>
+ +
+ <% end %> <% end %> <% if @moment.owned_by?(current_user) && @moment.shared? %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d24af6f85..d951e07f2c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -328,6 +328,7 @@ en: tagged_moments: 'Tagged Moments' new: 'New Moment' bookmark: 'Bookmark this moment?' + resource_recommendations: 'Display Resource Recommendations?' secret_share: singular: 'Secret Share' expires_at: 'Expire at' diff --git a/db/migrate/20200506222107_add_resource_recommendations_to_moments.rb b/db/migrate/20200506222107_add_resource_recommendations_to_moments.rb index 61eafab779..668cd2bb1f 100644 --- a/db/migrate/20200506222107_add_resource_recommendations_to_moments.rb +++ b/db/migrate/20200506222107_add_resource_recommendations_to_moments.rb @@ -1,5 +1,5 @@ class AddResourceRecommendationsToMoments < ActiveRecord::Migration[5.2] def change - add_column :moments, :resource_recommendations, :boolean + add_column :moments, :resource_recommendations, :boolean, default: true end end diff --git a/db/schema.rb b/db/schema.rb index c476c6015c..af1f22fe3e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -145,7 +145,7 @@ t.datetime "secret_share_expires_at" t.datetime "published_at" t.boolean "bookmarked", default: false - t.boolean "resource_recommendations" + t.boolean "resource_recommendations", default: true t.index ["secret_share_identifier"], name: "index_moments_on_secret_share_identifier", unique: true t.index ["slug"], name: "index_moments_on_slug", unique: true end