You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
4.5 KiB

  1. <template>
  2. <div class="calendar-page">
  3. <h1 class="calendar__month">
  4. {{ new Date(date).toLocaleString("default", { month: "long" }) }}
  5. </h1>
  6. <ul class="calendar">
  7. <li
  8. v-for="dow in daysOfWeek"
  9. :key="dow"
  10. :class="['calendar__day', 'calendar__day--dow']"
  11. >
  12. {{ dow }}
  13. </li>
  14. <li
  15. v-for="index in getDayOfWeekOffset(date)"
  16. :key="index + 'o'"
  17. class="calendar__day calendar__day--blank"
  18. />
  19. <li
  20. v-for="day in getDaysInMonth(date)"
  21. :key="day.toString()"
  22. class="calendar__day"
  23. >
  24. <span class="day__date"> {{ day.getDate() }} </span>
  25. <NuxtLink
  26. v-if="
  27. selectedDows.find((sched) =>
  28. sched.DowsList.find((dow) => dow.num == day.getDay())
  29. ) && day > new Date()
  30. "
  31. class="btn btn--primary btn--day"
  32. :to="
  33. '/flights/' +
  34. $route.params.o +
  35. '/' +
  36. $route.params.d +
  37. '/' +
  38. day.toLocaleDateString('en-CA')
  39. "
  40. >
  41. <span class="day__date"> {{ day.getDate() }} </span>
  42. </NuxtLink>
  43. <span
  44. v-if="
  45. selectedDows.find((sched) =>
  46. sched.DowsList.find((dow) => dow.num == day.getDay())
  47. ) &&
  48. day > new Date() &&
  49. selectedDows.filter((sched) =>
  50. sched.DowsList.find((dow) => dow.num == day.getDay())
  51. ).length == 1
  52. "
  53. class="badge badge--day badge--count"
  54. >
  55. {{ scheduleTime(selectedDows[0]) }}
  56. </span>
  57. <span
  58. v-if="
  59. selectedDows.find((sched) =>
  60. sched.DowsList.find((dow) => dow.num == day.getDay())
  61. ) &&
  62. day > new Date() &&
  63. selectedDows.filter((sched) =>
  64. sched.DowsList.find((dow) => dow.num == day.getDay())
  65. ).length > 1
  66. "
  67. class="badge badge--day badge--count"
  68. >
  69. {{
  70. selectedDows.filter((sched) =>
  71. sched.DowsList.find((dow) => dow.num == day.getDay())
  72. ).length + "x"
  73. }}
  74. </span>
  75. </li>
  76. </ul>
  77. </div>
  78. </template>
  79. <script>
  80. export default {
  81. props: {
  82. date: {
  83. type: [Date],
  84. default () {
  85. return new Date()
  86. }
  87. },
  88. selectedDows: {
  89. type: [Array],
  90. default () {
  91. return []
  92. }
  93. }
  94. },
  95. data () {
  96. return {
  97. daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
  98. }
  99. },
  100. methods: {
  101. getDayOfWeekOffset (thisDate) {
  102. const dow = new Date(thisDate.getFullYear(), thisDate.getMonth(), 1).getDay()
  103. return dow
  104. },
  105. getDaysInMonth (thisDate) {
  106. const daysInMonth = new Date(thisDate.getFullYear(), thisDate.getMonth() + 1, 0).getDate()
  107. const days = []
  108. for (let index = 1; index < daysInMonth + 1; index++) {
  109. days.push(new Date(thisDate.getFullYear(), thisDate.getMonth(), index))
  110. }
  111. return days
  112. },
  113. book (thisDate) {
  114. this.$emit('book', thisDate)
  115. },
  116. scheduleTime (dow) {
  117. // console.log(dow)
  118. const thisDate = new Date(dow.DepartureTimeFormatted)
  119. const hours = thisDate.getHours() + Math.round(thisDate.getMinutes() / 60)
  120. return ((hours > 12) ? (hours - 12) + 'pm' : hours + 'am')
  121. }
  122. }
  123. }
  124. </script>
  125. <style>
  126. .calendar-page {
  127. width: min(90vmin, 400px);
  128. }
  129. .calendar {
  130. display: grid;
  131. border-radius: 3rem;
  132. grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
  133. grid-template-rows: 0.5fr 1fr 1fr 1fr 1fr 1fr 1fr;
  134. gap: 0.75rem;
  135. }
  136. .day__date {
  137. font-size: 1.4rem;
  138. }
  139. .btn.btn--day {
  140. position: absolute;
  141. left: 0;
  142. width: 100%;
  143. height: 100%;
  144. top: 0;
  145. background: #007fff;
  146. color: white;
  147. border-radius: 999px;
  148. display: flex;
  149. align-items: center;
  150. justify-content: center;
  151. }
  152. .calendar__day {
  153. position: relative;
  154. aspect-ratio: 1;
  155. display: flex;
  156. align-items: center;
  157. justify-content: center;
  158. border-radius: 999px;
  159. background: #eee;
  160. }
  161. .calendar__day--dow {
  162. background: transparent;
  163. aspect-ratio: unset;
  164. color: gray;
  165. font-size: 1.2rem;
  166. font-weight: 300;
  167. }
  168. .calendar__day--blank {
  169. background: white;
  170. }
  171. h1.calendar__month {
  172. text-align: center;
  173. font-size: 2rem;
  174. margin: 0.5rem 0;
  175. font-weight: 700;
  176. }
  177. .badge.badge--day {
  178. position: absolute;
  179. background: hotpink;
  180. border: white 0.2rem solid;
  181. border-radius: 999px;
  182. color: white;
  183. padding: 0 0.4em;
  184. bottom: -0.25rem;
  185. right: -0.25rem;
  186. font-size: 0.7rem;
  187. }
  188. </style>