You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2018/08/06 14:59:23 UTC

[sling-org-apache-sling-app-cms] 03/05: Adding optimizer support

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

commit 5c488bab2ef27efa3d5dfbcb49f318c2d304925b
Author: Dan Klco <dk...@apache.org>
AuthorDate: Mon Aug 6 10:24:54 2018 -0400

    Adding optimizer support
---
 .../components/cms/optimizefile/optimizefile.jsp   | 88 ++++++++++++++++++++++
 .../libs/sling-cms/content/file/optimize.json      | 21 ++++++
 2 files changed, 109 insertions(+)

diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/optimizefile/optimizefile.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/optimizefile/optimizefile.jsp
new file mode 100644
index 0000000..888d686
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/optimizefile/optimizefile.jsp
@@ -0,0 +1,88 @@
+<%-- /*
+ * 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"%>
+<sling:adaptTo var="optimizer" adaptable="${slingRequest.requestPathInfo.suffixResource}" adaptTo="org.apache.sling.fileoptim.models.OptimizeResource" />
+<sling:adaptTo var="optimizedFile" adaptable="${sling:getRelativeResource(slingRequest.requestPathInfo.suffixResource,'jcr:content')}" adaptTo="org.apache.sling.fileoptim.models.OptimizedFile" />
+<div class="Grid Fit-Medium">
+	<div class="Cell Medium-50">
+		<h4>Info</h4>
+		<c:choose>
+			<c:when test="${optimizer.canOptimize && optimizer.result.optimized}">
+				<dl>
+					<dt>
+						Algorithm
+					</dt>
+					<dd>
+						${optimizer.result.algorithm}
+					</dd>
+					<dt>
+						Original Size
+					</dt>
+					<dd>
+						${optimizer.result.originalSize}
+					</dd>
+					<dt>
+						Optimized Size
+					</dt>
+					<dd>
+						${optimizer.result.optimizedSize}
+					</dd>
+					<dt>
+						Savings
+					</dt>
+					<dd>
+						<fmt:formatNumber value="${optimizer.result.savings * 100}" type="number" groupingUsed="false" maxFractionDigits="2" />%
+					</dd>
+				</dl>
+				<form action="${slingRequest.requestPathInfo.suffix}" class="Form-Ajax" method="post">
+					<input type="hidden" name=":operation" value="fileoptim:optimize" />
+					<input type="submit" value="Optimize" />
+				</form>
+			</c:when>
+			<c:when test="${optimizer.optimized}">
+				<strong>Already Optimized</strong>
+				<dl>
+					<dt>
+						Algorithm
+					</dt>
+					<dd>
+						${optimizedFile.algorithm}
+					</dd>
+					<dt>
+						Savings
+					</dt>
+					<dd>
+						<fmt:formatNumber value="${optimizedFile.savings * 100}" type="number" groupingUsed="false" maxFractionDigits="2" />%
+					</dd>
+				</dl>
+				<form action="${slingRequest.requestPathInfo.suffix}" class="Form-Ajax" method="post">
+					<input type="hidden" name=":operation" value="fileoptim:restore" />
+					<input type="submit" value="Restore Original" />
+				</form>
+			</c:when>
+			<c:otherwise>
+				<strong>File Cannot be Optimized</strong>
+			</c:otherwise>
+		</c:choose>
+	</div>
+	<div class="Cell Medium-50">
+		<h4>Preview</h4>
+		<object data="/system/fileoptim/preview?path=${slingRequest.requestPathInfo.suffix}" class="Preview"></object>
+	</div>
+</div>
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/file/optimize.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/file/optimize.json
new file mode 100644
index 0000000..373a184
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/file/optimize.json
@@ -0,0 +1,21 @@
+{
+	"jcr:primaryType": "sling:Page",
+	"jcr:content": {
+		"sling:resourceType": "sling-cms/components/pages/base",
+		"jcr:title": "Optimize File",
+		"jcr:primaryType": "nt:unstructured",
+		"container": {
+			"jcr:primaryType": "nt:unstructured",
+			"sling:resourceType": "sling-cms/components/general/container",
+			"richtext": {
+				"jcr:primaryType": "nt:unstructured",
+				"sling:resourceType": "sling-cms/components/general/richtext",
+				"text": "<h3>Optimize File</h3>"
+			},
+			"slingform": {
+				"jcr:primaryType": "nt:unstructured",
+				"sling:resourceType": "sling-cms/components/cms/optimizefile"
+			}
+		}
+	}
+}
\ No newline at end of file