X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fscheduler2%2Fstatic%2Fjs%2Fscheduler2.js;h=6b55b92afd4cf67fa1ab8a401aa2192fa7eb3462;hb=cb3a40dfdc1c79ca57458d1c18732334d58734fd;hp=0b294b472596bfe615320ae8f2f1fe5607a8eaac;hpb=606581446b8e61b0817aefa81cbcc64df9cb21ed;p=myslice.git diff --git a/plugins/scheduler2/static/js/scheduler2.js b/plugins/scheduler2/static/js/scheduler2.js index 0b294b47..6b55b92a 100755 --- a/plugins/scheduler2/static/js/scheduler2.js +++ b/plugins/scheduler2/static/js/scheduler2.js @@ -232,13 +232,15 @@ var SCHEDULER_COLWIDTH = 50; $scope.select = function(index, model_lease, model_resource) { - var data; + var data, resource_granularity; + + //resource_granularity = model_resource.granularity === undefined ? RESOURCE_DEFAULT_GRANULARITY : model_resource.granularity; console.log("Selected", index, model_lease, model_resource); var day_timestamp = SchedulerDateSelected.getTime() / 1000; - var start_time = day_timestamp + index * model_resource.granularity; - var end_time = day_timestamp + (index + 1) * model_resource.granularity; + var start_time = day_timestamp + index * model_resource.granularity; // XXX resource_granularity + var end_time = day_timestamp + (index + 1) * model_resource.granularity; // var start_date = new Date(start_time * 1000); var end_date = new Date(end_time * 1000); @@ -478,10 +480,6 @@ var SCHEDULER_COLWIDTH = 50; * be updated when resources arrive. Should be the pgcd in fact XXX */ this._granularity = DEFAULT_GRANULARITY; scope.granularity = this._granularity; - this._all_slots = this._generate_all_slots(); - - // A list of {id, time} dictionaries representing the slots for the given day - scope.slots = this._all_slots; this.scope_resources_by_key = {}; this.do_resize(); @@ -495,7 +493,16 @@ var SCHEDULER_COLWIDTH = 50; do_resize: function() { var scope = this._get_scope(); - var num_hidden_cells, new_max; + var num_hidden_cells, new_max, lcm; + + // do_resize has to be called when the window is resized, or one parameter changes + // e.g. when new resources have been received + // + this.resource_granularities = [3600, 1800]; //, 2400]; /* s */ + + /* Compute the slot length to accommodate all resources. This + * is the GCD of all resource granularities. */ + this._slot_length = this._gcdn(this.resource_granularities); $('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", SCHEDULER_FIRST_COLWIDTH); //self get width might need fix depending on the template @@ -503,13 +510,23 @@ var SCHEDULER_COLWIDTH = 50; /* Number of visible cells...*/ this._num_visible_cells = parseInt((tblwidth - SCHEDULER_FIRST_COLWIDTH) / SCHEDULER_COLWIDTH); + /* ...should be a multiple of the lcm of all encountered granularities. */ - // XXX Should be updated everytime a new resource is added - this._lcm_colspan = this._lcm(this._granularity, RESOURCE_DEFAULT_GRANULARITY) / this._granularity; - this._num_visible_cells = this._num_visible_cells - this._num_visible_cells % this._lcm_colspan; + lcm = this._lcmn(this.resource_granularities) / this._slot_length; + this._num_visible_cells = this._num_visible_cells - this._num_visible_cells % lcm; + + // A list of {id, time} dictionaries representing the slots for the given day + this._all_slots = this._generate_all_slots(); + /* scope also needs this value */ + scope.slots = this._all_slots; + scope.slot_length = this._slot_length; scope.num_visible_cells = this._num_visible_cells; - scope.lcm_colspan = this._lcm_colspan; + scope.lcm_colspan = this._lcmn(this.resource_granularities); // XXX WHY ? + + /* Redraw... */ + this._scope_clear_leases(); + this._set_all_lease_slots(); // Slider max value if ($('#tblSlider').data('slider') != undefined) { @@ -517,8 +534,8 @@ var SCHEDULER_COLWIDTH = 50; $('#tblSlider').slider('setAttribute', 'max', num_hidden_cells); $('#tblSlider').slider('setValue', scope.from, true); - this._get_scope().$apply(); } + this._get_scope().$apply(); }, @@ -561,7 +578,9 @@ var SCHEDULER_COLWIDTH = 50; var resource = jQuery.extend(true, {}, record); // Fix granularity - resource.granularity = typeof(resource.granularity) == "number" ? resource.granularity : RESOURCE_DEFAULT_GRANULARITY; + //resource_granularity = ((resource.granularity === undefined) || (typeof(resource.granularity) != "number")) ? RESOURCE_DEFAULT_GRANULARITY : resource.granularity; + if (typeof(resource.granularity) != "number") + resource.granularity = RESOURCE_DEFAULT_GRANULARITY; resource.leases = []; // a list of occupied timeslots self.scope_resources_by_key[resource['urn']] = resource; @@ -580,7 +599,7 @@ var SCHEDULER_COLWIDTH = 50; // Setup leases with a default free status... $.each(this.scope_resources_by_key, function(resource_key, resource) { resource.leases = []; - var colspan_lease = resource.granularity / self._granularity; //eg. 3600 / 1800 => 2 cells + var colspan_lease = resource.granularity / self._slot_length; //eg. 3600 / 1800 => 2 cells time = SchedulerDateSelected.getTime(); for (i=0; i < self._all_slots.length / colspan_lease; i++) { // divide by granularity resource.leases.push({ @@ -715,58 +734,58 @@ var SCHEDULER_COLWIDTH = 50; return true; // ~ continue id_end = Math.ceil((lease.end_time - day_timestamp) / resource.granularity); - colspan_lease = resource.granularity / this._granularity; //eg. 3600 / 1800 => 2 cells + colspan_lease = resource.granularity / this._slot_length; //eg. 3600 / 1800 => 2 cells if (id_end >= this._all_slots.length / colspan_lease) { /* Limit the display to the current day */ id_end = this._all_slots.length / colspan_lease } + lease_status = manifold.query_store.get_record_state(this.options.query_lease_uuid, lease_key, STATE_SET); + // the same slots might be affected multiple times. + // PENDING_IN + PENDING_OUT => IN + // + // RESERVED vs SELECTED ! + // + // PENDING !! + switch(lease_status) { + case STATE_SET_IN: + lease_class = 'selected'; // my leases + lease_success = ''; + break; + case STATE_SET_IN_SUCCESS: + lease_class = 'selected'; // my leases + lease_success = 'success'; + case STATE_SET_OUT_FAILURE: + lease_class = 'selected'; // my leases + lease_success = 'failure'; + break; + case STATE_SET_OUT: + lease_class = 'reserved'; // other leases + lease_success = ''; + break; + case STATE_SET_OUT_SUCCESS: + lease_class = 'free'; // other leases + lease_success = 'success'; + break; + case STATE_SET_IN_FAILURE: + lease_class = 'free'; // other leases + lease_success = 'failure'; + break; + case STATE_SET_IN_PENDING: + lease_class = 'pendingin'; + lease_success = ''; + break; + case STATE_SET_OUT_PENDING: + // pending_in & pending_out == IN == replacement + if (resource.leases[i].status == 'pendingin') + lease_class = 'pendingin' + else + lease_class = 'pendingout'; + lease_success = ''; + break; + + } for (i = id_start; i < id_end; i++) { - // the same slots might be affected multiple times. - // PENDING_IN + PENDING_OUT => IN - // - // RESERVED vs SELECTED ! - // - // PENDING !! - lease_status = manifold.query_store.get_record_state(this.options.query_lease_uuid, lease_key, STATE_SET); - switch(lease_status) { - case STATE_SET_IN: - lease_class = 'selected'; // my leases - lease_success = ''; - break; - case STATE_SET_IN_SUCCESS: - lease_class = 'selected'; // my leases - lease_success = 'success'; - case STATE_SET_OUT_FAILURE: - lease_class = 'selected'; // my leases - lease_success = 'failure'; - break; - case STATE_SET_OUT: - lease_class = 'reserved'; // other leases - lease_success = ''; - break; - case STATE_SET_OUT_SUCCESS: - lease_class = 'free'; // other leases - lease_success = 'success'; - break; - case STATE_SET_IN_FAILURE: - lease_class = 'free'; // other leases - lease_success = 'failure'; - break; - case STATE_SET_IN_PENDING: - lease_class = 'pendingin'; - lease_success = ''; - break; - case STATE_SET_OUT_PENDING: - // pending_in & pending_out == IN == replacement - if (resource.leases[i].status == 'pendingin') - lease_class = 'pendingin' - else - lease_class = 'pendingout'; - lease_success = ''; - break; - - } resource.leases[i].status = lease_class; resource.leases[i].success = lease_success; } @@ -796,6 +815,7 @@ var SCHEDULER_COLWIDTH = 50; var num_hidden_cells; $("#DateToRes").datepicker({ + dateFormat: "D, d M yy", onRender: function(date) { return date.valueOf() < now.valueOf() ? 'disabled' : ''; } @@ -816,14 +836,14 @@ var SCHEDULER_COLWIDTH = 50; init_cell = (new Date().getHours() - 1) * 3600 / self._granularity; if (init_cell > num_hidden_cells) init_cell = num_hidden_cells; - + $('#tblSlider').slider({ min: 0, - max: num_hidden_cells, // / self._lcm_colspan, + max: num_hidden_cells, value: init_cell, }).on('slide', function(ev) { var scope = self._get_scope(); - scope.from = ev.value * self._lcm_colspan; + scope.from = ev.value; scope.$apply(); }); scope.from = init_cell; @@ -843,6 +863,12 @@ var SCHEDULER_COLWIDTH = 50; return (y==0) ? x : this._gcd(y, x % y); }, + _gcdn : function(array) + { + var self = this; + return array.reduce(function(prev, cur, idx, arr) { return self._gcd(prev, cur); }); + }, + /** * Least common multiple */ @@ -850,6 +876,12 @@ var SCHEDULER_COLWIDTH = 50; { return x * y / this._gcd(x, y); }, + + _lcmn : function(array) + { + var self = this; + return array.reduce(function(prev, cur, idx, arr) { return self._lcm(prev, cur); }); + }, _pad_str : function(i) { @@ -876,7 +908,7 @@ var SCHEDULER_COLWIDTH = 50; /// ...and add the slot to the list of results slots.push({ id: i, time: tmpTime }); // Increment the date with the granularity - d = new Date(d.getTime() + this._granularity * 1000); + d = new Date(d.getTime() + this._slot_length * 1000); i++; } return slots;