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

fix(week-view): show recurring events in the weekview. Closes #252

  • Loading branch information...
Matt Lewis
Matt Lewis committed Jan 9, 2016
1 parent c594f39 commit 4615973a0bfff8e5a332799741bc111436c2e1d1
@@ -8,13 +8,13 @@ angular
{
title: 'Recurs monthly',
type: 'warning',
startsAt: moment().startOf('month').toDate(),
startsAt: moment().toDate(),
recursOn: 'month'
},
{
title: 'Recurs yearly',
type: 'info',
startsAt: moment().startOf('month').toDate(),
startsAt: moment().toDate(),
recursOn: 'year'
}
];
@@ -23,7 +23,7 @@ angular
// See here: https://github.com/mattlewis92/angular-bootstrap-calendar/issues/127#issuecomment-136022090

vm.calendarView = 'month';
vm.viewDate = moment().startOf('month').toDate();
vm.viewDate = moment().toDate();
vm.isCellOpen = true;

});
@@ -22,16 +22,15 @@ angular
return moment(oldEnd).add(diffInSeconds);
}

function eventIsInPeriod(event, periodStart, periodEnd) {
function getRecurringEventPeriod(eventPeriod, recursOn, containerPeriodStart) {

var eventStart = moment(event.startsAt);
var eventEnd = moment(event.endsAt || event.startsAt);
periodStart = moment(periodStart);
periodEnd = moment(periodEnd);
var eventStart = moment(eventPeriod.start);
var eventEnd = moment(eventPeriod.end);
var periodStart = moment(containerPeriodStart);

if (angular.isDefined(event.recursOn)) {
if (angular.isDefined(recursOn)) {

switch (event.recursOn) {
switch (recursOn) {
case 'year':
eventStart.set({
year: periodStart.year()
@@ -46,13 +45,26 @@ angular
break;

default:
throw new Error('Invalid value (' + event.recursOn + ') given for recurs on. Can only be year or month.');
throw new Error('Invalid value (' + recursOn + ') given for recurs on. Can only be year or month.');
}

eventEnd = adjustEndDateFromStartDiff(event.startsAt, eventStart, eventEnd);
eventEnd = adjustEndDateFromStartDiff(eventPeriod.start, eventStart, eventEnd);

}

return {start: eventStart, end: eventEnd};

}

function eventIsInPeriod(event, periodStart, periodEnd) {

periodStart = moment(periodStart);
periodEnd = moment(periodEnd);

var eventPeriod = getRecurringEventPeriod({start: event.startsAt, end: event.endsAt || event.startsAt}, event.recursOn, periodStart);
var eventStart = eventPeriod.start;
var eventEnd = eventPeriod.end;

return (eventStart.isAfter(periodStart) && eventStart.isBefore(periodEnd)) ||
(eventEnd.isAfter(periodStart) && eventEnd.isBefore(periodEnd)) ||
(eventStart.isBefore(periodStart) && eventEnd.isAfter(periodEnd)) ||
@@ -183,12 +195,18 @@ angular

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

var eventStart = moment(event.startsAt).startOf('day');
var eventEnd = moment(event.endsAt || event.startsAt).startOf('day');
var weekViewStart = moment(startOfWeek).startOf('day');
var weekViewEnd = moment(endOfWeek).startOf('day');
var offset, span;

var eventPeriod = getRecurringEventPeriod({
start: moment(event.startsAt).startOf('day'),
end: moment(event.endsAt || event.startsAt).startOf('day')
}, event.recursOn, weekViewStart);

var eventStart = eventPeriod.start;
var eventEnd = eventPeriod.end;

var offset, span;
if (eventStart.isBefore(weekViewStart) || eventStart.isSame(weekViewStart)) {
offset = 0;
} else {
@@ -478,6 +478,19 @@ describe('calendarHelper', function() {

});

describe('recurring events', function() {

it('should display recuring events', function() {
weekView = calendarHelper.getWeekView([{
startsAt: new Date(2016, 0, 9, 1),
recursOn: 'month'
}], new Date(2016, 1, 9, 1));
expect(weekView.events[0].daySpan).to.equal(1);
expect(weekView.events[0].dayOffset).to.equal(2);
});

});

});

describe('getDayView', function() {

0 comments on commit 4615973

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