From 898fac293b3d8042de3c1747776fac90d3ed40fa Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 22 Jul 2008 18:52:00 +0000 Subject: [PATCH] Adds custom fields on time entries (#772). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1689 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/custom_fields_controller.rb | 2 ++ app/controllers/issues_controller.rb | 1 + app/helpers/custom_fields_helper.rb | 1 + app/models/time_entry.rb | 1 + app/models/time_entry_custom_field.rb | 23 +++++++++++++++++++++ app/views/custom_fields/_form.rhtml | 3 +++ app/views/issues/_edit.rhtml | 3 +++ app/views/timelog/edit.rhtml | 3 +++ 8 files changed, 37 insertions(+) create mode 100644 app/models/time_entry_custom_field.rb diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index 1e1c988d9..d30e89493 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -39,6 +39,8 @@ class CustomFieldsController < ApplicationController @custom_field = UserCustomField.new(params[:custom_field]) when "ProjectCustomField" @custom_field = ProjectCustomField.new(params[:custom_field]) + when "TimeEntryCustomField" + @custom_field = TimeEntryCustomField.new(params[:custom_field]) else redirect_to :action => 'list' return diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index c0f31814b..c8edd1726 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -160,6 +160,7 @@ class IssuesController < ApplicationController @allowed_statuses = @issue.new_statuses_allowed_to(User.current) @priorities = Enumeration::get_values('IPRI') @edit_allowed = User.current.allowed_to?(:edit_issues, @project) + @time_entry = TimeEntry.new @notes = params[:notes] journal = @issue.init_journal(User.current, @notes) diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 3c795dc1f..f61824e65 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -19,6 +19,7 @@ module CustomFieldsHelper def custom_fields_tabs tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural}, + {:name => 'TimeEntryCustomField', :label => :label_spent_time}, {:name => 'ProjectCustomField', :label => :label_project_plural}, {:name => 'UserCustomField', :label => :label_user_plural} ] diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 759f9bed0..57a75604d 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -25,6 +25,7 @@ class TimeEntry < ActiveRecord::Base attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek + acts_as_customizable acts_as_event :title => Proc.new {|o| "#{o.user}: #{lwr(:label_f_hour, o.hours)} (#{(o.issue || o.project).event_title})"}, :url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}}, :author => :user, diff --git a/app/models/time_entry_custom_field.rb b/app/models/time_entry_custom_field.rb new file mode 100644 index 000000000..2ec3d27be --- /dev/null +++ b/app/models/time_entry_custom_field.rb @@ -0,0 +1,23 @@ +# redMine - project management software +# Copyright (C) 2008 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. + +class TimeEntryCustomField < CustomField + def type_name + :label_spent_time + end +end + diff --git a/app/views/custom_fields/_form.rhtml b/app/views/custom_fields/_form.rhtml index 5e4eadf21..f4aee6870 100644 --- a/app/views/custom_fields/_form.rhtml +++ b/app/views/custom_fields/_form.rhtml @@ -105,6 +105,9 @@ when "IssueCustomField" %> <% when "ProjectCustomField" %>

<%= f.check_box :is_required %>

+<% when "TimeEntryCustomField" %> +

<%= f.check_box :is_required %>

+ <% end %> <%= javascript_tag "toggle_custom_field_format();" %> diff --git a/app/views/issues/_edit.rhtml b/app/views/issues/_edit.rhtml index ba59c3ae9..2c7a4286e 100644 --- a/app/views/issues/_edit.rhtml +++ b/app/views/issues/_edit.rhtml @@ -25,6 +25,9 @@

<%= time_entry.select :activity_id, activity_collection_for_select_options %>

<%= time_entry.text_field :comments, :size => 60 %>

+ <% @time_entry.custom_field_values.each do |value| %> +

<%= custom_field_tag_with_label :time_entry, value %>

+ <% end %> <% end %> <% end %> diff --git a/app/views/timelog/edit.rhtml b/app/views/timelog/edit.rhtml index 7e8cc4591..0dd3503ec 100644 --- a/app/views/timelog/edit.rhtml +++ b/app/views/timelog/edit.rhtml @@ -10,6 +10,9 @@

<%= f.text_field :hours, :size => 6, :required => true %>

<%= f.text_field :comments, :size => 100 %>

<%= f.select :activity_id, activity_collection_for_select_options, :required => true %>

+<% @time_entry.custom_field_values.each do |value| %> +

<%= custom_field_tag_with_label :time_entry, value %>

+<% end %> <%= submit_tag l(:button_save) %> -- 2.39.5