X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=inline;f=plugins%2Fscheduler2%2Fstatic%2Fjs%2Fscheduler-helpers.js;h=7275b7556948109a825932d67bdea23126779237;hb=ca18b72eaf2f8f06a41136cb95fdc4f04cf67c0b;hp=df9ac9ffd2ab72ccc7b10ccdec83d9aeb6362fe1;hpb=bf8ddd53efffa8c459343678686c0e7e4575a651;p=myslice.git diff --git a/plugins/scheduler2/static/js/scheduler-helpers.js b/plugins/scheduler2/static/js/scheduler-helpers.js index df9ac9ff..7275b755 100755 --- a/plugins/scheduler2/static/js/scheduler-helpers.js +++ b/plugins/scheduler2/static/js/scheduler-helpers.js @@ -46,29 +46,23 @@ function schedulerCloneArray(originalArray) { return clonedArray; } -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); - var i = 0; - while (d.getDate() == 1) { - var tmpTime = schedulerPadStr(d.getHours()) + ':' + schedulerPadStr(d.getMinutes()); - slots.push({ id: i, time: tmpTime }); - d = schedulerAddMinutes(d, slotSpan); - i++; - } - return slots; -} - -function schedulerGetLeases(slotSpan) { - if (slotSpan == 0) slotSpan = 10; - var slots = []; - var d = new Date(2014, 1, 1, 0, 0, 0, 0); - var i = 0; + var i = 0; var j = 0; var g = 0; + var maxg = granularity / slotSpan; while (d.getDate() == 1) { //slots.push({ id: i, status: getRandomStatus() }); - slots.push({ id: i, status: "free" }); + slots.push({ id: i, status: "free", groupid: j, groupIndex: g }); d = schedulerAddMinutes(d, slotSpan); + //fix counters + g++; + if (maxg == g) { + g = 0; + j++; + } i++; } return slots; @@ -77,6 +71,7 @@ function schedulerGetLeases(slotSpan) { // //GetSlotId from time function schedulerGetSlotId(startTime, duration, granularity) { + //granularity in seconds startTime = parseInt(startTime); var d = new Date(startTime * 1000); var timespan = 60 / schedulerSlotsPerHour; @@ -85,13 +80,69 @@ 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); -function schedulerSelectSlot(slotId, resourceIndex) { - SchedulerDataViewData[resourceIndex].leases[slotId].status = 'selected'; + return tmpDateTime; } -function schedulerFreeSlot(slotId, resourceIndex) { - SchedulerDataViewData[resourceIndex].leases[slotId].status = 'free'; +// +//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) { + console.log('timeslot selected'); + _schedulerSetStatusSlot(slotId, rowIndex, resourceIndex, 'selected'); +} +function schedulerFreeSlot(slotId, rowIndex, resourceIndex) { + _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 + console.log(SchedulerData[resourceIndex].id); + 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[resourceIndex].leases[startSlotId].status = classText; + } + startSlotId++; + } + } +// +// Set Select - Free Slots *******End + // //Find Resource By Id function schedulerFindResourceById(Resources, id) { @@ -120,4 +171,26 @@ function schedulerPadStr(i) { function schedulerAddMinutes(date, minutes) { return new Date(date.getTime() + minutes * 60000); -} \ No newline at end of file +} + +/** + * Compares two dates + * + * Returns: + * 0 if they are equal + * -1 if the first is less than the second + * 1 if the first is more than the second + */ +function schedulerCompareOnDay(dateOne, dateTwo) +{ + if (dateOne.getYear() == dateTwo.getYear() && + dateOne.getMonth() == dateTwo.getMonth() && + dateOne.getDate() == dateTwo.getDate()) { + return 0; + } else if (dateOne > dateTwo) { + return -1; + } else { + return 1; + } + +}