-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] (please do not merge yet) Add autocompleting usernames with @ symbol #2913 #2925
[WIP] (please do not merge yet) Add autocompleting usernames with @ symbol #2913 #2925
Conversation
@cheneyshreve try |
@ViditChitkara Thank you!! Bower install noty did the trick. |
The autocomplete for usernames is working good I guess. However atwho's default styling is being overridden. Can you explore something about atwho's manual styling? @jywarren any ideas on this?? |
Hi @ViditChitkara, @jywarren . @ViditChitkara thanks for the tip on noty, I was able to fetch upstream and rebase changes for this branch. I will look into styling and see if I can find anything, but yes, let me @jywarren if you have any ideas about better styling. Thanks both :) |
Generated by 🚫 Danger |
Hi @ViditChitkara, @jywarren I had not yet added atwho to application.css. now the styling works as intended :) |
Awesome!!
…On Wed, Jun 27, 2018 at 2:37 AM Cheney Shreve ***@***.***> wrote:
Hi @ViditChitkara <https://github.com/ViditChitkara>, @jywarren
<https://github.com/jywarren> I had not yet added atwho to
application.css. now the styling works as intended :)
[image: demo_atwho]
<https://user-images.githubusercontent.com/29315273/41939275-182304f4-794a-11e8-9ac3-88b3628d0285.gif>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVkX0UUCOlfqgP1WXXiTgTczGxMUekRcks5uAqKNgaJpZM4U4h6R>
.
|
Hi! I'm wondering if it could be solved in a way very similar to @ViditChitkara's solution using the I think you can likely refactor your code just a little bit so that we have a similar solution. Do you think that would be OK? I love your implementation though! One thing I worry a bit about is autocompleting any user name from the whole database -- we have a lot of users (like, 300k+)! Instead, we might use the API to narrow the results: https://github.com/publiclab/plots2/blob/master/doc/API.md For example you might start typing @jywarren with https://publiclab.org/api/srch/profiles?srchString=jy The Horsey library is here: https://bevacqua.github.io/horsey/ This is looking really good! Thanks for tackling it -- i'm happy to offer more suggestions too! |
@ViditChitkara, @jywarren ahh, I think see what you mean now. I originally thought I couldn't use the Emoji approach because I couldn't find the @ for emoji, but it looks like I should be able to find a solution using just the horsey library and plucking the usernames, if I'm interpreting this right, and also limit the dropdown of users by setting a limit and/or looking into the API approach you mention above. I will get to work on the revision, thanks to both of you for the feedback :) |
awesome, and keep up the great work!
…On Tue, Jun 26, 2018 at 5:46 PM Cheney Shreve ***@***.***> wrote:
@ViditChitkara <https://github.com/ViditChitkara>, @jywarren
<https://github.com/jywarren> ahh, I think see what you mean now. I
originally thought I couldn't use the Emoji approach because I couldn't
find the @ for emoji, but it looks like I should be able to find a solution
using just the horsey library and plucking the usernames, if I'm
interpreting this right, and also limit the dropdown of users by setting a
limit. I will get to work on the revision, thanks to both of you for the
feedback :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ03qjwY0YLkjHANWrl-Jz5kwdFdsks5uAqpPgaJpZM4U4h6R>
.
|
hi @jywarren horsey(document.querySelector('textarea'), { I first tried adding that code snippet to /comments/_form.html.erb, checking both 'textarea' and 'textarea#text-input' to see if I typed in the @, if it would populate the input list as it does in the demo, but it doesn't. Also, when that code snippet is added, the emoji autocomplete stops working. I also tried to edit the one above to reflect the actual username data, using the code below: def user_names_list Returns this running locally, so it's the same format as the textarea output on the horsey demo site. [{:value=>"@admin", :text=>"admin"}, {:value=>"@moderator", :text=>"moderator"}, {:value=>"@user", :text=>"user"}, {:value=>"@cheneyshreve", :text=>"cheneyshreve"}] And to render:
But no success on that either yet. Any ideas? Thanks for any feedback you can give :) |
Maybe @ViditChitkara could offer some help?
…On Tue, Jun 26, 2018, 8:10 PM Cheney Shreve ***@***.***> wrote:
hi @jywarren <https://github.com/jywarren>
I'm trying to get the horsey textarea example from the demo site to work,
they give the code below at https://bevacqua.github.io/horsey/
horsey(document.querySelector('textarea'), {
source: [{ list: [
{ value: ***@***.*** <https://github.com/michael>', text: 'Michael Jackson'
},
{ value: ***@***.*** <https://github.com/jack>', text: 'Jack Johnson' },
{ value: ***@***.*** <https://github.com/ozzy>', text: 'Ozzy Osbourne' }
]}],
getText: 'text',
getValue: 'value',
anchor: '@'
});
I first tried adding that code snippet to /comments/_form.html.erb,
checking both 'textarea' and 'textarea#text-input' to see if I typed in the
@, if it would populate the input list as it does in the demo, but it
doesn't. Also, when that code snippet is added, the emoji autocomplete
stops working.
I also tried to edit the one above to reflect the actual username data,
using the code below:
/application_helper.rb
def user_names_list
usernames = User.all.collect(&:username)
list = []
usernames.each do |name|
val = "@#{name}"
list << { value: val, text: name }
end
[{ list: list }]
end
Returns this running locally, so it's the same format as the textarea
output on the horsey demo site.
***@***.***", :text=>"admin"}, ***@***.***
<https://github.com/Moderator>", :text=>"moderator"}, ***@***.***
<https://github.com/user>", :text=>"user"}, ***@***.***
<https://github.com/cheneyshreve>", :text=>"cheneyshreve"}]
And to render:
/comments/_form.html.erb
<% usernames = user_names_list %>
horsey(document.querySelector('textarea#text-input'), {
source: <% usernames %>,
getText: 'text',
getValue: 'value',
anchor: '@',
limit: 10
});
But no success on that either yet. Any ideas? Thanks for any feedback you
can give :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ0_Ll8afAd7Oc7D6hG0l5w2vQ1IRks5uAs1QgaJpZM4U4h6R>
.
|
Hi @ViditChitkara, @jywarren Unfortunately, I'm still unable to get things working with horsey. I doubled back on atwho just to see if I could do both the autocomplete username and autocomplete tags without interfering with emoji, and it's easy to add multiple callouts with a configuration setting. I'll double back on horsey again too ( should be same case there I'd imagine) and see if I can figure that out, just haven't had luck with that yet. I was hoping playing around with the other library might give me insight into horsey. with code to ensure limits on dropdown
|
Hmm, interesting! One reason I was hoping we could use horsey is that it
can be made to work with 'woofmark', our rich text editor.
But, we've had some serious issues getting that to work smoothly. I wonder
if atwho would work with woofmark, and we could switch everything to atwho?
Would you mind seeing if you could get atwho working on a page like /post
-- with the rich editor?
Thanks for such a deep dive on this!
…On Wed, Jun 27, 2018 at 3:53 PM Cheney Shreve ***@***.***> wrote:
Hi @ViditChitkara <https://github.com/ViditChitkara>, @jywarren
<https://github.com/jywarren> Unfortunately, I'm still unable to get
things working with horsey. I doubled back on atwho just to see if I could
do both the autocomplete username and autocomplete tags without interfering
with emoji, and it's easy to add multiple callouts with a configuration
setting. I'll double back on horsey again too ( should be same case there
I'd imagine) and see if I can figure that out, just haven't had luck with
that yet. I was hoping playing around with the other library might give me
insight into horsey.
[image: demo_atwho_v2]
<https://user-images.githubusercontent.com/29315273/41995931-21782ac0-7a08-11e8-83b1-eba219f61733.gif>
with code to ensure limits on dropdown
names = <%= raw User.pluck(:username).compact.to_json %>;
tagnames = <%= raw Tag.pluck(:name).compact.to_json %>;
var mentions_config = {
at: "@",
data: names,
limit: 6,
tpl: "<li data-value='@${names}'>${names}</li>"
},
hashtags_config = {
at: "#",
data: tagnames,
limit: 6,
tpl: "<li data-value='#${tagnames}'>${tagnames}</li>"
};
$('textarea#text-input').atwho(mentions_config).atwho(hashtags_config);
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ73FlNmaGp2_GKlueQzOi2-UskEmks5uA-J4gaJpZM4U4h6R>
.
|
@jywarren sure thing, I'll see if I can get atwho working on a page like/post with the rich editor. It's interesting to learn about this, especially with these kinds of editors becoming pretty popular. |
awesome!!!
…On Wed, Jun 27, 2018 at 6:23 PM Cheney Shreve ***@***.***> wrote:
@jywarren <https://github.com/jywarren> sure thing, I'll see if I can get
atwho working on a page like/post with the rich editor. It's interesting to
learn about this, especially with these kinds of editors becoming pretty
popular.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ09tmxA2H7mwj_Qrx_oHQAN4YLm4ks5uBAWkgaJpZM4U4h6R>
.
|
Hi @ViditChitkara @jywarren Looks like it does work in the rich text editor if I am testing this properly (I added earlier code snippet to rich.html.erb) I think that it might be possible to also use atwho to do the emojis, building on @ViditChitkara's code. I found this code snippet https://gist.github.com/conan007ai/9503021#file-gistfile1-txt-L44 but it is not as sophisticated as @ViditChitkara's because it doesn't do the substitution of the :: around the image so I'm not sure if it would work with markdown. I can try it out if you want. I'd probably need to build on @ViditChitkara's code he has there already. What do you think? |
Hi @jywarren I checked out the rich text editor and markdown editor and it is possible to use atwho to do autocomplete for the usernames, hashtags, and emojis together. Just let me know if you want me to make issues/PRs to move forward with this. in the markdown editor in rich text editor |
OMGGGGG This is the BEST 🎉 🎉 🐴 Wow. Ok, how about this. For this PR, let's use atwho. If you think it's ready to go, that's great. Next, let's refactor the emoji one into atwho, so it's consistent. Third, let's go into the rich editor and implement that feature over there too! That'll be a little more complex but I can help you out. How does that sound? Amazing work, @cheneyshreve !!! We're so lucky to have your contributions!!!!! 🙌🙌🙌 ⚡️ |
Let's test one more thing -- in the rich text editor, can you switch the mode using the |
Hi @jywarren many thanks for your support, I'm very excited to get to contribute to this project! Regarding toggling the rich text button & your earlier comments. Based on testing in rich.html.erb, you are right, it will need a bit of refactoring. It does okay with keeping the hashes separate from markdown (e.g. one hash is header 1) vs. Rich text (it keeps it as a tag, yay!) but it identifies a bogus username as a real username if it follows the @ symbol (see gif below) so will need to be refactored in the users controller, maybe adding a if !@user.nil? statement. Or maybe make it fancier and give the user a message that that person is not in the database, and then we'd still need a way to make sure it does not try to link to a bogus user page from the user's controller. Let me know how you'd like me to proceed. I've refactored the atwho calls into one statement, but obviously we'll want to fix this first. |
We can break out and address these issues, indeed. Let's make a new issue for the rich editor! In the meantime, is this PR ready to go? What follow-up issues do we want to make? Let's make a /checklist/ ✅✅✅✅ 😄 |
config/database.yml.sqlite
Outdated
@@ -0,0 +1,11 @@ | |||
development: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, i think this has to be removed -- see this for some help with that!
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great - can you try removing this file from the PR? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, still this one file to be removed!
Hi @jywarren the current PR [WIP] has the 3 autocomplete commands (username, tag, emoji) chained in the comments _form.html.erb, which I tested again locally to confirm however I still have some questions.
In terms of a checklist
thanks again for your patience and support :) |
I think we can solve the non-existent username issue in another, and it'll be fine, thanks! And the git mergability looks perfect. I'm going to request a review from someone else and then we should be good! Let's also open a new issue to see if we can optimize the emoji code - especially putting all emoji into a separate file which the browser can cache since it's a lot of code for each page load. |
app/views/comments/_form.html.erb
Outdated
}, | ||
limit: 6 | ||
|
||
names = <%= raw User.pluck(:username).compact.to_json %>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so here, does atwho allow for remote loading of suggestions and especially ones base on what letters you've already typed? That would do a lot to optimize this for when it runs on the full db which has 300k usernames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for this, see my note above about the API and
https://publiclab.org/api/srch/profiles?srchString=jy
I think atwho will probably have a way to fetch remote results!
Thanks and great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jywarren awesome to learn how to deal with this kind of transaction for a large user community (I haven't run into that before now ;) I think it should be possible to fetch remote data (e.g. from atwho docs):
When you set data as URL string, At.js will launch Ajax request to the server to get the JSON data
$('textarea').atwho({
at: "@",
data: "http://www.atjs.com/users.json",
limit: 7
});
so I would need to combine that with the API you mention to get the proper url.
And other example below where a user is doing more customized calls, e.g. binding an ajax call with "focus" and trigger the atwho on success so that the ajax calls are reduced and the filter gets done locally. Not sure if that is feasible for this situation but will keep looking/testing.
jQuery(document).ready(function(){
jQuery('textarea[rel*=atwhoMention]').bind("focus", function(event){
jQuery.ajax({
url: smf_scripturl + '?action=breezeajax;sa=usersmention',
type: "GET",
dataType: "json",
success: function(result)
{
jQuery('textarea[rel*=atwhoMention]').atwho('@', {
search_key: "name",
tpl: "<li data-value='(${name}, ${id})'>${name} <small>${id}</small></li>",
data: result,
limit: 20,
callback: {
filter: function (query, data, search_key) {
return jQuery.map(data, function(item, i) {
return item[search_key].toLowerCase().indexOf(query) < 0 ? null : item
})
},
}
});
},
});
});
});
As a side note, my less than a year old Mac has decided it's display wants to fail so in the next few days, I have to send it to Apple for repairs. If I fall off the radar for a few days, it is because of this, but I'm hoping it'll hold out for a few more days so I can get some work done before sending it off.
Hi @jywarren so with the query and without the underscore, e.g. $.post('/tag/suggested/' + query, function(response) {} still throws 404 error. I think what is going on is related to the sequence that functions are called by the atwho object but not sure what exactly is going on with the search string |
Does it still result in just /tags/suggested/ in the shown errors, or are
you starting to see, for example,
/tags/suggested/h
/tags/suggested/he
/tags/suggested/hel
/tags/suggested/hell
/tags/suggested/hello
which would indicate that it's getting passed through properly?
…On Fri, Jul 20, 2018 at 2:58 PM Cheney Shreve ***@***.***> wrote:
Hi @jywarren <https://github.com/jywarren> so with the query and without
the underscore, e.g.
$.post('/tag/suggested/' + query, function(response) {}
still throws 404 error.
I think what is going on is related to the sequence that functions are
called by the atwho object but not sure what *exactly* is going on with
the search string
callbacks <https://github.com/ichord/At.js/wiki/Callbacks>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ_NKYh6Fdr0HSrN68u3FCZEu3lmvks5uIigvgaJpZM4U4h6R>
.
|
Maybe just above the `$.post('/tag/suggested/' + query` line, you could do
`console.log(query)` to just see what's in there?
…On Fri, Jul 20, 2018 at 3:01 PM Jeffrey Warren ***@***.***> wrote:
Does it still result in just /tags/suggested/ in the shown errors, or are
you starting to see, for example,
/tags/suggested/h
/tags/suggested/he
/tags/suggested/hel
/tags/suggested/hell
/tags/suggested/hello
which would indicate that it's getting passed through properly?
On Fri, Jul 20, 2018 at 2:58 PM Cheney Shreve ***@***.***>
wrote:
> Hi @jywarren <https://github.com/jywarren> so with the query and without
> the underscore, e.g.
>
> $.post('/tag/suggested/' + query, function(response) {}
>
> still throws 404 error.
>
> I think what is going on is related to the sequence that functions are
> called by the atwho object but not sure what *exactly* is going on with
> the search string
> callbacks <https://github.com/ichord/At.js/wiki/Callbacks>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#2925 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AABfJ_NKYh6Fdr0HSrN68u3FCZEu3lmvks5uIigvgaJpZM4U4h6R>
> .
>
|
aha! OK, so we could add an `if (query != '') {` around the $.post() bloc,
and it won't start searching until you type... how does that sound?
…On Fri, Jul 20, 2018 at 3:21 PM Cheney Shreve ***@***.***> wrote:
ok so with console.log(query) for statement without underscore, it does
throw a 404 error first, but then it starts populating the letters..
[image: screen shot 2018-07-20 at 12 19 38 pm]
<https://user-images.githubusercontent.com/29315273/43021106-506728e2-8c17-11e8-8b01-a5d13c3b18aa.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ3Yj02z8sZoy0TOPb4V7jzbJAx62ks5uIi2ngaJpZM4U4h6R>
.
|
…t limit for at callbacks to 20
Hi @jywarren yes! The if condition gets rid of the 404 error so we can drop the underscore. Thanks for the tip! |
Awesome. As soon as you push a new commit I can do a final review and
probably merge this in! ⚡⚡👍🏼🙌🏼
…On Fri, Jul 20, 2018, 4:55 PM Cheney Shreve ***@***.***> wrote:
Hi @jywarren <https://github.com/jywarren> yes! The if condition gets rid
of the 404 error so we can drop the underscore. Thanks for the tip!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ8FK9nPl2Cm9xHqdFtUXZ6DwEY6eks5uIkO1gaJpZM4U4h6R>
.
|
Super I'll test this briefly today I hope then merge it! Thanks a million! |
OK, i used this a bit and ran into an encoding issue, and a few other things, so I made some small adjustments -- started including the emoji.json file in the page, rather than via a remote JS call. Then I wrestled with the display vs insertion formatters -- quite tough! But finally seemed to figure it out. The final changes are pretty small but I tested it out and it works /almost/ as well as we'd hoped. I think the next step will be to deal with this encoding issue so we can display the emoji in the editor instead of just in the published comments: #2665 But for now this is ready to merge -- VERY EXCITING!!! We have a few follow-ups, if you're interested (though, take a moment to celebrate, you've done a fantastic job here!)
In any case, THANK YOU!!!!! 🎉 Let's let this final version pass tests and I'll merge and publish it. |
Super, merging -- and done! OK, if you'd like to do a few follow-up things, we should open a new issue and copy in the checklist from above (and maybe your animated gif!) to start a new thread separate from this very long one! I hope you felt great about this and got a chance to build some useful skills! Thanks again! |
This is now live at PublicLab.org. Try it out! Say, on one of my posts: |
HI @jywarren awesome! I am definitely learning and grateful to have your support! I will copy/paste the checklist above and open a new issue. Thanks again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be /api/srch/profiles?query=
?
at: "@", | ||
callbacks: { | ||
remoteFilter: function(query, callback) { | ||
$.getJSON("/api/srch/profiles?srchString=" + query, {}, function(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns {"error":"query is missing"}
.
I think so - the api has changed in the past few months!
…On Sun, Jan 13, 2019 at 8:40 AM Pranshu Srivastava ***@***.***> wrote:
***@***.**** commented on this pull request.
Shouldn't this be /api/srch/profiles?query=?
------------------------------
In app/views/comments/_form.html.erb
<#2925 (comment)>:
> - <% image_map = emoji_names[:image_map] %>
- var image_map = <%= raw image_map.to_json %>
- horsey(document.querySelector('textarea#text-input'), {
- suggestions: (<%= raw emojis.to_json %>),
- anchor: ':',
- render: function (li, suggestion) {
- var image = image_map[suggestion.text];
- li.innerHTML = "<b>"+image+"</b><span>"+suggestion.text+"</span>";
+
+ (function() {
+
+ var at_config = {
+ at: "@",
+ callbacks: {
+ remoteFilter: function(query, callback) {
+ $.getJSON("/api/srch/profiles?srchString=" + query, {}, function(data) {
Shouldn't this be /api/srch/profiles?query=?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2925 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ25HQ0u8d0QC3w52bWAssmSmKGJMks5vCzcwgaJpZM4U4h6R>
.
|
Okay! I'll send a PR with the corrections. |
…ymbol publiclab#2913 (publiclab#2925) * initial setup commit * [WIP] updated emoji to read from static file, upstream fetch & rebase * [WIP] added autocomplete username to comment window using atwho library * [WIP] Add autocompleting usernames with @ symbol publiclab#2913 fixed typo * [WIP] refactoring atwho calls * finished refactoring using API call, adjusted indentations * removed unnecessary example file * [WIP] testing hashtag_config behavior, removed unnecessary files * [WIP] refactored hash_config, removed unnecessary file, set limits for dropdowns * [WIP] updated emoji code, rebased, removed unneccessary file * [WIP] removed unneccsary atwho code from application_helper.rb * updated hash call with conditional, removed query from emoji call, set limit for at callbacks to 20 * emoji fixes * resolved publiclab#3120 ONLY_FULL_GROUP_BY issue w/ mysql 5.7+
Hi @publiclab/reviewers, @ViditChitkara
I was able to get this working using jquery's atwho library. I was not able to get it to work using the emoji autocomplete approach. If you can give me more details on that and prefer to have it implemented differently, I'm happy to revise this. I do think I can get the Emoji approach to work with the hashes (I was planning on opening a different issue for that) because you can use the hash emoji, so that one should be very similar to the smiley emojis.
The reason I've marked this PR as WIP is because, when I did an upstream fetch and rebase of the master (which is not reflected in this current branch), I get the error
Checked in these paths:
Even though the appropriate files seem to be in-place:
And I have run bundle update, bundle install, and restarted the server. Any idea why this error still persists or have you gotten this error? I'm not sure if you can still merge this PR with the branch being behind master because I have not rebased this branch per the error above.
here is the demo of how the current branch/changes work to see if you want to keep it or maybe have me do some revisions, thanks so much for your help.