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-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/master by this push:
new ca1a3cc Fixing issues where the uploads weren't working, repeating
fields weren't editable, the template list was incorrect and the list of
available component groups was poorly laid out
ca1a3cc is described below
commit ca1a3ccbd2f6315d0244b17fc04b7d0f917d1148
Author: Dan Klco <[email protected]>
AuthorDate: Wed Sep 5 22:34:08 2018 -0400
Fixing issues where the uploads weren't working, repeating fields
weren't editable, the template list was incorrect and the list of
available component groups was poorly laid out
---
.../java/org/apache/sling/cms/core/CMSUtils.java | 10 +++-
.../apache/sling/cms/core/models/PageTemplate.java | 3 +
.../sling/cms/core/models/PageTemplateManager.java | 50 +++++++++-------
.../org/apache/sling/cms/core/models/Site.java | 21 +------
.../apache/sling/cms/core/models/SiteConfig.java | 66 ----------------------
.../apache/sling/cms/core/models/package-info.java | 2 +-
.../availablecomponenttypes.jsp | 6 +-
.../components/editor/fields/file/field.jsp | 4 +-
.../components/editor/fields/repeating/field.jsp | 4 +-
.../editor/scripts/pageTemplateOptions.jsp | 11 ++--
10 files changed, 57 insertions(+), 120 deletions(-)
diff --git a/core/src/main/java/org/apache/sling/cms/core/CMSUtils.java
b/core/src/main/java/org/apache/sling/cms/core/CMSUtils.java
index 09ccbf6..f09e4bd 100644
--- a/core/src/main/java/org/apache/sling/cms/core/CMSUtils.java
+++ b/core/src/main/java/org/apache/sling/cms/core/CMSUtils.java
@@ -17,6 +17,7 @@
package org.apache.sling.cms.core;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.ArrayUtils;
@@ -31,11 +32,14 @@ public class CMSUtils {
private CMSUtils() {
}
- public static final <T> List<T> adaptResources(List<Resource>
resources, Class<T> type) {
- List<T> values = new ArrayList<T>();
+ public static final <T> List<T> adaptResources(Collection<Resource>
resources, Class<T> type) {
+ List<T> values = new ArrayList<>();
if (resources != null) {
for (Resource resource : resources) {
- values.add(resource.adaptTo(type));
+ T val = resource.adaptTo(type);
+ if (val != null) {
+ values.add(val);
+ }
}
}
return values;
diff --git
a/core/src/main/java/org/apache/sling/cms/core/models/PageTemplate.java
b/core/src/main/java/org/apache/sling/cms/core/models/PageTemplate.java
index 98a661e..78aa1d5 100644
--- a/core/src/main/java/org/apache/sling/cms/core/models/PageTemplate.java
+++ b/core/src/main/java/org/apache/sling/cms/core/models/PageTemplate.java
@@ -68,6 +68,9 @@ public class PageTemplate {
* @return the allowedPaths
*/
public String[] getAllowedPaths() {
+ if (allowedPaths == null) {
+ return new String[0];
+ }
return allowedPaths;
}
diff --git
a/core/src/main/java/org/apache/sling/cms/core/models/PageTemplateManager.java
b/core/src/main/java/org/apache/sling/cms/core/models/PageTemplateManager.java
index a82c077..de7d8e4 100644
---
a/core/src/main/java/org/apache/sling/cms/core/models/PageTemplateManager.java
+++
b/core/src/main/java/org/apache/sling/cms/core/models/PageTemplateManager.java
@@ -19,8 +19,15 @@ package org.apache.sling.cms.core.models;
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.PostConstruct;
+
import org.apache.sling.api.resource.Resource;
+import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
+import org.apache.sling.cms.core.CMSUtils;
import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.injectorspecific.OSGiService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A model for retrieving the available templates to create a page under the
@@ -29,33 +36,38 @@ import org.apache.sling.models.annotations.Model;
@Model(adaptables = Resource.class)
public class PageTemplateManager {
- private SiteConfig siteConfig;
+ private static final Logger log =
LoggerFactory.getLogger(PageTemplateManager.class);
+
private Resource resource;
+ private List<PageTemplate> siteTemplates;
+
+ @OSGiService
+ private ConfigurationResourceResolver configurationResourceResolver;
+
public PageTemplateManager(Resource resource) {
- SiteManager siteMgr = resource.adaptTo(SiteManager.class);
- Site site = null;
- if (siteMgr != null) {
- site = siteMgr.getSite();
- }
- if (site != null) {
- this.siteConfig = site.getSiteConfig();
- }
this.resource = resource;
}
+ @PostConstruct
+ public void init() {
+ siteTemplates = CMSUtils.adaptResources(
+
configurationResourceResolver.getResourceCollection(resource, "site",
"templates"), PageTemplate.class);
+ }
+
public List<PageTemplate> getAvailableTemplates() {
String path = resource.getPath();
List<PageTemplate> availableTemplates = new ArrayList<>();
- if (siteConfig != null && siteConfig.getPageTemplates() !=
null) {
- for (PageTemplate template :
siteConfig.getPageTemplates()) {
- if (template != null &&
template.getAllowedPaths() != null) {
- for (String allowedPath :
template.getAllowedPaths()) {
- if (path.matches(allowedPath)) {
-
availableTemplates.add(template);
- break;
- }
- }
+
+ for (PageTemplate template : siteTemplates) {
+ log.debug("Checking to see if template {} is available
for path {}", template.getResource().getPath(),
+ path);
+ for (String allowedPath : template.getAllowedPaths()) {
+ log.trace("Checking to see if path {} matches
regex {}", path, allowedPath);
+ if (path.matches(allowedPath)) {
+ availableTemplates.add(template);
+ log.debug("Template {} is available for
path {}", template.getResource().getPath(), path);
+ break;
}
}
}
@@ -69,6 +81,6 @@ public class PageTemplateManager {
*/
@Override
public String toString() {
- return "PageTemplateManager [siteConfig=" + siteConfig + ",
resource=" + resource + "]";
+ return "PageTemplateManager [siteTemplates=" + siteTemplates +
", resource=" + resource + "]";
}
}
diff --git a/core/src/main/java/org/apache/sling/cms/core/models/Site.java
b/core/src/main/java/org/apache/sling/cms/core/models/Site.java
index 5f5b5eb..de9d4b6 100644
--- a/core/src/main/java/org/apache/sling/cms/core/models/Site.java
+++ b/core/src/main/java/org/apache/sling/cms/core/models/Site.java
@@ -55,11 +55,6 @@ public class Site {
}
@Inject
- @Named(PN_CONFIG)
- @Optional
- private String config;
-
- @Inject
@Named(CMSConstants.PN_DESCRIPTION)
@Optional
private String description;
@@ -135,18 +130,6 @@ public class Site {
return resource;
}
- public SiteConfig getSiteConfig() {
- Resource scr =
resource.getResourceResolver().getResource(getSiteConfigPath());
- if (scr != null) {
- return scr.adaptTo(SiteConfig.class);
- }
- return null;
- }
-
- public String getSiteConfigPath() {
- return config;
- }
-
public String getTitle() {
return title;
}
@@ -178,8 +161,8 @@ public class Site {
*/
@Override
public String toString() {
- return "Site [config=" + config + ", description=" +
description + ", locale=" + locale + ", resource="
- + resource + ", title=" + title + ", url=" +
url + "]";
+ return "Site [description=" + description + ", locale=" +
locale + ", resource=" + resource + ", title=" + title
+ + ", url=" + url + "]";
}
}
diff --git
a/core/src/main/java/org/apache/sling/cms/core/models/SiteConfig.java
b/core/src/main/java/org/apache/sling/cms/core/models/SiteConfig.java
deleted file mode 100644
index a2c4ce1..0000000
--- a/core/src/main/java/org/apache/sling/cms/core/models/SiteConfig.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.
- */
-package org.apache.sling.cms.core.models;
-
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.cms.core.CMSUtils;
-import org.apache.sling.models.annotations.Model;
-import org.apache.sling.models.annotations.Optional;
-
-/**
- * A model representing a site configuration.
- */
-@Model(adaptables = Resource.class)
-public class SiteConfig {
-
- @Inject
- @Optional
- private List<Resource> templates;
-
- @Inject
- @Optional
- private List<Resource> parameters;
-
- private Resource resource;
-
- public SiteConfig(Resource resource) {
- this.resource = resource;
- }
-
- /**
- * @return the pageTemplates
- */
- public List<PageTemplate> getPageTemplates() {
- return CMSUtils.adaptResources(templates, PageTemplate.class);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "SiteConfig [parameters=" + parameters + ", templates="
+ templates + ", resource=" + resource
- + "]";
- }
-
-}
diff --git
a/core/src/main/java/org/apache/sling/cms/core/models/package-info.java
b/core/src/main/java/org/apache/sling/cms/core/models/package-info.java
index ddf8d4f..bda8e2f 100644
--- a/core/src/main/java/org/apache/sling/cms/core/models/package-info.java
+++ b/core/src/main/java/org/apache/sling/cms/core/models/package-info.java
@@ -23,5 +23,5 @@
*
* @version 0.9.0
*/
[email protected]("0.10.0")
[email protected]("1.0.0")
package org.apache.sling.cms.core.models;
diff --git
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/availablecomponenttypes/availablecomponenttypes.jsp
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/availablecomponenttypes/availablecomponenttypes.jsp
index c5c71b3..44cfd1c 100644
---
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/availablecomponenttypes/availablecomponenttypes.jsp
+++
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/availablecomponenttypes/availablecomponenttypes.jsp
@@ -17,15 +17,15 @@
* under the License.
*/ --%>
<%@include file="/libs/sling-cms/global.jsp"%>
-<div class="Field-Group">
+<div class="field-container">
<label for="availableComponentTypes">
Available Component Types
</label>
- <div class="Field-Input">
+ <div class="field">
<c:set var="currentTypes"
value="|${fn:join(slingRequest.requestPathInfo.suffixResource.valueMap.availableComponentTypes,
'|')}|"/>
<sling:adaptTo var="componentManager"
adaptable="${resourceResolver}"
adaptTo="org.apache.sling.cms.core.models.ComponentManager" />
<c:forEach var="type"
items="${componentManager.componentTypes}">
- <label class="Checkbox-Label">
+ <label class="checkbox is-block">
<c:set var="search" value="|${type}|" />
<c:choose>
<c:when
test="${fn:contains(currentTypes,search)}">
diff --git
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/file/field.jsp
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/file/field.jsp
index a6f8e2f..9817976 100644
---
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/file/field.jsp
+++
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/file/field.jsp
@@ -26,7 +26,7 @@
</c:otherwise>
</c:choose>
<div class="repeating">
- <div disabled="disabled" class="repeating__template is-hidden">
+ <fieldset disabled="disabled" class="repeating__template is-hidden">
<div class="repeating__item Grid">
<div class="file has-name is-fullwidth">
<label class="file-label">
@@ -48,7 +48,7 @@
</label>
</div>
</div>
- </div>
+ </fieldset>
<div class="repeating__container">
<div class="repeating__item Grid">
<div class="file has-name is-fullwidth">
diff --git
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/repeating/field.jsp
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/repeating/field.jsp
index c01b4cb..fec99b8 100644
---
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/repeating/field.jsp
+++
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/repeating/field.jsp
@@ -18,7 +18,7 @@
*/ --%>
<%@include file="/libs/sling-cms/global.jsp"%>
<div class="repeating">
- <div disabled="disabled" class="repeating__template is-hidden">
+ <fieldset disabled="disabled" class="repeating__template is-hidden">
<div class="repeating__item field has-addons">
<div class="control">
<input type="${properties.type}" value=""
class="input" name="${properties.name}" ${required} ${disabled} />
@@ -29,7 +29,7 @@
</button>
</div>
</div>
- </div>
+ </fieldset>
<div class="repeating__container">
<c:forEach var="value"
items="${editProperties[properties.name]}">
<div class="repeating__item field has-addons">
diff --git
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/scripts/pageTemplateOptions.jsp
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/scripts/pageTemplateOptions.jsp
index 3f105f9..a551118 100644
---
a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/scripts/pageTemplateOptions.jsp
+++
b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/scripts/pageTemplateOptions.jsp
@@ -18,10 +18,11 @@
*/ --%>
<%@include file="/libs/sling-cms/global.jsp"%>
<option value="">Select Page Type</option>
-<sling:getCAConfigResources var="templates"
resource="${slingRequest.requestPathInfo.suffixResource}" bucket="site"
name="templates" />
-${templates}
-<c:forEach var="template" items="${templates}">
- <option value="${template.path}">
- <sling:encode value="${template.valueMap['jcr:title']}"
mode="HTML" />
+<sling:adaptTo var="templateMgr"
adaptable="${slingRequest.requestPathInfo.suffixResource}"
adaptTo="org.apache.sling.cms.core.models.PageTemplateManager" />
+templateMgr=${templateMgr}
+templates=${templateMgr.availableTemplates}
+<c:forEach var="template" items="${templateMgr.availableTemplates}">
+ <option value="${template.resource.path}">
+ <sling:encode value="${template.title}" mode="HTML" />
</option>
</c:forEach>
\ No newline at end of file