From c44a50e3cd599d03d3b17ebda580c2be7bc5bee5 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Wed, 30 Dec 2015 18:45:53 +0000 Subject: [PATCH] feat(current-day): rename current-day to view-date. Closes #244 BREAKING CHANGE: the `current-day` attribute has been renamed to `view-date` --- README.md | 8 ++--- index.html | 2 +- src/directives/mwlCalendar.js | 12 +++---- src/directives/mwlCalendarDay.js | 4 +-- src/directives/mwlCalendarHourList.js | 6 ++-- src/directives/mwlCalendarMonth.js | 6 ++-- src/directives/mwlCalendarWeek.js | 6 ++-- src/directives/mwlCalendarYear.js | 6 ++-- src/services/calendarHelper.js | 34 +++++++++---------- src/services/calendarTitle.js | 16 ++++----- src/templates/calendar.html | 10 +++--- src/templates/calendarDayView.html | 2 +- src/templates/calendarWeekView.html | 2 +- test/unit/directives/mwlCalendar.spec.js | 6 ++-- test/unit/directives/mwlCalendarDay.spec.js | 6 ++-- test/unit/directives/mwlCalendarMonth.spec.js | 6 ++-- test/unit/directives/mwlCalendarWeek.spec.js | 8 ++--- test/unit/directives/mwlCalendarYear.spec.js | 6 ++-- 18 files changed, 73 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 91246930..da8265e7 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ There is a single directive exposed to create the calendar, use it like so: ```javascript {{ vm.calendarTitle }} events="vm.events" view="vm.calendarView" view-title="vm.calendarTitle" - current-day="vm.calendarDay" + view-date="vm.calendarDay" on-event-click="vm.eventClicked(calendarEvent)" on-event-times-changed="vm.eventTimesChanged(calendarEvent); calendarEvent.startsAt = calendarNewEventStart; calendarEvent.endsAt = calendarNewEventEnd" edit-event-html="''" diff --git a/src/directives/mwlCalendar.js b/src/directives/mwlCalendar.js index a2083c16..9ab4cd68 100644 --- a/src/directives/mwlCalendar.js +++ b/src/directives/mwlCalendar.js @@ -12,7 +12,7 @@ angular vm.changeView = function(view, newDay) { vm.view = view; - vm.currentDay = newDay; + vm.viewDate = newDay; }; vm.dateClicked = function(date) { @@ -31,7 +31,7 @@ angular }; - var previousDate = moment(vm.currentDay); + var previousDate = moment(vm.viewDate); var previousView = vm.view; function eventIsValid(event) { @@ -58,7 +58,7 @@ angular function refreshCalendar() { if (calendarTitle[vm.view] && angular.isDefined($attrs.viewTitle)) { - vm.viewTitle = calendarTitle[vm.view](vm.currentDay); + vm.viewTitle = calendarTitle[vm.view](vm.viewDate); } vm.events = vm.events.filter(eventIsValid).map(function(event, index) { @@ -67,7 +67,7 @@ angular }); //if on-timespan-click="calendarDay = calendarDate" is set then don't update the view as nothing needs to change - var currentDate = moment(vm.currentDay); + var currentDate = moment(vm.viewDate); var shouldUpdate = true; if ( previousDate.clone().startOf(vm.view).isSame(currentDate.clone().startOf(vm.view)) && @@ -91,7 +91,7 @@ angular //Refresh the calendar when any of these variables change. $scope.$watchGroup([ - 'vm.currentDay', + 'vm.viewDate', 'vm.view', 'vm.cellIsOpen', function() { @@ -117,7 +117,7 @@ angular events: '=', view: '=', viewTitle: '=?', - currentDay: '=', + viewDate: '=', editEventHtml: '=', deleteEventHtml: '=', cellIsOpen: '=', diff --git a/src/directives/mwlCalendarDay.js b/src/directives/mwlCalendarDay.js index 53dfb3ee..e0b34094 100644 --- a/src/directives/mwlCalendarDay.js +++ b/src/directives/mwlCalendarDay.js @@ -21,7 +21,7 @@ angular vm.view = calendarHelper.getDayView( vm.events, - vm.currentDay, + vm.viewDate, vm.dayViewStart, vm.dayViewEnd, vm.dayViewSplit @@ -81,7 +81,7 @@ angular require: '^mwlCalendar', scope: { events: '=', - currentDay: '=', + viewDate: '=', onEventClick: '=', onEventTimesChanged: '=', onTimespanClick: '=', diff --git a/src/directives/mwlCalendarHourList.js b/src/directives/mwlCalendarHourList.js index 27585cc0..d20bb702 100644 --- a/src/directives/mwlCalendarHourList.js +++ b/src/directives/mwlCalendarHourList.js @@ -13,7 +13,7 @@ angular dayViewEnd = moment(vm.dayViewEnd || '23:00', 'HH:mm'); vm.dayViewSplit = parseInt(vm.dayViewSplit); vm.hours = []; - var dayCounter = moment(vm.currentDay) + var dayCounter = moment(vm.viewDate) .clone() .hours(dayViewStart.hours()) .minutes(dayViewStart.minutes()) @@ -42,7 +42,7 @@ angular 'vm.dayViewStart', 'vm.dayViewEnd', 'vm.dayViewSplit', - 'vm.currentDay' + 'vm.viewDate' ], function() { updateDays(); }); @@ -55,7 +55,7 @@ angular template: calendarUseTemplates ? require('./../templates/calendarHourList.html') : '', controller: 'MwlCalendarHourListCtrl as vm', scope: { - currentDay: '=', + viewDate: '=', dayViewStart: '=', dayViewEnd: '=', dayViewSplit: '=', diff --git a/src/directives/mwlCalendarMonth.js b/src/directives/mwlCalendarMonth.js index 59f15f1a..3cc85fff 100644 --- a/src/directives/mwlCalendarMonth.js +++ b/src/directives/mwlCalendarMonth.js @@ -14,7 +14,7 @@ angular vm.weekDays = calendarHelper.getWeekDayNames(); - vm.view = calendarHelper.getMonthView(vm.events, vm.currentDay, vm.cellModifier); + vm.view = calendarHelper.getMonthView(vm.events, vm.viewDate, vm.cellModifier); var rows = Math.floor(vm.view.length / 7); vm.monthOffsets = []; for (var i = 0; i < rows; i++) { @@ -25,7 +25,7 @@ angular if (vm.cellIsOpen && vm.openRowIndex === null) { vm.openDayIndex = null; vm.view.forEach(function(day) { - if (day.inMonth && moment(vm.currentDay).startOf('day').isSame(day.date)) { + if (day.inMonth && moment(vm.viewDate).startOf('day').isSame(day.date)) { vm.dayClicked(day, true); } }); @@ -97,7 +97,7 @@ angular require: '^mwlCalendar', scope: { events: '=', - currentDay: '=', + viewDate: '=', onEventClick: '=', onEditEventClick: '=', onDeleteEventClick: '=', diff --git a/src/directives/mwlCalendarWeek.js b/src/directives/mwlCalendarWeek.js index 818ce7a8..5295edca 100644 --- a/src/directives/mwlCalendarWeek.js +++ b/src/directives/mwlCalendarWeek.js @@ -21,13 +21,13 @@ angular if (vm.showTimes) { vm.view = calendarHelper.getWeekViewWithTimes( vm.events, - vm.currentDay, + vm.viewDate, vm.dayViewStart, vm.dayViewEnd, vm.dayViewSplit ); } else { - vm.view = calendarHelper.getWeekView(vm.events, vm.currentDay); + vm.view = calendarHelper.getWeekView(vm.events, vm.viewDate); } }); @@ -83,7 +83,7 @@ angular require: '^mwlCalendar', scope: { events: '=', - currentDay: '=', + viewDate: '=', onEventClick: '=', onEventTimesChanged: '=', dayViewStart: '=', diff --git a/src/directives/mwlCalendarYear.js b/src/directives/mwlCalendarYear.js index de6fdece..cbecaa58 100644 --- a/src/directives/mwlCalendarYear.js +++ b/src/directives/mwlCalendarYear.js @@ -10,13 +10,13 @@ angular vm.openMonthIndex = null; $scope.$on('calendar.refreshView', function() { - vm.view = calendarHelper.getYearView(vm.events, vm.currentDay, vm.cellModifier); + vm.view = calendarHelper.getYearView(vm.events, vm.viewDate, vm.cellModifier); //Auto open the calendar to the current day if set if (vm.cellIsOpen && vm.openMonthIndex === null) { vm.openMonthIndex = null; vm.view.forEach(function(month) { - if (moment(vm.currentDay).startOf('month').isSame(month.date)) { + if (moment(vm.viewDate).startOf('month').isSame(month.date)) { vm.monthClicked(month, true); } }); @@ -70,7 +70,7 @@ angular require: '^mwlCalendar', scope: { events: '=', - currentDay: '=', + viewDate: '=', onEventClick: '=', onEventTimesChanged: '=', onEditEventClick: '=', diff --git a/src/services/calendarHelper.js b/src/services/calendarHelper.js index 4526b261..8b8aca0b 100644 --- a/src/services/calendarHelper.js +++ b/src/services/calendarHelper.js @@ -88,11 +88,11 @@ angular return weekdays; } - function getYearView(events, currentDay, cellModifier) { + function getYearView(events, viewDate, cellModifier) { var view = []; - var eventsInPeriod = getEventsInPeriod(currentDay, 'year', events); - var month = moment(currentDay).startOf('year'); + var eventsInPeriod = getEventsInPeriod(viewDate, 'year', events); + var month = moment(viewDate).startOf('year'); var count = 0; while (count < 12) { var startPeriod = month.clone(); @@ -116,11 +116,11 @@ angular } - function getMonthView(events, currentDay, cellModifier) { + function getMonthView(events, viewDate, cellModifier) { - var startOfMonth = moment(currentDay).startOf('month'); + var startOfMonth = moment(viewDate).startOf('month'); var day = startOfMonth.clone().startOf('week'); - var endOfMonthView = moment(currentDay).endOf('month').endOf('week'); + var endOfMonthView = moment(viewDate).endOf('month').endOf('week'); var eventsInPeriod; if (calendarConfig.displayAllMonthEvents) { eventsInPeriod = filterEventsInPeriod(events, day, endOfMonthView); @@ -132,7 +132,7 @@ angular while (day.isBefore(endOfMonthView)) { - var inMonth = day.month() === moment(currentDay).month(); + var inMonth = day.month() === moment(viewDate).month(); var monthEvents = []; if (inMonth || calendarConfig.displayAllMonthEvents) { monthEvents = filterEventsInPeriod(eventsInPeriod, day, day.clone().endOf('day')); @@ -161,10 +161,10 @@ angular } - function getWeekView(events, currentDay) { + function getWeekView(events, viewDate) { - var startOfWeek = moment(currentDay).startOf('week'); - var endOfWeek = moment(currentDay).endOf('week'); + var startOfWeek = moment(viewDate).startOf('week'); + var endOfWeek = moment(viewDate).endOf('week'); var dayCounter = startOfWeek.clone(); var days = []; var today = moment().startOf('day'); @@ -215,20 +215,20 @@ angular } - function getDayView(events, currentDay, dayViewStart, dayViewEnd, dayViewSplit) { + function getDayView(events, viewDate, dayViewStart, dayViewEnd, dayViewSplit) { var dayStartHour = moment(dayViewStart || '00:00', 'HH:mm').hours(); var dayEndHour = moment(dayViewEnd || '23:00', 'HH:mm').hours(); var hourHeight = (60 / dayViewSplit) * 30; - var calendarStart = moment(currentDay).startOf('day').add(dayStartHour, 'hours'); - var calendarEnd = moment(currentDay).startOf('day').add(dayEndHour, 'hours'); + var calendarStart = moment(viewDate).startOf('day').add(dayStartHour, 'hours'); + var calendarEnd = moment(viewDate).startOf('day').add(dayEndHour, 'hours'); var calendarHeight = (dayEndHour - dayStartHour + 1) * hourHeight; var hourHeightMultiplier = hourHeight / 60; var buckets = []; var eventsInPeriod = filterEventsInPeriod( events, - moment(currentDay).startOf('day').toDate(), - moment(currentDay).endOf('day').toDate() + moment(viewDate).startOf('day').toDate(), + moment(viewDate).endOf('day').toDate() ); return eventsInPeriod.map(function(event) { @@ -293,8 +293,8 @@ angular } - function getWeekViewWithTimes(events, currentDay, dayViewStart, dayViewEnd, dayViewSplit) { - var weekView = getWeekView(events, currentDay); + function getWeekViewWithTimes(events, viewDate, dayViewStart, dayViewEnd, dayViewSplit) { + var weekView = getWeekView(events, viewDate); var newEvents = []; weekView.days.forEach(function(day) { var dayEvents = weekView.events.filter(function(event) { diff --git a/src/services/calendarTitle.js b/src/services/calendarTitle.js index d9ba7f96..0f1bfdde 100644 --- a/src/services/calendarTitle.js +++ b/src/services/calendarTitle.js @@ -6,21 +6,21 @@ angular .module('mwl.calendar') .factory('calendarTitle', function(moment, calendarConfig, calendarHelper) { - function day(currentDay) { - return calendarHelper.formatDate(currentDay, calendarConfig.titleFormats.day); + function day(viewDate) { + return calendarHelper.formatDate(viewDate, calendarConfig.titleFormats.day); } - function week(currentDay) { + function week(viewDate) { var weekTitleLabel = calendarConfig.titleFormats.week; - return weekTitleLabel.replace('{week}', moment(currentDay).week()).replace('{year}', moment(currentDay).format('YYYY')); + return weekTitleLabel.replace('{week}', moment(viewDate).week()).replace('{year}', moment(viewDate).format('YYYY')); } - function month(currentDay) { - return calendarHelper.formatDate(currentDay, calendarConfig.titleFormats.month); + function month(viewDate) { + return calendarHelper.formatDate(viewDate, calendarConfig.titleFormats.month); } - function year(currentDay) { - return calendarHelper.formatDate(currentDay, calendarConfig.titleFormats.year); + function year(viewDate) { + return calendarHelper.formatDate(viewDate, calendarConfig.titleFormats.year); } return { diff --git a/src/templates/calendar.html b/src/templates/calendar.html index ff31b174..585e0fc5 100644 --- a/src/templates/calendar.html +++ b/src/templates/calendar.html @@ -2,11 +2,11 @@
The value passed to the view attribute of the calendar is not set
-
The value passed to current-day attribute of the calendar is not set
+
The value passed to view-date attribute of the calendar is not set
+ view-date="vm.viewDate">
diff --git a/test/unit/directives/mwlCalendar.spec.js b/test/unit/directives/mwlCalendar.spec.js index 40a40187..26bd92c9 100644 --- a/test/unit/directives/mwlCalendar.spec.js +++ b/test/unit/directives/mwlCalendar.spec.js @@ -17,7 +17,7 @@ describe('mwlCalendar directive', function() { 'events="vm.events" ' + 'view="vm.calendarView" ' + 'view-title="vm.calendarTitle" ' + - 'current-day="vm.calendarDay" ' + + 'view-date="vm.calendarDay" ' + 'on-event-click="vm.eventClicked(calendarEvent)" ' + 'on-event-times-changed="vm.eventTimesChanged(calendarEvent); ' + 'calendarEvent.startsAt = calendarNewEventStart; calendarEvent.endsAt = calendarNewEventEnd" ' + @@ -107,14 +107,14 @@ describe('mwlCalendar directive', function() { var myDate = new Date(); MwlCalendarCtrl.changeView('day', myDate); expect(MwlCalendarCtrl.view).to.equal('day'); - expect(MwlCalendarCtrl.currentDay).to.equal(myDate); + expect(MwlCalendarCtrl.viewDate).to.equal(myDate); }); it('should change the current view', function() { var myDate = new Date(); MwlCalendarCtrl.dateClicked(myDate); expect(MwlCalendarCtrl.view).to.equal('day'); - expect(MwlCalendarCtrl.currentDay).to.eql(myDate); + expect(MwlCalendarCtrl.viewDate).to.eql(myDate); }); it('should refresh the calendar when appropriate', function() { diff --git a/test/unit/directives/mwlCalendarDay.spec.js b/test/unit/directives/mwlCalendarDay.spec.js index bbe78997..59fd93bf 100644 --- a/test/unit/directives/mwlCalendarDay.spec.js +++ b/test/unit/directives/mwlCalendarDay.spec.js @@ -14,7 +14,7 @@ describe('mwlCalendarDay directive', function() { template = '