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

LPS-98887 AB test variant layout content edition #76987

Closed
wants to merge 12 commits into from
Expand Up @@ -406,6 +406,10 @@ protected long getGroupId() {
return _groupId;
}

protected long getSegmentsExperienceId() {
return SegmentsExperienceConstants.ID_DEFAULT;
}

protected List<SoyContext> getSidebarPanelSoyContexts(
boolean pageIsDisplayPage)
throws PortalException {
Expand Down Expand Up @@ -997,7 +1001,7 @@ private SoyContext _getFragmentEntryLinksSoyContext()

themeDisplay.setIsolated(true);

long[] segmentsExperienceIds = {SegmentsExperienceConstants.ID_DEFAULT};
long[] segmentsExperienceIds = {getSegmentsExperienceId()};

try {
for (FragmentEntryLink fragmentEntryLink : fragmentEntryLinks) {
Expand Down Expand Up @@ -1210,7 +1214,7 @@ private String _getLayoutData() throws PortalException {
themeDisplay.getScopeGroupId(), classNameId, classPK, true);

_layoutData = layoutPageTemplateStructure.getData(
SegmentsExperienceConstants.ID_DEFAULT);
getSegmentsExperienceId());

return _layoutData;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@
import com.liferay.segments.model.SegmentsEntry;
import com.liferay.segments.model.SegmentsExperience;
import com.liferay.segments.service.SegmentsEntryServiceUtil;
import com.liferay.segments.service.SegmentsExperienceLocalServiceUtil;
import com.liferay.segments.service.SegmentsExperienceServiceUtil;

import java.util.ArrayList;
Expand Down Expand Up @@ -103,6 +104,35 @@ public SoyContext getFragmentsEditorToolbarSoyContext()
return _fragmentsEditorToolbarSoyContext;
}

@Override
protected long getSegmentsExperienceId() {
if (_segmentsExperienceId != null) {
return _segmentsExperienceId;
}

_segmentsExperienceId = SegmentsExperienceConstants.ID_DEFAULT;

long selectedSegmentsExperienceId = ParamUtil.getLong(
PortalUtil.getOriginalServletRequest(request),
"segmentsExperienceId", -1);

if ((selectedSegmentsExperienceId != -1) &&
(selectedSegmentsExperienceId !=
SegmentsExperienceConstants.ID_DEFAULT)) {

SegmentsExperience segmentsExperience =
SegmentsExperienceLocalServiceUtil.fetchSegmentsExperience(
selectedSegmentsExperienceId);

if (segmentsExperience != null) {
_segmentsExperienceId =
segmentsExperience.getSegmentsExperienceId();
}
}

return _segmentsExperienceId;
}

private SoyContext _getAvailableSegmentsEntriesSoyContext() {
SoyContext availableSegmentsEntriesSoyContext =
SoyContextFactoryUtil.createSoyContext();
Expand Down Expand Up @@ -297,6 +327,18 @@ private boolean _isShowSegmentsExperiences() throws PortalException {
return _showSegmentsExperiences;
}

private boolean _isSingleSegmentsExperienceMode() {
long segmentsExperienceId = ParamUtil.getLong(
PortalUtil.getOriginalServletRequest(request),
"segmentsExperienceId", -1);

if (segmentsExperienceId == -1) {
return false;
}

return true;
}

private void _populateSegmentsExperiencesSoyContext(SoyContext soyContext)
throws PortalException {

Expand All @@ -323,15 +365,20 @@ private void _populateSegmentsExperiencesSoyContext(SoyContext soyContext)
"hasEditSegmentsEntryPermission", _hasEditSegmentsEntryPermission()
).put(
"layoutDataList", _getLayoutDataListSoyContext()
).put(
"segmentsExperienceId", String.valueOf(getSegmentsExperienceId())
).put(
"selectedSegmentsEntryId", String.valueOf(_getSegmentsEntryId())
).put(
"singleSegmentsExperienceMode", _isSingleSegmentsExperienceMode()
);
}

private SoyContext _editorSoyContext;
private String _editSegmentsEntryURL;
private SoyContext _fragmentsEditorToolbarSoyContext;
private Long _segmentsEntryId;
private Long _segmentsExperienceId;
private Boolean _showSegmentsExperiences;

}
Expand Up @@ -28,9 +28,11 @@
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.portlet.JSONPortletResponseUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.service.LayoutLocalService;
import com.liferay.portal.kernel.service.ServiceContextFactory;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.transaction.Propagation;
Expand Down Expand Up @@ -180,6 +182,10 @@ private JSONObject _addSegmentsExperience(ActionRequest actionRequest)

_populateSegmentsSegmentsExperimentRelJSONObject(
jsonObject, segmentsExperimentRel, themeDisplay.getLocale());

_initializeDraftLayout(
themeDisplay.getScopeGroupId(), classPK, segmentsExperience,
baseSegmentsExperienceId);
}

return jsonObject;
Expand Down Expand Up @@ -261,6 +267,27 @@ private SegmentsExperiment _getSegmentsExperiment(
return segmentsExperiment;
}

private void _initializeDraftLayout(
long groupId, long classPK, SegmentsExperience segmentsExperience,
long baseSegmentsExperienceId)
throws PortalException {

Layout draftLayout = _layoutLocalService.fetchLayout(
_portal.getClassNameId(Layout.class.getName()), classPK);

if (draftLayout != null) {
_addLayoutData(
groupId, draftLayout.getClassNameId(), draftLayout.getPlid(),
segmentsExperience.getSegmentsExperienceId(),
baseSegmentsExperienceId);

_updateFragmentEntryLinksEditableValues(
groupId, draftLayout.getClassNameId(), draftLayout.getPlid(),
segmentsExperience.getSegmentsExperienceId(),
baseSegmentsExperienceId);
}
}

private void _populateFragmentEntryLinksJSONObject(
JSONObject jsonObject,
Map<Long, String> fragmentEntryLinksEditableValuesMap)
Expand Down Expand Up @@ -422,6 +449,9 @@ else if (editableJSONObject.has("defaultValue")) {
@Reference
private FragmentEntryLinkService _fragmentEntryLinkService;

@Reference
private LayoutLocalService _layoutLocalService;

@Reference
private LayoutPageTemplateStructureLocalService
_layoutPageTemplateStructureService;
Expand Down
Expand Up @@ -22,6 +22,7 @@
{@param? savingChanges: bool}
{@param? selectedSegmentsEntryId: string}
{@param? selectedSidebarPanelId: string}
{@param? singleSegmentsExperienceMode: bool}
{@param? spritemap: string}
{@param? store: ?}

Expand All @@ -39,7 +40,7 @@
<div class="{$toolbarClasses}">
<div class="container-fluid container-fluid-max-xl">
<ul class="navbar-nav">
{if $defaultSegmentsExperienceId }
{if $defaultSegmentsExperienceId and not $singleSegmentsExperienceMode }
<li class="nav-item">
{call com.liferay.layout.content.page.editor.web.SegmentsExperienceSelector.render}
{param availableSegmentsEntries: $availableSegmentsEntries /}
Expand Down Expand Up @@ -80,6 +81,13 @@
</li>

{if $discardDraftURL}
{let $discardLabel kind="text"}
{if $singleSegmentsExperienceMode}
{msg desc=""}discard-variant{/msg}
{else}
{msg desc=""}discard-draft{/msg}
{/if}
{/let}
<li class="nav-item">
<form
action="{$discardDraftURL}"
Expand Down Expand Up @@ -108,13 +116,20 @@
{/let}

<button {$discardButtonAttributes}>
{msg desc=""}discard-draft{/msg}
{$discardLabel}
</button>
</form>
</li>
{/if}

{if $publishURL}
{let $publishLabel kind="text"}
{if $singleSegmentsExperienceMode}
{msg desc=""}save-variant{/msg}
{else}
{msg desc=""}publish{/msg}
{/if}
{/let}
<li class="nav-item">
<form action="{$publishURL}" method="POST">
<input
Expand All @@ -139,7 +154,7 @@
{/let}

<button {$publishButtonAttributes}>
{msg desc=""}publish{/msg}
{$publishLabel}
</button>
</form>
</li>
Expand Down
Expand Up @@ -20,6 +20,7 @@ content-structure=Content Structure
content-type=Content Type
delete-experience=Delete Experience
deprioritize-experience=Deprioritize Experience
discard-variant=Discard Variant
do-you-want-to-delete-this-experience=Do you want to delete this experience? Its content will be deleted.
do-you-want-to-leave-this-site=Do you want to leave this site? Changes you made may not be saved.
draft-saved-at-x=Draft saved at {0}.
Expand Down Expand Up @@ -65,6 +66,7 @@ remove-background=Remove Background
reopen=Reopen
restore-values=Restore Values
saved=Saved
save-variant=Save Variant
saving-changes=Saving changes...
secondary-button=Secondary Button
section=Section
Expand Down
Expand Up @@ -23,7 +23,6 @@
import com.liferay.layout.page.template.service.LayoutPageTemplateEntryLocalService;
import com.liferay.layout.page.template.service.LayoutPageTemplateStructureLocalService;
import com.liferay.layout.util.LayoutCopyHelper;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
Expand Down Expand Up @@ -310,12 +309,11 @@ private void _copyPortletPreferences(
}

private long[] _getSegmentsExperienceIds(
long groupId, long classNameId, long classPK)
throws PortalException {
long groupId, long classNameId, long classPK) {

List<SegmentsExperience> segmentsExperiences =
_segmentsExperienceLocalService.getSegmentsExperiences(
groupId, classNameId, classPK, true);
groupId, classNameId, classPK);

Stream<SegmentsExperience> stream = segmentsExperiences.stream();

Expand Down
Expand Up @@ -283,6 +283,10 @@ public SegmentsExperience getSegmentsExperienceByUuidAndGroupId(
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public List<SegmentsExperience> getSegmentsExperiences(int start, int end);

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public List<SegmentsExperience> getSegmentsExperiences(
long groupId, long classNameId, long classPK);

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public List<SegmentsExperience> getSegmentsExperiences(
long groupId, long classNameId, long classPK, boolean active)
Expand Down
Expand Up @@ -340,6 +340,13 @@ public static String getOSGiServiceIdentifier() {
return getService().getSegmentsExperiences(start, end);
}

public static java.util.List<com.liferay.segments.model.SegmentsExperience>
getSegmentsExperiences(long groupId, long classNameId, long classPK) {

return getService().getSegmentsExperiences(
groupId, classNameId, classPK);
}

public static java.util.List<com.liferay.segments.model.SegmentsExperience>
getSegmentsExperiences(
long groupId, long classNameId, long classPK, boolean active)
Expand Down
Expand Up @@ -369,6 +369,14 @@ public com.liferay.segments.model.SegmentsExperience getSegmentsExperience(
start, end);
}

@Override
public java.util.List<com.liferay.segments.model.SegmentsExperience>
getSegmentsExperiences(long groupId, long classNameId, long classPK) {

return _segmentsExperienceLocalService.getSegmentsExperiences(
groupId, classNameId, classPK);
}

@Override
public java.util.List<com.liferay.segments.model.SegmentsExperience>
getSegmentsExperiences(
Expand Down
Expand Up @@ -15,6 +15,7 @@
package com.liferay.segments.experiment.web.internal.display.context;

import com.liferay.layout.content.page.editor.constants.ContentPageEditorPortletKeys;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
Expand All @@ -23,11 +24,13 @@
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.service.LayoutLocalService;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.ResourceBundleUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
Expand Down Expand Up @@ -60,12 +63,14 @@ public class SegmentsExperimentDisplayContext {

public SegmentsExperimentDisplayContext(
HttpServletRequest httpServletRequest, RenderResponse renderResponse,
Portal portal, SegmentsExperienceService segmentsExperienceService,
LayoutLocalService layoutLocalService, Portal portal,
SegmentsExperienceService segmentsExperienceService,
SegmentsExperimentService segmentsExperimentService,
SegmentsExperimentRelService segmentsExperimentRelService) {

_httpServletRequest = httpServletRequest;
_renderResponse = renderResponse;
_layoutLocalService = layoutLocalService;
_portal = portal;
_segmentsExperienceService = segmentsExperienceService;
_segmentsExperimentService = segmentsExperimentService;
Expand Down Expand Up @@ -98,6 +103,26 @@ public String getEditSegmentsExperimentURL() {
return _getSegmentsExperimentActionURL("/edit_segments_experiment");
}

public String getEditSegmentsVariantLayoutURL() throws PortalException {
Layout layout = _themeDisplay.getLayout();

Layout draftLayout = _layoutLocalService.fetchLayout(
_portal.getClassNameId(Layout.class), layout.getPlid());

if (draftLayout == null) {
return StringPool.BLANK;
}

String layoutFullURL = PortalUtil.getLayoutFullURL(
draftLayout, _themeDisplay);

layoutFullURL = HttpUtil.setParameter(
layoutFullURL, "p_l_mode", Constants.EDIT);

return HttpUtil.setParameter(
layoutFullURL, "p_l_back_url", _themeDisplay.getURLCurrent());
}

public String getEditSegmentsVariantURL() {
return _getSegmentsExperimentActionURL("/edit_segments_experiment_rel");
}
Expand Down Expand Up @@ -274,6 +299,7 @@ private String _getSegmentsExperimentActionURL(String action) {
}

private final HttpServletRequest _httpServletRequest;
private final LayoutLocalService _layoutLocalService;
private final Portal _portal;
private final RenderResponse _renderResponse;
private Long _segmentsExperienceId;
Expand Down