the admin info update!

This commit is contained in:
24c02 2025-01-09 14:17:08 -05:00
parent 2109725c8a
commit 1e031c3527
8 changed files with 91 additions and 1 deletions

View file

@ -15,3 +15,7 @@ end
gem "faraday", "~> 2.12"
gem "concurrent-ruby", "~> 1.3"
gem "activesupport", "~> 8.0"
gem "redcarpet", "~> 3.6"

View file

@ -1,9 +1,25 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (8.0.1)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.9)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
drb (2.2.1)
faraday (2.12.1)
faraday-net_http (>= 2.0, < 3.5)
json
@ -13,8 +29,11 @@ GEM
faraday-net_http_persistent (2.3.0)
faraday (~> 2.5)
net-http-persistent (>= 4.0.4, < 5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.9.0)
logger (1.6.2)
minitest (5.25.4)
multi_json (1.15.0)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
@ -38,7 +57,9 @@ GEM
rack (>= 3.0.0)
rackup (2.2.1)
rack (>= 3)
redcarpet (3.6.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
sinatra (4.1.1)
logger (>= 1.6.0)
mustermann (~> 3.0)
@ -53,6 +74,8 @@ GEM
sinatra (= 4.1.1)
tilt (~> 2.0)
tilt (2.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uri (1.0.2)
PLATFORMS
@ -61,11 +84,13 @@ PLATFORMS
x64-mingw-ucrt
DEPENDENCIES
activesupport (~> 8.0)
concurrent-ruby (~> 1.3)
faraday (~> 2.12)
norairrecord (~> 0.1.4)
puma (~> 6.5)
rackup (~> 2.2)
redcarpet (~> 3.6)
sinatra (~> 4.1)
sinatra-contrib (~> 4.1)

21
app/helpers.rb Normal file
View file

@ -0,0 +1,21 @@
require 'active_support/number_helper'
require 'redcarpet'
module Sinatra
module RenderMarkdownHelper
def md(markdown)
(@renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)).render(markdown)
end
end
module SchmoneyHelper
def cashify(amount)
ActiveSupport::NumberHelper.number_to_currency amount
end
end
module IIHelper
def render_ii(shipment, field, emoji, description, representation=nil)
return unless shipment[field]
"<br/><abbr title='#{description}'>#{emoji}</abbr>: #{representation&.call(shipment) || shipment[field]}"
end
end
end

View file

@ -2,7 +2,10 @@ require 'sinatra/base'
require "sinatra/content_for"
require "sinatra/cookies"
require 'securerandom'
require 'active_support'
require 'active_support/core_ext/object/blank'
require_relative './helpers'
require_relative './awawawa'
require_relative './signage'
@ -13,6 +16,9 @@ end
class ShipmentViewer < Sinatra::Base
helpers Sinatra::ContentFor
helpers Sinatra::Cookies
helpers Sinatra::RenderMarkdownHelper
helpers Sinatra::SchmoneyHelper
helpers Sinatra::IIHelper
set :host_authorization, permitted_hosts: []

View file

@ -93,6 +93,10 @@ class Shipment < Norairrecord::Table
source_record: source_url
}.compact.to_json
end
def internal_info_partial
nil
end
end
class WarehouseShipment < Shipment
@ -170,6 +174,10 @@ class WarehouseShipment < Shipment
"error parsing JSON for #{source_id}!"
end
end
def internal_info_partial
:_warehouse_internal_info
end
end
class HighSeasShipment < Shipment
@ -240,6 +248,10 @@ class HighSeasShipment < Shipment
def shipped?
fields['status'] == 'fulfilled'
end
def internal_info_partial
:_highseas_internal_info
end
end
class HSMinutemanShipment < HighSeasShipment

View file

@ -0,0 +1 @@
<%= render_ii(shipment, 'dollar_cost', '💸', 'cost to fulfill', -> (s) { cashify s['dollar_cost'] }) %>

View file

@ -29,9 +29,16 @@
<% end %>
<% end %>
<br/>
<br/><span>📅 Created on <%= shipment.date[..9] %></span>
<% if @show_ids %>
<br/>
👀 <span class="internal">Airtable: <%= external_link(shipment.source_id, shipment.source_url) %></span>
<% end %>
<br/><span>📅 Created on <%= shipment.date[..9] %></span>
<% if @internal and shipment.internal_info_partial %>
<br/>
<div class="internal" style="padding: 5px">
<b>🤫 internal info:</b><br/>
<%= erb shipment.internal_info_partial, locals: { shipment: } %>
</div>
<% end %>
</div>

View file

@ -0,0 +1,14 @@
<% if shipment.fields['Internal Notes'].present? %>
🗒️ notes:
<%= md shipment.fields['Internal Notes'] %>
<% end %>
<%# i acknowledge that this is nasty %>
💸: <%=
['Postage', 'Labor', 'Contents', 'Total'].map do |f|
next unless (c = shipment.fields["Warehouse#{f} Cost"])
"#{f.downcase}:&nbsp;#{cashify c}"
end.compact.join(", ").presence || "?"
%>
<%= render_ii(shipment, 'WarehouseOrder ID', '🆔', 'zenventory ID') %>
<%= render_ii(shipment, 'WarehouseWeight', '<i class="fa-solid fa-weight-hanging"></i>', 'weight') %>