提交 b110da62 编写于 作者: K kohsuke

playing with the SIMILE timeline component. It's still rather experimental,...

playing with the SIMILE timeline component. It's still rather experimental, but I'm commiting this so that I can play with it from home during the break.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24945 71c3de6d-444a-0410-be80-ed276b4c234a
上级 f29fe7c6
......@@ -333,7 +333,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler-jelly</artifactId>
<version>1.127</version>
<version>1.129</version>
<exclusions>
<exclusion>
<groupId>dom4j</groupId>
......@@ -349,10 +349,23 @@ THE SOFTWARE.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler-adjunct-timeline</artifactId>
<version>1.0</version>
</dependency>
<dependency><!-- this helps us see the source code of the control while we edit Hudson. -->
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler-adjunct-timeline</artifactId>
<version>1.0</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency><!-- until we get this version through Stapler -->
<groupId>org.kohsuke.stapler</groupId>
<artifactId>json-lib</artifactId>
<version>2.1-rev4</version>
<version>2.1-rev6</version>
</dependency>
<dependency>
<groupId>args4j</groupId>
......@@ -722,7 +735,7 @@ THE SOFTWARE.
<dependency>
<groupId>net.java.sezpoz</groupId>
<artifactId>sezpoz</artifactId>
<version>1.4</version>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
......
......@@ -70,10 +70,12 @@ 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;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.xml.transform.Transformer;
......@@ -82,6 +84,7 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONException;
......@@ -98,6 +101,7 @@ 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;
......@@ -1279,4 +1283,28 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
public ACL getACL() {
return Hudson.getInstance().getAuthorizationStrategy().getACL(this);
}
public void doTimelineData(@QueryParameter long min, @QueryParameter long max, StaplerResponse rsp) throws IOException {
Date l = new Date(min);
Date h = new Date(max);
List<Event> result = new ArrayList<Event>();
for (int i=0; i<10; i++) {
Event e = new Event();
e.start = new Date(min+ TimeUnit.HOURS.toMillis(i));
e.title = "Event "+i;
e.description = "Longish description of event "+i;
JSONObject.fromObject(e);
result.add(e);
}
JSONObject o = new JSONObject();
o.put("events", JSONArray.fromObject(result));
rsp.setContentType("application/javascript;charset=UTF-8");
o.write(rsp.getWriter());
}
public static final class Event {
public Date start;
public Date end;
public String title, description;
}
}
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt
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.
-->
<!--Experiment with timeline trend -->
<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">
<l:layout title="Timeline trend for ${it.name}">
<st:include page="sidepanel.jelly" />
<l:main-panel>
<st:adjunct includes="org.kohsuke.stapler.simile.timeline" />
<div id="tl" style="height:500px; border:1px solid black;" />
<div id="status" />
<script><![CDATA[
var timeline_data = { // save as a global variable
'dateTimeFormat': 'iso8601',
'events' : [
{'start': '1924',
'title': 'Barfusserkirche',
'description': 'by Lyonel Feininger, American/German Painter, 1871-1956',
'image': 'http://images.allposters.com/images/AWI/NR096_b.jpg',
'link': 'http://www.allposters.com/-sp/Barfusserkirche-1924-Posters_i1116895_.htm'
},
{'start': '1900',
'end': '1913',
'title': 'Three Figures',
'description': 'by Kasimir Malevich, Ukrainian Painter, 1878-1935',
'image': 'http://images.allposters.com/images/BRGPOD/75857_b.jpg',
'link': 'http://www.allposters.com/-sp/Three-Figures-1913-28-Posters_i1349989_.htm'
}
]};
var tl;
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
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) {
eventSource1.loadJSON(eval(t.responseText));
}
});
}
}
};
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(Date.UTC(1890, 0, 1));
theme1.timeline_stop = new Date(Date.UTC(2160, 0, 1));
var d = Timeline.DateTime.parseGregorianDateTime("1900")
var bandInfos = [
// the bar that shows outline
Timeline.createBandInfo({
width: "100px", // set to a minimum, autoWidth will then adjust
intervalUnit: Timeline.DateTime.DAY,
intervalPixels: 200,
eventSource: eventSource1,
date: d,
theme: theme1,
layout: 'overview' // original, overview, detailed
}),
// the main area
Timeline.createBandInfo({
width: "400px",
eventSource: eventSource1,
theme: theme1,
intervalUnit: Timeline.DateTime.HOUR,
intervalPixels: 200
})
];
bandInfos[0].highlight = true;
bandInfos[0].syncWith = 1;
// create the Timeline
tl = Timeline.create(tl_el, bandInfos, Timeline.HORIZONTAL);
tl.getBand(1).addOnScrollListener(function(band) {
eventSource1.ensureVisible(band);
});
var url = '.'; // The base url for image, icon and background image
// references in the data
eventSource1.loadJSON(timeline_data, url);
tl.layout(); // display the Timeline
},false);
var resizeTimerID = null;
window.addEventListener('resize',function() {
if (resizeTimerID == null) {
resizeTimerID = window.setTimeout(function() {
resizeTimerID = null;
tl.layout();
}, 500);
}
},false);
]]></script>
</l:main-panel>
</l:layout>
</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.
先完成此消息的编辑!
想要评论请 注册