Skip to content

Commit

Permalink
Merge branch 'with-calendar-week-print-style'
Browse files Browse the repository at this point in the history
  • Loading branch information
jkalbhenn committed Dec 11, 2018
2 parents 25bb475 + 1175dd7 commit ac162d5
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 74 deletions.
23 changes: 15 additions & 8 deletions app/controllers/timesheet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def report
@timesheet = Timesheet.new(params[:timesheet])
else
redirect_to :action => 'index'
return
end

@timesheet.allowed_projects = allowed_projects
Expand All @@ -49,29 +50,35 @@ def report
save_filters_to_session(@timesheet)
@timesheet.fetch_time_entries

# Sums
@total = { }
# collect spent time per project
@total = {}
unless @timesheet.sort == :issue
@timesheet.time_entries.each do |project,logs|
@total[project] = 0
@timesheet.time_entries.each do |project, logs|
@total[project] = []
if logs[:logs]
logs[:logs].each do |log|
@total[project] += log.hours
@total[project].push log.hours
end
end
end
else
@timesheet.time_entries.each do |project, project_data|
@total[project] = 0
@total[project] = []
if project_data[:issues]
project_data[:issues].each do |issue, issue_data|
@total[project] += issue_data.collect(&:hours).sum
@total[project].push issue_data.collect(&:hours).sum
end
end
end
end

@grand_total = @total.collect{|k,v| v}.inject{|sum,n| sum + n}
# sum hours per project
@total.each do |project, hours|
sum = hours.sum
@total[project] = (sum.round - sum).abs < 0.05 ? sum.round : sum
end

@grand_total = @total.collect{|k,v| v}.sum

respond_to do |format|
format.html { render :action => 'details', :layout => false if request.xhr? }
Expand Down
25 changes: 4 additions & 21 deletions app/helpers/timesheet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ def toggle_issue_arrow(issue_id, image, js, hide=false)

end

def toggle_issue_arrows_date(spent_on)
def toggle_issue_arrows_date(spent_on)
js = "toggleTimeEntriesdate('#{spent_on}'); return false;"

return toggle_issue_arrow_date(spent_on, 'toggle-arrow-closed.gif', js, false) +
toggle_issue_arrow(spent_on, 'toggle-arrow-open.gif', js, true)
end
Expand All @@ -101,21 +100,6 @@ def toggle_issue_arrow_date(spent_on, image, js, hide=false)
:class => "toggle-" + spent_on.to_s,
:style => style
)

end

def options_for_period_select(value)
options_for_select([[l(:label_all_time), 'all'],
[l(:label_today), 'today'],
[l(:label_yesterday), 'yesterday'],
[l(:label_this_week), 'current_week'],
[l(:label_last_week), 'last_week'],
[l(:label_last_n_days, 7), '7_days'],
[l(:label_this_month), 'current_month'],
[l(:label_last_month), 'last_month'],
[l(:label_last_n_days, 30), '30_days'],
[l(:label_this_year), 'current_year']],
value)
end

def displayed_time_entries_for_issue(time_entries)
Expand Down Expand Up @@ -152,15 +136,14 @@ def user_options(timesheet)
:id,
:name,
selected_users)

end

def options_for_period_select(value)
options_for_select([[l(:label_all_time), 'all'],
options_for_select([[l(:label_last_week), 'last_week'],
[l(:label_this_week), 'current_week'],
[l(:label_all_time), 'all'],
[l(:label_today), 'today'],
[l(:label_yesterday), 'yesterday'],
[l(:label_this_week), 'current_week'],
[l(:label_last_week), 'last_week'],
[l(:label_last_n_days, 7), '7_days'],
[l(:label_this_month), 'current_month'],
[l(:label_last_month), 'last_month'],
Expand Down
4 changes: 2 additions & 2 deletions app/models/timesheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Timesheet
# Sort time entries by this field
attr_accessor :sort
ValidSortOptions = {
:project => 'Project',
:user => 'User',
:project => 'Project',
:issue => 'Issue',
:group => 'Group',
:date => 'Date'
Expand Down Expand Up @@ -67,7 +67,7 @@ def initialize(options = { })
if !options[:sort].nil? && options[:sort].respond_to?(:to_sym) && ValidSortOptions.keys.include?(options[:sort].to_sym)
self.sort = options[:sort].to_sym
else
self.sort = :project
self.sort = :users
end

self.date_from = options[:date_from] || Date.today.to_s
Expand Down
4 changes: 1 addition & 3 deletions app/views/timesheet/_timesheet_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<%= call_hook(:plugin_timesheet_views_timesheet_group_header, {}) %>
<th></th>
</thead>
<tbody>
<%= render :partial => "time_entry", :collection => entry[:logs], :locals => { :time_entries => entry[:logs] } %>
</tbody>
<%= render :partial => "time_entry", :collection => entry[:logs], :locals => { :time_entries => entry[:logs] } %>
</table>
<br />
8 changes: 5 additions & 3 deletions app/views/timesheet/report.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<h2><%= l(:label_spent_time) %> (<%= h(number_with_precision(@grand_total, :precision => @precision)) -%> <%= h(l(:field_hours)) -%>)</h2>
<% @timesheet.time_entries.each do |entryname,entry|
case @timesheet.sort
when :user %>
<h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>)</h3>
<%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>
when :user %>
<section class="group">
<h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>)</h3>
<%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>
</section>
<% when :issue %>
<h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>)</h3>
<%= render :partial => 'by_issue', :locals => {:entry => entry, :name => entryname, :total => 0 } %>
Expand Down
14 changes: 9 additions & 5 deletions assets/javascripts/timesheet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
function report_add_calendar_weeks() {
var first = $("tr.week-number").first()
first_text = first.find("td:nth-child(9)").text()
first.remove()
first = $("<div>", {"class": "week-number"}).append(first_text)
$("#time_entries > h3").after(first)
var groups = $("#time_entries section.group")
groups.map(function(index, a) {
var group = $(a)
var first = group.find("tr.week-number").first()
first_text = first.find("td:nth-child(9)").text()
first.remove()
first = $("<div>", {"class": "week-number"}).append(first_text)
group.find("h3").after(first)
})
}

$(function() {
Expand Down
72 changes: 49 additions & 23 deletions assets/stylesheets/timesheet-print.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ h2,
/* hide version column */
#time_entries table td:nth-child(6),
#time_entries table th:nth-child(6) {
display: none;
display: none;
}

tr.total td {
Expand All @@ -46,36 +46,25 @@ tr.total td {
}

#time_entries a {
color: inherit;
text-decoration: none;
color: inherit;
text-decoration: none;
}

table td *, table th {
font-weight: normal;
font-weight: normal;
}

h3 {
page-break-before: always;
section {
page-break-before: always;
}

h3:first-of-type {
page-break-before: auto;
section:first-of-type {
page-break-before: auto;
}

* {
border: 0 !important;
background-color: #fff !important;
}

tr.total {
border-color: #ddd !important;
border-style: solid !important;
border-width: 0px !important;
border-top-width: 1px !important;
border-bottom-width: 1px;
height: 30px;
display: table-row;
border-top: 1px solid #ddd !important;
border: 0 !important;
background-color: #fff !important;
}

tr.week-number {
Expand Down Expand Up @@ -104,12 +93,49 @@ h3 + div.week-number {
}

table * {
text-align: left;
text-align: left;
}

/* right align hours column */
#time_entries td:nth-child(9),
#time_entries th:nth-child(9)
{
text-align: right;
text-align: right;
}

tr.total {
border-color: #ddd !important;
border-style: solid !important;
border-width: 0px !important;
border-top-width: 1px !important;
border-bottom-width: 1px;
height: 30px;
display: table-row;
border-top: 1px solid #ddd !important;
}

tr.week-number {
text-align: right;
padding-right: 5px;
padding-bottom: 5px;
padding-top: 10px;
display: table-row;
}

tr.week-number, div.week-number {
text-align: right;
font-weight: bold;
}

tr.week-number td {
padding-bottom: 5px;
padding-top: 10px;
}

h3 + div.week-number {
padding-bottom: 10px;
text-align: right;
margin-top: -33px;
font-size: 16px;
display: block;
}
9 changes: 0 additions & 9 deletions db/migrate/002_create_enum_prices.rb

This file was deleted.

0 comments on commit ac162d5

Please sign in to comment.