Commit abdeef43007690c8c81f81cc57d55382574ebb99
Exists in
master
and in
28 other branches
Merge remote-tracking branch 'participa/AI2937-folder_display_content' into folder-display-content
Conflicts: plugins/display_content/lib/display_content_block.rb plugins/display_content/test/unit/display_content_block_test.rb
Showing
5 changed files
with
128 additions
and
289 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
... | ... | @@ -16,7 +16,6 @@ class DisplayContentBlock < Block |
16 | 16 | ] |
17 | 17 | |
18 | 18 | settings_items :nodes, :type => Array, :default => [] |
19 | - settings_items :parent_nodes, :type => Array, :default => [] | |
20 | 19 | settings_items :sections, |
21 | 20 | :type => Array, |
22 | 21 | :default => [{:name => _('Publish date'), :checked => true}, |
... | ... | @@ -25,6 +24,7 @@ class DisplayContentBlock < Block |
25 | 24 | {:name => _('Body'), :checked => false}, |
26 | 25 | {:name => _('Image'), :checked => false}, |
27 | 26 | {:name => _('Tags'), :checked => false}] |
27 | + settings_items :display_folder_children, :type => :boolean, :default => true | |
28 | 28 | |
29 | 29 | def self.description |
30 | 30 | _('Display your contents') |
... | ... | @@ -35,20 +35,28 @@ class DisplayContentBlock < Block |
35 | 35 | end |
36 | 36 | |
37 | 37 | def checked_nodes= params |
38 | + self.nodes = params.keys | |
39 | + end | |
40 | + | |
41 | + before_save :expand_nodes | |
42 | + | |
43 | + def expand_nodes | |
38 | 44 | return self.nodes if self.holder.nil? |
39 | - articles = [] | |
40 | - parent_articles = [] | |
41 | - self.holder.articles.find(params.keys).map do |article| | |
42 | - if article.folder? | |
43 | - articles = articles + article.children | |
44 | - parent_articles << article.id | |
45 | - else | |
46 | - articles<< article | |
47 | - end | |
48 | - parent_articles = parent_articles + get_parent(article) unless parent_articles.include?(article.parent_id) | |
45 | + | |
46 | + articles = self.holder.articles.find(nodes) | |
47 | + children = articles.map { |article| article.children }.compact.flatten | |
48 | + | |
49 | + if display_folder_children | |
50 | + articles = articles - children | |
51 | + else | |
52 | + articles = (articles + children).uniq | |
49 | 53 | end |
50 | - self.parent_nodes = parent_articles | |
51 | - self.nodes = articles.map{|a| a.id if a.is_a?(TextArticle) }.compact | |
54 | + | |
55 | + self.nodes = articles.map(&:id) | |
56 | + end | |
57 | + | |
58 | + def parent_nodes | |
59 | + @parent_nodes ||= self.holder.articles.find(nodes).map { |article| get_parent(article) }.compact.flatten | |
52 | 60 | end |
53 | 61 | |
54 | 62 | VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] |
... | ... | @@ -60,17 +68,18 @@ class DisplayContentBlock < Block |
60 | 68 | |
61 | 69 | include ActionController::UrlWriter |
62 | 70 | def content(args={}) |
63 | - docs = owner.articles.find(:all, :conditions => {:id => self.nodes}) | |
71 | + extra_condition = display_folder_children ? 'OR articles.parent_id IN(:nodes)':'' | |
72 | + 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}]) | |
64 | 73 | |
65 | 74 | block_title(title) + |
66 | - content_tag('ul', docs.map {|item| | |
67 | - | |
68 | - content_sections = '' | |
69 | - read_more_section = '' | |
70 | - tags_section = '' | |
71 | - | |
72 | - sections.select { |section| | |
73 | - case section[:name] | |
75 | + content_tag('ul', docs.map {|item| | |
76 | + if !item.folder? | |
77 | + content_sections = '' | |
78 | + read_more_section = '' | |
79 | + tags_section = '' | |
80 | + | |
81 | + sections.select { |section| | |
82 | + case section[:name] | |
74 | 83 | when 'Publish date' |
75 | 84 | content_sections += (display_section?(section) ? (content_tag('div', show_date(item.published_at, false), :class => 'published-at') ) : '') |
76 | 85 | when 'Title' |
... | ... | @@ -92,14 +101,14 @@ class DisplayContentBlock < Block |
92 | 101 | tags_section = item.tags.map { |t| content_tag('span', t.name) }.join("") |
93 | 102 | content_sections += (display_section?(section) ? (content_tag('div', tags_section, :class => 'tags')) : '') |
94 | 103 | end |
95 | - end | |
96 | - } | |
104 | + end | |
105 | + } | |
97 | 106 | |
98 | - content_sections += read_more_section if !read_more_section.blank? | |
107 | + content_sections += read_more_section if !read_more_section.blank? | |
99 | 108 | |
100 | - content_tag('li', content_sections) | |
109 | + content_tag('li', content_sections) | |
110 | + end | |
101 | 111 | }.join(" ")) |
102 | - | |
103 | 112 | end |
104 | 113 | |
105 | 114 | def url_params |
... | ... | @@ -121,7 +130,7 @@ class DisplayContentBlock < Block |
121 | 130 | |
122 | 131 | def holder |
123 | 132 | return nil if self.box.nil? || self.owner.nil? |
124 | - if self.owner.kind_of?(Environment) | |
133 | + if self.owner.kind_of?(Environment) | |
125 | 134 | return nil if self.owner.portal_community.nil? |
126 | 135 | self.owner.portal_community |
127 | 136 | else | ... | ... |
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 |
... | ... | @@ -696,4 +493,37 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
696 | 493 | assert_match /#{a.published_at}/, block.content |
697 | 494 | end |
698 | 495 | |
496 | + should 'do not save children if a folder is checked' do | |
497 | + profile = create_user('testuser').person | |
498 | + Article.delete_all | |
499 | + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
500 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | |
501 | + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f1.id) | |
502 | + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f1.id) | |
503 | + | |
504 | + checked_articles= {f1.id => true, a1.id => true, a2.id => true, a3.id => false} | |
505 | + block = DisplayContentBlock.new | |
506 | + block.stubs(:holder).returns(profile) | |
507 | + block.checked_nodes= checked_articles | |
508 | + block.save! | |
509 | + assert_equivalent [f1.id], block.nodes | |
510 | + end | |
511 | + | |
512 | + should 'save folder and children if display_folder_children is false' do | |
513 | + profile = create_user('testuser').person | |
514 | + Article.delete_all | |
515 | + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
516 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | |
517 | + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f1.id) | |
518 | + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id, :parent_id => f1.id) | |
519 | + | |
520 | + checked_articles= {f1.id => true, a1.id => true, a2.id => true, a3.id => false} | |
521 | + block = DisplayContentBlock.new | |
522 | + block.display_folder_children = false | |
523 | + block.stubs(:holder).returns(profile) | |
524 | + block.checked_nodes= checked_articles | |
525 | + block.save! | |
526 | + assert_equivalent [f1.id, a1.id, a2.id, a3.id], block.nodes | |
527 | + end | |
528 | + | |
699 | 529 | end | ... | ... |
plugins/display_content/views/box_organizer/_display_content_block.rhtml
... | ... | @@ -17,6 +17,10 @@ |
17 | 17 | <div id="display_content"> |
18 | 18 | </div> |
19 | 19 | |
20 | +<div class="display_folder_children"> | |
21 | + <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %> | |
22 | +</div> | |
23 | + | |
20 | 24 | <script type="text/javascript" > |
21 | 25 | |
22 | 26 | jQuery_1_8_3("#display_content").jstree({ | ... | ... |