diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index ef00821bf..33c2b5498 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -70,6 +70,7 @@ def show format.html format.json { render json: @image.map(&:fup_json) } end + @image.order(:position) end def update @@ -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) diff --git a/app/views/images/_index.html.erb b/app/views/images/_index.html.erb index 6f9c58bc7..4edd3f69c 100644 --- a/app/views/images/_index.html.erb +++ b/app/views/images/_index.html.erb @@ -3,7 +3,7 @@

No images uploaded.

<%end%> - + <% @map.warpables.each do |warpable| %>
@@ -70,3 +70,14 @@ <% end %>
+ diff --git a/config/routes.rb b/config/routes.rb index 6dd6d53f8..0591ea8d8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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