Procházet zdrojové kódy

fix bug with hiddenDays and validRange, fixes #3846

Adam Shaw před 8 roky
rodič
revize
509134f4ce
3 změnil soubory, kde provedl 43 přidání a 9 odebrání
  1. 22 8
      src/View.date-range.js
  2. 1 1
      src/basic/BasicView.js
  3. 20 0
      tests/view-dates/validRange.js

+ 22 - 8
src/View.date-range.js

@@ -39,7 +39,7 @@ View.mixin({
 	// from its previous value. decremented = -1, incremented = 1 (default).
 	// from its previous value. decremented = -1, incremented = 1 (default).
 	buildDateProfile: function(date, direction, forceToValid) {
 	buildDateProfile: function(date, direction, forceToValid) {
 		var isDateAllDay = !date.hasTime();
 		var isDateAllDay = !date.hasTime();
-		var validUnzonedRange = this.buildValidRange();
+		var validUnzonedRange;
 		var minTime = null;
 		var minTime = null;
 		var maxTime = null;
 		var maxTime = null;
 		var currentInfo;
 		var currentInfo;
@@ -48,6 +48,9 @@ View.mixin({
 		var activeUnzonedRange;
 		var activeUnzonedRange;
 		var isValid;
 		var isValid;
 
 
+		validUnzonedRange = this.buildValidRange();
+		validUnzonedRange = this.trimHiddenDays(validUnzonedRange);
+
 		if (forceToValid) {
 		if (forceToValid) {
 			date = this.calendar.msToUtcMoment(
 			date = this.calendar.msToUtcMoment(
 				validUnzonedRange.constrainDate(date), // returns MS
 				validUnzonedRange.constrainDate(date), // returns MS
@@ -57,7 +60,12 @@ View.mixin({
 
 
 		currentInfo = this.buildCurrentRangeInfo(date, direction);
 		currentInfo = this.buildCurrentRangeInfo(date, direction);
 		isRangeAllDay = /^(year|month|week|day)$/.test(currentInfo.unit);
 		isRangeAllDay = /^(year|month|week|day)$/.test(currentInfo.unit);
-		renderUnzonedRange = this.buildRenderRange(currentInfo.unzonedRange, currentInfo.unit, isRangeAllDay);
+		renderUnzonedRange = this.buildRenderRange(
+			this.trimHiddenDays(currentInfo.unzonedRange),
+			currentInfo.unit,
+			isRangeAllDay
+		);
+		renderUnzonedRange = this.trimHiddenDays(renderUnzonedRange);
 		activeUnzonedRange = renderUnzonedRange.clone();
 		activeUnzonedRange = renderUnzonedRange.clone();
 
 
 		if (!this.opt('showNonCurrentDates')) {
 		if (!this.opt('showNonCurrentDates')) {
@@ -67,8 +75,7 @@ View.mixin({
 		minTime = moment.duration(this.opt('minTime'));
 		minTime = moment.duration(this.opt('minTime'));
 		maxTime = moment.duration(this.opt('maxTime'));
 		maxTime = moment.duration(this.opt('maxTime'));
 		activeUnzonedRange = this.adjustActiveRange(activeUnzonedRange, minTime, maxTime);
 		activeUnzonedRange = this.adjustActiveRange(activeUnzonedRange, minTime, maxTime);
-
-		activeUnzonedRange = activeUnzonedRange.intersect(validUnzonedRange);
+		activeUnzonedRange = activeUnzonedRange.intersect(validUnzonedRange); // might return null
 
 
 		if (activeUnzonedRange) {
 		if (activeUnzonedRange) {
 			date = this.calendar.msToUtcMoment(
 			date = this.calendar.msToUtcMoment(
@@ -96,6 +103,7 @@ View.mixin({
 			isRangeAllDay: isRangeAllDay,
 			isRangeAllDay: isRangeAllDay,
 
 
 			// dates that display events and accept drag-n-drop
 			// dates that display events and accept drag-n-drop
+			// will be `null` if no dates accept events
 			activeUnzonedRange: activeUnzonedRange,
 			activeUnzonedRange: activeUnzonedRange,
 
 
 			// date range with a rendered skeleton
 			// date range with a rendered skeleton
@@ -121,6 +129,7 @@ View.mixin({
 
 
 	// Builds an object with optional start/end properties.
 	// Builds an object with optional start/end properties.
 	// Indicates the minimum/maximum dates to display.
 	// Indicates the minimum/maximum dates to display.
+	// not responsible for trimming hidden days.
 	buildValidRange: function() {
 	buildValidRange: function() {
 		return this.getUnzonedRangeOption('validRange', this.calendar.getNow()) ||
 		return this.getUnzonedRangeOption('validRange', this.calendar.getNow()) ||
 			new UnzonedRange(); // completely open-ended
 			new UnzonedRange(); // completely open-ended
@@ -277,9 +286,9 @@ View.mixin({
 
 
 	// Computes the range that will represent the element/cells for *rendering*,
 	// Computes the range that will represent the element/cells for *rendering*,
 	// but which may have voided days/times.
 	// but which may have voided days/times.
+	// not responsible for trimming hidden days.
 	buildRenderRange: function(currentUnzonedRange, currentRangeUnit, isRangeAllDay) {
 	buildRenderRange: function(currentUnzonedRange, currentRangeUnit, isRangeAllDay) {
-		// cut off days in the currentUnzonedRange that are hidden
-		return this.trimHiddenDays(currentUnzonedRange);
+		return currentUnzonedRange.clone();
 	},
 	},
 
 
 
 
@@ -309,8 +318,13 @@ View.mixin({
 		var start = inputUnzonedRange.getStart();
 		var start = inputUnzonedRange.getStart();
 		var end = inputUnzonedRange.getEnd();
 		var end = inputUnzonedRange.getEnd();
 
 
-		start = this.skipHiddenDays(start);
-		end = this.skipHiddenDays(end, -1, true);
+		if (start) {
+			start = this.skipHiddenDays(start);
+		}
+
+		if (end) {
+			end = this.skipHiddenDays(end, -1, true);
+		}
 
 
 		return new UnzonedRange(start, end);
 		return new UnzonedRange(start, end);
 	},
 	},

+ 1 - 1
src/basic/BasicView.js

@@ -66,7 +66,7 @@ var BasicView = FC.BasicView = View.extend({
 			}
 			}
 		}
 		}
 
 
-		return this.trimHiddenDays(new UnzonedRange(start, end));
+		return new UnzonedRange(start, end);
 	},
 	},
 
 
 
 

+ 20 - 0
tests/view-dates/validRange.js

@@ -151,4 +151,24 @@ describe('validRange', function() {
 			});
 			});
 		});
 		});
 	});
 	});
+
+	describe('when hiddenDays causes no days to be active', function() {
+		pushOptions({
+			defaultView: 'agendaWeek',
+			defaultDate: '2017-10-04',
+			hiddenDays: [ 6 ], // Sunday, last day within natural week range
+			validRange: {
+				start: '2036-05-03',
+				end: '2036-06-01'
+			}
+		});
+
+		it('pushes view to nearest valid range', function() {
+			initCalendar();
+			ViewDateUtils.expectRenderRange('2036-05-04', '2036-05-10');
+			ViewDateUtils.expectActiveRange('2036-05-04', '2036-05-10');
+		});
+
+	});
+
 });
 });