X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fscheduler2%2Fstatic%2Fjs%2Fscheduler2.js;h=fe8e3e8cda4482b88cf3c2ab38d82989b4200f26;hb=6eb1d8c9d03d2b10b514c317b6fff11172097346;hp=10eaa9a8842c2e3ea806fe0361f2e8d18d5409ef;hpb=6e24f5c8289f13a60d28a86543e8a84db63f4426;p=myslice.git diff --git a/plugins/scheduler2/static/js/scheduler2.js b/plugins/scheduler2/static/js/scheduler2.js index 10eaa9a8..fe8e3e8c 100755 --- a/plugins/scheduler2/static/js/scheduler2.js +++ b/plugins/scheduler2/static/js/scheduler2.js @@ -26,6 +26,8 @@ # */ +// XXX groupid = all slots those that go with a min granularity + /* some params */ var scheduler2; var scheduler2Instance; @@ -33,26 +35,40 @@ var scheduler2Instance; var schedulerCtrlPressed = false; //table Id var schedulerTblId = "scheduler-reservation-table"; -var schedulerTblFirstColWidth = 150; -//Some Data +var SCHEDULER_FIRST_COLWIDTH = 150; + + +/* Number of scheduler slots per hour. Used to define granularity. Should be inferred from resources XXX */ var schedulerSlotsPerHour = 6; +var RESOURCE_DEFAULT_GRANULARITY = 1800 /* s */; // should be computed automatically from resource information +var DEFAULT_GRANULARITY = 1800 /* s */; // should be computed automatically from resource information. Test with 600 +var DEFAULT_PAGE_RANGE = 5; + var schedulerMaxRows = 12; + +/* All resources */ var SchedulerData = []; + +/* ??? */ var SchedulerSlots = []; + var SchedulerDateSelected = new Date(); +// Round to midnight +SchedulerDateSelected.setHours(0,0,0,0); + +/* Filtered resources */ var SchedulerDataViewData = []; + var SchedulerSlotsViewData = []; -var SchedulerTotalCells; -var SchedulerTotalVisibleCells; //Help Variables var _schedulerCurrentCellPosition = 0; -var _leasesDone = false; -var _resourcesDone = false; //Enable Debug var schedulerDebug = true; //tmp to delete var tmpSchedulerLeases = []; +var SCHEDULER_COLWIDTH = 50; + (function($) { scheduler2 = Plugin.extend({ @@ -67,13 +83,21 @@ var tmpSchedulerLeases = []; this.classname = "scheduler2"; // Call the parent constructor, see FAQ when forgotten this._super(options, element); + + var scope = this._get_scope() + + // XXX not needed scheduler2Instance = this; + // We need to remember the active filter for datatables filtering + // XXX not needed this.filters = Array(); + // XXX BETTER !!!! + $(window).delegate('*', 'keypress', function (evt){ + alert("erm"); + }); - SchedulerSlots = schedulerGetSlots(60 / schedulerSlotsPerHour); - //selection from table $(window).keydown(function(evt) { if (evt.which == 17) { // ctrl schedulerCtrlPressed = true; @@ -83,154 +107,178 @@ var tmpSchedulerLeases = []; schedulerCtrlPressed = false; } }); - $("#" + schedulerTblId).on('mousedown', 'td', rangeMouseDown).on('mouseup', 'td', rangeMouseUp).on('mousemove', 'td', rangeMouseMove); - // Explain this will allow query events to be handled - // What happens when we don't define some events ? - // Some can be less efficient + // XXX naming + //$("#" + schedulerTblId).on('mousedown', 'td', rangeMouseDown).on('mouseup', 'td', rangeMouseUp).on('mousemove', 'td', rangeMouseMove); - if (schedulerDebug) console.time("Listening_to_queries"); - /* Listening to queries */ + this._resources_received = false; + this._leases_received = false; + + scope._leases_by_resource = {}; - this.listen_query(options.query_uuid); - //this.listen_query(options.query_all_uuid, 'all'); - this.listen_query(options.query_all_resources_uuid, 'all_resources'); - this.listen_query(options.query_lease_uuid, 'lease'); - this.listen_query(options.query_all_leases_uuid, 'all_leases'); - if (schedulerDebug) console.timeEnd("Listening_to_queries"); + /* Listening to queries */ + this.listen_query(options.query_uuid, 'resources'); + this.listen_query(options.query_lease_uuid, 'leases'); + + /* Generate slots according to the default granularity. Should + * 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(); + + $('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", SCHEDULER_FIRST_COLWIDTH); + //this get width might need fix depending on the template + var tblwidth = $('#scheduler-tab').parent().outerWidth(); + + /* 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; + /* scope also needs this value */ + scope.num_visible_cells = this._num_visible_cells; + scope.lcm_colspan = this._lcm_colspan; + + scope.options = this.options; + scope.from = 0; + + // A list of {id, time} dictionaries representing the slots for the given day + scope.slots = this._all_slots; + this.scope_resources_by_key = {}; + + this._initUI(); }, /* Handlers */ - /* all_ev QUERY HANDLERS Start */ - on_all_ev_clear_records: function(data) { - //alert('all_ev clear_records'); - }, - on_all_ev_query_in_progress: function(data) { - // alert('all_ev query_in_progress'); - }, - on_all_ev_new_record: function(data) { - //alert('all_ev new_record'); - }, - on_all_ev_query_done: function(data) { - //alert('all_ev query_done'); + _get_scope : function() + { + return angular.element(document.getElementById('SchedulerCtrl')).scope(); }, - //another plugin has modified something, that requires you to update your display. - on_all_ev_field_state_changed: function(data) { - //alert('all_ev query_done'); - }, - /* all_ev QUERY HANDLERS End */ - /* all_resources QUERY HANDLERS Start */ - on_all_resources_clear_records: function(data) { - //data is empty on load - }, - on_all_resources_query_in_progress: function(data) { - //data is empty on load + + _scope_set_resources : function() + { + var self = this; + var scope = this._get_scope(); + + var records = manifold.query_store.get_records(this.options.query_uuid); + + scope.resources = []; + + $.each(records, function(i, record) { + if (!record.exclusive) + return true; // ~ continue + + // copy not to modify original record + var resource = jQuery.extend(true, {}, record); + + // Fix granularity + resource.granularity = typeof(resource.granularity) == "number" ? resource.granularity : RESOURCE_DEFAULT_GRANULARITY; + resource.leases = []; // a list of occupied timeslots + + self.scope_resources_by_key[resource['urn']] = resource; + scope.resources.push(resource); + }); }, - on_all_resources_new_record: function(data) { - //alert(data.toSource()); - if (data.exclusive == true) { - var tmpGran = schedulerDebug && data.granularity == null ? 1800 : data.granularity; - SchedulerData.push({ - id: data.urn, - index: SchedulerData.length, - name: data.hrn, - granularity: tmpGran, - leases: schedulerGetLeases(60 / schedulerSlotsPerHour, tmpGran), - type: data.type, - org_resource: data - }); - /*if (schedulerDebug && SchedulerData[SchedulerData.length - 1].org_resource.network_hrn == 'omf') { - SchedulerData[SchedulerData.length - 1].granularity = 1800; - }*/ - } - //alert(data.toSource()); + + _scope_clear_leases: function() + { + var self = this; + var scope = this._get_scope(); + + // 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 + for (i=0; i < self._all_slots.length / colspan_lease; i++) { // divide by granularity + resource.leases.push({ + id: 'coucou', + status: 'free', // 'selected', 'reserved', 'maintenance' XXX pending ?? + }); + } + }); }, - on_all_resources_query_done: function(data) { - _resourcesDone = true; - this._initScheduler(); + + _scope_set_leases: function() + { + var self = this; + var scope = this._get_scope(); + + var leases = manifold.query_store.get_records(this.options.query_lease_uuid); + $.each(leases, function(i, lease) { + + console.log("SET LEASES", new Date(lease.start_time* 1000)); + console.log(" ", new Date(lease.end_time* 1000)); + // XXX We should ensure leases are correctly merged, otherwise our algorithm won't work + + // Populate leases by resource array: this will help us merging leases later + if (!(lease.resource in scope._leases_by_resource)) + scope._leases_by_resource[lease.resource] = []; + scope._leases_by_resource[lease.resource].push(lease); + + var resource = self.scope_resources_by_key[lease.resource]; + var day_timestamp = SchedulerDateSelected.getTime() / 1000; + + var id_start = (lease.start_time - day_timestamp) / resource.granularity; + if (id_start < 0) { + /* Some leases might be in the past */ + id_start = 0; + } + + var id_end = (lease.end_time - day_timestamp) / resource.granularity - 1; + var colspan_lease = resource.granularity / self._granularity; //eg. 3600 / 1800 => 2 cells + if (id_end >= self._all_slots.length / colspan_lease) { + /* Limit the display to the current day */ + id_end = self._all_slots.length / colspan_lease + } + + 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 !! + resource.leases[i].status = 'selected'; + }); }, - //another plugin has modified something, that requires you to update your display. - on_all_resources_field_state_changed: function(data) { - //alert('all_resources query_done'); + + on_resources_query_done: function(data) + { + this._resources_received = true; + this._scope_set_resources(); + this._scope_clear_leases(); + if (this._leases_received) + this._scope_set_leases(); + + this._get_scope().$apply(); }, - /* all_resources QUERY HANDLERS End */ - /* lease QUERY HANDLERS Start */ - on_lease_clear_records: function(data) { console.log('clear_records'); }, - on_lease_query_in_progress: function(data) { console.log('lease_query_in_progress'); }, - on_all_leases_new_record: function(data) { - if (data.resource.indexOf("nitos") > -1) { - tmpSchedulerLeases.push({ - id: schedulerGetSlotId(data.start_time, data.duration, data.granularity), - end_id: schedulerGetSlotId(data.end_time, data.duration, data.granularity), - slice: data.slice, - status: 'reserved', - resource: data.resource, - network: data.network, - start_time: new Date(data.start_time * 1000), - start_time_unixtimestamp: data.start_time, - end_time: new Date(data.end_time * 1000), - end_time_unixtimestamp: data.end_time, - lease_type: data.lease_type, - granularity: data.granularity, - duration: data.duration - }); + + on_leases_query_done: function(data) + { + this._leases_received = true; + if (this._resources_received) { + this._scope_set_leases(); + this._get_scope().$apply(); } - //console.log(data.toSource()); console.log('lease_new_record'); }, - on_all_leases_query_done: function(data) { - _leasesDone = true; - this._initScheduler(); - // console.log('lease_query_done'); - }, - //another plugin has modified something, that requires you to update your display. - on_lease_field_state_changed: function(data) { console.log('lease_field_state_changed'); }, - /* lease QUERY HANDLERS End */ + /* Filters on resources */ + on_resources_filter_added: function(filter) { this._get_scope().$apply(); }, + on_resources_filter_removed: function(filter) { this._get_scope().$apply(); }, + on_resources_filter_clear: function() { this._get_scope().$apply(); }, - // no prefix - on_filter_added: function(filter) { - this.filters.push(filter); - this._SetFiletredResources(this.filters); - //angular and UI - var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope(); - if (SchedulerDataViewData.length == 0) { - $("#plugin-scheduler").hide(); - $("#plugin-scheduler-empty").show(); - tmpScope.clearStuff(); - } else { - $("#plugin-scheduler-empty").hide(); - $("#plugin-scheduler").show(); - tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length); - } - }, + /* Filters on leases ? */ + on_leases_filter_added: function(filter) { this._get_scope().$apply(); }, + on_leases_filter_removed: function(filter) { this._get_scope().$apply(); }, + on_leases_filter_clear: function() { this._get_scope().$apply(); }, - on_filter_removed: function(filter) { - // Remove corresponding filters - this.filters = $.grep(this.filters, function(x) { - return x == filter; - }); - this._SetFiletredResources(this.filters); - //angular and UI - var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope(); - if (SchedulerDataViewData.length == 0) { - $("#plugin-scheduler").hide(); - $("#plugin-scheduler-empty").show(); - tmpScope.clearStuff(); - } else { - $("#plugin-scheduler-empty").hide(); - $("#plugin-scheduler").show(); - tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length); - } - }, + /* INTERNAL FUNCTIONS */ - on_filter_clear: function() { - this.filters = []; - this._SetFiletredResources(this.filters); - //angular and UI - var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope(); +/* XXX IN TEMPLATE XXX if (SchedulerDataViewData.length == 0) { $("#plugin-scheduler").hide(); $("#plugin-scheduler-empty").show(); @@ -238,296 +286,158 @@ var tmpSchedulerLeases = []; } else { $("#plugin-scheduler-empty").hide(); $("#plugin-scheduler").show(); + // initSchedulerResources tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length); } - }, - - on_all_leases_filter_added: function(filter) { - console.log("Filter on Leases added !"); - }, - - // ... be sure to list all events here - - /* RECORD HANDLERS */ - on_all_new_record: function(record) { - //alert('on_all_new_record'); - }, - - debug: function(logTxt) { - if (typeof window.console != 'undefined') { - console.debug(logTxt); - } - }, +*/ - /* INTERNAL FUNCTIONS */ - _initScheduler: function() { - if (_resourcesDone && _leasesDone) { - SchedulerDataViewData = SchedulerData; - /* GUI setup and event binding */ - this._FixLeases(); - this._initUI(); - } - }, + /** + * Initialize the date picker, the table, the slider and the buttons. Once done, display scheduler. + */ + _initUI: function() + { + var self = this; - _initUI: function() { - //alert(1); - if (schedulerDebug) console.time("_initUI"); - //init DatePicker Start $("#DateToRes").datepicker({ dateFormat: "yy-mm-dd", minDate: 0, numberOfMonths: 3 }).change(function() { - //Scheduler2.loadWithDate(); + // the selected date SchedulerDateSelected = $("#DateToRes").datepicker("getDate"); - if (SchedulerDateSelected != null && SchedulerDateSelected != '') { - for (var i = 0; i < SchedulerData.length; i++) { - SchedulerData[i].leases = schedulerGetLeases(60 / schedulerSlotsPerHour, SchedulerData[i].granularity); - } - scheduler2Instance._FixLeases(); - $('#tblSlider').slider('value', 0); - var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope(); - tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length); - - //console.log(SchedulerDateSelected); - //console.log(SchedulerDateSelected.getTime()/1000); - var tomorrow = new Date(SchedulerDateSelected); - tomorrow.setDate(SchedulerDateSelected.getDate()+1); - //console.log(tomorrow); - //console.log(tomorrow.getTime()/1000); - - // Remove previous date interval - manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_REMOVED, ['start_time', '>']); - manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_REMOVED, ['start_time', '<']); - - // Add new date interval - manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_ADDED, ['start_time', '>', SchedulerDateSelected.getTime()/1000]); - manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_ADDED, ['start_time', '<', tomorrow.getTime()/1000]); - } else { + if (SchedulerDateSelected == null || SchedulerDateSelected == '') { alert("Please select a date, so the scheduler can reserve leases."); + return; } + // Set slider to origin + $('#tblSlider').slider('value', 0); + // Refresh leases + self._scope_clear_leases(); + self._scope_set_leases(); + // Refresh display + self._get_scope().$apply(); }).datepicker('setDate', SchedulerDateSelected); - /*.click(function () { - $("#ui-datepicker-div").css("z-index", 5); - })*/ - //End init DatePicker - - //init Table - this._FixTable(); - //End init Table //init Slider $('#tblSlider').slider({ min: 0, - max: SchedulerTotalCells - SchedulerTotalVisibleCells, + max: (this._all_slots.length - self._num_visible_cells) / self._lcm_colspan, value: 0, slide: function(event, ui) { - //$("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]); - //console.log(ui.value); - var angScope = angular.element(document.getElementById('SchedulerCtrl')).scope(); - if (_schedulerCurrentCellPosition > ui.value) { - angScope.moveBackSlot(ui.value, ui.value + SchedulerTotalVisibleCells); - } else if (_schedulerCurrentCellPosition < ui.value) { - angScope.moveFrontSlot(ui.value, ui.value + SchedulerTotalVisibleCells); - } - _schedulerCurrentCellPosition = ui.value; - } + var scope = self._get_scope(); + scope.from = ui.value * self._lcm_colspan; + scope.$apply(); + } }); - //End init Slider - - - //btn Submit leases - $('#btnSchedulerSubmit').click(function () { - console.log("click btnSchedulerSubmit"); - var leasesForCommit = new Array(); - var tmpDateTime = SchedulerDateSelected; - console.log(SchedulerData); - for (var i = 0; i < SchedulerData.length; i++) - { - var tpmR = SchedulerData[i]; - //for capturing start and end of the lease - var newLeaseStarted = false; - for (var j = 0; j < tpmR.leases.length; j++) { - var tpmL = tpmR.leases[j]; - if (newLeaseStarted == false && tpmL.status == 'selected') { - //get date of the slot - tmpDateTime = schedulerGetDateTimeFromSlotId(tpmL.id, tmpDateTime); - var unixStartTime = tmpDateTime.getTime() / 1000; - //add lease object - leasesForCommit.push({ - resource: tpmR.id, - //granularity: tpmR.granularity, - //lease_type: null, - //slice: null, - start_time: unixStartTime, - end_time: null, - //duration: null - }); - console.log(tpmR.id); - newLeaseStarted = true; - } else if (newLeaseStarted == true && tpmL.status != 'selected') { - //get date of the slot - tmpDateTime = schedulerGetDateTimeFromSlotId(tpmL.id, tmpDateTime); - var unixEndTime = tmpDateTime.getTime() / 1000; - //upate end_time - var tmpCL = leasesForCommit[leasesForCommit.length - 1]; - tmpCL.end_time = unixEndTime; - //tmpCL.duration = schedulerFindDuration(tmpCL.start_time, tmpCL.end_time, tmpCL.granularity); - newLeaseStarted = false; - } - } - } - console.log(leasesForCommit); - for (var i = 0; i < leasesForCommit.length; i++) { - manifold.raise_event(scheduler2Instance.options.query_lease_uuid, SET_ADD, leasesForCommit[i]); - } - }); - // - - //End btn Submit leases + $('#btnSchedulerSubmit').click(this._on_submit); - //other stuff $("#plugin-scheduler-loader").hide(); $("#plugin-scheduler").show(); - //fixOddEvenClasses(); - //$("#" + schedulerTblId + " td:not([class])").addClass("free"); - if (schedulerDebug) console.timeEnd("_initUI"); }, - _FixLeases : function () { - for (var i = 0; i < tmpSchedulerLeases.length; i++) { - var tmpLea = tmpSchedulerLeases[i]; - if ((schedulerCompareOnDay(tmpLea.start_time, SchedulerDateSelected) == 0) || - (tmpLea.start_time <= SchedulerDateSelected && SchedulerDateSelected <= tmpLea.end_time) || - (schedulerCompareOnDay(tmpLea.end_time, SchedulerDateSelected) == 0)) { - var tmpRes = schedulerFindResourceById(SchedulerData, tmpLea.resource); - if (tmpRes != null) { - //Replace Lease with current lease from the manifold - var orgLease = tmpRes.leases[tmpLea.id]; - tmpLea['groupid'] = orgLease.groupid; - tmpLea['groupIndex'] = orgLease.groupIndex; - if (orgLease.groupIndex != 0) { - if (!window.console) { - console.warn('there is an error with the leases of the resource :' + tmpRes.name + '\n The lease start in the middle of the granularity!' + '\n The Scheduler plugin might not work!'); - } - } - tmpRes.leases[tmpLea.id] = tmpLea; - this._ExtractLeaseSlots(tmpRes, tmpRes.leases[tmpLea.id]); + // GUI EVENTS + + // TO BE REMOVED + _on_submit : function() + { + var leasesForCommit = new Array(); + var tmpDateTime = SchedulerDateSelected; + for (var i = 0; i < SchedulerData.length; i++) + { + var tpmR = SchedulerData[i]; + //for capturing start and end of the lease + var newLeaseStarted = false; + for (var j = 0; j < tpmR.leases.length; j++) { + var tpmL = tpmR.leases[j]; + if (newLeaseStarted == false && tpmL.status == 'selected') { + //get date of the slot + tmpDateTime = schedulerGetDateTimeFromSlotId(tpmL.id, tmpDateTime); + var unixStartTime = tmpDateTime.getTime() / 1000; + //add lease object + leasesForCommit.push({ + resource: tpmR.id, + //granularity: tpmR.granularity, + //lease_type: null, + //slice: null, + start_time: unixStartTime, + end_time: null, + //duration: null + }); + console.log(tpmR.id); + newLeaseStarted = true; + } else if (newLeaseStarted == true && tpmL.status != 'selected') { + //get date of the slot + tmpDateTime = schedulerGetDateTimeFromSlotId(tpmL.id, tmpDateTime); + var unixEndTime = tmpDateTime.getTime() / 1000; + //upate end_time + var tmpCL = leasesForCommit[leasesForCommit.length - 1]; + tmpCL.end_time = unixEndTime; + //tmpCL.duration = schedulerFindDuration(tmpCL.start_time, tmpCL.end_time, tmpCL.granularity); + newLeaseStarted = false; } } } - }, - - _ExtractLeaseSlots: function (tmpRes, lease) { - var tmpStartDate = lease.start_time; - var tmpEndDate = lease.end_time; - var startLoop; var toLoop; - if (schedulerCompareOnDay(lease.start_time,lease.end_time) == 0) { - //in the same date - startLoop = lease.id; - toLoop = lease.end_id; - } else if (lease.start_time < SchedulerDateSelected && SchedulerDateSelected < lease.end_time) { - //one hole day (more than 3days) - startLoop = 0; - toLoop = tmpRes.leases.length; - } else if (schedulerCompareOnDay(lease.start_time, SchedulerDateSelected) == 0) { - //the same day and extends - startLoop = lease.id; - toLoop = tmpRes.leases.length; - } else if (schedulerCompareOnDay(lease.end_time, SchedulerDateSelected) == 0) { - //extends to the last say - startLoop = 0; - toLoop = lease.end_id; - } - //var minutGran = tmpRes.granularity * 60; - for (var li = lease.id; li < toLoop; li++) { - tmpRes.leases[li].status = 'reserved'; + console.log(leasesForCommit); + for (var i = 0; i < leasesForCommit.length; i++) { + manifold.raise_event(scheduler2Instance.options.query_lease_uuid, SET_ADD, leasesForCommit[i]); } - - //reserved - //tmpRes.leases[tmpLea.id }, + + // PRIVATE METHODS - _FixTable: function () { - var colWidth = 50; - SchedulerTotalCells = SchedulerSlots.length; - $('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", schedulerTblFirstColWidth); //.css("display", "block"); - //this get width might need fix depending on the template - var tblwidth = $('#scheduler-tab').parent().outerWidth(); - SchedulerTotalVisibleCells = parseInt((tblwidth - schedulerTblFirstColWidth) / colWidth); - - //if (SchedulerData.length == 0) { - // //puth some test data - // SchedulerData.push({ name: 'xyz+aaa', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+aaa', type: 'node' }); - // SchedulerData.push({ name: 'xyz+bbb', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+bbb', type: 'node' }); - // SchedulerData.push({ name: 'xyz+ccc', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+ccc', type: 'node' }); - // SchedulerData.push({ name: 'nitos1', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'nitos1', type: 'node' }); - //} - var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope(); - tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length); - + /** + * Greatest common divisor + */ + _gcd : function(x, y) + { + return (y==0) ? x : this._gcd(y, x % y); }, - _SetFiletredResources : function (filters) { - if (filters.length > 0) { - SchedulerDataViewData = new Array(); - var tmpAddIt = true; - for (var i = 0; i < SchedulerData.length; i++) { - loopfilters: - for (var f = 0; f < filters.length; f++) { - tmpAddIt = this._FilterResource(SchedulerData[i], filters[f]); - if (tmpAddIt == false) break loopfilters; - } - if (tmpAddIt) { - SchedulerDataViewData.push(SchedulerData[i]); - } - } - } else { - SchedulerDataViewData = SchedulerData; - } + /** + * Least common multiple + */ + _lcm : function(x, y) + { + return x * y / this._gcd(x, y); + }, + + _pad_str : function(i) + { + return (i < 10) ? "0" + i : "" + i; }, - _FilterResource: function (resource, filter) { - var key = filter[0]; - var op = filter[1]; - var value = filter[2]; - var colValue = resource.org_resource[key]; - var ret = true; - if (schedulerDebug && colValue == 'omf') colValue = 'nitos'; - - if (op == '=' || op == '==') { - if (colValue != value || colValue == null || colValue == "" || colValue == "n/a") - ret = false; - } else if (op == 'included') { - $.each(value, function (i, x) { - if (x == colValue) { - ret = true; - return false; - } else { - ret = false; - } - }); - } else if (op == '!=') { - if (colValue == value || colValue == null || colValue == "" || colValue == "n/a") - ret = false; + /** + * Member variables used: + * _granularity + * + * Returns: + * A list of {id, time} dictionaries. + */ + _generate_all_slots: function() + { + var slots = []; + // Start with a random date (a first of a month), only time will matter + var d = new Date(2014, 1, 1, 0, 0, 0, 0); + var i = 0; + // Loop until we change the day + while (d.getDate() == 1) { + // Nicely format the time... + var tmpTime = this._pad_str(d.getHours()) + ':' + this._pad_str(d.getMinutes()); + /// ...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); + i++; } + return slots; - return ret; }, - - _SetPeriodInPage: function (start, end) { - } }); - //Sched2 = new Scheduler2(); - /* Plugin registration */ $.plugin('Scheduler2', scheduler2); - // TODO Here use cases for instanciating plugins in different ways like in the pastie. - - })(jQuery);