This is an automated email from the ASF dual-hosted git repository.
jamesyong pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new b18dd6a Improved: Show border and file name for content rendered from ftl (OFBIZ-12002) b18dd6a is described below commit b18dd6a9ce39a595f6d1eebdb83f1b583a812d1d Author: James Yong <[hidden email]> AuthorDate: Sat Sep 12 20:10:08 2020 +0800 Improved: Show border and file name for content rendered from ftl (OFBIZ-12002) To reduce the need to view the page source from the browser. Activated when print.verbose=true and widget.verbose=true. Thanks: Jacques for review --- .../java/org/apache/ofbiz/base/util/UtilHtml.java | 35 ++++++++++++++++++++-- .../org/apache/ofbiz/widget/model/HtmlWidget.java | 19 +++++++----- .../widget/renderer/html/HtmlWidgetRenderer.java | 24 ++++++++++++++- themes/common-theme/webapp/common/css/info.css | 19 ++++++++++++ .../webapp/common/js/util/OfbizUtil.js | 8 +++++ themes/common-theme/widget/Theme.xml | 1 + 6 files changed, 95 insertions(+), 11 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHtml.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHtml.java index 94f72c3..bbafaaf 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHtml.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHtml.java @@ -18,6 +18,7 @@ *******************************************************************************/ package org.apache.ofbiz.base.util; +import org.apache.ofbiz.widget.model.ThemeFactory; import org.jsoup.parser.ParseError; import org.jsoup.parser.Parser; @@ -28,9 +29,12 @@ import javax.xml.stream.events.EndElement; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Stack; @@ -39,6 +43,7 @@ public final class UtilHtml { private static final String MODULE = UtilHtml.class.getName(); private static final Parser JSOUP_HTML_PARSER = createJSoupHtmlParser(); private static final String[] TAG_SHOULD_CLOSE_LIST = new String[]{"div"}; + private static List<String> visualThemeBasePathsName; private UtilHtml() { } private static Parser createJSoupHtmlParser() { @@ -110,7 +115,33 @@ public final class UtilHtml { return errorList; } - public static void logFormattedError(String content, String location, String error, String module) { - Debug.logError("[Parsing " + location + "] " + error, module); + public static List<String> getVisualThemeFolderNamesToExempt() { + if (visualThemeBasePathsName == null) { + try { + List<File> xmlThemes = ThemeFactory.getThemeXmlFiles(); + visualThemeBasePathsName = new ArrayList<>(); + String themePathKey = File.separator + "themes" + File.separator; + String pluginPathKey = File.separator + "plugins" + File.separator; + for (File xmlTheme : xmlThemes) { + String path = xmlTheme.toURI().toURL().toString(); + if (path.indexOf(themePathKey) > 0) { + path = path.substring(path.indexOf(themePathKey) + 8); + } else if (path.indexOf(pluginPathKey) > 0) { + path = path.substring(path.indexOf(pluginPathKey) + 9); + } + path = path.substring(0, path.indexOf(File.separator)); + if (!path.contains("common-theme") && !path.contains("ecommerce")) { + visualThemeBasePathsName.add(File.separator + path + File.separator); + } + } + } catch (IOException e) { + Debug.logError(e, MODULE); + } + } + return Collections.unmodifiableList(visualThemeBasePathsName); + } + + public static void logHtmlWarning(String content, String location, String error, String module) { + Debug.logWarning("[Parsing " + location + "] " + error, module); } } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java index bd21c03..4b275dc 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java @@ -269,14 +269,17 @@ public class HtmlWidget extends ModelScreenWidget { stringWriter.close(); if (Debug.verboseOn()) { - // check for unclosed tags - List<String> errorList = UtilHtml.hasUnclosedTag(data); - if (UtilValidate.isNotEmpty(errorList)) { - errorList.forEach(a -> UtilHtml.logFormattedError(data, location, a, MODULE)); - // check with JSoup Html Parser - List<ParseError> errList = UtilHtml.validateHtmlFragmentWithJSoup(data); - if (UtilValidate.isNotEmpty(errList)) { - errList.forEach(a -> UtilHtml.logFormattedError(data, location, a.toString(), MODULE)); + List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt(); + if (!themeBasePathsToExempt.stream().anyMatch(location::contains)) { + // check for unclosed tags + List<String> errorList = UtilHtml.hasUnclosedTag(data); + if (UtilValidate.isNotEmpty(errorList)) { + errorList.forEach(a -> UtilHtml.logHtmlWarning(data, location, a, MODULE)); + // check with JSoup Html Parser + List<ParseError> errList = UtilHtml.validateHtmlFragmentWithJSoup(data); + if (UtilValidate.isNotEmpty(errList)) { + errList.forEach(a -> UtilHtml.logHtmlWarning(data, location, a.toString(), MODULE)); + } } } } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java index 7c26716..caa1723 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java @@ -18,8 +18,12 @@ *******************************************************************************/ package org.apache.ofbiz.widget.renderer.html; +import java.io.File; import java.io.IOException; +import java.util.List; +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilHtml; import org.apache.ofbiz.base.util.UtilHttp; import org.apache.ofbiz.widget.model.ModelWidget; @@ -73,7 +77,25 @@ public class HtmlWidgetRenderer { } public static String formatBoundaryComment(String boundaryType, String widgetType, String widgetName) { - return "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + WHITE_SPACE; + String boundaryComment = "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + WHITE_SPACE; + if (!Debug.verboseOn()) { + return boundaryComment; + } + List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt(); + if (!themeBasePathsToExempt.stream().anyMatch(widgetName::contains)) { + // add additional visual label for non-theme ftl + switch (boundaryType) { + case "End": + String fileName = widgetName.substring(widgetName.lastIndexOf(File.separator) + 1); + return "</div><div class='info-overlay'><span class='info-overlay-item'>" + + fileName + + "</span></div></div>" + boundaryComment; + default: + return boundaryComment + "<div class='info-container'><div class='info-content'>"; + } + } else { + return boundaryComment; + } } public static String formatBoundaryJsComment(String boundaryType, String widgetType, String widgetName) { diff --git a/themes/common-theme/webapp/common/css/info.css b/themes/common-theme/webapp/common/css/info.css new file mode 100644 index 0000000..a861213 --- /dev/null +++ b/themes/common-theme/webapp/common/css/info.css @@ -0,0 +1,19 @@ +.info-container { + display: grid; +} +.info-overlay { + color: rgb(165, 42, 42); + justify-items: center; + z-index: 10; + border: 2px dashed rgba(236, 198, 48, 0.7); + transition: .5s ease-out; +} +.info-content, +.info-overlay { + grid-area: 1 / 1; +} +.info-overlay-item { + height: 50%; + background: rgba(255, 213, 70); + border: 2px dashed rgba(236, 198, 48); +} diff --git a/themes/common-theme/webapp/common/js/util/OfbizUtil.js b/themes/common-theme/webapp/common/js/util/OfbizUtil.js index 65f1940..9aa14bb 100644 --- a/themes/common-theme/webapp/common/js/util/OfbizUtil.js +++ b/themes/common-theme/webapp/common/js/util/OfbizUtil.js @@ -39,6 +39,14 @@ $(document).ready(function() { ajaxAutoCompleteDropDown(); // bindObservers will add observer on passed html section when DOM is ready. bindObservers("body"); + // fadeout info-overlay labels + setTimeout(function(){ + $('.info-overlay').fadeOut(1000, function(){ + $('.info-container').contents().unwrap(); + $('.info-content').contents().unwrap(); + $('.info-overlay').delay(1000).remove(); + }); + }, 3000); }); /* bindObservers function contains the code of adding observers and it can be called for specific section as well diff --git a/themes/common-theme/widget/Theme.xml b/themes/common-theme/widget/Theme.xml index 6730d5f..400729c 100644 --- a/themes/common-theme/widget/Theme.xml +++ b/themes/common-theme/widget/Theme.xml @@ -76,6 +76,7 @@ under the License. <!--Css styles: don't load them since they differ depending on theme --> <property name="VT_STYLESHEET['add']" value="/common/js/jquery/ui/jquery-ui-1.12.1.min.css"/> <property name="VT_STYLESHEET['add']" value="/common/js/jquery/plugins/datetimepicker/jquery-ui-timepicker-addon-1.6.3.min.css"/> + <property name="VT_STYLESHEET['add']" value="/common/css/info.css"/> </theme-properties> <templates><!-- Freemarker template use by this theme to render widget model--> |
Free forum by Nabble | Edit this page |