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

Image drag and drop #670

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Image drag and drop #670

wants to merge 1 commit into from

Conversation

divyabaid16
Copy link
Contributor

Fixes #644 (<=== Add issue number here)

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

GIF For the same:
Peek 2019-05-28 11-11

Thanks!

@codeclimate
Copy link

codeclimate bot commented Jun 6, 2019

Code Climate has analyzed commit f592c355 and detected 0 issues on this pull request.

View more on Code Climate.

@jywarren
Copy link
Member

jywarren commented Jun 6, 2019 via email

@grvsachdeva
Copy link
Member

https://travis-ci.org/publiclab/mapknitter/jobs/542107150
Functional tests are failing

@codecov
Copy link

codecov bot commented Jun 7, 2019

Codecov Report

Merging #670 into main will decrease coverage by 1.86%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #670      +/-   ##
==========================================
- Coverage   41.36%   39.49%   -1.87%     
==========================================
  Files          34       34              
  Lines        1308     1314       +6     
==========================================
- Hits          541      519      -22     
- Misses        767      795      +28
Impacted Files Coverage Δ
app/controllers/images_controller.rb 17.33% <16.66%> (-0.06%) ⬇️
app/controllers/application_controller.rb 35.48% <0%> (-25.81%) ⬇️
app/controllers/sessions_controller.rb 16.45% <0%> (-18.99%) ⬇️

@divyabaid16 divyabaid16 force-pushed the sort branch 4 times, most recently from 609d4df to ab5e4a9 Compare June 7, 2019 07:34
@divyabaid16
Copy link
Contributor Author

@gauravano
This test is failing because of newly added column position in warpables.
But it is not failing when I tried to run functional test in my terminal
Selection_170

@divyabaid16 divyabaid16 force-pushed the sort branch 2 times, most recently from 06ede26 to 4fa80d2 Compare June 7, 2019 16:29
<tbody>
<% @map.warpables.each do |warpable| %>
<tbody data-url = "<%= sort_images_path %>">
<% ary = @map.warpables.sort { |a, b| a.position <=> b.position } %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

    <% ary = @map.warpables.sort { |a, b| a.position <=> b.position } %>

@gauravano
This position is not being recognized even though it is added into the table.
After adding the column position from the rails terminal and migrating it did resolve the problem for me.

Copy link
Member

Choose a reason for hiding this comment

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

@divyabaid16 I think this was just a caching problem running rake db:drop db:setup fixed it for me. So thats not a prob

Copy link
Member

@sashadev-sky sashadev-sky left a comment

Choose a reason for hiding this comment

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

========

Update: I created this bug in PR #630 when I removed average = 0. I uploaded PR to fix it now #675. So sorry!! Perhaps we should add testing for this function to protect it? @jywarren @gauravano

This PR is good to go but it might be good to merge the bug fix first and I can repull this to confirm its gone.

========
This is working great, but there is a new bug that I think really needs to be fixed here -- basically if you upload an image onto a new map and refresh the page, unless you have moved the image from the sidebar onto the map AND interacted with the image (even click is fine), rails will throw an error. This is because the map controller show action calls average_cm_per_pixel in map.rb. There, we define a warpable right when the image is created. But a warpable is not a placed_warpable until you place the image on the map and click on it, which is when it gets assigned nodes

def average_cm_per_pixel
if !warpables.empty?
scales = []
count = 0
placed_warpables.each do |warpable|
count += 1
res = warpable.cm_per_pixel
res = 1 if res.zero? # let's not ever try to go for infinite resolution
scales << res unless res.nil?
end
total_sum = (scales.inject { |sum, n| sum + n }) if scales
return total_sum / count if total_sum
else
0
end
end

<tbody>
<% @map.warpables.each do |warpable| %>
<tbody data-url = "<%= sort_images_path %>">
<% ary = @map.warpables.sort { |a, b| a.position <=> b.position } %>
Copy link
Member

Choose a reason for hiding this comment

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

@divyabaid16 I think this was just a caching problem running rake db:drop db:setup fixed it for me. So thats not a prob

@sashadev-sky sashadev-sky mentioned this pull request Jun 8, 2019
5 tasks
@divyabaid16
Copy link
Contributor Author

@jywarren can this be merged?

@jywarren
Copy link
Member

Pretty soon! Sorry, i want to link this also to the question about re-ordering in #640. Perhaps we need a unified ordering system, but let's discuss the UI implications over there and come to a decision together?

@sashadev-sky
Copy link
Member

@divyabaid16 @jywarren this also needs to be retested after the bug fix in #675 I really think that one should be merged asap!

@divyabaid16 divyabaid16 reopened this Jun 14, 2019
@jywarren
Copy link
Member

Can we coordinate here to identify how to:

  1. send a new ordering to LDI from MK (so this code would trigger reordering of the displayed images in the map)
  2. send a new ordering from LDI to MK (the opposite)

so we can sync? I think on the MK end we may need a method like reorder(images) or something?

@grvsachdeva
Copy link
Member

Hey @jywarren, we want the mentioned functionality for Action cable syncing feature right?

@jywarren
Copy link
Member

jywarren commented Jul 26, 2019 via email

@grvsachdeva
Copy link
Member

can you clarify a bit, why we want to sync with LDI in-between? For syncing, we can just broadcast the coordinates of an image on a map in a channel and other users' view will be updated accordingly. Am I missing something?

Also, if there's any other strategy in mind, can you upload a rough sketch showing the whole data and control flow? Thanks!

@jywarren
Copy link
Member

jywarren commented Jul 26, 2019 via email

@grvsachdeva
Copy link
Member

ordering in the sidebar

Currently, we allow sorting of images. We need to make it async (just thinking of improvements there too).

Ok, getting back to issues. So, ordering in the sidebar is like if 2 users have the same map open in their browser window then if image order in the sidebar is changed by one, it should be reflected on others. Right? We need to save the state of the images too, in an array, maybe.

Ordering of images on map

For this, the first implementation approach which come to my mind is #670 (comment).

But, @jywarren I would like to understand this --> #670 (comment) approach. Can you please upload a sketch of control flow?

@ViditChitkara what's your current plan?

@jywarren
Copy link
Member

My thought was that each system (Leaflet map, sidebar list) ought to have a method available to accept a new image ordering programatically. Then when a change is made to either (OR we receive a new ordering from another user) each of the 2 displays can be reordered using their .order() method. Does this make sense?

@grvsachdeva
Copy link
Member

Hmm, so on receiving the data we have to refresh that particular section of screen ie., sidebar or map. The receiving functions would be channel sender and receiver but from there we need to call a function which would inject the data into the client side via JS.

@jywarren
Copy link
Member

Yes - makes sense. Can we split this in 2 - setting up events to trigger synchronicity between the sidebar ordering and the map ordering first, and then think about cross-user synchronization later? If we do a good job setting up the event listeners and triggers for sync in a single browser window, adding the extra Action Cable cross-user synchronization shouldn't be too hard as a next step, and we don't have to be blocked here. What do you think, @divyabaid16 ?

@jywarren
Copy link
Member

I believe DistortableImage just uses Leaflet's default bringToFront() system from the API, so it shouldn't be too hard to reorder the map images.

https://github.com/publiclab/Leaflet.DistortableImage/#single-image-interface-1

Then, we'd need to set up a listener on the map to trigger sidebar reordering whenever you reorder the map. cc @sashadev-sky just to keep folks synced!

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.

Order images in the sidebar using drag and drop
4 participants