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

Comment image uploading not working #5229

Closed
jywarren opened this issue Mar 21, 2019 · 25 comments · Fixed by #5657
Closed

Comment image uploading not working #5229

jywarren opened this issue Mar 21, 2019 · 25 comments · Fixed by #5657
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed help wanted requires help by anyone willing to contribute high-priority JavaScript

Comments

@jywarren
Copy link
Member

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 !!!

@jywarren jywarren added the bug the issue is regarding one of our programs which faces problems when a certain task is executed label Mar 21, 2019
@jywarren jywarren added help wanted requires help by anyone willing to contribute JavaScript high-priority labels Mar 21, 2019
@ViditChitkara
Copy link
Member

I'll have a look!

@GettyOrawo
Copy link
Contributor

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

pl-errorr

I could try trace why that behaviour.

@ViditChitkara
Copy link
Member

@GettyOrawo Yes!

@jywarren
Copy link
Member Author

That's right!

Wondering if it's related to #4771 ?

@ViditChitkara
Copy link
Member

@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?

@jywarren
Copy link
Member Author

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:

$('#create_progress').show()
$('#create_uploading').show()
$('#create_prompt').hide()

...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:

<div class="form-group dropzone">
<%
body = body || params[:body]
# Look for comment templates
if params[:body].nil? && @node && @node.has_power_tag('comment-template')
body = Node.find_by(slug: @node.power_tag('comment-template')).try(:body)
end
%>
<textarea style="border: 1px solid #bbb;border-bottom-left-radius: 0;border-bottom-right-radius: 0;border-bottom: 0;padding: 10px;" onFocus="editing=true" name="body" class="form-control" id="text-input" rows="6" cols="40" placeholder="<%= placeholder %>"><% if local_assigns[:is_new_answer].blank? %> <%= body %><% end %></textarea>
<div id="imagebar">
<div id="create_progress" style="display:none;" class="progress progress-striped active pull-right">
<div id="create_progress-bar" class="progress-bar" style="width: 0%;"></div>
</div>
<p>
<span id="create_uploading" class="uploading" style="display:none;">
<%= t('comments._form.uploading') %>
</span>
<span id="create_prompt" class="prompt">
<span style="padding-right:4px;float:left;" class="hidden-xs">
<%= raw t('comments._form.drag_and_drop') %>
</span>
<!-- http://stackoverflow.com/questions/11235206/twitter-bootstrap-form-file-element-upload-button -->
<label id="input_label" class="" for="fileinput">
<input id="fileinput" type="file" name="image[photo]" style="display:none;" />
<a class="hidden-xs">choose one</a>
<span class="visible-xs">
<i class="fa fa-upload"></i>
<a><%= t('comments._form.upload_image') %></a>
</span>
</label>
</span>
</p>
</div>
</div>

What do you think?

@ViditChitkara
Copy link
Member

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

@GettyOrawo
Copy link
Contributor

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. 🙂

@jywarren
Copy link
Member Author

jywarren commented Apr 9, 2019

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)

@jywarren
Copy link
Member Author

jywarren commented Apr 9, 2019

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

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

@jywarren
Copy link
Member Author

jywarren commented Apr 9, 2019

Also, shall we close these? #4617 #4771

@ViditChitkara
Copy link
Member

Okay, will have a look!

@ViditChitkara
Copy link
Member

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

@jywarren
Copy link
Member Author

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

Uncaught TypeError: Cannot read property 'find' of undefined

On:

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

@jywarren
Copy link
Member Author

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

@ViditChitkara
Copy link
Member

Will have a look

@jywarren
Copy link
Member Author

jywarren commented May 1, 2019

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.

@jywarren
Copy link
Member Author

jywarren commented May 2, 2019

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

@jywarren
Copy link
Member Author

jywarren commented May 3, 2019

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!

@ViditChitkara
Copy link
Member

Yes, doing it today!

@jywarren
Copy link
Member Author

jywarren commented May 3, 2019 via email

@ViditChitkara
Copy link
Member

Cool!

@ViditChitkara
Copy link
Member

ViditChitkara commented May 3, 2019 via email

@jywarren
Copy link
Member Author

jywarren commented May 7, 2019

Confirmed this works on stable server!

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 help wanted requires help by anyone willing to contribute high-priority JavaScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants