Skip to content

Commit afca250

Browse files
committed
add medication and triggers to headache logs
1 parent dd56628 commit afca250

File tree

7 files changed

+51
-11
lines changed

7 files changed

+51
-11
lines changed

app/controllers/headache_logs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def set_headache_log
7373

7474
# Only allow a list of trusted parameters through.
7575
def headache_log_params
76-
params.require(:headache_log).permit(:start_time, :end_time, :intensity, :notes)
76+
params.require(:headache_log).permit(:start_time, :end_time, :intensity, :notes, :medication, :triggers)
7777
end
7878

7979
def set_share_link

app/views/headache_logs/_form.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
<%= form.number_field :intensity, in: 1..10, class: "mt-1 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" %>
2727
</div>
2828

29+
<div>
30+
<%= form.label :medication, class: "block text-sm font-medium text-gray-700" %>
31+
<%= form.text_field :medication, class: "mt-1 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" %>
32+
</div>
33+
34+
<div>
35+
<%= form.label :triggers, class: "block text-sm font-medium text-gray-700" %>
36+
<%= form.text_area :triggers, class: "mt-1 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" %>
37+
</div>
38+
2939
<div>
3040
<%= form.label :notes, class: "block text-sm font-medium text-gray-700" %>
3141
<%= form.text_area :notes, class: "mt-1 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" %>

app/views/headache_logs/_headache_log.html.erb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
<p class="font-semibold">Start Time: <%= headache_log.start_time.strftime("%B %d, %Y at %I:%M %p") %></p>
44
<p>End Time: <%= headache_log.end_time&.strftime("%B %d, %Y at %I:%M %p") || "Ongoing" %></p>
55
<p>Intensity: <span class="font-bold"><%= headache_log.intensity %></span></p>
6-
<p>Notes: <%= headache_log.notes %></p>
6+
<% if headache_log.medication.present? %>
7+
<p>Medication: <%= headache_log.medication %></p>
8+
<% end %>
9+
<% if headache_log.triggers.present? %>
10+
<p>Triggers: <%= headache_log.triggers %></p>
11+
<% end %>
12+
<% if headache_log.notes.present? %>
13+
<p>Notes: <%= headache_log.notes %></p>
14+
<% end %>
715
<div class="mt-2">
816
<%= link_to "Edit", edit_headache_log_path(headache_log), class: "text-blue-500 hover:text-blue-700 mr-2" %>
9-
<%= link_to "Delete", headache_log_path(headache_log), data: { turbo_method: :delete, turbo_confirm: "Are you sure?" }, class: "text-red-500 hover:text-red-700" %>
17+
<%= button_to "Delete", headache_log_path(headache_log), method: :delete, data: { turbo_confirm: "Are you sure?" }, class: "text-red-500 hover:text-red-700" %>
1018
</div>
1119
</div>
1220
<% end %>

app/views/headache_logs/show.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
<p><strong class="font-semibold">Start time:</strong> <%= @headache_log.start_time.strftime("%B %d, %Y at %I:%M %p") %></p>
77
<p><strong class="font-semibold">End time:</strong> <%= @headache_log.end_time&.strftime("%B %d, %Y at %I:%M %p") || "Ongoing" %></p>
88
<p><strong class="font-semibold">Intensity:</strong> <%= @headache_log.intensity %></p>
9+
<% if @headache_log.medication.present? %>
10+
<p><strong class="font-semibold">Medication:</strong> <%= @headache_log.medication %></p>
11+
<% end %>
12+
<% if @headache_log.triggers.present? %>
13+
<p><strong class="font-semibold">Triggers:</strong> <%= @headache_log.triggers %></p>
14+
<% end %>
915
<p><strong class="font-semibold">Notes:</strong> <%= @headache_log.notes %></p>
1016
</div>
1117

app/views/shared_logs/show.html.erb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<div class="container mx-auto px-4 py-8">
22
<h1 class="text-2xl font-bold mb-4">Headache Logs for <%= @user.email %></h1>
3-
3+
44
<div class="space-y-4">
5-
<% @headache_logs.each do |log| %>
6-
<div class="bg-white shadow rounded-lg p-4">
7-
<p class="font-semibold">Start Time: <%= log.start_time.strftime("%B %d, %Y at %I:%M %p") %></p>
8-
<p>End Time: <%= log.end_time&.strftime("%B %d, %Y at %I:%M %p") || "Ongoing" %></p>
9-
<p>Intensity: <span class="font-bold"><%= log.intensity %></span></p>
10-
<p>Notes: <%= log.notes %></p>
5+
<% @headache_logs.each do |headache_log| %>
6+
<div class="bg-white p-4 rounded-lg shadow mb-4">
7+
<p class="font-semibold">Start Time: <%= headache_log.start_time.strftime("%B %d, %Y at %I:%M %p") %></p>
8+
<p>End Time: <%= headache_log.end_time&.strftime("%B %d, %Y at %I:%M %p") || "Ongoing" %></p>
9+
<p>Intensity: <span class="font-bold"><%= headache_log.intensity %></span></p>
10+
<% if headache_log.medication.present? %>
11+
<p>Medication: <%= headache_log.medication %></p>
12+
<% end %>
13+
<% if headache_log.triggers.present? %>
14+
<p>Triggers: <%= headache_log.triggers %></p>
15+
<% end %>
16+
<% if headache_log.notes.present? %>
17+
<p>Notes: <%= headache_log.notes %></p>
18+
<% end %>
1119
</div>
1220
<% end %>
1321
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddMedicationAndTriggersToHeadacheLogs < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :headache_logs, :medication, :string
4+
add_column :headache_logs, :triggers, :text
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)