Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

fix(WeekView): Temporarily revert to the old behaviour as the new fun…

…ctionality has a load of bugs
  • Loading branch information...
Matt Lewis
Matt Lewis committed Nov 30, 2015
1 parent 89dda6a commit 2d36a5415b45d54ef4f60f24528dff6a003d0bb1
@@ -18,16 +18,16 @@ angular
vm.dayViewEnd,
vm.dayViewSplit
);

vm.view = calendarHelper.getWeekView(vm.events, vm.currentDay, vm.showTimes);
if (vm.showTimes) {
vm.viewWithTimes = calendarHelper.getWeekViewWithTimes(
vm.view = calendarHelper.getWeekViewWithTimes(
vm.events,
vm.currentDay,
vm.dayViewStart,
vm.dayViewEnd,
vm.dayViewSplit
);
} else {
vm.view = calendarHelper.getWeekView(vm.events, vm.currentDay);
}
});

@@ -74,31 +74,6 @@ angular
event.tempStartsAt = moment(event.startsAt).add(minutesDiff, 'minutes').toDate();
};

vm.eventResizeComplete = function(event, edge, minuteChunksMoved) {
var minutesDiff = minuteChunksMoved * vm.dayViewSplit;
var start = moment(event.startsAt);
var end = moment(event.endsAt);
if (edge === 'start') {
start.add(minutesDiff, 'minutes');
} else {
end.add(minutesDiff, 'minutes');
}
delete event.tempStartsAt;

vm.onEventTimesChanged({
calendarEvent: event,
calendarNewEventStart: start.toDate(),
calendarNewEventEnd: end.toDate()
});
};

vm.eventResized = function(event, edge, minuteChunksMoved) {
var minutesDiff = minuteChunksMoved * vm.dayViewSplit;
if (edge === 'start') {
event.tempStartsAt = moment(event.startsAt).add(minutesDiff, 'minutes').toDate();
}
};

})
.directive('mwlCalendarWeek', function(calendarUseTemplates) {

@@ -161,7 +161,7 @@ angular

}

function getWeekView(events, currentDay, filterOneDayEvents) {
function getWeekView(events, currentDay) {

var startOfWeek = moment(currentDay).startOf('week');
var endOfWeek = moment(currentDay).endOf('week');
@@ -181,12 +181,6 @@ angular
dayCounter.add(1, 'day');
}

if (filterOneDayEvents) {
events = events.filter(function(event) {
return !moment(event.startsAt).isSame(moment(event.endsAt), 'day');
});
}

var eventsSorted = filterEventsInPeriod(events, startOfWeek, endOfWeek).map(function(event) {

var eventStart = moment(event.startsAt).startOf('day');
@@ -221,45 +215,8 @@ angular

}

function getCrossingsCount(event, dayEvents) {
var eventStart = moment(event.startsAt);
var eventEnd = moment(event.endsAt);

return dayEvents.filter(function(ev) {

return event.$id !== ev.$id &&
(moment(ev.startsAt).isBetween(eventStart, eventEnd) ||
moment(ev.startsAt).isSame(eventStart) ||
moment(ev.endsAt).isBetween(eventStart, eventEnd) ||
moment(ev.endsAt).isSame(eventEnd) ||
moment(ev.startsAt).isBefore(eventStart) && moment(ev.endsAt).isAfter(eventEnd));
}).length;
}

function eventsComparer(a, b) {
var aStart = moment(a.startsAt);
var bStart = moment(b.startsAt);

if (aStart.isBefore(bStart)) {
return -1;
}
function getDayView(events, currentDay, dayViewStart, dayViewEnd, dayViewSplit) {

if (aStart.isSame(bStart)) {
var aEnd = moment(a.endsAt);
var bEnd = moment(b.endsAt);

if (aEnd.isSame(bEnd)) {
return 0;
} else if (aEnd.isAfter(bEnd)) {
return -1;
}
return 1;
}
return 1;
}

function getDayView(events, currentDay, dayViewStart, dayViewEnd, dayViewSplit, isWeekViewWithTimes) {
var baseBucketWidth = isWeekViewWithTimes ? 14.285714285714285 : 150;
var dayStartHour = moment(dayViewStart || '00:00', 'HH:mm').hours();
var dayEndHour = moment(dayViewEnd || '23:00', 'HH:mm').hours();
var hourHeight = (60 / dayViewSplit) * 30;
@@ -274,7 +231,7 @@ angular
moment(currentDay).endOf('day').toDate()
);

return eventsInPeriod.sort(eventsComparer).map(function(event) {
return eventsInPeriod.map(function(event) {
if (moment(event.startsAt).isBefore(calendarStart)) {
event.top = 0;
} else {
@@ -300,10 +257,12 @@ angular
}

event.left = 0;

return event;
}).filter(function(event) {
return event.height > 0;
}).map(function(event) {

var cannotFitInABucket = true;
buckets.forEach(function(bucket, bucketIndex) {
var canFitInThisBucket = true;
@@ -317,47 +276,36 @@ angular

if (canFitInThisBucket && cannotFitInABucket) {
cannotFitInABucket = false;
event.left = bucketIndex * baseBucketWidth;
if (isWeekViewWithTimes) {
event.bucketIndex = buckets.length;
}
event.left = bucketIndex * 150;
buckets[bucketIndex].push(event);
}

});

if (cannotFitInABucket) {
event.left = buckets.length * baseBucketWidth;
if (isWeekViewWithTimes) {
event.bucketIndex = buckets.length;
}
event.left = buckets.length * 150;
buckets.push([event]);
}

return event;
}).map(function(event) {
if (isWeekViewWithTimes) {
event.width = getCrossingsCount(event, eventsInPeriod) > 0 ? baseBucketWidth / buckets.length : baseBucketWidth;
event.left = event.bucketIndex * baseBucketWidth / (buckets.length);
delete event.bucketIndex;
}
return event;

});

}

function getWeekViewWithTimes(events, currentDay, dayViewStart, dayViewEnd, dayViewSplit) {
var weekView = getWeekView(events, currentDay, false);
var weekView = getWeekView(events, currentDay);
var newEvents = [];
weekView.days.forEach(function(day) {
var dayEvents = weekView.events.filter(function(event) {
return moment(event.startsAt).isSame(moment(day.date), 'day') &&
moment(event.endsAt).isSame(moment(day.date), 'day');
return moment(event.startsAt).startOf('day').isSame(moment(day.date).startOf('day'));
});
var newDayEvents = getDayView(
dayEvents,
day.date,
dayViewStart,
dayViewEnd,
dayViewSplit,
true
dayViewSplit
);
newEvents = newEvents.concat(newDayEvents);
});
@@ -382,9 +330,7 @@ angular
getDayViewHeight: getDayViewHeight,
adjustEndDateFromStartDiff: adjustEndDateFromStartDiff,
formatDate: formatDate,
eventIsInPeriod: eventIsInPeriod, //expose for testing only
getCrossingsCount: getCrossingsCount, //expose for testing only
eventsComparer: eventsComparer //expose for testing only
eventIsInPeriod: eventIsInPeriod //expose for testing only
};

});
@@ -27,38 +27,6 @@
</div>

<div class="cal-day-panel clearfix" ng-style="{height: vm.showTimes ? (vm.dayViewHeight + 'px') : 'auto'}">
<div class="row">
<div class="col-xs-12">
<div
class="cal-row-fluid"
ng-repeat="event in vm.view.events track by event.$id">
<div
ng-class="'cal-cell' + event.daySpan + ' cal-offset' + event.dayOffset + ' day-highlight dh-event-' + event.type + ' ' + event.cssClass"
ng-style="{top: 'auto', position: 'inherit'}"
data-event-class
mwl-draggable="event.draggable === true"
axis="'x'"
snap-grid="{x: vm.dayColumnDimensions.width}"
on-drag="vm.tempTimeChanged(event, y)"
on-drag-end="vm.weekDragged(event, x, y)"
mwl-resizable="event.resizable === true && event.endsAt"
resize-edges="{left: true, right: true}"
on-resize-end="vm.weekResized(event, edge, x)">
<strong ng-bind="(event.tempStartsAt || event.startsAt) | calendarDate:'time':true" ng-show="vm.showTimes"></strong>
<a
href="javascript:;"
ng-click="vm.onEventClick({calendarEvent: event})"
class="event-item"
ng-bind-html="vm.$sce.trustAsHtml(event.title)"
tooltip-html-unsafe="{{ event.title }}"
tooltip-placement="left"
tooltip-append-to-body="true">
</a>
</div>
</div>
</div>

</div>

<mwl-calendar-hour-list
day-view-start="vm.dayViewStart"
@@ -68,25 +36,25 @@
on-timespan-click="vm.onTimespanClick"
ng-if="vm.showTimes">
</mwl-calendar-hour-list>
<div class="row" ng-if="vm.showTimes">

<div class="row">
<div class="col-xs-12">
<div
class="cal-row-fluid"
ng-repeat="event in vm.viewWithTimes.events track by event.$id">
class="cal-row-fluid "
ng-repeat="event in vm.view.events track by event.$id">
<div
ng-class="'cal-cell' + 1 + ' cal-offset' + event.dayOffset + ' day-highlight dh-event-' + event.type + ' ' + event.cssClass"
ng-style="{top: ((event.top + 2) + 'px'), position: 'absolute', height: event.height + 'px', left: event.left + '%', width: event.width + '%'}"
ng-class="'cal-cell' + (vm.showTimes ? 1 : event.daySpan) + ' cal-offset' + event.dayOffset + ' day-highlight dh-event-' + event.type + ' ' + event.cssClass"
ng-style="{top: vm.showTimes ? ((event.top + 2) + 'px') : 'auto', position: vm.showTimes ? 'absolute' : 'inherit'}"
data-event-class
mwl-draggable="event.draggable === true"
axis="vm.showTimes ? 'xy' : 'x'"
snap-grid="{x: vm.dayColumnDimensions.width, y: 30}"
snap-grid="vm.showTimes ? {x: vm.dayColumnDimensions.width, y: 30} : {x: vm.dayColumnDimensions.width}"
on-drag="vm.tempTimeChanged(event, y)"
on-drag-end="vm.weekDragged(event, x, y)"
mwl-resizable="event.resizable === true && event.endsAt"
resize-edges="{top: true, bottom: true}"
on-resize="vm.eventResized(event, edge, y)"
on-resize-end="vm.eventResizeComplete(event, edge, y)">
<strong ng-bind="(event.tempStartsAt || event.startsAt) | calendarDate:'time':true"></strong>
mwl-resizable="event.resizable === true && event.endsAt && !vm.showTimes"
resize-edges="{left: true, right: true}"
on-resize-end="vm.weekResized(event, edge, x)">
<strong ng-bind="(event.tempStartsAt || event.startsAt) | calendarDate:'time':true" ng-show="vm.showTimes"></strong>
<a
href="javascript:;"
ng-click="vm.onEventClick({calendarEvent: event})"
@@ -83,19 +83,18 @@ describe('mwlCalendarWeek directive', function() {

it('should get the new week view when calendar refreshes', function() {
sinon.stub(calendarHelper, 'getDayViewHeight').returns(1000);
sinon.stub(calendarHelper, 'getWeekView').returns({events: [{title: 'event1'}, {title: 'oneDayEvent'}]});
sinon.stub(calendarHelper, 'getWeekViewWithTimes').returns({events: [{title: 'oneDayEvent'}]});
sinon.stub(calendarHelper, 'getWeekView').returns({event: 'event1'});
sinon.stub(calendarHelper, 'getWeekViewWithTimes').returns({event: 'event2'});
scope.$broadcast('calendar.refreshView');
expect(calendarHelper.getDayViewHeight).to.have.been.calledWith('06:00', '22:00', 30);
expect(MwlCalendarCtrl.dayViewHeight).to.equal(1000);
expect(calendarHelper.getWeekView).to.have.been.calledWith(scope.events, scope.currentDay, false);
expect(MwlCalendarCtrl.view).to.eql({events: [{title: 'event1'}, {title: 'oneDayEvent'}]});
expect(calendarHelper.getWeekView).to.have.been.calledWith(scope.events, scope.currentDay);
expect(MwlCalendarCtrl.view).to.eql({event: 'event1'});

MwlCalendarCtrl.showTimes = true;
scope.$broadcast('calendar.refreshView');
expect(calendarHelper.getWeekView).to.have.been.calledWith(scope.events, scope.currentDay, true);
expect(calendarHelper.getWeekViewWithTimes).to.have.been.calledWith(scope.events, scope.currentDay, '06:00', '22:00', 30);
expect(MwlCalendarCtrl.viewWithTimes).to.eql({events: [{title: 'oneDayEvent'}]});
expect(MwlCalendarCtrl.view).to.eql({event: 'event2'});
});

it('should call the callback function when you finish dragging and event', function() {
Oops, something went wrong.

0 comments on commit 2d36a54

Please sign in to comment.
You can’t perform that action at this time.