Skip to content
Merged
31 changes: 29 additions & 2 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,34 @@ section {

/* Stats and Dojos table styling */
.stats-table {
td.inactive-item {
background-color: gainsboro;
table-layout: auto;

th {
padding: 10px;
text-align: center;
}

td {
padding: 1px 10px 1px 10px;
text-align: right;
font-size: smaller;

&.url-cell {
white-space: normal; /* 改行を許可 */
word-wrap: break-word; /* 古めのブラウザ向け */
overflow-wrap: break-word; /* 新しめのブラウザ向け */
word-break: break-all; /* 英数字が続く場合の保険 (必要に応じて) */
text-align: left;
}

&.inactive-item {
background-color: gainsboro;
}
}

// Activity page specific style for expired events
span.expired a {
color: red;
background-color: #ffe5e5; /* 薄い赤背景 */
}
}
13 changes: 13 additions & 0 deletions app/controllers/docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ def show
@doc.content.gsub! "{{ NUM_OF_TOTAL_EVENTS }}", Dojo::NUM_OF_TOTAL_EVENTS
@doc.content.gsub! "{{ NUM_OF_TOTAL_NINJAS }}", Dojo::NUM_OF_TOTAL_NINJAS
end

# INACTIVE_THRESHOLD を日本語の期間表記に変換
if @doc.content.include? "INACTIVE_THRESHOLD"
# 1.year → "1年間", 6.months → "6ヶ月間" のように変換
threshold_in_months = Dojo::INACTIVE_THRESHOLD.to_i / 1.month.to_i
threshold_text = if threshold_in_months >= 12
years = threshold_in_months / 12
"#{years.to_s.tr('0-9', '0-9')}年間"
else
"#{threshold_in_months.to_s.tr('0-9', '0-9')}ヶ月間"
end
@doc.content.gsub! "{{ INACTIVE_THRESHOLD }}", threshold_text
end

@content = Kramdown::Document.new(@doc.content, input: 'GFM').to_html
@url = request.url
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/dojos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,41 @@ def show
format.csv { send_data render_to_string, type: :csv }
end
end

# GET /dojos/activity
# 道場の活動状況を表示(旧 /events/latest から移行)
def activity
# ビューで使用するための閾値をインスタンス変数に設定(モデルから取得)
@inactive_threshold = Dojo::INACTIVE_THRESHOLD

@latest_event_by_dojos = []
Dojo.active.each do |dojo|
link_in_note = dojo.note.match(URI.regexp)
date_in_note = dojo.note.match(/(\d{4}-\d{1,2}-\d{1,2})/) # YYYY-MM-DD

latest_event = dojo.event_histories.newest.first

@latest_event_by_dojos << {
id: dojo.id,
name: dojo.name,
note: dojo.note,
url: dojo.url,
created_at: dojo.created_at, # 掲載日(/dojos と同じ)

# 直近の開催日(イベント履歴がある場合のみ)
latest_event_at: latest_event.nil? ? nil : latest_event.evented_at,
latest_event_url: latest_event.nil? ? nil : latest_event.event_url,

# note内の日付とリンク(fallback用)
note_date: date_in_note.nil? ? nil : Time.zone.parse(date_in_note.to_s),
note_link: link_in_note.nil? ? nil : link_in_note.to_s
}
end

# Sort by latest event date (or created_at if no events) && Dojo's order if same date
@latest_event_by_dojos.sort_by! do |dojo|
sort_date = dojo[:latest_event_at] || dojo[:note_date] || dojo[:created_at]
[sort_date, dojo[:order]]
end
end
end
38 changes: 0 additions & 38 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,4 @@ def index
}
end
end

def latest
# 現在はノートで細かな確認ができるため不要? (念のため残しています)
# @active_dojos_verified = [
# '和歌山', '市川真間', '泉', '石垣', '南紀田辺', '三好', '市川', 'ひばりヶ丘', '伊勢',
# '徳島', '柏', '富山', 'ももち', '木曽', '熊本'
# ]
@latest_event_by_dojos = []
Dojo.active.each do |dojo|
link_in_note = dojo.note.match(URI.regexp)
date_in_note = dojo.note.match(/(\d{4}-\d{1,2}-\d{1,2})/) # YYYY-MM-DD
last_session_link = link_in_note.nil? ? dojo_path(dojo.id) : link_in_note.to_s
last_session_date = date_in_note.nil? ? dojo.created_at : Time.zone.parse(date_in_note.to_s)

latest_event = dojo.event_histories.newest.first
latest_event_at = latest_event.nil? ? Time.zone.parse('2000-01-23') : latest_event.evented_at
@latest_event_by_dojos << {
id: dojo.id,
name: dojo.name,
note: dojo.note,
url: dojo.url,
has_event_histories: latest_event.nil?,

# 過去のイベント開催日と note 内の日付を比較し、新しい方の日付を表示
event_at: (latest_event_at < last_session_date) ?
last_session_date.strftime("%Y-%m-%d") :
latest_event.evented_at.strftime("%Y-%m-%d"),

# 過去のイベント開催日と note 内の日付を比較し、新しい方のリンクを表示
event_url: (latest_event_at < last_session_date) ?
last_session_link :
latest_event.event_url
}
end

# Sort by older events first && older Dojo ID first if same event date.
@latest_event_by_dojos.sort_by!{ |dojo| [dojo[:event_at], dojo[:id]] }
end
end
3 changes: 3 additions & 0 deletions app/models/dojo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class Dojo < ApplicationRecord
NUM_OF_TOTAL_EVENTS = "10,000"
NUM_OF_TOTAL_NINJAS = "62,000"
DOJO_INFO_YAML_PATH = Rails.root.join('db', 'dojos.yml')

# 1年以上イベント開催していない道場を判定する閾値
INACTIVE_THRESHOLD = 1.year

belongs_to :prefecture
has_many :dojo_event_services, dependent: :destroy
Expand Down
114 changes: 114 additions & 0 deletions app/views/dojos/activity.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<% provide(:title, '道場情報 - 活動状況まとめ') %>
<% provide(:desc, '道場別の掲載日と直近開催日をまとめたページです。') %>
<% provide(:url, activity_dojos_url) %>
<% provide(:meta_image, '/img/ogp-events.jpeg') %>

<section class="cover">
<%= lazy_image_tag('/events_cover.jpg', alt: 'Cover Photo on Upcoming Events', min: true) %>
</section>

<section id="events" class="text-center" style="margin-bottom: 100px;">
<br />
<h1>☯️ 道場別の活動状況まとめ</h1>
<br />
<p style="margin: 0 0px 40px 10px; line-height: 1.5em;">
主にデータ分析や
<a href="/signup#terms-of-use">Active/Inactive</a>
の判断などの用途で使われています。
<br>
<div class='form__terms list'>
<ul style='list-style-type: "\2713\0020"; font-size: smaller;'>
<li>「掲載日」は<%= link_to '統計情報 (道場別) ', dojos_path %> と同じロジックで表示しています。</li>
<li>「開催日」は<%= link_to '統計情報 (開催数)', stats_path %> から直近の開催日を表示しています。</li>
<li>「開催日」のデータは <a href='https://doorkeeper.jp/'>Doorkeeper</a> と <a href='http://connpass.com/'>connpass</a> にのみ対応しています。</li>
</ul>
</div>
</p>

<div style="margin-top: 20px;" align="center">
<table border="1" class="stats-table">
<tr>
<th>
<small>
☯️
<br class='ignore-pc'>
道場名 (ID 番号)
</small>
</th>
<th>
<small>
🗓
<br class='ignore-pc'>
<a href='/signup'>掲載日</a>
</small>
</th>
<th>
<small>
👥
<br class='ignore-pc'>
開催日
</small>
</th>
<th>
<small>
📝
<br class='ignore-pc'>
ノート
</small>
</th>
</tr>
<% @latest_event_by_dojos.each do |dojo| %>
<tr>
<td>
<small>
<%= link_to dojo_path(dojo[:id]) do %>
<%= dojo[:name] %><br>
<small>(ID: <%= dojo[:id] %>)</small>
<% end %>
</small>
</td>
<td>
<small><%= dojo[:created_at].strftime("%Y-%m-%d") %></small>
</td>
<td>
<small>
<% if dojo[:latest_event_at] %>
<!-- イベント履歴がある場合 -->
<% expired = dojo[:latest_event_at] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
<span class="<%= 'expired' if expired %>">
<%= link_to dojo[:latest_event_at].strftime("%Y-%m-%d"), dojo[:latest_event_url] %>
</span>
<% elsif dojo[:note_date] %>
<!-- note内に日付がある場合 -->
<% expired = dojo[:note_date] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
<span class="<%= 'expired' if expired %>">
<% if dojo[:note_link] %>
<%= link_to dojo[:note_date].strftime("%Y-%m-%d"), dojo[:note_link] %>
<% else %>
<%= dojo[:note_date].strftime("%Y-%m-%d") %>
<% end %>
</span>
<% else %>
<!-- 開催日情報なし -->
<span style="color: #999;">-</span>
<% end %>
</small>
</td>
<td class="url-cell">
<small>
<span title="<%= dojo[:note] %>">
<% truncated_note = truncate(dojo[:note], length: 60) %>
<%= raw Addressable::URI.unescape(Rinku.auto_link(truncated_note)) %>
</span>
</small>
</td>
</tr>
<% end %>
</table>
</div>

<p>
<pre style='white-space: pre-wrap; margin-top: 60px; color: #505050;'>本ページにある開催日は <br class='ignore-pc'><a href='https://doorkeeper.jp/'>Doorkeeper</a> と <a href='http://connpass.com/'>connpass</a> にのみ対応しています。</pre>
</p>
<div style='margin-top: 30px;'><a href='#top'>&uarr; 上に戻る</a></div>
</section>
21 changes: 0 additions & 21 deletions app/views/dojos/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,6 @@
</p>
</div>

<style type="text/css">
/* URL 用のセルにクラスを付けておく想定 */
table { table-layout: auto; }
td {
padding: 1px 10px 1px 10px;
text-align: right;
font-size: smaller;
}
td.url-cell {
white-space: normal; /* 改行を許可 */
word-wrap: break-word; /* 古めのブラウザ向け */
overflow-wrap: break-word; /* 新しめのブラウザ向け */
word-break: break-all; /* 英数字が続く場合の保険 (必要に応じて) */
text-align: left;
}
th {
padding: 10px;
text-align: center;
}
</style>

<div style="margin-top: 20px;" align="center">
<table border="1" class="stats-table">
<tr>
Expand Down
Loading