Skip to content

Commit 8b43954

Browse files
authored
Merge pull request #93 from amatsuda/integer_yyyymm
Respect Integer version of yyyymm here and there
2 parents 2a7afe9 + 6f7f2f2 commit 8b43954

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

app/controllers/messages_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class MessagesController < ApplicationController
33

44
# GET /ruby-dev
55
def index(list_name: nil, yyyymm: nil, q: nil)
6+
yyyymm = yyyymm.to_i
67
if list_name
78
@list = List.find_by_name list_name
89

app/views/shared/_yyyymm_selector.html.erb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
<%
2-
selected_year = @yyyymm&.[](0, 4)
3-
selected_month = @yyyymm&.[](4, 2)
4-
years_with_months = @yyyymms.group_by {|yyyymm| yyyymm[0, 4] }.sort.reverse
2+
selected_year, selected_month = @yyyymm&.divmod 100
3+
years_with_months = @yyyymms.group_by {|yyyymm| yyyymm / 100 }.sort.reverse
54
%>
65

76
<div class="mt-6 border border-gray-200 dark:border-gray-700 rounded-lg p-3 bg-white dark:bg-gray-800">
87
<!-- Year tabs -->
98
<div class="flex gap-2 overflow-x-auto pb-2 mb-3 border-b border-gray-200 dark:border-gray-700">
109
<% years_with_months.each do |year, months| %>
11-
<%= 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'}" %>
10+
<%= link_to year, [@list, yyyymm: "#{year}#{'%02d' % months.sort.first.modulo(100)}"], 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'}" %>
1211
<% end %>
1312
</div>
1413

1514
<!-- Month tabs -->
1615
<% if selected_year %>
1716
<div class="flex gap-1 flex-wrap">
18-
<% available_months = years_with_months.detect {|y, _| y == selected_year }&.last&.map {|yyyymm| yyyymm[4, 2] } || [] %>
19-
<% ('01'..'12').each do |month| %>
17+
<% available_months = years_with_months.detect {|y, _| y == selected_year }&.last&.map {|yyyymm| yyyymm.modulo 100 } || [] %>
18+
<% (1..12).each do |month| %>
2019
<% if available_months.include?(month) %>
21-
<%= 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'}" %>
20+
<%= link_to month, [@list, yyyymm: "#{selected_year}#{'%02d' % 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'}" %>
2221
<% else %>
2322
<span class="px-2 py-1 text-xs font-medium rounded text-gray-300 dark:text-gray-600 border-2 border-transparent"><%= month %></span>
2423
<% end %>

0 commit comments

Comments
 (0)