Redmineのコアビューに追加のSQLクエリを追加(プラグインのビューをオーバーライド)
-
05-07-2019 - |
質問
プラグイン(/views/reports/_details.rhtml)のRedmineコアビューをオーバーライドしています。割り当てられている未割り当ての問題と割り当てられていない問題の数など、追加のデータを印刷するため。
代わりにコントローラーをオーバーライドし、これを行うメソッドを追加しようとしましたが、機能しませんでしたので、ビューに以下のコードを追加しました(そう、見苦しいですが、ページはめったに使用されません)。
私の問題により、ビューはすべてのトラッカー(row.id)をループし、開いている問題と閉じている問題の数などの情報を表示しています。そこで、追加のSQLクエリを追加しましたが、最初のトラッカーの反復でのみ機能し、残りの部分では同じデータを繰り返し表示します。
development.logを見ると、SQLクエリは1つしかありません。しかし、row.id(<!> lt;%= row.id%<!> gt;)を出力すると、各トラッカーの正しい値が表示されます。
これをどのように解決すればよいですか
_details.rhtmlのコード
<% @total_assigned_and_open ||=
ActiveRecord::Base.connection.select_all("select count(i.id) as total
from
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Tracker.table_name} t
where
i.status_id=s.id
and i.tracker_id=#{row.id}
and i.project_id=#{@project.id}
and i.assigned_to_id is null
and s.is_closed = 0
group by s.id, s.is_closed, t.id limit 1") %>
development.logのSQLクエリ
select count(i.id) as total
from
issues i, issue_statuses s, trackers t
where
i.status_id=s.id
and i.tracker_id=1
and i.project_id=1
and i.assigned_to_id is null
and s.is_closed = 0
group by s.id, s.is_closed, t.id limit 1
(以前はRuby on RailsやRedmineを使用したことはありません...)
解決
選択したプロジェクトのすべての問題を選択する2つのSQLクエリ(ビュー内)を追加して解決しました。
<% @all_unsigned_issues ||=
ActiveRecord::Base.connection.select_all("select i.status_id as status, s.is_closed as
closed, t.id as tracker_id, count(i.id) as total
from
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Tracker.table_name} t
where
i.assigned_to_id is null
and i.project_id=#{@project.id}
and i.status_id=s.id
and i.tracker_id=t.id
group by i.id") %>
次に使用します。
<%= aggregate_link @all_unsigned_issues, { "tracker_id" => row.id, "status" => 5 },
:controller => 'issues', :action => 'index', :project_id => ((row.is_a?(Project) ? row : @project)) %>
所属していません StackOverflow