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

[EQK-32] Added different types in cell edit dialog #39

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ public class TableCellInfo {
public int getValueHash() {
return Objects.hashCode(value);
}

/**
* Gets the {@code type} attribute of the cell
*/
public String getType() {
if ("String".equals(type) && value != null && value.toString().length() > 76) {
return "longString";
}
return type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.exadel.etoolbox.querykit.core.models.query.helpers;

import com.google.common.collect.ImmutableMap;
import lombok.Getter;

import java.util.Map;

public class TableCellTypesHelper {
@Getter
private static final Map<String, String> typeToResourceType = ImmutableMap.of(
"String", "granite/ui/components/coral/foundation/form/textfield",
"longString", "granite/ui/components/coral/foundation/form/textarea",
"Date", "granite/ui/components/coral/foundation/form/datepicker",
"Boolean", "granite/ui/components/coral/foundation/form/checkbox",
"Long", "granite/ui/components/foundation/form/numberfield");
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
org.apache.sling.api.resource.ValueMap,
org.apache.sling.api.wrappers.ValueMapDecorator,
com.adobe.granite.ui.components.ds.ValueMapResource,
com.google.common.collect.ImmutableMap" %>
com.google.common.collect.ImmutableMap,
com.exadel.etoolbox.querykit.core.models.query.helpers.TableCellTypesHelper" %>

<%!
private String getParameter(SlingHttpServletRequest request, String name) {
Expand All @@ -31,7 +32,7 @@
}

private String getResourceType(String type) {
return "granite/ui/components/coral/foundation/form/textfield";
return TableCellTypesHelper.getTypeToResourceType().get(type);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can return null if key of type doesn't exist in map. Could it affect something?

}
%>
<%
Expand All @@ -44,10 +45,26 @@

String effectiveResourceType = getResourceType(type);

ValueMap valueMap = new ValueMapDecorator(ImmutableMap.<String, Object>of(
"sling:resourceType", effectiveResourceType,
"name", name,
"fieldLabel", "Edit value of [" + name + "]"));
ValueMap valueMap = new ValueMapDecorator(ImmutableMap.<String, Object>builder()
.put("sling:resourceType", effectiveResourceType)
.put("name", name)
.put("fieldLabel", "Edit value of [" + name + "]")
.put("type", "datetime")
.put("value", "true")
.put("uncheckedValue", "false")
.put("text", name)
.build());
Resource widgetResource = new ValueMapResource(resourceResolver, "", "nt:unstructured", valueMap);
cmp.include(widgetResource, effectiveResourceType, cmp.getOptions());

if (type.equals("Boolean")) {
ValueMap valueMapTypeHint = new ValueMapDecorator(ImmutableMap.<String, Object>builder()
.put("sling:resourceType", "granite/ui/components/foundation/form/hidden")
.put("ignoreData", "true")
.put("name", name + "@TypeHint")
.put("value", type)
.build());
Resource typeHintResource = new ValueMapResource(resourceResolver, "", "nt:unstructured", valueMapTypeHint);
cmp.include(typeHintResource, "granite/ui/components/foundation/form/hidden", cmp.getOptions());
}
%>