3 # Copyright (c) 2013 NITLab, University of Thessaly, CERTH, Greece
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 # This is a MySlice plugin for the NITOS Scheduler
29 // XXX groupid = all slots those that go with a min granularity
33 var scheduler2Instance;
34 //is ctrl keyboard button pressed
35 var schedulerCtrlPressed = false;
37 var schedulerTblId = "scheduler-reservation-table";
38 var SCHEDULER_FIRST_COLWIDTH = 200;
41 /* Number of scheduler slots per hour. Used to define granularity. Should be inferred from resources XXX */
42 var schedulerSlotsPerHour = 6;
43 var RESOURCE_DEFAULT_GRANULARITY = 1800 /* s */; // should be computed automatically from resource information
44 var DEFAULT_GRANULARITY = 1800 /* s */; // should be computed automatically from resource information. Test with 600
45 var DEFAULT_PAGE_RANGE = 5;
47 var schedulerMaxRows = 12;
50 var SchedulerData = [];
53 var SchedulerSlots = [];
55 var SchedulerDateSelected = new Date();
57 SchedulerDateSelected.setHours(0,0,0,0);
59 /* Filtered resources */
60 var SchedulerDataViewData = [];
62 var SchedulerSlotsViewData = [];
64 var _schedulerCurrentCellPosition = 0;
66 var schedulerDebug = true;
68 var tmpSchedulerLeases = [];
70 var SCHEDULER_COLWIDTH = 50;
73 /******************************************************************************
74 * ANGULAR CONTROLLER *
75 ******************************************************************************/
77 // Create a private execution space for our controller. When
78 // executing this function expression, we're going to pass in
79 // the Angular reference and our application module.
82 // Define our Controller constructor.
83 function Controller($scope) {
85 // Store the scope so we can reference it in our
89 // Set up the default scope value.
90 this.scope.errorMessage = null;
94 $scope.current_page = 1;
95 this.scope.items_per_page = 10;
96 $scope.from = 0; // JORDAN
98 $scope.instance = null;
99 $scope.resources = new Array();
100 $scope.slots = SchedulerSlotsViewData;
101 $scope.granularity = DEFAULT_GRANULARITY; /* Will be setup */
102 //$scope.msg = "hello";
104 angular.element(document).ready(function() {
105 //console.log('Hello World');
106 //alert('Hello World');
107 //afterAngularRendered();
112 $scope.range = function() {
113 var range_size = $scope.page_count() > DEFAULT_PAGE_RANGE ? DEFAULT_PAGE_RANGE : $scope.page_count();
117 start = $scope.current_page;
118 if ( start > $scope.page_count()-range_size ) {
119 start = $scope.page_count()-range_size+1;
122 for (var i=start; i<start+range_size; i++) {
128 $scope.prevPage = function() {
129 if ($scope.current_page > 1) {
130 $scope.current_page--;
134 $scope.prevPageDisabled = function() {
135 return $scope.current_page === 1 ? "disabled" : "";
138 $scope.page_count = function()
140 // XXX need visible resources only
141 var query_ext, visible_resources_length;
142 if (!$scope.instance)
144 query_ext = manifold.query_store.find_analyzed_query_ext($scope.instance.options.query_uuid);
145 var visible_resources_length = 0;
146 query_ext.state.each(function(i, state) {
147 if (state[STATE_VISIBLE])
148 visible_resources_length++;
150 return Math.ceil(visible_resources_length/$scope.items_per_page);
153 $scope.nextPage = function() {
154 if ($scope.current_page < $scope.page_count()) {
155 $scope.current_page++;
159 $scope.nextPageDisabled = function() {
160 return $scope.current_page === $scope.page_count() ? "disabled" : "";
163 $scope.setPage = function(n) {
164 $scope.current_page = n;
170 $scope.filter_visible = function(resource)
172 return manifold.query_store.get_record_state($scope.instance.options.query_uuid, resource['urn'], STATE_VISIBLE);
177 $scope._create_new_lease = function(resource_urn, start_time, end_time)
179 var lease_key, new_lease, data;
181 lease_key = manifold.metadata.get_key('lease');
184 resource: resource_urn,
185 start_time: start_time,
189 // This is needed to create a hashable object
190 new_lease.hashCode = manifold.record_hashcode(lease_key.sort());
191 new_lease.equals = manifold.record_equals(lease_key);
199 manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
200 /* Add to local cache also, unless we listen to events from outside */
201 if (!(resource_urn in $scope._leases_by_resource))
202 $scope._leases_by_resource[resource_urn] = [];
203 $scope._leases_by_resource[resource_urn].push(new_lease);
206 $scope._remove_lease = function(other)
208 var lease_key, other_key, data;
210 lease_key = manifold.metadata.get_key('lease');
212 // XXX This could be a manifold.record_get_value
214 resource: other.resource,
215 start_time: other.start_time,
216 end_time: other.end_time
218 other_key.hashCode = manifold.record_hashcode(lease_key.sort());
219 other_key.equals = manifold.record_equals(lease_key);
224 op : STATE_SET_REMOVE,
227 manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
228 /* Remove from local cache also, unless we listen to events from outside */
229 $scope._leases_by_resource[other.resource] = $.grep($scope._leases_by_resource[other.resource], function(x) { return x != other; });
233 $scope.select = function(index, model_lease, model_resource)
235 var data, resource_granularity;
237 //resource_granularity = model_resource.granularity === undefined ? RESOURCE_DEFAULT_GRANULARITY : model_resource.granularity;
239 console.log("Selected", index, model_lease, model_resource);
241 var day_timestamp = SchedulerDateSelected.getTime() / 1000;
242 var start_time = day_timestamp + index * model_resource.granularity; // XXX resource_granularity
243 var end_time = day_timestamp + (index + 1) * model_resource.granularity; //
244 var start_date = new Date(start_time * 1000);
245 var end_date = new Date(end_time * 1000);
247 var lease_key = manifold.metadata.get_key('lease');
249 // We search for leases in the cache we previously constructed
250 var resource_leases = $scope._leases_by_resource[model_resource.urn];
252 switch (model_lease.status)
256 if (resource_leases) {
257 /* Search for leases before */
258 $.each(resource_leases, function(i, other) {
259 if (other.end_time != start_time)
260 return true; // ~ continue
262 /* The lease 'other' is just before, and there should not exist
263 * any other lease before it */
264 start_time = other.start_time;
267 resource: other.resource,
268 start_time: other.start_time,
269 end_time: other.end_time
271 // This is needed to create a hashable object
272 other_key.hashCode = manifold.record_hashcode(lease_key.sort());
273 other_key.equals = manifold.record_equals(lease_key);
278 op : STATE_SET_REMOVE,
281 manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
282 /* Remove from local cache also, unless we listen to events from outside */
283 $scope._leases_by_resource[model_resource.urn] = $.grep($scope._leases_by_resource[model_resource.urn], function(x) { return x != other; });
284 return false; // ~ break
287 /* Search for leases after */
288 $.each(resource_leases, function(i, other) {
289 if (other.start_time != end_time)
290 return true; // ~ continue
292 /* The lease 'other' is just after, and there should not exist
293 * any other lease after it */
294 end_time = other.end_time;
296 resource: other.resource,
297 start_time: other.start_time,
298 end_time: other.end_time
300 // This is needed to create a hashable object
301 other_key.hashCode = manifold.record_hashcode(lease_key.sort());
302 other_key.equals = manifold.record_equals(lease_key);
307 op : STATE_SET_REMOVE,
310 manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
311 /* Remove from local cache also, unless we listen to events from outside */
312 $scope._leases_by_resource[model_resource.urn] = $.grep($scope._leases_by_resource[model_resource.urn], function(x) { return x != other; });
313 return false; // ~ break
317 $scope._create_new_lease(model_resource.urn, start_time, end_time);
318 model_lease.status = (model_lease.status == 'free') ? 'pendingin' : 'selected';
319 // unless the exact same lease already existed (pending_out status for the lease, not the cell !!)
325 // We remove the cell
327 /* We search for leases including this cell. Either 0, 1 or 2.
328 * 0 : NOT POSSIBLE, should be checked.
329 * 1 : either IN or OUT, we have make no change in the session
330 * 2 : both will be pending, since we have made a change in the session
331 * /!\ need to properly remove pending_in leases when removed again
333 if (resource_leases) {
334 $.each(resource_leases, function(i, other) {
335 if ((other.start_time <= start_time) && (other.end_time >= end_time)) {
336 // The cell is part of this lease.
338 // If the cell is not at the beginning of the lease, we recreate a lease with cells before
339 if (start_time > other.start_time) {
340 $scope._create_new_lease(model_resource.urn, other.start_time, start_time);
343 // If the cell is not at the end of the lease, we recreate a lease with cells after
344 if (end_time < other.end_time) {
345 $scope._create_new_lease(model_resource.urn, end_time, other.end_time);
348 // The other lease will be removed
349 $scope._remove_lease(other);
351 // NOTE: We can interrupt the search if we know that there is a single lease (depending on the status).
355 // cf comment in previous switch case
356 model_lease.status = (model_lease.status == 'selected') ? 'pendingout' : 'free';
367 //$scope._dump_leases();
370 $scope._dump_leases = function()
372 // DEBUG: display all leases and their status in the log
373 var leases = manifold.query_store.get_records($scope.instance.options.query_lease_uuid);
374 console.log("--------------------");
375 $.each(leases, function(i, lease) {
376 var key = manifold.metadata.get_key('lease');
377 var lease_key = manifold.record_get_value(lease, key);
378 var state = manifold.query_store.get_record_state($scope.instance.options.query_lease_uuid, lease_key, STATE_SET);
382 state_str = 'STATE_SET_IN';
385 state_str = 'STATE_SET_OUT';
387 case STATE_SET_IN_PENDING:
388 state_str = 'STATE_SET_IN_PENDING';
390 case STATE_SET_OUT_PENDING:
391 state_str = 'STATE_SET_OUT_PENDING';
393 case STATE_SET_IN_SUCCESS:
394 state_str = 'STATE_SET_IN_SUCCESS';
396 case STATE_SET_OUT_SUCCESS:
397 state_str = 'STATE_SET_OUT_SUCCESS';
399 case STATE_SET_IN_FAILURE:
400 state_str = 'STATE_SET_IN_FAILURE';
402 case STATE_SET_OUT_FAILURE:
403 state_str = 'STATE_SET_OUT_FAILURE';
406 console.log("LEASE", new Date(lease.start_time * 1000), new Date(lease.end_time * 1000), lease.resource, state_str);
410 // Return this object reference.
415 // Define the Controller as the constructor function.
416 app.controller("SchedulerCtrl", Controller);
418 })(angular, ManifoldApp);
420 /******************************************************************************
422 ******************************************************************************/
425 scheduler2 = Plugin.extend({
428 * @brief Plugin constructor
429 * @param options : an associative array of setting values
431 * @return : a jQuery collection of objects on which the plugin is
432 * applied, which allows to maintain chainability of calls
434 init: function(options, element) {
435 // Call the parent constructor, see FAQ when forgotten
436 this._super(options, element);
438 var scope = this._get_scope()
439 scope.instance = this;
442 scheduler2Instance = this;
444 // We need to remember the active filter for datatables filtering
446 this.filters = Array();
449 $(window).delegate('*', 'keypress', function (evt){
453 $(window).keydown(function(evt) {
454 if (evt.which == 17) { // ctrl
455 schedulerCtrlPressed = true;
457 }).keyup(function(evt) {
458 if (evt.which == 17) { // ctrl
459 schedulerCtrlPressed = false;
464 //$("#" + schedulerTblId).on('mousedown', 'td', rangeMouseDown).on('mouseup', 'td', rangeMouseUp).on('mousemove', 'td', rangeMouseMove);
466 this._resources_received = false;
467 this._leases_received = false;
469 scope._leases_by_resource = {};
471 /* Listening to queries */
472 this.listen_query(options.query_uuid, 'resources');
473 this.listen_query(options.query_lease_uuid, 'leases');
475 this.elmt().on('show', this, this.on_show);
476 this.elmt().on('shown.bs.tab', this, this.on_show);
477 this.elmt().on('resize', this, this.on_resize);
479 /* Generate slots according to the default granularity. Should
480 * be updated when resources arrive. Should be the pgcd in fact XXX */
481 this._granularity = DEFAULT_GRANULARITY;
482 scope.granularity = this._granularity;
483 this.scope_resources_by_key = {};
493 do_resize: function()
495 var scope = this._get_scope();
496 var num_hidden_cells, new_max, lcm;
498 // do_resize has to be called when the window is resized, or one parameter changes
499 // e.g. when new resources have been received
501 this.resource_granularities = [3600, 1800]; //, 2400]; /* s */
503 /* Compute the slot length to accommodate all resources. This
504 * is the GCD of all resource granularities. */
505 this._slot_length = this._gcdn(this.resource_granularities);
507 $('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", SCHEDULER_FIRST_COLWIDTH);
508 //self get width might need fix depending on the template
509 var tblwidth = $('#scheduler-reservation-table').parent().outerWidth();
511 /* Number of visible cells...*/
512 this._num_visible_cells = parseInt((tblwidth - SCHEDULER_FIRST_COLWIDTH) / SCHEDULER_COLWIDTH);
514 /* ...should be a multiple of the lcm of all encountered granularities. */
515 lcm = this._lcmn(this.resource_granularities) / this._slot_length;
516 this._num_visible_cells = this._num_visible_cells - this._num_visible_cells % lcm;
518 // A list of {id, time} dictionaries representing the slots for the given day
519 this._all_slots = this._generate_all_slots();
521 /* scope also needs this value */
522 scope.slots = this._all_slots;
523 scope.slot_length = this._slot_length;
524 scope.num_visible_cells = this._num_visible_cells;
525 scope.lcm_colspan = this._lcmn(this.resource_granularities); // XXX WHY ?
528 this._scope_clear_leases();
529 this._set_all_lease_slots();
532 if ($('#tblSlider').data('slider') != undefined) {
533 num_hidden_cells = this._all_slots.length - this._num_visible_cells;
535 $('#tblSlider').slider('setAttribute', 'max', num_hidden_cells);
536 $('#tblSlider').slider('setValue', scope.from, true);
538 this._get_scope().$apply();
547 self._get_scope().$apply();
550 on_resize: function(e)
554 self._get_scope().$apply();
559 _get_scope : function()
561 return angular.element(document.getElementById('SchedulerCtrl')).scope();
564 _scope_set_resources : function()
567 var scope = this._get_scope();
569 var records = manifold.query_store.get_records(this.options.query_uuid);
571 scope.resources = [];
573 $.each(records, function(i, record) {
574 if (!record.exclusive)
575 return true; // ~ continue
577 // copy not to modify original record
578 var resource = jQuery.extend(true, {}, record);
581 //resource_granularity = ((resource.granularity === undefined) || (typeof(resource.granularity) != "number")) ? RESOURCE_DEFAULT_GRANULARITY : resource.granularity;
582 if (typeof(resource.granularity) != "number")
583 resource.granularity = RESOURCE_DEFAULT_GRANULARITY;
584 resource.leases = []; // a list of occupied timeslots
586 self.scope_resources_by_key[resource['urn']] = resource;
587 scope.resources.push(resource);
591 _scope_clear_leases: function()
595 var scope = this._get_scope();
597 now = new Date().getTime();
599 // Setup leases with a default free status...
600 $.each(this.scope_resources_by_key, function(resource_key, resource) {
601 resource.leases = [];
602 var colspan_lease = resource.granularity / self._slot_length; //eg. 3600 / 1800 => 2 cells
603 time = SchedulerDateSelected.getTime();
604 for (i=0; i < self._all_slots.length / colspan_lease; i++) { // divide by granularity
605 resource.leases.push({
607 status: (time < now) ? 'disabled': 'free', // 'selected', 'reserved', 'maintenance' XXX pending ??
609 time += resource.granularity * 1000;
615 _scope_set_leases: function()
619 var scope = this._get_scope();
621 manifold.query_store.iter_records(this.options.query_lease_uuid, function(lease_key, lease) {
622 //console.log("SET LEASES", lease.resource, new Date(lease.start_time* 1000), new Date(lease.end_time* 1000));
623 // XXX We should ensure leases are correctly merged, otherwise our algorithm won't work
625 // Populate leases by resource array: this will help us merging leases later
627 // let's only put _our_ leases
628 lease_status = manifold.query_store.get_record_state(self.options.query_lease_uuid, lease_key, STATE_SET);
629 if (lease_status != STATE_SET_IN)
630 return true; // ~continue
631 if (!(lease.resource in scope._leases_by_resource))
632 scope._leases_by_resource[lease.resource] = [];
633 scope._leases_by_resource[lease.resource].push(lease);
637 this._set_all_lease_slots();
640 _set_all_lease_slots: function()
644 manifold.query_store.iter_records(this.options.query_lease_uuid, function(lease_key, lease) {
645 self._set_lease_slots(lease_key, lease);
649 on_resources_query_done: function(data)
651 this._resources_received = true;
652 this._scope_set_resources();
653 this._scope_clear_leases();
654 if (this._leases_received)
655 this._scope_set_leases();
657 this._get_scope().$apply();
660 on_leases_query_done: function(data)
662 this._leases_received = true;
663 if (this._resources_received) {
664 this._scope_set_leases();
665 this._get_scope().$apply();
669 /* Filters on resources */
670 on_resources_filter_added: function(filter) { this._get_scope().$apply(); },
671 on_resources_filter_removed: function(filter) { this._get_scope().$apply(); },
672 on_resources_filter_clear: function() { this._get_scope().$apply(); },
674 /* Filters on leases ? */
675 on_leases_filter_added: function(filter) { this._get_scope().$apply(); },
676 on_leases_filter_removed: function(filter) { this._get_scope().$apply(); },
677 on_leases_filter_clear: function() { this._get_scope().$apply(); },
679 on_field_state_changed: function(data)
682 this._set_lease_slots(lease_key, lease);
688 case STATE_SET_IN_SUCCESS:
689 case STATE_SET_OUT_FAILURE:
690 this.set_checkbox_from_data(data.value, true);
691 this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
694 case STATE_SET_OUT_SUCCESS:
695 case STATE_SET_IN_FAILURE:
696 this.set_checkbox_from_data(data.value, false);
697 this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
699 case STATE_SET_IN_PENDING:
700 this.set_checkbox_from_data(data.key, true);
701 this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_ADDED);
703 case STATE_SET_OUT_PENDING:
704 this.set_checkbox_from_data(data.key, false);
705 this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_REMOVED);
711 this.change_status(data.key, data.value);
718 /* INTERNAL FUNCTIONS */
720 _set_lease_slots: function(lease_key, lease)
722 var resource, lease_status, lease_class;
723 var day_timestamp, id_start, id_end, colspan_lease;
725 resource = this.scope_resources_by_key[lease.resource];
726 day_timestamp = SchedulerDateSelected.getTime() / 1000;
727 if(resource === undefined){
728 console.log('resource undefined = '+lease.resource);
731 id_start = Math.floor((lease.start_time - day_timestamp) / resource.granularity);
733 /* Some leases might be in the past */
736 /* Leases in the future: ignore */
737 if (id_start >= this._all_slots.length)
738 return true; // ~ continue
740 id_end = Math.ceil((lease.end_time - day_timestamp) / resource.granularity);
741 colspan_lease = resource.granularity / this._slot_length; //eg. 3600 / 1800 => 2 cells
742 if (id_end >= this._all_slots.length / colspan_lease) {
743 /* Limit the display to the current day */
744 id_end = this._all_slots.length / colspan_lease
746 lease_status = manifold.query_store.get_record_state(this.options.query_lease_uuid, lease_key, STATE_SET);
747 // the same slots might be affected multiple times.
748 // PENDING_IN + PENDING_OUT => IN
750 // RESERVED vs SELECTED !
753 switch(lease_status) {
755 lease_class = 'selected'; // my leases
758 case STATE_SET_IN_SUCCESS:
759 lease_class = 'selected'; // my leases
760 lease_success = 'success';
761 case STATE_SET_OUT_FAILURE:
762 lease_class = 'selected'; // my leases
763 lease_success = 'failure';
766 lease_class = 'reserved'; // other leases
769 case STATE_SET_OUT_SUCCESS:
770 lease_class = 'free'; // other leases
771 lease_success = 'success';
773 case STATE_SET_IN_FAILURE:
774 lease_class = 'free'; // other leases
775 lease_success = 'failure';
777 case STATE_SET_IN_PENDING:
778 lease_class = 'pendingin';
781 case STATE_SET_OUT_PENDING:
782 // pending_in & pending_out == IN == replacement
783 if (resource.leases[i].status == 'pendingin')
784 lease_class = 'pendingin'
786 lease_class = 'pendingout';
792 for (i = id_start; i < id_end; i++) {
793 resource.leases[i].status = lease_class;
794 resource.leases[i].success = lease_success;
798 /* XXX IN TEMPLATE XXX
799 if (SchedulerDataViewData.length == 0) {
800 $("#plugin-scheduler").hide();
801 $("#plugin-scheduler-empty").show();
802 tmpScope.clearStuff();
804 $("#plugin-scheduler-empty").hide();
805 $("#plugin-scheduler").show();
806 // initSchedulerResources
807 tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length);
812 * Initialize the date picker, the table, the slider and the buttons. Once done, display scheduler.
817 var scope = self._get_scope();
819 var num_hidden_cells;
821 $("#DateToRes").datepicker({
822 dateFormat: "D, d M yy",
823 onRender: function(date) {
824 return date.valueOf() < now.valueOf() ? 'disabled' : '';
826 }).on('changeDate', function(ev) {
827 SchedulerDateSelected = new Date(ev.date);
828 SchedulerDateSelected.setHours(0,0,0,0);
829 // Set slider to origin
830 //$('#tblSlider').slider('setValue', 0); // XXX
832 self._scope_clear_leases();
833 self._set_all_lease_slots();
835 self._get_scope().$apply();
836 }).datepicker('setValue', SchedulerDateSelected); //.data('datepicker');
839 num_hidden_cells = self._all_slots.length - self._num_visible_cells;
840 init_cell = (new Date().getHours() - 1) * 3600 / self._granularity;
841 if (init_cell > num_hidden_cells)
842 init_cell = num_hidden_cells;
844 $('#tblSlider').slider({
846 max: num_hidden_cells,
848 }).on('slide', function(ev) {
849 var scope = self._get_scope();
850 scope.from = ev.value;
853 scope.from = init_cell;
856 $("#plugin-scheduler-loader").hide();
857 $("#plugin-scheduler").show();
863 * Greatest common divisor
865 _gcd : function(x, y)
867 return (y==0) ? x : this._gcd(y, x % y);
870 _gcdn : function(array)
873 return array.reduce(function(prev, cur, idx, arr) { return self._gcd(prev, cur); });
877 * Least common multiple
879 _lcm : function(x, y)
881 return x * y / this._gcd(x, y);
884 _lcmn : function(array)
887 return array.reduce(function(prev, cur, idx, arr) { return self._lcm(prev, cur); });
890 _pad_str : function(i)
892 return (i < 10) ? "0" + i : "" + i;
896 * Member variables used:
900 * A list of {id, time} dictionaries.
902 _generate_all_slots: function()
905 // Start with a random date (a first of a month), only time will matter
906 var d = new Date(2014, 1, 1, 0, 0, 0, 0);
908 // Loop until we change the day
909 while (d.getDate() == 1) {
910 // Nicely format the time...
911 var tmpTime = this._pad_str(d.getHours()) + ':' + this._pad_str(d.getMinutes());
912 /// ...and add the slot to the list of results
913 slots.push({ id: i, time: tmpTime });
914 // Increment the date with the granularity
915 d = new Date(d.getTime() + this._slot_length * 1000);
923 /* Plugin registration */
924 $.plugin('Scheduler2', scheduler2);