@@ -36,116 +36,27 @@ module WorkPackagesHelper
3636 # Examples:
3737 #
3838 # link_to_work_package(package) # => Defect #6: This is the subject
39- # link_to_work_package(package, all_link: true) # => Defect #6: This is the subject (everything within the link)
40- # link_to_work_package(package, truncate: 9) # => Defect #6: This i...
41- # link_to_work_package(package, subject: false) # => Defect #6
42- # link_to_work_package(package, type: false) # => #6: This is the subject
43- # link_to_work_package(package, project: true) # => Foo - Defect #6
44- # link_to_work_package(package, id_only: true) # => #6
45- # link_to_work_package(package, subject_only: true) # => This is the subject (as link)
46- # link_to_work_package(package, status: true) # => #6 New (if #id => true)
47- def link_to_work_package ( package , options = { } )
48- if options [ :subject_only ]
49- options . merge! ( type : false ,
50- subject : true ,
51- id : false ,
52- all_link : true )
53- elsif options [ :id_only ]
54- options . merge! ( type : false ,
55- subject : false ,
56- id : true ,
57- all_link : true )
58- else
59- options . reverse_merge! ( type : true ,
60- subject : true ,
61- id : true )
62- end
63-
64- parts = { prefix : [ ] ,
65- hidden_link : [ ] ,
66- link : [ ] ,
67- suffix : [ ] ,
68- title : [ ] ,
69- css_class : link_to_work_package_css_classes ( package , options ) }
70-
71- # Prefix part
72-
73- parts [ :prefix ] << package . project . to_s if options [ :project ]
74-
75- # Link part
76-
77- parts [ :link ] << h ( options [ :before_text ] . to_s ) if options [ :before_text ]
78-
79- parts [ :link ] << h ( package . type . to_s ) if options [ :type ]
80-
81- parts [ :link ] << "##{ h ( package . id ) } " if options [ :id ]
82-
83- parts [ :link ] << h ( package . status ) . to_s if options [ :id ] && options [ :status ] && package . status_id
84-
85- # Hidden link part
86-
87- if package . closed? && !options [ :no_hidden ]
88- parts [ :hidden_link ] << content_tag ( :span ,
89- I18n . t ( :label_closed_work_packages ) ,
90- class : "sr-only" )
39+ # link_to_work_package(package, link_subject: true) # => Defect #6: This is the subject (everything within the link)
40+ # link_to_work_package(package, display_project: true) # => Foo - Defect #6: This is the subject
41+ def link_to_work_package ( work_package , display_project : false , link_subject : false ) # rubocop:disable Metrics/AbcSize
42+ output = "" . html_safe
43+ output << "#{ work_package . project } - " if display_project && work_package . project_id
44+
45+ link = link_to ( work_package_path ( work_package ) ,
46+ title : work_package . subject ,
47+ class : link_to_work_package_css_classes ( work_package ) ) do
48+ link_parts = [ ]
49+ link_parts << work_package . type . to_s if work_package . type_id
50+ link_parts << "##{ work_package . id } :"
51+ link_parts << content_tag ( :span , I18n . t ( :label_closed_work_packages ) , class : "sr-only" ) if work_package . closed?
52+ link_parts << work_package . subject if link_subject
53+
54+ safe_join ( link_parts , " " )
9155 end
9256
93- # Suffix part
94-
95- if options [ :subject ]
96- subject = if options [ :subject ]
97- subject = package . subject
98- if options [ :truncate ]
99- subject = truncate ( subject , length : options [ :truncate ] )
100- end
101-
102- subject
103- end
104-
105- parts [ :suffix ] << h ( subject )
106- end
107-
108- # title part
109-
110- parts [ :title ] << ( options [ :title ] . nil? ? package . subject : options [ :title ] )
111-
112- # combining
113-
114- prefix = parts [ :prefix ] . join ( " " )
115- suffix = parts [ :suffix ] . join ( " " )
116- link = parts [ :link ] . join ( " " ) . strip
117- hidden_link = parts [ :hidden_link ] . join
118- title = parts [ :title ] . join ( " " )
119- css_class = parts [ :css_class ] . join ( " " )
120-
121- # Determine path or url
122- work_package_link =
123- if options . fetch ( :only_path , true )
124- work_package_path ( package )
125- else
126- work_package_url ( package )
127- end
128-
129- if options [ :all_link ]
130- link_text = [ prefix , link ] . reject ( &:empty? ) . join ( " - " )
131- link_text = [ link_text , suffix ] . reject ( &:empty? ) . join ( ": " )
132- link_text = [ hidden_link , link_text ] . reject ( &:empty? ) . join
133-
134- link_to ( link_text . html_safe ,
135- work_package_link ,
136- title :,
137- class : css_class )
138- else
139- link_text = [ hidden_link , link ] . reject ( &:empty? ) . join
140-
141- html_link = link_to ( link_text . html_safe ,
142- work_package_link ,
143- title :,
144- class : css_class )
145-
146- [ [ prefix , html_link ] . reject ( &:empty? ) . join ( " - " ) ,
147- suffix ] . reject ( &:empty? ) . join ( ": " )
148- end . html_safe
57+ output << link
58+ output << " #{ work_package . subject } " unless link_subject
59+ output
14960 end
15061
15162 def work_package_list ( work_packages , &)
@@ -176,7 +87,7 @@ def work_package_formatted_dates(work_package)
17687 "#{ start_date } - #{ due_date } "
17788 end
17889
179- def send_notification_option ( checked = false )
90+ def send_notification_option ( checked : false )
18091 content_tag ( :label , for : "send_notification" , class : "form--label-with-check-box" ) do
18192 ( content_tag "span" , class : "form--check-box-container" do
18293 boxes = hidden_field_tag ( "send_notification" , "0" , id : nil )
@@ -220,10 +131,10 @@ def last_work_package_note(work_package)
220131
221132 def work_packages_columns_options
222133 @work_packages_columns_options ||= Query
223- . new
224- . displayable_columns
225- . sort_by ( &:caption )
226- . map { |column | { name : column . caption , id : column . name . to_s } }
134+ . new
135+ . displayable_columns
136+ . sort_by ( &:caption )
137+ . map { |column | { name : column . caption , id : column . name . to_s } }
227138 end
228139
229140 def selected_work_packages_columns_options
@@ -232,13 +143,14 @@ def selected_work_packages_columns_options
232143 end
233144
234145 def protected_work_packages_columns_options
146+ protected_columns = %w[ id subject ]
235147 work_packages_columns_options
236- . select { |column | column [ :id ] == "id" || column [ :id ] == "subject" }
148+ . select { |column | protected_columns . include? ( column [ :id ] ) }
237149 end
238150
239151 private
240152
241- def truncated_work_package_description ( work_package , lines = 3 )
153+ def truncated_work_package_description ( work_package , lines = 3 ) # rubocop:disable Metrics/AbcSize
242154 description_lines = work_package . description . to_s . lines . to_a [ 0 , lines ]
243155
244156 if description_lines [ lines - 1 ] && work_package . description . to_s . lines . to_a . size > lines
@@ -261,24 +173,9 @@ def truncated_work_package_description(work_package, lines = 3)
261173 end
262174 end
263175
264- def info_user_attributes ( work_package )
265- responsible = if work_package . responsible_id . present?
266- "<span class='label'>#{ WorkPackage . human_attribute_name ( :responsible ) } :</span> " +
267- h ( work_package . responsible . name ) . to_s
268- end
269-
270- assignee = if work_package . assigned_to_id . present?
271- "<span class='label'>#{ WorkPackage . human_attribute_name ( :assigned_to ) } :</span> " +
272- h ( work_package . assigned_to . name ) . to_s
273- end
274-
275- [ responsible , assignee ] . compact . join ( "<br>" ) . html_safe
276- end
277-
278- def link_to_work_package_css_classes ( package , options )
176+ def link_to_work_package_css_classes ( package )
279177 classes = [ "work_package" ]
280178 classes << "closed" if package . closed?
281- classes << options [ :class ] . to_s
282179
283180 classes
284181 end
0 commit comments