Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 6 additions & 7 deletions app/views/shared/_yyyymm_selector.html.erb
Original file line number Diff line number Diff line change
@@ -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
%>

<div class="mt-6 border border-gray-200 dark:border-gray-700 rounded-lg p-3 bg-white dark:bg-gray-800">
<!-- Year tabs -->
<div class="flex gap-2 overflow-x-auto pb-2 mb-3 border-b border-gray-200 dark:border-gray-700">
<% 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 %>
</div>

<!-- Month tabs -->
<% if selected_year %>
<div class="flex gap-1 flex-wrap">
<% 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 %>
<span class="px-2 py-1 text-xs font-medium rounded text-gray-300 dark:text-gray-600 border-2 border-transparent"><%= month %></span>
<% end %>
Expand Down
Loading