Skip to content

Commit

Permalink
Drag and drop added
Browse files Browse the repository at this point in the history
  • Loading branch information
divyabaid16 committed May 28, 2019
1 parent dc96ada commit dd041d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def show
format.html
format.json { render json: @image.map(&:fup_json) }
end
@image.order(:position)
end

def update
Expand Down Expand Up @@ -98,6 +99,12 @@ def update
render text: 'success'
end

def sort
params[:warpable].each_with_index do |id, index|
@warpable.where(id: id).update_all(position: index+1)
end
end

def destroy
@warpable = Warpable.find params[:id]
if logged_in? && current_user.can_delete?(@warpable)
Expand Down
13 changes: 12 additions & 1 deletion app/views/images/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p id="no-images">No images uploaded. </p>
<%end%>
<table class="warpables-all table table-striped">
<tbody>
<tbody data-url = "<%= sort_images_path %>">
<% @map.warpables.each do |warpable| %>
<tr id="warpable-<%= warpable.id %>">
<td class="warpable">
Expand Down Expand Up @@ -70,3 +70,14 @@
<% end %>
</tbody>
</table>
<script>
$('tbody').sortable({
update: function(e,ui){
$.ajax({
url: $(this).data("url"),
type: "PUT",
data: $(this).sortable('serialize'),
})
}
});
</script>
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@

# You can have the root of your site routed with 'root'
# just remember to delete public/index.html.

resources :images do
collection do
put :sort
end
end


root :to => 'maps#index'

# RESTful API
Expand Down

0 comments on commit dd041d6

Please sign in to comment.