[Rt-commit] rt branch, 4.2/queue-summary-refactoring, created. rt-4.1.13-231-g864f1ed

Ruslan Zakirov ruz at bestpractical.com
Wed Aug 28 11:37:18 EDT 2013


The branch, 4.2/queue-summary-refactoring has been created
        at  864f1ed6db0263aefbb6b7466ec8225d66b85c9c (commit)

- Log -----------------------------------------------------------------
commit 9a22d37be909141dd5f229276a457fe4b0967f7a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Feb 1 01:49:35 2011 +0300

    rename Prefs/Quicksearch.html as it going to be more generic

diff --git a/share/html/Elements/Quicksearch b/share/html/Elements/Quicksearch
index 77814ed..234516d 100644
--- a/share/html/Elements/Quicksearch
+++ b/share/html/Elements/Quicksearch
@@ -50,7 +50,7 @@
     title => loc("Quick search"),
     bodyclass => "",
     titleright => loc("Edit"),
-    titleright_href => RT->Config->Get('WebPath').'/Prefs/Quicksearch.html',
+    titleright_href => RT->Config->Get('WebPath').'/Prefs/QueueSummary.html',
 &>
 <& $comp,
    queue_filter => sub { $_->CurrentUserHasRight('ShowTicket') && !exists $unwanted->{$_->Name} },
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index e4b4914..91d8a70 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -564,7 +564,7 @@ my $build_main_nav = sub {
             title => loc('Dashboards in menu'),
             path  => '/Prefs/DashboardsInMenu.html',
         );
-        $settings->child( quicksearch    => title => loc('Quick search'),   path => '/Prefs/Quicksearch.html' );
+        $settings->child( quicksearch    => title => loc('Quick search'),   path => '/Prefs/QueueSummary.html' );
 
         my $search_menu = $settings->child( 'saved-searches' => title => loc('Saved Searches') );
         my $searches = [ $m->comp( "/Search/Elements/SearchesForObject",
diff --git a/share/html/Prefs/Quicksearch.html b/share/html/Prefs/QueueSummary.html
similarity index 98%
rename from share/html/Prefs/Quicksearch.html
rename to share/html/Prefs/QueueSummary.html
index 81757b9..7415680 100644
--- a/share/html/Prefs/Quicksearch.html
+++ b/share/html/Prefs/QueueSummary.html
@@ -50,7 +50,7 @@
 &>
 <& /Elements/ListActions, actions => \@actions &>
 <h1><&|/l&>Select queues to be displayed on the "RT at a glance" page</&></h1>
-<form method="post" action="Quicksearch.html" name="Preferences">
+<form method="post" action="QueueSummary.html" name="Preferences">
 <ul>
 % for my $queue (@queues) {
 <li><input type="checkbox" class="checkbox" id="Want-<%$queue->Name%>" name="Want-<%$queue->Name%>" value="1"

commit f1e050122a289a477888f518e55658ffc0bb693e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Feb 2 00:15:38 2011 +0300

    RT::SQL->Quote helper
    
    We could probably use DBI->quote instead, but implementation
    depends on DBD (database specific) and in theory a DB may has
    incompatible escaping rules.

diff --git a/lib/RT/SQL.pm b/lib/RT/SQL.pm
index 1a469d6..b551527 100644
--- a/lib/RT/SQL.pm
+++ b/lib/RT/SQL.pm
@@ -212,6 +212,19 @@ sub _BitmaskToString {
     return join ' or ', @res;
 }
 
+=head2 Quote
+
+Quotes a string for TicketSQL queries. Changes argument in void context.
+
+=cut
+
+sub Quote {
+    my $v = defined(wantarray)? \"$_[1]" : \$_[1];
+    $$v =~ s{(['\\])}{\\$1}g;
+    $$v = "'$$v'";
+    return $$v;
+}
+
 RT::Base->_ImportOverlays();
 
 1;

commit 63868ec0db914fa5527d29177fe7009923f0e438
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Feb 2 00:16:45 2011 +0300

    merge common code in QueueSummary* into /Elements/QueueSummary

diff --git a/share/html/Elements/QueueSummaryByStatus b/share/html/Elements/QueueSummary
similarity index 57%
copy from share/html/Elements/QueueSummaryByStatus
copy to share/html/Elements/QueueSummary
index ee6ae8f..6e3afc3 100644
--- a/share/html/Elements/QueueSummaryByStatus
+++ b/share/html/Elements/QueueSummary
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
 %#                                          <sales at bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -45,90 +45,34 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<table border="0" cellspacing="0" cellpadding="1" width="100%" class="queue-summary">
-
-<tr>
-    <th class="collection-as-table"><&|/l&>Queue</&></th>
-% for my $status ( @statuses ) {
-    <th class="collection-as-table"><% loc($status) %></th>
-% }
-</tr>
-
-<%PERL>
-my $i = 0;
-for my $queue (@queues) {
-    $i++;
-    my $lifecycle = $lifecycle{ lc $queue->{'Lifecycle'} };
-    my @queue_statuses = grep { $lifecycle->IsValid($_) } @statuses;
-</%PERL>
-<tr class="<% $i%2 ? 'oddline' : 'evenline'%>" >
-
-<td>
-    <a href="<% $link_all->($queue, \@queue_statuses) %>" title="<% $queue->{Description} %>"><% $queue->{Name} %></a>
-</td>
-
-<%perl>
-   for my $status (@statuses) {
-   if ( $lifecycle->IsValid( $status ) ) {
-</%perl>
-<td align="right">
-    <a href="<% $link_status->($queue, $status) %>"><% $data->{$queue->{id}}->{$status } || '-' %></a>
-</td>
-%   } else {
-<td align="right">-</td>
-%   }
-%   }
-</tr>
-% }
-</table>
 <%INIT>
-my $build_search_link = sub {
-    my ($queue_name, $extra_query) = @_;
-    $queue_name =~ s/(['\\])/\\$1/g; #'
-
-    return RT->Config->Get('WebPath')
-         . "/Search/Results.html?Query="
-         . $m->interp->apply_escapes("Queue = '$queue_name' AND $extra_query", 'u');
-};
-
-my $link_all = sub {
-    my ($queue, $all_statuses) = @_;
-    return $build_search_link->($queue->{Name}, "(".join(" OR ", map "Status = '$_'", @$all_statuses).")");
-};
-
-my $link_status = sub {
-    my ($queue, $status) = @_;
-    return $build_search_link->($queue->{Name}, "Status = '$status'");
-};
+$queues ||= RT::Queues->new( $session{'CurrentUser'} );
+$queues->UnLimit unless $queues->_isLimited;
 
-$m->callback(
-    CallbackName        => 'LinkBuilders',
-    build_search_link   => \$build_search_link,
-    link_all            => \$link_all,
-    link_status         => \$link_status,
-);
-
-my $Queues = RT::Queues->new( $session{'CurrentUser'} );
-$Queues->UnLimit();
-$m->callback( CallbackName => 'SQLFilter', Queues => $Queues );
+$m->callback( CallbackName => 'SQLFilter', Queues => $queues );
 
-my @queues = grep $queue_filter->($_), @{ $Queues->ItemsArrayRef };
+my @queues = $queue_filter
+    ? grep $queue_filter->($_), @{ $queues->ItemsArrayRef }
+    : @{ $queues->ItemsArrayRef }
+;
 $m->callback( CallbackName => 'Filter', Queues => \@queues );
 
- at queues = map {
-    {  id          => $_->Id,
-       Name        => $_->Name,
-       Description => $_->Description || '',
-       Lifecycle   => $_->Lifecycle,
-    }
-} grep $_, @queues;
-
-my %lifecycle;
+$preference = $preference
+    ? $session{'CurrentUser'}->UserObj->Preferences($preference, {})
+    : {}
+;
 
-for my $queue (@queues) {
-    my $cycle = RT::Lifecycle->Load( Name => $queue->{'Lifecycle'} );
-    $lifecycle{ lc $cycle->Name } = $cycle;
+my $comp = '/Elements/QueueSummaryByStatus';
+if ( $preference->{'SplitByLifecycle'} ) {
+    $comp = '/Elements/QueueSummaryByLifecycle';
 }
+if ( $preference->{'Unwanted'} && keys %{ $preference->{'Unwanted'} } ) {
+    @queues = grep !$preference->{'Unwanted'}{ $_->Name }, @queues;
+}
+
+return $m->comp( $comp ) unless @queues;
+
+my %lifecycle = map { lc $_->Name => $_ } map $_->LifecycleObj, @queues;
 
 unless (@statuses) {
     my %seen;
@@ -139,27 +83,72 @@ unless (@statuses) {
     }
 }
 
-my $data     = {};
-my $statuses = {};
-
 use RT::Report::Tickets;
 my $report = RT::Report::Tickets->new( RT->SystemUser );
 my $query =
-    "(".
-    join(" OR ", map {s{(['\\])}{\\$1}g; "Status = '$_'"} @statuses) #'
-    .") AND (".
-    join(' OR ', map "Queue = ".$_->{id}, @queues)
-    .")";
-$query = 'id < 0' unless @queues;
+    '('. join(" OR ", map "Status = ". RT::SQL->Quote($_), @statuses) .')'
+    .' AND ('. join(' OR ', map "Queue = ". $_->id, @queues) .')';
 $report->SetupGroupings( Query => $query, GroupBy => [qw(Status Queue)] );
 
+my (%data, %data_has_status);
 while ( my $entry = $report->Next ) {
-    $data->{ $entry->__Value("Queue") }->{ $entry->__Value("Status") }
-        = $entry->__Value('id');
-    $statuses->{ $entry->__Value("Status") } = 1;
+    my ($queue, $status, $count) = map $entry->__Value($_), qw(Queue Status id);
+
+    $data{ $queue }{ $status } = $count;
+    $data{ $queue }{''} += $count;
+    $data_has_status{ $status } = 1;
 }
+
+unless ( $preference->{'ShowEmptyColumns'} ) {
+    @statuses = grep $data_has_status{$_}, @statuses;
+}
+unless ( $preference->{'ShowEmptyRows'} ) {
+    @queues = grep $data{ $_->id }{''}, @queues;
+}
+
+my $build_search_link = sub {
+    my ($queue_name, $extra_query) = @_;
+
+    return RT->Config->Get('WebPath')
+         . "/Search/Results.html?Query="
+         . $m->interp->apply_escapes("Queue = ". RT::SQL->Quote($queue_name) ." AND $extra_query", 'u');
+};
+
+my $link_all = sub {
+    my ($queue, $all_statuses) = @_;
+    return $build_search_link->(
+        $queue->Name,
+        "(".join(" OR ", map "Status = ". RT::SQL->Quote($_), @$all_statuses).")"
+    );
+};
+
+my $link_status = sub {
+    my ($queue, $status) = @_;
+    return $build_search_link->($queue->Name, "Status = ". RT::SQL->Quote($status));
+};
+
+$m->callback(
+    CallbackName        => 'LinkBuilders',
+    build_search_link   => \$build_search_link,
+    link_all            => \$link_all,
+    link_status         => \$link_status,
+);
+
+return $m->comp(
+    $comp,
+    queues   => \@queues,
+    statuses => \@statuses,
+    data     => \%data,
+    linker => {
+        all => $link_all,
+        status => $link_status,
+        search => $build_search_link,
+    },
+);
 </%INIT>
 <%ARGS>
+$queues => undef
 $queue_filter => undef
+$preference => undef,
 @statuses => ()
 </%ARGS>
diff --git a/share/html/Elements/QueueSummaryByLifecycle b/share/html/Elements/QueueSummaryByLifecycle
index adcf489..d6af6c1 100644
--- a/share/html/Elements/QueueSummaryByLifecycle
+++ b/share/html/Elements/QueueSummaryByLifecycle
@@ -45,122 +45,71 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+<table border="0" cellspacing="0" cellpadding="1" width="100%" class="queue-summary">
+
 <%perl>
-    foreach my $lifecycle ( map $lifecycle{$_}, sort keys %lifecycle ) {
-    my @cur_statuses = grep $lifecycle->IsValid($_), @statuses;
-    next unless @cur_statuses;
-</%perl>
+my $i = 0;
 
-<table border="0" cellspacing="0" cellpadding="1" width="100%" class="queue-summary">
+foreach my $group ( map $groups{$_}, sort keys %groups ) {
+    my @statuses = @{ $group->{'statuses'} };
+</%perl>
 
 <tr>
     <th class="collection-as-table"><&|/l&>Queue</&></th>
-% for my $status ( @cur_statuses ) {
+% for my $status ( @statuses ) {
     <th class="collection-as-table"><% loc($status) %></th>
 % }
+% for ( 1 .. ($max - @statuses) ) {
+    <th class="collection-as-table"> </th>
+% }
 </tr>
 
 <%PERL>
-my $i = 0;
-for my $queue (@queues) {
-    next if lc($queue->{Lifecycle} || '') ne lc $lifecycle->Name;
-
+for my $queue (@{ $group->{'queues'} }) {
     $i++;
 </%PERL>
 <tr class="<% $i%2 ? 'oddline' : 'evenline'%>" >
 
 <td>
-    <a href="<% $link_all->($queue, \@cur_statuses) %>" title="<% $queue->{Description} %>"><% $queue->{Name} %></a>
+    <a href="<% $linker->{'all'}->($queue, $group->{'statuses'}) %>" title="<% $queue->Description %>"><% $queue->Name %></a>
 </td>
 
-%   for my $status (@cur_statuses) {
+%   for my $status (@statuses) {
 <td align="right">
-    <a href="<% $link_status->($queue, $status) %>"><% $data->{$queue->{id}}->{$status } || '-' %></a>
+    <a href="<% $linker->{'status'}->($queue, $status) %>"><% $data->{$queue->id}->{$status } || '-' %></a>
 </td>
 %   }
 </tr>
 % }
-</table>
 % }
+</table>
 <%INIT>
-my $build_search_link = sub {
-    my ($queue_name, $extra_query) = @_;
-    $queue_name =~ s/(['\\])/\\$1/g; #'
-
-    return RT->Config->Get('WebPath')
-         . "/Search/Results.html?Query="
-         . $m->interp->apply_escapes("Queue = '$queue_name' AND $extra_query", 'u');
-};
+return unless @queues && @statuses;
 
-my $link_all = sub {
-    my ($queue, $all_statuses) = @_;
-    return $build_search_link->($queue->{Name}, "(".join(" OR ", map "Status = '$_'", @$all_statuses).")");
-};
+my $max = 0;
 
-my $link_status = sub {
-    my ($queue, $status) = @_;
-    return $build_search_link->($queue->{Name}, "Status = '$status'");
-};
-
-$m->callback(
-    CallbackName        => 'LinkBuilders',
-    build_search_link   => \$build_search_link,
-    link_all            => \$link_all,
-    link_status         => \$link_status,
-);
-
-my $Queues = RT::Queues->new( $session{'CurrentUser'} );
-$Queues->UnLimit();
-$m->callback( CallbackName => 'SQLFilter', Queues => $Queues );
-
-my @queues = grep $queue_filter->($_), @{ $Queues->ItemsArrayRef };
-$m->callback( CallbackName => 'Filter', Queues => \@queues );
-
- at queues = map {
-    {  id          => $_->Id,
-       Name        => $_->Name,
-       Description => $_->Description || '',
-       Lifecycle   => $_->Lifecycle,
+my %groups;
+foreach my $queue ( @queues ) {
+    my $cycle = $queue->LifecycleObj;
+    my $cycle_name = $cycle->Name;
+    if ( $groups{ $cycle_name } ) {
+        push @{ $groups{ $cycle_name }{'queues'} }, $queue;
+        next;
     }
-} grep $_, @queues;
-
-my %lifecycle;
 
-for my $queue (@queues) {
-    my $cycle = RT::Lifecycle->Load( Name => $queue->{'Lifecycle'} );
-    $lifecycle{ lc $cycle->Name } = $cycle;
+    $groups{ $cycle_name } = {
+        cycle => $cycle,
+        statuses => [ grep $cycle->IsValid( $_), @statuses ],
+        queues => [$queue],
+    };
+    $max = @{ $groups{ $cycle_name }{'statuses'} }
+        if $max < @{ $groups{ $cycle_name }{'statuses'} };
 }
 
-unless (@statuses) {
-    my %seen;
-    foreach my $set ( 'initial', 'active' ) {
-        foreach my $lifecycle ( map $lifecycle{$_}, sort keys %lifecycle ) {
-            push @statuses, grep !$seen{ lc $_ }++, $lifecycle->Valid($set);
-        }
-    }
-}
-
-my $data     = {};
-my $statuses = {};
-
-use RT::Report::Tickets;
-my $report = RT::Report::Tickets->new( RT->SystemUser );
-my $query =
-    "(".
-    join(" OR ", map {s{(['\\])}{\\$1}g; "Status = '$_'"} @statuses) #'
-    .") AND (".
-    join(' OR ', map "Queue = ".$_->{id}, @queues)
-    .")";
-$query = 'id < 0' unless @queues;
-$report->SetupGroupings( Query => $query, GroupBy => [qw(Status Queue)] );
-
-while ( my $entry = $report->Next ) {
-    $data->{ $entry->__Value("Queue") }->{ $entry->__Value("Status") }
-        = $entry->__Value('id');
-    $statuses->{ $entry->__Value("Status") } = 1;
-}
 </%INIT>
 <%ARGS>
-$queue_filter => undef
- at statuses => ()
+ at queues          => ()
+ at statuses        => ()
+$data            => {}
+$linker          => {}
 </%ARGS>
diff --git a/share/html/Elements/QueueSummaryByStatus b/share/html/Elements/QueueSummaryByStatus
index ee6ae8f..5b4f1ae 100644
--- a/share/html/Elements/QueueSummaryByStatus
+++ b/share/html/Elements/QueueSummaryByStatus
@@ -58,13 +58,14 @@
 my $i = 0;
 for my $queue (@queues) {
     $i++;
-    my $lifecycle = $lifecycle{ lc $queue->{'Lifecycle'} };
+    my $lifecycle = $queue->LifecycleObj;
     my @queue_statuses = grep { $lifecycle->IsValid($_) } @statuses;
+
 </%PERL>
 <tr class="<% $i%2 ? 'oddline' : 'evenline'%>" >
 
 <td>
-    <a href="<% $link_all->($queue, \@queue_statuses) %>" title="<% $queue->{Description} %>"><% $queue->{Name} %></a>
+    <a href="<% $linker->{'all'}->($queue, \@queue_statuses) %>" title="<% $queue->Description %>"><% $queue->Name %></a>
 </td>
 
 <%perl>
@@ -72,7 +73,7 @@ for my $queue (@queues) {
    if ( $lifecycle->IsValid( $status ) ) {
 </%perl>
 <td align="right">
-    <a href="<% $link_status->($queue, $status) %>"><% $data->{$queue->{id}}->{$status } || '-' %></a>
+    <a href="<% $linker->{'status'}->($queue, $status) %>"><% $data->{$queue->id}->{$status } || '-' %></a>
 </td>
 %   } else {
 <td align="right">-</td>
@@ -82,84 +83,11 @@ for my $queue (@queues) {
 % }
 </table>
 <%INIT>
-my $build_search_link = sub {
-    my ($queue_name, $extra_query) = @_;
-    $queue_name =~ s/(['\\])/\\$1/g; #'
-
-    return RT->Config->Get('WebPath')
-         . "/Search/Results.html?Query="
-         . $m->interp->apply_escapes("Queue = '$queue_name' AND $extra_query", 'u');
-};
-
-my $link_all = sub {
-    my ($queue, $all_statuses) = @_;
-    return $build_search_link->($queue->{Name}, "(".join(" OR ", map "Status = '$_'", @$all_statuses).")");
-};
-
-my $link_status = sub {
-    my ($queue, $status) = @_;
-    return $build_search_link->($queue->{Name}, "Status = '$status'");
-};
-
-$m->callback(
-    CallbackName        => 'LinkBuilders',
-    build_search_link   => \$build_search_link,
-    link_all            => \$link_all,
-    link_status         => \$link_status,
-);
-
-my $Queues = RT::Queues->new( $session{'CurrentUser'} );
-$Queues->UnLimit();
-$m->callback( CallbackName => 'SQLFilter', Queues => $Queues );
-
-my @queues = grep $queue_filter->($_), @{ $Queues->ItemsArrayRef };
-$m->callback( CallbackName => 'Filter', Queues => \@queues );
-
- at queues = map {
-    {  id          => $_->Id,
-       Name        => $_->Name,
-       Description => $_->Description || '',
-       Lifecycle   => $_->Lifecycle,
-    }
-} grep $_, @queues;
-
-my %lifecycle;
-
-for my $queue (@queues) {
-    my $cycle = RT::Lifecycle->Load( Name => $queue->{'Lifecycle'} );
-    $lifecycle{ lc $cycle->Name } = $cycle;
-}
-
-unless (@statuses) {
-    my %seen;
-    foreach my $set ( 'initial', 'active' ) {
-        foreach my $lifecycle ( map $lifecycle{$_}, sort keys %lifecycle ) {
-            push @statuses, grep !$seen{ lc $_ }++, $lifecycle->Valid($set);
-        }
-    }
-}
-
-my $data     = {};
-my $statuses = {};
-
-use RT::Report::Tickets;
-my $report = RT::Report::Tickets->new( RT->SystemUser );
-my $query =
-    "(".
-    join(" OR ", map {s{(['\\])}{\\$1}g; "Status = '$_'"} @statuses) #'
-    .") AND (".
-    join(' OR ', map "Queue = ".$_->{id}, @queues)
-    .")";
-$query = 'id < 0' unless @queues;
-$report->SetupGroupings( Query => $query, GroupBy => [qw(Status Queue)] );
-
-while ( my $entry = $report->Next ) {
-    $data->{ $entry->__Value("Queue") }->{ $entry->__Value("Status") }
-        = $entry->__Value('id');
-    $statuses->{ $entry->__Value("Status") } = 1;
-}
+return unless @queues && @statuses;
 </%INIT>
 <%ARGS>
-$queue_filter => undef
- at statuses => ()
+ at queues          => ()
+ at statuses        => ()
+$data            => {}
+$linker          => {}
 </%ARGS>

commit 8cf9625808ac58ee4670ef40901a6e33b0d0ab65
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Feb 2 00:17:34 2011 +0300

    use new QueueSummary

diff --git a/share/html/Elements/MyAdminQueues b/share/html/Elements/MyAdminQueues
index 880ef3c..7ff78a3 100644
--- a/share/html/Elements/MyAdminQueues
+++ b/share/html/Elements/MyAdminQueues
@@ -45,8 +45,14 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<&|/Widgets/TitleBox, title => loc("Queues I administer"), bodyclass => "" &>
-<& /Elements/QueueSummaryByStatus,
-   queue_filter => sub { $_->CurrentUserHasRight('AdminQueue') },
+<&|/Widgets/TitleBox,
+    title => loc("Queues I administer"),
+    bodyclass => "",
+    titleright => loc("Edit"),
+    titleright_href => RT->Config->Get('WebPath').'/Prefs/QueueSummary.html?Pref=MyAdminQueues',
+&>
+<& /Elements/QueueSummary,
+    preference => 'MyAdminQueues',
+    queue_filter => sub { $_->CurrentUserHasRight('AdminQueue') },
 &>
 </&>
diff --git a/share/html/Elements/MySupportQueues b/share/html/Elements/MySupportQueues
index 6537ea1..a35453e 100644
--- a/share/html/Elements/MySupportQueues
+++ b/share/html/Elements/MySupportQueues
@@ -45,8 +45,14 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<&|/Widgets/TitleBox, title => loc("Queues I'm an AdminCc for"), bodyclass => "" &>
-<& /Elements/QueueSummaryByStatus,
-   queue_filter => sub { $_->IsAdminCc($session{'CurrentUser'}->Id) },
+<&|/Widgets/TitleBox,
+    title => loc("Queues I'm an AdminCc for"),
+    bodyclass => "",
+    titleright => loc("Edit"),
+    titleright_href => RT->Config->Get('WebPath').'/Prefs/QueueSummary.html?Pref=MySupportQueues',
+&>
+<& /Elements/QueueSummary,
+    preference => 'MySupportQueues',
+    queue_filter => sub { $_->IsAdminCc($session{'CurrentUser'}->Id) },
 &>
 </&>
diff --git a/share/html/Elements/Quicksearch b/share/html/Elements/Quicksearch
index 234516d..f015245 100644
--- a/share/html/Elements/Quicksearch
+++ b/share/html/Elements/Quicksearch
@@ -50,17 +50,11 @@
     title => loc("Quick search"),
     bodyclass => "",
     titleright => loc("Edit"),
-    titleright_href => RT->Config->Get('WebPath').'/Prefs/QueueSummary.html',
+    titleright_href => RT->Config->Get('WebPath').'/Prefs/QueueSummary.html?EditUnwanted=1',
 &>
-<& $comp,
-   queue_filter => sub { $_->CurrentUserHasRight('ShowTicket') && !exists $unwanted->{$_->Name} },
+<& /Elements/QueueSummary,
+    preference => 'QuickSearch',
+    queue_filter => sub { $_->CurrentUserHasRight('ShowTicket') },
 &>
 </&>
 </div>
-<%INIT>
-my $unwanted = $session{'CurrentUser'}->UserObj->Preferences('QuickSearch', {});
-my $comp = $SplitByLifecycle? '/Elements/QueueSummaryByLifecycle' : '/Elements/QueueSummaryByStatus';
-</%INIT>
-<%ARGS>
-$SplitByLifecycle => 1
-</%ARGS>

commit f6b030f6761ddcbf1bb896e24785f349d580f52f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Feb 2 00:18:11 2011 +0300

    new preferences UI for all portlets based on QueueSummary

diff --git a/share/html/Prefs/QueueSummary.html b/share/html/Prefs/QueueSummary.html
index 7415680..ba3fb2f 100644
--- a/share/html/Prefs/QueueSummary.html
+++ b/share/html/Prefs/QueueSummary.html
@@ -46,22 +46,48 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <& /Elements/Header, Title => $title &>
-<& /Elements/Tabs
-&>
+<& /Elements/Tabs &>
+
 <& /Elements/ListActions, actions => \@actions &>
-<h1><&|/l&>Select queues to be displayed on the "RT at a glance" page</&></h1>
+
 <form method="post" action="QueueSummary.html" name="Preferences">
+<input type="hidden" class="hidden" name="Pref" value="<% $Pref %>" \>
+<input type="hidden" class="hidden" name="EditUnwanted" value="<% $EditUnwanted %>" \>
+
+<h1><&|/l&>Select table preferences</&></h1>
+
+<label><input type="checkbox" class="checkbox" name="ShowEmptyRows" value="1" \
+% if ( $preference->{'ShowEmptyRows'} ) {
+checked="checked" \
+% }
+/><&|/l&>Show rows with all zeros</&></label><br />
+
+<label><input type="checkbox" class="checkbox" name="ShowEmptyColumns" value="1" \
+% if ( $preference->{'ShowEmptyColumns'} ) {
+checked="checked" \
+% }
+/><&|/l&>Show columns with all zeros</&></label><br />
+
+<label><input type="checkbox" class="checkbox" name="SplitByLifecycle" value="1" \
+% if ( $preference->{'SplitByLifecycle'} ) {
+checked="checked" \
+% }
+/><&|/l&>Split into groups with different status sets (lifecycles)</&></label><br />
+
+% if ( $EditUnwanted ) {
+<h1><&|/l&>Select queues to be displayed</&></h1>
 <ul>
 % for my $queue (@queues) {
-<li><input type="checkbox" class="checkbox" id="Want-<%$queue->Name%>" name="Want-<%$queue->Name%>" value="1"
-% unless ($unwanted->{$queue->Name}) {
-checked="checked"
+<li><input type="checkbox" class="checkbox" id="Want-<%$queue->Name%>" name="Want" value="<%$queue->Name%>"
+% unless ($preference->{'Unwanted'}{ $queue->Name }) {
+checked="checked" \
 % }
 />
 <label for="Want-<%$queue->Name%>"><%$queue->Name%><% $queue->Description ? ': '.$queue->Description : '' %></label>
 </li>
 % }
 </ul>
+% }
 <& /Elements/Submit,
     Caption             => loc("Save Changes"),
     Label               => loc('Save'),
@@ -69,41 +95,56 @@ checked="checked"
     Reset               => 1,
     CheckAll            => 1,
     ClearAll            => 1,
-    CheckboxNameRegex   => '/^Want-/',
+    CheckboxNameRegex   => '/^Want$/',
     &>
 
 </form>
 
 <%INIT>
 my @actions;
+
 my $title = loc("Customize").' '.loc("Quick search");
+
 my $user = $session{'CurrentUser'}->UserObj;
-my $unwanted = $user->Preferences('QuickSearch', {});
-my $Queues = RT::Queues->new($session{'CurrentUser'});
-$Queues->UnLimit;
-
-my $right = 'ShowTicket';
-$m->callback(
-    CallbackName    => 'ModifyQueues',
-    Queues          => \$Queues,
-    Right           => \$right,
-    Unwanted        => $unwanted,
-);
-
-my @queues = grep { $right ? $_->CurrentUserHasRight($right) : 1 } @{$Queues->ItemsArrayRef};
-
-if ($ARGS{'Save'}) {
-    for my $queue (@queues) {
-        if ($ARGS{"Want-".$queue->Name}) {
-            delete $unwanted->{$queue->Name};
-        }
-        else {
-            ++$unwanted->{$queue->Name};
-        }
-    }
-
-    my ($ok, $msg) = $user->SetPreferences('QuickSearch', $unwanted);
+
+my $preference = $user->Preferences($Pref, {});
+
+my @queues;
+if ( $EditUnwanted ) {
+    my $Queues = RT::Queues->new($session{'CurrentUser'});
+    $Queues->UnLimit;
+
+    my $right = 'ShowTicket';
+    $m->callback(
+        CallbackName    => 'ModifyQueues',
+        Queues          => \$Queues,
+        Right           => \$right,
+        Want            => \@Want,
+    );
+
+    @queues = grep { $right? $_->CurrentUserHasRight( $right ) : 1 } @{ $Queues->ItemsArrayRef };
+}
+
+if ( $Save ) {
+    my %Want = map { $_ => 1 } @Want;
+    $preference->{'Unwanted'} = { map { $_ => 1 } grep !$Want{ $_ }, map $_->Name, @queues };
+
+    $preference->{$_} = $ARGS{$_} foreach qw(
+        SplitByLifecycle
+        ShowEmptyRows
+        ShowEmptyColumns
+    );
+
+    my ($ok, $msg) = $user->SetPreferences( $Pref => $preference );
     push @actions, $ok ? loc('Preferences saved.') : $msg;
 }
 
 </%INIT>
+<%ARGS>
+$Pref         => 'QuickSearch'
+
+$EditUnwanted => 0
+ at Want         => ()
+
+$Save         => 0
+</%ARGS>

commit e825b16cb9d4c2a8279ed4f4507b610ee5eefbd8
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Feb 2 00:20:00 2011 +0300

    drop "quicksearch" preferences tab
    
    there are multiple quick search like portlets, each with its own
    preferences

diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 91d8a70..27815e6 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -564,7 +564,6 @@ my $build_main_nav = sub {
             title => loc('Dashboards in menu'),
             path  => '/Prefs/DashboardsInMenu.html',
         );
-        $settings->child( quicksearch    => title => loc('Quick search'),   path => '/Prefs/QueueSummary.html' );
 
         my $search_menu = $settings->child( 'saved-searches' => title => loc('Saved Searches') );
         my $searches = [ $m->comp( "/Search/Elements/SearchesForObject",

commit 6f84294ca312a2e4aeaba1cbe7d6cf33acba1aca
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Mar 2 16:21:38 2011 +0300

    adjust tests for new QueueSummary
    
    no more link under preferences, use one from "rt at glance"
    
    Want checkbox has been changed - it's an array now

diff --git a/t/web/custom_search.t b/t/web/custom_search.t
index 75f832d..408ad77 100644
--- a/t/web/custom_search.t
+++ b/t/web/custom_search.t
@@ -22,7 +22,8 @@ like ($t_link->url, qr/$id/, 'link to the ticket we created');
 $m->content_lacks ('customsearch at localhost', 'requestor not displayed ');
 $m->get ( $url.'Prefs/MyRT.html' );
 my $cus_hp = $m->find_link( text => "My Tickets" );
-my $cus_qs = $m->find_link( text => "Quick search" );
+$m->get ( $url );
+my $cus_qs = $m->find_link( text => "Edit", url_regex => qr/QueueSummary/ );
 $m->get ($cus_hp);
 $m->content_contains('highest priority tickets');
 
@@ -66,7 +67,7 @@ $m->content_lacks ('customsearch at localhost', 'requestor not displayed ');
 my $nlinks = $#{$m->find_all_links( text => "General" )};
 $m->get ($cus_qs);
 $m->form_name ('Preferences');
-$m->untick('Want-General', '1');
+$m->untick( Want => 'General');
 $m->click_button (name => 'Save');
 
 $m->get( $url );
@@ -76,7 +77,7 @@ is ($#{$m->find_all_links( text => "General" )}, $nlinks - 1,
 # get it back
 $m->get ($cus_qs);
 $m->form_name ('Preferences');
-$m->tick('Want-General', '1');
+$m->tick( Want => 'General' );
 $m->click_button (name => 'Save');
 
 $m->get( $url );

commit e1096353778a063e6a42c9b0b55badd40c40659f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Aug 28 18:06:39 2013 +0400

    update license tag

diff --git a/share/html/Elements/QueueSummary b/share/html/Elements/QueueSummary
index 6e3afc3..5dcd0e4 100644
--- a/share/html/Elements/QueueSummary
+++ b/share/html/Elements/QueueSummary
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
 %#                                          <sales at bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)

commit cdcb101ef59a4c648de5cbd403729c3fae2aefef
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Aug 28 18:17:42 2013 +0400

    make split by lifecycle default
    
    It was default in 4.0 and it is good default, so new preference
    is 'NoSplitByLifecycle'

diff --git a/share/html/Elements/QueueSummary b/share/html/Elements/QueueSummary
index 5dcd0e4..a8d560b 100644
--- a/share/html/Elements/QueueSummary
+++ b/share/html/Elements/QueueSummary
@@ -62,9 +62,9 @@ $preference = $preference
     : {}
 ;
 
-my $comp = '/Elements/QueueSummaryByStatus';
-if ( $preference->{'SplitByLifecycle'} ) {
-    $comp = '/Elements/QueueSummaryByLifecycle';
+my $comp = '/Elements/QueueSummaryByLifecycle';
+if ( $preference->{'NoSplitByLifecycle'} ) {
+    $comp = '/Elements/QueueSummaryByStatus';
 }
 if ( $preference->{'Unwanted'} && keys %{ $preference->{'Unwanted'} } ) {
     @queues = grep !$preference->{'Unwanted'}{ $_->Name }, @queues;
diff --git a/share/html/Prefs/QueueSummary.html b/share/html/Prefs/QueueSummary.html
index ba3fb2f..f8ce765 100644
--- a/share/html/Prefs/QueueSummary.html
+++ b/share/html/Prefs/QueueSummary.html
@@ -68,11 +68,11 @@ checked="checked" \
 % }
 /><&|/l&>Show columns with all zeros</&></label><br />
 
-<label><input type="checkbox" class="checkbox" name="SplitByLifecycle" value="1" \
-% if ( $preference->{'SplitByLifecycle'} ) {
+<label><input type="checkbox" class="checkbox" name="NoSplitByLifecycle" value="1" \
+% if ( $preference->{'NoSplitByLifecycle'} ) {
 checked="checked" \
 % }
-/><&|/l&>Split into groups with different status sets (lifecycles)</&></label><br />
+/><&|/l&>Don't split into groups with different status sets (lifecycles)</&></label><br />
 
 % if ( $EditUnwanted ) {
 <h1><&|/l&>Select queues to be displayed</&></h1>
@@ -130,7 +130,7 @@ if ( $Save ) {
     $preference->{'Unwanted'} = { map { $_ => 1 } grep !$Want{ $_ }, map $_->Name, @queues };
 
     $preference->{$_} = $ARGS{$_} foreach qw(
-        SplitByLifecycle
+        NoSplitByLifecycle
         ShowEmptyRows
         ShowEmptyColumns
     );

commit 0ded704ced690354edb2365af5eaf3625ab09dd9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Aug 28 18:58:38 2013 +0400

    make default to show empty rows/columns
    
    While it's useful to hide them in some conditions,
    but in most situations repeated position of queues
    and columns is win in user experience terms.

diff --git a/share/html/Elements/QueueSummary b/share/html/Elements/QueueSummary
index a8d560b..0c1d920 100644
--- a/share/html/Elements/QueueSummary
+++ b/share/html/Elements/QueueSummary
@@ -99,10 +99,10 @@ while ( my $entry = $report->Next ) {
     $data_has_status{ $status } = 1;
 }
 
-unless ( $preference->{'ShowEmptyColumns'} ) {
+if ( $preference->{'HideEmptyColumns'} ) {
     @statuses = grep $data_has_status{$_}, @statuses;
 }
-unless ( $preference->{'ShowEmptyRows'} ) {
+if ( $preference->{'HideEmptyRows'} ) {
     @queues = grep $data{ $_->id }{''}, @queues;
 }
 
diff --git a/share/html/Prefs/QueueSummary.html b/share/html/Prefs/QueueSummary.html
index f8ce765..5f24911 100644
--- a/share/html/Prefs/QueueSummary.html
+++ b/share/html/Prefs/QueueSummary.html
@@ -56,17 +56,17 @@
 
 <h1><&|/l&>Select table preferences</&></h1>
 
-<label><input type="checkbox" class="checkbox" name="ShowEmptyRows" value="1" \
-% if ( $preference->{'ShowEmptyRows'} ) {
+<label><input type="checkbox" class="checkbox" name="HideEmptyRows" value="1" \
+% if ( $preference->{'HideEmptyRows'} ) {
 checked="checked" \
 % }
-/><&|/l&>Show rows with all zeros</&></label><br />
+/><&|/l&>Hide rows with all zeros</&></label><br />
 
-<label><input type="checkbox" class="checkbox" name="ShowEmptyColumns" value="1" \
-% if ( $preference->{'ShowEmptyColumns'} ) {
+<label><input type="checkbox" class="checkbox" name="HideEmptyColumns" value="1" \
+% if ( $preference->{'HideEmptyColumns'} ) {
 checked="checked" \
 % }
-/><&|/l&>Show columns with all zeros</&></label><br />
+/><&|/l&>Hide columns with all zeros</&></label><br />
 
 <label><input type="checkbox" class="checkbox" name="NoSplitByLifecycle" value="1" \
 % if ( $preference->{'NoSplitByLifecycle'} ) {
@@ -131,8 +131,8 @@ if ( $Save ) {
 
     $preference->{$_} = $ARGS{$_} foreach qw(
         NoSplitByLifecycle
-        ShowEmptyRows
-        ShowEmptyColumns
+        HideEmptyRows
+        HideEmptyColumns
     );
 
     my ($ok, $msg) = $user->SetPreferences( $Pref => $preference );

commit 864f1ed6db0263aefbb6b7466ec8225d66b85c9c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Aug 28 19:35:56 2013 +0400

    upgrade script for old quicksearch preferences

diff --git a/etc/upgrade/4.1.22/content b/etc/upgrade/4.1.22/content
new file mode 100644
index 0000000..77053f1
--- /dev/null
+++ b/etc/upgrade/4.1.22/content
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+
+our @Initial = (sub {
+    my $pref_name = 'QuickSearch';
+
+    my $users = RT::Users->new(RT->SystemUser);
+    $users->FindAllRows;
+
+    my $attributes = $users->Join(
+        ALIAS1  => "main",
+        FIELD1  => "id",
+        TABLE2  => RT::Attributes->Table,
+        FIELD2  => "ObjectId",
+    );
+    $users->Limit(
+        ALIAS   => $attributes,
+        FIELD   => "ObjectType",
+        VALUE   => "RT::User",
+    );
+    $users->Limit(
+        ALIAS   => $attributes,
+        FIELD   => "Name",
+        VALUE   => RT::User::_PrefName( $pref_name ),
+    );
+
+    # Iterate all users (including disabled), with Quicksearch preferences set.
+    # Avoids running a query for every user in the system by only selecting
+    # those known to have preferences.
+    while (my $user = $users->Next) {
+        RT->Logger->debug(sprintf "User #%d has $pref_name preferences", $user->id);
+
+        my $config = $user->Preferences( $pref_name )
+            or next;
+        $user->SetPreferences( $pref_name, { Unwanted => $config } );
+        RT->Logger->debug(sprintf "Updated $pref_name preferences for user %s (#%d)", $user->Name, $user->id);
+    }
+});
+
+1;
\ No newline at end of file

-----------------------------------------------------------------------


More information about the Rt-commit mailing list