Skip to content

Commit

Permalink
[ifmeorg#1737] Toggle works for moment new and edit
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Warmenhoven authored and AlineRibeiro committed May 7, 2020
1 parent 729d114 commit cd797ea
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 16 deletions.
4 changes: 4 additions & 0 deletions app/controllers/concerns/moments_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def publishing?
params[:publishing] == '1'
end

def display?
params[:display] == true
end

def saving_as_draft?
!publishing?
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/moments_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/moment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# secret_share_expires_at :datetime
# published_at :datetime
# bookmarked :boolean
# resource_recommendations :boolean
#

class Moment < ApplicationRecord
Expand Down Expand Up @@ -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') }
Expand Down
22 changes: 12 additions & 10 deletions app/views/moments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@
</div>
<% end %>
<% if @resources.any? %>
<div class="smallMarginTop">
<div class="label"><%= label_tag t('moments.show.resources') %></div>
<ul>
<% @resources.take(3).each do |item| %>
<li><%= link_to item['name'], item['link'] %></li>
<%end %>
<li><%= link_to "#{t('load_more')}...", "/resources?#{@resources_tags}" %></li>
</ul>
</div>
<% if @moment.resource_recommendations? %>
<% if @resources.any? %>
<div class="smallMarginTop">
<div class="label"><%= label_tag t('moments.show.resources') %></div>
<ul>
<% @resources.take(3).each do |item| %>
<li><%= link_to item['name'], item['link'] %></li>
<%end %>
<li><%= link_to "#{t('load_more')}...", "/resources?#{@resources_tags}" %></li>
</ul>
</div>
<% end %>
<% end %>
<% if @moment.owned_by?(current_user) && @moment.shared? %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd797ea

Please sign in to comment.