Skip to content

Commit

Permalink
#28563 adding first draft to totally remove the TemplateAjax
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed May 20, 2024
1 parent b0bf1bc commit 325919e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.PermissionAPI;
import com.dotmarketing.business.Theme;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.portlets.containers.business.ContainerAPI;
import com.dotmarketing.portlets.containers.model.Container;
import com.dotmarketing.portlets.containers.model.ContainerView;
Expand All @@ -14,9 +15,12 @@
import com.dotmarketing.portlets.templates.design.bean.TemplateLayoutColumn;
import com.dotmarketing.portlets.templates.design.bean.TemplateLayoutRow;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.portlets.templates.model.TemplateWrapper;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.google.common.annotations.VisibleForTesting;
import com.liferay.portal.language.LanguageException;
import com.liferay.portal.language.LanguageUtil;
import com.liferay.portal.model.User;
import io.vavr.control.Try;

Expand Down Expand Up @@ -70,6 +74,7 @@ public Host getHost (final String hostId, final Supplier<Host> hostSupplier) {
* @return The {@link TemplateView} object with the Template data.
*/
public TemplateView toTemplateView(final Template template, final User user) {

final TemplateLayout layout = UtilMethods.isSet(template.getDrawedBody()) ?
DotTemplateTool.getTemplateLayout(template.getDrawedBody()) : null;
final Theme templateTheme =
Expand All @@ -78,7 +83,19 @@ public TemplateView toTemplateView(final Template template, final User user) {
if (null != templateTheme) {
template.setThemeName(templateTheme.getName());
}
return new TemplateView.Builder()

Host parentHost = null;
if(template instanceof TemplateWrapper) {
parentHost = ((TemplateWrapper) template).getHost();
} else {
try{
parentHost = APILocator.getTemplateAPI().getTemplateHost(template);
}catch(DotDataException e){
Logger.warn(this, "Could not find host for template = " + template.getIdentifier());
}
}

final TemplateView.Builder builder = new TemplateView.Builder()
.name(template.getName())
.friendlyName(template.getFriendlyName())
.title(template.getTitle())
Expand Down Expand Up @@ -118,8 +135,29 @@ public TemplateView toTemplateView(final Template template, final User user) {
.sortOrder(template.getSortOrder())
.layout(this.toLayoutView(layout))
.containers(this.findContainerInLayout(layout))
.themeInfo(null != templateTheme ? new ThemeView(templateTheme) : null)
.build();
.themeInfo(null != templateTheme ? new ThemeView(templateTheme) : null);

if (template.isAnonymous()){
try {
final String customLayoutTemplateLabel = LanguageUtil.get("editpage.properties.template.custom.label");
builder.fullTitle(customLayoutTemplateLabel);
builder.htmlTitle(customLayoutTemplateLabel);
} catch (LanguageException e) {
Logger.error(this.getClass(),
"Exception on toTemplateView exception message: " + e.getMessage(), e);
}
} else if(parentHost != null) {
builder.hostName(parentHost.getHostname());
builder.hostId(parentHost.getIdentifier());

builder.fullTitle(template.getTitle() + " (" + parentHost.getHostname() + ")" );
builder.htmlTitle("<div>" + template.getTitle() + "</div><small>" + parentHost.getHostname() + "</div></small>" );
} else {
builder.fullTitle(template.getTitle());
builder.htmlTitle(template.getTitle());
}

return builder.build();
}

public TemplateLayout toTemplateLayout(final TemplateLayoutView templateLayoutView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class TemplateView {
private final Set<ContainerView> containers;
private final ThemeView themeInfo;

private final String hostName;
private final String hostId;
private final String fullTitle;
private final String htmlTitle;

private TemplateView(final Builder builder) {
this.identifier = builder.identifier;
this.inode = builder.inode;
Expand Down Expand Up @@ -94,6 +99,26 @@ private TemplateView(final Builder builder) {
this.layout = builder.layout;
this.containers = builder.containers;
this.themeInfo = builder.themeInfo;
this.hostName = builder.hostName;
this.hostId = builder.hostId;
this.fullTitle = builder.fullTitle;
this.htmlTitle = builder.htmlTitle;
}

public String getHostName() {
return hostName;
}

public String getHostId() {
return hostId;
}

public String getFullTitle() {
return fullTitle;
}

public String getHtmlTitle() {
return htmlTitle;
}

public Map<String, ContainerView> getContainers() {
Expand Down Expand Up @@ -290,6 +315,31 @@ public static final class Builder {
private Set<ContainerView> containers;
private ThemeView themeInfo;

private String hostName;
private String hostId;
private String fullTitle;
private String htmlTitle;

public Builder hostName(final String hostName) {
this.hostName = hostName;
return this;
}

public Builder hostId(final String hostId) {
this.hostId = hostId;
return this;
}

public Builder fullTitle(final String fullTitle) {
this.fullTitle = fullTitle;
return this;
}

public Builder htmlTitle(final String htmlTitle) {
this.htmlTitle = htmlTitle;
return this;
}

public Builder containers (final Set<ContainerView> containers) {

this.containers = containers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,7 @@ dojo.declare("dotcms.dojo.data.TemplateReadStore", null, {

if(keywordArgs.onItem) {

let entities = templatesEntity.entity;
let templatesArray = [];
entities.forEach(template => {

templatesArray.push({
hostName:'',
hostId:'',
fullTitle: template.title,
htmlTitle: "<div>" + template.title + "</div>"
});
});
let templatesArray = templatesEntity.entity;

console.log('templatesArray', templatesArray);
dojo.forEach(templatesArray, function (template) {
Expand Down

0 comments on commit 325919e

Please sign in to comment.