-
Notifications
You must be signed in to change notification settings - Fork 45
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
Feature/imagechoice-component #1091
Open
marikannanm
wants to merge
41
commits into
adobe:dev
Choose a base branch
from
marikannanm:feature/imagechoice-component
base: dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
40143e0
Initial commit for Image Choice (V1) Core Component
marikannanm c525358
imagechoice component - updated impl file ,imagechoice.html and cq di…
marikannanm 892abfe
Imagechoice-component-Hiding placeholder from cq dialog
marikannanm 61caea9
reverting package-lock json changes
marikannanm 40643e0
imagechoice-component-Updated dialog option label and corresponding j…
marikannanm a92adaf
Merge pull request #1 from marikannanm/feature/imagechoice-dev
marikannanm 4595738
imagechoice-component-Updated imagechoiceview js file
marikannanm 5515cdb
Merge pull request #2 from marikannanm/feature/imagechoice-dev
marikannanm 882bf1d
imagechoice-component-update editDialog js
marikannanm 598294c
Merge pull request #3 from marikannanm/feature/imagechoice-dev
marikannanm 63bdef0
imagechoice -component - updated cq template
marikannanm d500d8f
imagechoice-component - updated class name for image tag
marikannanm dcf35e0
Merge pull request #4 from marikannanm/feature/imagechoice-dev
marikannanm 40df521
imagechoice-component- Updated ImageChoiceImpl java file - override g…
marikannanm fba9963
Merge pull request #5 from marikannanm/feature/imagechoice-dev
marikannanm 9594167
imagechoice-component - updated imageItem,imagechoice impl and html f…
marikannanm fe82092
Merge pull request #6 from marikannanm/feature/imagechoice-component
marikannanm ade6cf4
imagechoice-component - update imagechoice html file
marikannanm afca00e
Merge pull request #7 from marikannanm/feature/imagechoice-dev
marikannanm ac81d18
imagechoice-component - updated imagechoiceview js and imagechoiceimp…
marikannanm 4d6f982
Merge pull request #8 from marikannanm/feature/imagechoice-dev
marikannanm 44570e2
imagechoice-component-updated imagechoiceview js file
marikannanm 50de464
Merge pull request #9 from marikannanm/feature/imagechoice-dev
marikannanm c3f0a09
imagechoice-component - Added Unit Test cases
marikannanm c68ed4f
Merge pull request #10 from marikannanm/feature/imagechoice-dev
marikannanm 0973e2d
imagechoice-component-updated test.content,json
marikannanm a1212b9
removed unused imports
marikannanm cc0a771
Merge pull request #11 from marikannanm/feature/imagechoice-dev
marikannanm 9455a4a
imagechoice-component- updated readme file
marikannanm 11a7552
Merge pull request #12 from marikannanm/feature/imagechoice-dev
marikannanm 2b1fa68
imagechoice-component - removed notnull
marikannanm 4ba7f2a
Merge pull request #13 from marikannanm/feature/imagechoice-dev
marikannanm c5dfe48
imagechoice-component - Added ui.tests - authoring spec.js
marikannanm beeddf9
Merge pull request #14 from marikannanm/feature/imagechoice-dev
marikannanm 4cc54c0
imagechoice-Added cypress runtime test cases
marikannanm 6adfa6d
Added Test elements for imagechoice
marikannanm 32d5800
Merge pull request #15 from marikannanm/feature/imagechoice-dev
marikannanm d2f5502
imagechoice component - updated ui test runtime js and added sample
marikannanm c8fc5aa
Merge pull request #16 from marikannanm/feature/imagechoice-dev
marikannanm f763ab9
ImageChoiceComponent - Implemented Code Review feedback
marikannanm ec8d67c
Merge pull request #17 from marikannanm/feature/imagechoice-dev
marikannanm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
...main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ImageChoiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2024 Adobe | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
package com.adobe.cq.forms.core.components.internal.models.v1.form; | ||
|
||
import java.util.*; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.PostConstruct; | ||
import javax.inject.Inject; | ||
|
||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.models.annotations.Exporter; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.Optional; | ||
import org.apache.sling.models.annotations.Via; | ||
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; | ||
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.adobe.cq.export.json.ComponentExporter; | ||
import com.adobe.cq.export.json.ExporterConstants; | ||
import com.adobe.cq.forms.core.components.internal.form.FormConstants; | ||
import com.adobe.cq.forms.core.components.models.form.BaseConstraint; | ||
import com.adobe.cq.forms.core.components.models.form.CheckBox; | ||
import com.adobe.cq.forms.core.components.models.form.ImageChoice; | ||
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl; | ||
import com.adobe.cq.forms.core.components.util.ComponentUtils; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
@Model( | ||
adaptables = { SlingHttpServletRequest.class, Resource.class }, | ||
adapters = { ImageChoice.class, ComponentExporter.class }, | ||
resourceType = { FormConstants.RT_FD_FORM_IMAGECHOICE_V1 }) | ||
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) | ||
public class ImageChoiceImpl extends AbstractFieldImpl implements ImageChoice { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "orientation") | ||
@Nullable | ||
protected String orientationJcr; | ||
private CheckBox.Orientation orientation; | ||
|
||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "selectionType") | ||
@Nullable | ||
protected String selectionType; | ||
|
||
@Inject | ||
@Via("resource") | ||
@Optional | ||
protected List<ImageItem> options = new ArrayList<>(); | ||
|
||
@PostConstruct | ||
private void initImageChoiceModel() { | ||
orientation = CheckBox.Orientation.fromString(orientationJcr); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getCustomLayoutProperties() { | ||
Map<String, Object> customLayoutProperties = super.getCustomLayoutProperties(); | ||
if (orientation != null) { | ||
customLayoutProperties.put("orientation", orientation); | ||
} | ||
if (selectionType != null) { | ||
customLayoutProperties.put("selectionType", selectionType); | ||
} | ||
return customLayoutProperties; | ||
} | ||
|
||
@JsonIgnore | ||
public CheckBox.Orientation getOrientation() { | ||
return orientation; | ||
} | ||
|
||
@JsonIgnore | ||
public String getSelectionType() { | ||
return selectionType; | ||
} | ||
|
||
public List<ImageItem> getOptions() { | ||
options = setImageValueBasedOnSubmissionDataType(); | ||
return options; | ||
} | ||
|
||
private Map<Object, ImageItem> removeDuplicates() { | ||
LinkedHashMap<Object, ImageItem> map = new LinkedHashMap<>(); | ||
if (options != null) { | ||
for (ImageItem item : options) { | ||
map.put(item.getValue(), item); | ||
} | ||
} | ||
return map; | ||
} | ||
|
||
private List<ImageItem> setImageValueBasedOnSubmissionDataType() { | ||
if (options == null) { | ||
return null; | ||
} else { | ||
Map<Object, ImageItem> map = removeDuplicates(); | ||
List<ImageItem> updatedOptions = new ArrayList<>(); | ||
for (Map.Entry<Object, ImageItem> entry : map.entrySet()) { | ||
Object key = entry.getKey(); | ||
ImageItem item = entry.getValue(); | ||
Object coercedValue = coerceImageValue(type, key); | ||
item.setImageValue(coercedValue); | ||
updatedOptions.add(item); | ||
} | ||
return updatedOptions; | ||
} | ||
} | ||
|
||
private Object coerceImageValue(BaseConstraint.Type type, Object value) { | ||
if (type.equals(BaseConstraint.Type.NUMBER) || type.equals(BaseConstraint.Type.NUMBER_ARRAY)) { | ||
return Long.parseLong(value.toString()); | ||
} else if (type.equals(BaseConstraint.Type.BOOLEAN) || type.equals(BaseConstraint.Type.BOOLEAN_ARRAY)) { | ||
return Boolean.parseBoolean(value.toString()); | ||
} | ||
return value; | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return super.getType(); | ||
} | ||
|
||
@Override | ||
public Object[] getDefault() { | ||
Object[] typedDefaultValue = null; | ||
if (defaultValue != null) { | ||
typedDefaultValue = ComponentUtils.coerce(type, defaultValue); | ||
} | ||
return typedDefaultValue; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...e/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ImageItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2024 Adobe | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
|
||
package com.adobe.cq.forms.core.components.internal.models.v1.form; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; | ||
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
@Model(adaptables = Resource.class) | ||
public class ImageItem { | ||
@ValueMapValue(name = "imageSrc") | ||
private String imageSrc; | ||
|
||
@JsonIgnore | ||
@ValueMapValue(name = "imageValue") | ||
private String value; | ||
|
||
private Object imageValue; | ||
|
||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "altText") | ||
private String altText; | ||
|
||
public String getImageSrc() { | ||
return imageSrc; | ||
} | ||
|
||
public void setImageSrc(String imageSrc) { | ||
this.imageSrc = imageSrc; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public Object getImageValue() { | ||
return imageValue; | ||
} | ||
|
||
public void setImageValue(Object imageValue) { | ||
this.imageValue = imageValue; | ||
} | ||
|
||
public String getAltText() { | ||
return altText; | ||
} | ||
|
||
public void setAltText(String altText) { | ||
this.altText = altText; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...les/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/ImageChoice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2024 Adobe | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
|
||
package com.adobe.cq.forms.core.components.models.form; | ||
|
||
import java.util.List; | ||
|
||
import org.osgi.annotation.versioning.ConsumerType; | ||
|
||
import com.adobe.cq.forms.core.components.internal.models.v1.form.ImageItem; | ||
|
||
/** | ||
* Defines the form {@code ImageChoice} Sling Model used for the {@code /apps/core/fd/components/form/imagechoice/v1/imagechoice} | ||
* component. | ||
* | ||
* @since com.adobe.cq.forms.core.components.models.form 2.0.0 | ||
*/ | ||
@ConsumerType | ||
public interface ImageChoice extends Field { | ||
|
||
/** | ||
* Returns the type of selection for the image choice component, either single or multiple selection. | ||
* | ||
* @return the type of selection | ||
* @since com.adobe.cq.forms.core.components.models.form 2.0.0 | ||
*/ | ||
String getSelectionType(); | ||
|
||
/** | ||
* Returns the list of options associated with the image choice component. | ||
* | ||
* @return the list of options | ||
* @since com.adobe.cq.forms.core.components.models.form 2.0.0 | ||
*/ | ||
List<ImageItem> getOptions(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fieldType 'imagechoice' does not exists, I believe it should be 'checkbox'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for creating a new field type is that the image choice component is a composite multi/single selection type, and it will not store values as an enum.