Skip to content
Merged
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class HomeController < ApplicationController
def show
@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
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
8 changes: 6 additions & 2 deletions app/views/shared/_dojos.html+smartphone.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<div id="accordion" class="panel-group" aria-multiselectable="true" role="tablist">
<% regions_and_dojos.each_with_index do |(region, dojos), index| %>
<% if @prefectures_and_dojos.present? %>

<% @prefectures_and_dojos.each_with_index do |(prefecture, 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 %>
<%= prefecture %>
- <%= dojos.pluck(:counter).sum %> Dojos
</a>
</h4>
Expand All @@ -18,6 +20,8 @@
</div>
</div>
<% end %>

<% end %>
</div>

<script>
Expand Down