[Bps-public-commit] r15082 - in sd/trunk: . lib/App/SD/CLI/Command/Ticket/Attachment lib/App/SD/CLI/Command/Ticket/Comment

spang at bestpractical.com spang at bestpractical.com
Tue Aug 12 09:31:47 EDT 2008


Author: spang
Date: Tue Aug 12 09:31:44 2008
New Revision: 15082

Modified:
   sd/trunk/   (props changed)
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Attachment/Create.pm
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Comment/Create.pm
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Details.pm

Log:
 r47749 at loki:  spang | 2008-08-06 00:21:16 +0100
 simplify the details command code by using attachment/comment references instead of searching through all the attachment/comment records


Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Attachment/Create.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Attachment/Create.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Attachment/Create.pm	Tue Aug 12 09:31:44 2008
@@ -5,6 +5,8 @@
 
 before run => sub {
     my $self = shift;
+    $self->require_uuid;
+
     $self->set_prop(ticket => $self->cli->uuid);
 };
 

Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Comment/Create.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Comment/Create.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Comment/Create.pm	Tue Aug 12 09:31:44 2008
@@ -8,13 +8,14 @@
 # override args to feed in that ticket's uuid as an argument to the comment
 before run => sub {
     my $self = shift;
+    $self->require_uuid;
 
     my $content = $self->get_content(type => 'comment', default_edit => 1);
 
     die "Aborted.\n"
         if length($content) == 0;
 
-    $self->set_prop(ticket => $self->cli->uuid);
+    $self->set_prop(ticket => $ticket_uuid);
     $self->set_prop(content => $content);
 };
 

Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm	Tue Aug 12 09:31:44 2008
@@ -7,12 +7,16 @@
 sub run {
     my $self = shift;
     my $record = $self->_get_record_class();
-    $record->load( uuid => $self->uuid );
+
+    die "Cannot display comments without a ticket luid or uuid (specify with --id).\n"
+        unless (my $uuid = $self->uuid);
+
+    $record->load( uuid => $uuid );
     unless (@{$record->comments}) {
         print "No comments found\n";
     }
 
-    for my $entry (sort { $a->prop('date') cmp $b->prop('date') } @{$record->comments}) {
+    for my $entry (sort { $a->prop('created') cmp $b->prop('created') } @{$record->comments}) {
          print "id: ".$entry->luid." (".$entry->uuid.")\n";
         print "created: ".$entry->prop('created')."\n";
         print $entry->prop('content')."\n";

Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Details.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Details.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Details.pm	Tue Aug 12 09:31:44 2008
@@ -2,6 +2,8 @@
 use Moose;
 extends 'App::SD::CLI::Command::Ticket::Show';
 
+sub by_creation_date { $a->prop('created') cmp $b->prop('created') };
+
 override run => sub {
     my $self = shift;
     my $record = $self->_load_record;
@@ -10,25 +12,12 @@
     super();
 
     print "\n=head1 ATTACHMENTS\n\n";
-    my $attachments = App::SD::Collection::Attachment->new(
-        handle => $self->app_handle->handle,
-        app_handle => $self->app_handle,
-    );
-    $attachments->matching(sub {
-        shift->prop('ticket') eq $self->uuid ? 1 : 0;
-    });
-    print $_->format_summary . "\n" for $attachments->items;
+    my @attachments = sort by_creation_date @{$record->attachments};
+    print $_->format_summary . "\n" for @attachments;
 
     print "\n=head1 COMMENTS\n\n";
-    my $comments = App::SD::Collection::Comment->new(
-        handle => $self->app_handle->handle,
-    );
-    $comments->matching(sub {
-        shift->prop('ticket') eq $self->uuid ? 1 : 0;
-    });
-    my @items = sort { $a->prop('created') cmp $b->prop('created') }
-                    $comments->items;
-    print $_->prop('created') . "\n" . $_->prop('content') . "\n\n" for @items;
+    my @comments = sort by_creation_date @{$record->comments};
+    print $_->prop('created') . "\n" . $_->prop('content') . "\n\n" for @comments;
 };
 
 __PACKAGE__->meta->make_immutable;



More information about the Bps-public-commit mailing list