Module: MyHelper
- Defined in:
- app/helpers/my_helper.rb
Overview
Redmine - project management software Copyright © 2006-2022 Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Instance Method Summary collapse
-
#block_select_tag(user) ⇒ Object
Returns the select tag used to add a block to My page.
- #render_activity_block(block, settings) ⇒ Object
-
#render_block(block, user) ⇒ Object
Renders a single block.
-
#render_block_content(block, user) ⇒ Object
Renders a single block content.
-
#render_blocks(blocks, user, options = {}) ⇒ Object
Renders the blocks.
- #render_calendar_block(block, settings) ⇒ Object
- #render_documents_block(block, settings) ⇒ Object
- #render_issuequery_block(block, settings) ⇒ Object
- #render_issuesassignedtome_block(block, settings) ⇒ Object
- #render_issuesreportedbyme_block(block, settings) ⇒ Object
- #render_issuesupdatedbyme_block(block, settings) ⇒ Object
- #render_issueswatched_block(block, settings) ⇒ Object
- #render_news_block(block, settings) ⇒ Object
- #render_timelog_block(block, settings) ⇒ Object
Instance Method Details
#block_select_tag(user) ⇒ Object
Returns the select tag used to add a block to My page
69 70 71 72 73 74 75 76 |
# File 'app/helpers/my_helper.rb', line 69 def block_select_tag(user) blocks_in_use = user.pref.my_page_layout.values.flatten = content_tag('option') Redmine::MyPage.(blocks_in_use).each do |label, block| << content_tag('option', label, :value => block, :disabled => block.blank?) end select_tag('block', , :id => "block-select", :onchange => "$('#block-form').submit();") end |
#render_activity_block(block, settings) ⇒ Object
182 183 184 185 186 |
# File 'app/helpers/my_helper.rb', line 182 def render_activity_block(block, settings) events_by_day = Redmine::Activity::Fetcher.new(User.current, :author => User.current).events(nil, nil, :limit => 10).group_by {|event| User.current.time_to_date(event.event_datetime)} render :partial => 'my/blocks/activity', :locals => {:events_by_day => events_by_day} end |
#render_block(block, user) ⇒ Object
Renders a single block
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/my_helper.rb', line 34 def render_block(block, user) content = render_block_content(block, user) if content.present? handle = content_tag('span', '', :class => 'icon-only icon-sort-handle sort-handle', :title => l(:button_move)) close = link_to(l(:button_delete), {:action => "remove_block", :block => block}, :remote => true, :method => 'post', :class => "icon-only icon-close", :title => l(:button_delete)) content = content_tag('div', handle + close, :class => 'contextual') + content content_tag('div', content, :class => "mypage-box", :id => "block-#{block}") end end |
#render_block_content(block, user) ⇒ Object
Renders a single block content
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/my_helper.rb', line 49 def render_block_content(block, user) unless block_definition = Redmine::MyPage.find_block(block) Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") return end settings = user.pref.my_page_settings(block) if partial = block_definition[:partial] begin render(:partial => partial, :locals => {:user => user, :settings => settings, :block => block}) rescue ActionView::MissingTemplate Rails.logger.warn("Partial \"#{partial}\" missing for block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") return nil end else send "render_#{block_definition[:name]}_block", block, settings end end |
#render_blocks(blocks, user, options = {}) ⇒ Object
Renders the blocks
22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/my_helper.rb', line 22 def render_blocks(blocks, user, ={}) s = ''.html_safe if blocks.present? blocks.each do |block| s << render_block(block, user).to_s end end s end |
#render_calendar_block(block, settings) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/my_helper.rb', line 78 def render_calendar_block(block, settings) calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :week) calendar.events = Issue.visible. where(:project => User.current.projects). where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", calendar.startdt, calendar.enddt, calendar.startdt, calendar.enddt). includes(:project, :tracker, :priority, :assigned_to). references(:project, :tracker, :priority, :assigned_to). to_a render :partial => 'my/blocks/calendar', :locals => {:calendar => calendar, :block => block} end |
#render_documents_block(block, settings) ⇒ Object
90 91 92 93 94 |
# File 'app/helpers/my_helper.rb', line 90 def render_documents_block(block, settings) documents = Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).to_a render :partial => 'my/blocks/documents', :locals => {:block => block, :documents => documents} end |
#render_issuequery_block(block, settings) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/helpers/my_helper.rb', line 140 def render_issuequery_block(block, settings) query = IssueQuery.visible.find_by_id(settings[:query_id]) if query query.column_names = settings[:columns] if settings[:columns].present? query.sort_criteria = settings[:sort] if settings[:sort].present? issues = query.issues(:limit => 10) render :partial => 'my/blocks/issues', :locals => {:query => query, :issues => issues, :block => block, :settings => settings} else queries = IssueQuery.visible.sorted render :partial => 'my/blocks/issue_query_selection', :locals => {:queries => queries, :block => block, :settings => settings} end end |
#render_issuesassignedtome_block(block, settings) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/my_helper.rb', line 96 def render_issuesassignedtome_block(block, settings) query = IssueQuery.new(:name => l(:label_assigned_to_me_issues), :user => User.current) query.add_filter 'assigned_to_id', '=', ['me'] query.add_filter 'project.status', '=', ["#{Project::STATUS_ACTIVE}"] query.column_names = settings[:columns].presence || ['project', 'tracker', 'status', 'subject'] query.sort_criteria = settings[:sort].presence || [['priority', 'desc'], ['updated_on', 'desc']] issues = query.issues(:limit => 10) render :partial => 'my/blocks/issues', :locals => {:query => query, :issues => issues, :block => block} end |
#render_issuesreportedbyme_block(block, settings) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'app/helpers/my_helper.rb', line 107 def render_issuesreportedbyme_block(block, settings) query = IssueQuery.new(:name => l(:label_reported_issues), :user => User.current) query.add_filter 'author_id', '=', ['me'] query.add_filter 'project.status', '=', ["#{Project::STATUS_ACTIVE}"] query.column_names = settings[:columns].presence || ['project', 'tracker', 'status', 'subject'] query.sort_criteria = settings[:sort].presence || [['updated_on', 'desc']] issues = query.issues(:limit => 10) render :partial => 'my/blocks/issues', :locals => {:query => query, :issues => issues, :block => block} end |
#render_issuesupdatedbyme_block(block, settings) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'app/helpers/my_helper.rb', line 118 def render_issuesupdatedbyme_block(block, settings) query = IssueQuery.new(:name => l(:label_updated_issues), :user => User.current) query.add_filter 'updated_by', '=', ['me'] query.add_filter 'project.status', '=', ["#{Project::STATUS_ACTIVE}"] query.column_names = settings[:columns].presence || ['project', 'tracker', 'status', 'subject'] query.sort_criteria = settings[:sort].presence || [['updated_on', 'desc']] issues = query.issues(:limit => 10) render :partial => 'my/blocks/issues', :locals => {:query => query, :issues => issues, :block => block} end |
#render_issueswatched_block(block, settings) ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'app/helpers/my_helper.rb', line 129 def render_issueswatched_block(block, settings) query = IssueQuery.new(:name => l(:label_watched_issues), :user => User.current) query.add_filter 'watcher_id', '=', ['me'] query.add_filter 'project.status', '=', ["#{Project::STATUS_ACTIVE}"] query.column_names = settings[:columns].presence || ['project', 'tracker', 'status', 'subject'] query.sort_criteria = settings[:sort].presence || [['updated_on', 'desc']] issues = query.issues(:limit => 10) render :partial => 'my/blocks/issues', :locals => {:query => query, :issues => issues, :block => block} end |
#render_news_block(block, settings) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/helpers/my_helper.rb', line 154 def render_news_block(block, settings) news = News.visible. where(:project => User.current.projects). limit(10). includes(:project, :author). references(:project, :author). order("#{News.table_name}.created_on DESC"). to_a render :partial => 'my/blocks/news', :locals => {:block => block, :news => news} end |
#render_timelog_block(block, settings) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/helpers/my_helper.rb', line 166 def render_timelog_block(block, settings) days = settings[:days].to_i days = 7 if days < 1 || days > 365 entries = TimeEntry. where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, User.current.today - (days - 1), User.current.today). joins(:activity, :project). references(:issue => [:tracker, :status]). includes(:issue => [:tracker, :status]). order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC"). to_a entries_by_day = entries.group_by(&:spent_on) render :partial => 'my/blocks/timelog', :locals => {:block => block, :entries => entries, :entries_by_day => entries_by_day, :days => days} end |