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

Add cms:page_file_link tag to render page files #799

Merged
merged 1 commit into from
Mar 4, 2018
Merged

Conversation

glebm
Copy link
Contributor

@glebm glebm commented Feb 27, 2018

Examples:

{{ cms:page_file_link header }}
{{ cms:page_file_link attachments, filename: "cat.jpg", as: image }}

Dragging page-level files onto the textarea generates these tags.

See #796 for more information.
Fixes #796

@glebm glebm force-pushed the page-file branch 3 times, most recently from de13762 to 092e8a9 Compare February 27, 2018 21:17
= link_to truncated_filename, attachment,
data: {toggle: "page-file-popover", content: thumb},
class: "btn btn-light text-truncate", target: "_blank",
ondragstart: "event.dataTransfer.setData('text/plain', '#{cms_page_file_link_tag}');"
Copy link
Member

Choose a reason for hiding this comment

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

Don't think we can do inline JS like that if CSP is enabled. Let's move that into data attribute. Also how would one even know that this is something draggable?

Copy link
Contributor Author

@glebm glebm Feb 28, 2018

Choose a reason for hiding this comment

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

Done. I didn't write in CoffeeScript, but it's only a few line so perhaps you could rewrite it if you really want it to be CoffeeScript?

Also how would one even know that this is something draggable?

True that it's not very discoverable, but it does have cursor: pointer on hover, and I've now made a thumbnail the drag image for images.

(", filename: \"#{filename}\"" if multiple),
(", as: image" if attachment.image?),
" }}".html_safe
].compact.join
Copy link
Member

Choose a reason for hiding this comment

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

Kinda ugly. Let's move that into admin view helper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "comfortable_mexican_sofa/content/tags/file_content.rb"
Copy link
Member

Choose a reason for hiding this comment

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

require_relative ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "comfortable_mexican_sofa/content/tags/file_content.rb"
Copy link
Member

Choose a reason for hiding this comment

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

require_relative

@@ -0,0 +1,80 @@
# frozen_string_literal: true

require "comfortable_mexican_sofa/content/tags/file_content.rb"
Copy link
Member

Choose a reason for hiding this comment

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

require_relative

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

fragment.attachments.first
else
fragment.attachments.detect { |a| a.filename.to_s == filename }
end
Copy link
Member

Choose a reason for hiding this comment

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

Don't like massive offsets like these. Should be:

foo ||=
  if bar?

I thought rubocop would catch this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

I'll also move page file popovers into the same file

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

All done

@glebm glebm force-pushed the page-file branch 2 times, most recently from 9e02fce to 897a83a Compare February 28, 2018 00:32
@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

There is a small glitch with the popover re-appearing at the end of the drop on Firefox, the popover re-appears:

gif

Looking into it

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

Firefox glitch fixed

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

Files can now also be dragged out of the global files modal

@glebm glebm force-pushed the page-file branch 2 times, most recently from 5a9814e to 0e89b01 Compare February 28, 2018 07:17
@GBH
Copy link
Member

GBH commented Feb 28, 2018

For the JS drag-and-drop feature, do you mind writing a system test please? Capybara can do .drag_to thing. I only have couple of tests there, but anything involving JS interactions should have a system test.

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

OK, I'll try. Everything else looks good to you?

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

I wrote a system test as far as I could take it, because drag_to does not seem to work! Tried with the latest chromedriver too.

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

I've now written tests for both global files and page files drag'n'drop but they don't work and so are currently being skipped.

I've tried for a while to fix them but I couldn't. I won't look into this further.

@glebm glebm force-pushed the page-file branch 2 times, most recently from ae134b9 to 0341c68 Compare February 28, 2018 21:18
@GBH
Copy link
Member

GBH commented Feb 28, 2018

I'm going to take a look at the drag_to issue. Writing capybara tests is like pulling teeth even when everything works as it should.

Rest of PR looks fine, however tests right now are failing. Also, don't introduce new fixture items just for one test. Either mutate existing or spin up new records manually. System tests run in transactions, so it's safe to do.

About coffeescript, I am not against converting to regular JS. One less dependency to worry about. I'm just not sure what the cool kids do these days.

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

Cool kids these days use TypeScript

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

I've removed the extra fixtures.

I'm going to take a look at the drag_to issue.

Start with the page files test as it's simpler (no iframes).

@glebm
Copy link
Contributor Author

glebm commented Feb 28, 2018

I've made a drag'n'drop video for the release notes (used Peek to record):

cms file drag n drop

Examples:

  {{ cms:page_file_link header }}
  {{ cms:page_file_link attachments, filename: "cat.jpg", as: image }}

Dragging page-level files onto the textarea or CodeMirror generates these tags.
Site files can now also be dragged from the files modal onto the
textarea or CodeMirror.
@GBH
Copy link
Member

GBH commented Mar 4, 2018

I'm in process of merging. Running locally and it's great. Dragging files from file pop-up to places is awesome. Gonna leave comments, but just as notes.

/usr/lib/chromium-browser/chromedriver
/usr/local/bin/chromedriver
].find { |path| File.executable?(path) }

Copy link
Member

Choose a reason for hiding this comment

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

Had to remove this. Broke it for me as it wouldn't find my chromedriver that lives in a different bin directory (but still on my $PATH). There has to be a documentation on Rails Guides for installing all the crap. Guides only have a bit about testing, but nothing about how to get it all running in the first place.

# frozen_string_literal: true

# A mixin for tags that returns the file as their content.
module ComfortableMexicanSofa::Content::Tag::FileContent
Copy link
Member

Choose a reason for hiding this comment

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

moving this file into /mixins as it's not a tag

@@ -1,4 +1,7 @@
%li{data: {id: file.id}}
:ruby
file_tag = "{{ cms:file_link #{file.id} }}"
Copy link
Member

Choose a reason for hiding this comment

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

I think I want the same dealio to generate as: image for image attachments. Will expand that helper (or make new one) to do this.

@site = comfy_cms_sites(:default)
end

def test_site_file_drag_and_drop
Copy link
Member

Choose a reason for hiding this comment

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

seems like we can't test this due to chromedriver limitation. leaving skip but removing code.

@GBH GBH merged commit d1707f0 into comfy:master Mar 4, 2018

# Dragging the link should generate CMS markup.
skip "Drag'n'drop does not work for some reason"
find_link("image.jpg").drag_to(content_field)
Copy link
Member

Choose a reason for hiding this comment

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

Can't figure out this one either. By all accounts it should work. Dragging other links should work too (to eliminate js fuckery) but it does not. Maybe warrants filing issue with Capybara.

@GBH
Copy link
Member

GBH commented Mar 4, 2018

@glebm can you double check if everything works in Firefox? On my VM (Firefox 50 though) none of the draggable stuff works as in Chrome. Dragging from iframe doesn't work at all and dragging from page files dumps link's url and not the tag's string.

I'm trying to upgrade to latest Firefox here. If latest version works then no worries.

@glebm
Copy link
Contributor Author

glebm commented Mar 4, 2018

It works for me perfectly in Firefox 58 on Ubuntu 16.04. Firefox 50 is from June 2016. I'll double check with the current comfy master.

@GBH
Copy link
Member

GBH commented Mar 4, 2018

Got Firefox 58 on LinuxMint (Ubuntu). Page file link drag works perfectly. One thing that still doesn't work is that drag from the iframe. In Chrome iframe goes away and it's possible to drag into form input. In Firefox iframe sticks around.

@glebm
Copy link
Contributor Author

glebm commented Mar 4, 2018

@GBH Reproduced, fixed in #802

@glebm glebm deleted the page-file branch March 5, 2018 00:24
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.

2 participants