2008年1月15日火曜日

Redmineに機能追加(終了済み Issue をカレンダーで取り消し線)


--------------------------------
app/views/common/_calendar.rhtml
--------------------------------
<%= h("#{i.project.name} -") unless @project && @project == i.project %>
<%= link_to_issue i %>: <!-- 元の処理 %= h(truncate(i.subject, 30)) % -->
<!-- 追加開始 -->
<%= '<del>' if i.closed? %><%= h(truncate(i.subject, 30)) %><%= '</del>' if i.closed? %>
<!-- ここまで -->
<span class="tip"><%= render_issue_tooltip i %></span>

2008年1月14日月曜日

Redmineに工数確認機能を追加

Redmine で工数を入力できるけど、
日々の合計値や一覧がないので少し使いにくい。

なので簡単に機能追加。
#かなり adhoc だけどローカル用だしね。

試したのは redmine-0.6.3。


(1) まずはコントローラを追加
ruby script/generate cotroller man_hour


(2) 各ファイルを追記したり作成したり修正したり。

--------------------------------------
app/controllers/man_hour_controller.rb
--------------------------------------
class ManHourController < ApplicationController
layout 'base'

def index
@time_entries = TimeEntry.find(:all,
:conditions => ['spent_on > ?',
Time.now - 14.day],
:order => 'user_id, issue_id, spent_on')

@time_entries = [] if !@time_entries

respond_to do |format|
format.html
end
end

end

-----------------------------
app/views/man_hour/index.html
-----------------------------
<h1>入力工数一覧</h1>

<% start_day = Time.now - 13.day -%>
<table class="list">
<tr>
<th>メンバ</th><th>課題</th>
<% 14.times do |n| -%>
<th>
<!-- %= (start_day + n.day).strftime("%m/%d") % -->
<% d = (start_day + n.day) -%>
<%= "#{d.month}/" if d.day == 1 %>
<%= d.day %>
</th>
<% end -%>
</tr>
<% max = @time_entries.length -%>
<% i = 0 -%>
<% while i < max -%>
<% entry = @time_entries[i] -%>
<tr class="<%=cycle('odd', 'even') %>">
<td><%= entry.user.name %></td>
<td>[<%= entry.project.name %>] <%= entry.issue.subject if entry.issue %></td>
<% issue_id = entry.issue_id -%>
<% 14.times do |n| -%>
<% if entry && (issue_id == entry.issue_id) && (entry.spent_on.day == (start_day + n.day).day) -%>
<td>
<!-- %= entry.hours % -->
<% if entry.user_id == User.current.id -%>
<%= link_to entry.hours, :controller => "timelog", :action => "edit", :id => entry.id %>
<% else -%>
<%= entry.hours %>
<% end -%>
</td>
<% i = i.next -%>
<% entry = @time_entries[i] -%>
<% else -%>
<td></td>
<% end -%>
<% end -%>
</tr>
<% end -%>
</table>

----------------
config/routes.rb
----------------
map.connect 'man_hour/', :controller => 'man_hour', :action => 'index' # 追記

--------------------------------
app/controllers/my_controller.rb
--------------------------------
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
'issuesreportedbyme' => :label_reported_issues,
'issueswatched' => :label_watched_issues,
'news' => :label_news_latest,
'calendar' => :label_calendar,
'documents' => :label_document_plural,
'hourhistories' => '入力工数履歴' # UTF8 で追記
}.freeze

----------------------------------------
app/views/my/blocks/_hourhistories.rhtml
----------------------------------------
<h3>入力工数履歴</h3>

<ul>
<% sql =
"select user_id, spent_on, sum(hours) as day_hour" +
" from time_entries" +
" where user_id = #{user.id}" +
" group by spent_on" +
" order by spent_on desc" +
" limit 5"-%>
<% for entry in TimeEntry.find_by_sql(sql) %>
<li><%= "#{entry.spent_on}: #{entry.day_hour} h" %>
<% end %>
</ul>

<%= link_to "詳細", :controller => "man_hour" %>