diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 993018a..92b85d6 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -3,6 +3,7 @@ class MessagesController < ApplicationController # GET /ruby-dev def index(list_name: nil, yyyymm: nil, q: nil) + yyyymm = yyyymm.to_i if list_name @list = List.find_by_name list_name diff --git a/app/views/shared/_yyyymm_selector.html.erb b/app/views/shared/_yyyymm_selector.html.erb index f98d391..f5739b4 100644 --- a/app/views/shared/_yyyymm_selector.html.erb +++ b/app/views/shared/_yyyymm_selector.html.erb @@ -1,24 +1,23 @@ <% - selected_year = @yyyymm&.[](0, 4) - selected_month = @yyyymm&.[](4, 2) - years_with_months = @yyyymms.group_by {|yyyymm| yyyymm[0, 4] }.sort.reverse + selected_year, selected_month = @yyyymm&.divmod 100 + years_with_months = @yyyymms.group_by {|yyyymm| yyyymm / 100 }.sort.reverse %>
<% years_with_months.each do |year, months| %> - <%= 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'}" %> + <%= 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'}" %> <% end %>
<% if selected_year %>
- <% available_months = years_with_months.detect {|y, _| y == selected_year }&.last&.map {|yyyymm| yyyymm[4, 2] } || [] %> - <% ('01'..'12').each do |month| %> + <% available_months = years_with_months.detect {|y, _| y == selected_year }&.last&.map {|yyyymm| yyyymm.modulo 100 } || [] %> + <% (1..12).each do |month| %> <% if available_months.include?(month) %> - <%= 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'}" %> + <%= 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'}" %> <% else %> <%= month %> <% end %>