LogsListView.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. <ActionIconGlyph class="icon" :glyph="log.actionIcon" />
  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="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. import ActionIconGlyph from '../components/ActionIconGlyph.vue'
  92. const route = useRoute()
  93. const router = useRouter()
  94. const logs = ref([])
  95. const searchText = ref('')
  96. const pageSize = ref(10)
  97. const currentPage = ref(1)
  98. const loading = ref(false)
  99. const totalCount = ref(0)
  100. const selectedDate = ref(null)
  101. const { t } = useI18n()
  102. // Read date query parameter from route
  103. function updateDateFromRoute() {
  104. const dateParam = route.query.date
  105. if (dateParam) {
  106. selectedDate.value = dateParam
  107. } else {
  108. selectedDate.value = null
  109. }
  110. // Re-fetch logs when date changes
  111. fetchLogs()
  112. }
  113. // Watch for route changes to update date filter
  114. watch(() => route.query.date, () => {
  115. updateDateFromRoute()
  116. })
  117. const filteredLogs = computed(() => {
  118. let result = logs.value
  119. // Date filtering is now done server-side, so we only need to filter by search text
  120. if (searchText.value) {
  121. const searchLower = searchText.value.toLowerCase()
  122. result = result.filter(log =>
  123. log.actionTitle.toLowerCase().includes(searchLower)
  124. )
  125. }
  126. // Sort by timestamp with most recent first
  127. return [...result].sort((a, b) => {
  128. const dateA = a.datetimeStarted ? new Date(a.datetimeStarted).getTime() : 0
  129. const dateB = b.datetimeStarted ? new Date(b.datetimeStarted).getTime() : 0
  130. return dateB - dateA // Descending order (most recent first)
  131. })
  132. })
  133. async function fetchLogs() {
  134. loading.value = true
  135. try {
  136. const startOffset = (currentPage.value - 1) * pageSize.value
  137. const args = {
  138. "startOffset": BigInt(startOffset),
  139. "pageSize": BigInt(pageSize.value),
  140. }
  141. // Add date filter if selected
  142. if (selectedDate.value) {
  143. args.dateFilter = selectedDate.value
  144. }
  145. const response = await window.client.getLogs(args)
  146. logs.value = response.logs
  147. totalCount.value = Number(response.totalCount) || 0
  148. } catch (err) {
  149. console.error('Failed to fetch logs:', err)
  150. window.showBigError('fetch-logs', 'getting logs', err, false)
  151. } finally {
  152. loading.value = false
  153. }
  154. }
  155. function clearSearch() {
  156. searchText.value = ''
  157. }
  158. function clearDateFilter() {
  159. selectedDate.value = null
  160. // Remove date query parameter from URL
  161. const query = { ...route.query }
  162. delete query.date
  163. router.push({ path: route.path, query })
  164. }
  165. function formatDateFilter(dateString) {
  166. // Format YYYY-MM-DD to a short format (e.g., "Jan 15, 2024")
  167. try {
  168. const date = new Date(dateString + 'T00:00:00')
  169. return date.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })
  170. } catch (err) {
  171. return dateString
  172. }
  173. }
  174. function formatTimestamp(timestamp) {
  175. if (!timestamp) return 'Unknown'
  176. try {
  177. const date = new Date(timestamp)
  178. return date.toLocaleString()
  179. } catch (err) {
  180. return timestamp
  181. }
  182. }
  183. function handlePageChange(page) {
  184. currentPage.value = page
  185. fetchLogs()
  186. }
  187. function handlePageSizeChange(newPageSize) {
  188. pageSize.value = newPageSize
  189. currentPage.value = 1 // Reset to first page
  190. fetchLogs()
  191. }
  192. onMounted(() => {
  193. updateDateFromRoute()
  194. })
  195. </script>
  196. <style scoped>
  197. .logs-view {
  198. padding: 1rem;
  199. }
  200. .input-with-icons {
  201. display: flex;
  202. align-items: center;
  203. gap: 0.5rem;
  204. padding: 0.5rem;
  205. border: 1px solid var(--border-color);
  206. border-radius: 0.25rem;
  207. background: var(--section-background);
  208. width: 100%;
  209. max-width: 300px;
  210. }
  211. .input-with-icons input {
  212. border: none;
  213. outline: none;
  214. background: transparent;
  215. flex: 1;
  216. color: var(--text-primary);
  217. }
  218. .input-with-icons button {
  219. background: none;
  220. border: none;
  221. cursor: pointer;
  222. padding: 0.25rem;
  223. border-radius: 3px;
  224. }
  225. .input-with-icons button:disabled {
  226. opacity: 0.5;
  227. cursor: not-allowed;
  228. }
  229. .timestamp {
  230. font-family: monospace;
  231. font-size: 0.875rem;
  232. color: #666;
  233. }
  234. .icon {
  235. margin-right: 0.5rem;
  236. font-size: 1.2em;
  237. }
  238. .content {
  239. color: #007bff;
  240. text-decoration: none;
  241. cursor: pointer;
  242. }
  243. .content:hover {
  244. text-decoration: underline;
  245. }
  246. .annotation {
  247. font-weight: 500;
  248. font-size: smaller;
  249. }
  250. .empty-state {
  251. text-align: center;
  252. padding: 2rem;
  253. color: #666;
  254. }
  255. .empty-state a {
  256. color: #007bff;
  257. text-decoration: none;
  258. }
  259. .empty-state a:hover {
  260. text-decoration: underline;
  261. }
  262. .timestamp-header {
  263. display: flex;
  264. flex-direction: column;
  265. gap: 0.25rem;
  266. }
  267. .date-filter-indicator {
  268. display: flex;
  269. align-items: center;
  270. gap: 0.25rem;
  271. font-size: 0.75rem;
  272. font-weight: normal;
  273. color: var(--text-secondary, #666);
  274. white-space: nowrap;
  275. }
  276. .date-filter-text {
  277. font-style: italic;
  278. }
  279. .timestamp-header .clear-date-button {
  280. background: none;
  281. border: none;
  282. cursor: pointer;
  283. padding: 0.125rem;
  284. border-radius: 3px;
  285. display: flex;
  286. align-items: center;
  287. flex-shrink: 0;
  288. opacity: 0.7;
  289. transition: opacity 0.2s;
  290. }
  291. .timestamp-header .clear-date-button:hover {
  292. opacity: 1;
  293. background: var(--hover-background, rgba(0, 0, 0, 0.05));
  294. }
  295. .timestamp-header .clear-date-button svg {
  296. width: 0.75rem;
  297. height: 0.75rem;
  298. }
  299. </style>