From 4f5ea8fb2c1a3937b704a17f34d4004aa2d1c473 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 22 Apr 2013 10:35:48 +0200 Subject: [PATCH] =?utf8?q?Pflichtenhefversion=20nach=20=C3=84nderung=20an?= =?utf8?q?=20Items=20invalidieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RequirementSpecItem.pm | 34 ++++++++++++++++------------ SL/DB/RequirementSpecItem.pm | 32 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index 7dd8c8ee2..cffc22c16 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -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; diff --git a/SL/DB/RequirementSpecItem.pm b/SL/DB/RequirementSpecItem.pm index 8ed37b9d7..5ea599f89 100644 --- a/SL/DB/RequirementSpecItem.pm +++ b/SL/DB/RequirementSpecItem.pm @@ -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) = @_; -- 2.20.1