Skip to content

Commit 7c7e867

Browse files
authored
Merge pull request code-dot-org#26707 from code-dot-org/pool_controller
Add Pools page to level builder
2 parents 30321d9 + 88f646b commit 7c7e867

File tree

9 files changed

+33
-6
lines changed

9 files changed

+33
-6
lines changed

dashboard/app/controllers/blocks_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ class BlocksController < ApplicationController
22
before_action :require_levelbuilder_mode, except: :index
33
load_and_authorize_resource find_by: :name
44

5+
def index
6+
@blocks = Block.load_and_cache_by_pool(params[:pool])
7+
end
8+
59
def new
610
@block.pool = params[:pool]
711
render 'edit'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class PoolsController < ApplicationController
2+
def index
3+
@pools = Block.all_pool_names
4+
end
5+
end
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
%h1= 'Blocks'
2+
= link_to "Back to Pools", pools_path
3+
%br/
24
= link_to 'Create a New Block', new_block_path
35
%h2= 'Edit an existing block'
46
%ul
5-
- Block.order(:name).all.each do |b|
6-
%li= link_to b.name, edit_block_path(id: b.name)
7+
- @blocks.each do |b|
8+
%li= link_to b[:name], edit_block_path(id: b[:name])

dashboard/app/views/home/_levelbuilder.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
= link_to 'Scripts', scripts_path
66
= link_to '(Update all)', scripts_path(rake: '1'), data: { confirm: 'Are you sure want to re-seed script data?'}
77
%li= link_to t('builder.manage'), levels_path
8-
%li= link_to 'Blocks', blocks_path
8+
%li= link_to 'Pools', pools_path
99
%li= link_to 'Shared Functions', shared_blockly_functions_path
1010
%li= link_to 'Helper Libraries', libraries_path
1111
%li= link_to 'Gallery', 'projects/public'

dashboard/app/views/levels/new.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
=link_to 'Build a Dance Lab Level', new_level_path(type: 'Dancelab')
1919
%ul
2020
%li
21-
Hour of Code 2018. Edit #{link_to 'library', edit_library_path(id: 'DanceLab')}, #{link_to 'blocks', blocks_path}.
21+
Hour of Code 2018. Edit #{link_to 'library', edit_library_path(id: 'DanceLab')}, #{link_to 'blocks', blocks_path(pool: 'Dancelab')}.
2222
%li= link_to 'Build a Minecraft Level', new_level_path(type: 'Craft')
2323
%li= link_to 'Build a Star Wars Grid Level', new_level_path(type: 'StarWarsGrid')
2424

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%h1= 'Pools'
2+
%h2= 'Choose a block Pool'
3+
%ul
4+
- @pools.each do |p|
5+
%li= link_to p, blocks_path(pool: p)

dashboard/config/routes.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@
213213
get '/lang/:locale', to: 'home#set_locale', user_return_to: '/'
214214
get '*i18npath/lang/:locale', to: 'home#set_locale'
215215

216-
resources :blocks, constraints: {id: /[^\/]+/}
216+
get 'pools', to: 'pools#index', as: 'pools'
217+
scope 'pools/:pool' do
218+
resources :blocks, constraints: {id: /[^\/]+/}
219+
end
217220
resources :shared_blockly_functions, path: '/functions'
218221
resources :libraries
219222

dashboard/test/controllers/blocks_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class BlocksControllerTest < ActionController::TestCase
99
Rails.application.config.stubs(:levelbuilder_mode).returns true
1010
sign_in @levelbuilder
1111

12-
get :index
12+
get :index, params: {pool: :pool}
1313
assert_response :success
1414
end
1515
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'test_helper'
2+
3+
class PoolsControllerTest < ActionController::TestCase
4+
test 'can list pools' do
5+
get :index
6+
assert_response :success
7+
end
8+
end

0 commit comments

Comments
 (0)