Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3186: Enable Lens DF to use Reference DF as attribute field #3187

Open
wants to merge 9 commits into
base: rel-11_0
Choose a base branch
from
42 changes: 14 additions & 28 deletions Kernel/Modules/AdminDynamicFieldLens.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,23 @@ sub new {

# field types which are usable as attribute df
$Self->{IsAttributeFieldCapable} = {

# see https://github.com/RotherOSS/issues/3186
Agent => 0,
Agent => 1,
Checkbox => 1,

# see https://github.com/RotherOSS/otobo/issues/3809
ContactWD => 0,

# see https://github.com/RotherOSS/issues/3186
CustomerCompany => 0,

# see https://github.com/RotherOSS/issues/3186
CustomerUser => 0,
ContactWD => 0,
CustomerCompany => 1,
CustomerUser => 1,

# see https://github.com/RotherOSS/otobo/issues/3793
Database => 0,
Date => 1,
DateTime => 1,
Dropdown => 1,

# see https://github.com/RotherOSS/issues/3186
FAQ => 0,
GeneralCatalog => 1,

# see https://github.com/RotherOSS/issues/3186
ITSMConfigItem => 0,

# see https://github.com/RotherOSS/issues/3186
ITSMConfigItemVersion => 0,
Database => 0,
Date => 1,
DateTime => 1,
Dropdown => 1,
FAQ => 1,
GeneralCatalog => 1,
ITSMConfigItem => 1,
ITSMConfigItemVersion => 1,

# see https://github.com/RotherOSS/otobo/issues/3789
Lens => 0,
Expand All @@ -86,10 +74,8 @@ sub new {
Set => 1,
Text => 1,
TextArea => 1,

# see https://github.com/RotherOSS/issues/3186
Ticket => 0,
Title => 1,
Ticket => 1,
Title => 1,

# see https://github.com/RotherOSS/otobo/issues/3446
WebService => 0,
Expand Down
59 changes: 48 additions & 11 deletions Kernel/Modules/AgentReferenceSearch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,63 @@ sub Run {

# Get config for the dynamic field and check the sanity.
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
my $DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet(
my $InitialDynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet(
Name => $FieldName,
);
if (
!IsHashRefWithData($DynamicFieldConfig)
||
!$DynamicFieldBackendObject->HasBehavior(
DynamicFieldConfig => $DynamicFieldConfig,
Behavior => 'IsReferenceField',
)
)
{
if ( !IsHashRefWithData($InitialDynamicFieldConfig) ) {
return $LayoutObject->JSONReply(
Data => {
Success => 0,
Messsage => qq{Error reading the dynamic field '$FieldName'!},
}
},
);
}

# Check if we deal with a reference field
my $IsReferenceField = $DynamicFieldBackendObject->HasBehavior(
DynamicFieldConfig => $InitialDynamicFieldConfig,
Behavior => 'IsReferenceField',
);

my $DynamicFieldConfig;
if ( !$IsReferenceField ) {

# Check if we deal with a lens field with a reference attribute field
if ( $InitialDynamicFieldConfig->{FieldType} eq 'Lens' ) {

# TODO perhaps better use 'AttributeDFConfigGet'
$DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet(
ID => $InitialDynamicFieldConfig->{Config}{AttributeDF},
);
if ( !IsHashRefWithData($InitialDynamicFieldConfig) ) {
return $LayoutObject->JSONReply(
Data => {
Success => 0,
Messsage => qq{Error reading the dynamic field '$FieldName'!},
},
);
}

$IsReferenceField = $DynamicFieldBackendObject->HasBehavior(
DynamicFieldConfig => $DynamicFieldConfig,
Behavior => 'IsReferenceField',
);

if ( !$IsReferenceField ) {
return $LayoutObject->JSONReply(
Data => {
Success => 0,
Messsage => qq{Error reading the dynamic field '$FieldName'!},
},
);
}
$DynamicFieldConfig->{Name} = $FieldName;
}
}
else {
$DynamicFieldConfig = $InitialDynamicFieldConfig;
}

# search referenced object
my $MaxResults = int( $ParamObject->GetParam( Param => 'MaxResults' ) || 20 );
my $Term = $ParamObject->GetParam( Param => 'Term' ) || '';
Expand Down
6 changes: 5 additions & 1 deletion Kernel/System/DynamicField/Driver/BaseReference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,11 @@ sub GetFieldState {
my $DynamicFieldConfig = $Param{DynamicFieldConfig};

return () if !IsArrayRefWithData( $DynamicFieldConfig->{Config}{ReferenceFilterList} );
return () if none { $Param{ChangedElements}->{ $_->{EqualsObjectAttribute} // '' } } $DynamicFieldConfig->{Config}{ReferenceFilterList}->@*;
return ()
if (
( none { $Param{ChangedElements}->{ $_->{EqualsObjectAttribute} // '' } } $DynamicFieldConfig->{Config}{ReferenceFilterList}->@* )
&& !$Param{Lens}
);

my $Value = $Param{GetParam}{DynamicField}{ 'DynamicField_' . $DynamicFieldConfig->{Name} };

Expand Down
24 changes: 23 additions & 1 deletion Kernel/System/DynamicField/Driver/Lens.pm
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ sub GetFieldState {
DynamicFieldConfig => $DynamicFieldConfig,
Behavior => 'IsACLReducible',
);
my $SetsDynamicContent = $Self->HasBehavior(
DynamicFieldConfig => $DynamicFieldConfig,
Behavior => 'SetsDynamicContent',
);

my %Return;
my $ReferenceID = $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} } ? $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} }[0] : undef;
Expand Down Expand Up @@ -692,8 +696,26 @@ sub GetFieldState {
$DFParam->{"DynamicField_$DynamicFieldConfig->{Name}"} = $AttributeFieldValue;
}

if ($SetsDynamicContent) {

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

my %GetFieldState = $Param{DynamicFieldBackendObject}->GetFieldState(
%Param,
Lens => 1,
DynamicFieldConfig => $AttributeDFConfig,
);

return (
%GetFieldState,
%Return,
);
}

# if this field is non ACL reducible, set the field values
return %Return if !$IsACLReducible;
return %Return unless $IsACLReducible;

# get possible values if ACLReducible
# this is what the FieldRestrictions object would do for other fields
Expand Down
27 changes: 27 additions & 0 deletions var/httpd/htdocs/js/Core.AJAX.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,33 @@ Core.AJAX = (function (TargetNS) {
$Element.val( '' );
$ReferenceElement.val( '' );
}

// trigger reference search if autocomplete
if ( $Element.is('input') ) {

var $AutocompleteElement = $Element.parent().find('.DynamicFieldReference');

// check for surrounding set and if so, send setindex as request param
var SetIndexStrg = '';
var SetOuterFieldList = $Element.parents('.DFSetOuterField');
if ( SetOuterFieldList.length ) {
var MultiValueClass = Array.from(SetOuterFieldList[0].parentElement.classList).find(c => c.startsWith('MultiValue'));
if (MultiValueClass !== undefined && MultiValueClass != '') {
var SetIndexRegExp = new RegExp(/^MultiValue_(\d+)$/);
var MatchResults = SetIndexRegExp.exec(MultiValueClass);
SetIndexStrg = ';SetIndex=' + MatchResults[1];
}
}

var URL = Core.Config.Get('Baselink'),
QueryString = "Action=AgentReferenceSearch;ObjectID=" + DataValue[0][0]
+ ";Field=" + $AutocompleteElement.attr('id')
+ SetIndexStrg + ';';

QueryString += Core.AJAX.SerializeForm($Element.closest('form'), {'Action': 1, 'Subaction': 1, 'Term': 1, 'Field': 1, 'MaxResults': 1});
TargetNS.FunctionCall(URL, QueryString, function (Result) {
});
}
return;
}

Expand Down