Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/controllers/custom_timesheets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class CustomTimesheetsController < ApplicationController

SessionKey = 'timesheet_filter'

verify :method => :delete, :only => :reset, :render => {:nothing => true, :status => :method_not_allowed }

def index
load_filters_from_session
@timesheet ||= CustomTimesheet.new
Expand Down Expand Up @@ -105,7 +103,7 @@ def allowed_projects
if User.current.admin?
return Project.find(:all, :order => 'name ASC')
else
return Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name ASC')
return Project.find(:all, :conditions => Project.visible_condition(User.current), :order => 'name ASC')
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/custom_timesheets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ def showing_users(users)

def permalink_to_timesheet(timesheet)
link_to(l(:timesheet_permalink),
:controller => 'custom_timesheet',
:controller => 'custom_timesheets',
:action => 'report',
:timesheet => timesheet.to_param)
end

def link_to_csv_export(timesheet)
link_to('CSV',
{
:controller => 'custom_timesheet',
:controller => 'custom_timesheets',
:action => 'report',
:format => 'csv',
:timesheet => timesheet.to_param
Expand Down
15 changes: 8 additions & 7 deletions app/models/custom_timesheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def attributes
# TODO una time_entry contiene anche @user, @project, @activity, @issue: vedere se togliere queste cose quando si castrano gli attributi. sempre nello stesso posto, @attributes_cache può dare problemi?
dup_entry = entry.dup
dup_entry.attributes = filtered_attributes.dup
dup_entry.attributes['id'] = entry.id

@time_entries.push(dup_entry)
end
Expand Down Expand Up @@ -248,15 +249,15 @@ def to_param
end

def to_csv
returning '' do |out|
FCSV.generate out do |csv|
csv << csv_header

@time_entries.each do |t|
csv << time_entry_to_csv(t)
end
result = FCSV.generate do |csv|
csv << csv_header

@time_entries.each do |t|
csv << time_entry_to_csv(t)
end
end

result
end

def self.viewable_users
Expand Down
370 changes: 204 additions & 166 deletions app/views/common/_auto_completion.html.erb

Large diffs are not rendered by default.

56 changes: 29 additions & 27 deletions app/views/common/_custom_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
<%
# TODO concettualmente questi metodi sono helper e andrebbero quindi definiti
# nel file helper

# Aggiunge uno "0" davanti al numero passato se è minore di 10
def hours_min_string(number)
str = number.to_s
str = "0#{number}" if number < 10
str
end

# Restituisce un array di interi da 0 a 55 andando di 5 in 5
def minutes
mins = Array.new
(0..3).each { |i| mins << 15 * i}
mins
end
%>

<p>
<%= time_entry.select :start_hour, (0..23).to_a.collect {|a| [hours_min_string(a), a]}, { :include_blank => true, :required => true } -%>:<%= time_entry.select :start_minute, minutes.collect {|m| [hours_min_string(m), m]}, { :include_blank => true } -%>
</p>
<p>
<%= time_entry.select :end_hour, (0..23).to_a.collect {|a| [hours_min_string(a), a]}, { :include_blank => true, :required => true } -%>:<%= time_entry.select :end_minute, minutes.collect {|m| [hours_min_string(m), m]}, { :include_blank => true } -%>
</p>
<p><%= time_entry.text_field :billed_hours, :size => 6 %></p>

<%
# TODO concettualmente questi metodi sono helper e andrebbero quindi definiti
# nel file helper

# Aggiunge uno "0" davanti al numero passato se è minore di 10
def hours_min_string(number)
str = number.to_s
str = "0#{number}" if number < 10
str
end

# Restituisce un array di interi da 0 a 55 andando di 5 in 5
def minutes
mins = Array.new
(0..59).each { |i| mins << i}
mins
end
%>

<p>
<%= time_entry.select :start_hour, (0..23).to_a.collect {|a| [hours_min_string(a), a]}, { :include_blank => true, :required => false } -%>:<%= time_entry.select :start_minute, minutes.collect {|m| [hours_min_string(m), m]}, { :include_blank => true } -%>
<input type="button" id="startNow" onclick="javascript:setNowTime('time_entry_start_hour', 'time_entry_start_minute')" value="Now" />
</p>
<p>
<%= time_entry.select :end_hour, (0..23).to_a.collect {|a| [hours_min_string(a), a]}, { :include_blank => true, :required => false } -%>:<%= time_entry.select :end_minute, minutes.collect {|m| [hours_min_string(m), m]}, { :include_blank => true } -%>
<input type="button" id="endNow" onclick="javascript:setNowTime('time_entry_end_hour', 'time_entry_end_minute')" value="Now" />
</p>
<p><%= time_entry.text_field :billed_hours, :size => 6 %></p>

<%= render :partial => "common/auto_completion" %>
51 changes: 26 additions & 25 deletions app/views/custom_timesheets/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
<div id="form">
<% form_for :timesheet, :url =>{:action => 'report'} do |f| %>
<%= form_for :timesheet, :url => {:action => 'report'} do |f| %>
<%# Scelta del periodo %>

<div id="filters" class="float-left">
<fieldset>
<legend><%= l :t_filters %></legend>

<div id="date-options" class="float-left">

<p><%= l(:timesheet_period) %></p>

<%= radio_button_tag 'timesheet[period_type]', '3', @timesheet.period_type == CustomTimesheet::ValidPeriodType[:month] %>
<%= select_tag 'timesheet[year]', options_for_select([Time.now.year, Time.now.year - 1], (@timesheet.year.blank? ? Time.new.year : @timesheet.year)) %>
<%= select_tag 'timesheet[month]', options_for_select(l('date.month_names'), (@timesheet.month.blank? ? 0 : l('date.month_names')[@timesheet.month])) %>
<%= raw(radio_button_tag 'timesheet[period_type]', '3', @timesheet.period_type == CustomTimesheet::ValidPeriodType[:month]) %>
<%= raw(select_tag 'timesheet[year]', options_for_select([Time.now.year, Time.now.year - 1], (@timesheet.year.blank? ? Time.new.year : @timesheet.year))) %>
<%= raw(select_tag 'timesheet[month]', options_for_select(l('date.month_names'), (@timesheet.month.blank? ? 0 : l('date.month_names')[@timesheet.month]))) %>

<br/><br/>

<%= radio_button_tag 'timesheet[period_type]', '1', @timesheet.period_type == CustomTimesheet::ValidPeriodType[:default] %>
<%= select_tag 'timesheet[period]', options_for_period_select((params[:timesheet].nil? ? nil : params[:timesheet][:period])),
:onfocus => '$("timesheet_period_type_1").checked = true;' %>
<%= raw(radio_button_tag 'timesheet[period_type]', '1', @timesheet.period_type == CustomTimesheet::ValidPeriodType[:default]) %>
<%= raw(select_tag 'timesheet[period]', options_for_period_select((params[:timesheet].nil? ? nil : params[:timesheet][:period])),
:onfocus => '$("timesheet_period_type_1").checked = true;') %>
<br /><br />

<%= radio_button_tag 'timesheet[period_type]', '2', @timesheet.period_type == CustomTimesheet::ValidPeriodType[:free_period] %>
<%= raw(radio_button_tag 'timesheet[period_type]', '2', @timesheet.period_type == CustomTimesheet::ValidPeriodType[:free_period]) %>
<span onclick="$('timesheet_period_type_2').checked = true;">
<label for="timesheet_date_from"><%= l(:timesheet_date_from_label)%>:</label><br />
<%= f.text_field "date_from", :size => 10 %><%= calendar_for('timesheet_date_from') %><br />
<%= raw(f.text_field "date_from", :size => 10) %><%= calendar_for('timesheet_date_from') %><br />

<label for="timesheet_date_to"><%= l(:timesheet_date_to_label)%>:</label><br />
<%= f.text_field "date_to", :size => 10 %><%= calendar_for('timesheet_date_to') %><br /><br />
<%= raw(f.text_field "date_to", :size => 10) %><%= calendar_for('timesheet_date_to') %><br /><br />
</span>
</div>

<div id="sorting" class="float-left">
<label for="timesheet_sort"><%= l(:timesheet_sort_by) %>:</label><br />
<%= select_tag("timesheet[sort]", options_for_select(CustomTimesheet::SortOptions.invert.reject { |key, val| val == :hours || val == :billed_hours }, @timesheet.sort)) %>
<%= raw(select_tag("timesheet[sort]", options_for_select(CustomTimesheet::SortOptions.invert.reject { |key, val| val == :hours || val == :billed_hours }, @timesheet.sort))) %>
</div>

<div id="projects" class="float-left">
<label for="timesheet_projects_" class="select_all"><%= l(:t_projects)%>:</label><br />
<%= project_options(@timesheet) %>
<%= raw(project_options(@timesheet)) %>
</div>

<div id="activities" class="float-left">
<label for="timesheet_activities_" class="select_all"><%= l(:t_activities)%>:</label><br />
<%= select_tag 'timesheet[activities][]', activity_options(@timesheet, @activities), { :multiple => true, :size => @list_size} %>
<%= raw(select_tag 'timesheet[activities][]', activity_options(@timesheet, @activities), { :multiple => true, :size => @list_size}) %>
</div>

<div id="users" class="float-left">
<label for="timesheet_users_" class="select_all"><%= l(:t_users)%>:</label><br />
<%= select_tag 'timesheet[users][]', user_options(@timesheet), { :multiple => true, :size => @list_size} %>
<%= raw(select_tag 'timesheet[users][]', user_options(@timesheet), { :multiple => true, :size => @list_size}) %>
</div>

<div class="clear"/>
Expand All @@ -59,19 +60,19 @@
<legend><%= l :t_fields_to_include %></legend>

<div class="float-left columns-group first">
<%= complete_checkbox(:id, 'ID') %>
<%= complete_checkbox(:project_id, l(:field_project)) %>
<%= complete_checkbox(:user_id, l(:field_user)) %>
<%= complete_checkbox(:issue_id, l(:field_issue)) %>
<%= complete_checkbox(:comments, l(:t_comment)) %>
<%= raw(complete_checkbox(:id, 'ID')) %>
<%= raw(complete_checkbox(:project_id, l(:field_project))) %>
<%= raw(complete_checkbox(:user_id, l(:field_user))) %>
<%= raw(complete_checkbox(:issue_id, l(:field_issue))) %>
<%= raw(complete_checkbox(:comments, l(:t_comment))) %>
</div>

<div class="float-left columns-group">
<%= complete_checkbox(:activity_id, l(:field_activity)) %>
<%= complete_checkbox(:spent_on, l(:field_spent_on)) %>
<%= complete_checkbox(:tweek, l(:timesheet_week_of_year)) %>
<%= complete_checkbox(:hours, l(:field_hours)) %>
<%= complete_checkbox(:billed_hours, l(:timesheet_billed_hours)) %>
<%= raw(complete_checkbox(:activity_id, l(:field_activity))) %>
<%= raw(complete_checkbox(:spent_on, l(:field_spent_on))) %>
<%= raw(complete_checkbox(:tweek, l(:timesheet_week_of_year))) %>
<%= raw(complete_checkbox(:hours, l(:field_hours))) %>
<%= raw(complete_checkbox(:billed_hours, l(:timesheet_billed_hours))) %>
</div>

<div class="clear"/>
Expand All @@ -84,6 +85,6 @@
</div>
<% end %>

<%= button_to(l(:button_reset), {:controller => 'custom_timesheet', :action => 'reset'}, :method => 'delete') %>
<%= button_to(l(:button_reset), {:controller => 'custom_timesheets', :action => 'reset'}, :method => 'delete') %>
<div class="clear"/>
</div>
50 changes: 25 additions & 25 deletions app/views/custom_timesheets/report.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@

<% if !@timesheet.time_entries.blank? && @timesheet.time_entries.length > 0 %>
<%# TODO preparare il totale nel controller %>
<h2><%= l(:label_spent_time) %> (<%= @timesheet.total_hours -%> <%= h(l(:field_hours)) -%>,
<h2><%= l(:label_spent_time) %> (<%= @timesheet.total_hours -%> <%= l(:field_hours) -%>,
<%= @timesheet.total_billed_hours -%> <%= l(:timesheet_billed_hours) -%>)</h2>

<table class="list issues">
<thead>
<%= table_header '5', link_to(image_tag('toggle_check.png'), {}, :onclick => 'toggleIssuesSelection(Element.up(this, "table")); return false;',
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'toggle-all'), 'id' %>
<%= table_header '8', l(:label_date), 'spent_on' %>
<%= table_header '5', l(:timesheet_week_of_year), 'tweek' %>
<%= table_header '10', l(:label_member), 'user_id' %>
<%= table_header '10', l(:label_activity), 'activity_id' %>
<%= table_header '15', l(:label_project), 'project_id' %>
<%= table_header '10', l(:label_issue), 'issue_id' %>
<%= table_header '20', l(:field_comments), 'comments' %>
<%= table_header '6', l(:field_hours), 'hours' %>
<%= table_header '11', l(:timesheet_billed_hours), 'billed_hours' %>
<%= table_header '5', '', 'id' %>
<%= raw(table_header '5', link_to(image_tag('toggle_check.png'), {}, :onclick => 'toggleIssuesSelection(Element.up(this, "table")); return false;',
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'toggle-all'), 'id') %>
<%= raw(table_header '8', l(:label_date), 'spent_on') %>
<%= raw(table_header '5', l(:timesheet_week_of_year), 'tweek') %>
<%= raw(table_header '10', l(:label_member), 'user_id') %>
<%= raw(table_header '10', l(:label_activity), 'activity_id') %>
<%= raw(table_header '15', l(:label_project), 'project_id') %>
<%= raw(table_header '10', l(:label_issue), 'issue_id') %>
<%= raw(table_header '20', l(:field_comments), 'comments') %>
<%= raw(table_header '6', l(:field_hours), 'hours') %>
<%= raw(table_header '11', l(:timesheet_billed_hours), 'billed_hours') %>
<%= raw(table_header '5', '', 'id') %>
</thead>
<tbody>
<% @timesheet.time_entries.each do |time_entry| %>
<tr id="time_entry_<%= time_entry.id %>" class="time_entry <%= cycle("odd", "even") %> hascontextmenu">
<%= table_col true, 'id' do check_box_tag('ids[]', time_entry.id, false, { :class => 'checkbox' }) end %>
<%= table_col true, 'spent_on' do format_date(time_entry.spent_on) end %>
<%= table_col(true, 'tweek') { time_entry.tweek.to_s } %>
<%= table_col true, 'user_id' do time_entry.user.name end %>
<%= table_col true, 'activity_id' do time_entry.activity.name end %>
<%= table_col true, 'project_id' do time_entry.project.name end %>
<%= raw(table_col(true, 'id') { check_box_tag('ids[]', time_entry.id, false, { :class => 'checkbox' }) }) %>
<%= raw(table_col(true, 'spent_on') { format_date(time_entry.spent_on) }) %>
<%= raw(table_col(true, 'tweek') { time_entry.tweek.to_s }) %>
<%= raw(table_col(true, 'user_id') { time_entry.user.name }) %>
<%= raw(table_col(true, 'activity_id') { time_entry.activity.name }) %>
<%= raw(table_col(true, 'project_id') { time_entry.project.name }) %>
<% if selected?('issue_id') %>
<td align="center">
<% if time_entry.issue %>
Expand All @@ -50,15 +50,15 @@
<% end %>
</td>
<% end %>
<%= table_col false, 'comments' do time_entry.comments end %>
<%= table_col true, 'hours' do number_with_precision(time_entry.hours, :precision => @precision) end %>
<%= table_col true, 'billed_hours' do '<strong>' + number_with_precision(time_entry.billed_hours, :precision => @precision) + '</strong>' unless time_entry.billed_hours.blank? end %>
<%= raw(table_col(false, 'comments') { time_entry.comments }) %>
<%= raw(table_col(true, 'hours') { number_with_precision(time_entry.hours, :precision => @precision) }) %>
<%= raw(table_col(true, 'billed_hours') { '<strong>' + number_with_precision(time_entry.billed_hours, :precision => @precision) + '</strong>' unless time_entry.billed_hours.blank? }) %>
<% if selected?('id') %>
<td align="center">
<% if time_entry.editable_by?(User.current) -%>
<%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => time_entry},
<%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => time_entry.id},
:title => l(:button_edit) %>
<%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => time_entry},
<%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => time_entry.id},
:confirm => l(:text_are_you_sure),
:method => :post,
:title => l(:button_delete) %>
Expand All @@ -81,4 +81,4 @@
<% end %>

<div id="context-menu" style="display: none;"></div>
<%= javascript_tag "new ContextMenu('#{url_for(:controller => 'timesheet', :action => 'context_menu')}')" %>
<%= javascript_tag "new ContextMenu('#{url_for(:controller => 'custom_timesheets', :action => 'context_menu')}')" %>
Loading