Skip to content

Commit

Permalink
Make globe work for old imports, using available country data, if any (
Browse files Browse the repository at this point in the history
  • Loading branch information
forsbergplustwo authored Sep 22, 2023
2 parents 5a409bb + 482e367 commit e86a440
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
16 changes: 9 additions & 7 deletions app/controllers/imports/globes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ class Imports::GlobesController < ApplicationController

def show
@import = current_user.imports.find(params[:import_id])
@globe_data = globe_data

render json: globe_data
respond_to do |format|
format.json { render json: @globe_data }
format.html { render :show }
end
end

private

def globe_data
payments = @import.payments.pluck(:shop_country, :charge_type).last(72)
globe_data = []
payments.each do |c|
globe_data << {countryCode: c[0], reverse: c[1] == "refund"}
end
globe_data
@import.payments
.where.not(shop_country: nil)
.pluck(:shop_country, :charge_type)
.map { |country, charge_type| {countryCode: country, reverse: charge_type == "refund"} }
end
end
14 changes: 14 additions & 0 deletions app/views/imports/globes/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= turbo_frame_tag :globe do %>
<% if @import.csv_file_source? || @globe_data.present? %>

<%= polaris_spacer(vertical: :base) %>

<%= tag.div style: "width: 80%; height: 800px; margin: 0 auto; opacity: 0; transition: opacity 3s ease-in-out;",
data: {
controller: "globe",
globe_target: "container",
globe_fetch_url_value: import_globe_path(@import, format: :json),
} %>

<% end %>
<% end %>
10 changes: 1 addition & 9 deletions app/views/imports/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@

<% end %>

<% if @import.csv_file_source? %>
<%= polaris_spacer(vertical: :base) %>
<%= tag.div style: "width: 80%; height: 800px; margin: 0 auto; opacity: 0; transition: opacity 3s ease-in-out;",
data: {
controller: "globe",
globe_target: "container",
globe_fetch_url_value: import_globe_path(@import),
} %>
<% end %>
<%= turbo_frame_tag :globe, src: import_globe_path(@import) %>

<%= render "modals/destroy",
id: "destroy-modal",
Expand Down

0 comments on commit e86a440

Please sign in to comment.