From commits-return-70817-archive-asf-public=cust-asf.ponee.io@sling.apache.org Mon Sep 17 17:42:24 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E586D18067C for ; Mon, 17 Sep 2018 17:42:22 +0200 (CEST) Received: (qmail 13616 invoked by uid 500); 17 Sep 2018 15:42:22 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 13489 invoked by uid 99); 17 Sep 2018 15:42:21 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Sep 2018 15:42:21 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 38F6A828BA; Mon, 17 Sep 2018 15:42:21 +0000 (UTC) Date: Mon, 17 Sep 2018 15:42:22 +0000 To: "commits@sling.apache.org" Subject: [sling-org-apache-sling-app-cms] 02/10: initial refactoring of content breadcrumbs and content table MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: jeb@apache.org In-Reply-To: <153719894085.28725.5445399499046228836@gitbox.apache.org> References: <153719894085.28725.5445399499046228836@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: sling-org-apache-sling-app-cms X-Git-Refname: refs/heads/SLING-7900 X-Git-Reftype: branch X-Git-Rev: bea0d8cfc49237013085233488ffb20493448abb X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180917154221.38F6A828BA@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. jeb pushed a commit to branch SLING-7900 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git commit bea0d8cfc49237013085233488ffb20493448abb Author: JE Bailey AuthorDate: Mon Sep 10 16:36:03 2018 -0400 initial refactoring of content breadcrumbs and content table --- .../cms/core/models/components/Breadcrumbs.java | 94 ++++-- .../cms/core/models/components/ContentTable.java | 141 ++++++++ ui/pom.xml | 14 + ui/src/main/frontend/src/js/cms.js | 11 +- .../sling-cms/components/cms/columns/name/name.jsp | 2 +- .../components/cms/columns/publish/publish.jsp | 10 +- .../cms/contentbreadcrumb/contentbreadcrumb.jsp | 12 +- .../components/cms/contenttable/contenttable.jsp | 37 +-- .../libs/sling-cms/content/site/content.json | 364 +++++---------------- .../libs/sling-cms/content/site/sites.json | 163 +++------ .../libs/sling-cms/content/static/content.json | 176 +++++----- .../resources/jcr_root/libs/sling-cms/global.jsp | 2 +- ui/src/main/resources/jcr_root/web-fragment.xml | 5 - 13 files changed, 458 insertions(+), 573 deletions(-) diff --git a/core/src/main/java/org/apache/sling/cms/core/models/components/Breadcrumbs.java b/core/src/main/java/org/apache/sling/cms/core/models/components/Breadcrumbs.java index 4c7da58..a856490 100644 --- a/core/src/main/java/org/apache/sling/cms/core/models/components/Breadcrumbs.java +++ b/core/src/main/java/org/apache/sling/cms/core/models/components/Breadcrumbs.java @@ -17,77 +17,123 @@ package org.apache.sling.cms.core.models.components; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; -import javax.inject.Named; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.models.annotations.Default; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; import org.apache.sling.models.annotations.injectorspecific.Self; -@Model(adaptables = SlingHttpServletRequest.class,defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL) +@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class Breadcrumbs { @Inject + @Via("resource") int depth; @Inject - @Named("jcr:title") - String title; + Resource resource; @Inject + @Via("resource") String prefix; - + @Inject - Resource resource; - + @Via("resource") + @Default(values = "jcr:title") + String titleProp; + @Self SlingHttpServletRequest servletRequest; - + Resource suffixResource; - + List pathData = new ArrayList<>(); @PostConstruct public void postConstruct() { suffixResource = servletRequest.getRequestPathInfo().getSuffixResource(); - pathData.add(new PathData(prefix+resource.getPath(),title)); + if (suffixResource == null) { + return; + } + boolean first = true; + while (suffixResource.getParent() != null) { + String suffix = suffixResource.getPath(); + pathData.add(0, new PathData(prefix + suffix, getTitle(suffixResource),first)); + if (first) { + first = false; + } + suffixResource = suffixResource.getParent(); + } + while (--depth > 0) { + pathData.remove(0); + } + } + + private String getTitle(Resource resource) { + ValueMap map = resource.getValueMap(); + String title = map.get("jcr:title", String.class); + if (title != null) { + return title; + } + title = map.get("jcr:content/jcr:title", String.class); + if (title != null) { + return title; + } + return resource.getName(); } - + public String getTitle() { return null; } - + public List getPathData() { return pathData; } - - public String getString() { - return "flounder"; - } - - public static class PathData{ - + + public static class PathData { + private String href; private String title; - - public PathData(String href, String title) { + private boolean first; + + public PathData(String href, String title, boolean first) { this.href = href; this.title = title; + this.first= first; } + public String getHref() { - return href; //prefix + resource path + return href; // prefix + resource path } - //${parent.valueMap['jcr:title'] != null ? parent.valueMap['jcr:title'] : parent.valueMap['jcr:content/jcr:title']}" default="${parent.name}" + + // ${parent.valueMap['jcr:title'] != null ? parent.valueMap['jcr:title'] : + // parent.valueMap['jcr:content/jcr:title']}" default="${parent.name}" public String getTitle() { return title; } + public String getAria() { + if (first) { + return "aria-current='page'"; + } + return ""; + } + + public String getClassAttr() { + if (first) { + return "class='is-active'"; + } + return ""; + } + } } diff --git a/core/src/main/java/org/apache/sling/cms/core/models/components/ContentTable.java b/core/src/main/java/org/apache/sling/cms/core/models/components/ContentTable.java new file mode 100644 index 0000000..21ed513 --- /dev/null +++ b/core/src/main/java/org/apache/sling/cms/core/models/components/ContentTable.java @@ -0,0 +1,141 @@ +/* + * 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.components; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.models.annotations.DefaultInjectionStrategy; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; +import org.apache.sling.models.annotations.injectorspecific.Self; + +@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) +public class ContentTable { + + @Inject + @Via("resource") + private List columns; + + private String[] types; + + @Self + SlingHttpServletRequest slingRequest; + + @PostConstruct + public void init() { + Resource resource = slingRequest.getResource(); + ValueMap data = resource.getChild("columns").getValueMap(); + types = data.get("resourceTypes", new String[]{}); + } + + public List getColumnData() { + return columns.stream().map(ColumnData::new).filter(ColumnData::isEligible).collect(Collectors.toList()); + } + + public List getChildren() { + Resource suffix = slingRequest.getRequestPathInfo().getSuffixResource(); + if (suffix == null) { + return Collections.emptyList(); + } + List response = new ArrayList<>(); + suffix.listChildren().forEachRemaining(child -> { + for (String type:types) { + if (child.getResourceType().equals(type)) { + response.add(new ChildResourceData(child)); + } + } + }); + return response; + } + + public class ColumnData { + + private Resource resource; + + private String name; + + public ColumnData(Resource resource) { + this.resource = resource; + this.name = resource.getName(); + + } + + public String getClassString() { + String reply = ""; + switch (name) { + case "actions": + reply = "is-hidden"; + break; + case "publish": + reply = "has-text-centered"; + break; + } + return reply; + } + + public String getName() { + return name; + } + + public String getTitle() { + return resource.getValueMap().get("jcr:title", "foo"); + } + + public String getFieldResourceType() { + return resource.getValueMap().get("sling:resourceType", "foo"); + } + + public Resource getResource() { + return resource; + } + + public boolean isEligible() { + return true; + } + } + + public class ChildResourceData { + + private Resource resource; + + public ChildResourceData(Resource resource) { + this.resource = resource; + } + + public String getPath() { + return resource.getPath(); + } + + public String getDataType() { + return resource.getResourceType(); + } + + public boolean isEligible() { + return true; + } + } + +} diff --git a/ui/pom.xml b/ui/pom.xml index a5db13e..4a031e4 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -178,5 +178,19 @@ 0.9.1-SNAPSHOT provided + + org.apache.sling + + org.apache.sling.scripting.jsp.taglib + + 2.3.0 + provided + + + org.apache.geronimo.bundles + jstl + provided + + \ No newline at end of file diff --git a/ui/src/main/frontend/src/js/cms.js b/ui/src/main/frontend/src/js/cms.js index 97a9533..7f17092 100644 --- a/ui/src/main/frontend/src/js/cms.js +++ b/ui/src/main/frontend/src/js/cms.js @@ -39,7 +39,7 @@ Sling.CMS = { }, ui: { confirmMessage: function(title, message, complete){ - var $modal = $('