Skip to content

Commit

Permalink
added "Suggest new title" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ViditChitkara committed Jan 14, 2018
1 parent ac0f56f commit 142d6d2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,10 @@ def rsvp
@node.add_tag('rsvp:' + current_user.username, current_user)
redirect_to @node.path + '#comments'
end

def request_title_change
node = Node.find params[:id].to_i
node.update(title: params[:title])
redirect_to node.path + "#comments"
end
end
18 changes: 18 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,22 @@ def insert_extras(body)
def render_map(lat, lon, items)
render partial: 'map/leaflet', locals: { lat: lat, lon: lon, items: items }
end

def title_suggestion(body,user,nid,id)
body.gsub(/\{([^}]+)\}/) do |title_suggestion|
a = ActionController::Base.new()
is_creator = current_user.drupal_user == Node.find(nid).author
title = title_suggestion[1,title_suggestion.length-2] if title_suggestion.length>2
output = a.render_to_string(template: "notes/_title_suggestion",
layout: false,
locals: {
user: user,
nid: nid,
title: title,
is_creator: is_creator,
}
)
output
end
end
end
2 changes: 1 addition & 1 deletion app/views/notes/_comment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</script>

<div id="c<%= comment.cid %>show">
<p><%= raw sanitize(auto_link(RDiscount.new(comment.body).to_html)) %></p>
<p><%= raw sanitize (RDiscount.new(title_suggestion(comment.body, comment.drupal_user.name, comment.nid, comment.id)).to_html), attributes: %w(class style href data-method) %></p>
<% if comment.body.include?('?') %>
<p class="alert alert-info">Is this a question? <a href="/questions/new?title=<%= comment.body %>">Click here</a> to post it to the <a href="/questions">Questions page</a>.
</p>
Expand Down
6 changes: 6 additions & 0 deletions app/views/notes/_title_suggestion.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<blockquote>
<a href="/profile/<%= user %>"><%= user %></a> is suggesting an alternative title, "<%= title %>".
<% if is_creator %>
To accept this as a new title to your post, <a href="/request_title_change/<%= nid %>/<%= title %>" data-method='post'>click here</a>
<% end %>
</blockquote>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
post 'comment/create/token/:id.:format', to: 'comment#create_by_token'

get 'searches/test' => 'searches#test'
post '/request_title_change/:id/:title' => 'notes#request_title_change'

#Search RESTful endpoints
#constraints(subdomain: 'api') do
Expand Down

0 comments on commit 142d6d2

Please sign in to comment.