Skip to content

Commit

Permalink
add calendar week to print style
Browse files Browse the repository at this point in the history
  • Loading branch information
jkalbhenn committed Sep 21, 2017
1 parent 478bb0a commit bc18a11
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 16 deletions.
15 changes: 15 additions & 0 deletions app/helpers/timesheet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module TimesheetHelper
include ProjectsHelper

def add_day_total? time_entries, time_entry_counter
# if last list entry or spent_on (date) differs from previous entry
(time_entry_counter == (time_entries.length - 1)) ||
(time_entries[time_entry_counter + 1].spent_on != time_entries[time_entry_counter].spent_on)
end
Expand All @@ -16,6 +17,20 @@ def calculate_day_total time_entries, time_entry_counter
number_with_precision(hours_sum, :precision => @precision)
end

def add_week_number? time_entries, time_entry_counter
# if first list entry or previous spent_on (date) differs
(time_entry_counter == 0) ||
(time_entries[time_entry_counter - 1].tweek != time_entries[time_entry_counter].tweek)
end

def get_week_number time_entries, time_entry_counter
time_entries[time_entry_counter].tweek
end

def time_entry_title time_entry
"week: #{time_entry.tweek}"
end

def showing_users(users)
l(:timesheet_showing_users) + users.collect(&:name).join(', ')
end
Expand Down
9 changes: 8 additions & 1 deletion app/views/timesheet/_time_entry.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<tr id="time_entry_<%= time_entry.id %>" class="time_entry <%= cycle("odd", "even") %> hascontextmenu <%= call_hook(:plugin_timesheet_view_timesheets_time_entry_row_class, {:time_entry => time_entry }) %> <%= call_hook(:plugin_timesheet_views_timesheets_time_entry_row_class, {:time_entry => time_entry }) %>">
<% if add_week_number? time_entries, time_entry_counter %>
<tr class="week-number">
<%= ("<td></td>" * 8).html_safe %>
<td><%= t(:timesheet_label_week_number)%> <%= time_entry.tweek %></td>
<td></td>
</tr>
<% end %>
<tr id="time_entry_<%= time_entry.id %>" class="time_entry <%= cycle("odd", "even") %> hascontextmenu <%= call_hook(:plugin_timesheet_view_timesheets_time_entry_row_class, {:time_entry => time_entry }) %> <%= call_hook(:plugin_timesheet_views_timesheets_time_entry_row_class, {:time_entry => time_entry }) %>" data-week="<%=time_entry.tweek%>" title="<%= time_entry_title time_entry %>">
<td align="center"><%= check_box_tag 'ids[]', time_entry.id, false, { :class => 'checkbox' } %></td>
<td align="center"><%= format_date(time_entry.spent_on) %></td>
<td align="center"><%= time_entry.user.name %></td>
Expand Down
20 changes: 15 additions & 5 deletions assets/javascripts/timesheet.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
$(function() {
$('#select_timesheet_period_type_2').click(function() {
$('#timesheet_period_type_2').attr('checked','checked')
})
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)
}

$(function() {
$('#select_timesheet_period_type_1').focus(function() {
$('#timesheet_period_type_1').attr('checked','checked')
})

$('#select_timesheet_period_type_2').click(function() {
$('#timesheet_period_type_2').attr('checked','checked')
})

$("label.select-all").click(function () {
var select = $(this).siblings("select")
var options = select.children()
var selected = options.length != select.find(":selected").length
options.each(function (index, ele) { ele.selected = selected });
options.each(function (index, a) { a.selected = selected });
})

report_add_calendar_weeks()
})
31 changes: 31 additions & 0 deletions assets/stylesheets/timesheet-print.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,41 @@ h3:first-of-type {
}

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;
}

table * {
text-align: left;
}
Expand Down
17 changes: 7 additions & 10 deletions assets/stylesheets/timesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,16 @@ label.select-all {
display: inline;
}

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;
tr.total, tr.week-number, div.week-number {
display: none;
}

tr.total {
.timesheet-groups {
display: none;
}

.timesheet-groups {
display:none;
#time_entries table td:nth-child(1),
#time_entries table th:nth-child(1)
{
display: none;
}
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
de:
timesheet_label_week_number: KW
timesheet_title: Stundenzettel
timesheet_date_range_label: Zeitraum
timesheet_date_from_label: Von
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
en:
timesheet_label_week_number: Week
timesheet_title: Timesheet
timesheet_date_range_label: Period
timesheet_date_from_label: From
Expand Down
1 change: 1 addition & 0 deletions lang/de.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
timesheet_label_week_number: KW
timesheet_title: Stundenzettel
timesheet_date_range_label: Zeitraum
timesheet_date_from_label: Von
Expand Down
1 change: 1 addition & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
timesheet_label_week_number: Week
timesheet_title: Timesheet
timesheet_date_range_label: Period
timesheet_date_from_label: From
Expand Down

0 comments on commit bc18a11

Please sign in to comment.