Skip to content

Commit

Permalink
Merge branch '5.0/chart-table-business-hours-css' into 5.0-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrandtbuffalo committed Nov 20, 2023
2 parents 892a190 + bc467db commit 65747b9
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/RT/Interface/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5150,7 +5150,7 @@ sub ProcessCustomDateRanges {
}
}

if ( $spec->{business_time} != $args_ref->{"$id-business_time"} ) {
if ( $spec->{business_time} ne $args_ref->{"$id-business_time"} ) {
$spec->{business_time} = $args_ref->{"$id-business_time"};
$updated ||= 1;
}
Expand Down
26 changes: 16 additions & 10 deletions lib/RT/Record.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2636,20 +2636,26 @@ sub CustomDateRange {
my $schedule;
my $timezone;

# Prefer the schedule/timezone specified in %ServiceAgreements for current object
if ( $self->isa('RT::Ticket') && !$self->QueueObj->SLADisabled && $self->SLA ) {
if ( my $config = RT->Config->Get('ServiceAgreements') ) {
if ( ref( $config->{QueueDefault}{ $self->QueueObj->Name } ) eq 'HASH' ) {
$timezone = $config->{QueueDefault}{ $self->QueueObj->Name }{Timezone};
}
if ( $date_range_spec{business_time} eq '1' ) {
# Prefer the schedule/timezone specified in %ServiceAgreements for current object
if ( $self->isa('RT::Ticket') && !$self->QueueObj->SLADisabled && $self->SLA ) {
if ( my $config = RT->Config->Get('ServiceAgreements') ) {
if ( ref( $config->{QueueDefault}{ $self->QueueObj->Name } ) eq 'HASH' ) {
$timezone = $config->{QueueDefault}{ $self->QueueObj->Name }{Timezone};
}

# Each SLA could have its own schedule and timezone
if ( my $agreement = $config->{Levels}{ $self->SLA } ) {
$schedule = $agreement->{BusinessHours};
$timezone ||= $agreement->{Timezone};
# Each SLA could have its own schedule and timezone
if ( my $agreement = $config->{Levels}{ $self->SLA } ) {
$schedule = $agreement->{BusinessHours};
$timezone ||= $agreement->{Timezone};
}
}
}
}
else {
$schedule = $date_range_spec{business_time};
}

$timezone ||= RT->Config->Get('Timezone');
$schedule ||= 'Default';

Expand Down
115 changes: 106 additions & 9 deletions lib/RT/Report/Tickets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,24 @@ our %GROUPINGS_META = (
Show => 1,
Sort => 'duration',
Distinct => 1,
Display => sub {
my $self = shift;
my %args = (@_);
my $value = $args{VALUE};
my $format = $args{FORMAT} || 'text';
if ( $format eq 'html' ) {
RT::Interface::Web::EscapeHTML(\$value);
my $css_class;
if ( my $style = $self->__Value('_css_class') ) {
$css_class = $style->{$args{NAME}};
};
return $value unless $css_class;
return qq{<span class="$css_class">$value</span>};
}
else {
return $value;
}
},
},
);

Expand Down Expand Up @@ -825,9 +843,17 @@ sub _DoSearch {
$tickets->FromSQL( $self->{_query} );
my @groups = grep { $_->{TYPE} eq 'grouping' } map { $self->ColumnInfo($_) } $self->ColumnsList;
my %info;

my %bh_class = map { $_ => 'business_hours_' . HTML::Mason::Commands::CSSClass( lc $_ ) }
keys %{ RT->Config->Get('ServiceBusinessHours') || {} };

while ( my $ticket = $tickets->Next ) {
my $bh = $ticket->SLA ? RT->Config->Get('ServiceAgreements')->{Levels}{ $ticket->SLA }{BusinessHours} : '';

my @keys;
my $max = 1;
my @extra_keys;
my %css_class;
for my $group ( @groups ) {
my $value;

Expand Down Expand Up @@ -922,6 +948,10 @@ sub _DoSearch {
);
}
}

if ( $business_time ) {
push @extra_keys, join ' => ', $group->{FIELD}, $bh_class{$bh} || 'business_hours_none';
}
}
else {
my %ranges = RT::Ticket->CustomDateRanges;
Expand All @@ -944,6 +974,11 @@ sub _DoSearch {
);
}
}
if ( ref $spec && $spec->{business_time} ) {
# 1 means the corresponding one in SLA, which $bh already holds
$bh = $spec->{business_time} unless $spec->{business_time} eq '1';
push @extra_keys, join ' => ', $group->{FIELD}, $bh_class{$bh} || 'business_hours_none';
}
}
}

Expand All @@ -955,6 +990,7 @@ sub _DoSearch {
}
push @keys, $value;
}
push @keys, @extra_keys;

# @keys could contain arrayrefs, so we need to expand it.
# e.g. "open", [ "root", "foo" ], "General" )
Expand Down Expand Up @@ -1039,7 +1075,7 @@ sub _DoSearch {
$value = $ticket->CustomDateRange(
'',
{ value => "$end - $start",
business_time => 1,
business_time => $extra_info->{business_time},
format => sub { return $_[0] },
}
);
Expand Down Expand Up @@ -1097,6 +1133,14 @@ sub _DoSearch {
}
}
my $item = $self->NewItem();

# Has extra css info
for my $key (@keys) {
if ( $key =~ /(.+) => (.+)/ ) {
$row->{_css_class}{$1} = $2;
}
}

$item->LoadFromHash($row);
$self->AddRecord($item);
}
Expand Down Expand Up @@ -1407,12 +1451,57 @@ sub DurationAsString {
my %args = @_;
my $v = $args{'VALUE'};
my $max_unit = $args{INFO} && ref $args{INFO}[-1] && $args{INFO}[-1]{business_time} ? 'hour' : 'year';
my $format = $args{FORMAT} || 'text';

my $css_class;
if ( $format eq 'html'
&& $self->can('__Value')
&& $args{INFO}
&& ref $args{INFO}[-1]
&& $args{INFO}[-1]{business_time} )
{

# 1 means business hours in SLA, its css is already generated and saved in _css_class.
if ( $args{INFO}[-1]{business_time} eq '1' ) {
my $style = $self->__Value('_css_class');
my $field;
if ( $args{INFO}[1] =~ /^CustomDateRange/ ) {
$field = $args{INFO}[-2];
}
elsif ( $args{INFO}[1] =~ /^DateTimeInterval/ ) {
$field = join ' to ', $args{INFO}[-3], $args{INFO}[-2];
}

$css_class = $style->{$field} if $style && $field;
}
else {
$css_class = 'business_hours_' . HTML::Mason::Commands::CSSClass( lc $args{INFO}[-1]{business_time} )
}
}

unless ( ref $v ) {
return $self->loc("(no value)") unless defined $v && length $v;
return RT::Date->new( $self->CurrentUser )->DurationAsString(
$v, Show => 3, Short => 1, MaxUnit => $max_unit,
);
my $value;
if ( defined $v && length $v ) {
$value = RT::Date->new( $self->CurrentUser )->DurationAsString(
$v,
Show => 3,
Short => 1,
MaxUnit => $max_unit,
);
}
else {
$value = $self->loc("(no value)");
}

if ( $format eq 'html' ) {
RT::Interface::Web::EscapeHTML(\$value);
return $value unless $css_class;
return qq{<span class="$css_class">$value</span>};
}
else {
return $value;
}

}

my $date = RT::Date->new( $self->CurrentUser );
Expand All @@ -1422,6 +1511,14 @@ sub DurationAsString {
if defined $e && length $e;
$e = $self->loc("(no value)") unless defined $e && length $e;
}

if ( $format eq 'html' ) {
for my $key ( keys %res ) {
RT::Interface::Web::EscapeHTML(\$res{$key});
next unless $css_class;
$res{$key} = qq{<span class="$css_class">$res{$key}</span>};
}
}
return \%res;
}

Expand Down Expand Up @@ -1522,7 +1619,7 @@ sub FormatTable {
$i = 0;
my $last;
while ( my $entry = $self->Next ) {
my $value = $entry->LabelValue( $column );
my $value = $entry->LabelValue( $column, 'html' );
if ( !$last || $last->{'value'} ne $value ) {
push @{ $body[ $i++ ]{'cells'} }, $last = { type => 'label', value => $value };
$last->{even} = $g++ % 2
Expand Down Expand Up @@ -1608,7 +1705,7 @@ sub FormatTable {

while ( my $entry = $self->Next ) {
my $query = $entry->Query;
my $value = $entry->LabelValue( $column ) || {};
my $value = $entry->LabelValue( $column, 'html' ) || {};
$value = { '' => $value } unless ref $value;
foreach my $e ( @subs ) {
push @{ $body[ $i ]{'cells'} }, {
Expand All @@ -1625,7 +1722,7 @@ sub FormatTable {
my $total_code = $self->LabelValueCode( $column );
foreach my $e ( @subs ) {
my $total = $total{ $e };
$total = $total_code->( $self, %$info, VALUE => $total )
$total = $total_code->( $self, %$info, VALUE => $total, FORMAT => 'html' )
if $total_code;
push @{ $footer[0]{'cells'} }, { type => 'value', value => $total };
}
Expand Down Expand Up @@ -1712,7 +1809,7 @@ sub _SetupCustomDateRanges {
my %extra_info;
my $spec = $ranges{$name};
if ( ref $spec && $spec->{business_time} ) {
$extra_info{business_time} = 1;
$extra_info{business_time} = $spec->{business_time};
}

push @new_groupings, $name => $extra_info{business_time} ? 'DurationInBusinessHours' : 'Duration';
Expand Down
4 changes: 2 additions & 2 deletions lib/RT/Report/Tickets/Entry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ and ensuring that dates are in local not DB timezones.
sub LabelValue {
my $self = shift;
my $name = shift;
my $format = shift || 'text';

my $raw = $self->RawValue( $name, @_ );

if ( my $code = $self->Report->LabelValueCode( $name ) ) {
$raw = $code->( $self, %{ $self->Report->ColumnInfo( $name ) }, VALUE => $raw );
$raw = $code->( $self, %{ $self->Report->ColumnInfo( $name ) }, VALUE => $raw, FORMAT => $format );
return $self->loc('(no value)') unless defined $raw && length $raw;
return $raw;
}
Expand Down
17 changes: 14 additions & 3 deletions share/html/Elements/EditCustomDateRanges
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<th class="collection-as-table"><&|/l&>From Value<br>if Unset</&></th>
<th class="collection-as-table"><&|/l&>To</&></th>
<th class="collection-as-table"><&|/l&>To Value<br>if Unset</&></th>
<th class="collection-as-table"><&|/l&>Business<br>Hours?</&></th>
<th class="collection-as-table"><&|/l&>Business<br>Hours</&></th>
<th class="collection-as-table text-left">
<div class="custom-control custom-checkbox">
<input type="checkbox" name="DeleteAll" value="1" id="custom-date-ranges-delete-all" class="checkbox custom-control-input" onclick="setCheckbox(this, /^\d+-Delete$/)" />
Expand All @@ -77,7 +77,10 @@
<td class="collection-as-table"><& /Elements/SelectCustomDateRangeField, Name => "$id-to_fallback", Default => $date_range_spec{to_fallback} &></td>
<td class="collection-as-table">
<select name="<% $id %>-business_time" class="form-control selectpicker">
<option value="1" <% $date_range_spec{business_time} ? 'selected="selected"' : '' |n%>><&|/l&>Yes</&></option>
<option value="1" <% ($date_range_spec{business_time} // '') eq 1 ? 'selected="selected"' : '' |n%>><&|/l&>SLA</&></option>
% for my $bh ( @bhs ) {
<option value="<% $bh %>" <% ($date_range_spec{business_time} // '') eq $bh ? 'selected="selected"' : '' |n%>><% loc($bh) %></option>
% }
<option value="0" <% $date_range_spec{business_time} ? '': 'selected="selected"' |n%>><&|/l&>No</&></option>
</select>
</td>
Expand All @@ -102,7 +105,10 @@
<td class="collection-as-table"><& /Elements/SelectCustomDateRangeField, Name => 'to_fallback' &></td>
<td class="collection-as-table">
<select name="business_time" class="form-control selectpicker">
<option value="1"><&|/l&>Yes</&></option>
<option value="1"><&|/l&>SLA</&></option>
% for my $bh ( @bhs ) {
<option value="<% $bh %>"><% loc($bh) %></option>
% }
<option value="0" selected="selected"><&|/l&>No</&></option>
</select>
</td>
Expand All @@ -112,6 +118,11 @@
</table>
</div>

<%INIT>
my @bhs = sort keys %{ RT->Config->Get('ServiceBusinessHours') || {} };

</%INIT>

<%ARGS>
%CustomDateRanges => ()
$ObjectType => 'RT::Ticket'
Expand Down
14 changes: 12 additions & 2 deletions share/html/Elements/ShowCustomDateRanges
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<th class="collection-as-table"><&|/l&>From Value<br>if Unset</&></th>
<th class="collection-as-table"><&|/l&>To</&></th>
<th class="collection-as-table"><&|/l&>To Value<br>if Unset</&></th>
<th class="collection-as-table"><&|/l&>Business<br>Hours?</&></th>
<th class="collection-as-table"><&|/l&>Business<br>Hours</&></th>
</tr>
% my $i = 0;
% for my $name ( sort keys %CustomDateRanges ) {
Expand All @@ -65,7 +65,17 @@
<td class="collection-as-table"><% $date_range_spec{from_fallback} || '' %></td>
<td class="collection-as-table"><% $date_range_spec{to} %></td>
<td class="collection-as-table"><% $date_range_spec{to_fallback} || '' %></td>
<td class="collection-as-table"><% $date_range_spec{business_time} ? loc('Yes') : loc('No') %></td>
<td class="collection-as-table">
% if ( $date_range_spec{business_time} ) {
% if ( $date_range_spec{business_time} eq '1' ) {
<% loc('SLA') %>
% } else {
<% $date_range_spec{business_time} %>
% }
% } else {
<% loc('No') %>
% }
</td>
</tr>
% }
</table>
Expand Down
4 changes: 2 additions & 2 deletions share/html/Search/Elements/ChartTable
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ foreach my $section (qw(thead tbody tfoot)) {
)
. '" target="_blank">'
);
$m->out( $eh->( $cell->{'value'} ) );
$m->out( $cell->{value} );
$m->out('</a>');
}
else {
$m->out( $eh->( $cell->{'value'} ) );
$m->out( $cell->{value} );
}
}
else {
Expand Down
Loading

0 comments on commit 65747b9

Please sign in to comment.