@@ -1,119 +1,119 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2016 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module MyHelper |
|
20 | module MyHelper | |
21 | # Renders the blocks |
|
21 | # Renders the blocks | |
22 | def render_blocks(blocks, user, options={}) |
|
22 | def render_blocks(blocks, user, options={}) | |
23 | s = ''.html_safe |
|
23 | s = ''.html_safe | |
24 |
|
24 | |||
25 | if blocks.present? |
|
25 | if blocks.present? | |
26 | blocks.each do |block| |
|
26 | blocks.each do |block| | |
27 | content = render_block_content(block, user) |
|
27 | content = render_block_content(block, user) | |
28 | if content.present? |
|
28 | if content.present? | |
29 | if options[:edit] |
|
29 | if options[:edit] | |
30 | close = link_to(l(:button_delete), {:action => "remove_block", :block => block}, :method => 'post', :class => "icon-only icon-close") |
|
30 | close = link_to(l(:button_delete), {:action => "remove_block", :block => block}, :method => 'post', :class => "icon-only icon-close") | |
31 | content = close + content_tag('div', content, :class => 'handle') |
|
31 | content = close + content_tag('div', content, :class => 'handle') | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | s << content_tag('div', content, :class => "mypage-box", :id => "block-#{block}") |
|
34 | s << content_tag('div', content, :class => "mypage-box", :id => "block-#{block}") | |
35 | end |
|
35 | end | |
36 | end |
|
36 | end | |
37 | end |
|
37 | end | |
38 | s |
|
38 | s | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | # Renders a single block content |
|
41 | # Renders a single block content | |
42 | def render_block_content(block, user) |
|
42 | def render_block_content(block, user) | |
43 | unless Redmine::MyPage.blocks.key?(block) |
|
43 | unless Redmine::MyPage.blocks.key?(block) | |
44 | Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") |
|
44 | Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") | |
45 | return |
|
45 | return | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | begin |
|
48 | begin | |
49 | render(:partial => "my/blocks/#{block}", :locals => {:user => user}) |
|
49 | render(:partial => "my/blocks/#{block}", :locals => {:user => user}) | |
50 | rescue ActionView::MissingTemplate |
|
50 | rescue ActionView::MissingTemplate | |
51 | Rails.logger.warn("Template missing for block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") |
|
51 | Rails.logger.warn("Template missing for block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") | |
52 | return nil |
|
52 | return nil | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def block_select_tag(user) |
|
56 | def block_select_tag(user) | |
57 | disabled = user.pref.my_page_layout.values.flatten |
|
57 | disabled = user.pref.my_page_layout.values.flatten | |
58 | options = content_tag('option') |
|
58 | options = content_tag('option') | |
59 | Redmine::MyPage.block_options.each do |label, block| |
|
59 | Redmine::MyPage.block_options.each do |label, block| | |
60 | options << content_tag('option', label, :value => block, :disabled => disabled.include?(block)) |
|
60 | options << content_tag('option', label, :value => block, :disabled => disabled.include?(block)) | |
61 | end |
|
61 | end | |
62 |
c |
|
62 | select_tag('block', options, :id => "block-select") | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def calendar_items(startdt, enddt) |
|
65 | def calendar_items(startdt, enddt) | |
66 | Issue.visible. |
|
66 | Issue.visible. | |
67 | where(:project_id => User.current.projects.map(&:id)). |
|
67 | where(:project_id => User.current.projects.map(&:id)). | |
68 | where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", startdt, enddt, startdt, enddt). |
|
68 | where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", startdt, enddt, startdt, enddt). | |
69 | includes(:project, :tracker, :priority, :assigned_to). |
|
69 | includes(:project, :tracker, :priority, :assigned_to). | |
70 | references(:project, :tracker, :priority, :assigned_to). |
|
70 | references(:project, :tracker, :priority, :assigned_to). | |
71 | to_a |
|
71 | to_a | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def documents_items |
|
74 | def documents_items | |
75 | Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).to_a |
|
75 | Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).to_a | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def issuesassignedtome_items |
|
78 | def issuesassignedtome_items | |
79 | Issue.visible.open. |
|
79 | Issue.visible.open. | |
80 | assigned_to(User.current). |
|
80 | assigned_to(User.current). | |
81 | limit(10). |
|
81 | limit(10). | |
82 | includes(:status, :project, :tracker, :priority). |
|
82 | includes(:status, :project, :tracker, :priority). | |
83 | references(:status, :project, :tracker, :priority). |
|
83 | references(:status, :project, :tracker, :priority). | |
84 | order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") |
|
84 | order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def issuesreportedbyme_items |
|
87 | def issuesreportedbyme_items | |
88 | Issue.visible.open. |
|
88 | Issue.visible.open. | |
89 | where(:author_id => User.current.id). |
|
89 | where(:author_id => User.current.id). | |
90 | limit(10). |
|
90 | limit(10). | |
91 | includes(:status, :project, :tracker). |
|
91 | includes(:status, :project, :tracker). | |
92 | references(:status, :project, :tracker). |
|
92 | references(:status, :project, :tracker). | |
93 | order("#{Issue.table_name}.updated_on DESC") |
|
93 | order("#{Issue.table_name}.updated_on DESC") | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def issueswatched_items |
|
96 | def issueswatched_items | |
97 | Issue.visible.open.on_active_project.watched_by(User.current.id).recently_updated.limit(10) |
|
97 | Issue.visible.open.on_active_project.watched_by(User.current.id).recently_updated.limit(10) | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def news_items |
|
100 | def news_items | |
101 | News.visible. |
|
101 | News.visible. | |
102 | where(:project_id => User.current.projects.map(&:id)). |
|
102 | where(:project_id => User.current.projects.map(&:id)). | |
103 | limit(10). |
|
103 | limit(10). | |
104 | includes(:project, :author). |
|
104 | includes(:project, :author). | |
105 | references(:project, :author). |
|
105 | references(:project, :author). | |
106 | order("#{News.table_name}.created_on DESC"). |
|
106 | order("#{News.table_name}.created_on DESC"). | |
107 | to_a |
|
107 | to_a | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def timelog_items |
|
110 | def timelog_items | |
111 | TimeEntry. |
|
111 | TimeEntry. | |
112 | where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, User.current.today - 6, User.current.today). |
|
112 | where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, User.current.today - 6, User.current.today). | |
113 | joins(:activity, :project). |
|
113 | joins(:activity, :project). | |
114 | references(:issue => [:tracker, :status]). |
|
114 | references(:issue => [:tracker, :status]). | |
115 | includes(:issue => [:tracker, :status]). |
|
115 | includes(:issue => [:tracker, :status]). | |
116 | order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC"). |
|
116 | order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC"). | |
117 | to_a |
|
117 | to_a | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end |
General Comments 0
You need to be logged in to leave comments.
Login now