Commit 8efec986f67921606a878e5e7b20ffd1b2e73091
1 parent
102338bc
Exists in
master
and in
29 other branches
ActionItem0: Finishing the action item but there are some project question to review
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@37 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
18 changed files
with
131 additions
and
60 deletions
Show diff stats
app/controllers/application.rb
@@ -4,28 +4,48 @@ class ApplicationController < ActionController::Base | @@ -4,28 +4,48 @@ class ApplicationController < ActionController::Base | ||
4 | 4 | ||
5 | before_filter :detect_stuff_by_domain | 5 | before_filter :detect_stuff_by_domain |
6 | 6 | ||
7 | - before_filter :detect_edit_layout | 7 | + #TODO See a better way to do this. The layout need a owner to work |
8 | + before_filter :load_owner | ||
9 | + def load_owner | ||
10 | + @owner = User.find(1) | ||
11 | + end | ||
8 | 12 | ||
13 | + #TODO See a better way to do this. We need that something say to us when is the time to edit the layout. | ||
14 | + #I think the better way is set a different render class to the visualization and to edit a layout. | ||
15 | + before_filter :detect_edit_layout | ||
9 | def detect_edit_layout | 16 | def detect_edit_layout |
10 | @edit_layout = true unless params[:edit_layout].nil? | 17 | @edit_layout = true unless params[:edit_layout].nil? |
11 | end | 18 | end |
12 | 19 | ||
13 | -# after_filter :render_actions | ||
14 | - | ||
15 | - def render_actions | ||
16 | -@bla = 'funfou' | ||
17 | -#return @bla | ||
18 | - render_action('index', nil, true) | ||
19 | -# render :update do |page| | ||
20 | -# page.replace_html 'box_1', :partial => 'pending_todos' | ||
21 | -# page.replace_html 'completed_todos', :partial => 'completed_todos' | ||
22 | -# page.replace_html 'working_todos', :partial => 'working_todos' | ||
23 | -# end | 20 | + # This method changes a block content to a different box place and |
21 | + # updates all boxes at the ends | ||
22 | + def change_box | ||
23 | + b = Block.find(params[:block]) | ||
24 | + b.box = Box.find(params[:box_id]) | ||
25 | + b.save | ||
26 | + render :update do |page| | ||
27 | + @owner.boxes.each do |box| | ||
28 | + @box_number = box.number | ||
29 | + page.replace_html "box_#{box.number}", {:partial => 'layouts/box_template'} | ||
30 | + page.sortable "leo_#{box.number}", :url => {:action => 'sort_box', :box_number => box.number} | ||
31 | + end | ||
32 | + end | ||
24 | end | 33 | end |
25 | 34 | ||
26 | -# def render(type = nil) | ||
27 | -# render_actions | ||
28 | -# end | 35 | + def sort_box |
36 | + blocks = Array.new | ||
37 | + box_number = params[:box_number] | ||
38 | + pos = 0 | ||
39 | + params["leo_#{box_number}"].each do |block_id| | ||
40 | + pos = pos + 1 | ||
41 | + b = Block.find(block_id) | ||
42 | + b.position = pos | ||
43 | + b.save | ||
44 | + blocks.push(b) | ||
45 | + end | ||
46 | + @box_number = box_number | ||
47 | + render :partial => 'layouts/box_template' | ||
48 | + end | ||
29 | 49 | ||
30 | protected | 50 | protected |
31 | 51 |
app/controllers/home_controller.rb
1 | class HomeController < ApplicationController | 1 | class HomeController < ApplicationController |
2 | 2 | ||
3 | def index | 3 | def index |
4 | - #TODO this is a test case of owner | ||
5 | - @owner = User.find(1) | 4 | + render :template => 'home/index' |
6 | end | 5 | end |
7 | 6 | ||
8 | -def teste | ||
9 | - render :update do |page| | ||
10 | - page.replace_html 'box_1', :partial => 'leo' | ||
11 | -#'nem acredito' | ||
12 | -# page.replace_html 'completed_todos', :partial => 'completed_todos' | ||
13 | -# page.replace_html 'working_todos', :partial => 'working_todos' | ||
14 | - end | ||
15 | - | ||
16 | -end | ||
17 | end | 7 | end |
app/helpers/application_helper.rb
@@ -4,7 +4,39 @@ module ApplicationHelper | @@ -4,7 +4,39 @@ module ApplicationHelper | ||
4 | 4 | ||
5 | def show_block(owner,box_number) | 5 | def show_block(owner,box_number) |
6 | blocks = owner.boxes.find(:first, :conditions => ['number = ?', box_number]).blocks | 6 | blocks = owner.boxes.find(:first, :conditions => ['number = ?', box_number]).blocks |
7 | - @out = blocks.map {|b| b.to_html}.join('') | 7 | + @out = content_tag(:ul, |
8 | + blocks.map {|b| | ||
9 | + content_tag(:li, eval(b.to_html), :class =>"block_item_box_#{b.box_id}" , :id => "block_#{b.id}" ) + draggable('block_'+b.id.to_s) | ||
10 | + }, :id => "leo_#{box_number}" | ||
11 | + ) + drag_drop_item(box_number) | ||
12 | + | ||
13 | +#TODO when we put this parameter the elements stay blocked into the div element indicated. | ||
14 | +#THe consequence is we can't move the element between boxes. Comment it the element can be sorted | ||
15 | +#only when we move a element | ||
16 | +# sortable_block(box_number) | ||
17 | + end | ||
18 | + | ||
19 | + def sortable_block(box_number) | ||
20 | + sortable_element "leo_#{box_number}", | ||
21 | + :complete => visual_effect(:highlight, "leo_#{box_number}"), | ||
22 | + :url => {:action => 'sort_box', :box_number => box_number } | ||
23 | + end | ||
24 | + | ||
25 | + def draggable item | ||
26 | + draggable_element(item, :ghosting=>true, :revert=>true) | ||
27 | + end | ||
28 | + | ||
29 | + def drag_drop_item box_id | ||
30 | + boxes = Box.find_not_box(box_id) | ||
31 | + return boxes.map{ |b| | ||
32 | + drop_receiving_element("box_#{box_id}", | ||
33 | + :accept => "block_item_box_#{b.id}", | ||
34 | + :complete => "$('spinner').hide();", | ||
35 | + :before => "$('spinner').show();", | ||
36 | + :hoverclass => 'hover', | ||
37 | + :with => "'block=' + encodeURIComponent(element.id.split('_').last())", | ||
38 | + :url => {:action=>:change_box, :box_id=> box_id}) | ||
39 | + }.to_s | ||
8 | end | 40 | end |
9 | 41 | ||
10 | end | 42 | end |
app/models/block.rb
@@ -8,7 +8,8 @@ class Block < ActiveRecord::Base | @@ -8,7 +8,8 @@ class Block < ActiveRecord::Base | ||
8 | validates_presence_of :box_id | 8 | validates_presence_of :box_id |
9 | 9 | ||
10 | def to_html | 10 | def to_html |
11 | - return '<p>bli</p>' | 11 | + str = "content_tag(:p, 'bli')" |
12 | + return str | ||
12 | end | 13 | end |
13 | 14 | ||
14 | end | 15 | end |
app/models/box.rb
@@ -7,4 +7,8 @@ class Box < ActiveRecord::Base | @@ -7,4 +7,8 @@ class Box < ActiveRecord::Base | ||
7 | 7 | ||
8 | #<tt>number</tt> could not be nil and must be an integer | 8 | #<tt>number</tt> could not be nil and must be an integer |
9 | validates_numericality_of :number, :only_integer => true, :message => _('%{fn} must be composed only of integers.') | 9 | validates_numericality_of :number, :only_integer => true, :message => _('%{fn} must be composed only of integers.') |
10 | + | ||
11 | + def self.find_not_box(box_id) | ||
12 | + return Box.find(:all, :conditions => ['id != ?', box_id]) | ||
13 | + end | ||
10 | end | 14 | end |
app/models/link_block.rb
app/models/list_block.rb
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +<%= show_block(@owner, @box_number) %> |
app/views/layouts/application.rhtml
@@ -11,28 +11,29 @@ | @@ -11,28 +11,29 @@ | ||
11 | <%= link_to _('show layout'), params.merge({:edit_layout => false}) %> | 11 | <%= link_to _('show layout'), params.merge({:edit_layout => false}) %> |
12 | <%= link_to _('acao diferente'), :action => 'teste' %> | 12 | <%= link_to _('acao diferente'), :action => 'teste' %> |
13 | 13 | ||
14 | -teste | ||
15 | -<%= @bla %> | ||
16 | -oxe | ||
17 | - | ||
18 | <div id="box_1" > | 14 | <div id="box_1" > |
19 | <%= show_block(@owner, 1)%> | 15 | <%= show_block(@owner, 1)%> |
20 | </div> | 16 | </div> |
17 | +<%= update_page_tag{|page| | ||
18 | +#TODO this is to test | ||
19 | +#page.alert('leo') | ||
20 | +#@box_number=1 | ||
21 | +#page.replace_html "box_1", {:partial => 'leo'}; | ||
22 | +#page.replace_html "box_1", {:partial => 'layouts/box_template'}; | ||
23 | +#page.sortable "leo_1", :url => {:action => 'sort_box', :box_number => 1}; | ||
24 | +#)page.show | ||
25 | +} | ||
26 | +%> | ||
27 | + | ||
28 | + | ||
21 | <div id="box_2" > | 29 | <div id="box_2" > |
22 | - <%= show_block(@owner, 1)%> | ||
23 | - <ul> | ||
24 | - <li> | ||
25 | - <%= yield %> | ||
26 | - </li> | ||
27 | - </ul> | 30 | + <%= show_block(@owner, 2)%> |
31 | + <%= yield %> | ||
28 | </div> | 32 | </div> |
29 | <div id="box_3" > | 33 | <div id="box_3" > |
30 | - <%= show_block(@owner, 1)%> | ||
31 | - <ul> | ||
32 | - <li> lado direito | ||
33 | - </li> | ||
34 | - </ul> | 34 | + <%= show_block(@owner, 3)%> |
35 | </div> | 35 | </div> |
36 | 36 | ||
37 | </body> | 37 | </body> |
38 | + | ||
38 | </html> | 39 | </html> |
db/migrate/004_create_boxes.rb
1 | class CreateBoxes < ActiveRecord::Migration | 1 | class CreateBoxes < ActiveRecord::Migration |
2 | def self.up | 2 | def self.up |
3 | create_table :boxes do |t| | 3 | create_table :boxes do |t| |
4 | - t.column :number, :integer | 4 | + t.column :number, :integer |
5 | t.column :owner_type, :string | 5 | t.column :owner_type, :string |
6 | - t.column :owner_id, :integer | 6 | + t.column :owner_id, :integer |
7 | end | 7 | end |
8 | end | 8 | end |
9 | 9 |
db/migrate/005_create_blocks.rb
@@ -3,6 +3,7 @@ class CreateBlocks < ActiveRecord::Migration | @@ -3,6 +3,7 @@ class CreateBlocks < ActiveRecord::Migration | ||
3 | create_table :blocks do |t| | 3 | create_table :blocks do |t| |
4 | t.column :box_id, :integer | 4 | t.column :box_id, :integer |
5 | t.column :position, :integer | 5 | t.column :position, :integer |
6 | + t.column :type, :string | ||
6 | end | 7 | end |
7 | end | 8 | end |
8 | 9 |
test/fixtures/blocks.yml
1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
2 | +# Link Blocks | ||
2 | one: | 3 | one: |
3 | id: 1 | 4 | id: 1 |
4 | box_id: 1 | 5 | box_id: 1 |
5 | position: 1 | 6 | position: 1 |
7 | + type: 'LinkBlock' | ||
6 | two: | 8 | two: |
7 | id: 2 | 9 | id: 2 |
8 | box_id: 1 | 10 | box_id: 1 |
9 | position: 2 | 11 | position: 2 |
12 | + type: 'LinkBlock' | ||
13 | +# Normal Block | ||
10 | three: | 14 | three: |
11 | id: 3 | 15 | id: 3 |
12 | box_id: 1 | 16 | box_id: 1 |
13 | position: 3 | 17 | position: 3 |
18 | + | ||
14 | four: | 19 | four: |
15 | id: 4 | 20 | id: 4 |
16 | box_id: 2 | 21 | box_id: 2 |
@@ -19,7 +24,10 @@ five: | @@ -19,7 +24,10 @@ five: | ||
19 | id: 5 | 24 | id: 5 |
20 | box_id: 3 | 25 | box_id: 3 |
21 | position: 1 | 26 | position: 1 |
27 | + | ||
28 | +#List Blocks | ||
22 | six: | 29 | six: |
23 | id: 6 | 30 | id: 6 |
24 | box_id: 3 | 31 | box_id: 3 |
25 | position: 2 | 32 | position: 2 |
33 | + type: 'ListBlock' |
test/fixtures/link_blocks.yml
test/fixtures/list_blocks.yml
test/unit/block_test.rb
@@ -50,7 +50,7 @@ class BlockTest < Test::Unit::TestCase | @@ -50,7 +50,7 @@ class BlockTest < Test::Unit::TestCase | ||
50 | end | 50 | end |
51 | 51 | ||
52 | def test_valid_fixtures | 52 | def test_valid_fixtures |
53 | - Block.find_all.each do |b| | 53 | + Block.find(:all).each do |b| |
54 | assert b.valid? | 54 | assert b.valid? |
55 | end | 55 | end |
56 | end | 56 | end |
test/unit/link_block_test.rb
1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | ||
3 | class LinkBlockTest < Test::Unit::TestCase | 3 | class LinkBlockTest < Test::Unit::TestCase |
4 | - fixtures :link_blocks | 4 | + fixtures :blocks |
5 | 5 | ||
6 | # Replace this with your real tests. | 6 | # Replace this with your real tests. |
7 | def test_truth | 7 | def test_truth |
test/unit/list_block_test.rb
1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | ||
3 | class ListBlockTest < Test::Unit::TestCase | 3 | class ListBlockTest < Test::Unit::TestCase |
4 | - fixtures :list_blocks | 4 | + fixtures :blocks |
5 | 5 | ||
6 | # Replace this with your real tests. | 6 | # Replace this with your real tests. |
7 | def test_truth | 7 | def test_truth |