Files
mapknitter/app/controllers/export_controller.rb
Alicia Paz d2d45dbf42 Migrate from Travis to GitHub Actions for CI (#1534)
* Try migrating from Travis to GitHub Actions for CI

* Update actions.yml and tests.yml

* Add ruby version

* Update config/database.yml.example

* Try rubocop and docker jobs

* Fix indentation

* Update tests.yml

* Update tests.yml

* Update gemfile

* Update rubocop job and Gemfile

* Update .rubocop_shopify_styleguide.yml

* Update gemfile

* Update .rubocop_todo.yml

* Update rubocop configuration and styleguides

* Fix rubocop offenses

* Update .rubocop.yml

* Update .rubocop.yml

* Udate .codeclimate.yml

* Update .codeclimate.yml

* Update .codeclimate.yml

* Update .codeclimate.yml

* Setup unit tests

* Update find_verified_user method in connection.rb

* Add yarn cache and install to setup

* install exporter dependencies; gdal/imagemagick

* Introduce Gitpod to migration work (#1538)

* Add CORS headers (#1536)

* Create .gitpod.dockerfile

* Create .gitpod.yml

* Create database.yml.gitpod

* Update .gitpod.yml

* ruby 2.4.6 in gitpod.dockerfile

* Update .gitpod.yml

* Update database.yml.gitpod

Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>

* Install gdal and use egordm for yarn cache

* Delete unnecessary query and fix layout

* Run script with verbose output

* Try installing package in action.yml

* Setup controllers job

* Fix indentation

* Setup system tests job

* Setup docker development build job

* Fix identifiers

* Fix path to action.yml

* Update development dockerfile

* Setup docker production build job

* Update tests.yml

* Setup assets precompilation job

* Setup production environment

* Update tests.yml

* Update action.yml for production

* Try with test setup

* Remove action.yml for production

* Change names of jobs for friendliness and clarity

* Update .github/workflows/tests.yml

Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>

* Move dockerfiles to directory and change docker job names for clarity

* Update docker job names

Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org>
2021-09-20 18:50:31 -04:00

110 lines
3.2 KiB
Ruby

class ExportController < ApplicationController
protect_from_forgery except: :formats
def index
@exports = Export.where('status NOT IN (?)', %w(failed complete none))
.order('updated_at DESC')
@day = Export.where(status: 'complete')
.where('updated_at > (?)', (Time.now - 1.day).to_s(:db))
.count
@week = Export.where(status: 'complete')
.where('updated_at > (?)', (Time.now - 1.week).to_s(:db))
.count
end
# override logger to suppress huge amounts of inane /export/progress logging
def logger
if params[:action] == 'progress'
nil
else
Rails.logger
end
end
# https://mapknitter.org/warps/yale-farm/yale-farm.jpg
def jpg
send_file('public/warps/' + params[:id] + '/' + params[:id] + '.jpg')
end
# https://mapknitter.org/warps/yale-farm/yale-farm-geo.tif
def geotiff
send_file('public/warps/' + params[:id] + '/' + params[:id] + '-geo.tif')
end
def cancel
@map = Map.find_by(id: params[:id])
if @map.anonymous? || logged_in?
export = @map.export
export.status = 'none'
export.save
if params[:exports]
flash[:notice] = 'Export cancelled.'
redirect_to('/exports')
else
render(plain: 'cancelled')
end
else
render(plain: 'You must be logged in to export, unless the map is anonymous.')
end
end
def progress
map = Map.find_by(id: params[:id])
export = map.export
output = if export.present?
if export.status == 'complete'
'complete'
elsif export.status == 'none'
'export not running'
elsif export.status == 'failed'
'export failed'
else
export.status
end
else
'export has not been run'
end
render(plain: output, layout: false)
end
def status
map = Map.find_by(id: params[:id])
if export = map.export
if export.export_url.present?
status_response = ExporterClient.new(export.export_url).status
render(json: status_response)
else
render(json: export.to_json)
end
else
render(json: { status: 'export has not been run' })
end
end
def create
# Saving in export_url column because assuming that is not being used in new Export API
# if it is, instead create a new col like 'status_url' and save the url there
# mySQL2 error ActiveRecord::StatementInvalid (Mysql2::Error: Field 'bands_string' doesn't have a default value: INSERT INTO `exports` (`export_url`, `created_at`, `updated_at`) VALUES ('//export.mapknitter.org/id/1562102960/status.json', '2019-07-02 21:29:20', '2019-07-02 21:29:20')):
# so adding a default value for now. I think this column will be deprecated?
export = Export.create!(
export_url: params[:status_url],
user_id: current_user&.id || 0,
map_id: params[:map_id],
bands_string: 'default bands_string'
)
render(json: export.to_json)
end
# for demoing remote url functionality during testing
def external_url_test
render(json: Export.last.to_json)
end
private
def export_params
params.require(:export).permit(:status, :export_url)
end
end