Skip to content

Commit

Permalink
This needs some serious refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 28, 2016
1 parent 5337750 commit 107c2f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
6 changes: 6 additions & 0 deletions app/controllers/generic_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def index
nil
end

@no_picker = begin
((Time.now - @metrics.first.datetime) / 3600) > 168
rescue NoMethodError
true
end

@has_charts = false
end

Expand Down
36 changes: 22 additions & 14 deletions app/controllers/longterm_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@ class LongtermController < ApplicationController
before_action :require_login

def index
@sets = [
{
model: GlycatedHaemoglobin,
metrics: GlycatedHaemoglobin.all,
bucketed_metrics: GlycatedHaemoglobin.all.group_by { |g| g.datetime.strftime "%Y-%m-%d" },
with_year: nil
},
{
model: BloodPressure,
metrics: BloodPressure.all,
bucketed_metrics: BloodPressure.all.group_by { |g| g.datetime.strftime "%Y-%m-%d" }
}
]
@sets = []

[
GlycatedHaemoglobin,
BloodPressure
].each do |model|
metrics = model.all
bucketed_metrics = metrics.group_by { |g| g.datetime.strftime "%Y-%m-%d" }
with_year = begin
metrics.first.datetime.year < Time.now.year
rescue NoMethodError
nil
end

@sets.push({
model: model,
metrics: metrics,
bucketed_metrics: bucketed_metrics,
with_year: with_year
})
end

#This should be dependent on whether there's any data
@no_picker = true;
@with_year = true;
end
end
1 change: 1 addition & 0 deletions app/views/longterm/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<% @model = set[:model] %>
<% @metrics = set[:metrics] %>
<% @bucketed_metrics = set[:bucketed_metrics] %>
<% @with_year = set[:with_year] %>
<%= render partial: 'shared/block' %>
<% end %>

0 comments on commit 107c2f3

Please sign in to comment.