Pflichtenhefversion nach Ă„nderung an Items invalidieren
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 22 Apr 2013 08:35:48 +0000 (10:35 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:03:19 +0000 (13:03 +0200)
SL/Controller/RequirementSpecItem.pm
SL/DB/RequirementSpecItem.pm

index 7dd8c8e..cffc22c 100644 (file)
@@ -96,7 +96,7 @@ sub action_dragged_and_dropped {
   my $new_type            = $self->item->item_type;
   my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->section;
 
-  return $self->render($self->js) if !$old_visible_section || ($new_type eq 'section');
+  return $self->invalidate_version->render($self) if !$old_visible_section || ($new_type eq 'section');
 
   # From here on $old_visible_section is definitely set.
 
@@ -108,6 +108,7 @@ sub action_dragged_and_dropped {
 
   if ($old_visible_section->id != $new_visible_section->id) {
     # The currently visible item has been dragged to a different section.
+    $self->invalidate_version;
     return $self->render_list($new_section, $self->item)
       ->render($self);
   }
@@ -131,7 +132,7 @@ sub action_dragged_and_dropped {
 
   # $::lxdebug->dump(0, "js", $self->js->to_array);
 
-  $self->render($self->js);
+  $self->invalidate_version->render($self);
 }
 
 sub action_ajax_add_section {
@@ -181,6 +182,7 @@ sub action_ajax_create {
 
   if ($type eq 'section') {
     my $node = $self->presenter->requirement_spec_item_jstree_data($self->item);
+    $self->invalidate_version;
     return $self->render_list($self->item)
       ->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#sections', 'last'), $node)
       ->jstree->select_node('#tree', '#fb-' . $self->item->id)
@@ -199,7 +201,7 @@ sub action_ajax_create {
 
   $self->replace_bottom($self->item->parent) if $type eq 'sub-function-block';
 
-  $self->js->render($self);
+  $self->invalidate_version->render($self);
 }
 
 sub action_ajax_edit {
@@ -271,7 +273,7 @@ sub action_ajax_update {
 
     my $html = $self->render('requirement_spec_item/_section_header', { output => 0 }, requirement_spec_item => $self->item);
 
-    return $self->js
+    return $self->invalidate_version
       ->remove('#edit_section_form')
       ->html('#section-header-' . $self->item->id, $html)
       ->show('#section-header-' . $self->item->id)
@@ -295,7 +297,7 @@ sub action_ajax_update {
   $self->replace_bottom($self->item, id_prefix => $id_prefix);
   $self->replace_bottom($self->item->parent) if $type eq 'sub-function-block';
 
-  $self->js->render($self);
+  $self->invalidate_version->render($self);
 }
 
 sub action_ajax_delete {
@@ -338,8 +340,9 @@ sub action_ajax_delete {
     }
   }
 
-  $self->js->jstree->delete_node('#tree', '#fb-' . $self->item->id)
-           ->render($self);
+  $self->invalidate_version
+    ->jstree->delete_node('#tree', '#fb-' . $self->item->id)
+    ->render($self);
 }
 
 sub action_ajax_flag {
@@ -457,7 +460,7 @@ sub action_ajax_paste {
   # Update the current view if required.
   $self->insert_new_item_in_section_view($self->js) if $self->is_item_visible;
 
-  $self->js->render($self);
+  $self->invalidate_version->render($self);
 }
 
 #
@@ -469,14 +472,9 @@ sub check_auth {
   $::auth->assert('sales_quotation_edit');
 }
 
-sub load_requirement_spec {
-  my ($self) = @_;
-  $self->requirement_spec(SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id})->load || die "No such requirement spec");
-}
-
 sub load_requirement_spec_item {
   my ($self) = @_;
-  $self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load || die "No such requirement spec item");
+  $self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load);
 }
 
 #
@@ -616,4 +614,12 @@ sub is_item_visible {
   return $self->visible_section && ($self->visible_section->id == $item->section->id);
 }
 
+sub invalidate_version {
+  my ($self) = @_;
+
+  my $html   = $self->render('requirement_spec/_version', { output => 0 },
+                             requirement_spec => SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id} || $self->item->requirement_spec_id)->load);
+  return $self->js->html('#requirement_spec_version', $html);
+}
+
 1;
index 8ed37b9..5ea599f 100644 (file)
@@ -3,6 +3,9 @@ package SL::DB::RequirementSpecItem;
 use strict;
 
 use Carp;
+use List::MoreUtils qw(any);
+use Rose::DB::Object::Helpers;
+use Rose::DB::Object::Util;
 
 use SL::DB::MetaSetup::RequirementSpecItem;
 use SL::DB::Manager::RequirementSpecItem;
@@ -38,7 +41,9 @@ __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_i
 __PACKAGE__->attr_duration(qw(time_estimation));
 
 __PACKAGE__->before_save(\&_before_save_create_fb_number);
+__PACKAGE__->before_save(\  &_before_save_invalidate_requirement_spec_version);
 __PACKAGE__->before_delete(\&_before_delete_delete_children);
+__PACKAGE__->before_delete(\&_before_delete_invalidate_requirement_spec_version);
 
 sub _before_delete_delete_children {
   my ($self) = @_;
@@ -70,6 +75,33 @@ sub _before_save_create_fb_number {
   return 1;
 }
 
+sub _before_save_invalidate_requirement_spec_version {
+  my ($self, %params) = @_;
+
+  return 1 if !$self->requirement_spec_id;
+
+  my %changed_columns = map { $_ => 1 } (Rose::DB::Object::Helpers::dirty_columns($self));
+  my $has_changed     = !Rose::DB::Object::Util::is_in_db($self);
+  $has_changed      ||= any { $changed_columns{$_} } qw(requirement_spec_id parent_id position fb_number title description);
+
+  if (!$has_changed && $self->id) {
+    my $old_item = SL::DB::RequirementSpecItem->new(id => $self->id)->load;
+    $has_changed = join(':', sort map { $_->id } @{ $self->dependencies }) ne join(':', sort map { $_->id } @{ $old_item->dependencies });
+  }
+
+  $self->requirement_spec->invalidate_version if $has_changed;
+
+  return 1;
+}
+
+sub _before_delete_invalidate_requirement_spec_version {
+  my ($self, %params) = @_;
+
+  $self->requirement_spec->invalidate_version if $self->requirement_spec_id;
+
+  return 1;
+}
+
 sub validate {
   my ($self) = @_;