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

Feature/imagechoice-component #1091

Open
wants to merge 41 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 34 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 Feb 23, 2024
c525358
imagechoice component - updated impl file ,imagechoice.html and cq di…
marikannanm Feb 25, 2024
892abfe
Imagechoice-component-Hiding placeholder from cq dialog
marikannanm Feb 25, 2024
61caea9
reverting package-lock json changes
marikannanm Feb 25, 2024
40643e0
imagechoice-component-Updated dialog option label and corresponding j…
marikannanm Feb 26, 2024
a92adaf
Merge pull request #1 from marikannanm/feature/imagechoice-dev
marikannanm Feb 26, 2024
4595738
imagechoice-component-Updated imagechoiceview js file
marikannanm Feb 27, 2024
5515cdb
Merge pull request #2 from marikannanm/feature/imagechoice-dev
marikannanm Feb 27, 2024
882bf1d
imagechoice-component-update editDialog js
marikannanm Feb 27, 2024
598294c
Merge pull request #3 from marikannanm/feature/imagechoice-dev
marikannanm Feb 27, 2024
63bdef0
imagechoice -component - updated cq template
marikannanm Feb 27, 2024
d500d8f
imagechoice-component - updated class name for image tag
marikannanm Feb 27, 2024
dcf35e0
Merge pull request #4 from marikannanm/feature/imagechoice-dev
marikannanm Feb 27, 2024
40df521
imagechoice-component- Updated ImageChoiceImpl java file - override g…
marikannanm Feb 27, 2024
fba9963
Merge pull request #5 from marikannanm/feature/imagechoice-dev
marikannanm Feb 27, 2024
9594167
imagechoice-component - updated imageItem,imagechoice impl and html f…
marikannanm Feb 28, 2024
fe82092
Merge pull request #6 from marikannanm/feature/imagechoice-component
marikannanm Feb 28, 2024
ade6cf4
imagechoice-component - update imagechoice html file
marikannanm Feb 28, 2024
afca00e
Merge pull request #7 from marikannanm/feature/imagechoice-dev
marikannanm Feb 29, 2024
ac81d18
imagechoice-component - updated imagechoiceview js and imagechoiceimp…
marikannanm Mar 1, 2024
4d6f982
Merge pull request #8 from marikannanm/feature/imagechoice-dev
marikannanm Mar 1, 2024
44570e2
imagechoice-component-updated imagechoiceview js file
marikannanm Mar 1, 2024
50de464
Merge pull request #9 from marikannanm/feature/imagechoice-dev
marikannanm Mar 1, 2024
c3f0a09
imagechoice-component - Added Unit Test cases
marikannanm Mar 9, 2024
c68ed4f
Merge pull request #10 from marikannanm/feature/imagechoice-dev
marikannanm Mar 9, 2024
0973e2d
imagechoice-component-updated test.content,json
marikannanm Mar 9, 2024
a1212b9
removed unused imports
marikannanm Mar 9, 2024
cc0a771
Merge pull request #11 from marikannanm/feature/imagechoice-dev
marikannanm Mar 9, 2024
9455a4a
imagechoice-component- updated readme file
marikannanm Mar 9, 2024
11a7552
Merge pull request #12 from marikannanm/feature/imagechoice-dev
marikannanm Mar 9, 2024
2b1fa68
imagechoice-component - removed notnull
marikannanm Mar 11, 2024
4ba7f2a
Merge pull request #13 from marikannanm/feature/imagechoice-dev
marikannanm Mar 11, 2024
c5dfe48
imagechoice-component - Added ui.tests - authoring spec.js
marikannanm Mar 18, 2024
beeddf9
Merge pull request #14 from marikannanm/feature/imagechoice-dev
marikannanm Mar 18, 2024
4cc54c0
imagechoice-Added cypress runtime test cases
marikannanm Apr 1, 2024
6adfa6d
Added Test elements for imagechoice
marikannanm Apr 1, 2024
32d5800
Merge pull request #15 from marikannanm/feature/imagechoice-dev
marikannanm Apr 1, 2024
d2f5502
imagechoice component - updated ui test runtime js and added sample
marikannanm Apr 2, 2024
c8fc5aa
Merge pull request #16 from marikannanm/feature/imagechoice-dev
marikannanm Apr 2, 2024
f763ab9
ImageChoiceComponent - Implemented Code Review feedback
marikannanm Apr 29, 2024
ec8d67c
Merge pull request #17 from marikannanm/feature/imagechoice-dev
marikannanm Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -100,6 +100,9 @@ private FormConstants() {
/** The resource type for image v1 */
public static final String RT_FD_FORM_IMAGE_V1 = RT_FD_FORM_PREFIX + "image/v1/image";

/** The resource type for image choice v1 */
public static final String RT_FD_FORM_IMAGECHOICE_V1 = RT_FD_FORM_PREFIX + "imagechoice/v1/imagechoice";

/** The resource type for title v1 */
public static final String RT_FD_FORM_TITLE_V1 = RT_FD_FORM_PREFIX + "title/v1/title";

Expand Down
@@ -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;
}
}
@@ -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;
}

}
Expand Up @@ -35,7 +35,9 @@ public enum FieldType {
PANEL("panel"),
FORM("form"),
CHECKBOX_GROUP("checkbox-group"),
IMAGE("image");
IMAGE("image"),

IMAGECHOICE("imagechoice");
Copy link
Contributor

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'

Copy link
Author

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.


private String value;

Expand Down
@@ -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();
}