提交 e1837ec7 编写于 作者: K Kohsuke Kawaguchi 提交者: Stephen Connolly

Actions can now override their rendering in the parent model object.

上级 f4132a57
......@@ -58,7 +58,6 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
PAM authentication fails to restore group membership information on "remember me" tokens.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9094">issue 9094</a>)
......@@ -66,6 +65,8 @@ Upcoming changes</a>
Added an extension point to allow adding transient actions to computers.
<li class=rfe>
Added an extension point to allow associating custom properties with views.
<li class=rfe>
Actions can now override their rendering in the parent model object.
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -39,6 +39,7 @@ import hudson.tasks.test.TestResultProjectAction;
* while others do the former without the latter (for example, to just draw some graphs in <tt>floatingBox.jelly</tt>),
* and still some others do both.
*
* <h2>Views</h2>
* <p>
* If an action has a view named <tt>floatingBox.jelly</tt>,
* it will be displayed as a floating box on the top page of
......@@ -46,6 +47,19 @@ import hudson.tasks.test.TestResultProjectAction;
* the JUnit test result trend shows up in the project top page.
* See {@link TestResultProjectAction}.
*
* <p>
* On the target {@link ModelObject} page, actions are rendered as an item in the side panel
* by the "/lib/hudson:actions" jelly tag, but you can override this for your action by
* writing {@code action.jelly}. See the "actions" tag for what the default handling is and
* tweak from there. One of the use cases of this is to show nested actions, like where
* Jenkins show the option to wipe out the workspace inside the workspace link:
*
* <pre>
* &lt;l:task icon="images/24x24/folder.gif" href="${url}/ws/" title="${%Workspace}">
* &lt;l:task icon="images/24x24/folder-delete.gif" href="${url}/wipeOutWorkspace" title="${%Wipe Out Workspace}" />
* &lt;/l:task>
* </pre>
*
* <h2>Persistence</h2>
* <p>
* Actions are often persisted as a part of {@link Actionable}
......
......@@ -2388,9 +2388,12 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
}
public Object getDynamic(String token) {
for (Action a : getActions())
if(a.getUrlName().equals(token) || a.getUrlName().equals('/'+token))
for (Action a : getActions()) {
String url = a.getUrlName();
if (url==null) continue;
if (url.equals(token) || url.equals('/' + token))
return a;
}
for (Action a : getManagementLinks())
if(a.getUrlName().equals(token))
return a;
......
......@@ -27,9 +27,12 @@ THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:forEach var="action" items="${it.actions}">
<j:if test="${action.iconFileName!=null}">
<l:task icon="${h.getIconFilePath(action)}" title="${action.displayName}"
href="${h.getActionUrl(it.url,action)}" />
</j:if>
<!-- allow the action to take over the rendering, but otherwise fall back to the default -->
<st:include page="action.jelly" from="${action}" optional="true">
<j:if test="${action.iconFileName!=null}">
<l:task icon="${h.getIconFilePath(action)}" title="${action.displayName}"
href="${h.getActionUrl(it.url,action)}" />
</j:if>
</st:include>
</j:forEach>
</j:jelly>
\ No newline at end of file
/*
* The MIT License
*
* Copyright (c) 2011, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lib.hudson;
import hudson.model.InvisibleAction;
import hudson.model.RootAction;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestExtension;
/**
* @author Kohsuke Kawaguchi
*/
public class ActionsTest extends HudsonTestCase {
public void testOverride() throws Exception {
assertNotNull(createWebClient().goTo("").getElementById("bravo"));
}
@TestExtension
public static class RootActionImpl extends InvisibleAction implements RootAction {
}
}
<j:jelly xmlns:j="jelly:core">
<div>
<b id='bravo'>Bravo</b>
</div>
</j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册