Skip to content

Commit

Permalink
Merge pull request #4749 from galaxyproject/rove-blenny
Browse files Browse the repository at this point in the history
misc small bugs
  • Loading branch information
hexylena authored Feb 21, 2024
2 parents 94b7384 + 8b47aa9 commit 0fde6e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion _layouts/tutorial_hands_on.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ <h4 class="alert-heading">Under Development!</h4>

{% assign feedback_count = site | get_feedback_count: own_material_id %}
{% if feedback_count > 0 %}
<div><strong>{% icon rating %} Rating:</strong> <a href="#feedback-responses">{{ site | get_rating:own_material_id }}</a> ({{ site | get_feedback_count: own_material_id }} ratings)</div>
<div><strong>{% icon rating %} Rating:</strong> <a href="#feedback-responses">{{ site | get_rating_recent:own_material_id }}</a> ({{ site | get_feedback_count_recent: own_material_id }} recent ratings, {{ feedback_count }} all time)</div>
{% endif %}
<div><strong>{% icon version %} Revision:</strong> {{ page | get_version_number }} </div>

Expand Down
35 changes: 29 additions & 6 deletions _plugins/gtn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ def get_version_number(page)
Gtn::ModificationTimes.obtain_modification_count(page['path'])
end

def get_rating_histogram(site, material_id)
def get_rating_histogram(site, material_id, recent: false)
return {} if material_id.nil?

feedbacks = get_feedbacks(site, material_id)
feedbacks = recent ? get_recent_feedbacks_time(site, material_id) : get_feedbacks(site, material_id)

return {} if feedbacks.nil? || feedbacks.empty?

Expand All @@ -398,12 +398,17 @@ def get_rating_histogram_chart(site, material_id)
.to_h
end

def get_rating(site, material_id)
f = get_rating_histogram(site, material_id)
def get_rating(site, material_id, recent: false)
f = get_rating_histogram(site, material_id, recent: recent)
rating = f.map { |k, v| k * v }.sum / f.map { |_k, v| v }.sum.to_f
rating.round(1)
end

def get_rating_recent(site, material_id)
r = get_rating(site, material_id, recent: true)
r.nan? ? get_rating(site, material_id, recent: false) : r
end

# Only accepts an integer rating
def to_stars(rating)
if rating.nil? || (rating.to_i < 1) || (rating == '0') || rating.zero?
Expand Down Expand Up @@ -453,6 +458,24 @@ def get_feedback_count(site, material_id)
get_feedbacks(site, material_id).length
end

def get_feedback_count_recent(site, material_id)
get_recent_feedbacks_time(site, material_id).length
end

def get_recent_feedbacks_time(site, material_id)
feedbacks = get_feedbacks(site, material_id)
.select do |f|
f['pro']&.length&.positive? ||
f['con']&.length&.positive?
end
.map do |f|
f['f_date'] = Date.parse(f['date']).strftime('%B %Y')
f
end

feedbacks.select { |f| Date.parse(f['date']) > Date.today - 365 }
end

def get_recent_feedbacks(site, material_id)
feedbacks = get_feedbacks(site, material_id)
.select do |f|
Expand Down Expand Up @@ -580,9 +603,9 @@ def get_og_title(site, page, reverse)
Jekyll.logger.debug "Material #{page['layout']} :: #{page['path']} => #{topic_id}/#{material_id} => #{og_title}"

if reverse.to_s == 'true'
og_title.compact.reverse.join(' / ')
og_title.compact.reverse.join(' / ').gsub(/Hands-on: Hands-on:/, 'Hands-on:')
else
og_title.compact.join(' / ')
og_title.compact.join(' / ').gsub(/Hands-on: Hands-on:/, 'Hands-on:')
end
end

Expand Down
7 changes: 4 additions & 3 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ var clipboardSnippets=new ClipboardJS('[data-clipboard-snippet]',{

// Cited blockquotes
document.querySelectorAll("blockquote[cite],blockquote[author]").forEach(bq => {
var url = bq.getAttribute("cite") ? `<cite class="text-muted"><a href="${url}"><i>Source</i></a></cite>` : "";
var author = bq.getAttribute("author") ? "— " + bq.getAttribute("author") + " " : "";
bq.insertAdjacentHTML("beforeend", `<footer>${author}${url}</footer>`)
let bq_cite = bq.getAttribute("cite");
let bq_url = bq_cite ? `<cite class="text-muted"><a href="${bq_cite}"><i>Source</i></a></cite>` : "";
let bq_author = bq.getAttribute("author") ? "— " + bq.getAttribute("author") + " " : "";
bq.insertAdjacentHTML("beforeend", `<footer>${bq_author}${bq_url}</footer>`)
})

0 comments on commit 0fde6e7

Please sign in to comment.