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

added "Suggest new title" feature #2000

Merged
merged 10 commits into from
Jan 25, 2018

Conversation

ViditChitkara
Copy link
Member

@ViditChitkara ViditChitkara commented Jan 13, 2018

closes #919

Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks!

  • all tests pass -- rake test:all
  • code is in uniquely-named feature branch, and has been rebased on top of latest master (especially if you've been asked to make additional changes)
  • pull request is descriptively named with #number reference back to original issue

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/wiki/contributing-to-public-lab-software

We have a loose schedule of reviewing and pulling in changes every Tuesday and Friday, and publishing changes on Fridays. Please alert developers on plots-dev@googlegroups.com when your request is ready or if you need assistance.

Thanks!

@ViditChitkara
Copy link
Member Author

@jywarren I have a raw idea about this. Just like inline power tags there could be another syntax which could create the specified template for title suggestion (e.g {New title}).
Does this make sense?

@PublicLabBot
Copy link

PublicLabBot commented Jan 13, 2018

1 Message
📖 @ViditChitkara Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.

Generated by 🚫 Danger

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

This is a pretty interesting approach -- happy to help refine it and get it ready! Thanks!

config/routes.rb Outdated
@@ -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'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could simplify this and also not put the title itself in the path, as it may contain punctuation? It could be using ?title=____ instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we could do the same with id!! Also we'd need to have a check in the request_title_update method, since the route could easily be manipulated to change the id or title so an authorisation check is a must at the back-end.

@@ -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>
Copy link
Member

Choose a reason for hiding this comment

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

This isi getting quite long; any way to simplify via formatting?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe pass the comment object to title_suggestion method would be better rather than breaking it up into body, name, etc. 'Attributes' require href and data-method for the time being perhaps. I'll try something to shorten this!!,

@ViditChitkara ViditChitkara force-pushed the suggest-new-title-feature branch from 016d34f to 06b292b Compare January 14, 2018 14:35
@jywarren
Copy link
Member

PR #2000 -- cool! :-)

@@ -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)).to_html), attributes: %w(class style href data-method src) %></p>
Copy link
Member

Choose a reason for hiding this comment

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

This starts to get quite long. See how we've batched these in this code?

https://github.com/ViditChitkara/plots2/blob/624aa873794f0d904fb44e0772a2fddf51309d5d/app/helpers/application_helper.rb#L30-L42

What do you think about making this more readable with an additional helper somehow, rather than a long in-line code block?

Looking good though!

Copy link
Member Author

Choose a reason for hiding this comment

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

Some helper method like:- comment_body
It could look like this:-

def comment body(comment)
  RDiscount.new(title_suggestion(comment)).to_html), attributes: %w(class style href data-method src
end

Then we could use it in line 67 as:-

<p><%= raw sanitize(auto_link(RDiscount.new(comment_body(comment)).to_html)) %></p>

Will this be good?

@@ -0,0 +1,6 @@
<blockquote>
<a href="/profile/<%= user %>"><%= user %></a> is suggesting an alternative title, "<%= title %>".
Copy link
Member

Choose a reason for hiding this comment

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

Can we switch to 2-space indents here? sorry to be particular :-)

Also, can you share a screenshot of what this looks like?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I missed that!! I'll do!!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'll share the screenshots!

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

This is a complex feature and I love your implementation. Made a few requests, and perhaps a single line comment like this above some of your method definitions could help make it clear how this new function works/

# explanation
def method_name
  ...
end

config/routes.rb Outdated
@@ -6,6 +6,7 @@
post 'comment/create/token/:id.:format', to: 'comment#create_by_token'

get 'searches/test' => 'searches#test'
post '/reset-title' => 'notes#request_title_change'
Copy link
Member

Choose a reason for hiding this comment

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

Does this actually change the title, or does it request a title change? I think it actually changes the title. Maybe we could do like /node/update/title or something more descriptive? Same for the method name request_title_change -- could that be update_title to be more accurate, or do i misunderstand?

Copy link
Member Author

Choose a reason for hiding this comment

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

This actually changes the title. Yes, that's a cool idea!! I'll change the route name and method name to the above.

@ViditChitkara ViditChitkara force-pushed the suggest-new-title-feature branch from 5193310 to 1e15361 Compare January 16, 2018 20:45
@ViditChitkara
Copy link
Member Author

tsug-1
tsug-2
@jywarren Here are the screenshots of the feature

@jywarren
Copy link
Member

aha - cool. Do you think perhaps it should be something like this, though, so we can expand out for other types of inline comment features in the future?

[propose:title:_____________]

@ViditChitkara
Copy link
Member Author

This syntax looks cool indeed!! I'll do the changes

@jywarren
Copy link
Member

Or:

[propose:title]This is a new title[/propose]

which do you think makes more sense?

@ViditChitkara ViditChitkara force-pushed the suggest-new-title-feature branch from 1e15361 to 8876e12 Compare January 17, 2018 15:14
@ViditChitkara
Copy link
Member Author

@jywarren I have made the changes!! May I write tests if the design seems to be finalised?

@jywarren
Copy link
Member

Let's see -- one thing is, perhaps we can use an <div class="alert alert-warning"></div> instead of a blockquote? That'll seem more like an official feature.

Also, just to think through this, what if you press this twice? It'll just continually replace the title, right? No possibility of weird behavior I can think of... just want to be thorough. OK, let's go for tests then!

@ViditChitkara
Copy link
Member Author

ViditChitkara commented Jan 17, 2018

Yes, it would just replace the title continuously, I have tried that too and no weird behaviours were seen. I'd like to try and replace the block quote with something mentioned above.

@ViditChitkara
Copy link
Member Author

Duh! That was closed by mistake! I'll write the tests!

@ViditChitkara
Copy link
Member Author

ViditChitkara commented Jan 17, 2018

@jywarren written the tests and also replaced the blockquotes with <div class="alert alert-warning"></div>.
This actually looks nice with the alert panel!! Thanks for the suggestion.
Could you please see if this is good to go now?

@jywarren
Copy link
Member

Wow, very cool! I think we are ready to go; do you think we should try this out once merged, then think about a user interface as a follow-up? We could for example add a button like the "promote to answer" button on comments -- which could use a JavaScript prompt() to ask for the proposed title.

The button could appear as it does in this change by @Gauravano -- https://github.com/publiclab/plots2/pull/2001/files

What do you think, shall we merge this in, test it out, then think about UI as a follow-up?

@ViditChitkara
Copy link
Member Author

ViditChitkara commented Jan 18, 2018 via email

@ViditChitkara
Copy link
Member Author

@jywarren I was just thinking of another way of doing this! We would have a button in the comments section (which would say something like 'propose title'). When clicked, it would append the template for title suggestion like [propose:title]Propose your title here[/propose] in the comment editor.
This could be useful if a user wants to propose more than one title in a single comment. Then there would be no need of the prompt.
Your thoughts?

@jywarren
Copy link
Member

jywarren commented Jan 19, 2018 via email

@ViditChitkara
Copy link
Member Author

Cool!! Do you think we should merge this? I will create a fto issue for the left over part as explained above!!
Thanks.

@ViditChitkara
Copy link
Member Author

@jywarren please see if there are any more required changes to it.

@jywarren
Copy link
Member

Hi, I guess i'd like to know if there's a way to test the conversion of the [propose:title] tags in the helper code... what do you think? if it's too complex, we can just merge this, but it'd be nice to have a test for that too, no?

Sorry to be delaying on this a bit, it's a great feature :-) 👍

@ViditChitkara
Copy link
Member Author

That's interesting!! I'll do add the tests!!

@ViditChitkara
Copy link
Member Author

@jywarren the tests are written!! Please have a look!

@jywarren
Copy link
Member

Wow, this is so cool! 🎉

Merging this! I hope we can publish tomorrow, we'll see!

@jywarren
Copy link
Member

Hi, @ViditChitkara -- just noting one follow-up issue -- i see an error:

/app/app/helpers/application_helper.rb:55: warning: regular expression has ']' without escape: /\[propose:title](.*?)\[\/propose]/
/app/app/helpers/application_helper.rb:55: warning: regular expression has ']' without escape: /\[propose:title](.*?)\[\/propose]/

Looks like maybe we need to escape that?

@ViditChitkara
Copy link
Member Author

Oh I had this warning too, slipped out of my mind. Will give a quick fix to update this!!

@namangupta01
Copy link
Member

@ViditChitkara @jywarren working on this in #2125

@ViditChitkara
Copy link
Member Author

ViditChitkara commented Jan 26, 2018

Oops sorry didn't see that!! So are you covering the regex warning in fixing the robocup offences?

@namangupta01
Copy link
Member

@ViditChitkara yes i am covering all the rubocop offences there
see here: https://pastebin.com/raw/J2kxYX66

@jywarren
Copy link
Member

great, thanks folks!

SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
* added "Suggest new title" feature

closes publiclab#919

* formatted routes

* few changes for simplification

* authorisation check to request_title_change method

* changes for test faliures

* minor changes and enhancements

* minor changes

* changed inline syntax for title suggestion

* written tests

* added more tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Suggest a new title" feature to make friendly suggestions of more descriptive titles
4 participants