Skip to content

Commit 1c24a24

Browse files
authored
Merge pull request #81 from amatsuda/yyyymm_search
Filtering messages with published_at year and month
2 parents 3ecf976 + fe33111 commit 1c24a24

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

app/controllers/messages_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ class MessagesController < ApplicationController
22
PER_PAGE = 50
33

44
# GET /ruby-dev or /q=searchterm
5-
def index(list_name: nil, q: nil, page: nil)
5+
def index(list_name: nil, yyyymm: nil, q: nil, page: nil)
66
if list_name
77
@list = List.find_by_name list_name
88

9-
messages = Message.with_recursive(parent_and_children: [Message.where(list_id: @list, parent_id: nil).order(:id).limit(100), Message.joins('inner join parent_and_children on messages.parent_id = parent_and_children.id')])
9+
@yyyymms = Message.where(list_id: @list).order('yyyymm').pluck(Arel.sql "distinct to_char(published_at, 'YYYYMM') as yyyymm")
10+
@yyyymm = yyyymm || @yyyymms.last
11+
12+
root_query = Message.where(list_id: @list, parent_id: nil).where("to_char(published_at, 'YYYYMM') = ?", @yyyymm).order(:id)
13+
messages = Message.with_recursive(parent_and_children: [root_query, Message.joins('inner join parent_and_children on messages.parent_id = parent_and_children.id')])
1014
.joins('inner join parent_and_children on parent_and_children.id = messages.id')
15+
1116
@messages = compose_tree(messages)
1217
elsif q
1318
search q, page

app/views/layouts/application.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
<header class="bg-white dark:bg-gray-800 shadow-sm border-b border-gray-200 dark:border-gray-700">
2323
<div class="container mx-auto px-4 py-4">
2424
<h1 class="text-2xl font-bold text-gray-900 dark:text-gray-100">
25-
<%= link_to "blade.ruby-lang.org", root_path, class: "hover:text-red-600 dark:hover:text-red-400 transition-colors" %>
25+
<%= link_to @list&.name || 'blade.ruby-lang.org', @list || root_path, class: "hover:text-red-600 dark:hover:text-red-400 transition-colors" %>
2626
</h1>
27+
<p class="text-gray-600 dark:text-gray-400 mt-2">Mailing list archive</p>
2728
</div>
2829
</header>
2930

app/views/messages/index.html.erb

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,33 @@
66
</div>
77
<% end %>
88

9-
<div class="mb-4">
10-
<h1 class="text-3xl font-bold text-gray-900 dark:text-gray-100"><%= @list.name %></h1>
11-
<p class="text-gray-600 dark:text-gray-400 mt-2">Mailing list archive</p>
9+
<div class="mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 bg-white dark:bg-gray-800">
10+
<%
11+
selected_year = @yyyymm&.[](0, 4)
12+
selected_month = @yyyymm&.[](4, 2)
13+
years_with_months = @yyyymms.group_by {|yyyymm| yyyymm[0, 4] }.sort.reverse
14+
%>
15+
16+
<!-- Year tabs -->
17+
<div class="flex gap-2 overflow-x-auto pb-2 mb-3 border-b border-gray-200 dark:border-gray-700">
18+
<% years_with_months.each do |year, months| %>
19+
<%= link_to year, [@list, yyyymm: "#{year}#{months.sort.first[4, 2]}"], class: "px-3 py-1 text-sm font-medium rounded whitespace-nowrap transition-colors #{selected_year == year ? 'bg-red-600 dark:bg-red-500 text-white' : 'bg-gray-100 dark:bg-gray-900 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100'}" %>
20+
<% end %>
21+
</div>
22+
23+
<!-- Month tabs -->
24+
<% if selected_year %>
25+
<div class="flex gap-1 flex-wrap">
26+
<% available_months = years_with_months.detect {|y, _| y == selected_year }&.last&.map {|yyyymm| yyyymm[4, 2] } || [] %>
27+
<% ('01'..'12').each do |month| %>
28+
<% if available_months.include?(month) %>
29+
<%= link_to month, [@list, yyyymm: "#{selected_year}#{month}"], class: "px-2 py-1 text-xs font-medium rounded transition-colors #{selected_month == month ? 'bg-red-600 dark:bg-red-500 text-white border-2 border-red-700 dark:border-red-400' : 'bg-gray-100 dark:bg-gray-900 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 border-2 border-transparent'}" %>
30+
<% else %>
31+
<span class="px-2 py-1 text-xs font-medium rounded text-gray-300 dark:text-gray-600 border-2 border-transparent"><%= month %></span>
32+
<% end %>
33+
<% end %>
34+
</div>
35+
<% end %>
1236
</div>
1337

1438
<div class="grid grid-cols-4 gap-6" style="height: calc(100vh - 16rem);" data-controller="message-list">

0 commit comments

Comments
 (0)