Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
feat(dayView): allow external events to be dropped on the day view
Browse files Browse the repository at this point in the history
Closes #284
  • Loading branch information
Matt Lewis committed Feb 13, 2016
1 parent ba9a34b commit 9b937b1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/directives/mwlCalendarHourList.js
Expand Up @@ -51,6 +51,18 @@ angular
updateDays(); updateDays();
}); });


vm.eventDropped = function(event, date) {
var newStart = moment(date);
var newEnd = calendarHelper.adjustEndDateFromStartDiff(event.startsAt, newStart, event.endsAt);

vm.onEventTimesChanged({
calendarEvent: event,
calendarDate: date,
calendarNewEventStart: newStart.toDate(),
calendarNewEventEnd: newEnd ? newEnd.toDate() : null
});
};

}) })
.directive('mwlCalendarHourList', function(calendarConfig) { .directive('mwlCalendarHourList', function(calendarConfig) {


Expand All @@ -63,7 +75,8 @@ angular
dayViewStart: '=', dayViewStart: '=',
dayViewEnd: '=', dayViewEnd: '=',
dayViewSplit: '=', dayViewSplit: '=',
onTimespanClick: '=' onTimespanClick: '=',
onEventTimesChanged: '='
}, },
bindToController: true bindToController: true
}; };
Expand Down
3 changes: 2 additions & 1 deletion src/less/theme.less
Expand Up @@ -19,7 +19,8 @@
.cell-focus, .cell-focus,
[class*="cal-cell"] .drop-active, [class*="cal-cell"] .drop-active,
.cal-cell.drop-active, .cal-cell.drop-active,
.cal-week-box .cal-cell1.drop-active { .cal-week-box .cal-cell1.drop-active,
.cal-day-hour-part.drop-active {
background-color: @dayHover; background-color: @dayHover;
} }
.cal-year-box [class*="span"], .cal-year-box [class*="span"],
Expand Down
1 change: 1 addition & 0 deletions src/templates/calendarDayView.html
Expand Up @@ -11,6 +11,7 @@
day-view-end="vm.dayViewEnd" day-view-end="vm.dayViewEnd"
day-view-split="vm.dayViewSplit" day-view-split="vm.dayViewSplit"
on-timespan-click="vm.onTimespanClick" on-timespan-click="vm.onTimespanClick"
on-event-times-changed="vm.onEventTimesChanged"
view-date="vm.viewDate"> view-date="vm.viewDate">
</mwl-calendar-hour-list> </mwl-calendar-hour-list>


Expand Down
4 changes: 3 additions & 1 deletion src/templates/calendarHourList.html
Expand Up @@ -5,7 +5,9 @@
<div <div
class="row-fluid cal-day-hour-part" class="row-fluid cal-day-hour-part"
ng-repeat="chunk in vm.hourChunks track by chunk" ng-repeat="chunk in vm.hourChunks track by chunk"
ng-click="vm.onTimespanClick({calendarDate: hour.date.clone().add(vm.dayViewSplit * $index, 'minutes').toDate()})"> ng-click="vm.onTimespanClick({calendarDate: hour.date.clone().add(vm.dayViewSplit * $index, 'minutes').toDate()})"
mwl-droppable
on-drop="vm.eventDropped(dropData.event, hour.date.clone().add(vm.dayViewSplit * $index, 'minutes').toDate())">
<div class="span1 col-xs-1"><strong ng-bind="hour.label" ng-show="$first"></strong></div> <div class="span1 col-xs-1"><strong ng-bind="hour.label" ng-show="$first"></strong></div>
<div class="span11 col-xs-11"></div> <div class="span11 col-xs-11"></div>
</div> </div>
Expand Down
17 changes: 17 additions & 0 deletions test/unit/directives/mwlCalendarHoursList.spec.js
Expand Up @@ -15,6 +15,7 @@ describe('mwlCalendarDay directive', function() {
'day-view-start="dayViewStart" ' + 'day-view-start="dayViewStart" ' +
'day-view-end="dayViewEnd" ' + 'day-view-end="dayViewEnd" ' +
'day-view-split="dayViewSplit || 30" ' + 'day-view-split="dayViewSplit || 30" ' +
'on-event-times-changed="eventDropped(calendarEvent, calendarDate, calendarNewEventStart, calendarNewEventEnd)" ' +
'></mwl-calendar-hour-list>'; '></mwl-calendar-hour-list>';


function prepareScope(vm) { function prepareScope(vm) {
Expand Down Expand Up @@ -60,4 +61,20 @@ describe('mwlCalendarDay directive', function() {
moment.locale.restore(); moment.locale.restore();
}); });


it('should call the event times changed callback when an event is dropped', function() {
var event = {
startsAt: moment().toDate(),
endsAt: moment().add(1, 'day').toDate()
};
var date = moment().add(2, 'days').toDate();
MwlCalendarCtrl.onEventTimesChanged = sinon.spy();
MwlCalendarCtrl.eventDropped(event, date);
expect(MwlCalendarCtrl.onEventTimesChanged).to.have.been.calledWith({
calendarEvent: event,
calendarDate: date,
calendarNewEventStart: date,
calendarNewEventEnd: moment().add(3, 'days').toDate()
});
});

}); });

0 comments on commit 9b937b1

Please sign in to comment.