Skip to content

Commit a5181fa

Browse files
committed
feat: /dojos/activity に掲載日カラムを追加し、開催日と分離
- 掲載日(🗓): /dojos と同じロジック(created_at) - 開催日(👥): 直近のイベント開催日(なければ空欄) - ページタイトルを「活動状況まとめ」に更新 - テストを追加して新しいカラム構成を検証
1 parent 0b97c07 commit a5181fa

File tree

3 files changed

+83
-43
lines changed

3 files changed

+83
-43
lines changed

app/controllers/dojos_controller.rb

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,30 @@ def activity
113113
Dojo.active.each do |dojo|
114114
link_in_note = dojo.note.match(URI.regexp)
115115
date_in_note = dojo.note.match(/(\d{4}-\d{1,2}-\d{1,2})/) # YYYY-MM-DD
116-
last_session_link = link_in_note.nil? ? dojo_path(dojo.id) : link_in_note.to_s
117-
last_session_date = date_in_note.nil? ? dojo.created_at : Time.zone.parse(date_in_note.to_s)
118-
119-
latest_event = dojo.event_histories.newest.first
120-
latest_event_at = latest_event.nil? ? Time.zone.parse('2000-01-23') : latest_event.evented_at
116+
117+
latest_event = dojo.event_histories.newest.first
118+
121119
@latest_event_by_dojos << {
122-
id: dojo.id,
123-
name: dojo.name,
124-
note: dojo.note,
125-
url: dojo.url,
126-
has_event_histories: latest_event.nil?,
127-
128-
# 過去のイベント開催日と note 内の日付を比較し、新しい方の日付を表示
129-
event_at: (latest_event_at < last_session_date) ?
130-
last_session_date.strftime("%Y-%m-%d") :
131-
latest_event.evented_at.strftime("%Y-%m-%d"),
132-
133-
# 過去のイベント開催日と note 内の日付を比較し、新しい方のリンクを表示
134-
event_url: (latest_event_at < last_session_date) ?
135-
last_session_link :
136-
latest_event.event_url
120+
id: dojo.id,
121+
name: dojo.name,
122+
note: dojo.note,
123+
url: dojo.url,
124+
created_at: dojo.created_at, # 掲載日(/dojos と同じ)
125+
126+
# 直近の開催日(イベント履歴がある場合のみ)
127+
latest_event_at: latest_event.nil? ? nil : latest_event.evented_at,
128+
latest_event_url: latest_event.nil? ? nil : latest_event.event_url,
129+
130+
# note内の日付とリンク(fallback用)
131+
note_date: date_in_note.nil? ? nil : Time.zone.parse(date_in_note.to_s),
132+
note_link: link_in_note.nil? ? nil : link_in_note.to_s
137133
}
138134
end
139135

140-
# Sort by older events first && older Dojo ID first if same event date.
141-
@latest_event_by_dojos.sort_by!{ |dojo| [dojo[:event_at], dojo[:id]] }
136+
# Sort by latest event date (or created_at if no events) && older Dojo ID if same date
137+
@latest_event_by_dojos.sort_by! do |dojo|
138+
sort_date = dojo[:latest_event_at] || dojo[:note_date] || dojo[:created_at]
139+
[sort_date, dojo[:id]]
140+
end
142141
end
143142
end

app/views/dojos/activity.html.erb

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<% provide(:title, '道場情報 - 直近の開催日まとめ') %>
2-
<% provide(:desc, '道場別の直近開催日をまとめたページです。') %>
1+
<% provide(:title, '道場情報 - 活動状況まとめ') %>
2+
<% provide(:desc, '道場別の掲載日と直近開催日をまとめたページです。') %>
33
<% provide(:url, activity_dojos_url) %>
44
<% provide(:meta_image, '/img/ogp-events.jpeg') %>
55

@@ -9,7 +9,7 @@
99

1010
<section id="events" class="text-center" style="margin-bottom: 100px;">
1111
<br />
12-
<h1>☯️ 道場別の直近の開催日まとめ</h1>
12+
<h1>☯️ 道場別の活動状況まとめ</h1>
1313
<br />
1414
<p style="margin: 0 0px 40px 10px; line-height: 1.5em;">
1515
主にデータ分析や
@@ -18,9 +18,9 @@
1818
<br>
1919
<div class='form__terms list'>
2020
<ul style='list-style-type: "\2713\0020"; font-size: smaller;'>
21-
<li><%= link_to '近日開催', events_path %>のデータは含まず、<%= link_to '過去開催', stats_path %>のデータを使っています。</li>
21+
<li>「掲載日」は <%= link_to '/dojos', dojos_path %> ページと同じロジックで表示しています。</li>
22+
<li>「開催日」は <%= link_to '過去開催', stats_path %> のデータから直近の開催日を表示しています(<%= link_to '近日開催', events_path %>は含まず)。</li>
2223
<li>開催データは <a href='https://doorkeeper.jp/'>Doorkeeper</a><a href='http://connpass.com/'>connpass</a> にのみ対応しています。</li>
23-
<li>上記以外でイベント管理している場合は掲載日を表示しています。</li>
2424
</ul>
2525
</div>
2626
</p>
@@ -29,15 +29,32 @@
2929
<table border="1" class="stats-table">
3030
<tr>
3131
<th>
32-
<small>☯️ 道場名</small>
32+
<small>
33+
☯️
34+
<br class='ignore-pc'>
35+
道場名
36+
</small>
3337
</th>
3438
<th>
35-
<small><small>
36-
🗓 直近の開催日または掲載日
37-
</small></small>
39+
<small>
40+
🗓
41+
<br class='ignore-pc'>
42+
<a href='/signup'>掲載日</a>
43+
</small>
3844
</th>
3945
<th>
40-
<small>📝 ノート</small>
46+
<small>
47+
👥
48+
<br class='ignore-pc'>
49+
開催日
50+
</small>
51+
</th>
52+
<th>
53+
<small>
54+
📝
55+
<br class='ignore-pc'>
56+
ノート
57+
</small>
4158
</th>
4259
</tr>
4360
<% @latest_event_by_dojos.each do |dojo| %>
@@ -47,19 +64,30 @@
4764
<a href="<%= dojo[:url] %>"><%= dojo[:name] %></a>
4865
</small>
4966
</td>
67+
<td>
68+
<small><%= dojo[:created_at].strftime("%Y-%m-%d") %></small>
69+
</td>
5070
<td>
5171
<small>
52-
<% if dojo[:has_event_histories] %>
53-
<!-- 過去1年間イベント開催していない Dojo で、"Active" マークが無い場合はハイライトする -->
54-
<span class=<%= 'expired' if dojo[:event_at] <= Time.current.prev_year && !dojo[:note].include?('Active') %>>
55-
<%= link_to dojo[:event_at], dojo[:event_url] %>
56-
</span>
72+
<% if dojo[:latest_event_at] %>
73+
<!-- イベント履歴がある場合 -->
74+
<% expired = dojo[:latest_event_at] <= Time.current.prev_year && !dojo[:note].include?('Active') %>
75+
<span class="<%= 'expired' if expired %>">
76+
<%= link_to dojo[:latest_event_at].strftime("%Y-%m-%d"), dojo[:latest_event_url] %>
77+
</span>
78+
<% elsif dojo[:note_date] %>
79+
<!-- note内に日付がある場合 -->
80+
<% expired = dojo[:note_date] <= Time.current.prev_year && !dojo[:note].include?('Active') %>
81+
<span class="<%= 'expired' if expired %>">
82+
<% if dojo[:note_link] %>
83+
<%= link_to dojo[:note_date].strftime("%Y-%m-%d"), dojo[:note_link] %>
84+
<% else %>
85+
<%= dojo[:note_date].strftime("%Y-%m-%d") %>
86+
<% end %>
87+
</span>
5788
<% else %>
58-
<!-- 別サービスでイベント管理している Dojo で、"Active" マークが無い場合はハイライトする -->
59-
<!-- 別サービスでイベント管理している Dojo なら、note にある日付とリンクがあれば表示する -->
60-
<span class=<%= 'expired' if dojo[:event_at] <= Time.current.prev_year && !dojo[:note].include?('Active') %>>
61-
<%= link_to dojo[:event_at], dojo[:event_url] %>
62-
</span>
89+
<!-- 開催日情報なし -->
90+
<span style="color: #999;">-</span>
6391
<% end %>
6492
</small>
6593
</td>

spec/requests/dojos_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343

344344
it "displays the activity status page" do
345345
get activity_dojos_path
346-
expect(response.body).to include("道場別の直近の開催日まとめ")
346+
expect(response.body).to include("道場別の活動状況まとめ")
347347
end
348348

349349
it "includes only active dojos" do
@@ -356,5 +356,18 @@
356356
get "/events/latest"
357357
expect(response).to redirect_to(activity_dojos_path)
358358
end
359+
360+
it "displays proper column headers" do
361+
get activity_dojos_path
362+
expect(response.body).to include("掲載日")
363+
expect(response.body).to include("開催日")
364+
expect(response.body).to include("ノート")
365+
end
366+
367+
it "displays created_at date for active dojos" do
368+
get activity_dojos_path
369+
# 掲載日は YYYY-MM-DD 形式で表示される
370+
expect(response.body).to match(@active_dojo.created_at.strftime("%Y-%m-%d"))
371+
end
359372
end
360373
end

0 commit comments

Comments
 (0)