提交 15d32562 编写于 作者: K Kohsuke Kawaguchi

Timestamp should be a property, and formatting should be done in the UI.

上级 81bf5452
...@@ -29,10 +29,11 @@ import hudson.Functions; ...@@ -29,10 +29,11 @@ import hudson.Functions;
import hudson.model.Computer; import hudson.model.Computer;
import hudson.model.User; import hudson.model.User;
import org.acegisecurity.Authentication;
import org.jvnet.localizer.Localizable; import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.export.ExportedBean; import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported; import org.kohsuke.stapler.export.Exported;
import javax.annotation.Nonnull;
import java.util.Date; import java.util.Date;
/** /**
...@@ -42,32 +43,51 @@ import java.util.Date; ...@@ -42,32 +43,51 @@ import java.util.Date;
* <p> * <p>
* {@link OfflineCause} must have <tt>cause.jelly</tt> that renders a cause * {@link OfflineCause} must have <tt>cause.jelly</tt> that renders a cause
* into HTML. This is used to tell users why the node is put offline. * into HTML. This is used to tell users why the node is put offline.
* This view should render a block element like DIV. * This view should render a block element like DIV.
* *
* @author Kohsuke Kawaguchi * @author Kohsuke Kawaguchi
* @since 1.320 * @since 1.320
*/ */
@ExportedBean @ExportedBean
public abstract class OfflineCause { public abstract class OfflineCause {
protected final long timestamp = System.currentTimeMillis();
/**
* Timestamp in which the event happened.
*
* @since 1.612
*/
@Exported
public long getTimestamp() {
return timestamp;
}
/**
* Same as {@link #getTimestamp()} but in a different type.
*
* @since 1.612
*/
public final @Nonnull Date getTime() {
return new Date(timestamp);
}
/** /**
* {@link OfflineCause} that renders a static text, * {@link OfflineCause} that renders a static text,
* but without any further UI. * but without any further UI.
*/ */
public static class SimpleOfflineCause extends OfflineCause { public static class SimpleOfflineCause extends OfflineCause {
public final Localizable description; public final Localizable description;
public final Date timestamp;
/** /**
* @since 1.571 * @since 1.571
*/ */
protected SimpleOfflineCause(Localizable description) { protected SimpleOfflineCause(Localizable description) {
this.description = description; this.description = description;
this.timestamp = new Date();
} }
@Exported(name="description") @Override @Exported(name="description") @Override
public String toString() { public String toString() {
return "[" + timestamp.toString() + "] " + description.toString(); return description.toString();
} }
} }
......
...@@ -23,6 +23,13 @@ THE SOFTWARE. ...@@ -23,6 +23,13 @@ THE SOFTWARE.
--> -->
<?jelly escape-by-default='true'?> <?jelly escape-by-default='true'?>
<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: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" xmlns:i="jelly:fmt">
<p class="warning"><j:out value="${it}" /></p> <div class="warning">
<div class="timestamp">
<i:formatDate value="${it.time}" type="both" dateStyle="medium" timeStyle="medium"/>
</div>
<div class="message">
<j:out value="${it}" />
</div>
</div>
</j:jelly> </j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册