Skip to content

Commit

Permalink
Merge branch 'issue-#2313-dynamicfieldsets' into issue-#2251-multival…
Browse files Browse the repository at this point in the history
…ue-multirow
  • Loading branch information
Sven committed Jun 1, 2023
2 parents e6a0dd5 + 5b3c075 commit 5dc8112
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 117 deletions.
50 changes: 25 additions & 25 deletions Kernel/System/DynamicField/Driver/BaseSelect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,16 @@ sub DisplayValueRender {
# activate HTMLOutput when it wasn't specified
my $HTMLOutput = $Param{HTMLOutput} // 1;

my $Value = '';
my @Values;
# get raw Value strings from field value
my @Values = !ref $Param{Value} ? ( $Param{Value} )
: scalar $Param{Value}->@* ? $Param{Value}->@*
: ( '' );

if ( ref $Param{Value} eq 'ARRAY' ) {
@Values = @{ $Param{Value} };
}
else {
@Values = ( $Param{Value} );
}
$Param{ValueMaxChars} ||= '';

my @ReadableValues;
my @ReadableTitles;
for my $ValueItem (@Values) {

$ValueItem //= '';

# get real value
Expand All @@ -553,48 +550,51 @@ sub DisplayValueRender {
$ValueItem = $Param{LayoutObject}->{LanguageObject}->Translate($ValueItem);
}

# set title as value after update and before limit
push @ReadableTitles, $ValueItem;

# HTML Output transformation
if ($HTMLOutput) {
$Value = $Param{LayoutObject}->Ascii2Html(
Text => $Value,
Max => $Param{ValueMaxChars} || '',
$ValueItem = $Param{LayoutObject}->Ascii2Html(
Text => $ValueItem,
Max => $Param{ValueMaxChars},
);
}
else {
if ( $Param{ValueMaxChars} && length($ValueItem) > $Param{ValueMaxChars} ) {
$ValueItem = substr( $ValueItem, 0, $Param{ValueMaxChars} ) . '...';
}
}

push @ReadableValues, $ValueItem;
}

# set new line separator
my $ItemSeparator = $HTMLOutput ? '<br>' : '\n';

$Value = join $ItemSeparator, @ReadableValues;

# set title as value after update and before limit
my $Title = $Value;
my $ValueSeparator;
my $Title = join( ', ', @ReadableTitles );

# HTMLOutput transformations
if ($HTMLOutput) {
$Title = $Param{LayoutObject}->Ascii2Html(
Text => $Title,
Max => $Param{TitleMaxChars} || '',
);
$ValueSeparator = '<br/>';
}
else {
if ( $Param{ValueMaxChars} && length($Value) > $Param{ValueMaxChars} ) {
$Value = substr( $Value, 0, $Param{ValueMaxChars} ) . '...';
}
if ( $Param{TitleMaxChars} && length($Title) > $Param{TitleMaxChars} ) {
$Title = substr( $Title, 0, $Param{TitleMaxChars} ) . '...';
}
$ValueSeparator = "\n";
}

# set field link from config
my $Link = $Param{DynamicFieldConfig}->{Config}->{Link} || '';
my $LinkPreview = $Param{DynamicFieldConfig}->{Config}->{LinkPreview} || '';

# return a data structure
return {
Value => $Value,
Title => $Title,
Value => '' . join( $ValueSeparator, @ReadableValues ),
Title => '' . $Title,
Link => $Link,
LinkPreview => $LinkPreview,
};
Expand Down
115 changes: 36 additions & 79 deletions Kernel/System/DynamicField/Driver/BaseText.pm
Original file line number Diff line number Diff line change
Expand Up @@ -536,104 +536,61 @@ sub DisplayValueRender {
# activate HTMLOutput when it wasn't specified
my $HTMLOutput = $Param{HTMLOutput} // 1;

my $ValueMaxChars = $Param{ValueMaxChars} || '';
my $TitleMaxChars = $Param{TitleMaxChars} || '';
# get raw Value strings from field value
my @Values = !ref $Param{Value} ? ( $Param{Value} )
: scalar $Param{Value}->@* ? $Param{Value}->@*
: ( '' );

# check value
my @Values;
if ( ref $Param{Value} eq 'ARRAY' ) {
@Values = @{ $Param{Value} };
}
else {
@Values = ( $Param{Value} );
}
$Param{ValueMaxChars} ||= '';

my @ReadableValues;
my @ReadableTitles;
for my $ValueItem (@Values) {
$ValueItem //= '';

my $ShowValueEllipsis;
my $ShowTitleEllipsis;

VALUEITEM:
for my $Item (@Values) {
$Item //= '';
# set title as value after update and before limit
push @ReadableTitles, $ValueItem;

my $ReadableValue = $Item;

my $ReadableLength = length $ReadableValue;

# set title equal value
my $ReadableTitle = $ReadableValue;

# cut strings if needed
if ( $ValueMaxChars ne '' ) {

if ( length $ReadableValue > $ValueMaxChars ) {
$ShowValueEllipsis = 1;
}
$ReadableValue = substr $ReadableValue, 0, $ValueMaxChars;

# decrease the max parameter
$ValueMaxChars = $ValueMaxChars - $ReadableLength;
if ( $ValueMaxChars < 0 ) {
$ValueMaxChars = 0;
}
# HTML Output transformation
if ( $HTMLOutput ) {
$ValueItem = $Param{LayoutObject}->Ascii2Html(
Text => $ValueItem,
Max => $Param{ValueMaxChars},
);
}

if ( $TitleMaxChars ne '' ) {

if ( length $ReadableTitle > $ValueMaxChars ) {
$ShowTitleEllipsis = 1;
}
$ReadableTitle = substr $ReadableTitle, 0, $TitleMaxChars;

# decrease the max parameter
$TitleMaxChars = $TitleMaxChars - $ReadableLength;
if ( $TitleMaxChars < 0 ) {
$TitleMaxChars = 0;
else {
if ( $Param{ValueMaxChars} && length($ValueItem) > $Param{ValueMaxChars} ) {
$ValueItem = substr( $ValueItem, 0, $Param{ValueMaxChars} ) . '...';
}
}

# HTMLOutput transformations
if ($HTMLOutput) {

$ReadableValue = $Param{LayoutObject}->Ascii2Html(
Text => $ReadableValue,
);

$ReadableTitle = $Param{LayoutObject}->Ascii2Html(
Text => $ReadableTitle,
);
}

push @ReadableValues, $ReadableValue;

if ( length $ReadableTitle ) {
push @ReadableTitles, $ReadableTitle;
}
push @ReadableValues, $ValueItem;
}

# set new line separator
my $ItemSeparator = $HTMLOutput ? '<br>' : '\n';

my $Value = join $ItemSeparator, @ReadableValues;
my $Title = join $ItemSeparator, @ReadableTitles;

if ($ShowValueEllipsis) {
$Value .= '...';
my $ValueSeparator;
my $Title = join( ', ', @ReadableTitles );
if ( $HTMLOutput ) {
$Title = $Param{LayoutObject}->Ascii2Html(
Text => $Title,
Max => $Param{TitleMaxChars} || '',
);
$ValueSeparator = '<br/>';
}
if ($ShowTitleEllipsis) {
$Title .= '...';
else {
if ( $Param{TitleMaxChars} && length($Title) > $Param{TitleMaxChars} ) {
$Title = substr( $Title, 0, $Param{TitleMaxChars} ) . '...';
}
$ValueSeparator = "\n";
}

# set field link form config
# set field link from config
my $Link = $Param{DynamicFieldConfig}->{Config}->{Link} || '';
my $LinkPreview = $Param{DynamicFieldConfig}->{Config}->{LinkPreview} || '';

# return a data structure
return {
Value => $Value,
Title => $Title,
Value => '' . join( $ValueSeparator, @ReadableValues ),
Title => '' . $Title,
Link => $Link,
LinkPreview => $LinkPreview,
};
Expand Down
57 changes: 44 additions & 13 deletions Kernel/System/DynamicField/Driver/Set.pm
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ sub EditFieldValueGet {
return if !@DataAll;

# get the highest multivalue index (second to last; last is the empty template)
my $IndexMax = $Param{DynamicFieldConfig}{Config}{MultiValue} ? $DataAll[-2] : 0;
my $IndexMax = $Param{DynamicFieldConfig}{Config}{MultiValue} ? $DataAll[-2] // 0 : 0;

for my $i ( 0 .. $#{ $Param{DynamicFieldConfig}{Config}{Include} } ) {
my $DynamicField = $DynamicFieldObject->DynamicFieldGet(
Expand Down Expand Up @@ -424,7 +424,7 @@ sub EditFieldValueValidate {
);

# get the highest multivalue index (second to last; last is the empty template)
$IndexMax = $DataAll[-2];
$IndexMax = $DataAll[-2] // 0;
}

my $Result;
Expand Down Expand Up @@ -462,14 +462,16 @@ sub EditFieldValueValidate {
sub DisplayValueRender {
my ( $Self, %Param ) = @_;

# check for Null value
if ( !defined $Param{Value} ) {
if ( !$Param{Value} ) {
return {
Value => '',
Title => '',
};
}

# activate HTMLOutput when it wasn't specified
my $HTMLOutput = $Param{HTMLOutput} // 1;

my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
my $BackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');

Expand All @@ -492,6 +494,19 @@ sub DisplayValueRender {
return;
}

my $Label;
if ( $HTMLOutput ) {
$Label = $Param{LayoutObject}->Output(
Template => '[% Translate( Data.Label ) | html %]',
Data => {
Label => $DynamicField->{Label},
},
);
}
else {
$Label = $Param{LayoutObject}->{LanguageObject}->Translate( $DynamicField->{Label} );
}

VALUE:
for my $SetIndex ( 0 .. $#{ $Param{Value} } ) {
next VALUE if !defined $Param{Value}[$SetIndex][$i];
Expand All @@ -504,19 +519,35 @@ sub DisplayValueRender {

next VALUE if !defined $Element->{Value} || $Element->{Value} eq '';

# TODO: check Value vs Title (seems same for most DF), add Links (maybe use tt)
$SetValue{Value}[$SetIndex] .= "$DynamicField->{Label}: $Element->{Value}<br>";
$SetValue{Title}[$SetIndex] .= "$DynamicField->{Label}: $Element->{Title}<br>";
if ( $HTMLOutput ) {
$SetValue{Value}[$SetIndex] .= "<label>$Label</label><p class='Value'><span title='$Element->{Title}'>$Element->{Value}</span></p>";
}
else {
$SetValue{Value}[$SetIndex] .= "$Label: $Element->{Value}\n";
$SetValue{Title}[$SetIndex] .= "$Label: $Element->{Title}\n";
}
}
}

# return a data structure
my %Value;
for my $Return (qw/Value Title/) {
@{ $SetValue{$Return} } = map { $_ // '' } $SetValue{$Return}->@*;
if ( !scalar $SetValue{Value}->@* ) {
return {
Value => '',
Title => '',
};
}

$Value{$Return} = join( '<hr/>', $SetValue{$Return}->@* );
$Value{$Return} = $Value{$Return} ? "<div class='SetDisplayValue'>$Value{$Return}</div>" : '';
@{ $SetValue{Value} } = map { $_ // '' } $SetValue{Value}->@*;

my %Value;
if ( $HTMLOutput ) {
$Value{Value} = '<div class="SetDisplayValue">'
. join( '</div><div class="SetDisplayValue">', $SetValue{Value}->@* )
. '</div>';
$Value{Title} = '';
}
else {
$Value{Value} = join( "\n", $SetValue{Value}->@* );
$Value{Title} = join( "; ", $SetValue{Title}->@* );
}

return \%Value;
Expand Down
Loading

0 comments on commit 5dc8112

Please sign in to comment.