]> source.dussan.org Git - redmine.git/commitdiff
Adds helpers for retrieving my page data.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Dec 2012 21:08:03 +0000 (21:08 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Dec 2012 21:08:03 +0000 (21:08 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10922 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/my_helper.rb
app/views/my/blocks/_calendar.html.erb
app/views/my/blocks/_documents.html.erb
app/views/my/blocks/_issuesassignedtome.html.erb
app/views/my/blocks/_issuesreportedbyme.html.erb
app/views/my/blocks/_issueswatched.html.erb
app/views/my/blocks/_news.html.erb
app/views/my/blocks/_timelog.html.erb

index d8a624cc12655c812a58929c62cf02561bab259c..f81f09463dc5050b5a47c0ee7c59413a15c77516 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 module MyHelper
+  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).
+      all
+  end
+
+  def documents_items
+    Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).all
+  end
+
+  def issuesassignedtome_items
+    Issue.visible.open.
+      where(:assigned_to_id => ([User.current.id] + User.current.group_ids)).
+      limit(10).
+      includes(:status, :project, :tracker, :priority).
+      order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC").
+      all
+  end
+
+  def issuesreportedbyme_items
+    Issue.visible.
+      where(:author_id => User.current.id).
+      limit(10).
+      includes(:status, :project, :tracker).
+      order("#{Issue.table_name}.updated_on DESC").
+      all
+  end
+
+  def issueswatched_items
+    Issue.visible.on_active_project.watched_by(User.current.id).recently_updated.limit(10).all
+  end
+
+  def news_items
+    News.visible.
+      where(:project_id => User.current.projects.map(&:id)).
+      limit(10).
+      includes(:project, :author).
+      order("#{News.table_name}.created_on DESC").
+      all
+  end
+
+  def timelog_items
+    TimeEntry.
+      where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, Date.today - 6, Date.today).
+      includes(:activity, :project, {: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").
+      all
+  end
 end
index 9c6b793bfbc4f8826335034913a10ec6da5cc989..41ca18a10affee90d6e4f468d7fc5a2652f91dd3 100644 (file)
@@ -1,8 +1,6 @@
 <h3><%= l(:label_calendar) %></h3>
 
 <% calendar = Redmine::Helpers::Calendar.new(Date.today, current_language, :week)
-   calendar.events = Issue.visible.find :all,
-                     :conditions => ["#{Issue.table_name}.project_id in (#{@user.projects.collect{|m| m.id}.join(',')}) AND ((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", calendar.startdt, calendar.enddt, calendar.startdt, calendar.enddt],
-                     :include => [:project, :tracker, :priority, :assigned_to] unless @user.projects.empty? %>
+   calendar.events = calendar_items(calendar.startdt, calendar.enddt) %>
 
 <%= render :partial => 'common/calendar', :locals => {:calendar => calendar } %>
index d222e42036200ad2c7995c81734061a77be56e1e..a55094cf1ffcaca462c8dff198f9b4ad0c3fe3d3 100644 (file)
@@ -1,9 +1,3 @@
 <h3><%=l(:label_document_plural)%></h3>
 
-<% project_ids = @user.projects.select {|p| @user.allowed_to?(:view_documents, p)}.collect(&:id) %>
-<%= render(:partial => 'documents/document',
-           :collection => Document.find(:all,
-                         :limit => 10,
-                         :order => "#{Document.table_name}.created_on DESC",
-                         :conditions => "#{Document.table_name}.project_id in (#{project_ids.join(',')})",
-                         :include => [:project])) unless project_ids.empty? %>
\ No newline at end of file
+<%= render :partial => 'documents/document', :collection => documents_items %>
index 5391084350faa3c870ad886cd27c7710b00da4ca..02d8c9aa63ecc772525072326e5fc823714b77c2 100644 (file)
@@ -1,10 +1,6 @@
 <h3><%=l(:label_assigned_to_me_issues)%> (<%= Issue.visible.open.count(:conditions => {:assigned_to_id => ([User.current.id] + User.current.group_ids)})%>)</h3>
 
-<% assigned_issues = Issue.visible.open.find(:all,
-                                :conditions => {:assigned_to_id => ([User.current.id] + User.current.group_ids)},
-                                :limit => 10,
-                                :include => [ :status, :project, :tracker, :priority ],
-                                :order => "#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") %>
+<% assigned_issues = issuesassignedtome_items %>
 <%= render :partial => 'issues/list_simple', :locals => { :issues => assigned_issues } %>
 <% if assigned_issues.length > 0 %>
 <p class="small"><%= link_to l(:label_issue_view_all), :controller => 'issues',
index 7bd9bc28d3e8d6fd933970c3b2a387e8fb7329be..06bbda7f83488b3912db06348c8bf857034a7b0f 100644 (file)
@@ -1,10 +1,6 @@
 <h3><%=l(:label_reported_issues)%> (<%= Issue.visible.count(:conditions => { :author_id => User.current.id }) %>)</h3>
 
-<% reported_issues = Issue.visible.find(:all,
-                                :conditions => { :author_id => User.current.id },
-                                :limit => 10,
-                                :include => [ :status, :project, :tracker ],
-                                :order => "#{Issue.table_name}.updated_on DESC") %>
+<% reported_issues = issuesreportedbyme_items %>
 <%= render :partial => 'issues/list_simple', :locals => { :issues => reported_issues } %>
 <% if reported_issues.length > 0 %>
 <p class="small"><%= link_to l(:label_issue_view_all), :controller => 'issues',
index 6bc31ae371b3b8d2231be7d9c57fab5525849354..510920a089426187d7de54ebbdfd05d172e121f4 100644 (file)
@@ -1,5 +1,5 @@
 <h3><%=l(:label_watched_issues)%> (<%= Issue.visible.watched_by(user.id).count %>)</h3>
-<% watched_issues = Issue.visible.on_active_project.watched_by(user.id).recently_updated.limit(10) %>
+<% watched_issues = issueswatched_items %>
 
 <%= render :partial => 'issues/list_simple', :locals => { :issues => watched_issues } %>
 <% if watched_issues.length > 0 %>
index 3c391cedf4375608aa60e132c60eda2fd36e2220..c478e4196229f9f9228a183ff7f2fc8651ac092c 100644 (file)
@@ -1,8 +1,3 @@
 <h3><%=l(:label_news_latest)%></h3>
 
-<%= render(:partial => 'news/news',
-            :collection => News.find(:all,
-                                     :limit => 10,
-                                     :order => "#{News.table_name}.created_on DESC",
-                                     :conditions => "#{News.table_name}.project_id in (#{@user.projects.collect{|m| m.id}.join(',')})",
-                                     :include => [:project, :author])) unless @user.projects.empty? %>
+<%= render :partial => 'news/news', :collection => news_items %>
index a1fe39b15cd3e75331d25d3bc7dc2772a887ae2d..0e0e6142f29fcf12e74eda131025f087aa055214 100644 (file)
@@ -1,9 +1,6 @@
 <h3><%=l(:label_spent_time)%> (<%= l(:label_last_n_days, 7) %>)</h3>
 <%
-entries = TimeEntry.find(:all,
-        :conditions => ["#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", @user.id, Date.today - 6, Date.today],
-        :include => [:activity, :project, {: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")
+entries = timelog_items
 entries_by_day = entries.group_by(&:spent_on)
 %>