Merge pull request #259 from opf/feature/pes_allow_missing_dates

allow planning elements without dates.
pull/264/head
ulferts 11 years ago
commit c9ed9f0b76
  1. 4
      app/assets/javascripts/timelines.js
  2. 8
      app/helpers/planning_elements_helper.rb
  3. 8
      app/models/planning_element.rb
  4. 1
      doc/CHANGELOG.md
  5. 26
      spec/models/planning_element_spec.rb

@ -2376,6 +2376,10 @@ Timeline = {
hover_width = label_space.w - 2 * Timeline.HOVER_THRESHOLD;
}
if (in_aggregation && !has_both_dates) {
return;
}
var has_alternative = this.hasAlternateDates();
var could_have_been_milestone = (this.alternate_start === this.alternate_end);

@ -22,8 +22,8 @@ module PlanningElementsHelper
api.description(planning_element.description)
api.start_date(planning_element.start_date.to_formatted_s(:db))
api.end_date(planning_element.due_date.to_formatted_s(:db))
api.start_date(planning_element.start_date.to_formatted_s(:db)) unless planning_element.start_date.nil?
api.end_date(planning_element.due_date.to_formatted_s(:db)) unless planning_element.due_date.nil?
api.in_trash(!!planning_element.deleted_at)
@ -59,8 +59,8 @@ module PlanningElementsHelper
api.array(:scenarios, :size => scenarios.size) do
scenarios.each do |pe_scenario|
api.scenario(:id => pe_scenario.id, :name => pe_scenario.name) do
api.start_date(pe_scenario.start_date.to_formatted_s(:db))
api.end_date(pe_scenario.due_date.to_formatted_s(:db))
api.start_date(pe_scenario.start_date.to_formatted_s(:db)) unless pe_scenario.start_date.nil?
api.end_date(pe_scenario.due_date.to_formatted_s(:db)) unless pe_scenario.due_date.nil?
end
end
end

@ -122,7 +122,7 @@ class PlanningElement < WorkPackage
after_save :update_parent_attributes
after_save :create_alternate_date
validates_presence_of :subject, :start_date, :due_date, :project
validates_presence_of :subject, :project
validates_length_of :subject, :maximum => 255, :unless => lambda { |e| e.subject.blank? }
@ -265,8 +265,10 @@ class PlanningElement < WorkPackage
parent.reload
unless parent.children.without_deleted.empty?
parent.start_date = parent.children.without_deleted.minimum(:start_date)
parent.due_date = parent.children.without_deleted.maximum(:due_date)
children = parent.children.without_deleted
parent.start_date = [children.minimum(:start_date), children.minimum(:due_date)].reject(&:nil?).min
parent.due_date = [children.maximum(:start_date), children.maximum(:due_date)].reject(&:nil?).max
if parent.changes.present?
parent.note = I18n.t('timelines.planning_element_updated_automatically_by_child_changes', :child => "*#{id}")

@ -1,5 +1,6 @@
# Changelog
* `#1414` Remove start & due date requirement from planning elements
## 3.0.0pre8

@ -91,26 +91,24 @@ describe PlanningElement do
end
describe 'start_date' do
it 'is invalid w/o a start_date' do
it 'is valid w/o a start_date' do
attributes[:start_date] = nil
planning_element = PlanningElement.new.tap { |pe| pe.send(:assign_attributes, attributes, :without_protection => true) }
planning_element.should_not be_valid
planning_element.should be_valid
planning_element.errors[:start_date].should be_present
planning_element.errors[:start_date].should == ["can't be blank"]
planning_element.errors[:start_date].should_not be_present
end
end
describe 'due_date' do
it 'is invalid w/o a due_date' do
it 'is valid w/o a due_date' do
attributes[:due_date] = nil
planning_element = PlanningElement.new.tap { |pe| pe.send(:assign_attributes, attributes, :without_protection => true) }
planning_element.should_not be_valid
planning_element.should be_valid
planning_element.errors[:due_date].should be_present
planning_element.errors[:due_date].should == ["can't be blank"]
planning_element.errors[:due_date].should_not be_present
end
it 'is invalid if start_date is after due_date' do
@ -773,8 +771,8 @@ describe PlanningElement do
pe11 = FactoryGirl.create(:planning_element,
:project_id => project.id,
:parent_id => @pe1.id,
:start_date => Date.new(2011, 1, 1),
:due_date => Date.new(2011, 2, 1))
:start_date => nil,
:due_date => Date.new(2011, 1, 1))
pe12 = FactoryGirl.create(:planning_element,
:project_id => project.id,
:parent_id => @pe1.id,
@ -783,13 +781,13 @@ describe PlanningElement do
pe13 = FactoryGirl.create(:planning_element,
:project_id => project.id,
:parent_id => @pe1.id,
:start_date => Date.new(2013, 1, 1),
:due_date => Date.new(2013, 2, 1))
:start_date => Date.new(2013, 2, 1),
:due_date => nil)
@pe1.reload
@pe1.start_date.should == pe11.start_date
@pe1.due_date.should == pe13.due_date
@pe1.start_date.should == pe11.due_date
@pe1.due_date.should == pe13.start_date
pe11.reload
pe11.trash

Loading…
Cancel
Save