Skip to content

スマートフォン版のDojo表示を地方ごとから都道府県ごとに変更 #1701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 12, 2025
Merged
3 changes: 2 additions & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class HomeController < ApplicationController
def show
@dojo_count = Dojo.active_dojos_count
@dojo_count = Dojo.active_dojos_count
@regions_and_dojos = Dojo.group_by_region_on_active
@prefectures_and_dojos = Dojo.group_by_prefecture_on_active
end
end
13 changes: 13 additions & 0 deletions app/helpers/dojo_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module DojoHelper
def dojo_count_label(count)
if count == 1
"#{count} Dojo"
else
"#{count} Dojos"
end
end

def total_dojos_count(dojos)
dojos.sum(&:counter)
end
end
8 changes: 8 additions & 0 deletions app/models/dojo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def group_by_region_on_active
active.group_by_region
end

def group_by_prefecture
eager_load(:prefecture).default_order.group_by { |dojo| dojo.prefecture.name }
end

def group_by_prefecture_on_active
active.group_by_prefecture
end

def aggregatable_annual_count(period)
Hash[
joins(:dojo_event_services)
Expand Down
48 changes: 28 additions & 20 deletions app/views/shared/_dojos.html+smartphone.erb
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
<div id="accordion" class="panel-group" aria-multiselectable="true" role="tablist">
<% regions_and_dojos.each_with_index do |(region, dojos), index| %>
<div class="panel panel-default">
<div class="panel-heading" id="heading<%= index %>" role="tab">
<h4 class="panel-title">
<a data-toggle="collapse"
href="#collapse<%= index %>" role="button">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
<%= region %>
- <%= dojos.pluck(:counter).sum %> Dojos
</a>
</h4>
</div>
<div class="panel-collapse collapse" id="collapse<%= index %>" role="tabpanel">
<div class="panel-body grayscale-bg dojo-flex">
<%= render partial: 'shared/dojo', collection: dojos %>
<% if @prefectures_and_dojos.present? %>
<% @prefectures_and_dojos.each_with_index do |(prefecture, dojos), index| %>
<% dojo_count = total_dojos_count(dojos) %>
<div class="panel panel-default">
<div class="panel-heading" id="heading<%= index %>" role="tab">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse<%= index %>" role="button">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
<%= prefecture %> - <%= dojo_count_label(dojo_count) %>
</a>
</h4>
</div>
<div class="panel-collapse collapse" id="collapse<%= index %>" role="tabpanel">
<div class="panel-body grayscale-bg dojo-flex">
<%= render partial: 'shared/dojo', collection: dojos %>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
</div>

<script>
$(document).ready(function() {
$('.collapse').on('shown.bs.collapse', function() {
$(this).parent().find(".fa-chevron-right").removeClass("fa-chevron-right").addClass("fa-chevron-down");
$(this)
.parent()
.find(".fa-chevron-right")
.removeClass("fa-chevron-right")
.addClass("fa-chevron-down");
});

$('.collapse').on('hidden.bs.collapse', function() {
$(this).parent().find(".fa-chevron-down").removeClass("fa-chevron-down").addClass("fa-chevron-right");
$(this)
.parent()
.find(".fa-chevron-down")
.removeClass("fa-chevron-down")
.addClass("fa-chevron-right");
});
});
</script>
</script>
2 changes: 1 addition & 1 deletion app/views/shared/_social_buttons_raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
</a>
</li>
<%# コメントアウトされたLINEのボタンは省略 %>
</ol>
</ol>