2021-08-14 01:42:49 -07:00
|
|
|
<template>
|
|
|
|
<div class="calendar">
|
|
|
|
<div v-for="i in (startingDayOfWeek - 1)"></div>
|
|
|
|
<div v-for="d in iterateMonth(year, month)"
|
2021-08-18 09:51:11 -07:00
|
|
|
:class="['rounded-circle', getDayClass(d), markToday && d.equals(today) ? 'day-today' : '', d.equals(selectedDay) ? 'day-selected' : '']"
|
2021-08-14 01:42:49 -07:00
|
|
|
@click.stop="selectDay(d)"
|
|
|
|
:data-flag="getDayFlag(d)"
|
|
|
|
:style="getDayFlag(d) ? `background-image: url('${getDayFlag(d)}')` : ''"
|
|
|
|
>
|
|
|
|
<div class="day-number">{{ d.day }}</div>
|
|
|
|
<div v-if="currentYear.eventsByDate[d.toString()] !== undefined && d.equals(selectedDay)" class="day-tooltip card text-dark shadow">
|
2021-08-18 00:42:54 -07:00
|
|
|
<div class="card-header d-flex justify-content-between">
|
|
|
|
<p class="h5 mb-0"><strong><T :params="{day: d.day}">calendar.dates.{{d.month}}</T></strong></p>
|
|
|
|
<button class="btn btn-sm py-0" @clik="selectedDay = null"><Icon v="times"/></button>
|
2021-08-14 01:42:49 -07:00
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
<ul class="list-unstyled mb-0">
|
2021-08-19 08:33:48 -07:00
|
|
|
<CalendarEvent v-for="event in currentYear.eventsByDate[d.toString()]" :event="event" :key="event.name"/>
|
2021-08-14 01:42:49 -07:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-17 10:50:49 -07:00
|
|
|
import { Day, iterateMonth, EventLevel } from '../src/calendar/helpers';
|
2021-08-14 07:22:30 -07:00
|
|
|
import { currentYear } from '../src/calendar/calendar';
|
2021-08-14 01:42:49 -07:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
year: { required: true },
|
|
|
|
month: { required: true },
|
2021-08-18 09:51:11 -07:00
|
|
|
markToday: { type: Boolean },
|
2021-08-14 01:42:49 -07:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
iterateMonth,
|
|
|
|
currentYear,
|
|
|
|
today: Day.today(),
|
|
|
|
selectedDay: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$eventHub.$on('calendar-select', selectedDay => {
|
|
|
|
if (this.selectedDay && !this.selectedDay.equals(selectedDay)) {
|
|
|
|
this.selectedDay = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
if (process.client) {
|
|
|
|
document.addEventListener('click', this.documentClicked);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
if (process.client) {
|
|
|
|
document.removeEventListener('click', this.documentClicked);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
startingDayOfWeek() {
|
|
|
|
return new Day(this.year, this.month, 1).dayOfWeek;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getDayClass(d) {
|
|
|
|
if (this.currentYear.eventsByDate[d.toString()] === undefined) {
|
|
|
|
return 'day';
|
|
|
|
}
|
|
|
|
|
2021-08-17 10:50:49 -07:00
|
|
|
let maxLevel = 0;
|
|
|
|
for (let event of this.currentYear.eventsByDate[d.toString()]) {
|
|
|
|
if (event.level > maxLevel) {
|
|
|
|
maxLevel = event.level;
|
|
|
|
}
|
2021-08-14 01:42:49 -07:00
|
|
|
}
|
|
|
|
|
2021-08-17 10:50:49 -07:00
|
|
|
return `day day-event day-event-${maxLevel}`;
|
2021-08-14 01:42:49 -07:00
|
|
|
},
|
|
|
|
getDayFlag(d) {
|
2021-09-25 07:25:40 -07:00
|
|
|
for (let event of (this.currentYear.eventsByDate[d.toString()] || []).filter(e => e.level === EventLevel.Day && e.flag)) {
|
2021-08-14 01:42:49 -07:00
|
|
|
return `/flags/${event.flag}.png`;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
documentClicked() {
|
|
|
|
if (this.selectedDay) {
|
|
|
|
this.selectedDay = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectDay(d) {
|
|
|
|
if (d.equals(this.selectedDay)) {
|
|
|
|
this.selectedDay = null;
|
|
|
|
} else {
|
|
|
|
this.selectedDay = d;
|
|
|
|
}
|
|
|
|
this.$eventHub.$emit('calendar-select', this.selectedDay);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "assets/style";
|
|
|
|
|
|
|
|
.calendar {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(7, 1fr);
|
|
|
|
grid-column-gap: 2px;
|
|
|
|
grid-row-gap: 2px;
|
|
|
|
> .day {
|
2021-08-17 14:23:25 -07:00
|
|
|
/*aspect-ratio: 1;*/
|
|
|
|
&::before {
|
|
|
|
float: left;
|
|
|
|
padding-top: 100%;
|
|
|
|
content: '';
|
|
|
|
}
|
|
|
|
&::after {
|
|
|
|
display: block;
|
|
|
|
content: '';
|
|
|
|
clear: both;
|
|
|
|
}
|
|
|
|
|
2021-08-14 01:42:49 -07:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-evenly;
|
|
|
|
cursor: default;
|
|
|
|
user-select: none;
|
|
|
|
position: relative;
|
|
|
|
&.day-event {
|
|
|
|
cursor: pointer;
|
2021-08-17 10:50:49 -07:00
|
|
|
&.day-event-0 {
|
|
|
|
background-color: lighten($primary, 50%);
|
|
|
|
}
|
|
|
|
&.day-event-1 {
|
|
|
|
background-color: lighten($primary, 40%);
|
|
|
|
}
|
|
|
|
&.day-event-2 {
|
|
|
|
background-color: lighten($primary, 50%);
|
|
|
|
border: 1px solid lighten($primary, 25%);
|
|
|
|
}
|
|
|
|
&.day-event-3 {
|
|
|
|
border: 1px solid lighten($primary, 25%);
|
2021-08-14 01:42:49 -07:00
|
|
|
background-color: $primary;
|
|
|
|
color: $white;
|
|
|
|
.day-number {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
&[data-flag] {
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-position: center;
|
|
|
|
background-size: cover;
|
|
|
|
.day-number {
|
|
|
|
text-shadow: black 1px 1px 3px
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&:hover, &.day-selected {
|
|
|
|
background: lighten($primary, 25%) !important;
|
|
|
|
@extend .shadow;
|
|
|
|
.day-number {
|
|
|
|
color: $white;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&.day-today {
|
2021-08-29 15:57:54 -07:00
|
|
|
border: 3px solid $black !important;
|
2021-08-14 01:42:49 -07:00
|
|
|
@extend .shadow;
|
|
|
|
}
|
|
|
|
.day-tooltip {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
left: 100%;
|
|
|
|
width: 300px;
|
|
|
|
@include media-breakpoint-down('md', $grid-breakpoints) {
|
|
|
|
position: fixed;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
2021-08-18 00:42:54 -07:00
|
|
|
padding-bottom: 3rem;
|
2021-08-14 01:42:49 -07:00
|
|
|
}
|
2021-08-18 00:42:54 -07:00
|
|
|
z-index: 1040;
|
2021-08-14 01:42:49 -07:00
|
|
|
cursor: default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|