1 Index: test/unit/lib/redmine/menu_manager/menu_item_test.rb |
|
2 =================================================================== |
|
3 --- test/unit/lib/redmine/menu_manager/menu_item_test.rb (リビジョン 8213) |
|
4 +++ test/unit/lib/redmine/menu_manager/menu_item_test.rb (リビジョン 8214) |
|
5 @@ -114,7 +114,7 @@ |
|
6 |
|
7 def test_has_children |
|
8 parent_item = get_menu_item(:test_menu, :parent) |
|
9 - assert parent_item.hasChildren? |
|
10 + assert parent_item.children.present? |
|
11 assert_equal 2, parent_item.children.size |
|
12 assert_equal get_menu_item(:test_menu, :child_menu), parent_item.children[0] |
|
13 assert_equal get_menu_item(:test_menu, :child2_menu), parent_item.children[1] |
|
14 Index: config/environment.rb |
|
15 =================================================================== |
|
16 --- config/environment.rb (リビジョン 8213) |
|
17 +++ config/environment.rb (リビジョン 8214) |
|
18 @@ -54,7 +54,6 @@ |
|
19 # It will automatically turn deliveries on |
|
20 config.action_mailer.perform_deliveries = false |
|
21 |
|
22 - config.gem 'rubytree', :lib => 'tree' |
|
23 config.gem 'coderay', :version => '~>1.0.0' |
|
24 |
|
25 # Load any local configuration that is kept out of source control |
|
26 Index: lib/redmine/menu_manager.rb |
|
27 =================================================================== |
|
28 --- lib/redmine/menu_manager.rb (リビジョン 8213) |
|
29 +++ lib/redmine/menu_manager.rb (リビジョン 8214) |
|
30 @@ -15,93 +15,6 @@ |
|
31 # along with this program; if not, write to the Free Software |
|
32 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
33 |
|
34 -require 'tree' # gem install rubytree |
|
35 - |
|
36 -# Monkey patch the TreeNode to add on a few more methods :nodoc: |
|
37 -module TreeNodePatch |
|
38 - def self.included(base) |
|
39 - base.class_eval do |
|
40 - attr_reader :last_items_count |
|
41 - |
|
42 - alias :old_initilize :initialize |
|
43 - def initialize(name, content = nil) |
|
44 - old_initilize(name, content) |
|
45 - @childrenHash ||= {} |
|
46 - @last_items_count = 0 |
|
47 - extend(InstanceMethods) |
|
48 - end |
|
49 - end |
|
50 - end |
|
51 - |
|
52 - module InstanceMethods |
|
53 - # Adds the specified child node to the receiver node. The child node's |
|
54 - # parent is set to be the receiver. The child is added as the first child in |
|
55 - # the current list of children for the receiver node. |
|
56 - def prepend(child) |
|
57 - raise "Child already added" if @childrenHash.has_key?(child.name) |
|
58 - |
|
59 - @childrenHash[child.name] = child |
|
60 - @children = [child] + @children |
|
61 - child.parent = self |
|
62 - return child |
|
63 - |
|
64 - end |
|
65 - |
|
66 - # Adds the specified child node to the receiver node. The child node's |
|
67 - # parent is set to be the receiver. The child is added at the position |
|
68 - # into the current list of children for the receiver node. |
|
69 - def add_at(child, position) |
|
70 - raise "Child already added" if @childrenHash.has_key?(child.name) |
|
71 - |
|
72 - @childrenHash[child.name] = child |
|
73 - @children = @children.insert(position, child) |
|
74 - child.parent = self |
|
75 - return child |
|
76 - |
|
77 - end |
|
78 - |
|
79 - def add_last(child) |
|
80 - raise "Child already added" if @childrenHash.has_key?(child.name) |
|
81 - |
|
82 - @childrenHash[child.name] = child |
|
83 - @children << child |
|
84 - @last_items_count += 1 |
|
85 - child.parent = self |
|
86 - return child |
|
87 - |
|
88 - end |
|
89 - |
|
90 - # Adds the specified child node to the receiver node. The child node's |
|
91 - # parent is set to be the receiver. The child is added as the last child in |
|
92 - # the current list of children for the receiver node. |
|
93 - def add(child) |
|
94 - raise "Child already added" if @childrenHash.has_key?(child.name) |
|
95 - |
|
96 - @childrenHash[child.name] = child |
|
97 - position = @children.size - @last_items_count |
|
98 - @children.insert(position, child) |
|
99 - child.parent = self |
|
100 - return child |
|
101 - |
|
102 - end |
|
103 - |
|
104 - # Wrapp remove! making sure to decrement the last_items counter if |
|
105 - # the removed child was a last item |
|
106 - def remove!(child) |
|
107 - @last_items_count -= +1 if child && child.last |
|
108 - super |
|
109 - end |
|
110 - |
|
111 - |
|
112 - # Will return the position (zero-based) of the current child in |
|
113 - # it's parent |
|
114 - def position |
|
115 - self.parent.children.index(self) |
|
116 - end |
|
117 - end |
|
118 -end |
|
119 -Tree::TreeNode.send(:include, TreeNodePatch) |
|
120 - |
|
121 module Redmine |
|
122 module MenuManager |
|
123 class MenuError < StandardError #:nodoc: |
|
124 @@ -169,7 +82,7 @@ |
|
125 |
|
126 def display_main_menu?(project) |
|
127 menu_name = project && !project.new_record? ? :project_menu : :application_menu |
|
128 - Redmine::MenuManager.items(menu_name).size > 1 # 1 element is the root |
|
129 + Redmine::MenuManager.items(menu_name).children.present? |
|
130 end |
|
131 |
|
132 def render_menu(menu, project=nil) |
|
133 @@ -181,7 +94,7 @@ |
|
134 end |
|
135 |
|
136 def render_menu_node(node, project=nil) |
|
137 - if node.hasChildren? || !node.child_menus.nil? |
|
138 + if node.children.present? || !node.child_menus.nil? |
|
139 return render_menu_node_with_children(node, project) |
|
140 else |
|
141 caption, url, selected = extract_node_details(node, project) |
|
142 @@ -306,13 +219,13 @@ |
|
143 end |
|
144 |
|
145 def items(menu_name) |
|
146 - @items[menu_name.to_sym] || Tree::TreeNode.new(:root, {}) |
|
147 + @items[menu_name.to_sym] || MenuNode.new(:root, {}) |
|
148 end |
|
149 end |
|
150 |
|
151 class Mapper |
|
152 def initialize(menu, items) |
|
153 - items[menu] ||= Tree::TreeNode.new(:root, {}) |
|
154 + items[menu] ||= MenuNode.new(:root, {}) |
|
155 @menu = menu |
|
156 @menu_items = items[menu] |
|
157 end |
|
158 @@ -398,7 +311,102 @@ |
|
159 end |
|
160 end |
|
161 |
|
162 - class MenuItem < Tree::TreeNode |
|
163 + class MenuNode |
|
164 + include Enumerable |
|
165 + attr_accessor :parent |
|
166 + attr_reader :last_items_count, :name |
|
167 + |
|
168 + def initialize(name, content = nil) |
|
169 + @name = name |
|
170 + @childrenHash ||= {} |
|
171 + @children = [] |
|
172 + @last_items_count = 0 |
|
173 + end |
|
174 + |
|
175 + def children |
|
176 + if block_given? |
|
177 + @children.each {|child| yield child} |
|
178 + else |
|
179 + @children |
|
180 + end |
|
181 + end |
|
182 + |
|
183 + # Returns the number of descendants + 1 |
|
184 + def size |
|
185 + @children.inject(1) {|sum, node| sum + node.size} |
|
186 + end |
|
187 + |
|
188 + def each &block |
|
189 + yield self |
|
190 + children { |child| child.each(&block) } |
|
191 + end |
|
192 + |
|
193 + # Adds a child at first position |
|
194 + def prepend(child) |
|
195 + raise "Child already added" if @childrenHash.has_key?(child.name) |
|
196 + |
|
197 + @childrenHash[child.name] = child |
|
198 + @children = [child] + @children |
|
199 + child.parent = self |
|
200 + return child |
|
201 + end |
|
202 + |
|
203 + # Adds a child at given position |
|
204 + def add_at(child, position) |
|
205 + raise "Child already added" if @childrenHash.has_key?(child.name) |
|
206 + |
|
207 + @childrenHash[child.name] = child |
|
208 + @children = @children.insert(position, child) |
|
209 + child.parent = self |
|
210 + return child |
|
211 + end |
|
212 + |
|
213 + # Adds a child as last child |
|
214 + def add_last(child) |
|
215 + raise "Child already added" if @childrenHash.has_key?(child.name) |
|
216 + |
|
217 + @childrenHash[child.name] = child |
|
218 + @children << child |
|
219 + @last_items_count += 1 |
|
220 + child.parent = self |
|
221 + return child |
|
222 + end |
|
223 + |
|
224 + # Adds a child |
|
225 + def add(child) |
|
226 + raise "Child already added" if @childrenHash.has_key?(child.name) |
|
227 + |
|
228 + @childrenHash[child.name] = child |
|
229 + position = @children.size - @last_items_count |
|
230 + @children.insert(position, child) |
|
231 + child.parent = self |
|
232 + return child |
|
233 + end |
|
234 + alias :<< :add |
|
235 + |
|
236 + # Removes a child |
|
237 + def remove!(child) |
|
238 + @childrenHash.delete(child.name) |
|
239 + @children.delete(child) |
|
240 + @last_items_count -= +1 if child && child.last |
|
241 + child.parent = nil |
|
242 + child |
|
243 + end |
|
244 + |
|
245 + # Returns the position for this node in it's parent |
|
246 + def position |
|
247 + self.parent.children.index(self) |
|
248 + end |
|
249 + |
|
250 + # Returns the root for this node |
|
251 + def root |
|
252 + root = self |
|
253 + root = root.parent while root.parent |
|
254 + root |
|
255 + end |
|
256 + end |
|
257 + |
|
258 + class MenuItem < MenuNode |
|
259 include Redmine::I18n |
|
260 attr_reader :name, :url, :param, :condition, :parent, :child_menus, :last |
|
261 |
|