-
Notifications
You must be signed in to change notification settings - Fork 13
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
[EAK-366] Implemented Autocomplete component #385
Open
AlKaliada
wants to merge
9
commits into
epic/new-components
Choose a base branch
from
feature/EAK-366-autocomplete
base: epic/new-components
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d5ada24
[EAK-366] - Implemented Autocomplete component
4fac674
[EAK-366] Added test for Autocomplete component
19a75d3
[EAK-366] Implemented Autocomplete component
759d817
[EAK-366] Implemented Autocomplete component
df0db7c
[EAK-366] Implemented Autocomplete component
b1c4445
[EAK-366] Added test for Autocomplete component
8a1a2b3
[EAK-366] Implemented Autocomplete component
4f38b97
[EAK-366] Implemented Autocomplete component
e16b3b1
Merge remote-tracking branch 'origin/feature/EAK-366-autocomplete' in…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
93 changes: 93 additions & 0 deletions
93
.../main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/Autocomplete.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,93 @@ | ||
/* | ||
* 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.exadel.aem.toolkit.api.annotations.widgets.autocomplete3; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import com.exadel.aem.toolkit.api.annotations.meta.AnnotationRendering; | ||
import com.exadel.aem.toolkit.api.annotations.meta.ResourceType; | ||
import com.exadel.aem.toolkit.api.annotations.meta.ResourceTypes; | ||
import com.exadel.aem.toolkit.api.annotations.widgets.common.OptionProvider; | ||
|
||
@Target({ElementType.FIELD, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ResourceType(ResourceTypes.AUTOCOMPLETE_EAK) | ||
@AnnotationRendering(properties = "all") | ||
public @interface Autocomplete { | ||
|
||
/** | ||
* Used to specify the collection of {@link AutocompleteItem}s within this Autocomplete | ||
* @return Single {@code AutocompleteItem} annotation, or an array of AutocompleteItem | ||
*/ | ||
AutocompleteItem[] items() default {}; | ||
|
||
/** | ||
* Used to specify the source for options handled by the ToolKit's {@code OptionProvider} mechanism | ||
* @return {@link OptionProvider} instance, or an empty {@code OptionProvider} if not needed | ||
*/ | ||
OptionProvider optionProvider() default @OptionProvider; | ||
|
||
/** | ||
* When set to a non-blank string, maps to the {@code placeholder} attribute of this Granite UI component's node. | ||
* Used to define the text hint for an empty Autocomplete | ||
* @return String value | ||
*/ | ||
String placeholder() default StringUtils.EMPTY; | ||
|
||
/** | ||
* Maps to the {@code match} attribute of this Granite UI component's node. | ||
* Used to define Autocomplete match mode | ||
* @return One of {@code MatchMode} values | ||
* @see MatchMode | ||
*/ | ||
MatchMode matchMode() default MatchMode.CONTAINS; | ||
|
||
/** | ||
* When set to a non-blank string, maps to the {@code icon} attribute of this Granite UI component's node. | ||
* Used to define the component's icon | ||
* @return String value | ||
*/ | ||
String icon() default StringUtils.EMPTY; | ||
|
||
/** | ||
* When set to true, maps to the {@code disabled} attribute of this Granite UI component's node. | ||
* Changing the state of the autocomplete widget | ||
* @return True or false | ||
*/ | ||
boolean disabled() default false; | ||
|
||
/** | ||
* When set to true, maps to the {@code invalid} attribute of this Granite UI component's node. | ||
* @return True or false | ||
*/ | ||
boolean invalid() default false; | ||
|
||
/** | ||
* When set to true, maps to the {@code loading} attribute of this Granite UI component's node. | ||
* Used to show the loading spinner while preparing options | ||
* @return True or false | ||
*/ | ||
boolean loading() default false; | ||
|
||
/** | ||
* Indicates if the user is able to select multiple options | ||
* @return True or false | ||
*/ | ||
boolean multiple() default false; | ||
} |
75 changes: 75 additions & 0 deletions
75
...n/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/AutocompleteItem.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,75 @@ | ||
/* | ||
* 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.exadel.aem.toolkit.api.annotations.widgets.autocomplete3; | ||
|
||
import com.exadel.aem.toolkit.api.annotations.meta.AnnotationRendering; | ||
import com.exadel.aem.toolkit.api.annotations.meta.PropertyRendering; | ||
import com.exadel.aem.toolkit.api.annotations.meta.ResourceType; | ||
import com.exadel.aem.toolkit.api.annotations.meta.ResourceTypes; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Used to define an option within the {@link Autocomplete#items()} set | ||
* See documentation on <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/coral-ui/coralui3/Coral.Autocomplete.html"> | ||
* Autocomplete</a> component | ||
*/ | ||
@Target({ElementType.FIELD, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ResourceType(ResourceTypes.AUTOCOMPLETE_EAK) | ||
@AnnotationRendering(properties = "all") | ||
public @interface AutocompleteItem { | ||
|
||
/** | ||
* Maps to the {@code text} attribute of this Coral UI component's node. | ||
* Used to define the text displayed beside the option box | ||
* @return String value | ||
*/ | ||
String text(); | ||
|
||
/** | ||
* Maps to the {@code value} attribute of this Coral UI component's node. | ||
* Used to define the value to be stored when this option is checked | ||
* @return String value | ||
*/ | ||
@PropertyRendering(allowBlank = true) | ||
String value(); | ||
|
||
/** | ||
* When set to true, maps to the {@code disabled} attribute of this Granite UI component's node. | ||
* Changing the state of the autocomplete item | ||
* @return True or false | ||
*/ | ||
@PropertyRendering(ignoreValues = "false") | ||
boolean disabled() default false; | ||
|
||
/** | ||
* When set to true, maps to the {@code hidden} attribute of this Granite UI component's node. | ||
* Changing the state of the autocomplete item | ||
* @return True or false | ||
*/ | ||
@PropertyRendering(ignoreValues = "false") | ||
boolean hidden() default false; | ||
|
||
/** | ||
* When set to true, maps to the {@code selected} attribute of this Granite UI component's node. | ||
* Defines that the current option is selected by default | ||
* @return True or false | ||
*/ | ||
@PropertyRendering(ignoreValues = "false") | ||
boolean selected() default false; | ||
} |
18 changes: 18 additions & 0 deletions
18
...src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/MatchMode.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,18 @@ | ||
package com.exadel.aem.toolkit.api.annotations.widgets.autocomplete3; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public enum MatchMode { | ||
STARTS_WITH { | ||
@Override | ||
public String toString() { | ||
return "startswith"; | ||
} | ||
}, | ||
CONTAINS { | ||
@Override | ||
public String toString() { | ||
return StringUtils.EMPTY; | ||
} | ||
} | ||
} |
165 changes: 165 additions & 0 deletions
165
core/src/main/java/com/exadel/aem/toolkit/core/authoring/models/Autocomplete.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,165 @@ | ||
/* | ||
* 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.exadel.aem.toolkit.core.authoring.models; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.PostConstruct; | ||
import javax.inject.Named; | ||
|
||
import com.exadel.aem.toolkit.core.CoreConstants; | ||
|
||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.models.annotations.DefaultInjectionStrategy; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.ChildResource; | ||
import org.apache.sling.models.annotations.injectorspecific.OSGiService; | ||
import org.apache.sling.models.annotations.injectorspecific.SlingObject; | ||
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
import org.apache.sling.models.factory.ModelFactory; | ||
|
||
import com.exadel.aem.toolkit.api.annotations.main.AemComponent; | ||
import com.exadel.aem.toolkit.core.optionprovider.services.OptionProviderService; | ||
|
||
/** | ||
* Represents the back-end part of the {@code Autocomplete} component for Granite UI dialogs. | ||
* This Sling model is responsible for retrieving the properties of the component's node. | ||
*/ | ||
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) | ||
@AemComponent( | ||
path = "components/authoring/autocomplete", | ||
title = "Autocomplete", | ||
resourceSuperType = "etoolbox-authoring-kit/components/authoring/base" | ||
) | ||
public class Autocomplete extends BaseModel { | ||
|
||
@SlingObject | ||
private SlingHttpServletRequest request; | ||
|
||
@OSGiService | ||
private OptionProviderService optionProvider; | ||
|
||
@OSGiService | ||
private ModelFactory modelFactory; | ||
|
||
@ValueMapValue(name = CoreConstants.PN_VALUE) | ||
private String defaultValue; | ||
|
||
@ChildResource(name = "items") | ||
private List<Option> options = new ArrayList<>(); | ||
|
||
@ValueMapValue | ||
private String placeholder; | ||
|
||
@ValueMapValue | ||
private String matchMode; | ||
|
||
@ValueMapValue | ||
private String icon; | ||
|
||
@ValueMapValue | ||
private boolean disabled; | ||
|
||
@ValueMapValue | ||
private boolean invalid; | ||
|
||
@ValueMapValue | ||
private boolean loading; | ||
|
||
@ValueMapValue | ||
private boolean multiple; | ||
|
||
/** | ||
* Retrieves the list of {@link Option} objects | ||
* @return List of {@link Option} objects | ||
*/ | ||
public List<Option> getOptions() { | ||
return options; | ||
} | ||
|
||
/** | ||
* Retrieves the specified placeholder value of the autocomplete | ||
* @return String value | ||
*/ | ||
public String getPlaceholder() { | ||
return placeholder; | ||
} | ||
|
||
/** | ||
* Retrieves the specification of the autocomplete match mode | ||
* @return String value | ||
*/ | ||
public String getMatchMode() { | ||
return matchMode; | ||
} | ||
|
||
/** | ||
* Retrieves the specified icon value of the autocomplete | ||
* @return String | ||
*/ | ||
public String getIcon() { | ||
return icon; | ||
} | ||
|
||
/** | ||
* Retrieves the specification of the autocomplete if it is disabled or not | ||
* @return True or False | ||
*/ | ||
public boolean isDisabled() { | ||
return disabled; | ||
} | ||
|
||
/** | ||
* Retrieves the specification of the autocomplete if it is invalid or not | ||
* @return True or False | ||
*/ | ||
public boolean isInvalid() { | ||
return invalid; | ||
} | ||
|
||
/** | ||
* Retrieves whether the {@code Autocomplete} shows the loading spinner while preparing options. | ||
* @return True or False | ||
*/ | ||
public boolean isLoading() { | ||
return loading; | ||
} | ||
|
||
/** | ||
* Retrieves the specification of the autocomplete if it is support multiple values or not | ||
* @return True or False | ||
*/ | ||
public boolean isMultiple() { | ||
return multiple; | ||
} | ||
|
||
/** | ||
* Initializes this model per Sling Model standard | ||
*/ | ||
@PostConstruct | ||
private void init() { | ||
List<Option> optionsModels = optionProvider | ||
AlKaliada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.getOptions(request) | ||
.stream() | ||
.map(option -> modelFactory.createModel(option, Option.class)) | ||
.collect(Collectors.toList()); | ||
this.options.addAll(optionsModels); | ||
} | ||
|
||
@Override | ||
public Object getDefaultValue() { | ||
return defaultValue; | ||
} | ||
} |
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.