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

Commit

Permalink
fix(weekViewWithTimes): ensure on-timespan-click is called with the…
Browse files Browse the repository at this point in the history
… correct date

Closes #291
  • Loading branch information
Matt Lewis committed Feb 27, 2016
1 parent c8753d0 commit 66277a1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/directives/mwlCalendarHourList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var angular = require('angular');

angular
.module('mwl.calendar')
.controller('MwlCalendarHourListCtrl', function($scope, moment, calendarConfig, calendarHelper) {
.controller('MwlCalendarHourListCtrl', function($scope, $attrs, moment, calendarConfig, calendarHelper) {
var vm = this;
var dayViewStart, dayViewEnd;

Expand All @@ -14,10 +14,17 @@ angular
vm.dayViewSplit = parseInt(vm.dayViewSplit);
vm.hours = [];
var dayCounter = moment(vm.viewDate)
.clone()
.clone();

if ($attrs.dayWidth) {
dayCounter = dayCounter.startOf('week');
}

dayCounter
.hours(dayViewStart.hours())
.minutes(dayViewStart.minutes())
.seconds(dayViewStart.seconds());

for (var i = 0; i <= dayViewEnd.diff(dayViewStart, 'hours'); i++) {
vm.hours.push({
label: calendarHelper.formatDate(dayCounter, calendarConfig.dateFormats.hour),
Expand Down Expand Up @@ -63,6 +70,10 @@ angular
});
};

vm.getClickedDate = function(baseDate, minutes, days) {
return moment(baseDate).clone().add(minutes, 'minutes').add(days || 0, 'days').toDate();
};

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

Expand All @@ -75,6 +86,7 @@ angular
dayViewStart: '=',
dayViewEnd: '=',
dayViewSplit: '=',
dayWidth: '=?',
onTimespanClick: '=',
onEventTimesChanged: '='
},
Expand Down
12 changes: 12 additions & 0 deletions src/less/day.less
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
border-bottom: thin dashed @borderColor;

.cal-day-hour-part-time {
width: 60px;
text-align: center;
float: left;
}

.cal-day-hour-part-spacer {
height: 30px;
display: inline-block;
}

}
.cal-day-hour {
.day-highlight {
Expand Down
29 changes: 24 additions & 5 deletions src/templates/calendarHourList.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@
<div class="cal-day-hour" ng-repeat="hour in vm.hours track by $index">

<div
class="row-fluid cal-day-hour-part"
class="cal-day-hour-part"
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: vm.getClickedDate(hour.date, vm.dayViewSplit * $index)})"
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="span11 col-xs-11"></div>
on-drop="vm.eventDropped(dropData.event, vm.getClickedDate(hour.date, vm.dayViewSplit * $index))"
ng-if="!vm.dayWidth">
<div class="cal-day-hour-part-time">
<strong ng-bind="hour.label" ng-show="$first"></strong>
</div>
</div>

<div
class="cal-day-hour-part"
ng-repeat="chunk in vm.hourChunks track by chunk"
ng-if="vm.dayWidth">
<div class="cal-day-hour-part-time">
<strong ng-bind="hour.label" ng-show="$first"></strong>
</div>
<div
class="cal-day-hour-part-spacer"
ng-repeat="dayIndex in [0, 1, 2, 3, 4, 5, 6]"
ng-style="{width: vm.dayWidth + 'px'}"
ng-click="vm.onTimespanClick({calendarDate: vm.getClickedDate(hour.date, vm.dayViewSplit * $parent.$index, dayIndex)})"
mwl-droppable
on-drop="vm.eventDropped(dropData.event, vm.getClickedDate(hour.date, vm.dayViewSplit * $parent.$index, dayIndex))">
</div>
</div>

</div>
Expand Down
3 changes: 2 additions & 1 deletion src/templates/calendarWeekView.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
day-view-start="vm.dayViewStart"
day-view-end="vm.dayViewEnd"
day-view-split="vm.dayViewSplit"
day-width="vm.dayColumnDimensions.width"
view-date="vm.viewDate"
on-timespan-click="vm.onTimespanClick"
ng-if="vm.showTimes">
Expand All @@ -42,7 +43,7 @@
<div class="row">
<div class="col-xs-12">
<div
class="cal-row-fluid "
class="cal-row-fluid"
ng-repeat="event in vm.view.events track by event.$id">
<div
ng-class="'cal-cell' + (vm.showTimes ? 1 : event.daySpan) + (vm.showTimes ? '' : ' cal-offset' + event.dayOffset) + ' day-highlight dh-event-' + event.type + ' ' + event.cssClass"
Expand Down

0 comments on commit 66277a1

Please sign in to comment.