Commit 2920c5c036db7fdea76b13c800a6e2ab6e0caf43
1 parent
657be12f
Exists in
master
and in
23 other branches
Change display content to dinamically show parent content
Showing
5 changed files
with
123 additions
and
281 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
| 1 | 1 | class DisplayContentBlock < Block |
| 2 | 2 | |
| 3 | 3 | settings_items :nodes, :type => Array, :default => [] |
| 4 | - settings_items :parent_nodes, :type => Array, :default => [] | |
| 5 | 4 | settings_items :chosen_attributes, :type => Array, :default => ['title'] |
| 5 | + settings_items :display_folder_children, :type => :boolean, :default => true | |
| 6 | 6 | |
| 7 | 7 | def self.description |
| 8 | 8 | _('Display your contents') |
| ... | ... | @@ -13,20 +13,28 @@ class DisplayContentBlock < Block |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def checked_nodes= params |
| 16 | + self.nodes = params.keys | |
| 17 | + end | |
| 18 | + | |
| 19 | + before_save :expand_nodes | |
| 20 | + | |
| 21 | + def expand_nodes | |
| 16 | 22 | return self.nodes if self.holder.nil? |
| 17 | - articles = [] | |
| 18 | - parent_articles = [] | |
| 19 | - self.holder.articles.find(params.keys).map do |article| | |
| 20 | - if article.folder? | |
| 21 | - articles = articles + article.children | |
| 22 | - parent_articles << article.id | |
| 23 | - else | |
| 24 | - articles<< article | |
| 25 | - end | |
| 26 | - parent_articles = parent_articles + get_parent(article) unless parent_articles.include?(article.parent_id) | |
| 23 | + | |
| 24 | + articles = self.holder.articles.find(nodes) | |
| 25 | + children = articles.map { |article| article.children }.compact.flatten | |
| 26 | + | |
| 27 | + if display_folder_children | |
| 28 | + articles = articles - children | |
| 29 | + else | |
| 30 | + articles = (articles + children).uniq | |
| 27 | 31 | end |
| 28 | - self.parent_nodes = parent_articles | |
| 29 | - self.nodes = articles.map{|a| a.id if a.is_a?(TextArticle) }.compact | |
| 32 | + | |
| 33 | + self.nodes = articles.map(&:id) | |
| 34 | + end | |
| 35 | + | |
| 36 | + def parent_nodes | |
| 37 | + @parent_nodes ||= self.holder.articles.find(nodes).map { |article| get_parent(article) }.compact.flatten | |
| 30 | 38 | end |
| 31 | 39 | |
| 32 | 40 | VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] |
| ... | ... | @@ -38,14 +46,18 @@ class DisplayContentBlock < Block |
| 38 | 46 | |
| 39 | 47 | include ActionController::UrlWriter |
| 40 | 48 | def content(args={}) |
| 41 | - docs = owner.articles.find(:all, :conditions => {:id => self.nodes}) | |
| 49 | + extra_condition = display_folder_children ? 'OR articles.parent_id IN(:nodes)':'' | |
| 50 | + docs = nodes.blank? ? [] : owner.articles.find(:all, :conditions => ["(articles.id IN(:nodes) #{extra_condition}) AND articles.type IN(:types)", {:nodes => self.nodes, :types => VALID_CONTENT}]) | |
| 51 | + | |
| 42 | 52 | block_title(title) + |
| 43 | - content_tag('ul', docs.map {|item| | |
| 44 | - content_tag('li', | |
| 45 | - (display_attribute?('title') ? content_tag('div', link_to(h(item.title), item.url), :class => 'title') : '') + | |
| 46 | - (display_attribute?('abstract') ? content_tag('div', item.abstract ,:class => 'lead') : '') + | |
| 47 | - (display_attribute?('body') ? content_tag('div', item.body ,:class => 'body') : '') | |
| 48 | - ) | |
| 53 | + content_tag('ul', docs.map {|item| | |
| 54 | + if !item.folder? | |
| 55 | + content_tag('li', | |
| 56 | + (display_attribute?('title') ? content_tag('div', link_to(h(item.title), item.url), :class => 'title') : '') + | |
| 57 | + (display_attribute?('abstract') ? content_tag('div', item.abstract ,:class => 'lead') : '') + | |
| 58 | + (display_attribute?('body') ? content_tag('div', item.body ,:class => 'body') : '') | |
| 59 | + ) | |
| 60 | + end | |
| 49 | 61 | }.join("\n")) |
| 50 | 62 | |
| 51 | 63 | end | ... | ... |
plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb
| ... | ... | @@ -73,18 +73,16 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase |
| 73 | 73 | |
| 74 | 74 | should 'index action returns an json with node undetermined if the node is in the parent nodes list' do |
| 75 | 75 | Article.delete_all |
| 76 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id) | |
| 77 | - block.parent_nodes= [article.id] | |
| 76 | + f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) | |
| 77 | + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 78 | + article2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 79 | + block.nodes = [article.id] | |
| 78 | 80 | block.save! |
| 79 | 81 | |
| 80 | 82 | get :index, :block_id => block.id |
| 81 | 83 | json_response = ActiveSupport::JSON.decode(@response.body) |
| 82 | - expected_json = {'data' => article.title} | |
| 83 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 84 | - expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 85 | - expected_json['children'] = [] | |
| 86 | - | |
| 87 | - assert_equivalent [expected_json], json_response | |
| 84 | + expected_json = { 'node_id' => f.id, 'class' => 'jstree-undetermined', 'parent_id' => f.parent_id} | |
| 85 | + assert_equal expected_json, json_response.first['attr'] | |
| 88 | 86 | end |
| 89 | 87 | |
| 90 | 88 | should 'index action returns an json with node closed if the node has article with children' do |
| ... | ... | @@ -106,7 +104,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase |
| 106 | 104 | f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) |
| 107 | 105 | a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) |
| 108 | 106 | a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) |
| 109 | - block.parent_nodes = [f.id] | |
| 107 | + block.checked_nodes= {a1.id => true} | |
| 110 | 108 | block.save! |
| 111 | 109 | |
| 112 | 110 | get :index, :block_id => block.id |
| ... | ... | @@ -114,7 +112,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase |
| 114 | 112 | expected_json = {'data' => f.title} |
| 115 | 113 | expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} |
| 116 | 114 | children = [ |
| 117 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, | |
| 115 | + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id, "class" => "jstree-checked"}}, | |
| 118 | 116 | {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} |
| 119 | 117 | ] |
| 120 | 118 | expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) |
| ... | ... | @@ -130,7 +128,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase |
| 130 | 128 | a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) |
| 131 | 129 | a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) |
| 132 | 130 | a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => environment.portal_community.id) |
| 133 | - block.parent_nodes = [f.id] | |
| 131 | + block.checked_nodes= {a2.id => true, a3.id => true} | |
| 134 | 132 | block.save! |
| 135 | 133 | |
| 136 | 134 | get :index, :block_id => block.id |
| ... | ... | @@ -140,7 +138,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase |
| 140 | 138 | value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} |
| 141 | 139 | children = [ |
| 142 | 140 | {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, |
| 143 | - {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} | |
| 141 | + {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id, "class" => "jstree-checked"}} | |
| 144 | 142 | ] |
| 145 | 143 | value['attr'].merge!({'class' => 'jstree-undetermined'}) |
| 146 | 144 | value['children'] = children |
| ... | ... | @@ -148,7 +146,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase |
| 148 | 146 | expected_json.push(value) |
| 149 | 147 | |
| 150 | 148 | value = {'data' => a3.title} |
| 151 | - value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | |
| 149 | + value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id, "class" => "jstree-checked"} | |
| 152 | 150 | expected_json.push(value) |
| 153 | 151 | |
| 154 | 152 | assert_equivalent expected_json, json_response | ... | ... |
plugins/display_content/test/functional/display_content_plugin_myprofile_controller_test.rb
| ... | ... | @@ -73,18 +73,16 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase |
| 73 | 73 | |
| 74 | 74 | should 'index action returns an json with node undetermined if the node is in the parent nodes list' do |
| 75 | 75 | Article.delete_all |
| 76 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 77 | - block.parent_nodes= [article.id] | |
| 76 | + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 77 | + article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | |
| 78 | + article2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | |
| 79 | + block.nodes = [article.id] | |
| 78 | 80 | block.save! |
| 79 | 81 | |
| 80 | 82 | get :index, :block_id => block.id, :profile => profile.identifier |
| 81 | 83 | json_response = ActiveSupport::JSON.decode(@response.body) |
| 82 | - expected_json = {'data' => article.title} | |
| 83 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 84 | - expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 85 | - expected_json['children'] = [] | |
| 86 | - | |
| 87 | - assert_equivalent [expected_json], json_response | |
| 84 | + expected_json = { 'node_id' => f.id, 'class' => 'jstree-undetermined', 'parent_id' => f.parent_id} | |
| 85 | + assert_equal expected_json, json_response.first['attr'] | |
| 88 | 86 | end |
| 89 | 87 | |
| 90 | 88 | should 'index action returns an json with node closed if the node has article with children' do |
| ... | ... | @@ -107,7 +105,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase |
| 107 | 105 | f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) |
| 108 | 106 | a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) |
| 109 | 107 | a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) |
| 110 | - block.parent_nodes = [f.id] | |
| 108 | + block.checked_nodes = {a1.id => true} | |
| 111 | 109 | block.save! |
| 112 | 110 | |
| 113 | 111 | get :index, :block_id => block.id, :profile => profile.identifier |
| ... | ... | @@ -115,32 +113,32 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase |
| 115 | 113 | expected_json = {'data' => f.title} |
| 116 | 114 | expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} |
| 117 | 115 | children = [ |
| 118 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, | |
| 116 | + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id, "class" => "jstree-checked"}}, | |
| 119 | 117 | {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} |
| 120 | 118 | ] |
| 121 | 119 | expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) |
| 122 | 120 | expected_json['children'] = children |
| 123 | 121 | expected_json['state'] = 'closed' |
| 124 | 122 | |
| 125 | - assert_equivalent [expected_json], json_response | |
| 126 | - end | |
| 127 | - | |
| 128 | - should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do | |
| 129 | - Article.delete_all | |
| 130 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 131 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | |
| 132 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | |
| 133 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) | |
| 134 | - block.parent_nodes = [f.id] | |
| 135 | - block.save! | |
| 136 | - | |
| 137 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 138 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 139 | - expected_json = [] | |
| 140 | - value = {'data' => f.title} | |
| 141 | - value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 142 | - children = [ | |
| 143 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, | |
| 123 | + assert_equivalent [expected_json], json_response | |
| 124 | + end | |
| 125 | + | |
| 126 | + should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do | |
| 127 | + Article.delete_all | |
| 128 | + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 129 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | |
| 130 | + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | |
| 131 | + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) | |
| 132 | + block.checked_nodes = {a1.id => true} | |
| 133 | + block.save! | |
| 134 | + | |
| 135 | + get :index, :block_id => block.id, :profile => profile.identifier | |
| 136 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
| 137 | + expected_json = [] | |
| 138 | + value = {'data' => f.title} | |
| 139 | + value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 140 | + children = [ | |
| 141 | + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id, "class" => "jstree-checked"}}, | |
| 144 | 142 | {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} |
| 145 | 143 | ] |
| 146 | 144 | value['attr'].merge!({'class' => 'jstree-undetermined'}) | ... | ... |
plugins/display_content/test/unit/display_content_block_test.rb
| ... | ... | @@ -23,7 +23,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 23 | 23 | assert_equal [], block.nodes |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | - should 'not set nodes if there is no holder' do | |
| 26 | + should 'not expand nodes if there is no holder' do | |
| 27 | 27 | Article.delete_all |
| 28 | 28 | a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => 1) |
| 29 | 29 | |
| ... | ... | @@ -31,7 +31,9 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 31 | 31 | block = DisplayContentBlock.new |
| 32 | 32 | block.stubs(:holder).returns(nil) |
| 33 | 33 | block.checked_nodes= checked_articles |
| 34 | - assert_equal [], block.nodes | |
| 34 | + a1.delete | |
| 35 | + block.save! | |
| 36 | + assert_equal [a1.id], block.nodes | |
| 35 | 37 | end |
| 36 | 38 | |
| 37 | 39 | should 'nodes be the article ids in hash of checked nodes' do |
| ... | ... | @@ -90,28 +92,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 90 | 92 | assert_equal [], block.nodes - [a1.id, a4.id] |
| 91 | 93 | end |
| 92 | 94 | |
| 93 | - should "save the first children level of folders" do | |
| 94 | - profile = create_user('testuser').person | |
| 95 | - Article.delete_all | |
| 96 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 97 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id) | |
| 98 | - f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 99 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f1.id) | |
| 100 | - f2 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 101 | - a4 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f2.id) | |
| 102 | - a5 = fast_create(TextileArticle, :name => 'test article 5', :profile_id => profile.id, :parent_id => f2.id) | |
| 103 | - | |
| 104 | - checked_articles= {a1.id => true, a2.id => true, f1.id => false, f2.id => true} | |
| 105 | - | |
| 106 | - block = DisplayContentBlock.new | |
| 107 | - block.stubs(:holder).returns(profile) | |
| 108 | - block.checked_nodes= checked_articles | |
| 109 | - | |
| 110 | - assert_equal [], [a1.id, a2.id, a3.id, a4.id, a5.id] - block.nodes | |
| 111 | - assert_equal [], block.nodes - [a1.id, a2.id, a3.id, a4.id, a5.id] | |
| 112 | - end | |
| 113 | - | |
| 114 | - should "not save deeper level of folder's children" do | |
| 95 | + should "save selected folders and articles" do | |
| 115 | 96 | profile = create_user('testuser').person |
| 116 | 97 | Article.delete_all |
| 117 | 98 | a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) |
| ... | ... | @@ -128,11 +109,10 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 128 | 109 | block.stubs(:holder).returns(profile) |
| 129 | 110 | block.checked_nodes= checked_articles |
| 130 | 111 | |
| 131 | - assert_equal [], [a1.id, a2.id, a3.id] - block.nodes | |
| 132 | - assert_equal [], block.nodes - [a1.id, a2.id, a3.id] | |
| 112 | + assert_equivalent [a1.id, a2.id, f1.id], block.nodes | |
| 133 | 113 | end |
| 134 | 114 | |
| 135 | - should "save the first children level of blogs" do | |
| 115 | + should "save selected articles and blogs" do | |
| 136 | 116 | profile = create_user('testuser').person |
| 137 | 117 | Article.delete_all |
| 138 | 118 | a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) |
| ... | ... | @@ -149,8 +129,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 149 | 129 | block.stubs(:holder).returns(profile) |
| 150 | 130 | block.checked_nodes= checked_articles |
| 151 | 131 | |
| 152 | - assert_equal [], [a1.id, a2.id, a3.id, a4.id, a5.id] - block.nodes | |
| 153 | - assert_equal [], block.nodes - [a1.id, a2.id, a3.id, a4.id, a5.id] | |
| 132 | + assert_equivalent [a1.id, a2.id, b1.id, b2.id], block.nodes | |
| 154 | 133 | end |
| 155 | 134 | |
| 156 | 135 | should 'TextileArticle be saved as node' do |
| ... | ... | @@ -192,7 +171,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 192 | 171 | assert_equal [], block.nodes - [a1.id] |
| 193 | 172 | end |
| 194 | 173 | |
| 195 | - should 'Event not be saved as node' do | |
| 174 | + should 'Event be saved as node' do | |
| 196 | 175 | profile = create_user('testuser').person |
| 197 | 176 | Article.delete_all |
| 198 | 177 | a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) |
| ... | ... | @@ -203,41 +182,10 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 203 | 182 | block = DisplayContentBlock.new |
| 204 | 183 | block.stubs(:holder).returns(profile) |
| 205 | 184 | block.checked_nodes= checked_articles |
| 206 | - assert_equal [], [a1.id, a2.id] - block.nodes | |
| 207 | - assert_equal [], block.nodes - [a1.id, a2.id] | |
| 185 | + assert_equivalent [a1.id, a2.id, a3.id], block.nodes | |
| 208 | 186 | end |
| 209 | 187 | |
| 210 | - should 'RSS not be saved as node' do | |
| 211 | - profile = create_user('testuser').person | |
| 212 | - Article.delete_all | |
| 213 | - a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 214 | - a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id) | |
| 215 | - a3 = fast_create(RssFeed, :name => 'test article 3', :profile_id => profile.id) | |
| 216 | - | |
| 217 | - checked_articles= {a1.id => true, a2.id => true, a3.id => false} | |
| 218 | - block = DisplayContentBlock.new | |
| 219 | - block.stubs(:holder).returns(profile) | |
| 220 | - block.checked_nodes= checked_articles | |
| 221 | - assert_equal [], [a1.id, a2.id] - block.nodes | |
| 222 | - assert_equal [], block.nodes - [a1.id, a2.id] | |
| 223 | - end | |
| 224 | - | |
| 225 | - should 'UploadedFile not be saved as node' do | |
| 226 | - profile = create_user('testuser').person | |
| 227 | - Article.delete_all | |
| 228 | - a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 229 | - a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id) | |
| 230 | - a3 = fast_create(UploadedFile, :name => 'test article 3', :profile_id => profile.id) | |
| 231 | - | |
| 232 | - checked_articles= {a1.id => true, a2.id => true, a3.id => false} | |
| 233 | - block = DisplayContentBlock.new | |
| 234 | - block.stubs(:holder).returns(profile) | |
| 235 | - block.checked_nodes= checked_articles | |
| 236 | - assert_equal [], [a1.id, a2.id] - block.nodes | |
| 237 | - assert_equal [], block.nodes - [a1.id, a2.id] | |
| 238 | - end | |
| 239 | - | |
| 240 | - should 'Folder not be saved as node' do | |
| 188 | + should 'Folder be saved as node' do | |
| 241 | 189 | profile = create_user('testuser').person |
| 242 | 190 | Article.delete_all |
| 243 | 191 | a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) |
| ... | ... | @@ -248,11 +196,10 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 248 | 196 | block = DisplayContentBlock.new |
| 249 | 197 | block.stubs(:holder).returns(profile) |
| 250 | 198 | block.checked_nodes= checked_articles |
| 251 | - assert_equal [], [a1.id, a2.id] - block.nodes | |
| 252 | - assert_equal [], block.nodes - [a1.id, a2.id] | |
| 199 | + assert_equivalent [a1.id, a2.id, a3.id], block.nodes | |
| 253 | 200 | end |
| 254 | 201 | |
| 255 | - should 'Forum not be saved as node' do | |
| 202 | + should 'Forum be saved as node' do | |
| 256 | 203 | profile = create_user('testuser').person |
| 257 | 204 | Article.delete_all |
| 258 | 205 | a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) |
| ... | ... | @@ -263,26 +210,10 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 263 | 210 | block = DisplayContentBlock.new |
| 264 | 211 | block.stubs(:holder).returns(profile) |
| 265 | 212 | block.checked_nodes= checked_articles |
| 266 | - assert_equal [], [a1.id, a2.id] - block.nodes | |
| 267 | - assert_equal [], block.nodes - [a1.id, a2.id] | |
| 268 | - end | |
| 269 | - | |
| 270 | - should 'Gallery not be saved as node' do | |
| 271 | - profile = create_user('testuser').person | |
| 272 | - Article.delete_all | |
| 273 | - a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 274 | - a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id) | |
| 275 | - a3 = fast_create(Gallery, :name => 'test article 3', :profile_id => profile.id) | |
| 276 | - | |
| 277 | - checked_articles= {a1.id => true, a2.id => true, a3.id => false} | |
| 278 | - block = DisplayContentBlock.new | |
| 279 | - block.stubs(:holder).returns(profile) | |
| 280 | - block.checked_nodes= checked_articles | |
| 281 | - assert_equal [], [a1.id, a2.id] - block.nodes | |
| 282 | - assert_equal [], block.nodes - [a1.id, a2.id] | |
| 213 | + assert_equivalent [a1.id, a2.id, a3.id], block.nodes | |
| 283 | 214 | end |
| 284 | 215 | |
| 285 | - should 'Blog not be saved as node' do | |
| 216 | + should 'Blog be saved as node' do | |
| 286 | 217 | profile = create_user('testuser').person |
| 287 | 218 | Article.delete_all |
| 288 | 219 | a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) |
| ... | ... | @@ -293,141 +224,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 293 | 224 | block = DisplayContentBlock.new |
| 294 | 225 | block.stubs(:holder).returns(profile) |
| 295 | 226 | block.checked_nodes= checked_articles |
| 296 | - assert_equal [], [a1.id, a2.id] - block.nodes | |
| 297 | - assert_equal [], block.nodes - [a1.id, a2.id] | |
| 298 | - end | |
| 299 | - | |
| 300 | - should "save the article parents in parent_nodes variable" do | |
| 301 | - profile = create_user('testuser').person | |
| 302 | - Article.delete_all | |
| 303 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 304 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id) | |
| 305 | - f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 306 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f1.id) | |
| 307 | - f2 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 308 | - a4 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f2.id) | |
| 309 | - | |
| 310 | - checked_articles= {a1.id => 1, a3.id => 1, a4.id => 1, f2.id => true} | |
| 311 | - | |
| 312 | - block = DisplayContentBlock.new | |
| 313 | - block.stubs(:holder).returns(profile) | |
| 314 | - block.checked_nodes= checked_articles | |
| 315 | - | |
| 316 | - assert_equal [], [f1.id, f2.id] - block.parent_nodes | |
| 317 | - assert_equal [], block.parent_nodes - [f1.id, f2.id] | |
| 318 | - end | |
| 319 | - | |
| 320 | - should "save deeper level of article parents in parent_nodes variable" do | |
| 321 | - profile = create_user('testuser').person | |
| 322 | - Article.delete_all | |
| 323 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 324 | - f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 325 | - f2 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id, :parent_id => f1.id) | |
| 326 | - f3 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id, :parent_id => f2.id) | |
| 327 | - a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f3.id) | |
| 328 | - | |
| 329 | - checked_articles= {a2.id => 1} | |
| 330 | - | |
| 331 | - block = DisplayContentBlock.new | |
| 332 | - block.stubs(:holder).returns(profile) | |
| 333 | - block.checked_nodes= checked_articles | |
| 334 | - | |
| 335 | - assert_equal [], [f1.id, f2.id, f3.id] - block.parent_nodes | |
| 336 | - assert_equal [], block.parent_nodes - [f1.id, f2.id, f3.id] | |
| 337 | - end | |
| 338 | - | |
| 339 | - should "save only once time of parents if more than one children article is checked" do | |
| 340 | - profile = create_user('testuser').person | |
| 341 | - Article.delete_all | |
| 342 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 343 | - f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 344 | - a2 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f1.id) | |
| 345 | - f2 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 346 | - a3 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f2.id) | |
| 347 | - a4 = fast_create(TextileArticle, :name => 'test article 5', :profile_id => profile.id, :parent_id => f2.id) | |
| 348 | - a5 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f2.id) | |
| 349 | - | |
| 350 | - checked_articles= {a1.id => 1, a2.id => 1, a3.id => 1, a4.id => 1, a5.id => 1} | |
| 351 | - | |
| 352 | - block = DisplayContentBlock.new | |
| 353 | - block.stubs(:holder).returns(profile) | |
| 354 | - block.checked_nodes= checked_articles | |
| 355 | - | |
| 356 | - assert_equal [], [f1.id, f2.id] - block.parent_nodes | |
| 357 | - assert_equal [], block.parent_nodes - [f1.id, f2.id] | |
| 358 | - end | |
| 359 | - | |
| 360 | - should "save only once time of parents if a deeper level of children is checked" do | |
| 361 | - profile = create_user('testuser').person | |
| 362 | - Article.delete_all | |
| 363 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 364 | - f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 365 | - f2 = fast_create(Folder, :name => 'test folder 2', :profile_id => profile.id, :parent_id => f1.id) | |
| 366 | - f3 = fast_create(Folder, :name => 'test folder 2', :profile_id => profile.id, :parent_id => f2.id) | |
| 367 | - f4 = fast_create(Folder, :name => 'test folder 2', :profile_id => profile.id, :parent_id => f3.id) | |
| 368 | - f5 = fast_create(Folder, :name => 'test folder 2', :profile_id => profile.id, :parent_id => f2.id) | |
| 369 | - a2 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f4.id) | |
| 370 | - a3 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f5.id) | |
| 371 | - | |
| 372 | - checked_articles= {a2.id => 1, a3.id => 1} | |
| 373 | - | |
| 374 | - block = DisplayContentBlock.new | |
| 375 | - block.stubs(:holder).returns(profile) | |
| 376 | - block.checked_nodes= checked_articles | |
| 377 | - | |
| 378 | - assert_equal [], [f1.id, f2.id, f3.id, f4.id, f5.id] - block.parent_nodes | |
| 379 | - assert_equal [], block.parent_nodes - [f1.id, f2.id, f3.id, f4.id, f5.id] | |
| 380 | - end | |
| 381 | - | |
| 382 | - should "save the folder in parent_nodes variable if it was checked" do | |
| 383 | - profile = create_user('testuser').person | |
| 384 | - Article.delete_all | |
| 385 | - f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 386 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | |
| 387 | - a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f1.id) | |
| 388 | - | |
| 389 | - checked_articles= {f1.id => 1} | |
| 390 | - | |
| 391 | - block = DisplayContentBlock.new | |
| 392 | - block.stubs(:holder).returns(profile) | |
| 393 | - block.checked_nodes= checked_articles | |
| 394 | - | |
| 395 | - assert_equal [], [f1.id] - block.parent_nodes | |
| 396 | - assert_equal [], block.parent_nodes - [f1.id] | |
| 397 | - end | |
| 398 | - | |
| 399 | - should "save the blog in parent_nodes variable if it was checked" do | |
| 400 | - profile = create_user('testuser').person | |
| 401 | - Article.delete_all | |
| 402 | - b1 = fast_create(Blog, :name => 'test folder 1', :profile_id => profile.id) | |
| 403 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => b1.id) | |
| 404 | - a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => b1.id) | |
| 405 | - | |
| 406 | - checked_articles= {b1.id => 1} | |
| 407 | - | |
| 408 | - block = DisplayContentBlock.new | |
| 409 | - block.stubs(:holder).returns(profile) | |
| 410 | - block.checked_nodes= checked_articles | |
| 411 | - | |
| 412 | - assert_equal [], [b1.id] - block.parent_nodes | |
| 413 | - assert_equal [], block.parent_nodes - [b1.id] | |
| 414 | - end | |
| 415 | - | |
| 416 | - should "save the forum in parent_nodes variable if it was checked" do | |
| 417 | - profile = create_user('testuser').person | |
| 418 | - Article.delete_all | |
| 419 | - f1 = fast_create(Forum, :name => 'test folder 1', :profile_id => profile.id) | |
| 420 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | |
| 421 | - a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f1.id) | |
| 422 | - | |
| 423 | - checked_articles= {f1.id => 1} | |
| 424 | - | |
| 425 | - block = DisplayContentBlock.new | |
| 426 | - block.stubs(:holder).returns(profile) | |
| 427 | - block.checked_nodes= checked_articles | |
| 428 | - | |
| 429 | - assert_equal [], [f1.id] - block.parent_nodes | |
| 430 | - assert_equal [], block.parent_nodes - [f1.id] | |
| 227 | + assert_equivalent [a1.id, a2.id, a3.id], block.nodes | |
| 431 | 228 | end |
| 432 | 229 | |
| 433 | 230 | should "return all root articles from profile" do |
| ... | ... | @@ -672,4 +469,37 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 672 | 469 | assert block.display_attribute?('body') |
| 673 | 470 | end |
| 674 | 471 | |
| 472 | + should 'do not save children if a folder is checked' do | |
| 473 | + profile = create_user('testuser').person | |
| 474 | + Article.delete_all | |
| 475 | + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 476 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | |
| 477 | + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f1.id) | |
| 478 | + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f1.id) | |
| 479 | + | |
| 480 | + checked_articles= {f1.id => true, a1.id => true, a2.id => true, a3.id => false} | |
| 481 | + block = DisplayContentBlock.new | |
| 482 | + block.stubs(:holder).returns(profile) | |
| 483 | + block.checked_nodes= checked_articles | |
| 484 | + block.save! | |
| 485 | + assert_equivalent [f1.id], block.nodes | |
| 486 | + end | |
| 487 | + | |
| 488 | + should 'save folder and children if display_folder_children is false' do | |
| 489 | + profile = create_user('testuser').person | |
| 490 | + Article.delete_all | |
| 491 | + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 492 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | |
| 493 | + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f1.id) | |
| 494 | + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f1.id) | |
| 495 | + | |
| 496 | + checked_articles= {f1.id => true, a1.id => true, a2.id => true, a3.id => false} | |
| 497 | + block = DisplayContentBlock.new | |
| 498 | + block.display_folder_children = false | |
| 499 | + block.stubs(:holder).returns(profile) | |
| 500 | + block.checked_nodes= checked_articles | |
| 501 | + block.save! | |
| 502 | + assert_equivalent [f1.id, a1.id, a2.id, a3.id], block.nodes | |
| 503 | + end | |
| 504 | + | |
| 675 | 505 | end | ... | ... |
plugins/display_content/views/box_organizer/_display_content_block.rhtml
| ... | ... | @@ -11,6 +11,10 @@ |
| 11 | 11 | <div id="display_content"> |
| 12 | 12 | </div> |
| 13 | 13 | |
| 14 | +<div class="display_folder_children"> | |
| 15 | + <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %> | |
| 16 | +</div> | |
| 17 | + | |
| 14 | 18 | <script type="text/javascript" > |
| 15 | 19 | |
| 16 | 20 | jQuery_1_8_3("#display_content").jstree({ | ... | ... |