提交 be28fe6d 编写于 作者: K kohsuke

Timeline view is available in more places.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34042 71c3de6d-444a-0410-be80-ed276b4c234a
上级 3c992383
/*
* The MIT License
*
* Copyright (c) 2010, InfraDNA, 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 hudson.model;
import hudson.util.RunList;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.koshuke.stapler.simile.timeline.Event;
import org.koshuke.stapler.simile.timeline.TimelineEventList;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Date;
/**
* UI widget for showing the SMILE timeline control.
*
* <p>
* Return this from your "getTimeline" method.
*
* @author Kohsuke Kawaguchi
* @since 1.372
*/
public class BuildTimelineWidget {
protected final RunList<?,?> builds;
public BuildTimelineWidget(RunList<?,?> builds) {
this.builds = builds;
}
public Run<?, ?> getFirstBuild() {
return builds.getFirstBuild();
}
public Run<?, ?> getLastBuild() {
return builds.getLastBuild();
}
public TimelineEventList doData(StaplerRequest req, @QueryParameter long min, @QueryParameter long max) throws IOException {
TimelineEventList result = new TimelineEventList();
for (Run r : builds.byTimestamp(min,max)) {
Event e = new Event();
e.start = r.getTime();
e.end = new Date(r.timestamp+r.getDuration());
e.title = r.getFullDisplayName();
// what to put in the description?
// e.description = "Longish description of event "+r.getFullDisplayName();
// e.durationEvent = true;
e.link = req.getContextPath()+'/'+r.getUrl();
BallColor c = r.getIconColor();
e.color = String.format("#%06X",c.getBaseColor().darker().getRGB()&0xFFFFFF);
e.classname = "event-"+c.noAnime().toString()+" " + (c.isAnimated()?"animated":"");
result.add(e);
}
return result;
}
}
......@@ -395,6 +395,10 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
return getNode().getSelfLabel().loadStatistics;
}
public BuildTimelineWidget getTimeline() {
return new BuildTimelineWidget(getBuilds());
}
/**
* {@inheritDoc}
*/
......
......@@ -72,7 +72,6 @@ import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
......@@ -101,15 +100,12 @@ import org.jfree.chart.renderer.category.StackedAreaRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.RectangleInsets;
import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.WebMethod;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.koshuke.stapler.simile.timeline.Event;
import org.koshuke.stapler.simile.timeline.TimelineEventList;
/**
* A job is an runnable entity under the monitoring of Hudson.
......@@ -1370,22 +1366,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
return Hudson.getInstance().getAuthorizationStrategy().getACL(this);
}
public TimelineEventList doTimelineData(StaplerRequest req, @QueryParameter long min, @QueryParameter long max) throws IOException {
TimelineEventList result = new TimelineEventList();
for (RunT r : getBuildsByTimestamp(min,max)) {
Event e = new Event();
e.start = r.getTime();
e.end = new Date(r.timestamp+r.getDuration());
e.title = r.getFullDisplayName();
// what to put in the description?
// e.description = "Longish description of event "+r.getFullDisplayName();
// e.durationEvent = true;
e.link = req.getContextPath()+'/'+r.getUrl();
BallColor c = r.getIconColor();
e.color = String.format("#%06X",c.getBaseColor().darker().getRGB()&0xFFFFFF);
e.classname = "event-"+c.noAnime().toString()+" " + (c.isAnimated()?"animated":"");
result.add(e);
}
return result;
public BuildTimelineWidget getTimeline() {
return new BuildTimelineWidget(getBuilds());
}
}
......@@ -23,6 +23,7 @@
*/
package hudson.model;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import com.thoughtworks.xstream.XStream;
import hudson.CopyOnWrite;
import hudson.FeedAdapter;
......@@ -362,14 +363,14 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
*
* TODO: do we need some index for this?
*/
public List<AbstractBuild> getBuilds() {
@WithBridgeMethods(List.class)
public RunList getBuilds() {
List<AbstractBuild> r = new ArrayList<AbstractBuild>();
for (AbstractProject<?,?> p : Hudson.getInstance().getAllItems(AbstractProject.class))
for (AbstractBuild<?,?> b : p.getBuilds())
if(b.hasParticipant(this))
r.add(b);
Collections.sort(r,Run.ORDER_BY_DATE);
return r;
return RunList.fromRuns(r);
}
/**
......
......@@ -614,6 +614,10 @@ public abstract class View extends AbstractModelObject implements AccessControll
public RunList getBuilds() {
return new RunList(this);
}
public BuildTimelineWidget getTimeline() {
return new BuildTimelineWidget(getBuilds());
}
private void rss(StaplerRequest req, StaplerResponse rsp, String suffix, RunList runs) throws IOException, ServletException {
RSS.forwardToRss(getDisplayName()+ suffix, getUrl(),
......
......@@ -44,6 +44,8 @@ import java.util.List;
/**
* {@link List} of {@link Run}s, sorted in the date order.
*
* TODO: this should be immutable
*
* @author Kohsuke Kawaguchi
*/
public class RunList<J extends Job<J,R>, R extends Run<J,R>> extends ArrayList<R> {
......@@ -54,6 +56,14 @@ public class RunList<J extends Job<J,R>, R extends Run<J,R>> extends ArrayList<R
addAll(j.getBuilds());
}
public R getFirstBuild() {
return isEmpty() ? null : get(0);
}
public R getLastBuild() {
return isEmpty() ? null : get(size()-1);
}
public RunList(View view) {// this is a type unsafe operation
for (Item item : view.getItems())
for (Job<?,?> j : item.getAllJobs())
......@@ -141,9 +151,7 @@ public class RunList<J extends Job<J,R>, R extends Run<J,R>> extends ArrayList<R
int e = Collections.binarySearch(TIMESTAMP_ADAPTER, end, DESCENDING_ORDER);
if (e<0) e=-(e+1); else e++; // max is exclusive, so the exact match should be excluded
removeRange(s,size());
removeRange(0,e);
return this;
return fromRuns(subList(e,s));
}
/**
......
<!--
The MIT License
Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt, Seiji Sogabe
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.
-->
<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">
<st:documentation>
Show timeline trend image. It takes two builds
</st:documentation>
<st:adjunct includes="org.kohsuke.stapler.simile.timeline" />
<div id="tl" style="height:250px; border:1px solid black;" />
<div id="status" />
<script>
<j:invokeStatic var="tz" className="java.util.TimeZone" method="getDefault"/>
var tz = ${tz.rawOffset / 3600000};
<![CDATA[
window.addEventListener('load', function() {
var tl_el = document.getElementById("tl");
var eventSource1 = new Timeline.DefaultEventSource();
eventSource1.loaded = {};
var interval = 24*60*60*1000;
eventSource1.ensureVisible = function(band) {
// make sure all data are loaded for the portion visible in the band
// $('status').innerHTML = "min="+band.getMinDate()+" max="+band.getMaxDate();
var min = Math.floor(band.getMinDate().getTime()/interval);
var max = Math.ceil(band.getMaxDate().getTime()/interval);
for (var i=min; i<=max; i++) {
if (!this.loaded[i]) {
this.loaded[i] = true;
new Ajax.Request("timeline/data",{
method:"POST",
parameters: {min: i*interval, max:(i+1)*interval},
onSuccess: function(t) {
try {
eventSource1.loadJSON(eval('('+t.responseText+')'),'.');
} catch (e) {
alert(e);
}
}
});
}
}
};
var theme1 = Timeline.ClassicTheme.create();
// theme1.autoWidth = true; // Set the Timeline's "width" automatically.
// Set autoWidth on the Timeline's first band's theme,
// will affect all bands.
theme1.timeline_start = new Date(${it.firstBuild.timeInMillis-24*60*60*1000});
theme1.timeline_stop = new Date(${it.lastBuild.timeInMillis+24*60*60*1000});
var d = theme1.timeline_stop;
var bandInfos = [
// the bar that shows outline
Timeline.createBandInfo({
width: "50px", // set to a minimum, autoWidth will then adjust
intervalUnit: Timeline.DateTime.DAY,
intervalPixels: 200,
eventSource: eventSource1,
date: d,
timeZone: tz,
theme: theme1,
layout: 'overview' // original, overview, detailed
}),
// the main area
Timeline.createBandInfo({
width: "200px",
eventSource: eventSource1,
timeZone: tz,
theme: theme1,
intervalUnit: Timeline.DateTime.HOUR,
intervalPixels: 200
})
];
bandInfos[0].highlight = true;
bandInfos[0].syncWith = 1;
// create the Timeline
var tl = Timeline.create(tl_el, bandInfos, Timeline.HORIZONTAL);
tl.getBand(0).addOnScrollListener(function(band) {
eventSource1.ensureVisible(band);
});
tl.layout(); // display the Timeline
// if resized, redo layout
var resizeTimerID = null;
window.addEventListener('resize',function() {
if (resizeTimerID == null) {
resizeTimerID = window.setTimeout(function() {
resizeTimerID = null;
tl.layout();
}, 500);
}
},false);
},false);
]]></script>
</j:jelly>
......@@ -30,6 +30,10 @@ THE SOFTWARE.
<img src="${imagesURL}/48x48/notepad.gif" alt=""/>
${%title(it.displayName)}
</h1>
<st:include page="control.jelly" it="${it.timeline}" />
<div style="height:2em"/><!-- spacer -->
<t:buildListTable builds="${it.builds}" jobBaseUrl="${rootURL}/" />
</l:main-panel>
</l:layout>
......
......@@ -29,106 +29,9 @@ THE SOFTWARE.
<st:include page="sidepanel.jelly" />
<l:main-panel>
<h1>${%Timeline}</h1>
<st:adjunct includes="org.kohsuke.stapler.simile.timeline" />
<div id="tl" style="height:250px; border:1px solid black;" />
<div id="status" />
<script>
<j:invokeStatic var="tz" className="java.util.TimeZone" method="getDefault"/>
var tz = ${tz.rawOffset / 3600000};
<![CDATA[
window.addEventListener('load', function() {
var tl_el = document.getElementById("tl");
var eventSource1 = new Timeline.DefaultEventSource();
eventSource1.loaded = {};
var interval = 24*60*60*1000;
eventSource1.ensureVisible = function(band) {
// make sure all data are loaded for the portion visible in the band
// $('status').innerHTML = "min="+band.getMinDate()+" max="+band.getMaxDate();
var min = Math.floor(band.getMinDate().getTime()/interval);
var max = Math.ceil(band.getMaxDate().getTime()/interval);
for (var i=min; i<=max; i++) {
if (!this.loaded[i]) {
this.loaded[i] = true;
new Ajax.Request("timelineData",{
method:"POST",
parameters: {min: i*interval, max:(i+1)*interval},
onSuccess: function(t) {
try {
eventSource1.loadJSON(eval('('+t.responseText+')'),'.');
} catch (e) {
alert(e);
}
}
});
}
}
};
var theme1 = Timeline.ClassicTheme.create();
// theme1.autoWidth = true; // Set the Timeline's "width" automatically.
// Set autoWidth on the Timeline's first band's theme,
// will affect all bands.
theme1.timeline_start = new Date(${it.firstBuild.timeInMillis-24*60*60*1000});
theme1.timeline_stop = new Date(${it.lastBuild.timeInMillis+24*60*60*1000});
var d = theme1.timeline_stop;
var bandInfos = [
// the bar that shows outline
Timeline.createBandInfo({
width: "50px", // set to a minimum, autoWidth will then adjust
intervalUnit: Timeline.DateTime.DAY,
intervalPixels: 200,
eventSource: eventSource1,
date: d,
timeZone: tz,
theme: theme1,
layout: 'overview' // original, overview, detailed
}),
// the main area
Timeline.createBandInfo({
width: "200px",
eventSource: eventSource1,
timeZone: tz,
theme: theme1,
intervalUnit: Timeline.DateTime.HOUR,
intervalPixels: 200
})
];
bandInfos[0].highlight = true;
bandInfos[0].syncWith = 1;
// create the Timeline
var tl = Timeline.create(tl_el, bandInfos, Timeline.HORIZONTAL);
tl.getBand(0).addOnScrollListener(function(band) {
eventSource1.ensureVisible(band);
});
tl.layout(); // display the Timeline
// if resized, redo layout
var resizeTimerID = null;
window.addEventListener('resize',function() {
if (resizeTimerID == null) {
resizeTimerID = window.setTimeout(function() {
resizeTimerID = null;
tl.layout();
}, 500);
}
},false);
},false);
]]></script>
<st:include page="control.jelly" it="${it.timeline}" />
<div style="height:2em"/><!-- spacer -->
<h1>${%Build Time Trend}</h1>
<j:choose>
<j:when test="${it.builds.size()&gt;1}">
......
......@@ -31,6 +31,10 @@ THE SOFTWARE.
<img src="${imagesURL}/48x48/notepad.gif" alt=""/>
${%buildHistory(it.class.name=='hudson.model.AllView' ? app.displayName : it.displayName)}
</h1>
<st:include page="control.jelly" it="${it.timeline}" />
<div style="height:2em"/><!-- spacer -->
<div>
<a href="cc.xml">${%Export as plain XML}</a>
</div>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册