Skip to content

Commit f4cd64f

Browse files
authored
Merge pull request #165 from denis1011101/feature/training-blocks-account-section
Feature/training blocks account section
2 parents 4aa0214 + eb94e70 commit f4cd64f

11 files changed

Lines changed: 70 additions & 23 deletions

File tree

app/services/telegram/helpers/game_formatting.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ def self.training_program(game, limit: 600, locale: Telegram::I18n::DEFAULT_LOCA
9595

9696
text = kept.join(", ")
9797
dropped = titles.size - kept.size
98-
return text if dropped.zero?
98+
text = "#{text} #{Telegram::I18n.t(:program_more, locale: locale, count: dropped)}" if dropped.positive?
99+
text = "#{text} #{Telegram::I18n.t(:program_details_hint, locale: locale)}" if details?(game)
99100

100-
"#{text} #{Telegram::I18n.t(:program_more, locale: locale, count: dropped)}"
101+
text
102+
end
103+
104+
# Подробное описание блока в сообщение не тянем — оно бывает на 500
105+
# символов. Но человек должен знать, что оно есть и где искать: ссылка на
106+
# игру идёт следом.
107+
def self.details?(game)
108+
game.game_training_blocks.any? { |entry| entry.training_block&.description.to_s.strip.present? }
101109
end
102110

103111
def self.resolve_date(game)

app/views/training_blocks/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="mx-auto max-w-3xl space-y-4 px-4 py-6">
44
<div class="flex items-center justify-between">
55
<h1 class="text-2xl font-bold"><%= t("training_blocks.title") %></h1>
6-
<%= link_to t("training_blocks.back_to_games"), games_account_path, class: "text-sm text-indigo-600 hover:underline dark:text-indigo-400" %>
6+
<%= link_to t("common.back_to_account"), edit_account_path, class: "text-sm text-indigo-600 hover:underline dark:text-indigo-400" %>
77
</div>
88

99
<p class="text-sm text-gray-500 dark:text-slate-400"><%= t("training_blocks.hint") %></p>

app/views/users/edit.html.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
<%= t("users.edit.security") %>
3737
<% end %>
3838

39+
<%# Библиотека блоков — отдельный раздел кабинета: тренеру она нужна всегда, организатору — если блоки уже заведены. %>
40+
<% if current_user.coach? || current_user.training_blocks.exists? %>
41+
<%= link_to training_blocks_path,
42+
class: "inline-flex items-center gap-2 rounded-md bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 transition" do %>
43+
<svg class="h-4 w-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
44+
<path stroke-linecap="round" stroke-linejoin="round" d="M9 6.75h9M9 12h9M9 17.25h9M4.5 6.75h.008v.008H4.5V6.75zm0 5.25h.008v.008H4.5V12zm0 5.25h.008v.008H4.5v-.008z"/>
45+
</svg>
46+
<%= t("training_blocks.title") %>
47+
<% end %>
48+
<% end %>
49+
3950
<%= link_to courts_account_path,
4051
class: "inline-flex items-center gap-2 rounded-md bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 transition" do %>
4152
<svg class="h-4 w-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">

app/views/users/games.html.erb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@
3535
</section>
3636
<% end %>
3737

38-
<%# Конструктор тренировок нужен тренеру рядом с расписанием, но библиотека есть и у организатора. %>
39-
<% if current_user.coach? || current_user.training_blocks.exists? %>
40-
<section class="rounded-lg border bg-white p-4 dark:border-white/10 dark:bg-slate-800/80">
41-
<div class="flex items-center justify-between gap-3">
42-
<div>
43-
<h2 class="text-sm font-semibold text-gray-700 dark:text-slate-300"><%= t("training_blocks.title") %></h2>
44-
<p class="mt-1 text-sm text-gray-500 dark:text-slate-400"><%= t("training_blocks.hint") %></p>
45-
</div>
46-
<%= link_to t("training_blocks.manage"), training_blocks_path, class: "shrink-0 text-sm text-indigo-600 hover:underline dark:text-indigo-400" %>
47-
</div>
48-
</section>
49-
<% end %>
50-
5138
<% if @games.empty? %>
5239
<p class="text-gray-500"><%= t("users.games.empty") %></p>
5340
<% else %>

config/locales/telegram.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ ru:
133133
на корте %{court}'
134134
program_label: 'Программа: %{items}'
135135
program_more: '+ ещё %{count}'
136+
program_details_hint: '(подробное описание — на странице игры)'
136137
participants_label: 'Участники:'
137138
prebooking_request: 'Запрос на предбронирование игры #%{game_id} от %{name}'
138139
dates_label: 'Даты: %{dates}'
@@ -706,6 +707,7 @@ en:
706707
on %{court}'
707708
program_label: 'Programme: %{items}'
708709
program_more: '+ %{count} more'
710+
program_details_hint: '(full description on the game page)'
709711
participants_label: 'Participants:'
710712
prebooking_request: 'Prebooking request for Game #%{game_id} from %{name}'
711713
dates_label: 'Dates: %{dates}'
@@ -1237,6 +1239,7 @@ es:
12371239
a las %{time} en %{court}'
12381240
program_label: 'Programa: %{items}'
12391241
program_more: '+ %{count} más'
1242+
program_details_hint: '(descripción detallada en la página del partido)'
12401243
participants_label: 'Participantes:'
12411244
prebooking_request: 'Solicitud de reserva previa para el partido #%{game_id} de
12421245
%{name}'

config/locales/web.en.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,6 @@ en:
762762
training_blocks:
763763
title: "Training constructor"
764764
hint: "Session blocks live in your library: fill one in once and just tick it in the next training."
765-
manage: "Open"
766-
back_to_games: "Back to my games"
767765
new_title: "New block"
768766
create: "Add"
769767
save: "Save"

config/locales/web.ru.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,6 @@ ru:
771771
training_blocks:
772772
title: "Конструктор тренировок"
773773
hint: "Блоки занятия сохраняются в вашей библиотеке: заполнили один раз — дальше просто отмечаете их в тренировке."
774-
manage: "Открыть"
775-
back_to_games: "К моим играм"
776774
new_title: "Новый блок"
777775
create: "Добавить"
778776
save: "Сохранить"

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
post :dismiss_onboarding
5050
end
5151

52-
# Библиотека блоков тренировок живёт в личном кабинете рядом с расписанием.
52+
# Библиотека блоков тренировок — отдельный раздел личного кабинета.
5353
resources :training_blocks, only: %i[index create update destroy], path: "account/training_blocks"
5454

5555
resources :users, only: [ :index, :show ] do

docs/notification-examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Корт назван отдельной строкой «Корт: …»: «куда ехать» — первый вопрос, и раньше ответ на него был только по ссылке. В телеграме имя корта — ссылка на его страницу; так и в приглашении, и в напоминании, поэтому оба уходят с `parse_mode: HTML`, а всё, что ввели люди, экранируется (`Telegram::Helpers::Markup`). В письме то же имя идёт без разметки: `@body` вставляется и в текстовый шаблон тоже.
1616
- Свободные места считаются только для игры. На тренировку на один корт выходит хоть десять человек, и «0 мест свободно» читалось бы как «не приходи».
1717
- План занятия идёт строкой «Программа: …» — названия блоков через запятую. Длинный список режется по целым блокам, хвост считает пропущенные: «+ ещё 7».
18+
- Если у блоков заполнено подробное описание, в конце строки появляется «(подробное описание — на странице игры)». Само описание в сообщение не тянем: оно бывает на 500 символов, а ссылка на игру идёт следом.
1819
- Имя человека зависит от канала: в телеграме `@ник` (живое упоминание), в письме — имя и почта.
1920
- Превью ссылки в телеграме выключено: оно рисовалось из кэша телеграма и показывало чужой корт и чужую дату.
2021

test/controllers/users_controller_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,32 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
407407
user&.destroy
408408
court&.destroy
409409
end
410+
test "account page links to the training blocks library for a coach" do
411+
coach = User.create!(email: "coach-library-#{SecureRandom.hex(4)}@example.com", coach: true)
412+
post session_url, params: { email: coach.email }
413+
414+
get edit_account_url
415+
416+
assert_response :success
417+
assert_includes response.body, training_blocks_path
418+
assert_includes response.body, "Training constructor"
419+
ensure
420+
coach&.destroy
421+
end
422+
423+
test "account page hides the training blocks library from a player without blocks" do
424+
user_email = "player_library_#{SecureRandom.hex(4)}@example.com"
425+
post session_url, params: { email: user_email }
426+
user = User.find_by!(email: user_email)
427+
428+
get edit_account_url
429+
430+
assert_response :success
431+
assert_not_includes response.body, training_blocks_path
432+
ensure
433+
user&.destroy
434+
end
435+
410436
test "coach sees confirmed future dates in account games" do
411437
coach = User.create!(email: "coach-schedule@example.com", coach: true)
412438
game = Game.create!(

0 commit comments

Comments
 (0)