提交 220bd8ab 编写于 作者: J jglick

#130: store auto refresh status in a cookie.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1249 71c3de6d-444a-0410-be80-ed276b4c234a
上级 75624c75
......@@ -18,6 +18,7 @@ import java.util.SortedMap;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
import java.io.File;
import javax.servlet.http.HttpServletResponse;
/**
* @author Kohsuke Kawaguchi
......@@ -195,4 +196,35 @@ public class Functions {
}
private static final SimpleFormatter formatter = new SimpleFormatter();
public static void configureAutoRefresh(HttpServletRequest request, HttpServletResponse response) {
String param = request.getParameter("auto_refresh");
boolean refresh = isAutoRefresh(request);
if (param != null) {
refresh = Boolean.parseBoolean(param);
Cookie c = new Cookie("hudson_auto_refresh", Boolean.toString(refresh));
// Need to set path or it will not stick from e.g. a project page to the dashboard.
// Using request.getContextPath() might work but it seems simpler to just use the hudson_ prefix
// to avoid conflicts with any other web apps that might be on the same machine.
c.setPath("/");
response.addCookie(c);
}
if (refresh) {
response.addHeader("Refresh", "10");
}
}
public static boolean isAutoRefresh(HttpServletRequest request) {
String param = request.getParameter("auto_refresh");
if (param != null) {
return Boolean.parseBoolean(param);
}
for (Cookie c : request.getCookies()) {
if (c.getName().equals("hudson_auto_refresh")) {
return Boolean.parseBoolean(c.getValue());
}
}
return false;
}
}
......@@ -8,6 +8,7 @@
<st:contentType value="text/html;charset=UTF-8" />
<j:set var="rootURL" value="${request.contextPath}" />
<j:new var="h" className="hudson.Functions" /><!-- instead of JSP functions -->
<j:set var="_" value="${h.configureAutoRefresh(request, response)}"/>
<html>
<head>
<title>${h.appendIfNotNull(title, ' [Hudson]', 'Hudson')}</title>
......@@ -19,9 +20,6 @@
<script src="${rootURL}/scripts/sortable.js" type="text/javascript"></script>
<script src="${rootURL}/scripts/hudson-behavior.js" type="text/javascript"></script>
<meta name="ROBOTS" content="INDEX,NOFOLLOW" />
<j:if test="${request.getParameter('auto_refresh')}">
<meta http-equiv="Refresh" content="10" />
</j:if>
<j:set var="mode" value="header" />
<d:invokeBody />
</head>
......@@ -72,7 +70,7 @@
<td id="right-top-nav">
<span class="smallfont">
<j:choose>
<j:when test="${request.getParameter('auto_refresh')}">
<j:when test="${h.isAutoRefresh(request)}">
<a href="?auto_refresh=false">DISABLE AUTO REFRESH</a>
</j:when>
<j:otherwise>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册