Просмотр исходного кода

have View control minTime/maxTime

Adam Shaw 9 лет назад
Родитель
Сommit
70b0d4a1e1
3 измененных файлов с 55 добавлено и 13 удалено
  1. 3 0
      src/agenda/AgendaView.js
  2. 6 11
      src/common/TimeGrid.js
  3. 46 2
      src/common/View.date-range.js

+ 3 - 0
src/agenda/AgendaView.js

@@ -22,6 +22,9 @@ var AgendaView = FC.AgendaView = View.extend({
 	// when the time-grid isn't tall enough to occupy the given height, we render an <hr> underneath
 	bottomRuleEl: null,
 
+	// indicates that minTime/maxTime affects rendering
+	usesMinMaxTime: true,
+
 
 	initialize: function() {
 		this.timeGrid = this.instantiateTimeGrid();

+ 6 - 11
src/common/TimeGrid.js

@@ -8,8 +8,6 @@ var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 	slotDuration: null, // duration of a "slot", a distinct time segment on given day, visualized by lines
 	snapDuration: null, // granularity of time for dragging and selecting
 	snapsPerSlot: null,
-	minTime: null, // Duration object that denotes the first visible time of any given day
-	maxTime: null, // Duration object that denotes the exclusive visible end time of any given day
 	labelFormat: null, // formatting string for times running along vertical axis
 	labelInterval: null, // duration of how often a label should be displayed for a slot
 
@@ -71,13 +69,13 @@ var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 		var view = this.view;
 		var isRTL = this.isRTL;
 		var html = '';
-		var slotTime = moment.duration(+this.minTime); // wish there was .clone() for durations
+		var slotTime = moment.duration(+this.view.minTime); // wish there was .clone() for durations
 		var slotDate; // will be on the view's first day, but we only care about its time
 		var isLabeled;
 		var axisHtml;
 
 		// Calculate the time for each slot
-		while (slotTime < this.maxTime) {
+		while (slotTime < this.view.maxTime) {
 			slotDate = this.start.clone().time(slotTime);
 			isLabeled = isInt(divideDurationByDuration(slotTime, this.labelInterval));
 
@@ -127,9 +125,6 @@ var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 
 		this.minResizeDuration = snapDuration; // hack
 
-		this.minTime = moment.duration(view.opt('minTime'));
-		this.maxTime = moment.duration(view.opt('maxTime'));
-
 		// might be an array value (for TimelineView).
 		// if so, getting the most granular entry (the last one probably).
 		input = view.opt('slotLabelFormat');
@@ -255,7 +250,7 @@ var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 
 	// Given a row number of the grid, representing a "snap", returns a time (Duration) from its start-of-day
 	computeSnapTime: function(snapIndex) {
-		return moment.duration(this.minTime + this.snapDuration * snapIndex);
+		return moment.duration(this.view.minTime + this.snapDuration * snapIndex);
 	},
 
 
@@ -287,8 +282,8 @@ var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 		for (dayIndex = 0; dayIndex < this.daysPerRow; dayIndex++) {
 			dayDate = this.dayDates[dayIndex].clone(); // TODO: better API for this?
 			dayRange = {
-				start: dayDate.clone().time(this.minTime),
-				end: dayDate.clone().time(this.maxTime)
+				start: dayDate.clone().time(this.view.minTime),
+				end: dayDate.clone().time(this.view.maxTime)
 			};
 			seg = intersectRanges(range, dayRange); // both will be ambig timezone
 			if (seg) {
@@ -335,7 +330,7 @@ var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 	// Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
 	computeTimeTop: function(time) {
 		var len = this.slatEls.length;
-		var slatCoverage = (time - this.minTime) / this.slotDuration; // floating-point value of # of slots covered
+		var slatCoverage = (time - this.view.minTime) / this.slotDuration; // floating-point value of # of slots covered
 		var slatIndex;
 		var slatRemainder;
 

+ 46 - 2
src/common/View.date-range.js

@@ -24,6 +24,10 @@ View.mixin({
 	// TODO: entirely Calendar's responsibility
 	currentDate: null,
 
+	minTime: null, // Duration object that denotes the first visible time of any given day
+	maxTime: null, // Duration object that denotes the exclusive visible end time of any given day
+	usesMinMaxTime: false, // whether minTime/maxTime will affect the activeRange. Views must opt-in.
+
 	// DEPRECATED
 	start: null, // use activeRange.start
 	end: null, // use activeRange.end
@@ -51,6 +55,8 @@ View.mixin({
 			this.validRange = rangeInfo.validRange;
 			this.dateIncrement = rangeInfo.dateIncrement;
 			this.currentDate = rangeInfo.date;
+			this.minTime = rangeInfo.minTime;
+			this.maxTime = rangeInfo.maxTime;
 
 			// DEPRECATED, but we need to keep it updated
 			this.start = rangeInfo.activeRange.start;
@@ -90,6 +96,8 @@ View.mixin({
 	buildRangeInfo: function(givenDate, direction) {
 		var validRange = this.buildValidRange();
 		var constrainedDate = constrainDate(givenDate, validRange);
+		var minTime = null;
+		var maxTime = null;
 		var currentInfo;
 		var renderRange;
 		var activeRange;
@@ -103,6 +111,10 @@ View.mixin({
 			activeRange = constrainRange(activeRange, currentInfo.range);
 		}
 
+		minTime = moment.duration(this.opt('minTime'));
+		maxTime = moment.duration(this.opt('maxTime'));
+		this.adjustActiveRange(activeRange, minTime, maxTime);
+
 		activeRange = constrainRange(activeRange, validRange);
 		constrainedDate = constrainDate(constrainedDate, activeRange);
 
@@ -117,6 +129,8 @@ View.mixin({
 			currentRangeUnit: currentInfo.unit,
 			activeRange: activeRange,
 			renderRange: renderRange,
+			minTime: minTime,
+			maxTime: maxTime,
 			isValid: isValid,
 			date: constrainedDate,
 			dateIncrement: this.buildDateIncrement(currentInfo.duration)
@@ -160,7 +174,7 @@ View.mixin({
 			range = this.buildRangeFromDuration(date, direction, duration, unit);
 		}
 
-		this.normalizeRange(range, unit); // modifies in-place
+		this.normalizeCurrentRange(range, unit); // modifies in-place
 
 		return { duration: duration, unit: unit, range: range };
 	},
@@ -172,7 +186,7 @@ View.mixin({
 
 
 	// If the range has day units or larger, remove times. Otherwise, ensure times.
-	normalizeRange: function(range, unit) {
+	normalizeCurrentRange: function(range, unit) {
 
 		if (/^(year|month|week|day)$/.test(unit)) { // whole-days?
 			range.start.stripTime();
@@ -189,6 +203,36 @@ View.mixin({
 	},
 
 
+	// Mutates the given activeRange to have time values (un-ambiguate)
+	// if the minTime or maxTime causes the range to expand.
+	// TODO: eventually activeRange should *always* have times.
+	adjustActiveRange: function(range, minTime, maxTime) {
+		var hasSpecialTimes = false;
+
+		if (this.usesMinMaxTime) {
+
+			if (minTime < 0) {
+				range.start.time(0).subtract(minTime);
+				hasSpecialTimes = true;
+			}
+
+			if (maxTime > 24 * 60 * 60 * 1000) { // beyond 24 hours?
+				range.end.time(maxTime - (24 * 60 * 60 * 1000));
+				hasSpecialTimes = true;
+			}
+
+			if (hasSpecialTimes) {
+				if (!range.start.hasTime()) {
+					range.start.time(0);
+				}
+				if (!range.end.hasTime()) {
+					range.end.time(0);
+				}
+			}
+		}
+	},
+
+
 	// Builds the "current" range when it is specified as an explicit duration.
 	// `unit` is the already-computed computeGreatestUnit value of duration.
 	buildRangeFromDuration: function(date, direction, duration, unit) {