Skip to content

Commit 79f260d

Browse files
committed
feat: 年次フィルタリング時に統計情報を表示
選択した年の「開設道場数」と「合計道場数」を表示することで、 訪問者が /stats ページのグラフと数値を比較検証できるようにする 表示例: 2020年末時点のアクティブな道場を表示中 (開設道場数: 3 / 合計道場数: 7)
1 parent 806e706 commit 79f260d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

app/controllers/dojos_controller.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ def index
1818
# その年末時点でアクティブだった道場を取得
1919
dojos_scope = Dojo.active_at(end_of_year)
2020
@page_title = "#{@selected_year}年末時点のCoderDojo一覧"
21-
22-
# 成功メッセージもinline_で表示
23-
flash.now[:inline_info] = "#{@selected_year}年末時点のアクティブな道場を表示中"
2421
rescue ArgumentError
2522
flash[:inline_alert] = "無効な年が指定されました"
2623
return redirect_to dojos_path(anchor: 'table')
@@ -58,6 +55,12 @@ def index
5855

5956
# counter合計を計算(/statsとの照合用)
6057
@counter_sum = @dojos.sum { |d| d[:counter] }
58+
59+
# 年が選択されている場合、統計情報を含むメッセージを設定
60+
if @selected_year
61+
active_dojos_count = @dojos.count
62+
flash.now[:inline_info] = "#{@selected_year}年末時点のアクティブな道場を表示中<br>(開設道場数: #{active_dojos_count} / 合計道場数: #{@counter_sum})".html_safe
63+
end
6164

6265
respond_to do |format|
6366
format.html { render :index } # => app/views/dojos/index.html.erb

spec/requests/dojos_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@
293293
get dojos_path(year: 2020)
294294
expect(response.body).to include('2020年末時点')
295295
expect(response.body).to include('アクティブな道場を表示中')
296+
# 統計情報が含まれていることを確認(/statsページとの比較検証用)
297+
expect(response.body).to include('開設道場数:')
298+
expect(response.body).to include('合計道場数:')
296299
# inline_infoメッセージが表示されることを確認
297300
expect(response.body).to include('alert-info')
298301
end

0 commit comments

Comments
 (0)