Skip to content

Commit 4b629bc

Browse files
rafbgarciagregblake
authored andcommitted
List member's appointments
1 parent 04a08b3 commit 4b629bc

File tree

9 files changed

+141
-14
lines changed

9 files changed

+141
-14
lines changed

app/controllers/appointments_controller.rb

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class AppointmentsController < ApplicationController
2+
def index
3+
@appointments = current_user.member.appointments.upcoming.includes(:member, :holds, :loans)
4+
end
5+
26
def new
37
@holds = Hold.active.where(member: current_user.member)
48
@loans = current_user.member.loans.includes(:item).checked_out
@@ -19,7 +23,7 @@ def create
1923
end
2024

2125
if @appointment.save
22-
redirect_to appointment_path(@appointment), notice: "Appointment was successfully created."
26+
redirect_to appointments_path, notice: "Appointment was successfully created."
2327
else
2428
render :new, alert: @appointment.errors.full_messages
2529
end
@@ -29,12 +33,6 @@ def edit
2933
@appointment = Appointment.find(params[:id])
3034
end
3135

32-
def show
33-
@appointment = Appointment.includes(:member, :holds).find(params[:id])
34-
@starts_at = @appointment.starts_at
35-
@ends_at = @appointment.ends_at
36-
end
37-
3836
private
3937

4038
def appointment_params
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.appointments-page {
2+
.appointment {
3+
margin-top: 50px;
4+
h2 {
5+
font-size: 24px;
6+
}
7+
section {
8+
margin-top: 20px;
9+
}
10+
.gray-dark {
11+
color: $gray-color-dark;
12+
}
13+
.appointment-date {
14+
display: flex;
15+
align-items: start;
16+
h2:first-child {
17+
margin-right: 10px;
18+
}
19+
}
20+
.appointment-wrapper {
21+
padding-left: 30px;
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@import './users_password_new';
22
@import './users_sign_in';
33
@import './member_navbar';
4+
@import './appointments';

app/models/appointment.rb

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Appointment < ApplicationRecord
99

1010
validate :ends_at_later_than_starts_at
1111

12+
scope :upcoming, -> { where("starts_at > ?", Time.zone.now).order(:starts_at) }
13+
1214
private
1315

1416
def ends_at_later_than_starts_at

app/views/appointments/edit.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
<% content_for :header do %>
2+
<%= index_header "Editting Appointment" %>
3+
<% end %>
4+
5+
<h1 class="new_title">Schedule an Appointment</h1>
6+
17
<%= render partial: "form", locals: { holds: @appointment.holds, time_range_string: (@appointment.starts_at..@appointment.ends_at).to_s } %>

app/views/appointments/index.html.erb

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<div class="appointments-page">
2+
<h1 class="new_title">Upcoming Appointments</h1>
3+
4+
<% @appointments.each_with_index do |appointment, index| %>
5+
<section class="appointment">
6+
<div class="appointment-date">
7+
<h2 class="title_bold"><%= index + 1 %>.</h2>
8+
<h2 class="title_bold">
9+
<%= appointment.starts_at.strftime("%a") %>
10+
11+
<%= appointment.starts_at.strftime("%b %-d, %Y") %>
12+
<br />
13+
<small class="gray-dark"><%= "#{appointment.starts_at.strftime("%I:%M%P")} - #{appointment.ends_at.strftime("%I:%M%P")}" %></small>
14+
</h2>
15+
</div>
16+
17+
<div class="appointment-wrapper">
18+
<section>
19+
<h3 class="title_bold">Here's what you're returning</h3>
20+
21+
<% if appointment.loans.any? %>
22+
<table class="table table-scroll mb-2" id="items-to-pickup-table">
23+
<thead>
24+
<tr>
25+
<th class="caption">Image</th>
26+
<th class="caption">Item</th>
27+
<th class="caption">Inventory Number</th>
28+
<th class="caption">Due Date</th>
29+
<th class="caption">Status</th>
30+
</tr>
31+
</thead>
32+
33+
<tbody>
34+
<% appointment.loans.each do |loan| %>
35+
<tr>
36+
<td>
37+
<%= link_to item_path(loan.item) do %>
38+
<% if loan.item.image.attached? %>
39+
<%= image_tag url_for(rotated_variant(loan.item.image, resize_to_limit: [200, 140])), class: "p-centered" %>
40+
<% end %>
41+
<% end %>
42+
</td>
43+
<td><%= link_to loan.item.name, item_path(loan.item) %></td>
44+
<td><%= loan.item.complete_number %></td>
45+
<td class=<%= loan.due_at - Time.now < 3.days ? "warning" : "" %>><%= "Due #{humanize_due_date(loan)}" %></td>
46+
<td><%= loan.status %></td>
47+
</tr>
48+
<% end %>
49+
</tbody>
50+
</table>
51+
<% else %>
52+
No items to return
53+
<% end %>
54+
</section>
55+
56+
<section>
57+
<h3 class="title_bold">Here's what you're picking up</h3>
58+
59+
<table class="table table-scroll" id="items-to-pickup-table">
60+
<thead>
61+
<tr>
62+
<th class="caption">Image</th>
63+
<th class="caption">Item</th>
64+
<th class="caption">Inventory Number</th>
65+
<th class="caption">Status</th>
66+
</tr>
67+
</thead>
68+
69+
<tbody>
70+
<% appointment.holds.each do |hold| %>
71+
<tr>
72+
<td>
73+
<%= link_to item_path(hold.item) do %>
74+
<% if hold.item.image.attached? %>
75+
<%= image_tag url_for(rotated_variant(hold.item.image, resize_to_limit: [200, 140])), class: "p-centered" %>
76+
<% end %>
77+
<% end %>
78+
</td>
79+
<td><%= link_to hold.item.name, item_path(hold.item) %></td>
80+
<td><%= hold.item.complete_number %></td>
81+
<td><%= render_place_in_queue(hold) %></td>
82+
</tr>
83+
<% end %>
84+
</tbody>
85+
</table>
86+
</section>
87+
88+
<% if appointment.comment.present? %>
89+
<section>
90+
<label class="form-label">What kind of project are you working on?</label>
91+
<%= appointment.comment %>
92+
</section>
93+
<% end %>
94+
95+
<section>
96+
<%= button_to "Edit this Appointment", edit_appointment_path(appointment.id), class: "btn btn-primary btn-sm", method: :get %>
97+
</section>
98+
</div>
99+
</section>
100+
<% end %>
101+
</div>

app/views/appointments/new.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% content_for :header do %>
2-
<%= index_header "Appointments" %>
2+
<%= index_header "Schedule an Appointment" %>
33
<% end %>
44

55
<h1 class="new_title">Schedule an Appointment</h1>

app/views/appointments/show.html.erb

-5
This file was deleted.

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
get "/", to: "dashboard#index", as: "dashboard"
108108
end
109109

110-
resources :appointments, only: [:new, :create, :show, :edit]
110+
resources :appointments, only: [:index, :new, :create, :edit]
111111

112112
get "/s/:id", to: "short_links#show", as: :short_link
113113

0 commit comments

Comments
 (0)