LogsCalendarView.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <Section
  3. :title="t('logs.calendar-title')"
  4. :icon="Calendar01Icon"
  5. :padding="false"
  6. >
  7. <template #toolbar>
  8. <router-link
  9. :to="logsListLocation"
  10. class="button neutral inline-icon"
  11. >
  12. <svg
  13. xmlns="http://www.w3.org/2000/svg"
  14. width="1em"
  15. height="1em"
  16. viewBox="0 0 24 24"
  17. >
  18. <path
  19. fill="currentColor"
  20. d="M20 11H7.83l5.59-5.59L12 4l-8 8l8 8l1.41-1.41L7.83 13H20z"
  21. />
  22. </svg>
  23. {{ t('logs.back-to-list') }}
  24. </router-link>
  25. </template>
  26. <div class="padding">
  27. <Calendar
  28. :events="calendarEvents"
  29. :loading="loading"
  30. :error="error"
  31. :current-month="currentMonthIndex"
  32. :current-year="currentYear"
  33. @event-click="handleEventClick"
  34. @date-click="handleDayClick"
  35. @month-change="handleMonthChange"
  36. />
  37. </div>
  38. </Section>
  39. </template>
  40. <script setup>
  41. import { ref, computed, onMounted } from 'vue'
  42. import { useRoute, useRouter } from 'vue-router'
  43. import { useI18n } from 'vue-i18n'
  44. import { Calendar01Icon } from '@hugeicons/core-free-icons'
  45. import Calendar from 'picocrank/vue/components/Calendar.vue'
  46. import Section from 'picocrank/vue/components/Section.vue'
  47. import { loadStoredLogsFilter } from '../utils/logsFilterStorage.js'
  48. import { formatCalendarMonthQuery, parseCalendarMonthQuery } from '../utils/calendarMonthQuery.js'
  49. const router = useRouter()
  50. const route = useRoute()
  51. const { t } = useI18n()
  52. const logs = ref([])
  53. const loading = ref(false)
  54. const error = ref(null)
  55. // The month lives in the URL so that browser Back from an execution returns to the month being browsed.
  56. const displayedMonth = computed(() => parseCalendarMonthQuery(route.query.month))
  57. const currentMonthIndex = computed(() => displayedMonth.value.monthIndex)
  58. const currentYear = computed(() => displayedMonth.value.year)
  59. const logsListLocation = computed(() => {
  60. const filter = loadStoredLogsFilter()
  61. return filter ? { path: '/logs', query: { filter } } : '/logs'
  62. })
  63. // Convert logs to calendar events format
  64. const calendarEvents = computed(() => {
  65. return logs.value
  66. .filter(log => {
  67. // Only include logs with valid start dates
  68. if (!log.datetimeStarted) return false
  69. const startDate = new Date(log.datetimeStarted)
  70. return !isNaN(startDate.getTime())
  71. })
  72. .map(log => {
  73. const startDate = new Date(log.datetimeStarted)
  74. let endDate = log.datetimeFinished ? new Date(log.datetimeFinished) : null
  75. // Validate end date
  76. if (endDate && isNaN(endDate.getTime())) {
  77. endDate = null
  78. }
  79. return {
  80. id: log.executionTrackingId,
  81. title: log.actionTitle || 'Untitled Action',
  82. date: startDate,
  83. startDate,
  84. endDate,
  85. actionIcon: log.actionIcon,
  86. user: log.user,
  87. tags: log.tags,
  88. logEntry: log
  89. }
  90. })
  91. })
  92. async function fetchLogs () {
  93. loading.value = true
  94. error.value = null
  95. try {
  96. // Currently fetches only the default page (startOffset: 0)
  97. // Multi-page fetching: loop through pages until no more logs or limit reached
  98. const allLogs = []
  99. let startOffset = BigInt(0)
  100. const maxLogs = 10000 // Reasonable limit to prevent excessive API calls
  101. while (allLogs.length < maxLogs) {
  102. const args = {
  103. startOffset
  104. }
  105. const response = await window.client.getLogs(args)
  106. const pageLogs = response.logs || []
  107. // If no logs returned, we've reached the end
  108. if (pageLogs.length === 0) {
  109. break
  110. }
  111. // Append logs from this page
  112. allLogs.push(...pageLogs)
  113. // Update offset for next page
  114. const currentPageSize = Number(response.pageSize) || pageLogs.length
  115. startOffset += BigInt(currentPageSize)
  116. // If we got fewer logs than the page size, we've reached the end
  117. if (pageLogs.length < currentPageSize) {
  118. break
  119. }
  120. }
  121. logs.value = allLogs
  122. } catch (err) {
  123. console.error('Failed to fetch logs:', err)
  124. error.value = 'Failed to load logs'
  125. window.showBigError('fetch-logs-calendar', 'getting logs for calendar', err, false)
  126. } finally {
  127. loading.value = false
  128. }
  129. }
  130. function handleEventClick (event) {
  131. // Navigate to the execution view when clicking on a calendar event
  132. if (event.id) {
  133. router.push(`/logs/${event.id}`)
  134. }
  135. }
  136. function handleDayClick (date) {
  137. // Navigate to logs list filtered by the selected date
  138. // Format date as YYYY-MM-DD using local date components to avoid timezone issues
  139. const year = date.getFullYear()
  140. const month = String(date.getMonth() + 1).padStart(2, '0')
  141. const day = String(date.getDate()).padStart(2, '0')
  142. const dateString = `${year}-${month}-${day}`
  143. const query = { date: dateString }
  144. const storedFilter = loadStoredLogsFilter()
  145. if (storedFilter) {
  146. query.filter = storedFilter
  147. }
  148. router.push({ path: '/logs', query })
  149. }
  150. function handleMonthChange (month, year) {
  151. router.replace({ query: { ...route.query, month: formatCalendarMonthQuery(month, year) } })
  152. }
  153. onMounted(() => {
  154. fetchLogs()
  155. })
  156. </script>
  157. <style scoped>
  158. .padding {
  159. padding: 1rem;
  160. }
  161. </style>