From 142d6d212f873b4ed0106c706f7a003e66d5389d Mon Sep 17 00:00:00 2001 From: ViditChitkara Date: Sun, 14 Jan 2018 01:53:01 +0530 Subject: [PATCH] added "Suggest new title" feature closes #919 --- app/controllers/notes_controller.rb | 6 ++++++ app/helpers/application_helper.rb | 18 ++++++++++++++++++ app/views/notes/_comment.html.erb | 2 +- app/views/notes/_title_suggestion.html.erb | 6 ++++++ config/routes.rb | 1 + 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/views/notes/_title_suggestion.html.erb diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 3466e03c6cf..cc9a3bd7437 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2eb0e8cc541..ad325ed3d9d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/notes/_comment.html.erb b/app/views/notes/_comment.html.erb index 3fd38dd33d1..f694367d8de 100644 --- a/app/views/notes/_comment.html.erb +++ b/app/views/notes/_comment.html.erb @@ -64,7 +64,7 @@
-

<%= raw sanitize(auto_link(RDiscount.new(comment.body).to_html)) %>

+

<%= 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) %>

<% if comment.body.include?('?') %>

Is this a question? Click here to post it to the Questions page.

diff --git a/app/views/notes/_title_suggestion.html.erb b/app/views/notes/_title_suggestion.html.erb new file mode 100644 index 00000000000..2f69f88c0d9 --- /dev/null +++ b/app/views/notes/_title_suggestion.html.erb @@ -0,0 +1,6 @@ +
+ <%= user %> is suggesting an alternative title, "<%= title %>". + <% if is_creator %> + To accept this as a new title to your post, click here + <% end %> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8e94aeccb20..71807303f2c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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