[Rt-commit] rt branch, 4.6/row-colors-by-condition, repushed
Craig Kaiser
craig at bestpractical.com
Wed Jan 2 12:59:03 EST 2019
The branch 4.6/row-colors-by-condition was deleted and repushed:
was 3c65d935f2045210fdcff3bcd369190a3864881e
now 5c5318fb5bfcb14f86224cd5a6daf8b60320716e
1: 81390e43fa = 1: 81390e43fa Create ReplaceAttachments, ReplaceHeader and ReplaceContent Methods
2: 5bec6babae = 2: 5bec6babae Create rt-munge-attachments executable
3: 765817052e = 3: 765817052e Add tests for methods that munge the attachments table
4: 3c65d935f2 ! 4: 5c5318fb5b Inital commit
@@ -1,6 +1,33 @@
Author: Craig Kaiser <craig at bestpractical.com>
Inital commit
+
+diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
+--- a/etc/RT_Config.pm.in
++++ b/etc/RT_Config.pm.in
+@@
+
+ =cut
+
++=head2 HighLightOnCondition
++
++Allow collections of RT objects to be highlighted a color based on conditions. This can be
++configured for any object and any attribute through the RT_SiteConfig.pm option "HighLightOnCondition",
++or color can be set per user based on ticket status under preferences.
++
++You can use "__CurrentUser__" under the Value key to have the attribute checked against the current user.
++Names of attributes should conincide with the method names for the object collection being targeted.
++
++ Set(@HighLightOnCondition,
++ { "Attribute" => "Status", "Value" => "open", "Color" => "green" },
++ { "Attribute" => "Owner", "Value" => "__CurrentUser__", "Color" => "red" }
++ );
++
++=cut
++
++Set(@HighLightOnCondition, undef );
++
+ 1;
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
--- a/lib/RT/Config.pm
@@ -9,7 +36,7 @@
ServiceAgreements => {
Type => 'HASH',
},
-+ HighlightRowColor => {
++ HighLightOnCondition => {
+ Section => 'User Color Preferences', #loc
+ Overridable => 1,
+ Widget => '/Widgets/Form/Criteria',
@@ -20,6 +47,14 @@
);
my %OPTIONS = ();
my @LOADED_CONFIGS = ();
+@@
+ }
+ $res = $OPTIONS{$name} unless defined $res;
+ $res = $META{$name}->{'Default'} unless defined $res;
++
+ return $self->_ReturnValue( $res, $META{$name}->{'Type'} || 'SCALAR' );
+ }
+
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
--- a/lib/RT/Record.pm
@@ -41,19 +76,23 @@
+ my ($ret, $msg) = $user->Load($self->CurrentUser);
+ RT::Logger->error($msg) unless $ret;
+
-+ my $preferences = $user->Preferences($RT::System);
-+
+ my @classes;
-+
-+ my %color_config = $preferences->{'HighlightRowColor'} ? %{$preferences->{'HighlightRowColor'}} : ();
-+
-+ foreach my $condition (keys %color_config) {
-+ my ($attr, $value) = $condition =~ /(.*)-(.*)/;
++ my $color_config = RT::Config->Get('HighLightOnCondition', $user);
++
++ foreach my $condition (@{$color_config}) {
++ my ($attr, $value) = ( $condition->{Attribute}, $condition->{Value} );
+ if ( !$self->_CoreAccessible->{$attr} ) {
+ next;
+ } else {
-+ if ( $self->$attr eq $value ) {
-+ push @classes, "row-bg-color-". $color_config{$condition}->{color};
++ if ( $attr eq 'Queue' ) {
++ my $queue = RT::Queue->new($self->CurrentUser);
++ $queue->Load($value);
++ push @classes, "row-bg-color-". $condition->{Color} if $self->QueueObj->Name eq $queue->Name;
++ } elsif ( $value eq '__CurrentUser__' ) {
++ push @classes, "row-bg-color-". $condition->{Color} if $self->$attr eq $self->CurrentUser->Id;
++ }
++ elsif ( $self->$attr eq $value ) {
++ push @classes, "row-bg-color-". $condition->{Color};
+ }
+ }
+ }
@@ -207,18 +246,18 @@
+% my $i = 0;
+% foreach my $color (@colors) {
+ <div>
-+ <select name="Color-Arguement-<%$i%>" class="cascade-by-optgroup">
++ <select name="Color-Arguement" class="cascade-by-optgroup">
+ <optgroup label="Status">
-+% if ( $defaults{$i}->{attribute} ) {
-+ <option selected="selected" value="<% $defaults{$i}->{attribute} %>"><% $defaults{$i}->{value} %></option>
++% if ( $ARGS{'CurrentValue'}->[$i]->{Attribute} ) {
++ <option selected="selected" value="<% $ARGS{'CurrentValue'}->[$i]->{Attribute} %>"><% $ARGS{'CurrentValue'}->[$i]->{Value} %></option>
+% }
-+ <option value=""<% !$defaults{$i}->{value} && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
++ <option value=""<% !$ARGS{'CurrentValue'}->[$i]->{Value} && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
+% foreach my $status (@statuses) {
+ <option value="<% $status %>"><% $status %></option>
+% }
+ </optgroup>
+ </select>
-+ <& /Elements/SelectColor, Name => "Color-$i", Default => $defaults{$i}->{color} &>
++ <& /Elements/SelectColor, Name => "Color", Default => $ARGS{'CurrentValue'}->[$i]->{Color} &>
+ </div>
+% $i++;
+% }
@@ -245,22 +284,6 @@
+ my @temp_statuses = $lifecycle->Valid;
+ push @statuses, @temp_statuses;
+}
-+
-+my %defaults;
-+foreach my $key (keys %{$ARGS{'CurrentValue'}}) {
-+ if ( $ARGS{'CurrentValue'}{$key}{'attribute'} eq 'Queue' ) {
-+ my $queueObj = RT::Queue->new($session{CurrentUser});
-+ $queueObj->Load($ARGS{'CurrentValue'}{$key}{'value'});
-+
-+ $ARGS{'CurrentValue'}{$key}{'attribute'} = $queueObj->Name;
-+ }
-+
-+ $defaults{$ARGS{'CurrentValue'}{$key}{'input_id'}} = {
-+ value => $ARGS{'CurrentValue'}{$key}{'value'},
-+ color => $ARGS{'CurrentValue'}{$key}{'color'},
-+ attribute => $ARGS{'CurrentValue'}{$key}{'attribute'}
-+ };
-+}
+</%INIT>
+
+<%METHOD Process>
@@ -268,28 +291,19 @@
+</%ARGS>
+<%INIT>
+my %args = %{$ARGS{Arguments}};
-+my @color_arguements = grep /Color-Arguement-(\d*[^\'"'])/, keys %args;
-+
-+my %config;
-+foreach my $color_arg (@color_arguements) {
-+ next unless $args{$color_arg};
-+
-+ $color_arg =~ /Color-Arguement-(\d*[^\"])(?-)/;
-+
-+ my $value = $args{"Color-Arguement-$1"};
-+ my $attribute = $args{"Color-Arguement-$1-Groups"};
++
++my @HighLightOnCondition;
++my $i = 0;
++foreach my $color_argument ($args{'Color-Arguement'}) {
++ my $value = $color_argument;
++ my $attribute = $args{'Color-Arguement-Groups'}[$i];
++ my $color = $args{'Color'}[$i];
+
+ next unless $value and $attribute;
-+
-+ $config{$attribute . '-' . $value} = {
-+ color => $args{'Color-'.$1},
-+ input_id => $1,
-+ value => $value,
-+ attribute => $attribute,
-+ };
-+}
-+
-+return \%config;
++ push @HighLightOnCondition, { Attribute => $attribute, Value => $value, Color => $color };
++}
++
++return scalar @HighLightOnCondition ? \@HighLightOnCondition : undef;
+</%INIT>
+</%METHOD>
More information about the rt-commit
mailing list