]> source.dussan.org Git - redmine.git/commitdiff
Use helper methods for rendering blocks.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 16 Mar 2017 18:26:43 +0000 (18:26 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 16 Mar 2017 18:26:43 +0000 (18:26 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16414 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/_news.html.erb
app/views/my/blocks/_timelog.html.erb
lib/redmine/my_page.rb

index e40ccc27d18f36e85ea68cecc353c5605a6d176a..e49afc21bc58dd1f9980dd2054b462d40da3aba1 100644 (file)
@@ -65,6 +65,7 @@ module MyHelper
     end
   end
 
+  # Returns the select tag used to add a block to My page
   def block_select_tag(user)
     blocks_in_use = user.pref.my_page_layout.values.flatten
     options = content_tag('option')
@@ -74,21 +75,22 @@ module MyHelper
     select_tag('block', options, :id => "block-select", :onchange => "$('#block-form').submit();")
   end
 
-  def calendar_items(startdt, enddt)
-    Issue.visible.
+  def render_calendar_block(block, settings)
+    calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :week)
+    calendar.events = 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).
+      where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", calendar.startdt, calendar.enddt, calendar.startdt, calendar.enddt).
       includes(:project, :tracker, :priority, :assigned_to).
       references(:project, :tracker, :priority, :assigned_to).
       to_a
-  end
 
-  def documents_items
-    Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).to_a
+    render :partial => 'my/blocks/calendar', :locals => {:calendar => calendar, :block => block}
   end
 
-  def issues_items(block, settings)
-    send "#{block}_items", settings
+  def render_documents_block(block, settings)
+    documents = Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).to_a
+
+    render :partial => 'my/blocks/documents', :locals => {:block => block, :documents => documents}
   end
 
   def render_issuesassignedtome_block(block, settings)
@@ -134,17 +136,19 @@ module MyHelper
     end
   end
 
-  def news_items
-    News.visible.
+  def render_news_block(block, settings)
+    news = 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
+
+    render :partial => 'my/blocks/news', :locals => {:block => block, :news => news}
   end
 
-  def timelog_items(settings={})
+  def render_timelog_block(block, settings)
     days = settings[:days].to_i
     days = 7 if days < 1 || days > 365
 
@@ -155,7 +159,8 @@ module MyHelper
       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
+    entries_by_day = entries.group_by(&:spent_on)
 
-    return entries, days
+    render :partial => 'my/blocks/timelog', :locals => {:block => block, :entries => entries, :entries_by_day => entries_by_day, :days => days}
   end
 end
index 89dde0e01b88622423183a78b03ae383f076e537..c85190f2a5aaf8cc3e15700ed38613024c3ba8e6 100644 (file)
@@ -1,6 +1,3 @@
 <h3><%= l(:label_calendar) %></h3>
 
-<% calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :week)
-   calendar.events = calendar_items(calendar.startdt, calendar.enddt) %>
-
 <%= render :partial => 'common/calendar', :locals => {:calendar => calendar } %>
index a55094cf1ffcaca462c8dff198f9b4ad0c3fe3d3..560adca1eda4b316e609c10f517b1acfbdc4d146 100644 (file)
@@ -1,3 +1,3 @@
 <h3><%=l(:label_document_plural)%></h3>
 
-<%= render :partial => 'documents/document', :collection => documents_items %>
+<%= render :partial => 'documents/document', :collection => documents %>
index c478e4196229f9f9228a183ff7f2fc8651ac092c..62a618617ad1aa000b0efe0e5d07b6ce571cac74 100644 (file)
@@ -1,3 +1,3 @@
 <h3><%=l(:label_news_latest)%></h3>
 
-<%= render :partial => 'news/news', :collection => news_items %>
+<%= render :partial => 'news/news', :collection => news %>
index 83716d35eab4d111e9cc1d8440b68ad19793b0ec..da181c27ea5c0700ca8de69fa3331a3fc8d31f50 100644 (file)
@@ -1,8 +1,3 @@
-<%
-entries, days = timelog_items(settings)
-entries_by_day = entries.group_by(&:spent_on)
-%>
-
 <div class="contextual">
   <%= link_to_function l(:label_options), "$('#timelog-settings').toggle();", :class => 'icon-only icon-settings', :title => l(:label_options) %>
 </div>
index 34195bbcd1dedc1d7789669758a9f0a056e93bac..02feb54bb9487575100ee0924d18d1e4a766fcec 100644 (file)
@@ -24,10 +24,10 @@ module Redmine
         'issuesreportedbyme' => {:label => :label_reported_issues},
         'issueswatched' => {:label => :label_watched_issues},
         'issuequery' => {:label => :label_issue_plural, :max_occurs => 3},
-        'news' => {:label => :label_news_latest, :partial => 'my/blocks/news'},
-        'calendar' => {:label => :label_calendar, :partial => 'my/blocks/calendar'},
-        'documents' => {:label => :label_document_plural, :partial => 'my/blocks/documents'},
-        'timelog' => {:label => :label_spent_time, :partial => 'my/blocks/timelog'}
+        'news' => {:label => :label_news_latest},
+        'calendar' => {:label => :label_calendar},
+        'documents' => {:label => :label_document_plural},
+        'timelog' => {:label => :label_spent_time}
       }
 
     # Returns the available blocks