This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new e85f6c1 Fixing the page editor to not inject the markup in the wrong
section and adding the common editing features
e85f6c1 is described below
commit e85f6c1e639b800f849dd4bd738e6fdcc240e422
Author: Dan Klco <[email protected]>
AuthorDate: Wed Feb 7 11:14:25 2018 -0500
Fixing the page editor to not inject the markup in the wrong section and
adding the common editing features
---
.../java/org/apache/sling/cms/CMSConstants.java | 5 ++
.../sling/cms/core/filters/EditIncludeFilter.java | 13 +++--
.../apache/sling/cms/core/models/Component.java | 64 +++++++++++++++++++++-
.../sling/cms/core/models/EditableResource.java | 35 ++++++------
cms/ui/src/main/frontend/src/scss/styles.scss | 2 +-
.../components/cms/pageeditbar/actions/actions.jsp | 35 ++++++++++++
.../components/cms/pageeditbar/pageeditbar.jsp | 1 +
.../propertieseditor.jsp} | 10 +---
.../jcr_root/libs/sling-cms/content/page/edit.json | 36 +++++++++++-
.../page/{edit.json => editproperties.json} | 8 +--
10 files changed, 166 insertions(+), 43 deletions(-)
diff --git a/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java
b/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java
index 17866ce..76e814d 100644
--- a/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java
+++ b/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java
@@ -57,6 +57,11 @@ public class CMSConstants {
public static final String NT_SITE = NAMESPACE + ":Site";
/**
+ * The Component type for pages
+ */
+ public static final String COMPONENT_TYPE_PAGE = "Page";
+
+ /**
* Description attribute name
*/
public static final String PN_DESCRIPTION = "jcr:description";
diff --git
a/cms/core/src/main/java/org/apache/sling/cms/core/filters/EditIncludeFilter.java
b/cms/core/src/main/java/org/apache/sling/cms/core/filters/EditIncludeFilter.java
index 3c5da1f..bea6f4d 100644
---
a/cms/core/src/main/java/org/apache/sling/cms/core/filters/EditIncludeFilter.java
+++
b/cms/core/src/main/java/org/apache/sling/cms/core/filters/EditIncludeFilter.java
@@ -34,6 +34,7 @@ import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.cms.CMSConstants;
+import org.apache.sling.cms.core.models.Component;
import org.apache.sling.cms.core.models.EditableResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,10 +105,9 @@ public class EditIncludeFilter implements Filter {
"<button
class=\"Sling-CMS__edit-button\" data-sling-cms-action=\"delete\"
data-sling-cms-path=\""
+
resource.getPath() + "\" title=\"Delete\">×</button>");
}
- Resource component =
resource.adaptTo(EditableResource.class).getComponent();
- if (component != null &&
component.getValueMap().containsKey(CMSConstants.PN_TITLE)) {
- writer.write("<span
class=\"Sling-CMS__component-title\">"
- +
component.getValueMap().get(CMSConstants.PN_TITLE, String.class) + "</span>");
+ Component component =
resource.adaptTo(EditableResource.class).getComponent();
+ if (component != null) {
+ writer.write("<span
class=\"Sling-CMS__component-title\">" + component.getTitle() + "</span>");
}
writer.write("</div>");
}
@@ -123,7 +123,10 @@ public class EditIncludeFilter implements Filter {
if (resource != null) {
EditableResource editResource = new
EditableResource(resource);
if (editResource != null) {
- editPath = editResource.getEditPath();
+ Component component =
editResource.getComponent();
+ if (component != null &&
!component.isType(CMSConstants.COMPONENT_TYPE_PAGE)) {
+ editPath = component.getEditPath();
+ }
}
}
return editPath;
diff --git
a/cms/core/src/main/java/org/apache/sling/cms/core/models/Component.java
b/cms/core/src/main/java/org/apache/sling/cms/core/models/Component.java
index ac7fd8e..3d0ac1f 100644
--- a/cms/core/src/main/java/org/apache/sling/cms/core/models/Component.java
+++ b/cms/core/src/main/java/org/apache/sling/cms/core/models/Component.java
@@ -19,6 +19,8 @@ package org.apache.sling.cms.core.models;
import javax.inject.Inject;
import javax.inject.Named;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;
@@ -30,14 +32,16 @@ import org.apache.sling.models.annotations.Optional;
public class Component {
@Inject
- @Named("jcr:title")
- private String title;
+ @Optional
+ @Named("componentType")
+ private String[] componentType;
private Resource resource;
@Inject
@Optional
- private String[] componentType;
+ @Named("jcr:title")
+ private String title;
public Component(Resource resource) {
this.resource = resource;
@@ -65,6 +69,21 @@ public class Component {
return true;
}
+ private Resource getComponentEditPath(Resource component) {
+ if (component != null) {
+ if (component.getChild("edit") != null) {
+ return component.getChild("edit");
+ } else {
+ component = component.getResourceResolver()
+
.getResource(component.getResourceResolver().getParentResourceType(component));
+ if (component != null) {
+ return getComponentEditPath(component);
+ }
+ }
+ }
+ return null;
+ }
+
/**
* @return the componentType
*/
@@ -73,6 +92,25 @@ public class Component {
}
/**
+ * Returns the path for the editor for this resource if available
+ *
+ * @return the editor path or null
+ */
+ public String getEditPath() {
+ Resource editResource = getEditResource();
+ return editResource != null ? editResource.getPath() : null;
+ }
+
+ /**
+ * Returns the resource for the editor for this resource if available
+ *
+ * @return the editor resource or null
+ */
+ public Resource getEditResource() {
+ return getComponentEditPath(resource);
+ }
+
+ /**
* @return the resource
*/
public Resource getResource() {
@@ -99,6 +137,26 @@ public class Component {
return result;
}
+ /**
+ * Returns true if the only component type on the component is the
specified
+ * type.
+ *
+ * @param string
+ * @return
+ */
+ public boolean isType(String type) {
+ boolean isType = false;
+ if (this.getComponentType() != null &&
ArrayUtils.contains(this.getComponentType(), type)) {
+ isType = true;
+ for (String t : getComponentType()) {
+ if (StringUtils.isNotBlank(t) &&
!type.equals(t)) {
+ isType = false;
+ }
+ }
+ }
+ return isType;
+ }
+
/*
* (non-Javadoc)
*
diff --git
a/cms/core/src/main/java/org/apache/sling/cms/core/models/EditableResource.java
b/cms/core/src/main/java/org/apache/sling/cms/core/models/EditableResource.java
index 1dde7be..a31f5c5 100644
---
a/cms/core/src/main/java/org/apache/sling/cms/core/models/EditableResource.java
+++
b/cms/core/src/main/java/org/apache/sling/cms/core/models/EditableResource.java
@@ -30,40 +30,34 @@ public class EditableResource {
public EditableResource(Resource resource) {
this.resource = resource;
}
+
+ public Component getComponent() {
+ if(getComponentResource() != null) {
+ return getComponentResource().adaptTo(Component.class);
+ }
+ return null;
+ }
/**
* Gets the component for the specified resource.
*
* @return the component for the specified resource
*/
- public Resource getComponent() {
+ public Resource getComponentResource() {
String resourceType = resource.getResourceType();
return resource.getResourceResolver().getResource(resourceType);
}
- private Resource getComponentEditPath(Resource component) {
- if (component != null) {
- if (component.getChild("edit") != null) {
- return component.getChild("edit");
- } else {
- component = component.getResourceResolver()
-
.getResource(component.getResourceResolver().getParentResourceType(component));
- if (component != null) {
- return getComponentEditPath(component);
- }
- }
- }
- return null;
- }
-
/**
* Returns the path for the editor for this resource if available
*
* @return the editor path or null
*/
public String getEditPath() {
- Resource editResource = getEditResource();
- return editResource != null ? editResource.getPath() : null;
+ if(getComponent() != null) {
+ return getComponent().getEditPath();
+ }
+ return null;
}
/**
@@ -72,7 +66,10 @@ public class EditableResource {
* @return the editor resource or null
*/
public Resource getEditResource() {
- return getComponentEditPath(getComponent());
+ if(getComponent() != null) {
+ return getComponent().getEditResource();
+ }
+ return null;
}
/**
diff --git a/cms/ui/src/main/frontend/src/scss/styles.scss
b/cms/ui/src/main/frontend/src/scss/styles.scss
index 66eee77..38b46db 100644
--- a/cms/ui/src/main/frontend/src/scss/styles.scss
+++ b/cms/ui/src/main/frontend/src/scss/styles.scss
@@ -20,7 +20,7 @@
a.Button {
display: inline-block;
- padding: .1em .5em;
+ padding: 8px 12px;
color: white;
background-color: #00678c;
border: 0;
diff --git
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/actions/actions.jsp
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/actions/actions.jsp
new file mode 100644
index 0000000..c53514e
--- /dev/null
+++
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/actions/actions.jsp
@@ -0,0 +1,35 @@
+<%-- /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */ --%>
+<%@include file="/libs/sling-cms/global.jsp"%>
+<div class="Pull-Right">
+ <c:forEach var="actionConfig" items="${sling:listChildren(resource)}">
+ <c:choose>
+ <c:when test="${actionConfig.valueMap.modal}">
+ <a class="Button Fetch-Modal"
data-title="${sling:encode(actionConfig.valueMap.title,'HTML_ATTR')}"
data-path="${actionConfig.valueMap.ajaxPath != null ?
actionConfig.valueMap.ajaxPath : '.Main-Content form'}"
href="${actionConfig.valueMap.prefix}${slingRequest.requestPathInfo.suffix}"
title="${sling:encode(actionConfig.valueMap.title,'HTML_ATTR')}">
+ ${actionConfig.valueMap.text}
+ </a>
+ </c:when>
+ <c:otherwise>
+ <a class="Button" ${actionConfig.valueMap.new
!= false ? 'target="_blank"' : ''}
href="${actionConfig.valueMap.prefix}${slingRequest.requestPathInfo.suffix}"
title="${sling:encode(actionConfig.valueMap.title,'HTML_ATTR')}">
+ ${actionConfig.valueMap.text}
+ </a>
+ </c:otherwise>
+ </c:choose>
+ </c:forEach>
+</div>
\ No newline at end of file
diff --git
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/pageeditbar.jsp
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/pageeditbar.jsp
index aa5498a..5a3cbee 100644
---
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/pageeditbar.jsp
+++
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/pageeditbar.jsp
@@ -23,5 +23,6 @@
<a href="/cms/start.html" target="_blank"
class="Sling-CMS__component-title" target="Sling CMS">
<img src="/etc/clientlibs/sling-cms/img/sling-logo.svg"
class="Sling-CMS__logo" />
</a>
+ <sling:include path="actions"
resourceType="sling-cms/components/cms/pageeditbar/actions" />
</div>
<sling:call script="/libs/sling-cms/components/editor/scripts/finalize.jsp" />
\ No newline at end of file
diff --git
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/pageeditbar.jsp
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/propertieseditor/propertieseditor.jsp
similarity index 65%
copy from
cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/pageeditbar.jsp
copy to
cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/propertieseditor/propertieseditor.jsp
index aa5498a..5e6a1b0 100644
---
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/pageeditbar.jsp
+++
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageeditbar/propertieseditor/propertieseditor.jsp
@@ -17,11 +17,5 @@
* under the License.
*/ --%>
<%@include file="/libs/sling-cms/global.jsp"%>
-<link rel="stylesheet" href="/etc/clientlibs/sling-cms-editor/editor.css" />
-<sling:call script="/libs/sling-cms/components/editor/scripts/init.jsp" />
-<div class="Sling-CMS__edit-bar">
- <a href="/cms/start.html" target="_blank"
class="Sling-CMS__component-title" target="Sling CMS">
- <img src="/etc/clientlibs/sling-cms/img/sling-logo.svg"
class="Sling-CMS__logo" />
- </a>
-</div>
-<sling:call script="/libs/sling-cms/components/editor/scripts/finalize.jsp" />
\ No newline at end of file
+<sling:adaptTo
adaptable="${sling:getRelativeResource(slingRequest.requestPathInfo.suffixResource,'jcr:content')}"
adaptTo="org.apache.sling.cms.core.models.EditableResource" var="editable" />
+<sling:include path="${editable.editPath}"
resourceType="sling-cms/components/editor/slingform"
replaceSuffix="${editable.resource.path}" />
\ No newline at end of file
diff --git
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/edit.json
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/edit.json
index 86ed6c2..762c96c 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/edit.json
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/edit.json
@@ -9,7 +9,41 @@
"sling:resourceType":
"sling-cms/components/general/container",
"pageeditbar": {
"jcr:primaryType": "nt:unstructured",
- "sling:resourceType":
"sling-cms/components/cms/pageeditbar"
+ "sling:resourceType":
"sling-cms/components/cms/pageeditbar",
+ "actions": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType":
"sling-cms/components/cms/pageeditbar/actions",
+ "edit": {
+ "jcr:primaryType":
"nt:unstructured",
+ "ajaxPath": ".Form-Ajax",
+ "modal": true,
+ "prefix":
"/cms/page/editproperties.html",
+ "title": "Edit Page",
+ "text": "✏"
+ },
+ "version": {
+ "jcr:primaryType":
"nt:unstructured",
+ "ajaxPath": ".versionmanager",
+ "modal": true,
+ "title": "Manage Versions",
+ "text": "⧖",
+ "prefix":
"/cms/shared/versions.html"
+ },
+ "movecopy": {
+ "jcr:primaryType":
"nt:unstructured",
+ "modal": true,
+ "title": "Move / Copy Page",
+ "text": "⇆",
+ "prefix":
"/cms/shared/movecopy.html"
+ },
+ "delete": {
+ "jcr:primaryType":
"nt:unstructured",
+ "modal": true,
+ "title": "Delete Page",
+ "text": "×",
+ "prefix":
"/cms/shared/delete.html"
+ }
+ }
},
"pageeditor": {
"jcr:primaryType": "nt:unstructured",
diff --git
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/edit.json
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/editproperties.json
similarity index 61%
copy from
cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/edit.json
copy to
cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/editproperties.json
index 86ed6c2..b6df91d 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/edit.json
+++
b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/page/editproperties.json
@@ -2,18 +2,14 @@
"jcr:primaryType": "sling:Page",
"jcr:content": {
"jcr:primaryType": "nt:unstructured",
- "jcr:title": "Edit",
+ "jcr:title": "Edit Properties",
"sling:resourceType": "sling-cms/components/pages/editor",
"container": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType":
"sling-cms/components/general/container",
- "pageeditbar": {
- "jcr:primaryType": "nt:unstructured",
- "sling:resourceType":
"sling-cms/components/cms/pageeditbar"
- },
"pageeditor": {
"jcr:primaryType": "nt:unstructured",
- "sling:resourceType":
"sling-cms/components/cms/pageeditor"
+ "sling:resourceType":
"sling-cms/components/cms/pageeditbar/propertieseditor"
}
}
}
--
To stop receiving notification emails like this one, please contact
[email protected].