Skip to content

Commit

Permalink
Front-page looks like it did in my head :)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Jan 31, 2016
1 parent f3988cc commit 122ef84
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ a {
.buttons {
padding-top: $padding-large-vertical;
}

caption {
font-size: 1.5em;
}

.filler {
background-image: image-url('confectionary.png');
}
11 changes: 10 additions & 1 deletion app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
class WelcomeController < ApplicationController
def index
@hours = 36
@metrics = []
[
GlucoseMeasurement,
CarbohydrateIntake,
MedicationEvent
].each do |model|
@metrics.concat model.where(datetime: (Time.now - 48.hours)..Time.now)
@metrics.concat model.where(datetime: (Time.now - @hours.hours)..Time.now)
end

@widest = widest @metrics
end

private

def widest metrics
metrics.map { |m| m.class }.uniq.map { |u| u.fields.count }.max
end
end
11 changes: 10 additions & 1 deletion app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
</div>

<table class='table table-bordered table-striped'>
<caption>
Last <%= @hours %> hours
</caption>

<% date_sift(@metrics).each_pair do |day, values| %>
<tr>
<th colspan=64>
<th colspan='<%= @widest + 2 %>'>
<% date = Time.parse(day) %>
<%= date.strftime "%A %B #{date.day.ordinalize}" %>
</th>
Expand All @@ -22,10 +26,15 @@
<td>
<%= class_name(value).short_name %>
</td>
<% count = 0 %>
<% class_name(value).fields.each do |field| %>
<td class='<%= "#{value.class.name.underscore.gsub('_', '-')}-#{field}" %>'>
<%= value.send(field) %>
</td>
<% count += 1 %>
<% end %>
<% (@widest - count).times do %>
<td class='filler'></td>
<% end %>
</tr>
<% end %>
Expand Down
16 changes: 12 additions & 4 deletions spec/controllers/welcome_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
require 'rails_helper'

RSpec.describe WelcomeController, type: :controller do

describe WelcomeController, type: :controller do
let(:metrics) {
[
create(:glucose_measurement),
create(:medication_event),
create(:carbohydrate_intake),
create(:physical_exercise)
]
}
it 'knows which metric has the most fields' do
expect(described_class.new.send(:widest, metrics)).to eq 2
end
end

0 comments on commit 122ef84

Please sign in to comment.