在Redmine核心视图中添加额外的SQL查询(覆盖插件中的视图)
我正在覆盖插件中的 Redmine 核心视图 (/views/reports/_details.rhtml)。只是为了打印一些额外的数据,例如已分配和未分配的未决问题数。
我尝试重写控制器并添加一个方法来执行此操作,但我从未让它工作,因此我将下面的代码添加到视图中(是的,它很丑陋,但页面很少被使用)。
现在我的问题是,视图在所有跟踪器 (row.id) 中循环并显示信息,例如有多少问题处于打开和关闭状态。所以我添加了一个额外的 SQL 查询,但它只适用于第一次跟踪器迭代,其余的它会一遍又一遍地显示相同的数据。
当我查看development.log 时,其中只有一个SQL 查询。但是当我输出 row.id (<%= row.id %>) 时,它会显示每个跟踪器的正确值。
我应该如何解决这个问题?
_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...)
I'am overriding a Redmine core view in my plugin (/views/reports/_details.rhtml). Just to print some extra data, like how many open issues are assigned and not assigned.
I tried to override the controller instead and add a method to do this, but I never got it to work, so I added the code below to the view (yes, it's ugly, but the page will rarely by used).
Now to my problem, the view are looping trough all trackers (row.id) and showing information, like how many issues are open and closed. So I have added a extra SQL query, but it only works for the first tracker iteration, for the rest it shows the same data over and over again.
When I look at the development.log there are only one SQL query in it. But when I output row.id (<%= row.id %>) it shows the correct value for each tracker.
How should i solve this?
Code in _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") %>
SQL query in development.log
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
(Never used Ruby on Rails or Redmine before...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过添加两个 SQL 查询(在视图中)来解决这个问题,该查询选择所选项目的所有问题。
然后我用。
I solved it by adding two SQL queries (in the view) that selects all issues to the selected project.
Then I use.