Skip to content

Commit

Permalink
[NU-17] Show different color for current instrument in shared calendar (
Browse files Browse the repository at this point in the history
#5061)

* Show different color for current instrument in shared calendar

* Ignore admin holds for other instrument coloring

* Refactor calendar colors

* Only allow admins to discriminate shared calendar events

* Add specs

* Remove debugger

* Prevent conflicts between test reservations
  • Loading branch information
joaquinco authored Mar 7, 2025
1 parent 6706cdd commit 64c080a
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 12 deletions.
45 changes: 38 additions & 7 deletions app/assets/stylesheets/calendar/fullcalendar.extensions.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
.unavailable,
.fc-agenda .unavailable .fc-event-time,
.unavailable a {
background-color: #aaaaaa;
border-color: #DBDBDB;
color: #fff;
// Colors taken from google calendar which presumably
// follow accessibility good practices
$event-color: #039be5;
$event-color2: #c2c2c2;
$event-color3: #f6bf26;
$event-color4: #7cb342;

$event-text-color: white;

.fc-event {
background-color: $event-color;
border-color: $event-color;
color: $event-text-color;
transition: box-shadow 50ms linear;

&:hover {
color: $event-text-color;
box-shadow: 0px 6px 10px 0px rgba(0,0,0,.14),0px 1px 18px 0px rgba(0,0,0,.12),0px 3px 5px -1px rgba(0,0,0,.2);
}
}

.fc-bgevent.unavailable, // Monthly view unavailable days
.fc-agenda.fc-event-time.unavailable,
.fc-event.unavailable {
background-color: $event-color2;
border-color: $event-color2;

&:hover {
box-shadow: none;
}
}


.fc-event.other-instrument {
background-color: $event-color3;
border-color: $event-color3;
}

.fc-event.current-event {
background: #378006;
background-color: $event-color4;
border-color: $event-color4;
}

#overlay.on #spinner #hide {
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/reservations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def index

@show_details = params[:with_details] == "true" && (@instrument.show_details? || can?(:administer, Reservation))

discriminate = params[:discriminate] == "true" && can?(:administer, Reservation)

respond_to do |format|
format.js do
render(
Expand All @@ -70,6 +72,7 @@ def index
start_at: @start_at,
end_at: @end_at,
with_details: @show_details,
discriminate:,
view: params[:view]
).to_json
)
Expand Down
6 changes: 2 additions & 4 deletions app/presenters/calendar_events_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ def reservation_events

def calendar_opts
{
start_at:,
end_at:,
with_details: params[:with_details],
}
start_at:, end_at:, instrument_id: instrument.id,
}.merge(params.slice(:with_details, :discriminate))
end

def monthly_view?
Expand Down
6 changes: 6 additions & 0 deletions app/presenters/reservations/calendar_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class OrderCalendarPresenter < CalendarPresenter
def as_calendar_object(options = {})
ret = super

if options[:discriminate] && options[:instrument_id].present? && product_id != options[:instrument_id]
ret[:className] = "other-instrument"
end

return ret if options[:with_details].blank?

ret.merge(
Expand All @@ -60,8 +64,10 @@ def as_calendar_object(_options = {})
if expires_mins_before.present?
hash[:expiration] = "Expires #{MinutesToTimeFormatter.new(expires_mins_before)} prior"
end

hash[:className] = "unavailable" if __getobj__.is_a?(AdminReservation)
end
end
end

end
2 changes: 1 addition & 1 deletion app/views/instruments/schedule.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
= render "admin/shared/tabnav_product", secondary_tab: "reservations"

:javascript
var events_path = "#{calendar_events_path(current_facility, @product, with_details: true)}";
var events_path = "#{calendar_events_path(current_facility, @product, with_details: true, discriminate: true)}";
var orders_path_base = "#{facility_orders_path(current_facility)}";
var dailyBooking = #{@product.daily_booking?};

Expand Down
32 changes: 32 additions & 0 deletions spec/controllers/reservations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@
expect(assigns[:instrument]).to eq(instrument)
end

context "when discriminate=true" do
before do
@params[:discriminate] = true
end

it "does not allow non admin user" do
sign_in create(:user)

expect(CalendarEventsPresenter).to receive(:new).with(
anything,
anything,
anything,
a_hash_including(discriminate: false)
)

do_request
end

it "allow admin user" do
sign_in create(:user, :administrator)

expect(CalendarEventsPresenter).to receive(:new).with(
anything,
anything,
anything,
a_hash_including(discriminate: true)
)

do_request
end
end

describe "start/stop parameters" do
let(:start_range) { Time.zone.local(2018, 5, 15, 12, 13) }
let(:end_range) { start_range + 1.week }
Expand Down
55 changes: 55 additions & 0 deletions spec/system/admin/instrument_reservations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "instrument reservations" do
describe "shared schedule", :js do
let(:admin) { create(:user, :administrator) }
let!(:instrument) { create(:setup_instrument, :always_available) }
let!(:instrument2) do
create(
:setup_instrument,
:always_available,
facility:,
schedule: instrument.schedule
)
end
let(:facility) { instrument.facility }
let!(:reservation2) do
end

before do
# Use actual current time so
# loaded reservations are correct
travel_back

login_as admin
create(
:purchased_reservation,
reserve_start_at: 2.hours.from_now,
reserve_end_at: 3.hours.from_now,
product: instrument
)
end

it "show current instrument reservation with default color" do
visit facility_instrument_schedule_path(facility, instrument)

expect(page).to have_css(".fc-event")
expect(page).not_to have_css(".fc-event.other-instrument")
end

it "shows other instrument reservations with different color" do
create(
:purchased_reservation,
reserve_start_at: Time.zone.now,
reserve_end_at: 1.hour.from_now,
product: instrument2
)

visit facility_instrument_schedule_path(facility, instrument)

expect(page).to have_css(".fc-event.other-instrument")
end
end
end

0 comments on commit 64c080a

Please sign in to comment.