Skip to content

Commit

Permalink
Merge pull request #4963 from galaxyproject/echidna-banded
Browse files Browse the repository at this point in the history
Link to events from a tutorial that's included in those events
  • Loading branch information
shiltemann authored Jun 3, 2024
2 parents 747daa9 + 83f0b2b commit 51ef8bd
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _includes/event-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<td class="eventtable-date"> {{event | collapse_date_pretty }} </td>
<td>

<a class="eventtable-title" href="{% if event.external %}{{event.external}}{% else %}{{site.baseurl}}{{event.url}}{% endif %}">{{event.title}}{% if event.draft %} (draft, will be hidden) {% endif %}</a>
<a class="eventtable-title" href="{% if event.external %}{{event.external}}{% else %}{{site.baseurl}}{{event.url}}{% endif %}{% if include.campaign %}?utm_source=gtn&utm_medium=event-table&utm_campaign={{ include.campaign }}{% endif %}">{{event.title}}{% if event.draft %} (draft, will be hidden) {% endif %}</a>
<div class="eventtable-description"> {{event.description}} </div>
</td>
<td> {{event.location | format_location_short }} </td>
Expand Down
18 changes: 18 additions & 0 deletions _layouts/tutorial_hands_on.html
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,24 @@ <h2 id="funding">{{locale['references']| default: "Funding" }}</h2>
{% endfor %}
</blockquote>




{% assign upcoming_events = site | get_upcoming_events_for_this: new_material %}
{% assign upcoming_event_count = upcoming_events | size %}
{% if upcoming_event_count > 0 %}
<blockquote class="details hide-when-printing" id="upcoming-events">
<div id="upcoming-events-c" class="box-title">
<button type="button" aria-controls="upcoming-events-c" aria-expanded="false">
<i class="fas fa-calendar" aria-hidden="true"></i>
Upcoming events which cover this topic<span role="button" class="fold-unfold fa fa-minus-square" aria-hidden="true"></span>
</button>
</div>

<p>Want to learn more with a live instructor? Check out these upcoming events:</p>
{% include _includes/event-table.html events=upcoming_events campaign="via-tutorial" %}
</blockquote>
{% endif %}

</section>

Expand Down
58 changes: 58 additions & 0 deletions _plugins/gtn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,51 @@ def get_topic(page)
page['path'].split('/')[1]
end

##
# Get the list of 'upcoming' events (i.e. reg deadline or start is 30 days away.)
# Params:
# +site+:: The site object
# Returns:
# +Array+:: List of events
#
# Example:
# {{ site | get_upcoming_events }}
def get_upcoming_events(site)
cache.getset('upcoming-events') do
upcoming_events = site.pages
.select{|p| p.data['layout'] == 'event' || p.data['layout'] == 'event-external' }
.reject{|p| p.data['program'].nil? } # Only those with programs
.select{|p| p.data['event_upcoming'] == true } # Only those coming soon
.map{|p|
materials = p.data['program']
.map{|section| section['tutorials']}
.flatten
.reject{|x| x.nil?} # Remove nil entries
.reject{|x| x.fetch('type', nil) == 'custom'} # Remove custom entries
.map{|x| "#{x['topic']}/#{x['name']}"} # Just the material IDs.
.sort.uniq
[p, materials]
}
end
end


##
# Get the list of 'upcoming' events that include this material's ID
# Params:
# +site+:: The site object
# +material+:: The 'material' to get the topic of, it will inspect page.id (use new_material)
# Returns:
# +Array+:: List of events
#
# Example:
# {{ site | get_upcoming_events }}
def get_upcoming_events_for_this(site, material)
get_upcoming_events(site)
.select{|p, materials| materials.include? material['id']}
.map{|p, materials| p}
end

def shuffle(array)
array.shuffle
end
Expand Down Expand Up @@ -901,6 +946,19 @@ def find_learningpaths_including_topic(site, topic_id)
else
(page.data['date_end'] - page.data['date_start']).to_i + 1
end

# reg deadline
if page.data.key?('registration') && page.data['registration'].key?('deadline')
deadline = page.data['registration']['deadline']
else
deadline = page.data['date_start']
end

# If it's an 'upcoming event'
if deadline - 30 <= Date.today && Date.today <= deadline
page.data['event_upcoming'] = true
end

end
end

Expand Down
7 changes: 4 additions & 3 deletions _plugins/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ def collapse_event_date_pretty(event)
event['date_end']
end
# want dates like "Mar 22-25, 2024" or "Mar 22-May 1, 2024"
dash = " – " # thin space, en dash, thin space
if s.year == e.year
if s.month == e.month
if s.day == e.day
"#{s.strftime('%B')} #{s.day}, #{s.year}"
else
"#{s.strftime('%B')} #{s.day}-#{e.day}, #{s.year}"
"#{s.strftime('%B')} #{s.day}#{dash}#{e.day}, #{s.year}"
end
else
"#{s.strftime('%B')} #{s.day}-#{e.strftime('%B')} #{e.day}, #{s.year}"
"#{s.strftime('%B')} #{s.day}#{dash}#{e.strftime('%B')} #{e.day}, #{s.year}"
end
else
"#{s.strftime('%B')} #{s.day}, #{s.year}-#{e.strftime('%B')} #{e.day}, #{e.year}"
"#{s.strftime('%B')} #{s.day}, #{s.year}#{dash}#{e.strftime('%B')} #{e.day}, #{e.year}"
end
end

0 comments on commit 51ef8bd

Please sign in to comment.