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

Auto-complete of search not working on 'post' page #2795

Closed
Souravirus opened this issue Jun 8, 2018 · 38 comments
Closed

Auto-complete of search not working on 'post' page #2795

Souravirus opened this issue Jun 8, 2018 · 38 comments
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed gci-candidate JavaScript

Comments

@Souravirus
Copy link
Member

Souravirus commented Jun 8, 2018

Please describe the problem (or idea)

The auto complete is not working on search input on https://publiclab.org/post page
We are preparing to participate in Google Code-in, and have reserved this issue for participants in GCI - but we'd love to have your help with another one! Please check out https://code.publiclab.org to see more.

@Souravirus Souravirus added bug the issue is regarding one of our programs which faces problems when a certain task is executed JavaScript labels Jun 8, 2018
@angeryrohan
Copy link

Hey, can I have a link to .html file that is being loaded on https://publiclab.org/post ?

@jywarren
Copy link
Member

jywarren commented Nov 15, 2018 via email

@angeryrohan
Copy link

Hey @jywarren , Can you tell me how you see that, It has been a problem for me to locate the files that are being loaded :/

@kevinzluo
Copy link
Collaborator

Hi @rohancl .
I believe you should first check config/routes.rb, which tells you which controller each link goes to. In this case on line 268 and 269 you can see that post goes to editor#post.
Then you can go find the controller under app/controllers, and in this case it is editor. Within the controller you can see under post, unless some conditions are met, it will call rich, meaning rich.html.erb should be loaded.

This is what I have learned so far. Hopefully it is helpful, but some of it may be wrong.

@angeryrohan
Copy link

Got it, thanks @kevinzluo

@angeryrohan
Copy link

Problem in contributing

Hey @jywarren @kevinzluo , I have completed the task, but I still think I need some help here,

bruh 3

What I did

I checked the links, and found that the code in post.js which contains the code for auto- completion of the search bar isn't actually linked to the post page. (or to rich.html.erb) And also that it is dependent on typeahead.jquery.js to function properly/ So, I checked for the typeahead.jquery.js (located in /public/lib/typeahead.js/dist/typeahead.jquery.js) [NOTE: The /public/lib folder is present here, but not on this repository] script tag in rich.html.erb and I got the link

bruh

1: Now, I copied and pasted the code of post.js into the starting of typeahead.jquery.js (along with the pre existing code)
2: The auto-completion was now working ...

The Problem

There is no such file as /public/lib in this repository. So where do I commit my code ?

What I tried doing, but failed

I did notice that the /public/lib folder is created only if you install plots locally on a machine and thus it's not on this repository, So I thought instead of editing typeahead.jquery.js, I could move post.js in /public folder and directly link it to rich.html.erb like this:

bruh 4

I also did notice that post.js requires the typeahead.jquery.js file for proper function,

bruh 3
And, So I copied and pasted the code of typeahead.jquery.js into post.js and kept typeahead.jquery.js as it was earlier.
Then, I tried running the files of localhost , the post.js is linked to rich.html.erb as well but, The auto-completion didn't happen.
This is very strange and I'm a bit confused.
If I put the same code in the typeahead.jquery.js file, it works.
But, If i Put the same code in another js file that I've linked, nothing happens

Mentors, please explain in detail. Thanks ^.^

@angeryrohan
Copy link

@jywarren Please help.

@Souravirus
Copy link
Member Author

Hi @rohancl, the public/lib folder is used for installation of packages of yarn and since we don't want the main repository to contain such packages, we put public/lib in .gitignore. This is the reason why you don't see public/lib in the repository. Now the problem is that you want to connect typeahead.jquery.js to a file. You can do that by writing this line in app/assets/javascript/application.js //=require typeahead.js/dist/typeahead.jquery.js.
Thank you!!

@angeryrohan
Copy link

I could not understand this completely, can I edit typeahead.jquery.js anywhere on this repository ?

@Souravirus
Copy link
Member Author

No need to edit typeahead.jquery.js file as it is a file from outer source just like bootstrap. We only use it and never change it.

@angeryrohan
Copy link

Ok, I am somewhat getting it.... But how do i import this file into the post.js then ?

@angeryrohan
Copy link

and also, Why is application.js all quoted out, it contains of all comments.... Please explain, Thanks ^.^

@Souravirus
Copy link
Member Author

Those are not comments. It is actually the way for importing a js file.

@angeryrohan
Copy link

so we are linking a js file inside a js file right ?

@Souravirus
Copy link
Member Author

Yeah right and these js files can be used in any of the views.

@angeryrohan
Copy link

That means I can bring typeahead.jquery.js into post.js by typing in: //=require typeahead.js/dist/typeahead.jquery.js . right ?

@Souravirus
Copy link
Member Author

Yeah that's what you have to do

@angeryrohan
Copy link

angeryrohan commented Nov 17, 2018

I did but it's not working,
I have post.js in my public folder and I have imported it in rich.html.erb like this:
posto

I reloaded the post page, the post.js is linked (i tested it with an alert box)
Then, I pasted the require code you gave me in post.js

req

reloaded the page, the dropdowns didn't come :/

@Souravirus
Copy link
Member Author

I dont understand why you are keeping anything in public folder. I think it should be kept inside app/assets/javascript folder.

@angeryrohan
Copy link

that was because I could not link the file anywhere else i tried writing:
../app/assets/javascript/post.js
but it gave me a warning

screenshot from 2018-11-17 19-24-16

I know I am probably doing something dumb, Please help @Souravirus

@Souravirus
Copy link
Member Author

Can you send a PR? So, that I can see what exactly you are doing.

@angeryrohan
Copy link

Yeah sure, wait a moment....

@angeryrohan
Copy link

#3996
checkout my last2 commits

@Souravirus
Copy link
Member Author

Please add the //= require line in application.js as I have told you before. Also there should be space between /= and require. I guess you haven't given any space in there. Please see to this.

@angeryrohan
Copy link

Oh sorry I forgot to commit the application.js part, but I have it updated in my localhost.
I've added the spaces too, still... not working

@Souravirus
Copy link
Member Author

What's the error now?

@angeryrohan
Copy link

ERROR: I cannot link the post.js file

bru

Here are the addresses of my main files in plots2:

post.js: app/assets/javascript/post.js
rich.html.erb:
app/views/editor/rich.html.erb

Updated code in post.js:

bru

Updated code in rich.html.erb:

*look at the last line*

kiu

@angeryrohan
Copy link

Also, along with the linking error in the inspect element tab, I am getting this too:

newerr
Tell me if it's a problem, because as far as I know, this is an outsource

@jywarren
Copy link
Member

jywarren commented Nov 17, 2018 via email

@jywarren
Copy link
Member

jywarren commented Nov 17, 2018 via email

@angeryrohan
Copy link

angeryrohan commented Nov 18, 2018

Hey @Souravirus @jywarren , Is the file that has autocompletition code already linked to rich.html.erb ?
Thanks ^.^

@oorjitchowdhary
Copy link
Member

Is this task already done or picked up by someone?
If not, I'd like to solve it

@jywarren
Copy link
Member

@rohancl yes it is - see the top few lines of rich.html.erb -- you can see it included in there.

@oorjitchowdhary -- maybe you could help @rohancl take the next step on this one?

@jonxuxu
Copy link
Member

jonxuxu commented Nov 24, 2018

I saw this task was free and claimed it. Can I work on it?

@Souravirus
Copy link
Member Author

Yeah sure @JonathanXu1

@jonxuxu
Copy link
Member

jonxuxu commented Nov 25, 2018

I believe that the reason the auto-complete isn't working properly is because the neccessary scripts and css were not included in rich.html.erb. I dug around and found /public/lib/publiclab-editor/examples/autocomplete.html, which has very similar code to rich.html.erb. See it here. Essentially the header has been modified like such:
image

So I copied the script and css tags to the rich page and modified the directories to the rich local, where I now get the following error:
image
image

I'm not familiar with ruby on rails, and I'm not really sure if I'm going in the right direction. Any help would be appreciated! @Souravirus @jywarren

@kevinzluo
Copy link
Collaborator

Hello. I am very confused currently.
I saw this task open this morning and claimed it.
Is there anyone else with this task claimed currently on GCI? Is it possible that it has been duplicated?

On a side note, I believe the issue is a result of the inclusion of typeahead.jquery.js, which is changing the properties of the search field, here:

<script src="/lib/typeahead.js/dist/typeahead.jquery.js"></script>
.

When I check the documentation it seems to only be a "standalone UI view", so I do not think it is actually essential to the tags module which still works once I remove it.

autocompleteonpost

If no one else has this task currently claimed on GCI, I will submit a PR tomorrow with more detail on my findings.

@Souravirus
Copy link
Member Author

Hi @kevinzluo, this issue is currently available as it is abandoned by 2 students. So, you can surely submit a PR to address this issue. Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed gci-candidate JavaScript
Projects
None yet
Development

No branches or pull requests

6 participants