From 546d5148434646dd3e5121c8b49cfa80b8890117 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jordan=20Aug=C3=A9?= Date: Thu, 28 Nov 2013 18:08:42 +0100 Subject: [PATCH] fixed error in manifold.js + updated scheduler --- manifold/static/js/manifold.js | 6 ++ plugins/googlemap/static/js/googlemap.js | 20 +++--- plugins/scheduler/static/js/scheduler.js | 77 ++++++++++++++++++------ 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/manifold/static/js/manifold.js b/manifold/static/js/manifold.js index 3f514345..b5085fbe 100644 --- a/manifold/static/js/manifold.js +++ b/manifold/static/js/manifold.js @@ -799,11 +799,15 @@ var manifold = { switch(value.request) { case FIELD_REQUEST_CHANGE: + if (update_query.params[value.key] === undefined) + update_query.params[value.key] = Array(); update_query.params[value.key] = value.value; break; case FIELD_REQUEST_ADD: if ($.inArray(value.value, update_query_orig.params[value.key]) != -1) value.request = FIELD_REQUEST_ADD_RESET; + if (update_query.params[value.key] === undefined) + update_query.params[value.key] = Array(); update_query.params[value.key].push(value.value); break; case FIELD_REQUEST_REMOVE: @@ -812,6 +816,8 @@ var manifold = { var arr = update_query.params[value.key]; arr = $.grep(arr, function(x) { return x != value.value; }); + if (update_query.params[value.key] === undefined) + update_query.params[value.key] = Array(); update_query.params[value.key] = arr; break; diff --git a/plugins/googlemap/static/js/googlemap.js b/plugins/googlemap/static/js/googlemap.js index 0c511a08..23345a27 100644 --- a/plugins/googlemap/static/js/googlemap.js +++ b/plugins/googlemap/static/js/googlemap.js @@ -243,16 +243,16 @@ googlemap_debug_detailed=false; on_field_state_changed: function(data) { if (googlemap_debug_detailed) messages.debug("on_field_state_changed"); switch(data.request) { - case FIELD_REQUEST_ADD: - case FIELD_REQUEST_ADD_RESET: - this.set_checkbox(data.value, true); - break; - case FIELD_REQUEST_REMOVE: - case FIELD_REQUEST_REMOVE_RESET: - this.set_checkbox(data.value, false); - break; - default: - break; + case FIELD_REQUEST_ADD: + case FIELD_REQUEST_ADD_RESET: + this.set_checkbox(data.value, true); + break; + case FIELD_REQUEST_REMOVE: + case FIELD_REQUEST_REMOVE_RESET: + this.set_checkbox(data.value, false); + break; + default: + break; } }, diff --git a/plugins/scheduler/static/js/scheduler.js b/plugins/scheduler/static/js/scheduler.js index 06ad5314..6f6908c0 100644 --- a/plugins/scheduler/static/js/scheduler.js +++ b/plugins/scheduler/static/js/scheduler.js @@ -194,6 +194,29 @@ var txt_otherslice = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-s // this.initial_leases=leases; }, + on_lease_field_state_changed: function(data) + { + switch(data.request) { + case FIELD_REQUEST_ADD: + case FIELD_REQUEST_ADD_RESET: + this._leases.push(data.value); + /* XXX Not optimal, we could only redraw the right cell */ + /* We need a mapping between the lease and the cell */ + /* How is it done in d3 ? based on key */ + this._draw(); + break; + case FIELD_REQUEST_REMOVE: + case FIELD_REQUEST_REMOVE_RESET: + // We remove data.value (aka keep those leases different from data.value + this._leases = $.grep(this._leases, function(x) { return x != data.value; }); + this._draw(); + break; + default: + break; + + } + }, + on_lease_query_done: function(record) { /* We have received all resources */ @@ -393,6 +416,7 @@ var txt_otherslice = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-s lease.nodename = nodename; lease.urn = urn; lease.nodelabel = nodelabel; + lease.id = 0; /* XXX how to use CSS selector to find a given lease... */ if (slicename == "") { lease.initial = "free"; @@ -583,39 +607,56 @@ var txt_otherslice = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-s /* Add a new lease : XXX should be replaced by a dictionary */ // Do we have a lease with the same urn just before or just after ? - var removeIdBefore = null; - var removeIdAfter = null; + //var removeIdBefore = null; + //var removeIdAfter = null; + var remove_lease_before = null; + var remove_lease_after = null; + // It is important to group leases, while this is technically + // equivalent, some testbeds such as IotLab limit the number of + // leases a user can have. + // XXX we might have several leases before or after if they have + // XXX not been grouped like this tool does $.each(scheduler._leases, function(i, lease) { if (lease[0] == urn) { if (lease[1] + lease[2] * 1800 == start_time) { // XXX HARDCODED LEASE GRAIN // Merge with previous lease - removeIdBefore = i; - start_time = lease[1]; - duration += lease[2]; + // removeIdBefore = i; + remove_lease_before = lease; + start_time = lease[1]; + duration += lease[2]; } if (lease[1] == end_time) { // Merge with following lease - removeIdAfter = i; - duration += lease[2]; + // removeIdAfter = i; + remove_lease_after = lease; + duration += lease[2]; } } }); - if (removeIdBefore != null) { - scheduler._leases.splice(removeIdBefore , 1); - if (removeIdAfter != null) - removeIdAfter -= 1; - } - if (removeIdAfter != null) { - scheduler._leases.splice(removeIdAfter , 1); - } - - scheduler._leases.push([this.urn, start_time, duration]); + //if (removeIdBefore != null) { + // scheduler._leases.splice(removeIdBefore , 1); + // if (removeIdAfter != null) + // removeIdAfter -= 1; + //} + //if (removeIdAfter != null) { + // scheduler._leases.splice(removeIdAfter , 1); + //} + + // We add the new lease, no need to push + var new_lease = [this.urn, start_time, duration]; + + // We send events, manifold will inform us about the change and we will react accordingly + if (remove_lease_before != null) + manifold.raise_event(scheduler.options.query_lease_uuid, SET_REMOVED, remove_lease_before); + if (remove_lease_after != null) + manifold.raise_event(scheduler.options.query_lease_uuid, SET_REMOVED, remove_lease_after); + manifold.raise_event(scheduler.options.query_lease_uuid, SET_ADD, new_lease); + //scheduler._leases.push([this.urn, start_time, duration]); //console.log(scheduler._leases); //jQuery.publish('/update-set/' + scheduler.options.query_uuid, [scheduler._leases]); /* We need to inform manifold about the whole diff, in addition to maintaining our own structure */ - jQuery.publish('/update-set/' + scheduler.options.lease_query_uuid, [scheduler._leases]); }, _lease_init_mine: function (lease, unclick) -- 2.43.0