Skip to content

Commit

Permalink
add participations icons on threshold awards for activity
Browse files Browse the repository at this point in the history
  • Loading branch information
vol1ura committed Jan 12, 2025
1 parent 0b68b04 commit ca23f65
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/jobs/athletes_awarding_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def minute_bingo_awarding!(athlete)
tt_sec = @activity.results.where(athlete_id: athlete.id).pick(:total_time).sec
athlete_seconds = athlete.stats.dig('results', 'seconds') || []
if athlete_seconds.exclude?(tt_sec)
athlete.update!(stats: athlete.stats.deep_merge('results' => { 'seconds' => athlete_seconds.push(tt_sec).sort }))
athlete_seconds << tt_sec
athlete.update!(stats: athlete.stats.deep_merge('results' => { 'seconds' => athlete_seconds.sort }))
end
athlete.trophies.create! badge: minute_bingo_badge, date: activity_date if (ALL_SECONDS - athlete_seconds).empty?
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/badge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def self.dataset_of(kind:, type:)
public_send(:"#{kind}_kind").where("info->>'type' = ?", type).order(Arel.sql("info->'threshold'"))
end

def self.participating_thresholds
@participating_thresholds ||=
%i[result volunteer].index_with do |type|
dataset_of(kind: :participating, type: type).pluck(:info).pluck('threshold')
end
end

def self.ransackable_attributes(_auth_object = nil)
%w[kind name received_date]
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def self.authorized_for(user)
where(id: user.permissions.where(subject_class: 'Activity').select(:event_id))
end

def almost_jubilee_athletes_dataset(type, delta = 1, thresholds = nil)
thresholds ||= Badge.dataset_of(kind: :participating, type: type.singularize).pluck(:info).pluck('threshold')
def almost_jubilee_athletes_dataset(type, delta = 1)
thresholds = Badge.participating_thresholds[type.singularize.to_sym].map { |x| x - delta }
ds =
athletes
.where("(stats->?->'count')::integer in (?)", type, thresholds.map { |x| x - delta })
.where("(stats->?->'count')::integer in (?)", type, thresholds)
.order(Arel.sql("stats->?->'count' DESC, updated_at DESC", type))
return ds if delta > 1 || ds.present?

almost_jubilee_athletes_dataset(type, delta.next, thresholds)
almost_jubilee_athletes_dataset(type, delta.next)
end

def to_combobox_display
Expand Down
8 changes: 8 additions & 0 deletions app/views/_badge_icon.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span class="position-relative d-inline-block px-2" style="margin-bottom: 0.35rem" aria-hidden="true" title="<%= label %>">
<svg class="<%= icon_class %> position-absolute top-50 start-50 translate-middle" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="width: 1rem;">
<path fill="currentColor" d="M211 7.3C205 1 196-1.4 187.6 .8s-14.9 8.9-17.1 17.3L154.7 80.6l-62-17.5c-8.4-2.4-17.4 0-23.5 6.1s-8.5 15.1-6.1 23.5l17.5 62L18.1 170.6c-8.4 2.1-15 8.7-17.3 17.1S1 205 7.3 211l46.2 45L7.3 301C1 307-1.4 316 .8 324.4s8.9 14.9 17.3 17.1l62.5 15.8-17.5 62c-2.4 8.4 0 17.4 6.1 23.5s15.1 8.5 23.5 6.1l62-17.5 15.8 62.5c2.1 8.4 8.7 15 17.1 17.3s17.3-.2 23.4-6.4l45-46.2 45 46.2c6.1 6.2 15 8.7 23.4 6.4s14.9-8.9 17.1-17.3l15.8-62.5 62 17.5c8.4 2.4 17.4 0 23.5-6.1s8.5-15.1 6.1-23.5l-17.5-62 62.5-15.8c8.4-2.1 15-8.7 17.3-17.1s-.2-17.4-6.4-23.4l-46.2-45 46.2-45c6.2-6.1 8.7-15 6.4-23.4s-8.9-14.9-17.3-17.1l-62.5-15.8 17.5-62c2.4-8.4 0-17.4-6.1-23.5s-15.1-8.5-23.5-6.1l-62 17.5L341.4 18.1c-2.1-8.4-8.7-15-17.1-17.3S307 1 301 7.3L256 53.5 211 7.3z"></path>
</svg>
<span class="fw-semibold text-white position-absolute top-50 start-50 translate-middle z-1" aria-hidden="true" style="font-size: 0.4rem;">
<%= label %>
</span>
</span>
9 changes: 7 additions & 2 deletions app/views/activities/_result.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% results_count = @results_count[result.athlete_id] %>

<%= tag.tr data: { male: result.athlete&.male } do %>
<td class="position align-middle"><%= result.position %></td>
<td>
Expand All @@ -6,7 +8,7 @@
<%= link_to result.athlete.name.presence || t('common.nobody'), result.athlete, class: 'athlete-link' %>
</div>
<div class="athlete-details fw-lighter">
<%= t '.total_runs_html', count: @results_count[result.athlete_id] %>
<%= t '.total_runs_html', count: results_count %>
<% if @volunteering_r_count[result.athlete_id] %>
<div class="vr"></div>
<%= t '.total_volunteering_html', count: @volunteering_r_count[result.athlete_id] %>
Expand All @@ -20,10 +22,13 @@
<% if result.personal_best %>
<%= tag.i class: 'fa-solid fa-bolt text-primary', title: t('.personal_best') %>
<% end %>
<% if Badge.participating_thresholds[:result].include?(results_count) %>
<%= render partial: '/badge_icon', locals: { label: results_count, icon_class: 'text-primary' } %>
<% end %>
<% if result.first_run %>
<%=
tag.i(
class: ['fa-solid fa-heart', @results_count[result.athlete_id] == 1 ? 'text-success' : 'text-primary'],
class: ['fa-solid fa-heart', results_count == 1 ? 'text-success' : 'text-primary'],
title: t('.first_run'),
)
%>
Expand Down
10 changes: 7 additions & 3 deletions app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,23 @@
</thead>
<tbody class="table-group-divider">
<% @volunteers.each do |volunteer| %>
<% volunteering_count = @volunteering_v_count[volunteer.athlete_id] %>
<tr>
<td>
<div>
<%= link_to volunteer.name, athlete_path(volunteer.athlete), class: 'athlete-link' %>
</div>
<div class="athlete-details fw-lighter">
<%= t '.total_volunteering', count: @volunteering_v_count[volunteer.athlete_id] %>
<%= t '.total_volunteering', count: volunteering_count %>
</div>
</td>
<td class="align-middle">
<%= human_volunteer_role volunteer.role %>
<% if @volunteering_v_count[volunteer.athlete_id] == 1 %>
<i class="fa-solid fa-heart text-danger" title="Первое волонтёрство!"></i>
<% case volunteering_count %>
<% when 1 %>
<%= tag.i class: 'fa-solid fa-heart text-danger', title: t('.first_volunteering') %>
<% when *Badge.participating_thresholds[:volunteer] %>
<%= render partial: '/badge_icon', locals: { label: volunteering_count, icon_class: 'text-danger' } %>
<% end %>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<%= render partial: 'activity', collection: @event.activities.published.order(date: :desc), cached: true %>
</tbody>
</table>
<%= render partial: '/expand_button' if @total_activities > 15 %>
<%= render '/expand_button' if @total_activities > 15 %>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions app/views/pages/about.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<div id="carouselControls" class="carousel slide my-3" data-bs-ride="carousel">
<div class="carousel-inner">
<% VkPhotos.call(7).each_with_index do |photo, idx| %>
<div class="carousel-item <%= 'active' if idx.zero? %>">
<%= tag.div class: ['carousel-item', 'active' => idx.zero?] do %>
<img src="<%= photo %>" class="d-block w-100" alt="Кузьминки" loading="lazy">
</div>
<% end %>
<% end %>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselControls" data-bs-slide="prev">
Expand Down
1 change: 1 addition & 0 deletions config/locales/rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ rs:
volunteer: Volonter
role: Uloga
total_volunteering: 'volontiranja %{count}'
first_volunteering: 'Prvo volontirsko delanje!'
protocol:
position_short: Poz.
position_full: Pozicija
Expand Down
1 change: 1 addition & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ ru:
volunteer: Волонтёр
role: Роль
total_volunteering: 'волонтёрств %{count}'
first_volunteering: 'Первое волонтёрство!'
protocol:
position_short: Поз.
position_full: Место
Expand Down

0 comments on commit ca23f65

Please sign in to comment.