Browse code

[Calendar] BM-12938 Fix: Adapt freebusy slot to match current displayed range

Mehdi Rande authored on 08/03/2018 15:12:54
Showing 3 changed files
... ...
@@ -452,22 +452,16 @@ net.bluemind.calendar.vevent.VEventPresenter.prototype.freeBusyRequest = functio
452 452
       if (slot['type'] == 'FREE') {
453 453
         return;
454 454
       }
455
-      var dtstart = new net.bluemind.date.DateTime(this.ctx.helper('date').fromBMDateTime(slot['dtstart']));
456
-      var dtend = new net.bluemind.date.DateTime(this.ctx.helper('date').fromBMDateTime(slot['dtend']));
457
-
458
-      var i = dtstart.getDay() * 24 * 2;
459
-      if (dtstart.getHours()) {
460
-        i += dtstart.getHours() * 2;
461
-      }
462
-      if (dtstart.getMinutes() == 30) {
463
-        i += 1;
464
-      }
455
+      var dtstart = this.ctx.helper('date').fromBMDateTime(slot['dtstart']);
456
+      var dtend = this.ctx.helper('date').fromBMDateTime(slot['dtend']);
457
+      dtstart = new net.bluemind.date.DateTime(range.isAfter(dtstart) ? range.getStartDate() : dtstart);
458
+      dtend = new net.bluemind.date.DateTime(range.isBefore(dtend) ? range.getEndDate() : dtend);
465 459
 
466 460
       var step = new goog.date.Interval(goog.date.Interval.MINUTES, 30);
467 461
       while (goog.date.Date.compare(dtstart, dtend) < 0) {
462
+        var i = ((dtstart.getDay() * 24) + dtstart.getHours ()) * 2 + Math.trunc(dtstart.getMinutes() / 30);
468 463
         slots[i] = slot['type'];
469 464
         dtstart.add(step)
470
-        i++;
471 465
       }
472 466
     }, this);
473 467
     return slots;
... ...
@@ -216,6 +216,9 @@ net.bluemind.calendar.vevent.ui.Freebusy.prototype.updateBusySlots = function()
216 216
   }, this);
217 217
   for (var i = 0; i < this.currentBusySlots_.length; i++) {
218 218
     var time = times.item(i);
219
+    if (!time) {
220
+      continue;
221
+    }
219 222
     goog.dom.classlist.enable(time, goog.getCssName('outOfWorkFreeBusy'),
220 223
         this.currentBusySlots_[i] == 'BusyUnavailable');
221 224
     goog.dom.classlist.enable(time, goog.getCssName('Busy'), this.currentBusySlots_[i] == 'Busy');
... ...
@@ -548,6 +551,7 @@ net.bluemind.calendar.vevent.ui.Freebusy.prototype.loadEventInfos = function(use
548 548
         date = dateFormatter.time.format(start);
549 549
       } else {
550 550
         date = dateFormatter.date.format(start);
551
+        end.add(new goog.date.Interval(0, 0, -1));
551 552
       }
552 553
       if (goog.date.isSameDay(start, end)) {
553 554
         if (!allday) {
... ...
@@ -805,6 +809,9 @@ net.bluemind.calendar.vevent.ui.Freebusy.prototype.setFreeBusy_ = function(atten
805 805
       var index = (i + start) % opt_slots.length;
806 806
       var slot = opt_slots[index];
807 807
       var time = times.item(i);
808
+      if (!time) {
809
+        continue;
810
+      }
808 811
       // TODO css for BUSYTENTATIVE ?
809 812
       goog.dom.classlist.enable(time, goog.getCssName('Busy'), (slot == 'BUSY' || slot == 'BUSYTENTATIVE'));
810 813
       goog.dom.classlist.enable(time, goog.getCssName('outOfWorkFreeBusy'), slot == 'BUSYUNAVAILABLE');
... ...
@@ -105,6 +105,28 @@ net.bluemind.date.DateRange.prototype.contains = function(date) {
105 105
   return date.valueOf() >= this.getStartDate().valueOf() && date.valueOf() < this.getEndDate().valueOf();
106 106
 };
107 107
 
108
+
109
+/**
110
+ * Tests if a date falls before this range.
111
+ * 
112
+ * @param {goog.date.Date} date The date to test.
113
+ * @return {boolean} Whether the date is in the range.
114
+ */
115
+net.bluemind.date.DateRange.prototype.isAfter = function(date) {
116
+  return date.valueOf() < this.getStartDate().valueOf() ;
117
+};
118
+
119
+
120
+/**
121
+ * Tests if a date falls after this range.
122
+ * 
123
+ * @param {goog.date.Date} date The date to test.
124
+ * @return {boolean} Whether the date is in the range.
125
+ */
126
+net.bluemind.date.DateRange.prototype.isBefore = function(date) {
127
+  return  date.valueOf() >= this.getEndDate().valueOf();
128
+};
129
+
108 130
 /**
109 131
  * Only iterate over included days
110 132
  *