Skip to content

Commit

Permalink
styling of calendar view, separating out long events
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanVanVugt committed Aug 3, 2023
1 parent f4a11ec commit 23b8e7d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
12 changes: 12 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -984,3 +984,15 @@ div {
word-break: break-word;
display: inline-block
}

/* Calendar inset numbers */
td.day {
position: relative;
}
td.day .day-number {
position: absolute;
bottom: 0px;
right: 6px;
font-size: 1.5em;
color: rgb(186, 186, 186);
}
4 changes: 2 additions & 2 deletions app/controllers/concerns/searchable_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module SearchableIndex

included do
attr_reader :facet_fields, :search_params, :facet_params, :page, :sort_by, :index_resources
before_action :set_params, only: [:index, :count]
before_action :fetch_resources, only: [:index, :count]
before_action :set_params, only: [:index, :count, :calendar]
before_action :fetch_resources, only: [:index, :count, :calendar]

helper 'search'
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def index
# GET /events/calendar
# GET /events/calendar.js
def calendar
set_params
fetch_resources
@bioschemas = @events.flat_map(&:to_bioschemas)
# now customize the list by moving all events longer than 3 days into a separate array
@long_events, @events = @events.partition { |e| (e.end - e.start) > 3.days }
respond_to do |format|
format.js
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/events/calendar.js.erb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
$("#events_calendar").html("<%= escape_javascript render("events/partials/calendar", events: @events) %>");
$("#events_calendar").html("<%= escape_javascript render("events/partials/calendar", events: @events) %>");
$("#events_calendar_long_events").html("<%= escape_javascript render("events/partials/calendar_long_events", events: @long_events) %>");
14 changes: 10 additions & 4 deletions app/views/events/partials/_calendar.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<%= month_calendar(events: events, attribute: :start, end_attribute: :end) do |date, events| %>
<%= date.day %>
<div class="day-number">
<%= date.day %>
</div>

<% events.each do |event| %>
<%= link_to "#{event.title} #{l event.start, format: :time_short} - #{l event.end, format: :time_short}", event, class: 'clear-both' %>
<% end %>
<ul class="list-unstyled">
<% events.each do |event| %>
<li>
<%= link_to "#{event.title}", event, class: 'clear-both', 'title': "#{l event.start, format: :time_short} - #{l event.end, format: :time_short}" %>
</li>
<% end %>
</ul>
<% end %>
2 changes: 2 additions & 0 deletions app/views/events/partials/_calendar_loader.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<%= image_tag('ajax-loader2.gif') %>
</div>
</div>
<div id="events_calendar_long_events">
</div>

11 changes: 11 additions & 0 deletions app/views/events/partials/_calendar_long_events.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h4>Long events</h4>
<ul>
<% events.each do |event| %>
<li>
<%= link_to event do %>
<%= event.title %>
<%= l event.start, format: :short %> - <%= l event.end, format: :short %>
<% end %>
</li>
<% end %>
</ul>

0 comments on commit 23b8e7d

Please sign in to comment.