Plots2: Comment image uploading not working

Created on 21 Mar 2019  Â·  25Comments  Â·  Source: publiclab/plots2

I think this may be related to the new reply-to-comment feature -- @ViditChitkara could you take a look at this one? I don't see any error message but I did see this warning:

Found 35 elements with non-unique id #comment-form: (More info: https://goo.gl/9p2vKq) 

Related? I was testing both dragging an image into the comment field (not a reply) and also clicking "choose an image" in the bottom bar of the comment field, and neither triggered any reaction. Thank you !!!

JavaScript bug help wanted high-priority

Most helpful comment

Okay, will have a look!

All 25 comments

I'll have a look!

I believe this is part of the error right? It does nothing on image upload.

pl-errorr

I could try trace why that behaviour.

@GettyOrawo Yes!

That's right!

Wondering if it's related to #4771 ?

@jywarren the problem here is that there are multiple comment boxes on a single page. Editor.js and dragdrop js are written assuming a single text area.
I think we need to decide the best possible way to rewrite the editor and dragdrop code which will cater for multiple comment boxes.
Any suggestions on this?

I think we could issue each comment box a unique ID and ensure that this is passed through dragdrop -- often you can use the this keyword to target a specific element within a jQuery queried element:

https://github.com/publiclab/plots2/blob/master/app/assets/javascripts/dragdrop.js

So, instead of the hard-coded regions we're updating in there on these lines:

https://github.com/publiclab/plots2/blob/e7d1315189f3e4b7ad0e1f50c1ed74c1d371c6bf/app/assets/javascripts/dragdrop.js#L45-L47

...we could use:

$(this).find('.create_progress'); // searching inside the given `dropzone` element

This should work because all the progress bar and other relevant elements are inside the dropzone element:

https://github.com/publiclab/plots2/blob/e7d1315189f3e4b7ad0e1f50c1ed74c1d371c6bf/app/views/comments/_form.html.erb#L20-L60

What do you think?

I'll give this a shot!! An interesting one!!

Hello guys. Sorry I've been relatively passive on this issue. Was wondering what could be causing this. Thanks @jywarren and @ViditChitkara would love to see the PR for this and how you solve it or maybe work with you and learn from it. :slightly_smiling_face:

Hmm, @ViditChitkara I still can't seem to drag an image into a comment form - i just tried here: https://publiclab.org/notes/vibhordelgupta/04-09-2019/soc-proposal-image-sequencer-broadening-avenues

Would you be able to take a look and see what's going on?

I see this error;

Uncaught TypeError: Cannot read property 'find' of undefined
    at HTMLDivElement.start (dragdrop-3093ac31fa5b1856b1a4ee669fa42254025330e04a7280d52baf98a2d0f34447.js:45)
    at $.(anonymous function).(anonymous function)._trigger (https://publiclab.org/assets/application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:14170:13)
    at $.(anonymous function).(anonymous function)._beforeSend (https://publiclab.org/assets/application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:14945:22)
    at $.(anonymous function).(anonymous function)._beforeSend (https://publiclab.org/assets/application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:13786:25)
    at $.(anonymous function).(anonymous function)._onSend (https://publiclab.org/assets/application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:15056:18)
    at $.(anonymous function).(anonymous function)._onSend (https://publiclab.org/assets/application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:13786:25)
    at Object.data.submit (application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:14800)
    at $.(anonymous function).(anonymous function).<anonymous> (https://publiclab.org/assets/application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:14373:30)
    at fire (application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:3233)
    at Object.add [as done] (application-f7dff6c9332f860098e629b658f6713cfd16a4dedda6132019e35496c592bac1.js:3292)

It's referring to this line in dragdrop.js:

        ($D.selected).find('#create_progress').eq(0).show();

Okay, will have a look!

I think we may close the issue after I fix this. Seems they are related to image uploading.

Update- really want to fix this, i think it's related to this error:

Uncaught TypeError: Cannot read property 'find' of undefined

On:

https://github.com/publiclab/plots2/blob/099a1aba9af851c7dd53504395513ab9a4c1ac12/app/assets/javascripts/dragdrop.js#L45

Right now, only drag/drop seems broken. You can select an image to upload without drag/dropping it.

For writing a system test for this, we could explore:

Will have a look

System test is going well for selecting a file, but we would have to add one for dragging in a file. Selecting is working on the production site right now, just not dragging.

A system test could look like:

test "uploading by dragging" do
    # log in
    visit Node.last.path
    drop_in_dropzone 'public/images/pl.png'
    click_button 'Publish'
    expect(page.find('#comments .comment image')['src']).to match('test.png')
end

def drop_in_dropzone(file_path)
  # Generate a fake input selector
  page.execute_script <<-JS
    fakeFileInput = window.$('<input/>').attr(
      {id: 'fakeFileInput', type:'file'}
    ).appendTo('body');
  JS
  # Attach the file to the fake input selector with Capybara
  attach_file("fakeFileInput", file_path)
  # Add the file to a fileList array
  page.execute_script("var fileList = [fakeFileInput.get(0).files[0]]")
  # Trigger the fake drop event
  page.execute_script <<-JS
    var e = jQuery.Event('drop', { dataTransfer : { files : fileList } });
    $('.dropzone')[0].dropzone.listeners[0].events.drop(e);
  JS
end

Hi @ViditChitkara -- we really need some help with the ($D.selected).find('#create_progress').eq(0).show(); error; are you able to put some time into this to resolve issues related to the new reply-to-comment code? Thank you!

Yes, doing it today!

awesome, thank you. I started a system test here but it can be kept
separate: https://github.com/publiclab/plots2/pull/5655 thank you!!!

On Fri, May 3, 2019 at 10:38 AM Vidit notifications@github.com wrote:

Yes, doing it today!

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/5229#issuecomment-489117826,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAF6J6ZQGTHPI3G57XTFULPTRE2RANCNFSM4HAH3SMQ
.

Cool!

I think I found a solution. Need to do some testing though. Will be pushing
it soon.
Thanks

On Fri, May 3, 2019, 8:18 PM Jeffrey Warren notifications@github.com
wrote:

awesome, thank you. I started a system test here but it can be kept
separate: https://github.com/publiclab/plots2/pull/5655 thank you!!!

On Fri, May 3, 2019 at 10:38 AM Vidit notifications@github.com wrote:

Yes, doing it today!

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<https://github.com/publiclab/plots2/issues/5229#issuecomment-489117826
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/AAAF6J6ZQGTHPI3G57XTFULPTRE2RANCNFSM4HAH3SMQ

.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/5229#issuecomment-489121577,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFMRPUKJGVVP6QBGR7RS5D3PTRGDNANCNFSM4HAH3SMQ
.

Confirmed this works on stable server!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milaaraujo picture milaaraujo  Â·  3Comments

keshavsethi picture keshavsethi  Â·  3Comments

RuthNjeri picture RuthNjeri  Â·  3Comments

grvsachdeva picture grvsachdeva  Â·  3Comments

divyabaid16 picture divyabaid16  Â·  3Comments