To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / my_helper.rb @ 1541:2696466256ff

History | View | Annotate | Download (2.8 KB)

1
# encoding: utf-8
2
#
3
# Redmine - project management software
4
# Copyright (C) 2006-2014  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

    
20
module MyHelper
21

    
22
  def calendar_items(startdt, enddt)
23
    Issue.visible.
24
      where(:project_id => User.current.projects.map(&:id)).
25
      where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", startdt, enddt, startdt, enddt).
26
      includes(:project, :tracker, :priority, :assigned_to).
27
      all
28
  end
29

    
30
  def all_colleagues_of(user)
31
    # Return a list of all user ids who have worked with the given user
32
    # (on projects that are visible to the current user)
33
    user.projects.select { |p| p.visible? }.map { |p| p.members.map { |m| m.user_id } }.flatten.sort.uniq.reject { |i| user.id == i }
34
  end
35

    
36
  def documents_items
37
    Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).all
38
  end
39

    
40
  def issuesassignedtome_items
41
    Issue.visible.open.
42
      where(:assigned_to_id => ([User.current.id] + User.current.group_ids)).
43
      limit(10).
44
      includes(:status, :project, :tracker, :priority).
45
      order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC").
46
      all
47
  end
48

    
49
  def issuesreportedbyme_items
50
    Issue.visible.
51
      where(:author_id => User.current.id).
52
      limit(10).
53
      includes(:status, :project, :tracker).
54
      order("#{Issue.table_name}.updated_on DESC").
55
      all
56
  end
57

    
58
  def issueswatched_items
59
    Issue.visible.on_active_project.watched_by(User.current.id).recently_updated.limit(10).all
60
  end
61

    
62
  def news_items
63
    News.visible.
64
      where(:project_id => User.current.projects.map(&:id)).
65
      limit(10).
66
      includes(:project, :author).
67
      order("#{News.table_name}.created_on DESC").
68
      all
69
  end
70

    
71
  def timelog_items
72
    TimeEntry.
73
      where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, Date.today - 6, Date.today).
74
      includes(:activity, :project, {:issue => [:tracker, :status]}).
75
      order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC").
76
      all
77
  end
78
end