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

wip: Add alternate text for lead images #8106

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,16 @@ def edit
else
if @node.main_image
@main_image = @node.main_image.path(:default)
@node.main_image.photo_text = params[:photo_text]
@node.save!
elsif params[:main_image] && Image.find_by(id: params[:main_image])
@main_image = Image.find_by(id: params[:main_image]).path
Image.find_by(id: params[:main_image]).photo_text = params[:photo_text]
Image.find_by(id: params[:main_image]).save!
elsif @image
@main_image = @image.path(:default)
@image.photo_text = params[:photo_text]
@image.save!
end
flash.now[:notice] = "This is the new rich editor. For the legacy editor, <a href='/notes/edit/#{@node.id}?#{request.env['QUERY_STRING']}&legacy=true'>click here</a>."
render template: 'editor/rich'
Expand Down
6 changes: 6 additions & 0 deletions app/views/editor/rich.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
>Select an optional main image for your post.</span
>
</p>
<p>
<input class="form-control input-lg" type="text" id="alt-text" placeholder="Add alternate text for image" value="<% if @node && @node.main_image.photo_text %><%= @node.main_image.photo_text %><% else %><%= params[:photo_text] %><% end %>"/>
</p>
<p>
<input class="form-control input-lg" type="text" id="alt-text" placeholder="Add alternate text for image" value="<% if @node && @node.main_image.photo_text %><%= @node.main_image.photo_text %><% else %><%= params[:photo_text] %><% end %>"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tlazypanda found that the issue is because some notes do not have images hence the nil error..we can use a safe navigator to cater for the nodes without 'main_images' like so

input class="form-control input-lg" type="text" id="alt-text" placeholder="Add alternate text for image" value="<% if @node && @node&.main_image&.photo_text %><%= @node.main_image.photo_text %><% else %><%= params[:photo_text] %><% end %>"/>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Tlazypanda I will prioritize this coming week so we can collaborate and have it merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow this is v cool! can we see a screenshot at some point? Thanks!!

</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<% if @node.main_image %>
<a class="main-image" style="max-width:100%;width:800px;" href="<%= @node.main_image.path(:original) %>">
<%= image_tag(@node.main_image.path(:large), class:"rounded d-none d-lg-inline", style:'max-height:600px;max-width:100%;') %>
<%= image_tag(@node.main_image.path(:large), class:"rounded d-none d-lg-inline", style:'max-height:600px;max-width:100%;', alt:@node.main_image.photo_text) %>
<%= image_tag(@node.main_image.path(:large), class:"rounded d-lg-none", style:'width:100%;') %>
</a>
<!--<div class="expand"><a onClick="$('.main-image').toggleClass('compressed');"><i class="fa fa-angle-down"></i></a></div>-->
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200629163837_add_photo_text_to_images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPhotoTextToImages < ActiveRecord::Migration[5.2]
def change
add_column :images, :photo_text, :string
end
end