Skip to content

Commit

Permalink
Issue #2987: Made DF Lens set capable.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaerter committed Feb 19, 2024
1 parent 44350e2 commit 4a9b82d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
79 changes: 74 additions & 5 deletions Kernel/System/DynamicField/Driver/Lens.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ sub new {
'IsCustomerInterfaceCapable' => 0,
'IsHiddenInTicketInformation' => 0,
'SetsDynamicContent' => 1,
'IsSetCapable' => 1,
};

return $Self;
Expand All @@ -93,10 +94,12 @@ sub ValueGet {

my $LensDFConfig = $Param{DynamicFieldConfig};

# in set case, an arrayref of object ids is returned
my $ReferencedObjectID = $Self->_GetReferencedObjectID(
ObjectID => $Param{ObjectID},
LensDynamicFieldConfig => $LensDFConfig,
EditFieldValue => $Param{UseReferenceEditField},
Set => $Param{Set},
);

return unless $ReferencedObjectID;
Expand All @@ -105,6 +108,19 @@ sub ValueGet {
LensDynamicFieldConfig => $LensDFConfig,
);

# in set case, values need to be collected one by one
if ( $Param{Set} ) {
my @Values;
for my $RefID ( $ReferencedObjectID->@* ) {
push @Values, $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueGet(
DynamicFieldConfig => $AttributeDFConfig,
ObjectID => $RefID,
Set => 1,
);
}
return \@Values;
}

return $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueGet(
DynamicFieldConfig => $AttributeDFConfig,
ObjectID => $ReferencedObjectID,
Expand All @@ -116,6 +132,39 @@ sub ValueSet {

my $LensDFConfig = $Param{DynamicFieldConfig};

my $AttributeDFConfig = $Self->_GetAttributeDFConfig(
LensDynamicFieldConfig => $LensDFConfig,
);

# in set case, we iterate over the values and set them one by one
if ( $Param{Set} ) {
for my $SetIndex ( 0 .. $#{ $Param{Value} } ) {

# with param SetIndex, a single obect id is returned
# as we are already saving we trust, that the reference edit field has been validated
my $ReferencedObjectID = $Self->_GetReferencedObjectID(
ObjectID => $Param{ObjectID},
LensDynamicFieldConfig => $LensDFConfig,
EditFieldValue => $Param{EditFieldValue} // 1,
SetIndex => $SetIndex,
);

return unless $ReferencedObjectID;

my $Success = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueSet(
%Param,
Value => $Param{Value}[$SetIndex],
ConfigItemHandled => 0,
EditFieldValue => 0,
Set => 0,
DynamicFieldConfig => $AttributeDFConfig,
ObjectID => $ReferencedObjectID,
);
return unless $Success;
}
return 1;
}

# as we are already saving we trust, that the reference edit field has been validated
my $ReferencedObjectID = $Self->_GetReferencedObjectID(
ObjectID => $Param{ObjectID},
Expand All @@ -125,10 +174,6 @@ sub ValueSet {

return unless $ReferencedObjectID;

my $AttributeDFConfig = $Self->_GetAttributeDFConfig(
LensDynamicFieldConfig => $LensDFConfig,
);

return $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueSet(
%Param,
ConfigItemHandled => 0,
Expand Down Expand Up @@ -788,23 +833,47 @@ sub _GetReferencedObjectID {

if ( $Param{EditFieldValue} ) {

# fetching a single object id for a specified set index
if ( exists $Param{SetIndex} ) {
my $ObjectID = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->EditFieldValueGet(
DynamicFieldConfig => {
$ReferenceDFConfig->%*,
Name => $ReferenceDFConfig->{Name} . '_' . $Param{SetIndex},
},
ParamObject => $Kernel::OM->Get('Kernel::System::Web::Request'),
TransformDates => 0,
ForLens => 1,
Set => 0,
);

return $ObjectID->[0] if ref $ObjectID;
return $ObjectID;
}

my $ObjectID = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->EditFieldValueGet(
DynamicFieldConfig => $ReferenceDFConfig,
ParamObject => $Kernel::OM->Get('Kernel::System::Web::Request'),
TransformDates => 0,
ForLens => 1,
Set => $Param{Set},
);

return $ObjectID->[0] if ref $ObjectID;
return $ObjectID;
}

my $ObjectID = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueGet(
DynamicFieldConfig => $ReferenceDFConfig,
ObjectID => $Param{ObjectID},
ForLens => 1,
Set => $Param{Set},
);

# in set case, we need to map the returned array of arrays into an array of first values as multivalue lenses are not supported at the moment
if ( $Param{Set} ) {
my @ObjectIDs = map { $_->[0] } $ObjectID->@*;
return \@ObjectIDs;
}

return $ObjectID->[0] if ref $ObjectID;
return $ObjectID;
}
Expand Down
4 changes: 2 additions & 2 deletions var/httpd/htdocs/js/Core.UI.InputFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -2935,7 +2935,7 @@ Core.UI.InputFields = (function (TargetNS) {
// change the hidden SetIndex
$Cell.children('.Field').children('input[name^=SetIndex]').first().val(To);

$('[id^=DynamicField_], [id^=DynamicFieldDBDetailedSearch_]', $Cell).each( function() {
$('[id^=DynamicField_], [id^=DynamicFieldDBDetailedSearch_], [id^=Autocomplete_DynamicField_]', $Cell).each( function() {
['name'].forEach( Attribute => {
var Attr = $(this).attr(Attribute);
if ( Attr && Attr.match( ReplaceRegEx ) ) {
Expand All @@ -2947,7 +2947,7 @@ Core.UI.InputFields = (function (TargetNS) {
// for attributes which can also contain multivalue data, we have to target the second to last index if two are present
ReplaceRegEx = new RegExp( '(DynamicField_[\\w\\d_-]+?_)' + From + '((_\d+)?(Data|Container)?)', 'g' );

$('[id^=DynamicField_], [id^=DynamicFieldDBDetailedSearch_]', $Cell).each( function() {
$('[id^=DynamicField_], [id^=DynamicFieldDBDetailedSearch_], [id^=Autocomplete_DynamicField_]', $Cell).each( function() {
['id', 'field'].forEach( Attribute => {
var Attr = $(this).attr(Attribute);
if ( Attr && Attr.match( ReplaceRegEx ) ) {
Expand Down

0 comments on commit 4a9b82d

Please sign in to comment.