Skip to content

Commit

Permalink
New layouts and that
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 25, 2016
1 parent d936fca commit a786fd4
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 27 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ table {
bottom: -3px;
}
}

.new-metric, .edit-metric {
font-size: 1.5em;
}
11 changes: 10 additions & 1 deletion app/controllers/generic_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ class GenericController < ApplicationController
before_action :require_login

def index
@metrics = find_class.all
@hours = 72
if params[:hours]
@hours = hours(params[:hours]) ? hours(params[:hours]) : @hours
end

@metrics = find_class.where(datetime: (Time.now - @hours.hours)..Time.now)
@data = ControllerHelpers.for_table @metrics
@widest = ControllerHelpers.widest @data
end
Expand Down Expand Up @@ -54,4 +59,8 @@ def find_class
def metrics_path
send("#{@metric.class.name.underscore}s_path".to_sym)
end

def hours parameter
return parameter.to_i if parameter.to_i > 0
end
end
2 changes: 2 additions & 0 deletions app/controllers/longterm_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ def index
ControllerHelpers.for_table(GlycatedHaemoglobin.all),
ControllerHelpers.for_table(BloodPressure.all)
]

@no_picker = true;
end
end
2 changes: 1 addition & 1 deletion app/views/shared/_edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% @decorated_metric = @metric.presenter %>
<h1><%= @decorated_metric.short_name %></h1>
<h1 class='edit-metric'>Edit <%= @decorated_metric.short_name %></h1>

<%= render 'form' %>
8 changes: 5 additions & 3 deletions app/views/shared/_hours_picker.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<div id='hours-picker' class='row'>
<div class='col-xs-12'>
<%= render partial: 'shared/hours_slider' %>
|
<%= link_to "#{path}?#{request.query_string}", title: label do %>
<i class='fa <%= fontawesome %>'></i>
<% if path %>
|
<%= link_to "#{path}?#{request.query_string}", title: label do %>
<i class='fa <%= fontawesome %>'></i>
<% end %>
<% end %>
</div>
</div>
8 changes: 8 additions & 0 deletions app/views/shared/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
</div>
</div>

<% unless @no_picker %>
<%= render partial: 'shared/hours_picker', locals: {
label: 'Charts',
fontawesome: 'fa-area-chart',
path: nil
}%>
<% end %>
<%= render partial: 'shared/table', locals: {
metrics: @metrics,
with_year: true
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% @decorated_metric = @metric.presenter %>
<h1>Add <%= @decorated_metric.short_name %></h1>
<h1 class='new-metric'>Add <%= @decorated_metric.short_name %></h1>

<%= render partial: 'shared/form' %>
2 changes: 1 addition & 1 deletion lib/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.date_sift measurements

def self.to_presenter metric
return metric if metric.class.name =~ /Presenter$/
"#{metric.class.name}Presenter".constantize.new metric
metric.presenter
end

def self.for_table metrics
Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/blood_pressures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

describe 'GET #index' do
it 'populates an array of bp values' do
blood_pressure = create(:blood_pressure)
get :index
expect(assigns(:metrics)).to eq [blood_pressure]
Timecop.freeze 2016, 02, 21, 16, 00 do
blood_pressure = create(:blood_pressure)
get :index
expect(assigns(:metrics)).to eq [blood_pressure]
end
end

it 'renders the #index view' do
Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/glycated_haemoglobins_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

describe 'GET #index' do
it 'populates an array of hba1c values' do
glycated_haemoglobin = create(:glycated_haemoglobin)
get :index
expect(assigns(:metrics)).to eq [glycated_haemoglobin]
Timecop.freeze 2016, 02, 20, 18, 11 do
glycated_haemoglobin = create(:glycated_haemoglobin)
get :index
expect(assigns(:metrics)).to eq [glycated_haemoglobin]
end
end

it 'renders the #index view' do
Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/medication_events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

describe 'GET #index' do
it 'populates an array of medication events' do
medication_event = create(:medication_event)
get :index
expect(assigns(:metrics)).to eq [medication_event]
Timecop.freeze 2016, 01, 28, 20, 11 do
medication_event = create(:medication_event)
get :index
expect(assigns(:metrics)).to eq [medication_event]
end
end

it 'renders the #index view' do
Expand Down
12 changes: 7 additions & 5 deletions spec/requests/glucose_measurements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
end

it 'edits a measurement' do
glucose_measurement = create(:glucose_measurement, datetime: '1992-06-15 12:00:00', value: '7')
visit glucose_measurements_path(as: user)
click_link '12:00'
expect(page).to have_content 'Glucose'
expect(page).to have_content 'Delete'
Timecop.freeze 1992, 06, 15, 18, 11 do
glucose_measurement = create(:glucose_measurement, datetime: '1992-06-15 12:00:00', value: '7')
visit glucose_measurements_path(as: user)
click_link '12:00'
expect(page).to have_content 'Glucose'
expect(page).to have_content 'Delete'
end
end

it 'adds several measurements' do
Expand Down
13 changes: 7 additions & 6 deletions spec/requests/medication_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@

it 'edits an event' do
DatabaseCleaner.clean

medication_event = create(:medication_event, datetime: '1992-06-15 12:00:00', dose: '7', insulin: 'humalog')
visit medication_events_path(as: user)
click_link '12:00'
expect(page).to have_content 'Meds'
expect(page).to have_content 'Delete'
Timecop.freeze 1992, 06, 15, 18, 11 do
medication_event = create(:medication_event, datetime: '1992-06-15 12:00:00', dose: '7', insulin: 'humalog')
visit medication_events_path(as: user)
click_link '12:00'
expect(page).to have_content 'Meds'
expect(page).to have_content 'Delete'
end
end

it 'adds several measurements' do
Expand Down

0 comments on commit a786fd4

Please sign in to comment.