[Bps-public-commit] r16156 - in sd/trunk: . lib/App/SD/CLI/Model

spang at bestpractical.com spang at bestpractical.com
Mon Sep 29 18:16:57 EDT 2008


Author: spang
Date: Mon Sep 29 18:16:56 2008
New Revision: 16156

Modified:
   sd/trunk/   (props changed)
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm
   sd/trunk/lib/App/SD/CLI/Model/Ticket.pm

Log:
 r50158 at loki:  spang | 2008-09-29 09:36:21 -0400
 make sd ticket update work with the new way of displaying tickets in an editor


Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm	Mon Sep 29 18:16:56 2008
@@ -15,43 +15,23 @@
     my $props = $record->get_props;
 
     if (!@{$self->prop_set} || $self->has_arg('edit')) {
+        my $ticket_string_to_edit = $self->create_record_string($record);
         my $do_not_edit = $record->props_not_to_edit;
 
-        my @show_props;
-        if ($record->can('props_to_show')) {
-            @show_props = $record->props_to_show;
-        } else {
-            @show_props = sort keys %$props;
-        }
-
-        # props we want to show for editing
-        my %prefill_props = %{$record->get_props};
-        map { $prefill_props{$_} = '' if !exists $prefill_props{$_} } @show_props;
-
-        # add any other defined props onto the end of the ordering and remove
-        # unwanted props
-        my %tmp;
-        map { $tmp{$_} = 1 } @show_props;
-        map { push @show_props, $_ unless exists $tmp{$_} } keys %prefill_props;
-        @show_props = grep !/$do_not_edit/, @show_props;
-
-        my $updated = $self->get_content( type => 'ticket', default_edit => 1,
-                                          prefill_props => \%prefill_props,
-                                          props_order => \@show_props,
-                                          footer => comment_separator(),
-                                      );
+        my $updated = $self->edit_text($ticket_string_to_edit);
 
         die "Aborted.\n"
-            if length($updated) == 0;
+            if $updated eq $ticket_string_to_edit; # user didn't change anything
 
-        my ($props_ref, $comment) = $self->parse_record($updated);
+        my ($props_ref, $comment) = $self->parse_record_string($updated);
 
         no warnings 'uninitialized';
 
+        # set new props but don't add props that didn't change to the changeset
         foreach my $prop (keys %$props_ref) {
             my $val = $props_ref->{$prop};
-            $record->set_prop(name => $prop, value => $val) unless
-                ($prop =~ /$do_not_edit/ or $val eq $prefill_props{$prop});
+            $record->set_prop(name => $prop, value => $val)
+                unless $val eq $record->prop($prop);
         }
 
         # if a formerly existing prop was removed from the output, delete it

Modified: sd/trunk/lib/App/SD/CLI/Model/Ticket.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Model/Ticket.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Model/Ticket.pm	Mon Sep 29 18:16:56 2008
@@ -97,18 +97,25 @@
 
 sub comment_pattern { qr/^\s*#/ }
 
-=head2 create_record_string
+=head2 create_record_string RECORD
 
 Creates a string representing a new record, prefilling default props
 and props specified on the command line. Intended to be presented to
 the user for editing using L<Prophet::CLI::Command->edit_text>
 and then parsed using L</create_record_string>.
 
+If RECORD is given, then we are updating that record rather than
+creating a new one, and the ticket string will be created from its
+props rather than prop defaults.
+
 =cut
 
 sub create_record_string {
     my $self = shift;
-    my $record = $self->_get_record_object;
+    my $record = shift;
+    my $update = 0;
+
+    defined($record) ? $update = 1 : $record = $self->_get_record_object;
 
     my $props_not_to_edit = $record->props_not_to_edit;
     my (@metadata_order, @editable_order);
@@ -120,24 +127,31 @@
     # that shouldn't be changed, such as uuid
     foreach my $prop ($record->props_to_show) {
         if ($prop =~ $props_not_to_edit) {
-            unless ($prop eq 'id' or $prop eq 'created') {
+            if ($prop eq 'id' && $update) {
+                # id isn't a *real* prop, so we have to mess with it some more
+                push @metadata_order, $prop;
+                $metadata_props{$prop} = $record->luid . ' (' . $record->uuid . ")";
+            }
+            elsif (!(($prop eq 'id' or $prop eq 'created') && !$update)) {
                 push @metadata_order, $prop;
                 # which came first, the chicken or the egg?
                 #
-                # we don't want to display id/created because they can't by
-                # their nature be specified until the ticket is actually
-                # created
-                $metadata_props{$prop} = undef;
+                # we don't want to display id/created for ticket creates
+                # because they can't by their nature be specified until the
+                # ticket is actually created
+                $metadata_props{$prop} = $update ? $record->prop($prop) : undef;
             }
         } else {
             push @editable_order, $prop;
-            $editable_props{$prop} = undef;
+            $editable_props{$prop} = $update ? $record->prop($prop) : undef;
         }
     }
 
-    # fill in prop defaults
-    $record->default_props(\%metadata_props);
-    $record->default_props(\%editable_props);
+    # fill in prop defaults if we're creating a new ticket
+    unless ($update) {
+        $record->default_props(\%metadata_props);
+        $record->default_props(\%editable_props);
+    }
 
     # fill in props specified on the commandline (overrides defaults)
     if ($self->has_arg('edit')) {



More information about the Bps-public-commit mailing list