Skip to content

Commit e747622

Browse files
committed
Handle deleting appointments; fixes #2929:
1 parent fdf0716 commit e747622

File tree

7 files changed

+61
-9
lines changed

7 files changed

+61
-9
lines changed

app/components/aeon/appointment_component.html.erb

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
<%= link_to edit_aeon_appointment_path(appointment.id), data: { action: 'modal#open' } do %>
55
<i class="bi bi-pencil-fill me-1"></i>Edit appointment
66
<% end %>
7-
<%= link_to aeon_appointment_path(appointment.id), data: { turbo_method: :delete }, aria: { label: 'Delete'} do %>
8-
<i class="bi bi-trash"></i>
9-
<% end %>
7+
<% if helpers.can? :destroy, appointment %>
8+
<button class="btn btn-link su-underline p-0" data-bs-toggle="modal" data-bs-target="#delete-appointment-<%= @appointment.id %>">
9+
<i class="bi bi-trash align-middle"></i><span class="visually-hidden">Delete appointment</span>
10+
</button>
11+
<% end %>
1012
</div>
1113
<div class="card-body">
1214
<% if appointment.requests.present? %>
@@ -40,4 +42,31 @@
4042
</div>
4143
<% end %>
4244
</div>
45+
<!-- Delete modal -->
46+
<div class="modal fade" id="delete-appointment-<%= appointment.id %>" tabindex="-1" aria-labelledby="title-appointment-<%= appointment.id %>" aria-hidden="true">
47+
<div class="modal-dialog modal-dialog-centered">
48+
<div class="modal-content">
49+
<div class="modal-header">
50+
<h2 class="modal-title" id="title-appointment-<%= appointment.id %>">Delete appointment?</h2>
51+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
52+
</div>
53+
<div class="modal-body fw-normal">
54+
<div class="mb-2"><%= appointment.reading_room.name %></div>
55+
<div class="my-2"><i class="bi bi-calendar me-2"></i><%= appointment_date %><i class="bi bi-clock mx-2"></i><%= appointment_time_range %></div>
56+
<% if appointment.requests.any? %>
57+
<p class="mb-0">
58+
<%= pluralize(appointment.requests.length, 'requested item') %> are assigned to this appointment. If you cancel or delete the appointment, the items will not be deleted.
59+
Instead, they will be moved to <strong>Draft requests</strong>.
60+
</p>
61+
<% end %>
62+
</div>
63+
<div class="modal-footer">
64+
<button type="button" class="btn btn-outline-primary" data-bs-dismiss="modal">No</button>
65+
<%= form_with url: aeon_appointment_path(appointment.id), method: 'delete' do %>
66+
<button type="submit" class="btn btn-primary" data-bs-dismiss="modal">Yes - Delete</button>
67+
<% end %>
68+
</div>
69+
</div>
70+
</div>
71+
</div>
4372
</div>

app/components/aeon/appointment_component.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ def appointment_time_range
1616

1717
"#{start} - #{stop} (#{appointment.start_time.zone})"
1818
end
19+
20+
def appointment_date
21+
appointment.start_time.strftime('%b %-d, %Y')
22+
end
1923
end
2024
end

app/components/aeon/request_actions_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<% end %>
1111
<% end %>
1212
<% if helpers.can? :destroy, request %>
13-
<button class="btn btn-link su-underline p-0" type="submit" data-bs-toggle="modal" data-bs-target="#delete-<%= transaction_number %>">
13+
<button class="btn btn-link su-underline p-0" data-bs-toggle="modal" data-bs-target="#delete-<%= transaction_number %>">
1414
<i class="bi bi-trash align-middle"></i><span class="visually-hidden">Delete <%= title %> request</span>
1515
</button>
1616
<% end %>

app/controllers/aeon_appointments_controller.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ def update # rubocop:disable Metrics/AbcSize
8181
redirect_to aeon_appointments_path, notice: 'Appointment created successfully'
8282
end
8383

84-
def destroy
84+
def destroy # rubocop:disable Metrics/AbcSize
8585
authorize! :delete, @appointment
86-
AeonClient.new.cancel_appointment(params[:id])
86+
87+
@appointment.requests.each do |request|
88+
aeon_client.update_request(request.transaction_number, AeonClient::DeleteAppointmentRequestData.new)
89+
aeon_client.update_request_route(transaction_number: request.transaction_number,
90+
status: Settings.aeon.queue_names.draft.transaction.first)
91+
end
92+
aeon_client.cancel_appointment(params[:id])
8793

8894
redirect_to aeon_appointments_path, notice: 'Appointment cancelled successfully'
8995
end

app/controllers/aeon_requests_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def submitted
3131
def resubmit
3232
authorize! :update, @aeon_request
3333

34-
AeonClient.new.update_request_route(transaction_number: params[:id], status: 'Submitted by User')
34+
aeon_client.update_request_route(transaction_number: params[:id], status: 'Submitted by User')
3535
respond_to do |format|
3636
format.turbo_stream { render turbo_stream: turbo_stream.remove("request-#{params[:id]}") }
3737
end
@@ -46,7 +46,7 @@ def edit
4646
def update # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
4747
authorize! :update, @aeon_request
4848

49-
new_request = AeonClient.new.update_request(
49+
new_request = aeon_client.update_request(
5050
@aeon_request.transaction_number,
5151
AeonClient::RequestData.with_defaults.with(
5252
appointment_id: aeon_request_params[:appointment_id]&.to_i,
@@ -68,7 +68,7 @@ def update # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
6868
def destroy
6969
authorize! :destroy, @aeon_request
7070

71-
AeonClient.new.update_request_route(transaction_number: params[:id], status: 'Cancelled by User')
71+
aeon_client.update_request_route(transaction_number: params[:id], status: 'Cancelled by User')
7272
respond_to do |format|
7373
format.turbo_stream { render turbo_stream: turbo_stream.remove(@aeon_request) }
7474
end

app/controllers/concerns/aeon_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ module AeonController
1111
def current_ability
1212
@current_ability ||= SiteAbility.new(current_user).merge(AeonAbility.new(current_user.aeon))
1313
end
14+
15+
def aeon_client
16+
@aeon_client ||= AeonClient.new
17+
end
1418
end

app/services/aeon_client.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ def self.with_defaults
188188
end
189189
end
190190

191+
# Special payload for removing an appointment from a request
192+
class DeleteAppointmentRequestData
193+
def as_patch_json
194+
[
195+
{ op: 'remove', path: '/appointmentId' }
196+
]
197+
end
198+
end
199+
191200
private
192201

193202
def get(path, params: nil)

0 commit comments

Comments
 (0)