Project

General

Profile

Patch #655 » MY_TIME_REPORT.diff

Mykhaylo Sorochan, 2008-02-14 12:32

View differences:

app/helpers/timelog_helper.rb (working copy)
end
sum
end
def render_time_entry_tooltip(time_entry)
@cached_label_comments ||= l(:field_comments)
issue = time_entry.issue.nil? ? "" : link_to_issue(time_entry.issue) + ": #{h(time_entry.issue.subject)}<br />"
issue + "<strong>#{@cached_label_comments}</strong>: #{time_entry.comments}"
end
end
app/controllers/my_controller.rb (working copy)
class MyController < ApplicationController
helper :issues
helper :timelog
layout 'base'
before_filter :require_login
......
'issueswatched' => :label_watched_issues,
'news' => :label_news_latest,
'calendar' => :label_calendar,
'documents' => :label_document_plural
'documents' => :label_document_plural,
'mytimereport' => :label_my_time_report
}.freeze
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
app/views/my/blocks/_mytimereport.rhtml (revision 0)
<h3><%= l(:label_my_time_report) %></h3>
<% calendar = Redmine::Helpers::TimeReportCalendar.new(Date.today, current_language, :week2)
calendar.time_entries = TimeEntry.find :all,
:conditions => ["(user_id = #{@user.id}) AND (spent_on>=? and spent_on<=?)", calendar.startdt, calendar.enddt],
:include => [:project, :activity] unless @user.projects.empty?
%>
<%= render :partial => 'common/mytimereportcalendar', :locals => {:calendar => calendar } %>
app/views/common/_mytimereportcalendar.rhtml (revision 0)
<table class="cal">
<thead>
<tr><td></td><% 7.times do |i| %><th><%= day_name( (calendar.first_wday+i)%7 ) %></th><% end %></tr>
</thead>
<tbody>
<tr>
<% day = calendar.startdt
while day <= calendar.enddt %>
<%= "<th>#{day.cweek}</th>" if day.cwday == calendar.first_wday %>
<td class="<%= day.month==calendar.month ? 'even' : 'odd' %><%= ' today' if Date.today == day %>">
<p class="day-num"><%= day.day %></p>
<% day_hours = 0 %>
<% calendar.time_entries_on(day).each do |i| %>
<% day_hours += i.hours %>
<div class="tooltip">
<%= h("#{i.project.name} - #{i.activity.name} : #{i.hours}") %>
<span class="tip"><%= render_time_entry_tooltip i %></span>
</div>
<% end %>
<% if day_hours > 0 %>
<%= h("TOTAL: #{day_hours}") %>
<% end %>
</td>
<%= '</tr><tr>' if day.cwday==calendar.last_wday and day!=calendar.enddt %>
<% day = day + 1
end %>
</tr>
</tbody>
</table>
lang/en.yml (working copy)
label_general: General
label_more: More
label_scm: SCM
label_my_time_report: My time report
button_login: Login
button_submit: Submit
lib/redmine/helpers/time_report_calendar.rb (revision 0)
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module Redmine
module Helpers
#class for calculating personal time entries
class TimeReportCalendar < Calendar
def initialize(date, lang = current_language, period = :week2)
@date = date
@events = []
@ending_events_by_days = {}
@starting_events_by_days = {}
@time_entries = []
@spent_time_entries_by_days = {}
set_language lang
case period
when :week2
@startdt = date - 7 - (date.cwday - first_wday)%7
@enddt = date + (last_wday - date.cwday)%7
else
super(date, lang, period)
end
end
# Sets calendar time_entries
def time_entries=(time_entries)
@time_entries = time_entries
@spent_time_entries_by_days = @time_entries.group_by {|entry| entry.spent_on}
end
# Returns time_entries for the given day
def time_entries_on(day)
@spent_time_entries_by_days[day] || []
end
end
end
end
(2-2/2)