Skip to content

Commit

Permalink
feat: Update WebUI Framework to be adapted to new layout editor - MEE…
Browse files Browse the repository at this point in the history
…D-3875 - Meeds-io/MIPs#120 (#870)

This change will allow to:
- Retrieve portlet with a designated mode using `maximizedPortletMode`
Request Parameter
- Return default skin when no selected skin in currently displayed site
- Avoid reloading the whole page when using WebUI ajax query
- include supported portlet modes in Application Registry DTO
  • Loading branch information
boubaker committed Apr 18, 2024
1 parent 423996c commit aa20e0c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.exoplatform.portal.config.model.ApplicationType;

import lombok.Getter;
import lombok.Setter;

/**
* Created by the eXo platform team User: Benjamin Mestrallet Date: 15 juin 2004
*/
Expand Down Expand Up @@ -58,6 +62,10 @@ public class Application implements Serializable {
/** . */
private String contentId;

@Getter
@Setter
private List<String> supportedModes;

public String getContentId() {
return contentId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
def jsManager = rcontext.getJavascriptManager();
jsManager.require("SHARED/bodyScrollListener", "bodyScrollListener");
uicomponent.renderChildren();
uicomponent.includePortletScripts();
%>
</div>
<% /* Include extensible templates configured by Kernel configuration to be imported in Page Header */ %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,15 @@ public RequestNavigationData getNavigationData() {
controllerContext.getParameter(RequestNavigationData.REQUEST_PATH));
}

@SuppressWarnings("unchecked")
public static PortalRequestContext getCurrentInstance() {
return (PortalRequestContext) RequestContext.getCurrentInstance();
RequestContext currentInstance = RequestContext.getCurrentInstance();
if (currentInstance == null) {
return null;
} else if (currentInstance instanceof PortalRequestContext portalRequestContext) {
return portalRequestContext;
} else {
return (PortalRequestContext) currentInstance.getParentAppRequestContext();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public String getSkinId() {
}

public String getId() {
return storageId == null ? getStorageName() : storageId;
return storageId == null ? "UIPortlet-" + getStorageName() : storageId;
}

public String getApplicationId() {
Expand Down Expand Up @@ -333,7 +333,18 @@ private Map<String, String> stringToThemeMap(String themesString) {
}

public PortletMode getCurrentPortletMode() {
String maximizedPortletMode = getMaximizedPortletMode();
if (StringUtils.isBlank(maximizedPortletMode)) {
return currentPortletMode_;
} else if (maximizedPortletMode.equals(PortletMode.VIEW.toString())) {
return PortletMode.VIEW;
} else if (maximizedPortletMode.equals(PortletMode.HELP.toString())) {
return PortletMode.HELP;
} else if (maximizedPortletMode.equals(PortletMode.EDIT.toString())) {
return PortletMode.EDIT;
} else {
return new PortletMode(maximizedPortletMode);
}
}

public void setCurrentPortletMode(PortletMode mode) {
Expand Down Expand Up @@ -1033,10 +1044,6 @@ public Text generateRenderMarkup(PortletInvocationResponse pir, WebuiRequestCont
lazyResourcesLoading = false;
}
}
JavascriptManager jsMan = context.getJavascriptManager();
if (!lazyResourcesLoading) {
jsMan.loadScriptResource(ResourceScope.PORTLET, getApplicationId());
}

FragmentResponse fragmentResponse = (FragmentResponse) pir;
switch (fragmentResponse.getType()) {
Expand All @@ -1056,6 +1063,7 @@ public Text generateRenderMarkup(PortletInvocationResponse pir, WebuiRequestCont
if (fragmentResponse.getProperties() != null) {
// setup transport headers
if (fragmentResponse.getProperties().getTransportHeaders() != null) {
JavascriptManager jsMan = context.getJavascriptManager();
MultiValuedPropertyMap<String> transportHeaders = fragmentResponse.getProperties().getTransportHeaders();
for (String key : transportHeaders.keySet()) {
if (JAVASCRIPT_DEPENDENCY.equals(key)) {
Expand Down Expand Up @@ -1123,4 +1131,15 @@ public Text generateRenderMarkup(PortletInvocationResponse pir, WebuiRequestCont

return markup;
}

public boolean isLazyResourcesLoading() {
return lazyResourcesLoading != null && lazyResourcesLoading.booleanValue();
}

private String getMaximizedPortletMode() {
PortalRequestContext prContext = Util.getPortalRequestContext();
HttpServletRequest req = prContext.getRequest();
return req.getParameter("maximizedPortletMode");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ public void execute(Event<UIPortalApplication> event) throws Exception {
}

showedUIPortal.refreshUIPage();
pcontext.ignoreAJAXUpdateOnPortlets(true);
pcontext.addUIComponentToUpdateByAjax(uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID));
pcontext.ignoreAJAXUpdateOnPortlets(!pcontext.useAjax());
}

private UIPortal buildUIPortal(UIPortalApplication uiPortalApp, PortalRequestContext pcontext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
import java.util.*;
import java.util.stream.Collectors;

import javax.portlet.PortletMode;

/**
* This extends the UIApplication and hence is a sibling of UIPortletApplication (used by any eXo Portlets as the Parent class
* to build the portlet component tree). The UIPortalApplication is responsible to build its subtree according to some
Expand Down Expand Up @@ -581,15 +583,16 @@ public Collection<SkinConfig> getPortalSkins(SkinVisitor visitor) {
* - skin for specific site<br>
*/
public Collection<SkinConfig> getPortalSkins() {
String skin = getSkin();
List<SkinConfig> skins = null;
if (skinVisitor == null) {
skins = new ArrayList<>(skinService.getPortalSkins(skin_));
skins = new ArrayList<>(skinService.getPortalSkins(skin));
} else {
skins = new ArrayList<>(getPortalSkins(skinVisitor));
}

//
SkinConfig skinConfig = skinService.getSkin(getCurrentSite().getName(), skin_);
SkinConfig skinConfig = skinService.getSkin(getCurrentSite().getName(), skin);
if (skinConfig != null) {
skins.add(skinConfig);
}
Expand All @@ -613,7 +616,7 @@ private Set<SkinConfig> getPortalPortletSkins() {
}

private Collection<SkinConfig> getCustomSkins() {
return skinService.getCustomPortalSkins(skin_);
return skinService.getCustomPortalSkins(getSkin());
}

private void getPortalPortletSkinConfig(Set<SkinConfig> portletConfigs, UIComponent component) {
Expand All @@ -630,7 +633,16 @@ private void getPortalPortletSkinConfig(Set<SkinConfig> portletConfigs, UICompon
}

public String getSkin() {
return skin_;
if (skin_ == null) {
String siteSkin = getCurrentSite().getSkin();
if (siteSkin == null) {
return skinService.getDefaultSkin();
} else {
return siteSkin;
}
} else {
return skin_;
}
}

public void setSkin(String skin) {
Expand Down Expand Up @@ -668,13 +680,14 @@ public Set<Skin> getPortletSkins() {
}
}

String skin = getSkin();
List<SkinConfig> additionalSkins = portletSkins.stream()
.filter(portletSkin -> portletSkin instanceof SkinConfig skinConfig
&& CollectionUtils.isNotEmpty(skinConfig.getAdditionalModules()))
.map(portletSkin -> ((SkinConfig) portletSkin).getAdditionalModules())
.flatMap(List::stream)
.distinct()
.map(module -> skinService.getPortalSkin(module, skin_))
.map(module -> skinService.getPortalSkin(module, skin))
.filter(Objects::nonNull)
.toList();
portletSkins.addAll(additionalSkins);
Expand Down Expand Up @@ -757,7 +770,7 @@ public List<ContainerPortletInfo> getPagePortletInfos() {
private SkinConfig getPortletSkinConfig(UIPortlet portlet) {
String portletId = portlet.getSkinId();
if (portletId != null) {
return skinService.getSkin(portletId, skin_);
return skinService.getSkin(portletId, getSkin());
} else {
return null;
}
Expand Down Expand Up @@ -1050,7 +1063,7 @@ private String getAddSkinScript(ControllerContext context, Set<UIComponent> upda
for (UIPortlet uiPortlet : uiportlets) {
String skinId = uiPortlet.getSkinId();
if (skinId != null) {
SkinConfig skinConfig = skinService.getSkin(skinId, skin_);
SkinConfig skinConfig = skinService.getSkin(skinId, getSkin());
if (skinConfig != null) {
if (portalPortletSkins.contains(skinConfig)) {
reloadPortalPortletSkins = true;
Expand Down Expand Up @@ -1196,6 +1209,19 @@ public ComponentTab getComponentTab() {
throw new IllegalStateException("Unexpected "+ UIPortalApplication.class.getName() +".modeState value "+ modeState +".");
}
}

@SuppressWarnings("rawtypes")
public void includePortletScripts() {
PortalRequestContext pcontext = PortalRequestContext.getCurrentInstance();
JavascriptManager jsMan = pcontext.getJavascriptManager();
List<UIPortlet> portlets = new ArrayList<>();
getCurrentPage().findComponentOfType(portlets, UIPortlet.class);
for (UIPortlet uiPortlet : portlets) {
if (!uiPortlet.isLazyResourcesLoading()) {
jsMan.loadScriptResource(ResourceScope.PORTLET, uiPortlet.getApplicationId());
}
}
}

public String getLastPortal() {
return lastPortal;
Expand Down

0 comments on commit aa20e0c

Please sign in to comment.