summaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/my_helper.rb55
-rw-r--r--app/helpers/queries_helper.rb18
2 files changed, 46 insertions, 27 deletions
diff --git a/app/helpers/my_helper.rb b/app/helpers/my_helper.rb
index 3975d80b1..2a20a7bf2 100644
--- a/app/helpers/my_helper.rb
+++ b/app/helpers/my_helper.rb
@@ -44,16 +44,17 @@ module MyHelper
# Renders a single block content
def render_block_content(block, user)
- unless Redmine::MyPage.blocks.key?(block)
+ unless block_definition = Redmine::MyPage.blocks[block]
Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences")
return
end
settings = user.pref.my_page_settings(block)
+ partial = block_definition[:partial]
begin
- render(:partial => "my/blocks/#{block}", :locals => {:user => user, :settings => settings})
+ render(:partial => partial, :locals => {:user => user, :settings => settings, :block => block})
rescue ActionView::MissingTemplate
- Rails.logger.warn("Template missing for block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences")
+ Rails.logger.warn("Partial \"#{partial}\" missing for block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences")
return nil
end
end
@@ -80,30 +81,38 @@ module MyHelper
Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).to_a
end
- def issuesassignedtome_items
- Issue.visible.open.
- assigned_to(User.current).
- limit(10).
- includes(:status, :project, :tracker, :priority).
- references(:status, :project, :tracker, :priority).
- order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC")
+ def issues_items(block, settings)
+ send "#{block}_items", settings
end
- def issuesreportedbyme_items
- Issue.visible.open.
- where(:author_id => User.current.id).
- limit(10).
- includes(:status, :project, :tracker, :priority).
- references(:status, :project, :tracker).
- order("#{Issue.table_name}.updated_on DESC")
+ def issuesassignedtome_items(settings)
+ query = IssueQuery.new(:name => l(:label_assigned_to_me_issues), :user => User.current)
+ query.add_filter 'assigned_to_id', '=', ['me']
+ query.column_names = settings[:columns].presence || ['project', 'tracker', 'status', 'subject']
+ query.sort_criteria = settings[:sort].presence || [['priority', 'desc'], ['updated_on', 'desc']]
+ issues = query.issues(:limit => 10)
+
+ return issues, query
end
- def issueswatched_items
- Issue.visible.open.
- on_active_project.watched_by(User.current.id).
- preload(:status, :project, :tracker, :priority).
- recently_updated.
- limit(10)
+ def issuesreportedbyme_items(settings)
+ query = IssueQuery.new(:name => l(:label_reported_issues), :user => User.current)
+ query.add_filter 'author_id', '=', ['me']
+ query.column_names = settings[:columns].presence || ['project', 'tracker', 'status', 'subject']
+ query.sort_criteria = settings[:sort].presence || [['updated_on', 'desc']]
+ issues = query.issues(:limit => 10)
+
+ return issues, query
+ end
+
+ def issueswatched_items(settings)
+ query = IssueQuery.new(:name => l(:label_watched_issues), :user => User.current)
+ query.add_filter 'watcher_id', '=', ['me']
+ query.column_names = settings[:columns].presence || ['project', 'tracker', 'status', 'subject']
+ query.sort_criteria = settings[:sort].presence || [['updated_on', 'desc']]
+ issues = query.issues(:limit => 10)
+
+ return issues, query
end
def news_items
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 1d0db2877..b4a0a0b75 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -161,7 +161,7 @@ module QueriesHelper
content_tag('span', label + " " + value, :class => "total-for-#{column.name.to_s.dasherize}")
end
- def column_header(query, column)
+ def column_header(query, column, options={})
if column.sortable?
css, order = nil, column.default_order
if column.name.to_s == query.sort_criteria.first_key
@@ -173,11 +173,21 @@ module QueriesHelper
order = 'asc'
end
end
- sort_param = { :sort => query.sort_criteria.add(column.name, order).to_param }
- content = link_to(column.caption,
- {:params => request.query_parameters.merge(sort_param)},
+ param_key = options[:sort_param] || :sort
+ sort_param = { param_key => query.sort_criteria.add(column.name, order).to_param }
+ while sort_param.keys.first.to_s =~ /^(.+)\[(.+)\]$/
+ sort_param = {$1 => {$2 => sort_param.values.first}}
+ end
+ link_options = {
:title => l(:label_sort_by, "\"#{column.caption}\""),
:class => css
+ }
+ if options[:sort_link_options]
+ link_options.merge! options[:sort_link_options]
+ end
+ content = link_to(column.caption,
+ {:params => request.query_parameters.deep_merge(sort_param)},
+ link_options
)
else
content = column.caption