Skip to content

モバイル版のDojo一覧を地域ごとにアコーディオンにまとめるようにする #188

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 3 commits into from
Nov 10, 2017
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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ gem 'faraday_middleware', '0.10'

gem 'koala'

gem 'rack-user_agent'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ページを参照している端末が、スマホかそうでないかの判定に使用します


group :development do
gem 'web-console'
gem 'spring'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ GEM
rack
rack-test (0.7.0)
rack (>= 1.0, < 3)
rack-user_agent (0.5.2)
rack (>= 1.5)
woothee (>= 1.0.0)
rails (5.1.4)
actioncable (= 5.1.4)
actionmailer (= 5.1.4)
Expand Down Expand Up @@ -294,6 +297,7 @@ GEM
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
woothee (1.7.0)
xpath (2.1.0)
nokogiri (~> 1.3)

Expand All @@ -316,6 +320,7 @@ DEPENDENCIES
pg
pry-rails
rack-host-redirect
rack-user_agent
rails (= 5.1.4)
rails-controller-testing
rake
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/static_pages.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$ ->
$('.collapse').on 'shown.bs.collapse', ->
$(this).parent().find(".fa-chevron-right").removeClass("fa-chevron-right").addClass("fa-chevron-down")
$('.collapse').on 'hidden.bs.collapse', ->
$(this).parent().find(".fa-chevron-down").removeClass("fa-chevron-down").addClass("fa-chevron-right")
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper

before_action :set_request_variant

private

def store_location
Expand All @@ -16,4 +18,7 @@ def login_page_access?
%w(login_page sessions).include? self.controller_name
end

def set_request_variant
request.variant = request.device_variant
end
end
3 changes: 2 additions & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class StaticPagesController < ApplicationController
def home
@dojos = Dojo.all
@dojo_count = Dojo.count
@regions_and_dojos = Dojo.includes(:prefecture).group_by { |dojo| dojo.prefecture.region }
end

def letsencrypt
Expand Down
14 changes: 14 additions & 0 deletions app/views/static_pages/_dojo.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<li class="dojo">
<header>
<a href="<%= dojo.url %>">
<span class="dojo-picture" style="background-image: url(<%= dojo.logo %>);"></span>
<span class="dojo-name"><%= dojo.name %></span>
</a>
</header>
<ul class="tags">
<% dojo.tags.each do |tag| %>
<li><%= tag %></li>
<% end %>
</ul>
<p><%= dojo.description %></p>
</li>
21 changes: 21 additions & 0 deletions app/views/static_pages/_dojos.html+smartphone.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

<% @regions_and_dojos.each_with_index do |(region, dojos), index| %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="<%= "heading#{index}" %>">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#<%= "collapse#{index}" %>">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
<%= region %> - <%= dojos.count %> Dojos
</a>
</h4>
</div>
<div id="<%= "collapse#{index}" %>" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body grayscale-bg">
<%= render partial: 'dojo', collection: dojos %>
</div>
</div>
</div>
<% end %>

</div>
3 changes: 3 additions & 0 deletions app/views/static_pages/_dojos.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<ul class="loaded">
<%= render partial: 'dojo', collection: @regions_and_dojos.values.flatten %>
</ul>
23 changes: 4 additions & 19 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</section>

<section class="introduction text-center list">
<p>CoderDojo は7〜17歳の子どもを対象にしたプログラミング道場です。2011年にアイルランドで始まり、世界では<%= Dojo::NUM_OF_COUNTRIES %>カ国・<%= Dojo::NUM_OF_WHOLE_DOJOS %>の道場、日本では全国に<b><%= @dojos.count %></b>以上の道場があります。これまでに<b><%= Dojo::NUM_OF_WHOLE_EVENTS %></b>回以上のイベントが開催されました。</p>
<p>CoderDojo は7〜17歳の子どもを対象にしたプログラミング道場です。2011年にアイルランドで始まり、世界では<%= Dojo::NUM_OF_COUNTRIES %>カ国・<%= Dojo::NUM_OF_WHOLE_DOJOS %>の道場、日本では全国に<b><%= @dojo_count %></b>以上の道場があります。これまでに<b><%= Dojo::NUM_OF_WHOLE_EVENTS %></b>回以上のイベントが開催されました。</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dojo.count -> @dojo_count 👍

<p>CoderDojo で学べる内容は道場ごとに異なります。例えば、次の内容を学べる道場があります。</p>
<ul>
<li>Scratch, Hour of Code</li>
Expand Down Expand Up @@ -84,24 +84,9 @@
<br />
<h2>全国の道場</h2>
<br />
<ul class="loaded">
<% @dojos.each do |dojo| %>
<li class="dojo">
<header>
<a href="<%= dojo.url %>">
<span class="dojo-picture" style="background-image: url(<%= dojo.logo %>);"></span>
<span class="dojo-name"><%= dojo.name %></span>
</a>
</header>
<ul class="tags">
<% dojo.tags.each do |tag| %>
<li><%= tag %></li>
<% end %>
</ul>
<p><%= dojo.description %></p>
</li>
<% end %>
</ul>

<%= render 'dojos' %>

</section>

<section class="text-center">
Expand Down