2011-12-14 19:56:23 +00:00
# encoding: utf-8
#
2011-08-31 08:40:05 +00:00
# Redmine - project management software
2016-03-13 10:30:10 +00:00
# Copyright (C) 2006-2016 Jean-Philippe Lang
2006-12-03 19:55:45 +00:00
#
# 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.
2011-08-31 08:40:05 +00:00
#
2006-12-03 19:55:45 +00:00
# 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.
2011-08-31 08:40:05 +00:00
#
2006-12-03 19:55:45 +00:00
# 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.
module MyHelper
2016-10-29 08:10:19 +00:00
# Renders the blocks
def render_blocks ( blocks , user , options = { } )
s = '' . html_safe
if blocks . present?
blocks . each do | block |
content = render_block_content ( block , user )
if content . present?
if options [ :edit ]
2016-10-29 08:22:37 +00:00
close = link_to ( l ( :button_delete ) , { :action = > " remove_block " , :block = > block } , :method = > 'post' , :class = > " icon-only icon-close " )
2016-10-29 08:10:19 +00:00
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
# Renders a single block content
def render_block_content ( block , user )
2016-10-29 10:10:31 +00:00
unless Redmine :: MyPage . blocks . key? ( block )
2016-10-29 08:10:19 +00:00
Rails . logger . warn ( " Unknown block \" #{ block } \" found in #{ user . login } (id= #{ user . id } ) preferences " )
return
end
begin
render ( :partial = > " my/blocks/ #{ block } " , :locals = > { :user = > user } )
rescue ActionView :: MissingTemplate
Rails . logger . warn ( " Template missing for block \" #{ block } \" found in #{ user . login } (id= #{ user . id } ) preferences " )
return nil
end
end
2016-10-29 10:10:31 +00:00
def block_select_tag ( user )
disabled = user . pref . my_page_layout . values . flatten
options = content_tag ( 'option' )
Redmine :: MyPage . block_options . each do | label , block |
options << content_tag ( 'option' , label , :value = > block , :disabled = > disabled . include? ( block ) )
end
content_tag ( 'select' , options , :id = > " block-select " )
end
2012-12-02 21:08:03 +00:00
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 ) .
2014-10-22 17:37:16 +00:00
references ( :project , :tracker , :priority , :assigned_to ) .
to_a
2012-12-02 21:08:03 +00:00
end
def documents_items
2014-10-22 17:37:16 +00:00
Document . visible . order ( " #{ Document . table_name } .created_on DESC " ) . limit ( 10 ) . to_a
2012-12-02 21:08:03 +00:00
end
def issuesassignedtome_items
Issue . visible . open .
2015-10-21 17:00:14 +00:00
assigned_to ( User . current ) .
2012-12-02 21:08:03 +00:00
limit ( 10 ) .
includes ( :status , :project , :tracker , :priority ) .
2014-10-22 17:37:16 +00:00
references ( :status , :project , :tracker , :priority ) .
2015-10-21 16:45:42 +00:00
order ( " #{ IssuePriority . table_name } .position DESC, #{ Issue . table_name } .updated_on DESC " )
2012-12-02 21:08:03 +00:00
end
def issuesreportedbyme_items
2016-08-31 16:58:17 +00:00
Issue . visible . open .
2012-12-02 21:08:03 +00:00
where ( :author_id = > User . current . id ) .
limit ( 10 ) .
includes ( :status , :project , :tracker ) .
2014-10-22 17:37:16 +00:00
references ( :status , :project , :tracker ) .
2015-10-21 16:45:42 +00:00
order ( " #{ Issue . table_name } .updated_on DESC " )
2012-12-02 21:08:03 +00:00
end
def issueswatched_items
2016-04-09 09:57:37 +00:00
Issue . visible . open . on_active_project . watched_by ( User . current . id ) . recently_updated . limit ( 10 )
2012-12-02 21:08:03 +00:00
end
def news_items
News . visible .
where ( :project_id = > User . current . projects . map ( & :id ) ) .
limit ( 10 ) .
includes ( :project , :author ) .
2014-10-22 17:37:16 +00:00
references ( :project , :author ) .
2012-12-02 21:08:03 +00:00
order ( " #{ News . table_name } .created_on DESC " ) .
2014-10-22 17:37:16 +00:00
to_a
2012-12-02 21:08:03 +00:00
end
def timelog_items
TimeEntry .
2016-05-07 10:42:22 +00:00
where ( " #{ TimeEntry . table_name } .user_id = ? AND #{ TimeEntry . table_name } .spent_on BETWEEN ? AND ? " , User . current . id , User . current . today - 6 , User . current . today ) .
2015-03-10 19:42:45 +00:00
joins ( :activity , :project ) .
references ( :issue = > [ :tracker , :status ] ) .
includes ( :issue = > [ :tracker , :status ] ) .
2012-12-02 21:08:03 +00:00
order ( " #{ TimeEntry . table_name } .spent_on DESC, #{ Project . table_name } .name ASC, #{ Tracker . table_name } .position ASC, #{ Issue . table_name } .id ASC " ) .
2014-10-22 17:37:16 +00:00
to_a
2012-12-02 21:08:03 +00:00
end
2006-12-03 19:55:45 +00:00
end