Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

WCM-88 Group items by category in form builder #18

Closed
wants to merge 6 commits into from
This page is out of date. Refresh to see the latest.
12 content-targeting-api/service/com/liferay/contenttargeting/api/model/Rule.java
View
@@ -23,6 +23,8 @@
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
+import javax.servlet.http.HttpServletRequest;
+
/**
* Provides the Rule interface, allowing custom rule creation and evaluation
* for the Content Targeting Portlet.
@@ -44,10 +46,18 @@
* <code>false</code> otherwise
*/
public boolean evaluate(
- RuleInstance ruleInstance, AnonymousUser anonymousUser)
+ HttpServletRequest request, RuleInstance ruleInstance,
+ AnonymousUser anonymousUser)
throws Exception;
/**
+ * Returns the key that identifies the category of the rule.
+ *
+ * @return the key that identifies the category
+ */
+ public String getCategoryKey();
+
+ /**
* Returns the rule description.
*
* @param locale the language's locale
5 content-targeting-api/service/com/liferay/contenttargeting/api/model/RulesEngine.java
View
@@ -19,12 +19,15 @@
import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+
/**
* @author Julio Camarero
*/
public interface RulesEngine {
public boolean matches(
- AnonymousUser anonymousUser, List<RuleInstance> ruleInstances);
+ HttpServletRequest request, AnonymousUser anonymousUser,
+ List<RuleInstance> ruleInstances);
}
11 content-targeting-api/src/com/liferay/contenttargeting/api/model/BaseRule.java
View
@@ -53,6 +53,11 @@ public void deActivate() {
}
@Override
+ public String getCategoryKey() {
+ return StringPool.BLANK;
+ }
+
+ @Override
public String getDescription(Locale locale) {
String key = getClass().getName().concat(".description");
@@ -74,7 +79,7 @@ public String getFormHTML(
try {
populateContext(ruleInstance, context);
- content = parseTemplate(getClass(), _FORM_TEMPLATE_PATH, context);
+ content = parseTemplate(getClass(), getFormTemplatePath(), context);
}
catch (Exception e) {
_log.error(
@@ -107,6 +112,10 @@ public boolean isInstantiable() {
return false;
}
+ protected String getFormTemplatePath() {
+ return _FORM_TEMPLATE_PATH;
+ }
+
protected String parseTemplate(
Class clazz, String templatePath, Map<String, Object> context)
throws Exception {
13 content-targeting-api/src/com/liferay/contenttargeting/hook/filter/UserSegmentFilter.java
View
@@ -80,7 +80,8 @@ public void doFilter(
}
public long[] getMatchesUserSegmentIds(
- long[] groupIds, AnonymousUser anonymousUser)
+ HttpServletRequest request, long[] groupIds,
+ AnonymousUser anonymousUser)
throws Exception {
if (ArrayUtil.isEmpty(groupIds)) {
@@ -93,7 +94,7 @@ public void doFilter(
UserSegmentLocalServiceUtil.getUserSegments(groupIds);
for (UserSegment userSegment : userSegments) {
- if (matches(anonymousUser, userSegment)) {
+ if (matches(request, anonymousUser, userSegment)) {
userSegmentIds.add(userSegment.getUserSegmentId());
}
}
@@ -107,7 +108,9 @@ public void init(FilterConfig filterConfig) {
_intiRulesEngine();
}
- public boolean matches(AnonymousUser anonymousUser, UserSegment userSegment)
+ public boolean matches(
+ HttpServletRequest request, AnonymousUser anonymousUser,
+ UserSegment userSegment)
throws Exception {
if (_rulesEngine == null) {
@@ -115,7 +118,7 @@ public boolean matches(AnonymousUser anonymousUser, UserSegment userSegment)
}
return _rulesEngine.matches(
- anonymousUser, userSegment.getRuleInstances());
+ request, anonymousUser, userSegment.getRuleInstances());
}
protected long[] getGroupIds(HttpServletRequest request)
@@ -192,7 +195,7 @@ else if (pathInfo.length() > 1) {
long[] groupIds = getGroupIds(request);
- return getMatchesUserSegmentIds(groupIds, anonymousUser);
+ return getMatchesUserSegmentIds(request, groupIds, anonymousUser);
}
catch (Exception e) {
e.printStackTrace();
7 content-targeting-api/src/com/liferay/contenttargeting/internal/DefaultRulesEngineImpl.java
View
@@ -24,6 +24,8 @@
import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@@ -35,7 +37,8 @@
@Override
public boolean matches(
- AnonymousUser anonymousUser, List<RuleInstance> ruleInstances) {
+ HttpServletRequest request, AnonymousUser anonymousUser,
+ List<RuleInstance> ruleInstances) {
for (RuleInstance ruleInstance : ruleInstances) {
Rule rule = _rulesRegistry.getRule(ruleInstance.getRuleKey());
@@ -45,7 +48,7 @@ public boolean matches(
}
try {
- if (!rule.evaluate(ruleInstance, anonymousUser)) {
+ if (!rule.evaluate(request, ruleInstance, anonymousUser)) {
return false;
}
}
5 content-targeting-api/src/content/Language.properties
View
@@ -17,6 +17,9 @@ action.ADD_USER_SEGMENT=Add User Segment
alias=Alias
campaigns=Campaigns
+session-attributes=Session Attributes
+user-attributes=User Attributes
user-segment=User Segment
user-segments=User Segments
-user-segment-description=User Segment Description
+user-segment-description=User Segment Description
+behavior=Behavior
70 content-targeting-web/docroot/css/content_targeting/main.css
View
@@ -10,7 +10,9 @@
}
.tabbable {
+ float: left;
margin-left: 0;
+ position: relative;
width: 240px;
}
@@ -44,8 +46,72 @@
margin: 10px 0;
overflow: hidden;
+ .category-header {
+ border-bottom: solid 1px #DDD;
+ margin-bottom: 5px;
+ margin-right: 20px;
+ padding: 10px 0;
+ position: relative;
+
+ .category-icon {
+ background-color: #009AE5;
+ color: #FFF;
+ display: inline-block;
+ font-size: 30px;
+ padding: 5px;
+ }
+
+ .category-info {
+ left: 50px;
+ line-height: 16px;
+ position: absolute;
+ top: 10px;
+
+ .category-title {
+ color: #009AE5;
+ font-size: 15px;
+ font-weight: 400;
+ }
+
+ .category-description {
+ font-size: 13px;
+ }
+ }
+
+ &:after{
+ color: #009AE5;
+ content: "\f054";
+ font-family: "fontawesome-alloy";
+ font-size: 14px;
+ position: absolute;
+ right: 0;
+ top: 20px;
+ }
+
+ &.toggler-header-expanded:after {
+ content: "\f078";
+ }
+ }
+
+ .category-content {
+ margin-right: 20px;
+ padding-left: 40px;
+
+ &.toggler-content-expanded {
+ border-bottom: solid 1px #DDD;
+ }
+ }
+
+ .category-wrapper:last-child {
+ .category-content.toggler-content-expanded {
+ border-bottom: none;
+ }
+ }
+
.diagram-builder-field {
+ float: none;
height: inherit;
+ margin-bottom: 10px;
position: relative;
text-align: left;
width: 100%;
@@ -55,6 +121,10 @@
color: #009ae5;
}
+ &.unselectable {
+ color: inherit;
+ }
+
.diagram-builder-field-icon {
display: block;
font-size: 22px;
2  content-targeting-web/docroot/html/content_targeting/edit_user_segment.ftl
View
@@ -60,7 +60,7 @@
<#assign rule = template.getRule()>
<#assign templateKey = template.getTemplateKey()>
- <li class="diagram-builder-field form-builder-field hide" data-icon="${rule.getIcon()}" data-key="${templateKey}" data-template="${template.getTemplate()}" data-unique="${(!rule.isInstantiable())?string}">
+ <li class="diagram-builder-field form-builder-field hide" data-category="${rule.getCategoryKey()}" data-icon="${rule.getIcon()}" data-key="${templateKey}" data-template="${template.getTemplate()}" data-unique="${(!rule.isInstantiable())?string}">
<span class="icon diagram-builder-field-icon ${rule.getIcon()}"></span>
<div class="diagram-builder-field-label">
<div class="row">
94 content-targeting-web/docroot/js/content_targeting/ct_form_builder.js
View
@@ -18,6 +18,16 @@ AUI.add(
'<div class="field-editor">{editor}</div>' +
'</div>',
+ ITEM_CATEGORY_HEADER_TPL = '<div class="category-header toggler-header toggler-header-expanded">' +
+ '<span class="category-icon icon {icon}"></span>' +
+ '<div class="category-info"> ' +
+ '<div class="category-title">{name}</div>' +
+ '<div class="category-description">{description}</div>' +
+ '</div>' +
+ '</div>',
+
+ ITEM_CATEGORY_CONTENT_TPL = '<div class="category-content toggler-content toggler-content-expanded"></div>',
+
LiferayCTFormItemSearch = A.Base.create('Search', A.Base, [A.AutoCompleteBase],
{
initializer: function() {
@@ -68,23 +78,40 @@ AUI.add(
_afterUiSetAvailableFields: function(event) {
var instance = this,
+ fieldsContainer = A.one('.diagram-builder-fields-container'),
searchBox = instance.get('searchBox');
if (searchBox) {
A.one('.tab-pane.active').insertBefore(
searchBox,
- A.one('.diagram-builder-fields-container')
+ fieldsContainer
).removeClass('hide');
}
+ var categories = {};
+
A.Array.each(
instance.get('availableFields'),
function(item) {
var title = item.labelNode.one('.field-title').text();
- item.get('node').attr('title', title);
+ var itemNode = item.get('node');
+
+ itemNode.attr('title', title);
+
+ var category = item.get('options').category;
+
+ if (category) {
+ if (!categories[category]) {
+ categories[category] = [];
+ }
+
+ categories[category].push(itemNode);
+ }
}
);
+
+ instance._groupFields(categories, fieldsContainer);
},
_createItemFilter: function() {
@@ -117,6 +144,60 @@ AUI.add(
return fieldSearch;
},
+ _groupFields: function(categories, fieldsContainer) {
+ var instance = this,
+ categoryContent,
+ categoryHeader,
+ categoryWrapper;
+
+ A.Object.each(
+ categories,
+ function(category, categoryName) {
+ categoryHeader = A.Node.create(
+ A.Lang.sub(
+ ITEM_CATEGORY_HEADER_TPL,
+ {
+ description: '',
+ icon: 'icon-star-empty',
+ name: categoryName
+ }
+ )
+ );
+
+ categoryContent = A.Node.create(
+ A.Lang.sub(
+ ITEM_CATEGORY_CONTENT_TPL
+ )
+ );
+
+ A.Array.each(
+ category,
+ function(item) {
+ categoryContent.append(item);
+ }
+ );
+
+ categoryWrapper = A.Node.create('<div class="category-wrapper"></div>');
+ categoryWrapper.append(categoryHeader);
+ categoryWrapper.append(categoryContent);
+
+ fieldsContainer.append(categoryWrapper);
+ }
+ );
+
+ if (!instance._togglerDelegate) {
+ instance._togglerDelegate = new A.TogglerDelegate(
+ {
+ animated: true,
+ container: fieldsContainer,
+ content: '.category-content',
+ expanded: true,
+ header: '.category-header'
+ }
+ );
+ }
+ },
+
_onClickField: function(event) {
var instance = this,
field = A.Widget.getByNode(event.target);
@@ -165,7 +246,8 @@ AUI.add(
fieldsContainer.all('.form-builder-field').each(
function(field) {
- var description = field.one('.field-description').text(),
+ var category = field.attr('data-category'),
+ description = field.one('.field-description').text(),
editor = field.attr('data-template'),
icon = field.attr('data-icon'),
key = field.attr('data-key'),
@@ -184,6 +266,7 @@ AUI.add(
fields.push(
{
+ category: category,
iconClass: icon,
id: /^([^_]*)(_.*)?$/.exec(key)[1],
label: A.Lang.sub(
@@ -193,6 +276,9 @@ AUI.add(
description: description
}
),
+ options: {
+ category: category
+ },
type: key,
unique: unique
}
@@ -310,6 +396,6 @@ AUI.add(
},
'',
{
- requires: ['aui-form-builder', 'aui-parse-content', 'autocomplete-base', 'autocomplete-filters']
+ requires: ['aui-form-builder', 'aui-parse-content', 'aui-toggler', 'autocomplete-base', 'autocomplete-filters']
}
);
10 rule-age/src/com/liferay/contenttargeting/rules/age/AgeRule.java
View
@@ -38,6 +38,8 @@
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
+import javax.servlet.http.HttpServletRequest;
+
import org.osgi.service.component.annotations.Component;
/**
@@ -48,7 +50,8 @@
@Override
public boolean evaluate(
- RuleInstance ruleInstance, AnonymousUser anonymousUser)
+ HttpServletRequest request, RuleInstance ruleInstance,
+ AnonymousUser anonymousUser)
throws Exception {
User user = anonymousUser.getUser();
@@ -73,6 +76,11 @@ public boolean evaluate(
}
@Override
+ public String getCategoryKey() {
+ return "user-attributes";
+ }
+
+ @Override
public String getIcon() {
return "icon-calendar-empty";
}
10 rule-gender/src/com/liferay/contenttargeting/rules/gender/GenderRule.java
View
@@ -32,6 +32,8 @@
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
+import javax.servlet.http.HttpServletRequest;
+
import org.osgi.service.component.annotations.Component;
/**
@@ -42,7 +44,8 @@
@Override
public boolean evaluate(
- RuleInstance ruleInstance, AnonymousUser anonymousUser)
+ HttpServletRequest request, RuleInstance ruleInstance,
+ AnonymousUser anonymousUser)
throws Exception {
User user = anonymousUser.getUser();
@@ -63,6 +66,11 @@ public boolean evaluate(
}
@Override
+ public String getCategoryKey() {
+ return "user-attributes";
+ }
+
+ @Override
public String getIcon() {
return "icon-female";
}
10 rule-ip-geocode/src/com/liferay/contenttargeting/rules/ipgeocode/IpGeocodeRule.java
View
@@ -38,6 +38,8 @@
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
+import javax.servlet.http.HttpServletRequest;
+
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@@ -49,7 +51,8 @@
@Override
public boolean evaluate(
- RuleInstance ruleInstance, AnonymousUser anonymousUser)
+ HttpServletRequest request, RuleInstance ruleInstance,
+ AnonymousUser anonymousUser)
throws Exception {
IPInfo ipInfo = _ipGeocoder.getIPInfo(anonymousUser.getLastIp());
@@ -92,6 +95,11 @@ public boolean evaluate(
}
@Override
+ public String getCategoryKey() {
+ return "session-attributes";
+ }
+
+ @Override
public String getIcon() {
return "icon-globe";
}
10 rule-score-points/src/com/liferay/contenttargeting/rules/scorepoints/ScorePointsRule.java
View
@@ -32,6 +32,8 @@
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
+import javax.servlet.http.HttpServletRequest;
+
import org.osgi.service.component.annotations.Component;
/**
@@ -42,7 +44,8 @@
@Override
public boolean evaluate(
- RuleInstance ruleInstance, AnonymousUser anonymousUser)
+ HttpServletRequest request, RuleInstance ruleInstance,
+ AnonymousUser anonymousUser)
throws Exception {
String typeSettings = ruleInstance.getTypeSettings();
@@ -63,6 +66,11 @@ public boolean evaluate(
}
@Override
+ public String getCategoryKey() {
+ return "behavior";
+ }
+
+ @Override
public String getIcon() {
return "icon-star";
}
10 rule-time/src/com/liferay/contenttargeting/rules/time/TimeRule.java
View
@@ -35,6 +35,8 @@
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
+import javax.servlet.http.HttpServletRequest;
+
import org.osgi.service.component.annotations.Component;
/**
@@ -45,7 +47,8 @@
@Override
public boolean evaluate(
- RuleInstance ruleInstance, AnonymousUser anonymousUser)
+ HttpServletRequest request, RuleInstance ruleInstance,
+ AnonymousUser anonymousUser)
throws Exception {
String typeSettings = ruleInstance.getTypeSettings();
@@ -63,6 +66,11 @@ public boolean evaluate(
}
@Override
+ public String getCategoryKey() {
+ return "session-attributes";
+ }
+
+ @Override
public String getIcon() {
return "icon-time";
}
Something went wrong with that request. Please try again.