11module KnowledgebaseHelper
22 include Redmine ::Export ::PDF
33 include KnowledgebaseSettingsHelper
4+ include ActionView ::Helpers ::NumberHelper
45
56 def format_article_summary ( article , format , options = { } )
67 output = case format
78 when "normal"
8- truncate article . summary , :length => options [ :truncate ]
9+ ""
10+ #truncate article.summary, :length => options[:truncate]
911 when "newest"
1012 l ( :label_summary_newest_articles ,
1113 :ago => time_ago_in_words ( article . created_at ) ,
@@ -19,15 +21,24 @@ def format_article_summary(article, format, options = {})
1921 :count => article . view_count ,
2022 :created => article . created_at . to_date . to_formatted_s ( :rfc822 ) )
2123 when "toprated"
22- l ( :label_summary_toprated_articles ,
23- :rating_avg => article . rating_average . to_s ,
24- :rating_max => "5" ,
25- :count => article . rated_count )
24+ if article . rating_average . to_i == 0
25+ l ( :label_unrated_article )
26+ else
27+ l ( :label_summary_toprated_articles ,
28+ :rating_avg => article . rating_average . to_s ,
29+ :rating_max => "5" ,
30+ :count => article . rated_count )
31+ end
2632 else
2733 nil
2834 end
2935
30- content_tag ( :div , raw ( output ) , :class => "summary" )
36+ sum = ""
37+ unless redmine_knowledgebase_settings_value ( :disable_article_summaries )
38+ sum = "<p>" + ( truncate article . summary , :length => options [ :truncate ] ) + "</p>"
39+ end
40+
41+ content_tag ( :div , raw ( sum + output ) , :class => "summary" )
3142 end
3243
3344 def sort_categories?
@@ -54,7 +65,7 @@ def sortable(column, title = nil)
5465 title ||= column . titleize
5566 css_class = column == sort_column ? "current #{ sort_direction } " : nil
5667 direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
57- link_to title , { :id => params [ :id ] , :sort => column , :direction => direction } , { :class => css_class }
68+ link_to title , { :id => params [ :id ] , :tag => params [ :tag ] , :author_id => params [ :author_id ] , : sort => column , :direction => direction } , { :class => css_class }
5869 end
5970
6071 def article_to_pdf ( article , project )
@@ -94,13 +105,29 @@ def write_article(pdf, article)
94105 end
95106
96107 def article_tabs
97- tabs = [ { :name => 'content' , :action => :content , :partial => 'articles/sections/content' , :label => :label_content } ,
98- { :name => 'comments' , :action => :comments , :partial => 'articles/sections/comments' , :label => :label_comment_plural } ,
99- { :name => 'attachments' , :action => :attachments , :partial => 'articles/sections/attachments' , :label => :label_attachment_plural } ,
100- { :name => 'history' , :action => :history , :partial => 'articles/sections/history' , :label => :label_history }
101- ]
108+
109+ content = { :name => 'content' , :action => :content , :partial => 'articles/sections/content' , :label => :label_content }
110+ comments = { :name => 'comments' , :action => :comments , :partial => 'articles/sections/comments' , :label => :label_comment_plural }
111+ attachments = { :name => 'attachments' , :action => :attachments , :partial => 'articles/sections/attachments' , :label => :label_attachment_plural }
112+ history = { :name => 'history' , :action => :history , :partial => 'articles/sections/history' , :label => :label_history }
113+
114+ unless redmine_knowledgebase_settings_value ( :show_attachments_first )
115+
116+ tabs = [ content , comments , attachments , history ]
117+ else
118+
119+ tabs = [ attachments , content , comments , history ]
120+ end
121+
122+ # Do not show History if no permission
123+ unless User . current . allowed_to? ( :view_article_history , @project )
124+ tabs . pop ( 1 )
125+ end
126+
102127 # TODO permissions?
103128 # tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
129+
130+ return tabs
104131 end
105132
106133 def create_preview_link
0 commit comments