Skip to content

Commit

Permalink
Create Status.json (#483)
Browse files Browse the repository at this point in the history
* Export bug fix

* Working export json

* Update example view

* Clean up code

* Clean up code pt2

* Refactor export progress to show status JSON

* Update demo view

* Clean up comments
  • Loading branch information
sashadev-sky authored and jywarren committed Apr 15, 2019
1 parent 96ea574 commit d58e237
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/controllers/export_controller.rb
Expand Up @@ -66,4 +66,12 @@ def progress
render :text => output, :layout => false
end

def status
map = Map.find(params[:id])
if export = map.export
render json: export.to_json
else
render json: { status: 'export has not been run' }
end
end
end
6 changes: 3 additions & 3 deletions app/models/map.rb
Expand Up @@ -206,13 +206,13 @@ def grouped_images_histogram(binsize)
def run_export(user, resolution)
key = APP_CONFIG ? APP_CONFIG["google_maps_api_key"] : "AIzaSyAOLUQngEmJv0_zcG1xkGq-CXIPpLQY8iQ"
unless export
export = Export.new({
new_export = Export.new({
:map_id => id
})
end
end
Exporter.run_export(user,
resolution,
self.export,
self.export || new_export,
self.id,
self.slug,
Rails.root.to_s,
Expand Down
6 changes: 4 additions & 2 deletions app/views/maps/_sidebar_exports.html.erb
Expand Up @@ -103,14 +103,16 @@ var exporting, exportResolutionSlider
// 'complete', 'failed', ''
exportProgress = function() {
$.ajax({
url: '/export/progress/<%= @map.id %>?authenticity_token=<%= form_authenticity_token %>'
url: '/export/status/<%= @map.id %>?authenticity_token=<%= form_authenticity_token %>',
dataType: "json"
}).done(function(data) {
$('.progress').show()
$('#export_progress').html(data)
$('#export_progress').html(data['status'])
// change progress indicator appearance accordingly
// -- maybe have a handler which assigns prog indicator state based on status?
})
}

<% if @map.exporting? %>
exporting = true
setInterval(exportProgress,5000)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -100,6 +100,7 @@
get 'maps/:id/warpables' => 'maps#images' # deprecate this in favor of resourceful route below; this is just to override maps/:id
post 'maps/:map_id/warpables' => 'images#create' # deprecate this in favor of resourceful route below; this is just to override maps/:id
get 'export/progress/:id' => 'export#progress'
get 'export/status/:id' => 'export#status'
get 'exports' => 'export#index'
get 'maps/:id' => 'maps#show'
get 'map/:id', to: redirect('/maps/%{id}')
Expand Down

0 comments on commit d58e237

Please sign in to comment.