Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
pcmt
pcmt
Commits
4d5874c3
Commit
4d5874c3
authored
Feb 17, 2021
by
Piotr Borek
Browse files
filtering attributes in drop-down
parent
7674bb77
Pipeline
#257695709
passed with stages
in 13 minutes and 51 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
18 deletions
+130
-18
pim/src/PcmtRulesBundle/Controller/AttributeController.php
pim/src/PcmtRulesBundle/Controller/AttributeController.php
+31
-0
pim/src/PcmtRulesBundle/Resources/config/requirejs.yml
pim/src/PcmtRulesBundle/Resources/config/requirejs.yml
+6
-0
pim/src/PcmtRulesBundle/Resources/config/routing.yml
pim/src/PcmtRulesBundle/Resources/config/routing.yml
+5
-0
pim/src/PcmtRulesBundle/Resources/public/js/fetcher/attributes-for-f2f-mapping.js
...Resources/public/js/fetcher/attributes-for-f2f-mapping.js
+24
-0
pim/src/PcmtRulesBundle/Resources/public/js/job/rules/edit/attribute-mapping.js
...e/Resources/public/js/job/rules/edit/attribute-mapping.js
+13
-18
pim/src/PcmtRulesBundle/Service/RuleAttributeProvider.php
pim/src/PcmtRulesBundle/Service/RuleAttributeProvider.php
+17
-0
pim/src/PcmtRulesBundle/Tests/Service/RuleAttributeProviderTest.php
...mtRulesBundle/Tests/Service/RuleAttributeProviderTest.php
+34
-0
No files found.
pim/src/PcmtRulesBundle/Controller/AttributeController.php
View file @
4d5874c3
...
...
@@ -90,4 +90,35 @@ class AttributeController
return
new
JsonResponse
(
$normalizedAttributes
);
}
public
function
getForF2FMappingAction
(
Request
$request
):
Response
{
$sourceFamilyCode
=
$request
->
query
->
get
(
'sourceFamily'
);
$destinationFamilyCode
=
$request
->
query
->
get
(
'destinationFamily'
);
[
$sourceAttributeList
,
$destinationAttributeList
]
=
$this
->
ruleAttributeProvider
->
getForF2FAttributeMapping
(
$sourceFamilyCode
?
$this
->
familyRepository
->
findOneBy
([
'code'
=>
$sourceFamilyCode
])
:
null
,
$destinationFamilyCode
?
$this
->
familyRepository
->
findOneBy
([
'code'
=>
$destinationFamilyCode
])
:
null
);
$normalizedSourceAttributes
=
array_map
(
function
(
$attribute
)
{
return
$this
->
lightAttributeNormalizer
->
normalize
(
$attribute
,
'internal_api'
,
[
'locale'
=>
$this
->
userContext
->
getUiLocale
()
->
getCode
()]
);
},
$sourceAttributeList
);
$normalizedDestinationAttributes
=
array_map
(
function
(
$attribute
)
{
return
$this
->
lightAttributeNormalizer
->
normalize
(
$attribute
,
'internal_api'
,
[
'locale'
=>
$this
->
userContext
->
getUiLocale
()
->
getCode
()]
);
},
$destinationAttributeList
);
return
new
JsonResponse
([
'sourceAttributeList'
=>
$normalizedSourceAttributes
,
'destinationAttributeList'
=>
$normalizedDestinationAttributes
,
]);
}
}
\ No newline at end of file
pim/src/PcmtRulesBundle/Resources/config/requirejs.yml
View file @
4d5874c3
...
...
@@ -5,6 +5,7 @@ config:
pcmt/rules/fetcher/key-attribute-for-rules
:
pcmtrules/js/fetcher/key-attribute-for-rules-fetcher
pcmt/rules/fetcher/attributes-for-rules-job
:
pcmtrules/js/fetcher/attributes-for-rules-job-fetcher
pcmt/rules/fetcher/attributes-for-f2f-mapping
:
pcmtrules/js/fetcher/attributes-for-f2f-mapping
pcmt/rules/job/field/select
:
pcmtrules/js/job/field/select
pcmt/rules/job/field/attribute-select
:
pcmtrules/js/job/field/attribute-select
...
...
@@ -69,6 +70,11 @@ config:
urls
:
list
:
pcmt_rules_attributes_for_options
get
:
pim_enrich_attribute_rest_get
attributes-for-f2f-mapping
:
module
:
pcmt/rules/fetcher/attributes-for-f2f-mapping
options
:
urls
:
list
:
pcmt_rules_attributes_for_f2f_mapping
job-instance-rules
:
module
:
pim/base-fetcher
options
:
...
...
pim/src/PcmtRulesBundle/Resources/config/routing.yml
View file @
4d5874c3
...
...
@@ -8,6 +8,11 @@ pcmt_rules_attributes_for_options:
defaults
:
{
_controller
:
pcmt.controller.rest.attributes
:
getForOptionsAction
}
methods
:
[
GET
]
pcmt_rules_attributes_for_f2f_mapping
:
path
:
/rest/attributes-for-f2f-mapping/
defaults
:
{
_controller
:
pcmt.controller.rest.attributes
:
getForF2FMappingAction
}
methods
:
[
GET
]
pcmt_rules_index_new
:
resource
:
'
@PcmtRulesBundle/Resources/config/routing/rules_profile.yml'
prefix
:
/rules
...
...
pim/src/PcmtRulesBundle/Resources/public/js/fetcher/attributes-for-f2f-mapping.js
0 → 100644
View file @
4d5874c3
'
use strict
'
;
define
([
'
jquery
'
,
'
underscore
'
,
'
pim/base-fetcher
'
,
'
routing
'
],
function
(
$
,
_
,
BaseFetcher
,
Routing
)
{
return
BaseFetcher
.
extend
({
/**
* Fetch all elements of the collection
*
* @return {Promise}
*/
fetchForOptions
:
function
(
options
)
{
let
searchOptions
=
{};
let
possibleOptions
=
[
'
sourceFamily
'
,
'
destinationFamily
'
];
_
.
each
(
possibleOptions
,
function
(
option
)
{
if
(
options
[
option
])
{
searchOptions
[
option
]
=
options
[
option
];
}
});
console
.
log
(
searchOptions
);
return
this
.
search
(
searchOptions
);
},
});
});
pim/src/PcmtRulesBundle/Resources/public/js/job/rules/edit/attribute-mapping.js
View file @
4d5874c3
...
...
@@ -65,34 +65,29 @@ define(
}
},
postUpdate
:
function
(
data
)
{
var
changed
=
false
;
if
(
data
.
configuration
.
sourceFamily
!==
this
.
sourceFamily
)
{
this
.
sourceFamily
=
data
.
configuration
.
sourceFamily
;
this
.
fetchSourceAttributes
()
;
changed
=
true
;
}
if
(
data
.
configuration
.
destinationFamily
!==
this
.
destinationFamily
)
{
this
.
destinationFamily
=
data
.
configuration
.
destinationFamily
;
this
.
fetchDestinationAttributes
();
changed
=
true
;
}
if
(
changed
)
{
this
.
fetchAttributes
();
}
},
fetchSourceAttributes
:
function
()
{
let
options
=
{
family
:
this
.
sourceFamily
};
FetcherRegistry
.
getFetcher
(
'
attributes-for-rules-job
'
).
fetchForOptions
(
options
).
then
(
function
(
options
)
{
this
.
sourceAttributeList
=
options
;
this
.
render
();
}.
bind
(
this
)
);
},
fetchDestinationAttributes
:
function
()
{
fetchAttributes
:
function
()
{
let
options
=
{
family
:
this
.
destinationFamily
sourceFamily
:
this
.
sourceFamily
,
destinationFamily
:
this
.
destinationFamily
};
FetcherRegistry
.
getFetcher
(
'
attributes-for-rules-job
'
).
fetchForOptions
(
options
).
then
(
function
(
options
)
{
this
.
destinationAttributeList
=
options
;
FetcherRegistry
.
getFetcher
(
'
attributes-for-f2f-mapping
'
).
fetchForOptions
(
options
).
then
(
function
(
result
)
{
this
.
sourceAttributeList
=
result
.
sourceAttributeList
;
this
.
destinationAttributeList
=
result
.
destinationAttributeList
;
this
.
render
();
}.
bind
(
this
)
);
...
...
pim/src/PcmtRulesBundle/Service/RuleAttributeProvider.php
View file @
4d5874c3
...
...
@@ -109,4 +109,21 @@ class RuleAttributeProvider
{
return
$this
->
attributeRepository
->
findOneBy
([
'code'
=>
$code
]);
}
public
function
getForF2FAttributeMapping
(
?FamilyInterface
$sourceFamily
,
?FamilyInterface
$destinationFamily
):
array
{
$sourceAttributeList
=
$sourceFamily
?
$sourceFamily
->
getAttributes
()
->
getValues
()
:
[];
$destinationAttributeList
=
$destinationFamily
?
$destinationFamily
->
getAttributes
()
->
getValues
()
:
[];
// removing those attributes that are in both families
foreach
(
$sourceAttributeList
as
$sKey
=>
$sourceAttribute
)
{
foreach
(
$destinationAttributeList
as
$dKey
=>
$destinationAttribute
)
{
if
(
$sourceAttribute
->
getCode
()
===
$destinationAttribute
->
getCode
())
{
unset
(
$sourceAttributeList
[
$sKey
],
$destinationAttributeList
[
$dKey
]);
}
}
}
return
[
array_values
(
$sourceAttributeList
),
array_values
(
$destinationAttributeList
)];
}
}
\ No newline at end of file
pim/src/PcmtRulesBundle/Tests/Service/RuleAttributeProviderTest.php
View file @
4d5874c3
...
...
@@ -12,6 +12,7 @@ namespace PcmtRulesBundle\Tests\Service;
use
Akeneo\Pim\Structure\Component\AttributeTypes
;
use
Akeneo\Pim\Structure\Component\Model\Family
;
use
Akeneo\Pim\Structure\Component\Model\FamilyInterface
;
use
Akeneo\Pim\Structure\Component\Repository\AttributeRepositoryInterface
;
use
PcmtRulesBundle\Service\RuleAttributeProvider
;
use
PcmtRulesBundle\Tests\TestDataBuilder\AttributeBuilder
;
...
...
@@ -168,6 +169,39 @@ class RuleAttributeProviderTest extends TestCase
$this
->
assertEquals
(
$attribute
->
getCode
(),
$result
->
getCode
());
}
public
function
dataGetForF2FAttributeMapping
():
array
{
$attribute1
=
(
new
AttributeBuilder
())
->
withCode
(
'a1'
)
->
build
();
$attribute2
=
(
new
AttributeBuilder
())
->
withCode
(
'a2'
)
->
build
();
$attribute3
=
(
new
AttributeBuilder
())
->
withCode
(
'a3'
)
->
build
();
$attribute4
=
(
new
AttributeBuilder
())
->
withCode
(
'a4'
)
->
build
();
$sourceFamily
=
(
new
FamilyBuilder
())
->
build
();
$sourceFamily
->
addAttribute
(
$attribute1
);
$sourceFamily
->
addAttribute
(
$attribute2
);
$destinationFamily
=
(
new
FamilyBuilder
())
->
build
();
$destinationFamily
->
addAttribute
(
$attribute2
);
$destinationFamily
->
addAttribute
(
$attribute3
);
$destinationFamily
->
addAttribute
(
$attribute4
);
$result
=
[[
$attribute1
],
[
$attribute3
,
$attribute4
]];
return
[
[
$sourceFamily
,
$destinationFamily
,
$result
],
];
}
/** @dataProvider dataGetForF2FAttributeMapping */
public
function
testGetForF2FAttributeMapping
(
?FamilyInterface
$sourceFamily
,
?FamilyInterface
$destinationFamily
,
array
$expectedResult
):
void
{
$provider
=
$this
->
getRuleAttributeProviderInstance
();
$result
=
$provider
->
getForF2FAttributeMapping
(
$sourceFamily
,
$destinationFamily
);
$this
->
assertEquals
(
$expectedResult
,
$result
);
}
private
function
getRuleAttributeProviderInstance
():
RuleAttributeProvider
{
return
new
RuleAttributeProvider
(
$this
->
attributeRepositoryMock
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment