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.

223 lines
5.0 KiB

3 years ago
  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. <a
  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. :href="
  33. $BASE_URL() + '/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. </a>
  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.Departure_TimeL)
  119. const timeArray = dow.Departure_TimeL.split(':')
  120. const thisHour = timeArray[0]
  121. const thisMinute = timeArray[1]
  122. const hours = parseInt(thisHour) + Math.round(parseInt(thisMinute) / 60)
  123. let timeString = ''
  124. switch (true) {
  125. case (hours > 12):
  126. timeString = (hours - 12) + 'pm'
  127. break
  128. case (hours === 12):
  129. timeString = '12pm'
  130. break
  131. case (hours < 12 && hours > 0):
  132. timeString = hours + 'am'
  133. break
  134. case (hours === 0):
  135. timeString = '12am'
  136. break
  137. default:
  138. break
  139. }
  140. return timeString
  141. }
  142. }
  143. }
  144. </script>
  145. <style scoped>
  146. .calendar-page {
  147. width: min(90vmin, 400px);
  148. }
  149. .calendar {
  150. display: grid;
  151. border-radius: 3rem;
  152. grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
  153. grid-template-rows: 0.5fr 1fr 1fr 1fr 1fr 1fr 1fr;
  154. gap: 0.75rem;
  155. }
  156. .day__date {
  157. font-size: 1.4rem;
  158. }
  159. .btn.btn--day {
  160. position: absolute;
  161. left: 0;
  162. width: 100%;
  163. height: 100%;
  164. top: 0;
  165. background: #007fff;
  166. color: white;
  167. border-radius: 999px;
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. }
  172. .calendar__day {
  173. position: relative;
  174. aspect-ratio: 1;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. border-radius: 999px;
  179. background: #eee;
  180. }
  181. .calendar__day--dow {
  182. background: transparent;
  183. aspect-ratio: unset;
  184. color: gray;
  185. font-size: 1.2rem;
  186. font-weight: 300;
  187. }
  188. .calendar__day--blank {
  189. background: white;
  190. }
  191. h1.calendar__month {
  192. text-align: center;
  193. font-size: 2rem;
  194. margin: 0.5rem 0;
  195. font-weight: 700;
  196. }
  197. .badge.badge--day {
  198. position: absolute;
  199. background: hotpink;
  200. border: white 0.15rem solid;
  201. border-radius: 999px;
  202. color: white;
  203. padding: 0 0.4em;
  204. bottom: -0.25rem;
  205. right: -0.25rem;
  206. font-size: 0.6rem;
  207. }
  208. </style>