Skip to content

Commit

Permalink
Merge pull request #624 from /issues/618-htl-server
Browse files Browse the repository at this point in the history
Issues/618 htl server
  • Loading branch information
cmrockwell authored Apr 26, 2021
2 parents daaa44b + 5901bee commit f5bce05
Show file tree
Hide file tree
Showing 108 changed files with 3,295 additions and 442 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ export default {
this.reWrapEditable()
},

refreshEditor(vm) {
vm.$refs.editview.contentWindow.location.reload()
},

onInlineClick(event) {
this.pingToolbar()
},
Expand Down
29 changes: 16 additions & 13 deletions admin-base/ui.apps/src/main/js/stateActions/addComponentToPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,22 @@ export default function(me, target) {
processed = true;
return me.getApi().insertNodeAt(target.pagePath+targetNode.path, componentPath, target.drop, variation)
.then( (data) => {
if(targetNodeUpdate.fromTemplate === true) {
return me.getApi().populatePageView(me.getNodeFromView('/pageView/path'))
} else {
if(target.drop.startsWith('into')) {
Vue.set(targetNodeUpdate, 'children', data.children)
}
else if(target.drop === 'before' || target.drop === 'after')
{
Vue.set(targetNodeUpdate, 'children', data.children)
}
log.fine(data)
}
})
if(view.pageView.page.serverSide) {
me.action(me.getApp().$children[0], 'refreshEditor', view.pageView.page)
return me.getApi().populatePageView(me.getNodeFromView('/pageView/path'))
} else if(targetNodeUpdate.fromTemplate === true) {
return me.getApi().populatePageView(me.getNodeFromView('/pageView/path'))
} else {
if(target.drop.startsWith('into')) {
Vue.set(targetNodeUpdate, 'children', data.children)
}
else if(target.drop === 'before' || target.drop === 'after')
{
Vue.set(targetNodeUpdate, 'children', data.children)
}
log.fine(data)
}
})
}

// copy/paste?
Expand Down
3 changes: 2 additions & 1 deletion admin-base/ui.apps/src/main/js/stateActions/savePageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export default function(me, target) {
delete view.state.editor;
set(view, '/state/editorVisible', false)
if(view.pageView.page.serverSide) {
me.action(me.getApp().$children[0], 'refreshEditor', view.pageView.page).then( () => { resolve() })
me.action(me.getApp().$children[0], 'refreshEditor', view.pageView.page)
resolve()
} else {
resolve()
}
Expand Down
1 change: 1 addition & 0 deletions docker/scripts/install-peregrine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PKG_ORDER=( \
base.ui.apps-1.0-SNAPSHOT.zip \
felib.ui.apps-1.0-SNAPSHOT.zip \
pagerender-vue.ui.apps-1.0-SNAPSHOT.zip \
pagerender-server.ui.apps-1.0-SNAPSHOT.zip \
admin.ui.apps-1.0-SNAPSHOT.zip \
admin.ui.materialize-1.0-SNAPSHOT.zip \
admin.sling.ui.apps-1.0-SNAPSHOT.zip \
Expand Down
20 changes: 17 additions & 3 deletions pagerenderer/server/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<artifactId>pagerender-server.core</artifactId>
<packaging>bundle</packaging>

<name>peregrine server page renderer - Core</name>
<name>Peregrine CMS - Page Render Server - Core</name>
<description>
OSGi Bundle for the Page Render Server module.
</description>
Expand Down Expand Up @@ -128,8 +128,9 @@
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -146,6 +147,19 @@
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
<version>1.0.18</version>
<scope>provided</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package com.peregrine.pagerender.server.helpers;

import com.peregrine.adaption.PerPage;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.models.factory.ModelFactory;
import org.apache.sling.scripting.sightly.pojo.Use;
import org.slf4j.Logger;

import javax.jcr.Node;
import javax.jcr.Session;
import javax.script.Bindings;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Objects;

import static com.peregrine.commons.util.PerConstants.JCR_CONTENT;

public class BaseHelper implements Use {

// GLOBAL OBJECTS (from Use API Binding)
private Node currentNode;
private Session currentSession;
private Logger log;
private PrintWriter out;
private ValueMap properties;
private BufferedReader reader;
private SlingHttpServletRequest request;
private ResourceResolver resolver;
private Resource resource;
private SlingHttpServletResponse response;
private SlingScriptHelper sling;

// Peregrine API
private Object model;
private Resource siteRoot;
private PerPage currentPage;
private String pagePath;

// Constants
public static String CURRENT_NODE = "currentNode";
public static String CURRENT_SESSION = "currentSession";
public static String LOG = "log";
public static String OUT = "out";
public static String PROPERTIES = "properties";
public static String READER = "reader";
public static String REQUEST = "request";
public static String RESOLVER = "resolver";
public static String RESOURCE = "resource";
public static String RESPONSE = "response";
public static String SLING = "sling";

public void init(Bindings bindings) {
// initialize all global bindings (minus caconfig)
currentNode = (Node) bindings.get(CURRENT_NODE);
currentSession = (Session) bindings.get(CURRENT_SESSION);
log = (Logger) bindings.get(LOG);
out = (PrintWriter) bindings.get(OUT);
properties = (ValueMap) bindings.get(PROPERTIES);
reader = (BufferedReader) bindings.get(READER);
request = (SlingHttpServletRequest) bindings.get(REQUEST);
resolver = (ResourceResolver) bindings.get(RESOLVER);
resource = (Resource) bindings.get(RESOURCE);
response = (SlingHttpServletResponse) bindings.get(RESPONSE);
sling = (SlingScriptHelper) bindings.get(SLING);

// initialize peregrine api
pagePath = request.getRequestPathInfo().getResourcePath();
pagePath = pagePath.substring(0, pagePath.indexOf(JCR_CONTENT));
Resource pageRes = resolver.getResource(pagePath);
if (Objects.nonNull(pageRes)){
currentPage = pageRes.adaptTo(PerPage.class);
}
if (Objects.nonNull(currentPage)){
siteRoot = currentPage.getSiteResource();
}
try {
model = sling.getService(ModelFactory.class).getModelFromResource(resource);
if (Objects.isNull(model)) {
model = sling.getService(ModelFactory.class).getModelFromRequest(request);
}
} catch(Throwable t) {
log.warn("could not get model for "+resource.getPath());
}
}

public PrintWriter getOut() {
return out;
}

public ValueMap getProperties() {
return properties;
}

public BufferedReader getReader() {
return reader;
}

public SlingHttpServletRequest getRequest() {
return request;
}

public ResourceResolver getResolver() {
return resolver;
}

public Resource getResource() {
return resource;
}

public SlingHttpServletResponse getResponse() {
return response;
}

public SlingScriptHelper getSling() {
return sling;
}

public Object getModel() {
return model;
}

public Resource getSiteRoot() {
return siteRoot;
}

public PerPage getCurrentPage() {
return currentPage;
}

public String getPagePath() {
return pagePath;
}

public Node getCurrentNode() {
return currentNode;
}

public Session getCurrentSession() {
return currentSession;
}

public Logger getLog() {
return log;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.peregrine.pagerender.server.helpers;

import javax.script.Bindings;
import com.peregrine.pagerender.server.models.PageModel;

import java.util.Objects;

public class PageHelper extends BaseHelper {

public String getPath() {
return this.getResource().getPath();
}

public String getSiteRootPath() {
return Objects.nonNull(getSiteRoot()) ? getSiteRoot().getPath() : null;
}

public String getModelClass() {
return Objects.nonNull(getModel()) ? getModel().getClass().toString() : null;
}

public String[] getSiteCSS(){
PageModel page = getResource().adaptTo(PageModel.class);
return page.getSiteCSS();
}

public void init(Bindings bindings) {
super.init(bindings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,28 @@
* #L%
*/

import static com.peregrine.commons.util.PerConstants.JACKSON;
import static com.peregrine.commons.util.PerConstants.JSON;
import static com.peregrine.pagerender.server.models.PageRenderServerConstants.PR_SERVER_COMPONENT_CONTAINER_TYPE;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.peregrine.adaption.PerPage;
import com.peregrine.nodetypes.models.AbstractComponent;
import com.peregrine.nodetypes.models.IComponent;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.CompositeValueMap;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import javax.annotation.PostConstruct;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static com.peregrine.commons.util.PerConstants.JACKSON;
import static com.peregrine.commons.util.PerConstants.JCR_CONTENT;
import static com.peregrine.commons.util.PerConstants.JSON;
import static com.peregrine.pagerender.server.models.PageRenderServerConstants.PR_SERVER_COMPONENT_CONTAINER_TYPE;

/**
* Created by rr on 12/2/2016.
Expand All @@ -51,6 +60,14 @@
extensions = JSON)
public class Container extends AbstractComponent {

private ResourceResolver resolver;
private String pagePath;
private Resource page;
private PerPage templatePage;
private PerPage perPage;
private String relativePath;
private Resource templateContainer;

@Inject
@Named(".")
private List<IComponent> children;
Expand All @@ -64,4 +81,47 @@ public Container(Resource r) {
public List<IComponent> getChildren() {
return children;
}

public List<Resource> getCombinedResources(){
if (Objects.isNull(resolver)){
setup();
}
List<Resource> merged = new ArrayList<>();
// get template container children, add them to the list
if(Objects.nonNull(templateContainer)){
templateContainer.getChildren().forEach(resource -> merged.add(resource));
}
// get page container children
this.getResource().getChildren().forEach(resource -> {
merged.add(resource);
});
return merged;
}

public ValueMap getCombinedProperties(){
if (Objects.isNull(resolver)){
setup();
}
ValueMap contentVM = this.getResource().getValueMap();
if (Objects.nonNull(templateContainer)){
ValueMap templateVM = templateContainer.getValueMap();
return new CompositeValueMap(contentVM, templateVM, true);
} else {
return contentVM;
}
}


void setup() {
resolver = this.getResource().getResourceResolver();
pagePath = this.getResource().getPath().substring(0, this.getResource().getPath().indexOf(JCR_CONTENT));
page = resolver.getResource(pagePath);
perPage = page.adaptTo(PerPage.class);
templatePage = perPage.getTemplate();
relativePath = this.getPath();
// find the container under the template
if (Objects.nonNull(templatePage)) {
templateContainer = resolver.getResource(templatePage.getPath() + relativePath);
}
}
}
Loading

0 comments on commit f5bce05

Please sign in to comment.