Skip to content

Commit

Permalink
Merge pull request #148 from lsa-mis/LRA-969-room-ready-show-last-roo…
Browse files Browse the repository at this point in the history
…m-update-log-entry

Lra 969 room ready show last RoomUpdateLog entry
  • Loading branch information
britaumich authored Jul 10, 2024
2 parents 2425c9b + 10acad2 commit 18a7aeb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def welcome_rovers

def dashboard
authorize :static_page
@room_update_log = RoomUpdateLog.last

@selected_date = params[:dashboard_date].present? ? Date.parse(params[:dashboard_date]) : Date.today

@latest_tickets = latest_room_tickets
Expand Down
3 changes: 3 additions & 0 deletions app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ def total_rooms(zone)
.count
end

def room_update_log_status(log_note)
log_note.split("|").first.strip
end
end
37 changes: 37 additions & 0 deletions app/views/static_pages/_last_room_update_log.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="col-lg-4 col-md-6 col-sm-12 mb-3">
<div class="card">
<div class="card-header">
<h3>Resources Script</h3>
</div>
<div class="card-body">
<h6 class="card-text mb-4">Last Run at: <%= show_date_with_time(last_room_update_log.created_at) %></h6>
<h6 class="card-text mb-4">
Status:
<span
class="<%= room_update_log_status(last_room_update_log.note) == 'error' ? 'text-danger' : 'text-success' %>">
<%= last_room_update_log.note.include?('success') ? 'SUCCESS' : 'ERROR' %>
</span>
</h6>

<h6 class="card-text mb-4">
Note:
<% if room_update_log_status(last_room_update_log.note) == 'success' %>
Resources updated successfully for rooms.
<% elsif room_update_log_status(last_room_update_log.note) == 'success-partial' %>
Resources updated successfully for rooms.
<a class="text-primary" data-bs-toggle="collapse" href="#nonExistingRooms" role="button" aria-expanded="false" aria-controls="nonExistingRooms">
These
</a>
rooms (rmrecnbr) don't exist in WebCheckout.
<div class="collapse" id="nonExistingRooms">
<div class="card card-body">
<%= last_room_update_log.note.split(':').last.strip %>
</div>
</div>
<% elsif room_update_log_status(last_room_update_log.note) == 'error' %>
An error occurred while updating resources for rooms. Please report an issue.
<% end %>
</h6>
</div>
</div>
</div>
8 changes: 6 additions & 2 deletions app/views/static_pages/dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<% end %>


<h2>Zone Overview</h2>
<div class="row">
<% @zones.each do |zone| %>
Expand Down Expand Up @@ -83,5 +83,9 @@
</div>
<% end %>
</div>
<hr>
<hr>
<h2>Daily Resource Update Script</h2>
<% if @room_update_log %>
<%= render 'last_room_update_log', last_room_update_log: @room_update_log %>
<% end %>
</div>
8 changes: 4 additions & 4 deletions lib/tasks/update_resources.rake
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ task update_resources: :environment do
end
end

raise "Transaction failed, error updating resources: #{transaction_error.message}" unless transaction_succeeded
raise "Transaction failed, error updating resources: #{transaction_error}" unless transaction_succeeded

if rooms_to_update.any?
# these rooms were not updated because they don't eexist in wco
list = Room.where(rmrecnbr: rooms_to_update).pluck(:rmrecnbr).join(", ")
note = "Resources updated successfully for rooms. The following rooms don't exist in WebCheckout database: #{list}"
RoomUpdateLog.create(date: Date.today, note: note)
RoomUpdateLog.create(date: Date.today, note: "success-partial | #{note}")
else
RoomUpdateLog.create(date: Date.today, note: "Resources updated successfully for all rooms")
RoomUpdateLog.create(date: Date.today, note: "success | Resources updated successfully for all rooms")
end
rescue StandardError => e
RoomUpdateLog.create(date: Date.today, note: e)
RoomUpdateLog.create(date: Date.today, note: "error | #{e}")
end
end

Expand Down

0 comments on commit 18a7aeb

Please sign in to comment.