[Rt-commit] rt branch, 4.2/more-info-in-admin-templates-ui, created. rt-4.0.2-157-g0c58e8d

Ruslan Zakirov ruz at bestpractical.com
Tue Nov 29 10:49:46 EST 2011


The branch, 4.2/more-info-in-admin-templates-ui has been created
        at  0c58e8db3e718a98f5c2447ef09dd9630a2e4dfd (commit)

- Log -----------------------------------------------------------------
commit 368725f38f91107a8c11f86f0260bd644b626c4c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 29 19:44:12 2011 +0400

    IsEmpty column map for templates

diff --git a/share/html/Elements/RT__Template/ColumnMap b/share/html/Elements/RT__Template/ColumnMap
index d9d55cf..b983d31 100644
--- a/share/html/Elements/RT__Template/ColumnMap
+++ b/share/html/Elements/RT__Template/ColumnMap
@@ -78,6 +78,10 @@ my $COLUMN_MAP = {
         title     => 'Queue', # loc
         value     => sub { $_[0]->Queue },
     },
+    IsEmpty => {
+        title     => 'Empty', # loc
+        value     => sub { $_[0]->IsEmpty? $_[0]->loc('Yes') : $_[0]->loc('No') },
+    },
 };
 
 </%ONCE>

commit 22b49aeb862541398dbfbab13046e3f758b4a2cb
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 29 19:47:40 2011 +0400

    UsedBy method and column map for Templates

diff --git a/lib/RT/Condition/CustomFieldChange.pm b/lib/RT/Condition/CustomFieldChange.pm
new file mode 100644
index 0000000..9868654
--- /dev/null
+++ b/lib/RT/Condition/CustomFieldChange.pm
@@ -0,0 +1,39 @@
+use strict;
+use warnings;
+
+package RT::Condition::CustomFieldChange;
+use base 'RT::Condition';
+
+sub IsApplicable {
+    my $self = shift;
+
+    my $cf_name = $self->Argument
+        or die "Argument of the condition must be name of a CF";
+
+    my $txn = $self->TransactionObj;
+    my $type = $txn->Type;
+    if ( $type eq 'Create' ) {
+        my $v = $self->TicketObj->FirstCustomFieldValue( $cf_name );
+        return 1 if defined $v && length $v;
+    }
+    elsif ( $type eq 'CustomField' ) {
+        my $cf = RT::CustomField->new( $self->CurrentUser );
+        $cf->Load( $txn->Field );
+        return 0 unless $cf->id;
+        return 1 if lc $cf->Name eq lc $cf_name;
+    }
+    return 0;
+}
+
+sub Argument {
+    my $self = shift;
+    my $arg = $self->SUPER::Argument;
+    unless ( defined $arg && length $arg ) {
+        $RT::Logger->error("Argument must be defined");
+        return undef;
+    }
+    if ( $arg =~ /Change,Add,Delete,Create/ ) {
+    }
+}
+
+1;
diff --git a/lib/RT/CustomFieldValues/Test.pm b/lib/RT/CustomFieldValues/Test.pm
new file mode 100644
index 0000000..50c08d5
--- /dev/null
+++ b/lib/RT/CustomFieldValues/Test.pm
@@ -0,0 +1,30 @@
+package RT::CustomFieldValues::Test;
+
+use strict;
+use warnings;
+
+use base qw(RT::CustomFieldValues::External);
+
+sub SourceDescription {
+    return 'RT test category';
+}
+
+sub ExternalValues {
+    my $self = shift;
+
+    my $i = 0;
+
+    my @res;
+    push @res, { name => 'v1', description => 'd1', category => 'c1', sortorder=> $i++ };
+    push @res, { name => 'v3', description => 'd3', category => 'c1', sortorder=> $i++ };
+    push @res, { name => 'v5', description => 'd2', category => 'c1', sortorder=> $i++ };
+    push @res, { name => 'v2', description => 'd2', category => 'c2', sortorder=> $i++ };
+    push @res, { name => 'v4', description => 'd1', category => 'c2', sortorder=> $i++ };
+    push @res, { name => 'v6', description => 'd3', category => 'c2', sortorder=> $i++ };
+    return \@res;
+}
+
+RT::Base->_ImportOverlays();
+
+1;
+
diff --git a/lib/RT/Template.pm b/lib/RT/Template.pm
index 6f0251d..34fe671 100644
--- a/lib/RT/Template.pm
+++ b/lib/RT/Template.pm
@@ -260,6 +260,50 @@ sub Delete {
     return ( $self->SUPER::Delete(@_) );
 }
 
+=head2 UsedBy
+
+Returns L<RT::Scrips> limitted to scrips that use this template. Takes
+into account that template can be overriden in a queue.
+
+=cut
+
+sub UsedBy {
+    my $self = shift;
+
+    my $scrips = RT::Scrips->new( $self->CurrentUser );
+
+    if ( $self->Queue ) {
+        my $global = RT::Template->new( $self->CurrentUser );
+        $global->LoadGlobalTemplate( $self->Name );
+        $scrips->Limit( FIELD => 'Template', VALUE => $self->id );
+        $scrips->Limit( FIELD => 'Template', VALUE => $global->id ) if $global->id;
+        $scrips->Limit( FIELD => 'Queue',    VALUE => $self->Queue );
+        $scrips->Limit( FIELD => 'Queue',    VALUE => 0 );
+    }
+    else {
+        $scrips->Limit( FIELD => 'Template', VALUE => $self->id );
+        my $alias = $scrips->Join(
+            TYPE => 'LEFT',
+            FIELD1 => 'Queue',
+            TABLE2 => 'Templates',
+            FIELD2 => 'Queue',
+        );
+        $scrips->Limit( LEFTJOIN => $alias, FIELD => 'Name', VALUE => $self->Name );
+        $scrips->Limit( LEFTJOIN => $alias, FIELD => 'Queue', OPERATOR => '!=', VALUE => 0 );
+        $scrips->_OpenParen('UsedBy');
+        $scrips->Limit( SUBCLAUSE => 'UsedBy', FIELD => 'Queue', VALUE => 0 );
+        $scrips->Limit(
+            SUBCLAUSE => 'UsedBy',
+            ALIAS => $alias,
+            FIELD => 'id',
+            OPERATOR => 'IS',
+            VALUE => 'NULL',
+        );
+        $scrips->_CloseParen('UsedBy');
+    }
+    return $scrips;
+}
+
 =head2 IsEmpty
 
 Returns true value if content of the template is empty, otherwise
diff --git a/share/html/Elements/RT__Template/ColumnMap b/share/html/Elements/RT__Template/ColumnMap
index b983d31..f41b71f 100644
--- a/share/html/Elements/RT__Template/ColumnMap
+++ b/share/html/Elements/RT__Template/ColumnMap
@@ -82,6 +82,21 @@ my $COLUMN_MAP = {
         title     => 'Empty', # loc
         value     => sub { $_[0]->IsEmpty? $_[0]->loc('Yes') : $_[0]->loc('No') },
     },
+    UsedBy => {
+        title     => 'Used by scrips', # loc
+        value     => sub {
+            my @res;
+            my $scrips = $_[0]->UsedBy;
+            while ( my $scrip = $scrips->Next ) {
+                push @res, ', ' if @res;
+                push @res, \'<a href="', RT->Config->Get('WebPath'), '/Admin';
+                push @res, $scrip->Queue? '/Queues': '/Global';
+                push @res, '/Scrip.html?Queue='. ($scrip->Queue ||0) .'&id='. $scrip->id;
+                push @res, \'" title="', $scrip->Description, \'">', $scrip->id, \'</a>';
+            }
+            return @res;
+        },
+    },
 };
 
 </%ONCE>

commit 0c58e8db3e718a98f5c2447ef09dd9630a2e4dfd
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 29 19:48:09 2011 +0400

    show UsedBy and IsEmpty columns in templates AdminUI

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 466b7d6..ed672d4 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2444,7 +2444,7 @@ Set(%AdminSearchResultFormat,
     Templates =>
         q{'<a href="__WebPath__/__WebRequestPathDir__/Template.html?Queue=__QueueId__&Template=__id__">__id__</a>/TITLE:#'}
         .q{,'<a href="__WebPath__/__WebRequestPathDir__/Template.html?Queue=__QueueId__&Template=__id__">__Name__</a>/TITLE:Name'}
-        .q{,'__Description__'},
+        .q{,'__Description__','__UsedBy__','__IsEmpty__'},
     Classes =>
         q{ '<a href="__WebPath__/Admin/Articles/Classes/Modify.html?id=__id__">__id__</a>/TITLE:#'}
         .q{,'<a href="__WebPath__/Admin/Articles/Classes/Modify.html?id=__id__">__Name__</a>/TITLE:Name'}

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


More information about the Rt-commit mailing list