Merge pull request #967 from RickCarlino/email_part_ii

Minor Touchups
pull/968/head^2
Rick Carlino 2018-08-17 07:27:42 -05:00 committed by GitHub
commit b9b0e15e0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 5 deletions

View File

@ -1,5 +1,10 @@
class LogDeliveryMailer < ApplicationMailer
WHOAH = "Device %s is sending too many emails!!! (> 20 / hr)"
WHOAH = "Device %s is sending too many emails!!! (> 20 / hr)"
SUBJECT = "🌱 New message from %s!"
def timestamp(time, zone)
time.in_time_zone(zone).strftime("%F %I:%M %p")
end
def maybe_crash_if_too_many_logs(device)
query_params = { sent_at: 1.hours.ago..Time.now, device_id: device.id }
@ -9,13 +14,14 @@ class LogDeliveryMailer < ApplicationMailer
end
def send_a_digest(device, unsent)
timezone = device.timezone || "UTC"
@emails = device.users.pluck(:email)
@messages = unsent
.pluck(:created_at, :message)
.map{|(t,m)| [t.in_time_zone(device.timezone || "UTC"), m] }
.map{|(t,m)| [timestamp(t, timezone), m] }
.map{|(x,y)| "[#{x}]: #{y}"}
@device_name = device.name
mail(to: @emails, subject: "🌱 New message from #{@device_name}!")
mail(to: @emails, subject: SUBJECT % [@device_name])
unsent.update_all(sent_at: Time.now)
end

View File

@ -0,0 +1,13 @@
<p>
<%= @device_name %> sent you an email.
</p>
<p>
Here's what your device had to say:
</p>
<ul>
<% @messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>

View File

@ -4,4 +4,5 @@ Here's what your device had to say:
<% @messages.each do |msg| %>
* <%= msg %>
<% end %>
<% end %>

View File

@ -16,7 +16,7 @@ export function ToolBayNumberCol({ axis, value, dispatch, slot }: NumColProps) {
<BlurableInput
value={value.toString()}
onCommit={(e) => {
dispatch(edit(slot, { [axis]: parseInt(e.currentTarget.value, 10) }));
dispatch(edit(slot, { [axis]: parseFloat(e.currentTarget.value) }));
}}
type="number" />
</Col>;