Skip to content

Commit 832dcca

Browse files
authored
Merge pull request #340 from coderdojo-japan/hide_dojo
道場を非表示にする仕組みの追加
2 parents 875f9c3 + 0fddc9a commit 832dcca

File tree

9 files changed

+21
-6
lines changed

9 files changed

+21
-6
lines changed

app/controllers/home_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class HomeController < ApplicationController
22
def show
3-
@dojo_count = Dojo.count
4-
@regions_and_dojos = Dojo.group_by_region
3+
@dojo_count = Dojo.active.count
4+
@regions_and_dojos = Dojo.group_by_region_on_active
55
end
66
end

app/controllers/stats_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class StatsController < ApplicationController
22
def show
33
@url = request.url
44
@dojo_count = Dojo.count
5-
@regions_and_dojos = Dojo.group_by_region
5+
@regions_and_dojos = Dojo.group_by_region_on_active
66

77
# TODO: 次の静的なDojoの開催数もデータベース上で集計できるようにする
88
# https://github.com/coderdojo-japan/coderdojo.jp/issues/190

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def full_url(page_url)
2121
def full_description(description)
2222
description = kata_description if @obj && @obj.permalink == "kata"
2323
if description.empty?
24-
"CoderDojo は子どものためのプログラミング道場です。2011年にアイルランドで始まり、全国では#{Dojo::NUM_OF_JAPAN_DOJOS}ヶ所以上、世界では#{Dojo::NUM_OF_COUNTRIES}ヶ国・#{Dojo::NUM_OF_WHOLE_DOJOS}ヶ所で開催されています。" # Default description
24+
"CoderDojo は子どものためのプログラミング道場です。2011年にアイルランドで始まり、全国では#{Dojo.active.count}ヶ所以上、世界では#{Dojo::NUM_OF_COUNTRIES}ヶ国・#{Dojo::NUM_OF_WHOLE_DOJOS}ヶ所で開催されています。" # Default description
2525
else
2626
description
2727
end

app/models/dojo.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class Dojo < ApplicationRecord
22
NUM_OF_COUNTRIES = "85"
33
NUM_OF_WHOLE_DOJOS = "1,600"
4-
NUM_OF_JAPAN_DOJOS = Dojo.count.to_s
54
YAML_FILE = Rails.root.join('db', 'dojos.yaml')
65

76
belongs_to :prefecture
@@ -12,6 +11,7 @@ class Dojo < ApplicationRecord
1211
before_save { self.email = self.email.downcase }
1312

1413
scope :default_order, -> { order(prefecture_id: :asc, order: :asc) }
14+
scope :active, -> { where(is_active: true) }
1515

1616
validates :name, presence: true, length: { maximum: 50 }
1717
validates :email, presence: false
@@ -35,6 +35,10 @@ def group_by_region
3535
eager_load(:prefecture).default_order.group_by { |dojo| dojo.prefecture.region }
3636
end
3737

38+
def group_by_region_on_active
39+
active.group_by_region
40+
end
41+
3842
def aggregatable_annual_count(period)
3943
Hash[
4044
joins(:dojo_event_services)

db/dojos.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@
295295
description: 埼玉県所沢市小手指にて毎月開催
296296
tags:
297297
- Scratch
298+
is_active: false
298299
- id: 11
299300
order: '112097'
300301
created_at: '2015-05-13'
@@ -409,6 +410,7 @@
409410
description: 千葉県野田市で不定期開催
410411
tags:
411412
- Scratch
413+
is_active: false
412414
- id: 23
413415
order: '122173'
414416
created_at: '2014-09-22'
@@ -1104,6 +1106,7 @@
11041106
tags:
11051107
- Scratch
11061108
- ラズベリーパイ
1109+
is_active: false
11071110
- id: 46
11081111
order: '271403'
11091112
created_at: '2016-03-22'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddIsActiveToDojos < ActiveRecord::Migration[5.1]
2+
def change
3+
add_column :dojos, :is_active, :boolean, null: false, default: true
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20180316062512) do
13+
ActiveRecord::Schema.define(version: 20180604070534) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -36,6 +36,7 @@
3636
t.datetime "created_at", null: false
3737
t.datetime "updated_at", null: false
3838
t.integer "prefecture_id"
39+
t.boolean "is_active", default: true, null: false
3940
end
4041

4142
create_table "event_histories", id: :serial, force: :cascade do |t|

lib/tasks/dojos.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace :dojos do
3838
d.created_at = d.new_record? ? Time.zone.now : dojo['created_at'] || d.created_at
3939
d.updated_at = Time.zone.now
4040
d.prefecture_id = dojo['prefecture_id']
41+
d.is_active = dojo['is_active'].nil? ? true : dojo['is_active']
4142

4243
d.save!
4344
end

spec/models/dojo_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
it { should respond_to(:tags) }
2121

2222
it { should be_valid }
23+
it { expect(Dojo.new.is_active?).to be(true) }
2324

2425
describe "when name is not present" do
2526
before { @dojo.name = " " }

0 commit comments

Comments
 (0)