From d58e23783c8703b26965c03492406ff3a5824763 Mon Sep 17 00:00:00 2001 From: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> Date: Mon, 15 Apr 2019 19:07:19 -0400 Subject: [PATCH] Create Status.json (#483) * 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 --- app/controllers/export_controller.rb | 8 ++++++++ app/models/map.rb | 6 +++--- app/views/maps/_sidebar_exports.html.erb | 6 ++++-- config/routes.rb | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 6c7912927..5790a7109 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -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 diff --git a/app/models/map.rb b/app/models/map.rb index a21a93486..cbef8a58c 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -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, diff --git a/app/views/maps/_sidebar_exports.html.erb b/app/views/maps/_sidebar_exports.html.erb index 5399a5501..d21b1dd25 100644 --- a/app/views/maps/_sidebar_exports.html.erb +++ b/app/views/maps/_sidebar_exports.html.erb @@ -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) diff --git a/config/routes.rb b/config/routes.rb index 2ae8dcf59..5c9444b67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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}')