diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb index 861c2acc7..0c3e7e6b6 100644 --- a/app/helpers/timelog_helper.rb +++ b/app/helpers/timelog_helper.rb @@ -25,11 +25,18 @@ module TimelogHelper links << link_to_issue(@issue) if @issue breadcrumb links end - - def activity_collection_for_select_options - activities = TimeEntryActivity.all + + # Returns a collection of activities for a select field. time_entry + # is optional and will be used to check if the selected TimeEntryActivity + # is active. + def activity_collection_for_select_options(time_entry=nil) + activities = TimeEntryActivity.active collection = [] - collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default) + if time_entry && !time_entry.activity.active? + collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] + else + collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default) + end activities.each { |a| collection << [a.name, a.id] } collection end diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index 4fb7d6d07..436e82373 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -53,9 +53,17 @@ class Enumeration < ActiveRecord::Base find(:first, :conditions => { :is_default => true }) end end + # End backwards compatiblity named_scopes named_scope :all, :order => 'position' + named_scope :active, lambda { + { + :conditions => {:active => true}, + :order => 'position' + } + } + def self.default # Creates a fake default scope so Enumeration.default will check # it's type. STI subclasses will automatically add their own diff --git a/app/views/enumerations/_form.rhtml b/app/views/enumerations/_form.rhtml index 741bbc5d9..21b948166 100644 --- a/app/views/enumerations/_form.rhtml +++ b/app/views/enumerations/_form.rhtml @@ -6,6 +6,9 @@
<%= text_field 'enumeration', 'name' %>
++<%= check_box 'enumeration', 'active' %>
+<%= check_box 'enumeration', 'is_default' %>
@@ -13,4 +16,4 @@ <% @enumeration.custom_field_values.each do |value| %><%= custom_field_tag_with_label :enumeration, value %>
<% end %> - \ No newline at end of file + diff --git a/app/views/enumerations/list.rhtml b/app/views/enumerations/list.rhtml index 3ae144487..817751ab2 100644 --- a/app/views/enumerations/list.rhtml +++ b/app/views/enumerations/list.rhtml @@ -6,10 +6,18 @@ <% enumerations = klass.all %> <% if enumerations.any? %><%= l(:field_name) %> | +<%= l(:field_is_default) %> | +<%= l(:field_active) %> | ++ | + |
---|---|---|---|---|
<%= link_to h(enumeration), :action => 'edit', :id => enumeration %> | <%= image_tag('true.png') if enumeration.is_default? %> | +<%= image_tag('true.png') if enumeration.active? %> | <%= reorder_links('enumeration', {:action => 'update', :id => enumeration}) %> |
<%= link_to l(:button_delete), { :action => 'destroy', :id => enumeration },
diff --git a/app/views/timelog/edit.rhtml b/app/views/timelog/edit.rhtml
index a0ff860f8..00d0a77c0 100644
--- a/app/views/timelog/edit.rhtml
+++ b/app/views/timelog/edit.rhtml
@@ -9,7 +9,7 @@
<%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %> <%= 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 %> +<%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %> <% @time_entry.custom_field_values.each do |value| %><%= custom_field_tag_with_label :time_entry, value %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index f46c57c08..8a07c644a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -748,6 +748,8 @@ en: status_active: active status_registered: registered status_locked: locked + + field_active: Active text_select_mail_notifications: Select actions for which email notifications should be sent. text_regexp_info: eg. ^[A-Z0-9]+$ diff --git a/db/migrate/20090401231134_add_active_field_to_enumerations.rb b/db/migrate/20090401231134_add_active_field_to_enumerations.rb new file mode 100644 index 000000000..55824fa65 --- /dev/null +++ b/db/migrate/20090401231134_add_active_field_to_enumerations.rb @@ -0,0 +1,9 @@ +class AddActiveFieldToEnumerations < ActiveRecord::Migration + def self.up + add_column :enumerations, :active, :boolean, :default => true, :null => false + end + + def self.down + remove_column :enumerations, :active + end +end diff --git a/test/fixtures/enumerations.yml b/test/fixtures/enumerations.yml index c9d619e64..7deacd731 100644 --- a/test/fixtures/enumerations.yml +++ b/test/fixtures/enumerations.yml @@ -4,66 +4,85 @@ enumerations_001: id: 1 opt: DCAT type: DocumentCategory + active: true enumerations_002: name: User documentation id: 2 opt: DCAT type: DocumentCategory + active: true enumerations_003: name: Technical documentation id: 3 opt: DCAT type: DocumentCategory + active: true enumerations_004: name: Low id: 4 opt: IPRI type: IssuePriority + active: true enumerations_005: name: Normal id: 5 opt: IPRI type: IssuePriority is_default: true + active: true enumerations_006: name: High id: 6 opt: IPRI type: IssuePriority + active: true enumerations_007: name: Urgent id: 7 opt: IPRI type: IssuePriority + active: true enumerations_008: name: Immediate id: 8 opt: IPRI type: IssuePriority + active: true enumerations_009: name: Design id: 9 opt: ACTI type: TimeEntryActivity + active: true enumerations_010: name: Development id: 10 opt: ACTI type: TimeEntryActivity is_default: true + active: true enumerations_011: name: QA id: 11 opt: ACTI type: TimeEntryActivity + active: true enumerations_012: name: Default Enumeration id: 12 opt: '' type: Enumeration is_default: true + active: true enumerations_013: name: Another Enumeration id: 13 opt: '' type: Enumeration + active: true +enumerations_014: + name: Inactive Activity + id: 14 + opt: ACTI + type: TimeEntryActivity + active: false diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index e9ca2d2bb..01ca505a0 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # redMine - project management software # Copyright (C) 2006-2007 Jean-Philippe Lang # @@ -71,6 +72,28 @@ class TimelogControllerTest < ActionController::TestCase assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/edit/2' } end + def test_get_edit_should_only_show_active_time_entry_activities + @request.session[:user_id] = 3 + get :edit, :project_id => 1 + assert_response :success + assert_template 'edit' + assert_no_tag :tag => 'option', :content => 'Inactive Activity' + + end + + def test_get_edit_with_an_existing_time_entry_with_inactive_activity + te = TimeEntry.find(1) + te.activity = TimeEntryActivity.find_by_name("Inactive Activity") + te.save! + + @request.session[:user_id] = 1 + get :edit, :project_id => 1, :id => 1 + assert_response :success + assert_template 'edit' + # Blank option since nothing is pre-selected + assert_tag :tag => 'option', :content => '--- Please select ---' + end + def test_post_edit # TODO: should POST to issues’ time log instead of project. change form # and routing |