Module: MyHelper
- Defined in:
- app/helpers/my_helper.rb
Overview
Redmine - project management software Copyright (C) 2006-2016 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
- #calendar_items(startdt, enddt) ⇒ Object
- #documents_items ⇒ Object
- #issuesassignedtome_items ⇒ Object
- #issuesreportedbyme_items ⇒ Object
- #issueswatched_items ⇒ Object
- #news_items ⇒ Object
-
#render_block_content(block, user) ⇒ Object
Renders a single block content.
-
#render_blocks(blocks, user, options = {}) ⇒ Object
Renders the blocks.
- #timelog_items(settings = {}) ⇒ Object
Instance Method Details
#block_select_tag(user) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/helpers/my_helper.rb', line 57 def block_select_tag(user) disabled = user.pref.my_page_layout.values.flatten = content_tag('option') Redmine::MyPage..each do |label, block| << content_tag('option', label, :value => block, :disabled => disabled.include?(block)) end select_tag('block', , :id => "block-select") end |
#calendar_items(startdt, enddt) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/helpers/my_helper.rb', line 66 def calendar_items(startdt, enddt) Issue.visible. where(:project_id => User.current.projects.map(&:id)). where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", startdt, enddt, startdt, enddt). includes(:project, :tracker, :priority, :assigned_to). references(:project, :tracker, :priority, :assigned_to). to_a end |
#documents_items ⇒ Object
75 76 77 |
# File 'app/helpers/my_helper.rb', line 75 def documents_items Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).to_a end |
#issuesassignedtome_items ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'app/helpers/my_helper.rb', line 79 def issuesassignedtome_items Issue.visible.open. assigned_to(User.current). limit(10). includes(:status, :project, :tracker, :priority). references(:status, :project, :tracker, :priority). order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") end |
#issuesreportedbyme_items ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'app/helpers/my_helper.rb', line 88 def issuesreportedbyme_items Issue.visible.open. where(:author_id => User.current.id). limit(10). includes(:status, :project, :tracker). references(:status, :project, :tracker). order("#{Issue.table_name}.updated_on DESC") end |
#issueswatched_items ⇒ Object
97 98 99 |
# File 'app/helpers/my_helper.rb', line 97 def issueswatched_items Issue.visible.open.on_active_project.watched_by(User.current.id).recently_updated.limit(10) end |
#news_items ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'app/helpers/my_helper.rb', line 101 def news_items News.visible. where(:project_id => User.current.projects.map(&:id)). limit(10). includes(:project, :author). references(:project, :author). order("#{News.table_name}.created_on DESC"). to_a end |
#render_block_content(block, user) ⇒ Object
Renders a single block content
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/my_helper.rb', line 42 def render_block_content(block, user) unless Redmine::MyPage.blocks.key?(block) Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") return end settings = user.pref.my_page_settings(block) begin render(:partial => "my/blocks/#{block}", :locals => {:user => user, :settings => settings}) rescue ActionView::MissingTemplate Rails.logger.warn("Template missing for block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") return nil end end |
#render_blocks(blocks, user, options = {}) ⇒ Object
Renders the blocks
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/my_helper.rb', line 22 def render_blocks(blocks, user, ={}) s = ''.html_safe if blocks.present? blocks.each do |block| content = render_block_content(block, user) if content.present? if [:edit] close = link_to(l(:button_delete), {:action => "remove_block", :block => block}, :method => 'post', :class => "icon-only icon-close") content = close + content_tag('div', content, :class => 'handle') end s << content_tag('div', content, :class => "mypage-box", :id => "block-#{block}") end end end s end |
#timelog_items(settings = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/helpers/my_helper.rb', line 111 def timelog_items(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 return entries, days end |