LogsListView.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <Section :title="t('logs.title')" :padding="false">
  3. <template #toolbar>
  4. <router-link to="/logs/calendar" class="button neutral">
  5. {{ t('logs.calendar') }}
  6. </router-link>
  7. <label class="input-with-icons">
  8. <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
  9. <path fill="currentColor"
  10. d="m19.6 21l-6.3-6.3q-.75.6-1.725.95T9.5 16q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l6.3 6.3zM9.5 14q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14" />
  11. </svg>
  12. <input :placeholder="t('search-filter')" v-model="searchText" />
  13. <button :title="t('logs.clear-filter')" :disabled="!searchText" @click="clearSearch">
  14. <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
  15. <path fill="currentColor"
  16. d="M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12z" />
  17. </svg>
  18. </button>
  19. </label>
  20. </template>
  21. <p class = "padding">{{ t('logs.page-description') }}</p>
  22. <div v-show="filteredLogs.length > 0">
  23. <table class="logs-table">
  24. <thead>
  25. <tr>
  26. <th>
  27. <div class="timestamp-header">
  28. <span>{{ t('logs.timestamp') }}</span>
  29. <span v-if="selectedDate" class="date-filter-indicator">
  30. <span class="date-filter-text">{{ formatDateFilter(selectedDate) }}</span>
  31. <button :title="t('logs.clear-date-filter')" @click="clearDateFilter" class="clear-date-button">
  32. <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
  33. <path fill="currentColor"
  34. d="M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12z" />
  35. </svg>
  36. </button>
  37. </span>
  38. </div>
  39. </th>
  40. <th>{{ t('logs.action') }}</th>
  41. <th>{{ t('logs.metadata') }}</th>
  42. <th>{{ t('logs.status') }}</th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. <tr v-for="log in filteredLogs" :key="log.executionTrackingId" class="log-row" :title="log.actionTitle">
  47. <td class="timestamp">{{ formatTimestamp(log.datetimeStarted) }}</td>
  48. <td>
  49. <span class="icon" v-html="log.actionIcon"></span>
  50. <router-link :to="`/logs/${log.executionTrackingId}`">
  51. {{ log.actionTitle }}
  52. </router-link>
  53. </td>
  54. <td class="tags">
  55. <span class="annotation">
  56. <span class="annotation-key">User:</span>
  57. <span class="annotation-val">{{ log.user }}</span>
  58. </span>
  59. <span v-if="log.tags && log.tags.length > 0" class="tag-list">
  60. <span v-for="tag in log.tags" :key="tag" class="tag">{{ tag }}</span>
  61. </span>
  62. </td>
  63. <td class="exit-code">
  64. <ActionStatusDisplay :logEntry="log" />
  65. </td>
  66. </tr>
  67. </tbody>
  68. </table>
  69. <Pagination :pageSize="pageSize" :total="totalCount" :currentPage="currentPage" @page-change="handlePageChange" class = "padding"
  70. @page-size-change="handlePageSizeChange" itemTitle="execution logs" />
  71. </div>
  72. <div v-show="selectedDate && filteredLogs.length === 0" class="empty-state">
  73. <p>{{ t('logs.no-logs-to-display') }} {{ formatDateFilter(selectedDate) }}.</p>
  74. <button @click="clearDateFilter" class="button neutral">
  75. {{ t('logs.clear-date-filter') }}
  76. </button>
  77. </div>
  78. <div v-show="logs.length === 0 && !selectedDate" class="empty-state">
  79. <p>{{ t('logs.no-logs-to-display') }}</p>
  80. <router-link to="/">{{ t('return-to-index') }}</router-link>
  81. </div>
  82. </Section>
  83. </template>
  84. <script setup>
  85. import { ref, computed, onMounted, watch } from 'vue'
  86. import { useRoute, useRouter } from 'vue-router'
  87. import Pagination from 'picocrank/vue/components/Pagination.vue'
  88. import Section from 'picocrank/vue/components/Section.vue'
  89. import { useI18n } from 'vue-i18n'
  90. import ActionStatusDisplay from '../components/ActionStatusDisplay.vue'
  91. const route = useRoute()
  92. const router = useRouter()
  93. const logs = ref([])
  94. const searchText = ref('')
  95. const pageSize = ref(10)
  96. const currentPage = ref(1)
  97. const loading = ref(false)
  98. const totalCount = ref(0)
  99. const selectedDate = ref(null)
  100. const { t } = useI18n()
  101. // Read date query parameter from route
  102. function updateDateFromRoute() {
  103. const dateParam = route.query.date
  104. if (dateParam) {
  105. selectedDate.value = dateParam
  106. } else {
  107. selectedDate.value = null
  108. }
  109. // Re-fetch logs when date changes
  110. fetchLogs()
  111. }
  112. // Watch for route changes to update date filter
  113. watch(() => route.query.date, () => {
  114. updateDateFromRoute()
  115. })
  116. const filteredLogs = computed(() => {
  117. let result = logs.value
  118. // Date filtering is now done server-side, so we only need to filter by search text
  119. if (searchText.value) {
  120. const searchLower = searchText.value.toLowerCase()
  121. result = result.filter(log =>
  122. log.actionTitle.toLowerCase().includes(searchLower)
  123. )
  124. }
  125. // Sort by timestamp with most recent first
  126. return [...result].sort((a, b) => {
  127. const dateA = a.datetimeStarted ? new Date(a.datetimeStarted).getTime() : 0
  128. const dateB = b.datetimeStarted ? new Date(b.datetimeStarted).getTime() : 0
  129. return dateB - dateA // Descending order (most recent first)
  130. })
  131. })
  132. async function fetchLogs() {
  133. loading.value = true
  134. try {
  135. const startOffset = (currentPage.value - 1) * pageSize.value
  136. const args = {
  137. "startOffset": BigInt(startOffset),
  138. }
  139. // Add date filter if selected
  140. if (selectedDate.value) {
  141. args.dateFilter = selectedDate.value
  142. }
  143. const response = await window.client.getLogs(args)
  144. logs.value = response.logs
  145. pageSize.value = Number(response.pageSize) || 0
  146. totalCount.value = Number(response.totalCount) || 0
  147. } catch (err) {
  148. console.error('Failed to fetch logs:', err)
  149. window.showBigError('fetch-logs', 'getting logs', err, false)
  150. } finally {
  151. loading.value = false
  152. }
  153. }
  154. function clearSearch() {
  155. searchText.value = ''
  156. }
  157. function clearDateFilter() {
  158. selectedDate.value = null
  159. // Remove date query parameter from URL
  160. const query = { ...route.query }
  161. delete query.date
  162. router.push({ path: route.path, query })
  163. }
  164. function formatDateFilter(dateString) {
  165. // Format YYYY-MM-DD to a short format (e.g., "Jan 15, 2024")
  166. try {
  167. const date = new Date(dateString + 'T00:00:00')
  168. return date.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })
  169. } catch (err) {
  170. return dateString
  171. }
  172. }
  173. function formatTimestamp(timestamp) {
  174. if (!timestamp) return 'Unknown'
  175. try {
  176. const date = new Date(timestamp)
  177. return date.toLocaleString()
  178. } catch (err) {
  179. return timestamp
  180. }
  181. }
  182. function handlePageChange(page) {
  183. currentPage.value = page
  184. fetchLogs()
  185. }
  186. function handlePageSizeChange(newPageSize) {
  187. pageSize.value = newPageSize
  188. currentPage.value = 1 // Reset to first page
  189. fetchLogs()
  190. }
  191. onMounted(() => {
  192. updateDateFromRoute()
  193. })
  194. </script>
  195. <style scoped>
  196. .logs-view {
  197. padding: 1rem;
  198. }
  199. .input-with-icons {
  200. display: flex;
  201. align-items: center;
  202. gap: 0.5rem;
  203. padding: 0.5rem;
  204. border: 1px solid var(--border-color);
  205. border-radius: 0.25rem;
  206. background: var(--section-background);
  207. width: 100%;
  208. max-width: 300px;
  209. }
  210. .input-with-icons input {
  211. border: none;
  212. outline: none;
  213. background: transparent;
  214. flex: 1;
  215. color: var(--text-primary);
  216. }
  217. .input-with-icons button {
  218. background: none;
  219. border: none;
  220. cursor: pointer;
  221. padding: 0.25rem;
  222. border-radius: 3px;
  223. }
  224. .input-with-icons button:disabled {
  225. opacity: 0.5;
  226. cursor: not-allowed;
  227. }
  228. .timestamp {
  229. font-family: monospace;
  230. font-size: 0.875rem;
  231. color: #666;
  232. }
  233. .icon {
  234. margin-right: 0.5rem;
  235. font-size: 1.2em;
  236. }
  237. .content {
  238. color: #007bff;
  239. text-decoration: none;
  240. cursor: pointer;
  241. }
  242. .content:hover {
  243. text-decoration: underline;
  244. }
  245. .annotation {
  246. font-weight: 500;
  247. font-size: smaller;
  248. }
  249. .empty-state {
  250. text-align: center;
  251. padding: 2rem;
  252. color: #666;
  253. }
  254. .empty-state a {
  255. color: #007bff;
  256. text-decoration: none;
  257. }
  258. .empty-state a:hover {
  259. text-decoration: underline;
  260. }
  261. .timestamp-header {
  262. display: flex;
  263. flex-direction: column;
  264. gap: 0.25rem;
  265. }
  266. .date-filter-indicator {
  267. display: flex;
  268. align-items: center;
  269. gap: 0.25rem;
  270. font-size: 0.75rem;
  271. font-weight: normal;
  272. color: var(--text-secondary, #666);
  273. white-space: nowrap;
  274. }
  275. .date-filter-text {
  276. font-style: italic;
  277. }
  278. .timestamp-header .clear-date-button {
  279. background: none;
  280. border: none;
  281. cursor: pointer;
  282. padding: 0.125rem;
  283. border-radius: 3px;
  284. display: flex;
  285. align-items: center;
  286. flex-shrink: 0;
  287. opacity: 0.7;
  288. transition: opacity 0.2s;
  289. }
  290. .timestamp-header .clear-date-button:hover {
  291. opacity: 1;
  292. background: var(--hover-background, rgba(0, 0, 0, 0.05));
  293. }
  294. .timestamp-header .clear-date-button svg {
  295. width: 0.75rem;
  296. height: 0.75rem;
  297. }
  298. </style>