Added an active field track if an Enumeration is active on the frontend view.
* Changed TimelogHelper#activity_collection_for_select_options to only use active TimeEntryActivities. * Changed TimelogHelper#activity_collection_for_select_options to return a blank option if the time_entry's current activity is inactive. #4077 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2946 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ac4937a767
commit
e76d4c5c4c
|
@ -25,11 +25,18 @@ module TimelogHelper
|
||||||
links << link_to_issue(@issue) if @issue
|
links << link_to_issue(@issue) if @issue
|
||||||
breadcrumb links
|
breadcrumb links
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity_collection_for_select_options
|
# Returns a collection of activities for a select field. time_entry
|
||||||
activities = TimeEntryActivity.all
|
# 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 = []
|
||||||
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] }
|
activities.each { |a| collection << [a.name, a.id] }
|
||||||
collection
|
collection
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,9 +53,17 @@ class Enumeration < ActiveRecord::Base
|
||||||
find(:first, :conditions => { :is_default => true })
|
find(:first, :conditions => { :is_default => true })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# End backwards compatiblity named_scopes
|
||||||
|
|
||||||
named_scope :all, :order => 'position'
|
named_scope :all, :order => 'position'
|
||||||
|
|
||||||
|
named_scope :active, lambda {
|
||||||
|
{
|
||||||
|
:conditions => {:active => true},
|
||||||
|
:order => 'position'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def self.default
|
def self.default
|
||||||
# Creates a fake default scope so Enumeration.default will check
|
# Creates a fake default scope so Enumeration.default will check
|
||||||
# it's type. STI subclasses will automatically add their own
|
# it's type. STI subclasses will automatically add their own
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
<p><label for="enumeration_name"><%=l(:field_name)%></label>
|
<p><label for="enumeration_name"><%=l(:field_name)%></label>
|
||||||
<%= text_field 'enumeration', 'name' %></p>
|
<%= text_field 'enumeration', 'name' %></p>
|
||||||
|
|
||||||
|
<p><label for="enumeration_active"><%=l(:field_active)%></label>
|
||||||
|
<%= check_box 'enumeration', 'active' %></p>
|
||||||
|
|
||||||
<p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
|
<p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
|
||||||
<%= check_box 'enumeration', 'is_default' %></p>
|
<%= check_box 'enumeration', 'is_default' %></p>
|
||||||
<!--[eoform:optvalue]-->
|
<!--[eoform:optvalue]-->
|
||||||
|
@ -13,4 +16,4 @@
|
||||||
<% @enumeration.custom_field_values.each do |value| %>
|
<% @enumeration.custom_field_values.each do |value| %>
|
||||||
<p><%= custom_field_tag_with_label :enumeration, value %></p>
|
<p><%= custom_field_tag_with_label :enumeration, value %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,10 +6,18 @@
|
||||||
<% enumerations = klass.all %>
|
<% enumerations = klass.all %>
|
||||||
<% if enumerations.any? %>
|
<% if enumerations.any? %>
|
||||||
<table class="list">
|
<table class="list">
|
||||||
|
<tr>
|
||||||
|
<th><%= l(:field_name) %></th>
|
||||||
|
<th style="width:15%;"><%= l(:field_is_default) %></th>
|
||||||
|
<th style="width:15%;"><%= l(:field_active) %></th>
|
||||||
|
<th style="width:15%;"></th>
|
||||||
|
<th align="center" style="width:10%;"> </th>
|
||||||
|
</tr>
|
||||||
<% enumerations.each do |enumeration| %>
|
<% enumerations.each do |enumeration| %>
|
||||||
<tr class="<%= cycle('odd', 'even') %>">
|
<tr class="<%= cycle('odd', 'even') %>">
|
||||||
<td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td>
|
<td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td>
|
||||||
<td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
|
<td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
|
||||||
|
<td style="width:15%;"><%= image_tag('true.png') if enumeration.active? %></td>
|
||||||
<td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}) %></td>
|
<td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}) %></td>
|
||||||
<td class="buttons">
|
<td class="buttons">
|
||||||
<%= link_to l(:button_delete), { :action => 'destroy', :id => enumeration },
|
<%= link_to l(:button_delete), { :action => 'destroy', :id => enumeration },
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
|
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
|
||||||
<p><%= f.text_field :hours, :size => 6, :required => true %></p>
|
<p><%= f.text_field :hours, :size => 6, :required => true %></p>
|
||||||
<p><%= f.text_field :comments, :size => 100 %></p>
|
<p><%= f.text_field :comments, :size => 100 %></p>
|
||||||
<p><%= f.select :activity_id, activity_collection_for_select_options, :required => true %></p>
|
<p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
|
||||||
<% @time_entry.custom_field_values.each do |value| %>
|
<% @time_entry.custom_field_values.each do |value| %>
|
||||||
<p><%= custom_field_tag_with_label :time_entry, value %></p>
|
<p><%= custom_field_tag_with_label :time_entry, value %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -748,6 +748,8 @@ en:
|
||||||
status_active: active
|
status_active: active
|
||||||
status_registered: registered
|
status_registered: registered
|
||||||
status_locked: locked
|
status_locked: locked
|
||||||
|
|
||||||
|
field_active: Active
|
||||||
|
|
||||||
text_select_mail_notifications: Select actions for which email notifications should be sent.
|
text_select_mail_notifications: Select actions for which email notifications should be sent.
|
||||||
text_regexp_info: eg. ^[A-Z0-9]+$
|
text_regexp_info: eg. ^[A-Z0-9]+$
|
||||||
|
|
|
@ -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
|
|
@ -4,66 +4,85 @@ enumerations_001:
|
||||||
id: 1
|
id: 1
|
||||||
opt: DCAT
|
opt: DCAT
|
||||||
type: DocumentCategory
|
type: DocumentCategory
|
||||||
|
active: true
|
||||||
enumerations_002:
|
enumerations_002:
|
||||||
name: User documentation
|
name: User documentation
|
||||||
id: 2
|
id: 2
|
||||||
opt: DCAT
|
opt: DCAT
|
||||||
type: DocumentCategory
|
type: DocumentCategory
|
||||||
|
active: true
|
||||||
enumerations_003:
|
enumerations_003:
|
||||||
name: Technical documentation
|
name: Technical documentation
|
||||||
id: 3
|
id: 3
|
||||||
opt: DCAT
|
opt: DCAT
|
||||||
type: DocumentCategory
|
type: DocumentCategory
|
||||||
|
active: true
|
||||||
enumerations_004:
|
enumerations_004:
|
||||||
name: Low
|
name: Low
|
||||||
id: 4
|
id: 4
|
||||||
opt: IPRI
|
opt: IPRI
|
||||||
type: IssuePriority
|
type: IssuePriority
|
||||||
|
active: true
|
||||||
enumerations_005:
|
enumerations_005:
|
||||||
name: Normal
|
name: Normal
|
||||||
id: 5
|
id: 5
|
||||||
opt: IPRI
|
opt: IPRI
|
||||||
type: IssuePriority
|
type: IssuePriority
|
||||||
is_default: true
|
is_default: true
|
||||||
|
active: true
|
||||||
enumerations_006:
|
enumerations_006:
|
||||||
name: High
|
name: High
|
||||||
id: 6
|
id: 6
|
||||||
opt: IPRI
|
opt: IPRI
|
||||||
type: IssuePriority
|
type: IssuePriority
|
||||||
|
active: true
|
||||||
enumerations_007:
|
enumerations_007:
|
||||||
name: Urgent
|
name: Urgent
|
||||||
id: 7
|
id: 7
|
||||||
opt: IPRI
|
opt: IPRI
|
||||||
type: IssuePriority
|
type: IssuePriority
|
||||||
|
active: true
|
||||||
enumerations_008:
|
enumerations_008:
|
||||||
name: Immediate
|
name: Immediate
|
||||||
id: 8
|
id: 8
|
||||||
opt: IPRI
|
opt: IPRI
|
||||||
type: IssuePriority
|
type: IssuePriority
|
||||||
|
active: true
|
||||||
enumerations_009:
|
enumerations_009:
|
||||||
name: Design
|
name: Design
|
||||||
id: 9
|
id: 9
|
||||||
opt: ACTI
|
opt: ACTI
|
||||||
type: TimeEntryActivity
|
type: TimeEntryActivity
|
||||||
|
active: true
|
||||||
enumerations_010:
|
enumerations_010:
|
||||||
name: Development
|
name: Development
|
||||||
id: 10
|
id: 10
|
||||||
opt: ACTI
|
opt: ACTI
|
||||||
type: TimeEntryActivity
|
type: TimeEntryActivity
|
||||||
is_default: true
|
is_default: true
|
||||||
|
active: true
|
||||||
enumerations_011:
|
enumerations_011:
|
||||||
name: QA
|
name: QA
|
||||||
id: 11
|
id: 11
|
||||||
opt: ACTI
|
opt: ACTI
|
||||||
type: TimeEntryActivity
|
type: TimeEntryActivity
|
||||||
|
active: true
|
||||||
enumerations_012:
|
enumerations_012:
|
||||||
name: Default Enumeration
|
name: Default Enumeration
|
||||||
id: 12
|
id: 12
|
||||||
opt: ''
|
opt: ''
|
||||||
type: Enumeration
|
type: Enumeration
|
||||||
is_default: true
|
is_default: true
|
||||||
|
active: true
|
||||||
enumerations_013:
|
enumerations_013:
|
||||||
name: Another Enumeration
|
name: Another Enumeration
|
||||||
id: 13
|
id: 13
|
||||||
opt: ''
|
opt: ''
|
||||||
type: Enumeration
|
type: Enumeration
|
||||||
|
active: true
|
||||||
|
enumerations_014:
|
||||||
|
name: Inactive Activity
|
||||||
|
id: 14
|
||||||
|
opt: ACTI
|
||||||
|
type: TimeEntryActivity
|
||||||
|
active: false
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
# redMine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# 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' }
|
assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/edit/2' }
|
||||||
end
|
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
|
def test_post_edit
|
||||||
# TODO: should POST to issues’ time log instead of project. change form
|
# TODO: should POST to issues’ time log instead of project. change form
|
||||||
# and routing
|
# and routing
|
||||||
|
|
Loading…
Reference in New Issue