From f96c4dccedd88193b7e273dc0a925ce5e76c44f1 Mon Sep 17 00:00:00 2001 From: Chrysostomos Kolovos Date: Sat, 3 May 2014 00:48:08 +0300 Subject: [PATCH] Chrysostomos for scheduler --- .../scheduler2/static/js/scheduler-helpers.js | 62 +- .../static/js/scheduler-table-selector.js | 34 +- plugins/scheduler2/static/js/scheduler2.js | 553 ++++++++++-------- plugins/scheduler2/templates/scheduler.html | 91 +-- 4 files changed, 429 insertions(+), 311 deletions(-) diff --git a/plugins/scheduler2/static/js/scheduler-helpers.js b/plugins/scheduler2/static/js/scheduler-helpers.js index 5de21cb9..d6f32247 100755 --- a/plugins/scheduler2/static/js/scheduler-helpers.js +++ b/plugins/scheduler2/static/js/scheduler-helpers.js @@ -61,6 +61,7 @@ function schedulerGetSlots(slotSpan) { } function schedulerGetLeases(slotSpan, granularity) { + granularity = granularity / 60; if (slotSpan == 0) slotSpan = 10; var slots = []; var d = new Date(2014, 1, 1, 0, 0, 0, 0); @@ -84,6 +85,7 @@ function schedulerGetLeases(slotSpan, granularity) { // //GetSlotId from time function schedulerGetSlotId(startTime, duration, granularity) { + //granularity in seconds startTime = parseInt(startTime); var d = new Date(startTime * 1000); var timespan = 60 / schedulerSlotsPerHour; @@ -92,15 +94,67 @@ function schedulerGetSlotId(startTime, duration, granularity) { slotid += d.getMinutes() / timespan; return slotid; } +// +//GetSlotId from time +function schedulerGetDateTimeFromSlotId(slotId, tmpDateTime) { + + var timespan = 60 / schedulerSlotsPerHour; + var totalMinutes = slotId * timespan; + var totalHours = totalMinutes / 60; + if (totalHours >= 1) { + totalHours = Math.floor(totalHours); + totalMinutes = totalMinutes - totalHours * 60; + } else { + totalHours = 0; + } + tmpDateTime.setHours(totalHours, totalMinutes, 0, 0); + return tmpDateTime; +} +// +//GetSlotId from time +function schedulerFindDuration(startTime, endTime, granularity) { + var duration = 0; + var fd = new Date(startTime * 1000); + var td = new Date(endTime * 1000); + while (fd < td) { + duration++; + fd.setMinutes(fd.getMinutes() + granularity); + } + return duration; +} + +// +// Set Select - Free Slots *******Start function schedulerSelectSlot(slotId, rowIndex, resourceIndex) { - SchedulerDataViewData[rowIndex].leases[slotId].status = 'selected'; - SchedulerData[resourceIndex].leases[slotId].status = 'selected'; + _schedulerSetStatusSlot(slotId, rowIndex, resourceIndex, 'selected'); } function schedulerFreeSlot(slotId, rowIndex, resourceIndex) { - SchedulerDataViewData[rowIndex].leases[slotId].status = 'free'; - SchedulerData[resourceIndex].leases[slotId].status = 'free'; + _schedulerSetStatusSlot(slotId, rowIndex, resourceIndex, 'free'); } + +function _schedulerSetStatusSlot(slotId, rowIndex, resourceIndex, classText) { + var tmpVS = SchedulerDataViewData[rowIndex].leases[slotId]; // for the display + var tmpS = SchedulerData[resourceIndex].leases[slotId]; // for the data + tmpVS.status = classText; + tmpS.status = classText; + //select other from the group in the same granularity + var slotSpan = 60 / schedulerSlotsPerHour; + var maxg = (SchedulerData[resourceIndex].granularity / 60) / slotSpan; + + var startSlotId = tmpVS.groupIndex == 0 ? 0 : slotId - tmpVS.groupIndex; + for (var s = 0; s < maxg; s++) { + if (tmpVS.groupIndex != s) { + SchedulerDataViewData[rowIndex].leases[startSlotId].status = classText; + SchedulerData[rowIndex].leases[startSlotId].status = classText; + } + startSlotId++; + } + +} +// +// Set Select - Free Slots *******End + // //Find Resource By Id function schedulerFindResourceById(Resources, id) { diff --git a/plugins/scheduler2/static/js/scheduler-table-selector.js b/plugins/scheduler2/static/js/scheduler-table-selector.js index 6f5f4a9b..abd8a69f 100755 --- a/plugins/scheduler2/static/js/scheduler-table-selector.js +++ b/plugins/scheduler2/static/js/scheduler-table-selector.js @@ -28,9 +28,10 @@ function rangeMouseDown(e) { //var allCells = $("#tblReservation td"); //dragStart = allCells.index($(this)); - if ( $(this).hasClass("free")) + if ( $(this).hasClass("free")){ $(this).addClass("selected_tmp"); - + $(this).siblings("td[data-groupid='" + $(this).data('groupid') + "']").addClass("selected_tmp"); + } schedulerTableIsDragging = true; //selectRange(); @@ -82,6 +83,7 @@ function selectRange(isTemp) { if (!schedulerCtrlPressed) $("#" + schedulerTblId + " td.selected, #" + schedulerTblId + " td.selected_tmp").each(function() { $(this).removeClass('selected selected_tmp').addClass('free'); + $(this).siblings("td[data-groupid='" + $(this).data('groupid') + "']").removeClass('selected selected_tmp').addClass("free"); schedulerFreeSlot($(this).data('slotid'), $(this).siblings('th').data('rowindex'), $(this).siblings('th').data('resourceindex')); }); @@ -116,38 +118,50 @@ function selectRange(isTemp) { switch (curClass) { case "free_tmp": $(cell).removeClass('selected_tmp selected free_tmp free'); - if (isTemp) + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").removeClass("selected_tmp selected free_tmp free"); + if (isTemp){ $(cell).addClass("free_tmp"); - else{ + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("free"); + } else { schedulerFreeSlot($(cell).data('slotid'), $(cell).siblings('th').data('rowindex'), $(cell).siblings('th').data('resourceindex')); $(cell).addClass("free"); + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("free"); } break; case "free": $(cell).removeClass('selected_tmp selected free_tmp free'); - if (isTemp) + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").removeClass("selected_tmp selected free_tmp free"); + if (isTemp){ $(cell).addClass("selected_tmp"); - else { + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("selected_tmp"); + }else { schedulerSelectSlot($(cell).data('slotid'), $(cell).siblings('th').data('rowindex'), $(cell).siblings('th').data('resourceindex')); $(cell).addClass("selected"); + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("selected"); } break; case "selected_tmp": $(cell).removeClass('selected_tmp selected free_tmp free'); - if (isTemp) + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").removeClass("selected_tmp selected free_tmp free"); + if (isTemp){ $(cell).addClass("selected_tmp"); - else { + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("selected_tmp"); + } else { schedulerSelectSlot($(cell).data('slotid'), $(cell).siblings('th').data('rowindex'), $(cell).siblings('th').data('resourceindex')); $(cell).addClass("selected"); + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("selected"); } break; case "selected": $(cell).removeClass('selected_tmp selected free_tmp free'); - if (isTemp) + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").removeClass("selected_tmp selected free_tmp free"); + if (isTemp){ $(cell).addClass("free_tmp"); - else { + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("free_tmp"); + } else { schedulerFreeSlot($(cell).data('slotid'), $(cell).siblings('th').data('rowindex'), $(cell).siblings('th').data('resourceindex')); $(cell).addClass("free"); + $(cell).siblings("td[data-groupid='" + $(cell).data('groupid') + "']").addClass("free"); } break; case "closed": diff --git a/plugins/scheduler2/static/js/scheduler2.js b/plugins/scheduler2/static/js/scheduler2.js index 8f786de5..3b59755f 100755 --- a/plugins/scheduler2/static/js/scheduler2.js +++ b/plugins/scheduler2/static/js/scheduler2.js @@ -53,277 +53,324 @@ var schedulerDebug = true; //tmp to delete var tmpSchedulerLeases = []; -(function ($) { - scheduler2 = Plugin.extend({ +(function($) { + scheduler2 = Plugin.extend({ - /** XXX to check + /** XXX to check * @brief Plugin constructor * @param options : an associative array of setting values * @param element : * @return : a jQuery collection of objects on which the plugin is * applied, which allows to maintain chainability of calls */ - init: function (options, element) { - this.classname="scheduler2"; - // Call the parent constructor, see FAQ when forgotten - this._super(options, element); - scheduler2Instance = this; - // We need to remember the active filter for datatables filtering - this.filters = Array(); - - - SchedulerSlots = schedulerGetSlots(60/schedulerSlotsPerHour); - //selection from table - $(window).keydown(function (evt) { - if (evt.which == 17) { // ctrl - schedulerCtrlPressed = true; + init: function(options, element) { + this.classname = "scheduler2"; + // Call the parent constructor, see FAQ when forgotten + this._super(options, element); + scheduler2Instance = this; + // We need to remember the active filter for datatables filtering + this.filters = Array(); + + + SchedulerSlots = schedulerGetSlots(60 / schedulerSlotsPerHour); + //selection from table + $(window).keydown(function(evt) { + if (evt.which == 17) { // ctrl + schedulerCtrlPressed = true; + } + }).keyup(function(evt) { + if (evt.which == 17) { // ctrl + 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 + + if (schedulerDebug) console.time("Listening_to_queries"); + /* Listening to queries */ + + 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_lease_uuid, 'lease'); + if (schedulerDebug) console.timeEnd("Listening_to_queries"); + + }, + + /* 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'); + }, + //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 + }, + 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; + }*/ } - }).keyup(function (evt) { - if (evt.which == 17) { // ctrl - schedulerCtrlPressed = false; + //alert(data.toSource()); + + }, + on_all_resources_query_done: function(data) { + _resourcesDone = true; + this._initScheduler(); + }, + //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'); + }, + /* 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_lease_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 + }); } - }); - $("#" + 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 - - if (schedulerDebug) console.time("Listening_to_queries"); - /* Listening to queries */ - - 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_lease_uuid, 'lease'); - if (schedulerDebug) console.timeEnd("Listening_to_queries"); - - }, - - /* 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'); - }, - //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 - }, - on_all_resources_new_record: function (data) { - //alert(data.toSource()); - if (data.exclusive == true){ - SchedulerData.push({ - id: data.urn, - index: SchedulerData.length, - name: data.hrn, - granularity: data.granularity, - leases: schedulerGetLeases(60 / schedulerSlotsPerHour, data.granularity), - type: data.type, - org_resource: data - }); - if (schedulerDebug && SchedulerData[SchedulerData.length - 1].org_resource.network_hrn == 'omf') { - SchedulerData[SchedulerData.length - 1].granularity = 1800; + //console.log(data.toSource()); console.log('lease_new_record'); + }, + on_lease_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 */ + + + // 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); } - } - //alert(data.toSource()); + }, - }, - on_all_resources_query_done: function (data) { - _resourcesDone = true; - this._initScheduler(); - }, - //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'); - }, - /* 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_lease_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_filter_removed: function(filter) { + // Remove corresponding filters + this.filters = $.grep(this.filters, function(x) { + return x == filter; }); - } - //console.log(data.toSource()); console.log('lease_new_record'); - }, - on_lease_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 */ - - - // 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); - } - }, - - 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); - } - }, - - on_filter_clear: function () { - this.filters = []; - 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); - } - }, - - // ... be sure to list all events here - - /* RECORD HANDLERS */ - on_all_new_record: function (record) { - //alert('on_all_new_record'); - }, + 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); + } + }, + + on_filter_clear: function() { + this.filters = []; + 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); + } + }, - debug : function (logTxt) { - if (typeof window.console != 'undefined') { - console.debug(logTxt); - } - }, + // ... be sure to list all events here - /* INTERNAL FUNCTIONS */ - _initScheduler: function () { - if (_resourcesDone && _leasesDone) - { - SchedulerDataViewData = SchedulerData; - /* GUI setup and event binding */ - this._FixLeases(); - this._initUI(); - } - }, + /* RECORD HANDLERS */ + on_all_new_record: function(record) { + //alert('on_all_new_record'); + }, - _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(); - 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); - } else { - alert("Please select a date, so the scheduler can reserve leases."); + debug: function(logTxt) { + if (typeof window.console != 'undefined') { + console.debug(logTxt); } - }).datepicker('setDate', SchedulerDateSelected); - /*.click(function () { + }, + + /* INTERNAL FUNCTIONS */ + _initScheduler: function() { + if (_resourcesDone && _leasesDone) { + SchedulerDataViewData = SchedulerData; + /* GUI setup and event binding */ + this._FixLeases(); + this._initUI(); + } + }, + + _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(); + 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); + } else { + alert("Please select a date, so the scheduler can reserve leases."); + } + }).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, - 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); + //End init DatePicker + + //init Table + this._FixTable(); + //End init Table + + //init Slider + $('#tblSlider').slider({ + min: 0, + max: SchedulerTotalCells - SchedulerTotalVisibleCells, + 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; + } + }); + //End init Slider + + + //btn Submit leases + $('#btnSchedulerSubmit').click(function () { + var leasesForCommit = new Array(); + var newLeaseStarted = false; + var tmpDateTime = SchedulerDateSelected; + for (var i = 0; i < SchedulerData.length; i++) + { + var tpmR = SchedulerData[i]; + 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 + }); + 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; + } + } } - else if (_schedulerCurrentCellPosition < ui.value) { - angScope.moveFrontSlot(ui.value, ui.value + SchedulerTotalVisibleCells); + + for (var i = 0; i < leasesForCommit.length; i++) { + //manifold.raise_event(scheduler.options.query_lease_uuid, SET_ADD, new_lease); } - _schedulerCurrentCellPosition = ui.value; - } - }); - //End init Slider - - //other stuff - $("#plugin-scheduler-loader").hide(); - $("#plugin-scheduler").show(); - //fixOddEvenClasses(); - //$("#" + schedulerTblId + " td:not([class])").addClass("free"); - if (schedulerDebug) console.timeEnd("_initUI"); - }, + }); + // + + + //End btn Submit leases + + //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++) { @@ -427,7 +474,7 @@ var tmpSchedulerLeases = []; if (schedulerDebug && colValue == 'omf') colValue = 'nitos'; if (op == '=' || op == '==') { - if (colValue != value || colValue == null || colValue == "" || colValue == "n/a") + if (colValue != value || colValue == null || colValue == "" || colValue == "n/a") ret = false; } else if (op == 'included') { $.each(value, function (i, x) { @@ -439,7 +486,7 @@ var tmpSchedulerLeases = []; } }); } else if (op == '!=') { - if (colValue == value || colValue == null || colValue == "" || colValue == "n/a") + if (colValue == value || colValue == null || colValue == "" || colValue == "n/a") ret = false; } diff --git a/plugins/scheduler2/templates/scheduler.html b/plugins/scheduler2/templates/scheduler.html index f5faba9f..d7cd16e6 100755 --- a/plugins/scheduler2/templates/scheduler.html +++ b/plugins/scheduler2/templates/scheduler.html @@ -16,6 +16,7 @@
+ {% comment %}
@@ -51,7 +54,7 @@ # - + {[{ slot.time }]} @@ -59,7 +62,7 @@ {[{ resource.name }]} - + @@ -79,48 +82,48 @@ - {% comment %} -
- - - - {% for ts in time_slots %} - - {% endfor %} - - - + {% comment %} +
+
{{ ts|safe }}
+ + + {% for ts in time_slots %} + + {% endfor %} + + + - {% for itms in nodes %} - {% for n in itms.1 %} - - {% for ts in time_slots %} - {% if n == 'node020' %} - - {% elif n == 'node023' or n == 'node030' %} - - {% else %} - - {% endif %} + {% for itms in nodes %} + {% for n in itms.1 %} + + {% for ts in time_slots %} + {% if n == 'node020' %} + + {% elif n == 'node023' or n == 'node030' %} + + {% else %} + + {% endif %} + {% endfor %} + {% endfor %} - - {% endfor %} - {% endfor %} - -
{{ ts|safe }}
-
- {% endcomment %} + {% endfor %} + + + + {% endcomment %} -
-
    -
  1. free
  2. -
  3. selected
  4. -
  5. reserved
  6. -
  7. maintenance
  8. -
-
- - - \ No newline at end of file +
+
    +
  1. free
  2. +
  3. selected
  4. +
  5. reserved
  6. +
  7. maintenance
  8. +
+
+ + + -- 2.47.0