mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Remove format from ExportJob.perform_later call
This commit is contained in:
parent
2a960826eb
commit
fb8b2958b6
4 changed files with 11 additions and 23 deletions
|
|
@ -12,7 +12,7 @@ class ExportsController < ApplicationController
|
||||||
export_name = "export_from_#{params[:start_at].to_date}_to_#{params[:end_at].to_date}"
|
export_name = "export_from_#{params[:start_at].to_date}_to_#{params[:end_at].to_date}"
|
||||||
export = current_user.exports.create(name: export_name, status: :created)
|
export = current_user.exports.create(name: export_name, status: :created)
|
||||||
|
|
||||||
ExportJob.perform_later(export.id, params[:start_at], params[:end_at], format: params[:format])
|
ExportJob.perform_later(export.id, params[:start_at], params[:end_at])
|
||||||
|
|
||||||
redirect_to exports_url, notice: 'Export was successfully initiated. Please wait until it\'s finished.'
|
redirect_to exports_url, notice: 'Export was successfully initiated. Please wait until it\'s finished.'
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
class ExportJob < ApplicationJob
|
class ExportJob < ApplicationJob
|
||||||
queue_as :exports
|
queue_as :exports
|
||||||
|
|
||||||
def perform(export_id, start_at, end_at, format: :json)
|
def perform(export_id, start_at, end_at)
|
||||||
export = Export.find(export_id)
|
export = Export.find(export_id)
|
||||||
|
|
||||||
Exports::Create.new(export:, start_at:, end_at:, format:).call
|
Exports::Create.new(export:, start_at:, end_at:).call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Exports::Create
|
class Exports::Create
|
||||||
def initialize(export:, start_at:, end_at:, format: :json)
|
def initialize(export:, start_at:, end_at:)
|
||||||
@export = export
|
@export = export
|
||||||
@user = export.user
|
@user = export.user
|
||||||
@start_at = start_at.to_datetime
|
@start_at = start_at.to_datetime
|
||||||
@end_at = end_at.to_datetime
|
@end_at = end_at.to_datetime
|
||||||
@format = format
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
|
@ -19,7 +18,7 @@ class Exports::Create
|
||||||
Rails.logger.debug "====Exporting #{points.size} points"
|
Rails.logger.debug "====Exporting #{points.size} points"
|
||||||
|
|
||||||
data = ::ExportSerializer.new(points, user.email).call
|
data = ::ExportSerializer.new(points, user.email).call
|
||||||
file_path = Rails.root.join('public', 'exports', "#{export.name}.#{format}")
|
file_path = Rails.root.join('public', 'exports', "#{export.name}.json")
|
||||||
|
|
||||||
File.open(file_path, 'w') { |file| file.write(data) }
|
File.open(file_path, 'w') { |file| file.write(data) }
|
||||||
|
|
||||||
|
|
@ -36,7 +35,7 @@ class Exports::Create
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :user, :export, :start_at, :end_at, :format
|
attr_reader :user, :export, :start_at, :end_at
|
||||||
|
|
||||||
def time_framed_points
|
def time_framed_points
|
||||||
user
|
user
|
||||||
|
|
@ -61,10 +60,4 @@ class Exports::Create
|
||||||
content: "Export \"#{export.name}\" failed: #{error.message}, stacktrace: #{error.backtrace.join("\n")}"
|
content: "Export \"#{export.name}\" failed: #{error.message}, stacktrace: #{error.backtrace.join("\n")}"
|
||||||
).call
|
).call
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_json_export(points)
|
|
||||||
end
|
|
||||||
|
|
||||||
def process_gpx_export(points)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,33 +3,28 @@
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
<%= form_with url: points_path, method: :get do |f| %>
|
<%= form_with url: points_path, method: :get do |f| %>
|
||||||
<div class="flex flex-col md:flex-row md:space-x-4 md:items-end">
|
<div class="flex flex-col md:flex-row md:space-x-4 md:items-end">
|
||||||
<div class="w-full md:w-3/12">
|
<div class="w-full md:w-2/6">
|
||||||
<div class="flex flex-col space-y-2">
|
<div class="flex flex-col space-y-2">
|
||||||
<%= f.label :start_at, class: "text-sm font-semibold" %>
|
<%= f.label :start_at, class: "text-sm font-semibold" %>
|
||||||
<%= f.datetime_local_field :start_at, class: "rounded-md w-full", value: @start_at %>
|
<%= f.datetime_local_field :start_at, class: "rounded-md w-full", value: @start_at %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full md:w-3/12">
|
<div class="w-full md:w-2/6">
|
||||||
<div class="flex flex-col space-y-2">
|
<div class="flex flex-col space-y-2">
|
||||||
<%= f.label :end_at, class: "text-sm font-semibold" %>
|
<%= f.label :end_at, class: "text-sm font-semibold" %>
|
||||||
<%= f.datetime_local_field :end_at, class: "rounded-md w-full", value: @end_at %>
|
<%= f.datetime_local_field :end_at, class: "rounded-md w-full", value: @end_at %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full md:w-1/12">
|
<div class="w-full md:w-2/6">
|
||||||
<div class="flex flex-col space-y-2">
|
<div class="flex flex-col space-y-2">
|
||||||
<%= f.submit "Search", class: "px-4 py-2 bg-blue-500 text-white rounded-md" %>
|
<%= f.submit "Search", class: "px-4 py-2 bg-blue-500 text-white rounded-md" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full md:w-2/12">
|
<div class="w-full md:w-2/6">
|
||||||
<div class="flex flex-col space-y-2 text-center">
|
<div class="flex flex-col space-y-2 text-center">
|
||||||
<%= link_to 'Export points', exports_path(start_at: @start_at, end_at: @end_at), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points withing timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md join-item" %>
|
<%= link_to 'Export points', exports_path(start_at: @start_at, end_at: @end_at), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points withing timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<%# <div class="w-full md:w-2/12"> %>
|
|
||||||
<%# <div class="flex flex-col space-y-2 text-center"> %>
|
|
||||||
<%# <%= link_to 'Export as GPX', exports_path(start_at: @start_at, end_at: @end_at, format: :gpx), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points withing timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md join-item" %>
|
|
||||||
<%# </div> %>
|
|
||||||
<%# </div> %>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue