* be updated when resources arrive. Should be the pgcd in fact XXX */\r
this._granularity = DEFAULT_GRANULARITY;\r
scope.granularity = this._granularity;\r
- this._all_slots = this._generate_all_slots();\r
-\r
- // A list of {id, time} dictionaries representing the slots for the given day\r
- scope.slots = this._all_slots;\r
this.scope_resources_by_key = {};\r
\r
this.do_resize();\r
do_resize: function()\r
{\r
var scope = this._get_scope();\r
- var num_hidden_cells, new_max;\r
+ var num_hidden_cells, new_max, lcm;\r
+\r
+ // do_resize has to be called when the window is resized, or one parameter changes\r
+ // e.g. when new resources have been received\r
+ //\r
+ this.resource_granularities = [3600, 1800]; //, 2400]; /* s */\r
+\r
+ /* Compute the slot length to accommodate all resources. This\r
+ * is the GCD of all resource granularities. */\r
+ this._slot_length = this._gcdn(this.resource_granularities);\r
\r
$('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", SCHEDULER_FIRST_COLWIDTH);\r
//self get width might need fix depending on the template \r
\r
/* Number of visible cells...*/\r
this._num_visible_cells = parseInt((tblwidth - SCHEDULER_FIRST_COLWIDTH) / SCHEDULER_COLWIDTH);\r
+\r
/* ...should be a multiple of the lcm of all encountered granularities. */\r
- // XXX Should be updated everytime a new resource is added\r
- this._lcm_colspan = this._lcm(this._granularity, RESOURCE_DEFAULT_GRANULARITY) / this._granularity;\r
- this._num_visible_cells = this._num_visible_cells - this._num_visible_cells % this._lcm_colspan;\r
+ lcm = this._lcmn(this.resource_granularities) / this._slot_length;\r
+ this._num_visible_cells = this._num_visible_cells - this._num_visible_cells % lcm;\r
+\r
+ // A list of {id, time} dictionaries representing the slots for the given day\r
+ this._all_slots = this._generate_all_slots();\r
+\r
/* scope also needs this value */\r
+ scope.slots = this._all_slots;\r
+ scope.slot_length = this._slot_length;\r
scope.num_visible_cells = this._num_visible_cells;\r
- scope.lcm_colspan = this._lcm_colspan;\r
+ scope.lcm_colspan = this._lcmn(this.resource_granularities); // XXX WHY ?\r
+\r
+ /* Redraw... */\r
+ this._scope_clear_leases();\r
+ this._set_all_lease_slots();\r
\r
// Slider max value\r
if ($('#tblSlider').data('slider') != undefined) {\r
\r
$('#tblSlider').slider('setAttribute', 'max', num_hidden_cells);\r
$('#tblSlider').slider('setValue', scope.from, true);\r
- this._get_scope().$apply();\r
}\r
+ this._get_scope().$apply();\r
\r
\r
},\r
// Setup leases with a default free status...\r
$.each(this.scope_resources_by_key, function(resource_key, resource) {\r
resource.leases = [];\r
- var colspan_lease = resource.granularity / self._granularity; //eg. 3600 / 1800 => 2 cells\r
+ var colspan_lease = resource.granularity / self._slot_length; //eg. 3600 / 1800 => 2 cells\r
time = SchedulerDateSelected.getTime();\r
for (i=0; i < self._all_slots.length / colspan_lease; i++) { // divide by granularity\r
resource.leases.push({\r
return true; // ~ continue\r
\r
id_end = Math.ceil((lease.end_time - day_timestamp) / resource.granularity);\r
- colspan_lease = resource.granularity / this._granularity; //eg. 3600 / 1800 => 2 cells\r
+ colspan_lease = resource.granularity / this._slot_length; //eg. 3600 / 1800 => 2 cells\r
if (id_end >= this._all_slots.length / colspan_lease) {\r
/* Limit the display to the current day */\r
id_end = this._all_slots.length / colspan_lease\r
\r
$('#tblSlider').slider({\r
min: 0,\r
- max: num_hidden_cells, // / self._lcm_colspan,\r
+ max: num_hidden_cells,\r
value: init_cell,\r
}).on('slide', function(ev) {\r
var scope = self._get_scope();\r
- scope.from = ev.value * self._lcm_colspan;\r
+ scope.from = ev.value;\r
scope.$apply();\r
});\r
scope.from = init_cell;\r
return (y==0) ? x : this._gcd(y, x % y);\r
},\r
\r
+ _gcdn : function(array)\r
+ {\r
+ var self = this;\r
+ return array.reduce(function(prev, cur, idx, arr) { return self._gcd(prev, cur); });\r
+ },\r
+\r
/**\r
* Least common multiple\r
*/\r
{\r
return x * y / this._gcd(x, y);\r
},\r
+\r
+ _lcmn : function(array)\r
+ {\r
+ var self = this;\r
+ return array.reduce(function(prev, cur, idx, arr) { return self._lcm(prev, cur); });\r
+ },\r
\r
_pad_str : function(i)\r
{\r
/// ...and add the slot to the list of results\r
slots.push({ id: i, time: tmpTime });\r
// Increment the date with the granularity\r
- d = new Date(d.getTime() + this._granularity * 1000);\r
+ d = new Date(d.getTime() + this._slot_length * 1000);\r
i++;\r
}\r
return slots;\r