Skip to content

Commit

Permalink
Merge pull request #524 from exadel-inc/bugfix/EAK-519
Browse files Browse the repository at this point in the history
[EAK-519] Allowed skipping the "path" property in @Datasource
  • Loading branch information
smiakchilo authored May 31, 2024
2 parents 4391638 + eb1db23 commit 4dd60d4
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ abstract class OptionProviderHandler {
* @param target {@code Target} instance to store data in
*/
void appendDataSourceData(DataSource dataSource, Target target) {
if (StringUtils.isAnyBlank(dataSource.path(), dataSource.resourceType())) {
if (StringUtils.isAllBlank(dataSource.path(), dataSource.resourceType())) {
return;
}
Target datasourceElement = target.getOrCreateTarget(CoreConstants.NN_DATASOURCE)
.attribute(CoreConstants.PN_PATH, dataSource.path())
.attribute(DialogConstants.PN_SLING_RESOURCE_TYPE, dataSource.resourceType());
if (StringUtils.isNotBlank(dataSource.path())) {
datasourceElement.attribute(CoreConstants.PN_PATH, dataSource.path());
}
Arrays.stream(dataSource.properties())
.forEach(property -> datasourceElement.attribute(property.name(), property.value()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ public class SelectWidget {
deleteHint = false
)
String acsListOptions;

@DialogField(label="Custom Datasource")
@Select(
datasource = @DataSource(resourceType = "acs/list/resource/type")
)
String customDatasourceOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
path="/path/to/acs/list"
sling:resourceType="acs/list/resource/type"/>
</acsListOptions>
<customDatasourceOptions
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
disabled="{Boolean}false"
fieldLabel="Custom Datasource"
name="./customDatasourceOptions"
renderHidden="{Boolean}false"
required="{Boolean}false">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="acs/list/resource/type"/>
</customDatasourceOptions>
</items>
</column>
</items>
Expand Down
177 changes: 107 additions & 70 deletions plugin/src/test/resources/handlers/widgets/select/_cq_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,95 +8,132 @@
<content jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container">
<layout jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"/>
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container">
<column jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<rating jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./rating"
fieldLabel="Rating"
disabled="{Boolean}false"
emptyText="Select rating"
multiple="{Boolean}true"
renderHidden="{Boolean}false"
required="{Boolean}false"
translateOptions="{Boolean}false"
variant="quick">
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./rating"
fieldLabel="Rating"
disabled="{Boolean}false"
emptyText="Select rating"
multiple="{Boolean}true"
renderHidden="{Boolean}false"
required="{Boolean}false"
translateOptions="{Boolean}false"
variant="quick">
<items jcr:primaryType="nt:unstructured">
<item jcr:primaryType="nt:unstructured" text="Empty" value=""/>
<item1 jcr:primaryType="nt:unstructured" text="Blank" value=" "/>
<item jcr:primaryType="nt:unstructured"
text="Empty"
value=""/>
<item1 jcr:primaryType="nt:unstructured"
text="Blank"
value=" "/>
<item2 jcr:primaryType="nt:unstructured"
text="1 star"
value="1"
selected="{Boolean}true"
statusIcon="/content/dam/samples/icons/1-star-rating.png"
statusText="This is to set 1-star rating"
statusVariant="success"/>
<item3 jcr:primaryType="nt:unstructured" text="2 stars" value="2"/>
<item4 jcr:primaryType="nt:unstructured" text="3 stars" value="3"/>
<item5 jcr:primaryType="nt:unstructured" text="4 stars" value="4" disabled="{Boolean}true"/>
<item6 jcr:primaryType="nt:unstructured" text="5 stars" value="5" disabled="{Boolean}true"/>
text="1 star"
value="1"
selected="{Boolean}true"
statusIcon="/content/dam/samples/icons/1-star-rating.png"
statusText="This is to set 1-star rating"
statusVariant="success"/>
<item3 jcr:primaryType="nt:unstructured"
text="2 stars"
value="2"/>
<item4 jcr:primaryType="nt:unstructured"
text="3 stars"
value="3"/>
<item5 jcr:primaryType="nt:unstructured"
text="4 stars"
value="4"
disabled="{Boolean}true"/>
<item6 jcr:primaryType="nt:unstructured"
text="5 stars"
value="5"
disabled="{Boolean}true"/>
</items>
</rating>
<timezone jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./timezone"
fieldLabel="Timezone"
disabled="{Boolean}false"
emptyOption="{Boolean}true"
emptyText="Select timezone"
ordered="{Boolean}true"
renderHidden="{Boolean}false"
required="{Boolean}false">
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./timezone"
fieldLabel="Timezone"
disabled="{Boolean}false"
emptyOption="{Boolean}true"
emptyText="Select timezone"
ordered="{Boolean}true"
renderHidden="{Boolean}false"
required="{Boolean}false">
<items jcr:primaryType="nt:unstructured">
<item0200 jcr:primaryType="nt:unstructured" text="UTC +2" value="+02:00"/>
<item0100 jcr:primaryType="nt:unstructured" text="UTC +1" value="+01:00"/>
<item0000 jcr:primaryType="nt:unstructured" text="UTC" value="00:00"/>
<item1 jcr:primaryType="nt:unstructured" text="UTC -1" value="-01:00"/>
<item2 jcr:primaryType="nt:unstructured" text="UTC -2" value="-02:00"/>
<item0200 jcr:primaryType="nt:unstructured"
text="UTC +2"
value="+02:00"/>
<item0100 jcr:primaryType="nt:unstructured"
text="UTC +1"
value="+01:00"/>
<item0000 jcr:primaryType="nt:unstructured"
text="UTC"
value="00:00"/>
<item1 jcr:primaryType="nt:unstructured"
text="UTC -1"
value="-01:00"/>
<item2 jcr:primaryType="nt:unstructured"
text="UTC -2"
value="-02:00"/>
</items>
</timezone>
<optionList jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./optionList"
fieldLabel="Provided options list"
disabled="{Boolean}false"
renderHidden="{Boolean}false"
required="{Boolean}false">
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./optionList"
fieldLabel="Provided options list"
disabled="{Boolean}false"
renderHidden="{Boolean}false"
required="{Boolean}false">
<datasource jcr:primaryType="nt:unstructured"
sling:resourceType="/apps/etoolbox-authoring-kit/datasources/option-provider"
prepend="[None:none]"
path1="/path/to/acs/list"
path2="/path/to/acs/list2"
textMember2="pageTitle"
selected="none"
sorted="{Boolean}true"/>
sling:resourceType="/apps/etoolbox-authoring-kit/datasources/option-provider"
prepend="[None:none]"
path1="/path/to/acs/list"
path2="/path/to/acs/list2"
textMember2="pageTitle"
selected="none"
sorted="{Boolean}true"/>
</optionList>
<staticOptionList jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./staticOptionList"
fieldLabel="Provided options list with only static options"
disabled="{Boolean}false"
renderHidden="{Boolean}false"
required="{Boolean}false">
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./staticOptionList"
fieldLabel="Provided options list with only static options"
disabled="{Boolean}false"
renderHidden="{Boolean}false"
required="{Boolean}false">
<datasource jcr:primaryType="nt:unstructured"
sling:resourceType="/apps/etoolbox-authoring-kit/datasources/option-provider"
prepend="[None:none,Null:null]"
append="[All:all,Any:any]"
selected="none"
sorted="{Boolean}true"/>
sling:resourceType="/apps/etoolbox-authoring-kit/datasources/option-provider"
prepend="[None:none,Null:null]"
append="[All:all,Any:any]"
selected="none"
sorted="{Boolean}true"/>
</staticOptionList>
<acsListOptions jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./acsListOptions"
fieldLabel="ACS options list"
deleteHint="{Boolean}false"
disabled="{Boolean}false"
renderHidden="{Boolean}false"
required="{Boolean}false">
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./acsListOptions"
fieldLabel="ACS options list"
deleteHint="{Boolean}false"
disabled="{Boolean}false"
renderHidden="{Boolean}false"
required="{Boolean}false">
<datasource jcr:primaryType="nt:unstructured"
sling:resourceType="acs/list/resource/type"
path="/path/to/acs/list"/>
sling:resourceType="acs/list/resource/type"
path="/path/to/acs/list"/>
</acsListOptions>
<customDatasourceOptions
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
disabled="{Boolean}false"
fieldLabel="Custom Datasource"
name="./customDatasourceOptions"
renderHidden="{Boolean}false"
required="{Boolean}false">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="acs/list/resource/type"/>
</customDatasourceOptions>
</items>
</column>
</items>
Expand Down

0 comments on commit 4dd60d4

Please sign in to comment.