Skip to content

Commit

Permalink
Factor stuff out
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 20, 2016
1 parent e00aced commit 226338c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 56 deletions.
7 changes: 3 additions & 4 deletions app/views/shared/_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<table class='table table-bordered table-striped'>
<table class='table table-bordered table-hover' id='metric'>
<% date_sift(metrics).each_pair do |day, values| %>
<tr>
<th colspan=64> <!-- bootstrap ignores this maybe? -->
<th colspan='4' class='day-marker'> <!-- bootstrap ignores this maybe? -->
<% date = Time.parse(day) %>
<%= date.strftime "%A %B #{date.day.ordinalize}" %>
</th>
</tr>

<% values.each do |value| %>
<%= render partial: 'shared/table_row', locals: {
passed_value: value,
fields: class_name(@metrics).fields
value: value
} %>
<% end %>
<% end %>
Expand Down
34 changes: 27 additions & 7 deletions app/views/shared/_table_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
<tr>
<td>
<%= link_to passed_value.datetime.strftime('%H:%M'),
send("edit_#{passed_value.class.name.underscore}_path".to_sym, passed_value) %>
<!-- this resolves to e.g. edit_medication_event_path -->
<%= link_to value.datetime.strftime('%H:%M'),
send(edit_path(value), value),
title: 'Edit this metric'
%>
</td>

<% fields.each do |field| %>
<td class='<%= "#{passed_value.class.name.underscore.gsub('_', '-')}-#{field}" %>'>
<%= passed_value.send(field) %>
<td>
<%= class_name(value).short_name %>
</td>
<% count = 0 %>
<% class_name(value).fields.each do |field| %>
<td class='<%= class_for_table_cell value, field %>'>
<% if value.class.units[:applies_to] == field.to_sym %>
<div class='value'
data-toggle='tooltip'
data-placement='top'
title='<%= value.send(field) %> <%= value.class.units[:full] %>'>
<span class='number'><%= value.send(field) %></span>
<span class='units'><%= value.class.units[:short] %></span>
</div>
<% else %>
<%= value.send(field) %>
<% end %>
</td>
<% count += 1 %>
<% end %>
<% if @widest %>
<% (@widest - count).times do %>
<td class='filler'></td>
<% end %>
<% end %>
</tr>
34 changes: 3 additions & 31 deletions app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,9 @@
</th>
</tr>
<% values.each do |value| %>
<tr>
<td>
<%= link_to value.datetime.strftime('%H:%M'),
send(edit_path(value), value),
title: 'Edit this metric'
%>
</td>
<td>
<%= class_name(value).short_name %>
</td>
<% count = 0 %>
<% class_name(value).fields.each do |field| %>
<td class='<%= class_for_table_cell value, field %>'>
<% if value.class.units[:applies_to] == field.to_sym %>
<div class='value'
data-toggle='tooltip'
data-placement='top'
title='<%= value.send(field) %> <%= value.class.units[:full] %>'>
<span class='number'><%= value.send(field) %></span>
<span class='units'><%= value.class.units[:short] %></span>
</div>
<% else %>
<%= value.send(field) %>
<% end %>
</td>
<% count += 1 %>
<% end %>
<% (@widest - count).times do %>
<td class='filler'></td>
<% end %>
</tr>
<%= render partial: 'shared/table_row', locals: {
value: value
} %>
<% end %>
<% end %>
</table>
15 changes: 1 addition & 14 deletions spec/helpers/glycated_haemoglobins_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the GlycatedHaemoglobinsHelper. For example:
#
# describe GlycatedHaemoglobinsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe GlycatedHaemoglobinsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
describe GlycatedHaemoglobinsHelper, type: :helper do
end
4 changes: 4 additions & 0 deletions spec/models/glucose_measurement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
it 'is invalid with a value less than zero' do
expect(build :glucose_measurement, value: -1).to_not be_valid
end

it 'represents itself as an array of table cells' do

end
end

0 comments on commit 226338c

Please sign in to comment.