Commit 8895178ce7bbe3ee35c0a3f212479d185bc67a46
1 parent
7be8e232
Exists in
staging
and in
42 other branches
ActionItem0: refactoring layout structure
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@59 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
12 changed files
with
138 additions
and
33 deletions
Show diff stats
app/controllers/application.rb
... | ... | @@ -5,6 +5,12 @@ class ApplicationController < ActionController::Base |
5 | 5 | before_filter :detect_stuff_by_domain |
6 | 6 | attr_reader :virtual_community |
7 | 7 | |
8 | + before_filter :load_boxes | |
9 | + def load_boxes | |
10 | + @owner = User.find(1) | |
11 | + @boxes = @owner.boxes | |
12 | + end | |
13 | + | |
8 | 14 | protected |
9 | 15 | |
10 | 16 | def detect_stuff_by_domain | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +class EditTemplateController < ApplicationController | |
2 | + | |
3 | + # TODO: this methods don't belong here | |
4 | + #TODO See a better way to do this. The layout need a owner to work | |
5 | +# before_filter :load_owner | |
6 | +# def load_owner | |
7 | +# end | |
8 | + | |
9 | +# before_filter :load_boxes | |
10 | + def load_boxes | |
11 | + @owner = User.find(1) | |
12 | + @boxes = @owner.boxes | |
13 | + end | |
14 | + | |
15 | + # This method changes a block content to a different box place and | |
16 | + # updates all boxes at the ends | |
17 | + def change_box | |
18 | + b = Block.find(params[:block]) | |
19 | + b.box = Box.find(params[:box_id]) | |
20 | + b.save | |
21 | + render :update do |page| | |
22 | + @owner.boxes.each do |box| | |
23 | + @box_number = box.number | |
24 | + page.replace_html "box_#{box.number}", {:partial => 'layouts/box_template'} | |
25 | + page.sortable "sort_#{box.number}", :url => {:action => 'sort_box', :box_number => box.number} | |
26 | + end | |
27 | + end | |
28 | + end | |
29 | + | |
30 | + def sort_box | |
31 | + blocks = Array.new | |
32 | + box_number = params[:box_number] | |
33 | + pos = 0 | |
34 | + params["sort_#{box_number}"].each do |block_id| | |
35 | + pos = pos + 1 | |
36 | + b = Block.find(block_id) | |
37 | + b.position = pos | |
38 | + b.save | |
39 | + blocks.push(b) | |
40 | + end | |
41 | + @box_number = box_number | |
42 | + render :partial => 'layouts/box_template' | |
43 | + end | |
44 | + | |
45 | +end | ... | ... |
app/controllers/home_controller.rb
app/helpers/application_helper.rb
1 | 1 | # Methods added to this helper will be available to all templates in the application. |
2 | 2 | module ApplicationHelper |
3 | 3 | |
4 | + def display_boxes(boxes, main_content) | |
5 | + boxes.each do |box| | |
6 | + content_tag(:div, show_blocks(box, main_content) ,:id=>"box_#{box.id}") | |
7 | + end | |
8 | + end | |
4 | 9 | |
5 | - def show_block(owner,box_number) | |
6 | - blocks = owner.boxes.find(:first, :conditions => ['number = ?', box_number]).blocks | |
7 | - @out = content_tag(:ul, | |
10 | + def show_blocks(box, main_content) | |
11 | + blocks = box.blocks | |
12 | + content_tag(:ul, | |
8 | 13 | 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) | |
14 | + content_tag(:li, b.main? ? main_content : b.to_html, :class =>"block_item_box_#{b.box_id}" , :id => "block_#{b.id}" ) + draggable('block_'+b.id.to_s) | |
15 | + }, :id => "sort_#{box_number}" | |
16 | + ) +"" | |
17 | + #drag_drop_item(box_number) + sortable_block(box_number) | |
18 | + end | |
19 | + | |
20 | + def sortable_(box_number) | |
21 | + drag_drop_item(box_number) + sortable_block(box_number) | |
17 | 22 | end |
18 | 23 | |
19 | 24 | def sortable_block(box_number) |
20 | - sortable_element "leo_#{box_number}", | |
21 | - :complete => visual_effect(:highlight, "leo_#{box_number}"), | |
25 | + sortable_element "sort_#{box_number}", | |
26 | + :complete => visual_effect(:highlight, "sort_#{box_number}"), | |
22 | 27 | :url => {:action => 'sort_box', :box_number => box_number } |
23 | 28 | end |
24 | 29 | |
... | ... | @@ -39,4 +44,5 @@ module ApplicationHelper |
39 | 44 | }.to_s |
40 | 45 | end |
41 | 46 | |
47 | + | |
42 | 48 | end | ... | ... |
app/models/block.rb
1 | 1 | class Block < ActiveRecord::Base |
2 | + include ActionView::Helpers::UrlHelper | |
3 | + include ActionView::Helpers::TagHelper | |
2 | 4 | belongs_to :box |
3 | 5 | |
4 | 6 | #<tt>position</tt> codl not be nil and must be an integer |
... | ... | @@ -8,8 +10,12 @@ class Block < ActiveRecord::Base |
8 | 10 | validates_presence_of :box_id |
9 | 11 | |
10 | 12 | def to_html |
11 | - str = "content_tag(:p, 'bli')" | |
12 | - return str | |
13 | + #TODO Upgrade this test | |
14 | +# raise _("This is a main class, don't use it") | |
15 | + end | |
16 | + | |
17 | + def main? | |
18 | + false | |
13 | 19 | end |
14 | 20 | |
15 | 21 | end | ... | ... |
app/models/link_block.rb
1 | 1 | class LinkBlock < Block |
2 | 2 | def to_html |
3 | - str = 'content_tag(:p,[' + | |
4 | - User.find(:all).map{ |u| | |
5 | - "[link_to '"+u.name + "', {:controller => 'user', :action => 'test'}]"}.join(',') + | |
6 | - "])" | |
7 | - return str | |
3 | + users = User.find(:all).map do |u| | |
4 | + content_tag("a href='http://www.google.com.br'", u.name) | |
5 | + end | |
6 | + users.join(',') | |
8 | 7 | end |
9 | 8 | end | ... | ... |
app/models/list_block.rb
... | ... | @@ -0,0 +1,18 @@ |
1 | +<html> | |
2 | + <head> | |
3 | + <%= javascript_include_tag :defaults %> | |
4 | + <%= stylesheet_link_tag 'default' %> | |
5 | + | |
6 | + </head> | |
7 | + <body> | |
8 | + <%= image_tag 'loading.gif', :id=>'spinner', :style=>"display:none; float:right;" %> | |
9 | + | |
10 | + <%= link_to _('edit layout'), params.merge({:edit_layout => true}) %> | |
11 | + <%= link_to _('show layout'), params.merge({:edit_layout => false}) %> | |
12 | + <%= link_to _('acao diferente'), :action => 'teste' %> | |
13 | + | |
14 | + <%= display_boxes(@boxes, yield) %> | |
15 | + | |
16 | + </body> | |
17 | + | |
18 | +</html> | ... | ... |
test/fixtures/blocks.yml
1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
2 | -# Link Blocks | |
2 | +#Main Block | |
3 | 3 | one: |
4 | 4 | id: 1 |
5 | - box_id: 1 | |
5 | + box_id: 2 | |
6 | 6 | position: 1 |
7 | - type: 'LinkBlock' | |
7 | + type: 'MainBlock' | |
8 | +# Link Blocks | |
8 | 9 | two: |
9 | 10 | id: 2 |
10 | 11 | box_id: 1 |
11 | 12 | position: 2 |
12 | 13 | type: 'LinkBlock' |
13 | -# Normal Block | |
14 | 14 | three: |
15 | 15 | id: 3 |
16 | 16 | box_id: 1 |
17 | 17 | position: 3 |
18 | - | |
18 | + type: 'LinkBlock' | |
19 | +#List Blocks | |
19 | 20 | four: |
20 | 21 | id: 4 |
21 | - box_id: 2 | |
22 | + box_id: 1 | |
22 | 23 | position: 1 |
24 | + type: 'ListBlock' | |
23 | 25 | five: |
24 | 26 | id: 5 |
25 | 27 | box_id: 3 |
26 | 28 | position: 1 |
27 | - | |
28 | -#List Blocks | |
29 | + type: 'ListBlock' | |
29 | 30 | six: |
30 | 31 | id: 6 |
31 | 32 | box_id: 3 | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | +require 'edit_template_controller' | |
3 | + | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class EditTemplateController; def rescue_action(e) raise e end; end | |
6 | + | |
7 | +class EditTemplateControllerTest < Test::Unit::TestCase | |
8 | + def setup | |
9 | + @controller = EditTemplateController.new | |
10 | + @request = ActionController::TestRequest.new | |
11 | + @response = ActionController::TestResponse.new | |
12 | + end | |
13 | + | |
14 | + # Replace this with your real tests. | |
15 | + def test_truth | |
16 | + assert true | |
17 | + end | |
18 | +end | ... | ... |