[Bps-public-commit] r9833 - in RT-Client-Console: trunk/bin trunk/lib/RT/Client trunk/lib/RT/Client/Console trunk/lib/RT/Client/Console/Session trunk/lib/RT/Client/Console/Session/Ticket
dams at bestpractical.com
dams at bestpractical.com
Thu Dec 6 09:48:39 EST 2007
Author: dams
Date: Thu Dec 6 09:48:37 2007
New Revision: 9833
Modified:
RT-Client-Console/ (props changed)
RT-Client-Console/trunk/bin/rtconsole
RT-Client-Console/trunk/lib/RT/Client/Console.pm
RT-Client-Console/trunk/lib/RT/Client/Console/Cnx.pm
RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm
RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm
RT-Client-Console/trunk/lib/RT/Client/Console/Session/Progress.pm
RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm
RT-Client-Console/trunk/lib/RT/Client/Console/Session/Status.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:
r21 at pundit: dams | 2007-12-06 14:48:24 +0000
added exception catching in rtconsole. removed most of GLOBAL_HEAP use. some cleaging
Modified: RT-Client-Console/trunk/bin/rtconsole
==============================================================================
--- RT-Client-Console/trunk/bin/rtconsole (original)
+++ RT-Client-Console/trunk/bin/rtconsole Thu Dec 6 09:48:37 2007
@@ -75,12 +75,20 @@
my @queues = split(/\s+/, $queues);
use RT::Client::Console;
-RT::Client::Console->run(curses_handler => $curses_handler,
- rt_servername => $config->{connection}{server},
- rt_username => $config->{connection}{user},
- rt_password => $config->{connection}{pass},
- queue_ids => \@queues,
- );
+use Error qw(:try);
+
+try {
+ RT::Client::Console->run(curses_handler => $curses_handler,
+ rt_servername => $config->{connection}{server},
+ rt_username => $config->{connection}{user},
+ rt_password => $config->{connection}{pass},
+ queue_ids => \@queues,
+ );
+} otherwise {
+ use Curses;
+ endwin;
+ print STDERR "\n\n ---- Main Error Message :\n$@\n";
+};
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 Thu Dec 6 09:48:37 2007
@@ -3,31 +3,21 @@
use warnings;
use strict;
use Carp;
-our $VERSION = '0.0.2';
+our $VERSION = '0.0.3';
use Params::Validate qw(:all);
+my $curses_handler;
+
+sub get_curses_handler {
+ return $curses_handler;
+}
+
# global heap to keep an application-level state
my %GLOBAL_HEAP = ( curses => {
- handler => undef,
need_clear => 0,
},
- rt => { cnx => {
- handler => undef,
- servername => undef,
- username => undef,
- password => undef,
- },
- tickets => {
- current_id => undef, # current ticket id
- list => [], # arrayref containing the ordered tickets objects list
-
-# attachments => {
-# current => undef,
-# total => 0,
-# },
-# total => 0,
- },
+ rt => {
},
server => {
id_to_queue => {},
@@ -38,12 +28,7 @@
current => undef,
total => 0,
},
- modal_sessions => [],
},
-# current_atta => undef,
-# total_tab => 0,
-# current_tab => undef,
- sessions => {},
);
sub GLOBAL_HEAP { \%GLOBAL_HEAP }
@@ -58,7 +43,7 @@
);
- $class->GLOBAL_HEAP->{curses}{handler} = delete $params{curses_handler};
+ $curses_handler = delete $params{curses_handler};
use RT::Client::Console::Session::Root;
RT::Client::Console::Session::Root->create();
@@ -123,7 +108,6 @@
my $title = $args{title};
my ($screen_w, $screen_h);
- my $curses_handler = $class->GLOBAL_HEAP->{curses}{handler};
$curses_handler->getmaxyx($screen_h, $screen_w);
use List::Util qw(min max);
Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Cnx.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Cnx.pm (original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Cnx.pm Thu Dec 6 09:48:37 2007
@@ -4,6 +4,17 @@
use Params::Validate qw(:all);
+my %cnx_data = (
+ handler => undef,
+ servername => undef,
+ username => undef,
+ password => undef,
+ );
+
+sub get_cnx_data {
+ return { %cnx_data };
+}
+
sub connect {
my ($class, @args) = @_;
my %params = validate( @args, { rt_servername => 0,
@@ -32,16 +43,16 @@
(my $rv, $params{rt_username}, $params{rt_password}) = logon('connect to RT server', BTN_OK | BTN_CANCEL, 50, qw(white red yellow) );
}
$rt_handler->login(username => $params{rt_username}, password => $params{rt_password});
- $class->GLOBAL_HEAP->{rt}{cnx}{handler} = $rt_handler;
- $class->GLOBAL_HEAP->{rt}{cnx}{servername} = $params{rt_servername};
- $class->GLOBAL_HEAP->{rt}{cnx}{username} = $params{rt_username};
- $class->GLOBAL_HEAP->{rt}{cnx}{password} = $params{rt_password};
+ $cnx_data{handler} = $rt_handler;
+ $cnx_data{servername} = $params{rt_servername};
+ $cnx_data{username} = $params{rt_username};
+ $cnx_data{password} = $params{rt_password};
# if (@{$params{queue_ids}}) {
# my $idx = 0;
-# my $rt_handler = $class->GLOBAL_HEAP->{rt}{cnx}{handler};
+# my $rt_handler = $cnx_data{handler};
# use RT::Client::Console::Session::Progress;
# RT::Client::Console::Session::Progress->add_progress(
@@ -77,12 +88,13 @@
sub disconnect {
my ($class) = @_;
- undef $class->GLOBAL_HEAP->{rt}{cnx}{handler};
- undef $class->GLOBAL_HEAP->{rt}{cnx}{servername};
- undef $class->GLOBAL_HEAP->{rt}{cnx}{username};
- undef $class->GLOBAL_HEAP->{rt}{cnx}{password};
+ undef $cnx_data{handler};
+ undef $cnx_data{servername};
+ undef $cnx_data{username};
+ undef $cnx_data{password};
my $ticket;
- while ($ticket = $class->GLOBAL_HEAP->{rt}{tickets}{current}) {
+ use RT::Client::Console::Session::Ticket;
+ while ($ticket = RT::Client::Console::Session::Ticket->get_current_ticket()) {
$ticket->unload();
}
return;
Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm (original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm Thu Dec 6 09:48:37 2007
@@ -4,6 +4,12 @@
use POE;
+my %sessions;
+
+my @modal_sessions;
+my $modal_index = 0;
+
+
sub create {
my ($class, $name, %args) = @_;
$args{inline_states}{_start} = sub {
@@ -11,26 +17,27 @@
$kernel->alias_set($name);
$kernel->call($name, 'init');
};
- $class->GLOBAL_HEAP->{sessions}{$name} = {
- poe_object => POE::Session->create(%args),
- displayed => 1,
- };
+ $sessions{$name} = {
+ poe_object => POE::Session->create(%args),
+ displayed => 1,
+ };
return $name;
}
+sub get_sessions { return %sessions; }
+
sub run {
my ($class) = @_;
$poe_kernel->run();
}
+sub set_display {
+ my ($class, $session_name, $display_state) = @_;
+ $sessions{$session_name}{displayed} = $display_state ? 1 : 0;
+}
-
-{
-
-my $modal_index = 0;
-
sub create_modal {
my ($class, %args) = @_;
@@ -47,7 +54,8 @@
my $width = max (map { length } (split(/\n/, $text), $args{title}));
my ($screen_w, $screen_h);
- my $curses_handler = $class->GLOBAL_HEAP->{curses}{handler};
+
+ my $curses_handler = $class->get_curses_handler();
$curses_handler->getmaxyx($screen_h, $screen_w);
use Curses::Widgets::Label;
@@ -79,7 +87,7 @@
exists $args{keys}->{$keystroke} or return;
if ($args{keys}{$keystroke}{code}->()) {
# stop modal mode
- pop @{$class->GLOBAL_HEAP->{modal_sessions}};
+ pop @modal_sessions;
$kernel->post('key_handler', 'draw_all');
} else {
$kernel->yield('draw');
@@ -87,15 +95,18 @@
},
draw => sub {
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
- my $curses_handler = $class->GLOBAL_HEAP->{curses}{handler};
+ my $curses_handler = $class->get_curses_handler();
$heap->{label}->draw($curses_handler);
},
},
);
- push @{$class->GLOBAL_HEAP->{modal_sessions}}, $modal_session_name;
+ push @modal_sessions, $modal_session_name;
return $modal_session_name;
}
+sub get_modal_sessions {
+ my ($class) = @_;
+ return @modal_sessions;
}
=head2 remove
@@ -108,7 +119,7 @@
sub remove {
my ($class, $session_name) = @_;
- delete $class->GLOBAL_HEAP->{sessions}{$session_name};
+ delete $sessions{$session_name};
}
1;
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 Thu Dec 6 09:48:37 2007
@@ -35,9 +35,10 @@
$keystroke = '<' . uc(keyname($keystroke)) . '>';
}
print STDERR "handler got $keystroke\n";
- if (@{$class->GLOBAL_HEAP->{modal_sessions}}) {
- print STDERR "modal handler : " . $class->GLOBAL_HEAP->{modal_sessions}->[-1] . "\n";
- $kernel->call($class->GLOBAL_HEAP->{modal_sessions}->[-1], 'key_handler', $keystroke);
+ my @modal_sessions = $class->get_modal_sessions();
+ if (@modal_sessions) {
+ print STDERR "modal handler : " . @modal_sessions . "\n";
+ $kernel->call(@modal_sessions, 'key_handler', $keystroke);
# $kernel->yield('compute_keys');
$kernel->yield('draw_all');
} elsif (exists $heap->{key_to_action}->{$keystroke}) {
@@ -53,7 +54,8 @@
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
my $status_message = '';
$heap->{key_to_action} = {};
- while (my ($session_name, $struct) = each %{$class->GLOBAL_HEAP->{sessions}}) {
+ my %sessions = $class->get_sessions();
+ while (my ($session_name, $struct) = each %sessions) {
$struct->{displayed} or next;
my @list = $kernel->call($session_name, 'available_keys');
foreach (@list) {
@@ -75,11 +77,12 @@
$class->GLOBAL_HEAP->{curses}{need_clear} = 0;
$kernel->yield('draw_all');
} else {
- while (my ($session_name, $struct) = each %{$class->GLOBAL_HEAP->{sessions}}) {
+ my %sessions = $class->get_sessions();
+ while (my ($session_name, $struct) = each %sessions) {
$struct->{displayed} and
$kernel->call($session_name, 'draw');
}
- foreach my $modal_session (@{$class->GLOBAL_HEAP->{modal_sessions}}) {
+ foreach my $modal_session ($class->get_modal_sessions()) {
$kernel->call($modal_session, 'draw');
}
}
Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Progress.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Progress.pm (original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Progress.pm Thu Dec 6 09:48:37 2007
@@ -18,7 +18,7 @@
my $draw_x = 0;
my @toremove = ();
my ($screen_w, $screen_h);
- my $curses_handler = RT::Client::Console->GLOBAL_HEAP->{curses}{handler};
+ my $curses_handler = $class->get_curses_handler();
$curses_handler->getmaxyx($screen_h, $screen_w);
my $label = Curses::Widgets::Label->new({
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 Thu Dec 6 09:48:37 2007
@@ -17,17 +17,18 @@
init => sub {
my ($kernel, $heap) = @_[ KERNEL, HEAP ];
print STDERR "root : init\n";
- $class->GLOBAL_HEAP->{curses}{handler}->clear();
+ $class->get_curses_handler()->clear();
$kernel->yield('create_tab_bar');
$kernel->yield('create_status_session');
$kernel->yield('create_progress_session');
},
available_keys => sub {
my @available_list = ();
- if (!$class->GLOBAL_HEAP->{rt}{cnx}{handler}) {
+ use RT::Client::Console::Cnx;
+ my $rt_handler = RT::Client::Console::Cnx->get_cnx_data()->{handler};
+ if (!$rt_handler) {
push @available_list, ['s', 'connect to RT server', 'connect_server'];
- }
- if ($class->GLOBAL_HEAP->{rt}{cnx}{handler}) {
+ } else {
push @available_list, ['d', 'disconnect from RT server', 'disconnect_server'];
push @available_list, ['o', 'open a ticket', 'open_ticket'];
if (defined RT::Client::Console::Session::Ticket->get_current_id()) {
Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Status.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Status.pm (original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Status.pm Thu Dec 6 09:48:37 2007
@@ -16,7 +16,7 @@
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
# Get the main screen max y & X
my ($screen_w, $screen_h);
- $class->GLOBAL_HEAP->{curses}{handler}->getmaxyx($screen_h, $screen_w);
+ $class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
$heap->{'pos_x'} = 0;
$heap->{'pos_y'} = $screen_h - 4;
@@ -46,7 +46,7 @@
BORDERCOL => 'black',
});
#refresh;
- $label->draw($class->GLOBAL_HEAP->{curses}{handler});
+ $label->draw($class->get_curses_handler());
},
},
heap => { 'pos_x' => 0,
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 Thu Dec 6 09:48:37 2007
@@ -18,15 +18,15 @@
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
# Get the main screen max y & X
my ($screen_w, $screen_h);
- $class->GLOBAL_HEAP->{curses}{handler}->getmaxyx($screen_h, $screen_w);
+ $class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
$heap->{width} = $screen_w;
},
draw => sub {
my ($kernel,$heap) = @_[ KERNEL, HEAP ];
- my $curses_handler = $class->GLOBAL_HEAP->{curses}{handler};
+ my $curses_handler = $class->get_curses_handler();
- my @tickets = @{$class->GLOBAL_HEAP->{rt}{tickets}{list}};
+ my @tickets = RT::Client::Console::Session::Ticket->get_tickets_list();
@tickets > 0 or return;
# clear the tab bar
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 Thu Dec 6 09:48:37 2007
@@ -9,11 +9,16 @@
use POE;
+
+
+my @tickets_list = ();
+my $current_ticket_id;
+
=head1 CONSTRUCTORS
=head2 load
-Loads a new ticket, or if already created, make sur it's made visible. If
+Loads a new ticket, or if already created, make sure it's made visible. If
needed, it adds it in the list of tickets.
input :
@@ -33,6 +38,13 @@
return;
}
+=head2 load_from_id
+
+Given an id, loads a new ticket, or if already created, make sure it's made
+visible. If needed, it adds it in the list of tickets.
+
+=cut
+
sub load_from_id {
my ($class, $id) = @_;
use Error qw(:try);
@@ -40,8 +52,7 @@
my $ticket;
if (! ($ticket = $class->_is_loaded($id)) ) {
$ticket = $class->new($id);
- push @{$class->GLOBAL_HEAP->{rt}{tickets}{list}}, $ticket;
- $class->GLOBAL_HEAP->{rt}{tickets}{total}++;
+ push @tickets_list, $ticket;
}
$class->set_current_id($id);
$class->_set_visibility();
@@ -53,27 +64,32 @@
sub _set_visibility {
my ($class) = @_;
- foreach my $ticket (@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}) {
+ foreach my $ticket (@tickets_list) {
foreach my $session (@{$ticket->{sessions}}) {
- $class->GLOBAL_HEAP->{sessions}{$session}{displayed} = 0;
+ RT::Client::Console::Session->set_display($session, 0);
}
}
- foreach my $session (@{$class->get_current_ticket()->{sessions}}) {
- $class->GLOBAL_HEAP->{sessions}{$session}{displayed} = 1;
+ my $current_ticket = $class->get_current_ticket();
+ defined $current_ticket or return;
+ foreach my $session (@{$current_ticket->{sessions}}) {
+ RT::Client::Console::Session->set_display($session, 1);
}
}
=head2 open_from_id
-simply return the REST ticket, don't display it, nor add it to the tab, or list of loaded tickets.
+Given an id, simply returns the REST ticket, don't display it, nor add it to
+the tab, or list of loaded tickets.
=cut
sub open_from_id {
my ($class, $id) = @_;
use RT::Client::REST::Ticket;
+ use RT::Client::Console::Cnx;
+ my $rt_handler = RT::Client::Console::Cnx->get_cnx_data()->{handler};
my $ticket = RT::Client::REST::Ticket->new(
- rt => $class->GLOBAL_HEAP->{rt}{cnx}{handler},
+ rt => $rt_handler,
id => $id,
);
$ticket->retrieve();
@@ -107,6 +123,18 @@
return bless $self, $class;
}
+=head1 ACCESSORS
+
+=head2 get_tickets_list
+
+Returns the list of loaded tickets.
+
+=cut
+
+sub get_tickets_list {
+ return @tickets_list;
+}
+
=head1 METHODS
=head2 unload
@@ -122,11 +150,11 @@
RT::Client::Console::Session->remove($session_name);
}
# remove from the list of tickets
- @{$self->GLOBAL_HEAP->{rt}{tickets}{list}} = grep { $_ ne $self } @{$self->GLOBAL_HEAP->{rt}{tickets}{list}};
+ @tickets_list = grep { $_ ne $self } @tickets_list;
# display the next visible ticket
if ($self->get_current_id() == $self->id()) {
- if (@{$self->GLOBAL_HEAP->{rt}{tickets}{list}} > 0) {
- $self->set_current_ticket($self->GLOBAL_HEAP->{rt}{tickets}{list}->[-1]);
+ if (@tickets_list > 0) {
+ $self->set_current_ticket($tickets_list[-1]);
$self->cls();
} else {
$self->set_current_id(undef);
@@ -144,9 +172,9 @@
sub get_current_ticket {
my ($class) = @_;
- my $current_id = $class->GLOBAL_HEAP->{rt}{tickets}{current_id};
+ my $current_id = $class->get_current_id();
defined $current_id or return;
- foreach my $ticket (@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}) {
+ foreach my $ticket (@tickets_list) {
$ticket->id() == $current_id and return $ticket;
}
return;
@@ -158,7 +186,7 @@
sub get_current_id {
my ($class) = @_;
- return $class->GLOBAL_HEAP->{rt}{tickets}{current_id};
+ return $current_ticket_id;
}
=head2 set_current_ticket
@@ -167,7 +195,7 @@
sub set_current_ticket {
my ($class, $ticket) = @_;
- $class->GLOBAL_HEAP->{rt}{tickets}{current_id} = defined $ticket ? $ticket->id() : undef;
+ $current_ticket_id = defined $ticket ? $ticket->id() : undef;
}
=head set_current_id
@@ -176,7 +204,7 @@
sub set_current_id {
my ($class, $id) = @_;
- $class->GLOBAL_HEAP->{rt}{tickets}{current_id} = $id;
+ $current_ticket_id = $id;
}
@@ -191,13 +219,13 @@
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]);
+ foreach my $ticket (@tickets_list) {
+ if ($ticket->id() == $current_id && exists $tickets_list[$index+1] ) {
+ $class->set_current_ticket($tickets_list[$index+1]);
}
- $class->_set_visibility();
$index++;
}
+ $class->_set_visibility();
return;
}
@@ -212,13 +240,13 @@
my $current_id = $class->get_current_id();
my $index = 0;
- foreach my $ticket (@{$class->GLOBAL_HEAP->{rt}{tickets}{list}}) {
+ foreach my $ticket (@tickets_list) {
if ($ticket->id() == $current_id && $index > 0 ) {
- $class->set_current_ticket($class->GLOBAL_HEAP->{rt}{tickets}{list}->[$index-1]);
+ $class->set_current_ticket($tickets_list[$index-1]);
}
- $class->_set_visibility();
$index++;
}
+ $class->_set_visibility();
return;
}
@@ -226,7 +254,7 @@
sub _is_loaded {
my ($class, $id) = @_;
- my @matches = grep { $_->{id} eq $id } @{$class->GLOBAL_HEAP->{rt}{tickets}{list}};
+ my @matches = grep { $_->{id} eq $id } @tickets_list;
@matches <= 1 or die "tickets loaded twice, shouldn't happen";
return @matches;
}
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 Thu Dec 6 09:48:37 2007
@@ -18,7 +18,7 @@
my ($screen_w, $screen_h);
- $class->GLOBAL_HEAP->{curses}{handler}->getmaxyx($screen_h, $screen_w);
+ $class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
$heap->{'pos_x'} = 0;
$heap->{'pos_y'} = 1+5+5;
@@ -68,9 +68,11 @@
try {
my $user_id = $attachment->creator_id();
use RT::Client::REST::User;
+ use RT::Client::Console::Cnx;
+ my $rt_handler = RT::Client::Console::Cnx->get_cnx_data()->{handler};
my ($user, $user_name, $user_email, $user_real_name, $user_gecos, $user_comments)
- = _get_user_details( rt => $class->GLOBAL_HEAP->{rt}{cnx}{handler},
+ = _get_user_details( rt => $rt_handler,
id => $user_id,
);
$user_details = "By : $user_real_name ($user_name) <$user_email>";
@@ -115,8 +117,7 @@
READONLY => 1,
}
);
-# $widget->execute($class->GLOBAL_HEAP->{curses}{handler});
- $widget->draw($class->GLOBAL_HEAP->{curses}{handler});
+ $widget->draw($class->get_curses_handler());
},
},
heap => { 'pos_x' => 0,
@@ -163,7 +164,8 @@
my @ids;
my $idx = 0;
- my $rt_handler = $class->GLOBAL_HEAP->{rt}{cnx}{handler};
+ use RT::Client::Console::Cnx;
+ my $rt_handler = RT::Client::Console::Cnx->get_cnx_data()->{handler};
my $iterator;
use RT::Client::Console::Session::Progress;
RT::Client::Console::Session::Progress->add_progress(
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 Thu Dec 6 09:48:37 2007
@@ -17,7 +17,7 @@
print STDERR "ticket_custfields : init\n";
my ($screen_w, $screen_h);
- $class->GLOBAL_HEAP->{curses}{handler}->getmaxyx($screen_h, $screen_w);
+ $class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
$heap->{'pos_x'} = 0;
$heap->{'pos_y'} = 8;
@@ -84,7 +84,7 @@
WIDGETS => \%custom_fields_widgets,
},
);
- $form->draw($class->GLOBAL_HEAP->{curses}{handler});
+ $form->draw($class->get_curses_handler());
# refresh($mwh);
},
},
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 Thu Dec 6 09:48:37 2007
@@ -17,7 +17,7 @@
my ($kernel, $heap) = @_[ KERNEL, HEAP ];
my ($screen_w, $screen_h);
- $class->GLOBAL_HEAP->{curses}{handler}->getmaxyx($screen_h, $screen_w);
+ $class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
$heap->{'pos_x'} = 0;
$heap->{'pos_y'} = 1;
@@ -151,7 +151,7 @@
WIDGETS => \%label_widgets,
},
);
- $form->draw($class->GLOBAL_HEAP->{curses}{handler});
+ $form->draw($class->get_curses_handler());
# refresh($mwh);
},
},
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 Thu Dec 6 09:48:37 2007
@@ -17,7 +17,7 @@
my ($kernel, $heap) = @_[ KERNEL, HEAP ];
my ($screen_w, $screen_h);
- $class->GLOBAL_HEAP->{curses}{handler}->getmaxyx($screen_h, $screen_w);
+ $class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
$heap->{'pos_x'} = $screen_w * 2 / 3 + 1;
$heap->{'pos_y'} = 1;
@@ -29,55 +29,65 @@
},
change_links => sub {
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
- $heap->{change_links_mode} = 1;
- my $text = qq(
-
- c : cancel
-);
- my $height = scalar( () = $text =~ /(\n)/g) + 1;
- use List::Util qw(max);
- my $title = ' Change ticket links ';
- my $width = max (map { length } (split(/\n/, $text), $title));
- my ($screen_w, $screen_h);
- my $curses_handler = $class->GLOBAL_HEAP->{curses}{handler};
- $curses_handler->getmaxyx($screen_h, $screen_w);
-
- use Curses::Widgets::Label;
- my $label = Curses::Widgets::Label->new({
- CAPTION => $title,
- CAPTIONCOL => 'yellow',
- BORDER => 1,
- LINES => $height,
- COLUMNS => $width,
- Y => $screen_h/2-($height+2)/2,
- X => $screen_w/2-($width+2)/2,,
- VALUE => $text,
- FOREGROUND => 'white',
- BACKGROUND => 'blue',
- BORDERCOL => 'white',
- });
- $label->draw($curses_handler);
- $class->GLOBAL_HEAP->{modal_session} = 'ticket_links';
- },
- modal_handler => sub {
- my ( $kernel, $heap, $keystroke) = @_[ KERNEL, HEAP, ARG0 ];
-
- my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
- if ($keystroke eq 'c' || $keystroke eq '<^[>') {
- delete $class->GLOBAL_HEAP->{modal_session};
- } else {
- $kernel->yield('change_links');
- }
- return;
+ $class->create_modal( title => 'Change tickets links',
+ text => '',
+ keys => {
+ p => { text => 'change parents',
+ code => sub {
+ if (my $new_parents = $class->input_ok_cancel(' Change parents ', join(', ', map {$_->id() } @{$heap->{parents}}), 500)) {
+ return 1; # stop modal mode
+ }
+
+ }
+ },
+ c => { text => 'change children',
+ code => sub {
+ if (my $new_children = $class->input_ok_cancel(' Change children ', join(', ', map {$_->id() } @{$heap->{children}}), 500)) {
+ return 1; # stop modal mode
+ }
+
+ }
+ },
+ d => { text => 'change depends',
+ code => sub {
+ if (my $new_children = $class->input_ok_cancel(' Change depends ', join(', ', map {$_->id() } @{$heap->{depends}}), 500)) {
+ return 1; # stop modal mode
+ }
+
+ }
+ },
+ D => { text => 'change depended',
+ code => sub {
+ if (my $new_children = $class->input_ok_cancel(' Change depended ', join(', ', map {$_->id() } @{$heap->{depended}}), 500)) {
+ return 1; # stop modal mode
+ }
+
+ }
+ },
+ r => { text => 'change refers',
+ code => sub {
+ if (my $new_children = $class->input_ok_cancel(' Change refers ', join(', ', map {$_->id() } @{$heap->{refers}}), 500)) {
+ return 1; # stop modal mode
+ }
+
+ }
+ },
+ R => { text => 'change refered',
+ code => sub {
+ if (my $new_children = $class->input_ok_cancel(' Change refered ', join(', ', map {$_->id() } @{$heap->{refere}}), 500)) {
+ return 1; # stop modal mode
+ }
+
+ }
+ },
+ }
+ );
},
draw => sub {
my ( $kernel, $heap) = @_[ KERNEL, HEAP ];
my $label;
my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
-
-print STDERR "LINKS ---> got $ticket \n";
-
if (!defined($heap->{parents})) {
$class->_generate_job($kernel, $heap, 'parents', q(HasMember=') . $ticket->id() . q('))
}
@@ -171,7 +181,7 @@
},
);
use Data::Dumper;
- $form->draw($class->GLOBAL_HEAP->{curses}{handler});
+ $form->draw($class->get_curses_handler());
# refresh($mwh);
},
},
@@ -189,7 +199,8 @@
$heap->{$element} = [];
my @ids;
my $idx = 0;
- my $rt_handler = $class->GLOBAL_HEAP->{rt}{cnx}{handler};
+ use RT::Client::Console::Cnx;
+ my $rt_handler = RT::Client::Console::Cnx->get_cnx_data()->{handler};
use RT::Client::Console::Session::Progress;
RT::Client::Console::Session::Progress->add_progress(
steps_nb => sub { scalar(@ids) },
More information about the Bps-public-commit
mailing list