var y_sep = 10;
// 1-grain leases attributes
-var x_grain = 24;
+var x_grain = 20;
var y_node = 15;
var radius= 6;
var anim_delay=500;
/* decorations / headers */
+/* note: looks like the 'font' attr is not effective... */
// vertical rules
var attr_rules={'fill':"#888", 'stroke-dasharray':'- ', 'stroke-width':0.5};
-var txt_timelabel = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#008"};
+// set font-size separately in here rather than depend on the height
+var txt_timelabel = {"font": 'Times, "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif',
+ stroke: "none", fill: "#008", 'font-size': 9};
var txt_allnodes = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#404"};
var txt_nodelabel = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#008"};
-var attr_timebutton = {'fill': '#888','stroke-width':2};
+var attr_timebutton = {'fill':'#bbf', 'stroke': '#338','stroke-width':2,
+ 'stroke-linecap':'round', 'stroke-linejoin':'miter', 'stroke-miterlimit':3};
+// keep consistent with sizes above - need for something nicer
+var timebutton_path = "M1,0L19,0L10,8L1,0";
/* lease dimensions and colors */
+/* refrain from using gradient color, seems to not be animated properly */
/* lease was originally free and is still free */
var attr_lease_free_free={'fill':"#def", 'stroke-width':0.5, 'stroke-dasharray':''};
/* lease was originally free and is now set for our usage */
var attr_lease_mine_mine={'fill':"#beb", 'stroke-width':0.5, 'stroke-dasharray':''};
/* was mine and is about to be released */
var attr_lease_mine_free={'fill':"white", 'stroke-width':1, 'stroke-dasharray':'-..'};
-// refrained from using gradient color, was not animated properly
-// var color_lease_mine_free="0-#fff-#def:50-#fff";
var attr_lease_other={'fill':"#f88"};
/* other slices name */
-var txt_slice = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#444",
- "font-size": 15 };
+var txt_otherslice = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#444",
+ "font-size": 12 };
////////////////////////////////////////////////////////////
// the scheduler object
-function Scheduler (slicename, axisx, axisy, data) {
+function Scheduler (sliceid, slicename, axisx, axisy, data) {
- // the data only contain slice names, we need this to find our own leases (mine)
+ // the data contains slice names, and lease_id, we need this to find our own leases (mine)
+ this.sliceid=sliceid;
this.slicename=slicename;
this.axisx=axisx;
this.axisy=axisy;
col +=1;
// display time label
var timelabel=paper.text(left,y,timelabel).attr(txt_timelabel)
- .attr({"font-size":y_header, "text-anchor":"middle"});
+ .attr({"text-anchor":"middle"});
// draw vertical line
var path_spec="M"+left+" "+(y+y_header/2)+"L"+left+" "+this.total_height;
var rule=paper.path(path_spec).attr(attr_rules);
allnodes.click(allnodes_methods.click);
// timeslot buttons
for (var i=0, len=axisx.length; i < len; ++i) {
- var timebutton = paper.rect(left,top,x_grain,y_node,radius).attr(attr_timebutton);
+ var timebutton=paper.path(timebutton_path).attr({'translation':left+','+top}).attr(attr_timebutton);
timebutton.from_time=axisx[i][0];
timebutton.scheduler=this;
timebutton.click(timebutton_methods.click);
left+=x_grain;
}
- //////// the body of the scheduler: nodes
+ //////// the body of the scheduler : loop on nodes
top += y_node+y_sep;
var data_index=0;
for (var i=0, len=axisy.length; i<len; ++i) {
left += x_nodelabel;
var grain=0;
while (grain < this.nb_grains()) {
- slicename=data[data_index][0];
- duration=data[data_index][1];
+ lease_id=data[data_index][0];
+ slicename=data[data_index][1];
+ duration=data[data_index][2];
var lease=paper.rect (left,top,x_grain*duration,y_node,radius);
+ lease.lease_id=lease_id;
lease.nodename=nodename;
lease.nodelabel=nodelabel;
if (slicename == "") {
}
this.submit = function () {
+ document.body.style.cursor = "wait";
+ var actions=new Array();
for (var i=0, len=this.leases.length; i<len; ++i) {
var lease=this.leases[i];
if (lease.current != lease.initial) {
/* scan the leases just after this one and merge if appropriate */
var j=i+1;
while (j<len && lease_methods.compare (lease, until_time, this.leases[j])) {
- window.console.log('merged index='+j);
+// window.console.log('merged index='+j);
until_time=this.leases[j].until_time;
++j; ++i;
}
- var method=(lease.current=='free') ? 'DeleteLeases' : 'AddLeases';
- window.console.log(method + "(" +
- "[" + lease.nodename + "]," +
- this.slicename + "," +
- from_time + "," +
- until_time + ')');
+ if (lease.current!='free') { // lease to add
+ actions.push(new Array('add-leases',
+ new Array(lease.nodename),
+ this.slicename,
+ from_time,
+ until_time));
+ } else { // lease to delete
+ actions.push(new Array ('delete-leases',
+ lease.lease_id));
+ }
}
}
+ sliceid=this.sliceid;
+ // once we're done with the side-effect performed in actions.php, we need to refresh this view
+ redirect = function (sliceid) {
+ window.location = '/db/slices/slice.php?id=' + sliceid + '&show_details=0&show_nodes=1&show_nodes_resa=1';
+ }
+ // Ajax.Request comes with prototype
+ var ajax=new Ajax.Request('/planetlab/common/actions.php',
+ {method:'post',
+ parameters:{'action':'manage-leases',
+ 'actions':actions.toJSON()},
+ onSuccess: function(transport) {
+ var response = transport.responseText || "no response text";
+ document.body.style.cursor = "default";
+ alert("Server answered:\n\n" + response + "\n\nPress OK to refresh page");
+ redirect(sliceid);
+ },
+ onFailure: function(){
+ document.body.style.cursor = "default";
+ alert("Could not reach server, sorry...\n\nPress OK to refresh page");
+ // not too sure what to do here ...
+ redirect(sliceid);
+ },
+ });
}
this.clear = function () {
/* a text obj to display the name of the slice that owns that lease */
var otherslicelabel = paper.text (lease.attr("x")+lease.attr("width")/2,
// xxx
- lease.attr("y")+lease.attr("height")/2,slicename).attr(txt_slice);
+ lease.attr("y")+lease.attr("height")/2,slicename).attr(txt_otherslice);
/* hide it right away */
otherslicelabel.hide();
/* record it */
axisx.push(getInnerText(cell).split("&"));
});
// leases - expect colspan to describe length in grains
+ // the text contents is expected to be lease_id & slicename
table.getElementsBySelector("tbody>tr>td").each(function (cell) {
- data.push(new Array (getInnerText(cell),cell.colSpan));
+ var cell_data;
+ slice_attributes=getInnerText(cell).split('&');
+ // booked leases come with lease id and slice name
+ if (slice_attributes.length == 2) {
+ // leases is booked : slice_id, slice_name, duration in grains
+ cell_data=new Array (slice_attributes[0], slice_attributes[1], cell.colSpan);
+ } else {
+ cell_data = new Array ('','',cell.colSpan);
+ }
+ data.push(cell_data);
});
- // slicename : the upper-left cell
- var scheduler = new Scheduler (getInnerText(table.getElementsBySelector("thead>tr>td")[0]), axisx, axisy, data);
+ // sliceid & slicename : the upper-left cell
+ var slice_attributes = getInnerText(table.getElementsBySelector("thead>tr>td")[0]).split('&');
+ var sliceid=slice_attributes[0];
+ var slicename=slice_attributes[1];
+ var scheduler = new Scheduler (sliceid,slicename, axisx, axisy, data);
table.hide();
// leases_area is a <div> created by slice.php as a placeholder
scheduler.init ("leases_area");