[Bps-public-commit] r9614 - in RT-Client-Console/trunk/lib/RT/Client: . Console/Session

dams at bestpractical.com dams at bestpractical.com
Wed Nov 7 11:13:08 EST 2007


Author: dams
Date: Wed Nov  7 11:13:07 2007
New Revision: 9614

Modified:
   RT-Client-Console/trunk/lib/RT/Client/Console.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/TabBar.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm

Log:
bugfix in tab view, multi ticket loading. Changed internal ticket structure

Modified: RT-Client-Console/trunk/lib/RT/Client/Console.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console.pm	Wed Nov  7 11:13:07 2007
@@ -19,7 +19,7 @@
 									password => undef,
 								   },
 							tickets => {
-										current => undef, # points to the current ticket structure
+										current_id => undef, # current ticket id
 										list => [], # arrayref containing the ordered tickets objects list
 										
 #										attachments => {

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm	Wed Nov  7 11:13:07 2007
@@ -53,14 +53,15 @@
  			my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
  			my $status_message = '';
  			$heap->{key_to_action} = {};
- 			foreach my $session (keys %{$class->GLOBAL_HEAP->{sessions}}) {
- 				my @list = $kernel->call($session, 'available_keys');
+			while (my ($session_name, $struct) = each %{$class->GLOBAL_HEAP->{sessions}}) {
+				$struct->{displayed} or next;
+ 				my @list = $kernel->call($session_name, 'available_keys');
 				foreach (@list) {
 					defined && ref or next;
 					my ($key, $message, $event) = @$_;
 					defined $key or next;
 					$status_message .= " | $key: $message";
-					$heap->{key_to_action}->{$key} = { session => $session, event => $event };
+					$heap->{key_to_action}->{$key} = { session => $session_name, event => $event };
 				}
  			}
 			$kernel->call('status', 'set_message', $status_message);
@@ -75,7 +76,6 @@
 				$kernel->yield('draw_all');
  			} else {
 				while (my ($session_name, $struct) = each %{$class->GLOBAL_HEAP->{sessions}}) {
-					print STDERR "$session_name : " . $struct->{displayed} . "\n";
 					$struct->{displayed} and 
 					  $kernel->call($session_name, 'draw');
 				}

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm	Wed Nov  7 11:13:07 2007
@@ -3,6 +3,7 @@
 use base qw(RT::Client::Console::Session);
 
 use Params::Validate qw(:all);
+use RT::Client::Console::Session::Ticket;
 
 use POE;
 
@@ -29,7 +30,7 @@
 			if ($class->GLOBAL_HEAP->{rt}{cnx}{handler}) {
 				push @available_list, ['d', 'disconnect from RT server', 'disconnect_server'];
 				push @available_list, ['o', 'open a ticket', 'open_ticket'];
-				if ($class->GLOBAL_HEAP->{rt}{tickets}{current}) {
+				if (defined RT::Client::Console::Session::Ticket->get_current_id()) {
 					push @available_list, ['c', 'close current ticket', 'close_ticket'];
 					push @available_list, ['p', 'prev. ticket', 'prev_ticket'];
 					push @available_list, ['n', 'next ticket', 'next_ticket'];
@@ -59,18 +60,15 @@
 		},
 		open_ticket => sub {
 			print STDERR "root.pm : opening ticket\n";
-			use RT::Client::Console::Session::Ticket;
 			RT::Client::Console::Session::Ticket->load();
 		},
 		close_ticket => sub {
-			$class->GLOBAL_HEAP->{rt}{tickets}{current}->unload();
+			RT::Client::Console::Session::Ticket->get_current_ticket()->unload();
 		},
 		next_ticket => sub {
-			use RT::Client::Console::Session::Ticket;
 			RT::Client::Console::Session::Ticket->next_ticket();
 		},
 		prev_ticket => sub {
-			use RT::Client::Console::Session::Ticket;
 			RT::Client::Console::Session::Ticket->prev_ticket();
 		},
 	}

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/TabBar.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/TabBar.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/TabBar.pm	Wed Nov  7 11:13:07 2007
@@ -43,16 +43,16 @@
 									});
 				$label->draw($curses_handler);
 				
-				my $current_id = $class->GLOBAL_HEAP->{rt}{tickets}{current}->id();
+				use RT::Client::Console::Session::Ticket;
+				my $current_id = RT::Client::Console::Session::Ticket->get_current_id();
 				my @visible_tickets = @tickets;
-				while (! _is_visible($current_id, @visible_tickets, $heap->{width})) {
+				while (! _is_visible($current_id, \@visible_tickets, $heap->{width})) {
 					shift @visible_tickets;					
 				}
 
 				my $widgets = {};
 				my $current_pos_x = 0;
 				foreach my $index (0.. at visible_tickets-1) {
-					print STDERR "-- in loop : $index \n";
 					my $ticket = $visible_tickets[$index];
 					my $string = '[ ' . $ticket->id() . ' ]';
 					$current_pos_x + length($string) > $heap->{width} and last;
@@ -93,12 +93,16 @@
 }
 
 sub _is_visible {
-	my ($id, @visible_tickets, $max_width) = @_;
+	my ($id, $visible_tickets, $max_width) = @_;
 	my $current_pos_x = 0;
-	foreach my $ticket (@visible_tickets) {
+	foreach my $ticket (@$visible_tickets) {
 		$current_pos_x += length "[ $id ]";
+		print STDERR ("-- ticket id : " . $ticket->id() . "\n");
+		print STDERR ("-- id : " . $id . "\n");
+		print STDERR ("-- " . ($current_pos_x > $max_width) . "\n");
 		if ( $ticket->id() == $id ) {
-			return ($current_pos_x > $max_width);
+			print STDERR ("-- YES\n");
+			return (! ($current_pos_x > $max_width));
 		}
 	}
 	die "shouldn't reach here";

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm	Wed Nov  7 11:13:07 2007
@@ -31,7 +31,7 @@
 				push @{$class->GLOBAL_HEAP->{rt}{tickets}{list}}, $ticket;
 				$class->GLOBAL_HEAP->{rt}{tickets}{total}++;
 			}
-			$class->GLOBAL_HEAP->{rt}{tickets}{current} = $ticket;
+			$class->set_current_id($id);
 			$class->_set_visibility();
 		}
 	} otherwise {
@@ -47,7 +47,7 @@
 			$class->GLOBAL_HEAP->{sessions}{$session}{displayed} = 0;
 		}
 	}
-	foreach my $session (@{$class->GLOBAL_HEAP->{rt}{tickets}{current}->{sessions}}) {
+	foreach my $session (@{$class->get_current_ticket()->{sessions}}) {
 		$class->GLOBAL_HEAP->{sessions}{$session}{displayed} = 1;
 	}
 }
@@ -101,20 +101,62 @@
 	# remove from the list of tickets
 	@{$self->GLOBAL_HEAP->{rt}{tickets}{list}} = grep { $_ ne $self } @{$self->GLOBAL_HEAP->{rt}{tickets}{list}};
 	# display the next visible ticket
-	if ($self->GLOBAL_HEAP->{rt}{tickets}{current} == $self) {
+	if ($self->get_current_id() == $self->id()) {
 		if (@{$self->GLOBAL_HEAP->{rt}{tickets}{list}} > 0) {
-			$self->GLOBAL_HEAP->{rt}{tickets}{current} = $self->GLOBAL_HEAP->{rt}{tickets}{list}->[-1];
+			$self->set_current_ticket($self->GLOBAL_HEAP->{rt}{tickets}{list}->[-1]);
 			$self->cls();
 		} else {
-			$self->GLOBAL_HEAP->{rt}{tickets}{current} = undef;
+			$self->set_current_id(undef);
 			$self->cls();
 		}
 	}
-	$class->_set_visibility();
+	$self->_set_visibility();
 }
 
 =head1 METHODS
 
+=head2 get_current_ticket
+
+=cut
+
+sub get_current_ticket {
+	my ($class) = @_;
+	my $current_id = $class->GLOBAL_HEAP->{rt}{tickets}{current_id};
+	defined $current_id or return;
+	foreach my $ticket (@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}) {
+		$ticket->id() == $current_id and return $ticket;
+	}
+	return;
+}
+
+=head2 get_current_id
+
+=cut
+
+sub get_current_id {
+	my ($class) = @_;
+	return $class->GLOBAL_HEAP->{rt}{tickets}{current_id};
+}
+
+=head2 set_current_ticket 
+
+=cut
+
+sub set_current_ticket {
+	my ($class, $ticket) = @_;
+	$class->GLOBAL_HEAP->{rt}{tickets}{current_id} = defined $ticket ? $ticket->id() : undef;
+}
+
+=head set_current_id
+
+=cut
+
+sub set_current_id {
+	my ($class, $id) = @_;
+	$class->GLOBAL_HEAP->{rt}{tickets}{current_id} = $id;
+}
+
+
 =head2 next
 
 show the next ticket from the list
@@ -124,13 +166,14 @@
 sub next_ticket {
 	my ($class) = @_;
 
-	foreach my $index (0..@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}-1) {
-		if ($class == $class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index]
-			&& exists $class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index+1] ){
-			$class->GLOBAL_HEAP->{rt}{tickets}{current} = 
-			$class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index+1];
+	my $current_id = $class->get_current_id();
+	my $index = 0;
+	foreach my $ticket (@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}) {
+		if ($ticket->id() == $current_id && exists $class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index+1] ) {
+			$class->set_current_ticket($class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index+1]);
 		}
 		$class->_set_visibility();
+		$index++;
 	}
 	return;
 }
@@ -143,14 +186,15 @@
 
 sub prev_ticket {
 	my ($class) = @_;
-
-	foreach my $index (0..@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}-1) {
-		if ($class == $class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index]
-			&& $index > 0 ){
-			$class->GLOBAL_HEAP->{rt}{tickets}{current} = 
-			$class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index-1];
+	
+	my $current_id = $class->get_current_id();
+	my $index = 0;
+	foreach my $ticket (@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}) {
+		if ($ticket->id() == $current_id && $index > 0 ) {
+			$class->set_current_ticket($class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index-1]);
 		}
 		$class->_set_visibility();
+		$index++;
 	}
 	return;
 }

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm	Wed Nov  7 11:13:07 2007
@@ -9,9 +9,9 @@
 
 # class method
 sub create {
-	my ($class, $id) = @_;
+	my ($class, $ticket_id) = @_;
 	$class->SUPER::create(
-	"ticket_attachments_$id",
+	"ticket_attachments_$ticket_id",
 	inline_states => {
 		init => sub {
 			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
@@ -25,8 +25,6 @@
 			$heap->{width} = $screen_w * 2 / 3 - 2;
 			$heap->{height} = $screen_h - 5 - 7 - 5;
 
-			my $ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current};
-
 		},
 		available_keys => sub {
 			return (['<KEY_NPAGE>', 'next attachment', 'next_attachment'],
@@ -35,33 +33,33 @@
 		},
 		next_attachment => sub {
 			my ( $kernel, $heap) = @_[ KERNEL, HEAP ];
-			$class->GLOBAL_HEAP->{rt}{attachments}{current}++;
-			$class->GLOBAL_HEAP->{rt}{attachments}{current} > $class->GLOBAL_HEAP->{rt}{attachments}{total} - 1
-			  and $class->GLOBAL_HEAP->{rt}{attachments}{current} = $class->GLOBAL_HEAP->{rt}{attachments}{total} - 1;
+			$class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current}++;
+			$class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current} > $class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{total} - 1
+			  and $class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current} = $class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{total} - 1;
 			$kernel->call('key_handler', 'draw_all');
 		},
 		prev_attachment => sub {
 			my ( $kernel, $heap) = @_[ KERNEL, HEAP ];
-			$class->GLOBAL_HEAP->{rt}{attachments}{current}--;
-			$class->GLOBAL_HEAP->{rt}{attachments}{current} < 0
-			  and $class->GLOBAL_HEAP->{rt}{attachments}{current} = 0;
+			$class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current}--;
+			$class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current} < 0
+			  and $class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current} = 0;
 			$kernel->call('key_handler', 'draw_all');
 		},
 		draw => sub {
 			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
 			my $label;
 
-			if (!defined($heap->{attachments})) {
-				$class->_generate_job($kernel, $heap);
+			if (!defined($heap->{attachments}{$ticket_id})) {
+				$class->_generate_job($kernel, $heap, $ticket_id);
 			}
-			defined($heap->{attachments}) or return;
-			my $total = $class->GLOBAL_HEAP->{rt}{attachments}{total};
+			defined($heap->{attachments}{$ticket_id}) or return;
+			my $total = $class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{total};
 			$total > 0 or return;
-			$class->GLOBAL_HEAP->{rt}{attachments}{current} ||= 0;
+			$class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current} ||= 0;
 
-			my $idx = $class->GLOBAL_HEAP->{rt}{attachments}{current};
+			my $idx = $class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{current};
 
-			my $attachment = $heap->{attachments}->[$idx];
+			my $attachment = $heap->{attachments}{$ticket_id}->[$idx];
 
 			my $text = '...loading...';
 			my $user_details = '';
@@ -160,8 +158,8 @@
 }
 
 sub _generate_job {
-	my ($class, $kernel, $heap) = @_;
-	$heap->{attachments} = [];
+	my ($class, $kernel, $heap, $ticket_id) = @_;
+	$heap->{attachments}{$ticket_id} = [];
 
 	my @ids;
 	my $idx = 0;
@@ -169,19 +167,20 @@
 	my $iterator;
 	use RT::Client::Console::Session::Progress;
 	RT::Client::Console::Session::Progress->add_progress(
-			steps_nb => sub { $class->GLOBAL_HEAP->{rt}{attachments}{total} },
+			steps_nb => sub { $class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{total} },
 			caption => sub { 'attachments' },
 			initially => sub {
-				my $ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current};
+				use RT::Client::Console::Session::Ticket;
+				my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
 				my $attachments_obj = $ticket->attachments();
 				my $count = $attachments_obj->count();
-				$class->GLOBAL_HEAP->{rt}{attachments}{total} = $count;
+				$class->GLOBAL_HEAP->{rt}{attachments}{$ticket_id}{total} = $count;
 				$iterator = $attachments_obj->get_iterator();
 			},
 			code => sub {
 				my $attachment = $iterator->();
 				defined $attachment or return;
-				push @{$heap->{attachments}}, $attachment;
+				push @{$heap->{attachments}{$ticket_id}}, $attachment;
 				$idx++ or $kernel->call('key_handler', 'draw_all');
 				return 1;
 			},

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm	Wed Nov  7 11:13:07 2007
@@ -3,7 +3,7 @@
 use base qw(RT::Client::Console::Session);
 
 use Params::Validate qw(:all);
-
+use RT::Client::Console::Session::Ticket;
 use POE;
 
 # class method
@@ -40,7 +40,7 @@
 			my ( $kernel, $heap) = @_[ KERNEL, HEAP ];
 			my $label;
 
-			my $ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current};
+			my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
 			my @custom_fields = sort $ticket->cf();
 			use POSIX qw(floor);
 			my $per_col = POSIX::floor(@custom_fields/3);

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm	Wed Nov  7 11:13:07 2007
@@ -30,7 +30,8 @@
 		},
 		change_header => sub {
 			my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
-			my $ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current};
+			use RT::Client::Console::Session::Ticket;
+			my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
 			$class->create_modal( title => ' Change ticket headers ',
 								  text => '',
 								  keys => {
@@ -100,7 +101,8 @@
 			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
 			my $label;
 
-			my $ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current};
+			use RT::Client::Console::Session::Ticket;
+			my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
 			my @requestors = $ticket->requestors();
 			my @requestor_text_list = map {
 				[ 'Requestor ' . $_ . ':' => $requestors[$_-1] ]

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm	Wed Nov  7 11:13:07 2007
@@ -3,6 +3,7 @@
 use base qw(RT::Client::Console::Session);
 
 use Params::Validate qw(:all);
+use RT::Client::Console::Session::Ticket;
 
 use POE;
 
@@ -61,7 +62,7 @@
 		modal_handler => sub {
 			my ( $kernel, $heap, $keystroke) = @_[ KERNEL, HEAP, ARG0 ];
 
-			my $ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current};
+			my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
 			if ($keystroke eq 'c' || $keystroke eq '<^[>') {
 				delete $class->GLOBAL_HEAP->{modal_session};
 			} else {
@@ -73,7 +74,7 @@
 			my ( $kernel, $heap) = @_[ KERNEL, HEAP ];
 			my $label;
 
-			my $ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current};
+			my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
 
 			if (!defined($heap->{parents})) {
 				$class->_generate_job($kernel, $heap, 'parents', q(HasMember=') . $ticket->id() . q('))
@@ -197,7 +198,6 @@
 			},
 			code => sub { my $id = $ids[$idx++];
 						  defined $id or return;
-						  use RT::Client::Console::Session::Ticket;
 						  push @{$heap->{$element}},
 							RT::Client::Console::Session::Ticket->load_ticket($rt_handler, $id);
 						  #										   $kernel->post('ticket_links', 'draw');



More information about the Bps-public-commit mailing list