Skip to content

Commit b939527

Browse files
committed
Active / Inactive チェック表で note の内容が自動反映されるロジックを追加
1 parent 2dad0c2 commit b939527

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

app/controllers/events_controller.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@ def latest
2424
Dojo.active.each do |dojo|
2525
latest_event = dojo.event_histories.newest.first
2626

27+
link_in_note = dojo.note.match(URI.regexp)
28+
date_in_note = dojo.note.match(/(\d{4}-\d{1,2}-\d{1,2})/) # YYYY-MM-DD
29+
last_session_link = link_in_note.nil? ? dojo_path(dojo.id) : link_in_note
30+
last_session_date = date_in_note.nil? ? dojo.created_at : Time.zone.parse(date_in_note.to_s)
2731
@latest_event_by_dojos << {
2832
id: dojo.id,
2933
name: dojo.name,
3034
note: dojo.note,
3135
url: dojo.url,
36+
has_event_histories: latest_event.nil?,
3237

33-
# 過去のイベント開催データが無ければ、大体として掲載日を入力
38+
# 過去のイベント開催データが無ければ、note 内にある日付または掲載日を表示
3439
event_at: latest_event.nil? ?
35-
dojo.created_at.strftime("%Y-%m-%d") :
40+
last_session_date.strftime("%Y-%m-%d") :
3641
latest_event.evented_at.strftime("%Y-%m-%d"),
3742
event_url: latest_event.nil? ?
38-
nil :
43+
last_session_link.to_s :
3944
latest_event.event_url
4045
}
4146
end

app/views/events/latest.html.erb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,14 @@
7676
</td>
7777
<td>
7878
<small>
79-
<% if dojo[:event_url].nil? %>
80-
<!-- 別サービスでイベント管理している Dojo で、"Active" の確認が無い場合はハイライトする -->
81-
<span class=<%= 'expired' if !dojo[:note].include?('Active') %>>
82-
<%= link_to dojo[:event_at], dojo_path(dojo[:id]) %>
83-
</span>
84-
<% elsif dojo[:event_at] <= Time.current.prev_year && !dojo[:note].include?('Active') %>
79+
<% if dojo[:has_event_histories] %>
8580
<!-- 過去1年間イベント開催していない Dojo で、"Active" の確認が無い場合はハイライトする -->
86-
<span class='expired'>
81+
<span class=<%= 'expired' if dojo[:event_at] <= Time.current.prev_year && !dojo[:note].include?('Active') %>>
8782
<%= link_to dojo[:event_at], dojo[:event_url] %>
8883
</span>
8984
<% else %>
90-
<span>
85+
<!-- 別サービスでイベント管理している Dojo で、"Active" の確認が無い場合はハイライトする -->
86+
<span class=<%= 'expired' if dojo[:event_at] <= Time.current.prev_year && !dojo[:note].include?('Active') %>>
9187
<%= link_to dojo[:event_at], dojo[:event_url] %>
9288
</span>
9389
<% end %>

db/dojos.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@
494494
- Islay
495495
- id: 8
496496
order: '082244'
497-
note: 'Active for years.'
497+
note: 'Active - 2025-04-05 http://coderdojo-moriya.com/archives/5011'
498498
created_at: '2016-07-12'
499499
name: 守谷
500500
prefecture_id: 8
@@ -1111,6 +1111,7 @@
11111111
- Webサイト
11121112
- id: 331
11131113
order: '131032'
1114+
note: 'Active - 2025-03-09 に開催 https://note.com/coderdojo_konan/n/n63193aa2048c'
11141115
created_at: '2024-12-19'
11151116
name: 品川港南
11161117
prefecture_id: 13

0 commit comments

Comments
 (0)