Skip to content

Commit

Permalink
Include attributes with day events
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Reyes committed Dec 11, 2017
1 parent 6ea538e commit ca5e896
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/components/CalendarDay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

<script>
import defaults from '../utils/defaults';
import { arrayHasItems } from '../utils/helpers';
export default {
props: {
Expand Down Expand Up @@ -107,16 +108,16 @@ export default {
return this.attributes.find(this.dayInfo);
},
hasBackgrounds() {
return this.backgrounds && this.backgrounds.length;
return arrayHasItems(this.backgrounds);
},
hasDots() {
return this.dots && this.dots.length;
return arrayHasItems(this.dots);
},
dotsStyle_() {
return this.styles.dots;
},
hasBars() {
return this.bars && this.bars.length;
return arrayHasItems(this.bars);
},
barsStyle_() {
return this.styles.bars;
Expand All @@ -126,6 +127,15 @@ export default {
this.backgrounds.map(b => b.highlight) :
[];
},
attributesMap() {
return this.attributeDates.reduce((map, ad) => {
map[ad.attribute.key] = {
...ad.attribute,
targetDate: ad.dateInfo,
};
return map;
}, {});
},
},
watch: {
attributes() {
Expand Down Expand Up @@ -160,21 +170,21 @@ export default {
Math.abs(state.x - state.startX) <= defaults.maxTapTolerance &&
Math.abs(state.y - state.startY) <= defaults.maxTapTolerance;
if (state.tapDetected) {
this.$emit('daySelect', this.dayInfo);
this.$emit('daySelect', this.dayInfo, this.attributesMap);
}
state.started = false;
},
click() {
if (this.touchState && this.touchState.tapDetected) return;
this.$emit('daySelect', this.dayInfo);
this.$emit('daySelect', this.dayInfo, this.attributesMap);
},
mouseenter() {
this.isHovered = true;
this.$emit('dayMouseEnter', this.dayInfo);
this.$emit('dayMouseEnter', this.dayInfo, this.attributesMap);
},
mouseleave() {
this.isHovered = false;
this.$emit('dayMouseLeave', this.dayInfo);
this.$emit('dayMouseLeave', this.dayInfo, this.attributesMap);
},
processAttributes() {
const backgrounds = [];
Expand Down
1 change: 0 additions & 1 deletion src/utils/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const Attribute = (config) => {
},
// Accepts: DayInfo object
// Returns: First attribute date or date range that occurs on given day.
// includesDay: dayInfo => dates.map(d => d.includesDay(dayInfo)).find(d => d),
includesDay: (dayInfo) => {
const matchDate = dates
.map(d => d.includesDay(dayInfo))
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dateInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const DateInfo = (config, order) => {
}
}
// Assign flag if date info is complex
info.isComplex = info.on;
info.isComplex = !!info.on;
}
// Determines if any part of this date intersects any part of the other date
info.intersectsDate = (other) => {
Expand Down

0 comments on commit ca5e896

Please sign in to comment.