Updated Branches: refs/heads/master 0a78cab9e -> d3d61d898
Add DevTool component Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/d3d61d89 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/d3d61d89 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/d3d61d89 Branch: refs/heads/master Commit: d3d61d898975283759d9417c133bf09f1bc01a8d Parents: 0a78cab Author: Howard M. Lewis Ship <[email protected]> Authored: Thu Sep 5 12:16:17 2013 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Thu Sep 5 12:16:17 2013 -0700 ---------------------------------------------------------------------- .../tapestry5/corelib/components/DevTool.java | 147 +++++++++++++++++++ .../tapestry5/corelib/components/DevTool.tml | 35 +++++ .../integration/app1/components/Border.tml | 5 + 3 files changed, 187 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3d61d89/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DevTool.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DevTool.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DevTool.java new file mode 100644 index 0000000..0094f97 --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DevTool.java @@ -0,0 +1,147 @@ +// Copyright 2013 The Apache Software Foundation +// +// Licensed 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.tapestry5.corelib.components; + +import org.apache.tapestry5.BindingConstants; +import org.apache.tapestry5.ComponentResources; +import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.alerts.AlertManager; +import org.apache.tapestry5.annotations.Component; +import org.apache.tapestry5.annotations.Environmental; +import org.apache.tapestry5.annotations.Parameter; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.annotations.Symbol; +import org.apache.tapestry5.services.Request; +import org.apache.tapestry5.services.Session; +import org.apache.tapestry5.services.javascript.JavaScriptSupport; + +/** + * Renders a dropdown menu of useful options when developing. By default, the DevTool is disabled (invisible) + * during production. + * <p/> + * Note that due to conflicts between Prototype and jQuery, the dev tool is hidden after selecting an item from the menu. + * + * @tapestrydoc + * @since 5.4 + */ +public class DevTool +{ + /** + * If false, then the component does not render. Defaults to true unless production mode is enabled. + */ + @Parameter + private boolean enabled; + + /** + * If true, then the DevTool modifies its markup so as to work within a Bootstrap 3 NavBar. This renders + * the component as an {@code <li>} (instead of a {@code <div>}), and removes the "btn" CSS classes. + */ + @Parameter + private boolean navbar; + + /** + * Additional CSS selectors, e.g., "pull-right" or "dropup". + */ + @Parameter(name = "class", defaultPrefix = BindingConstants.LITERAL) + private String className; + + + @Inject + @Symbol(SymbolConstants.PRODUCTION_MODE) + private boolean productionMode; + + @Component(inheritInformalParameters = true, parameters = { + "class=zoneClass", + "elementName=${zoneElement}" + }) + private Zone devmodezone; + + + @Inject + private AlertManager alertManager; + + @Inject + private Request request; + + @Environmental + private JavaScriptSupport javaScriptSupport; + + @Inject + private ComponentResources resources; + + public String getZoneElement() + { + return navbar ? "li" : "div"; + } + + public String getZoneClass() + { + return "dropdown" + (className == null ? "" : " " + className); + } + + public String getTriggerClass() + { + return "dropdown-toggle" + (navbar ? "" : " btn btn-default btn-xs"); + } + + boolean defaultEnabled() + { + return !productionMode; + } + + /** + * When disabled, this prevents any part of the tool from rendering. + */ + boolean beginRender() + { + if (enabled) + { + javaScriptSupport.importStack("core").require("bootstrap/dropdown"); + } + + return enabled; + } + + Object onActionFromReset() + { + if (!productionMode) + { + resources.discardPersistentFieldChanges(); + + alertManager.info("Page state discarded."); + } + + return devmodezone.getBody(); + } + + Object onActionFromKill() + { + if (!productionMode) + { + Session session = request.getSession(false); + + if (session == null) + { + alertManager.info("No server-side session currently exist."); + } else + { + session.invalidate(); + alertManager.info("Server-side session invalidated."); + } + } + + return devmodezone.getBody(); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3d61d89/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/DevTool.tml ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/DevTool.tml b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/DevTool.tml new file mode 100644 index 0000000..0fcbbb5 --- /dev/null +++ b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/DevTool.tml @@ -0,0 +1,35 @@ +<div t:id="devmodezone" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"> + <a href="#" class="${triggerClass}" data-toggle="dropdown" title="Dev Tools"> + <t:glyphicon name="cog"/> + <span class="caret"/> + </a> + <ul class="dropdown-menu"> + <li class="dropdown-header">Developer Options</li> + <li class="dropdown-header"> + ${componentResources.page.componentResources.componentModel.componentClassName} + </li> + <li class="divider"></li> + <li> + <t:actionlink zone="^" t:id="reset">Reset Page State</t:actionlink> + </li> + <li> + <t:actionlink zone="^" t:id="kill">Kill Session</t:actionlink> + </li> + <li> + <t:pagelink page="prop:componentResources.pageName">Re-render + page <strong>${componentResources.pageName}</strong></t:pagelink> + </li> + <li> + <t:pagelink page="prop:componentResources.pageName" + parameters="{ 't:component-trace': true }"> + Re-render page w/ rendering comments + </t:pagelink> + </li> + <li class="divider"/> + <li> + <t:pagelink target="_new" page="t5dashboard">Go to T5 Dashboard + <t:glyphicon name="new-window"/> + </t:pagelink> + </li> + </ul> +</div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3d61d89/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml index 66e0fe0..555d51d 100644 --- a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml +++ b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml @@ -27,6 +27,9 @@ <t:pagelink page="prop:componentResources.pageName">Refresh Page</t:pagelink> </li> </ul> + <ul class="nav navbar-nav navbar-right"> + <t:devtool navbar="true"/> + </ul> </div> </div> </div> @@ -38,6 +41,8 @@ <div class="container"> <div class="main"> + <t:devtool class="pull-right"/> + <t:remove>alert-class is for the AlertsTest.check_informal_parameters test</t:remove> <t:alerts class="alert-class"/>
