|
| 1 | +<script setup lang="ts"> |
| 2 | +import FilterInput from "@/components/FilterInput.vue"; |
| 3 | +import { storeToRefs } from "pinia"; |
| 4 | +import { useAuditStore } from "@/stores/AuditStore.ts"; |
| 5 | +import ListFilterSelector from "@/components/audit/ListFilterSelector.vue"; |
| 6 | +import { computed, ref, watch } from "vue"; |
| 7 | +import DatePickerRange from "@/components/audit/DatePickerRange.vue"; |
| 8 | +
|
| 9 | +const store = useAuditStore(); |
| 10 | +const { sortBy, messageFilterString, selectedEndpointName, endpoints, itemsPerPage, dateRange } = storeToRefs(store); |
| 11 | +const endpointNames = computed(() => { |
| 12 | + return [...new Set(endpoints.value.map((endpoint) => endpoint.name))]; |
| 13 | +}); |
| 14 | +const sortByItemsMap = new Map([ |
| 15 | + ["Latest sent", "time_sent,desc"], |
| 16 | + ["Oldest sent", "time_sent,asc"], |
| 17 | + ["Fastest processing", "processing_time,asc"], |
| 18 | + ["Slowest processing", "processing_time,desc"], |
| 19 | +]); |
| 20 | +const numberOfItemsPerPage = ["50", "100", "250", "500"]; |
| 21 | +const sortByItems = computed(() => [...sortByItemsMap.keys()]); |
| 22 | +
|
| 23 | +function findKeyByValue(searchValue: string) { |
| 24 | + for (const [key, value] of sortByItemsMap.entries()) { |
| 25 | + if (value === searchValue) { |
| 26 | + return key; |
| 27 | + } |
| 28 | + } |
| 29 | + return ""; |
| 30 | +} |
| 31 | +
|
| 32 | +const r = `${sortBy.value.property},${sortBy.value.isAscending ? "asc" : "desc"}`; |
| 33 | +
|
| 34 | +const selectedSortByItem = ref(findKeyByValue(r)); //computed(() => sortByItemsMap.get(`${sortBy.value.property},${sortBy.value.isAscending ? "asc" : "desc"}`) || "time_sent,desc"); |
| 35 | +const selectedItemsPerPage = ref(itemsPerPage.value.toString()); |
| 36 | +
|
| 37 | +watch(selectedItemsPerPage, (newValue) => { |
| 38 | + itemsPerPage.value = Number(newValue); |
| 39 | +}); |
| 40 | +watch(selectedSortByItem, (newValue) => { |
| 41 | + const item = sortByItemsMap.get(newValue); |
| 42 | + if (item) { |
| 43 | + const strings = item.split(","); |
| 44 | + sortBy.value = { isAscending: strings[1] === "asc", property: strings[0] }; |
| 45 | + } else { |
| 46 | + sortBy.value = { isAscending: true, property: "time_sent" }; |
| 47 | + } |
| 48 | +}); |
| 49 | +</script> |
| 50 | + |
| 51 | +<template> |
| 52 | + <div class="filters"> |
| 53 | + <div class="filter"> |
| 54 | + <div class="filter-label"></div> |
| 55 | + <div class="filter-component text-search-container"><FilterInput v-model="messageFilterString" placeholder="Search messages..." aria-label="Search messages" /></div> |
| 56 | + </div> |
| 57 | + <div class="filter"> |
| 58 | + <div class="filter-label">Endpoints:</div> |
| 59 | + <div class="filter-component"> |
| 60 | + <ListFilterSelector :items="endpointNames" instructions="Select an endpoint" v-model="selectedEndpointName" item-name="endpoint" label="Endpoint" default-empty-text="Any" :show-clear="true" :show-filter="true" /> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + <div class="filter"> |
| 64 | + <div class="filter-label">Dates:</div> |
| 65 | + <div class="filter-component"> |
| 66 | + <DatePickerRange v-model="dateRange" /> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + <div class="filter"> |
| 70 | + <div class="filter-label">Show:</div> |
| 71 | + <div class="filter-component"> |
| 72 | + <ListFilterSelector :items="numberOfItemsPerPage" instructions="Select how many result to display" v-model="selectedItemsPerPage" item-name="result" default-empty-text="Any" :show-clear="false" :show-filter="false" /> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + <div class="filter last-filter"> |
| 76 | + <div class="filter-label">Sort:</div> |
| 77 | + <div class="filter-component"> |
| 78 | + <ListFilterSelector :items="sortByItems" instructions="" v-model="selectedSortByItem" item-name="result" default-empty-text="Any" :show-clear="false" :show-filter="false" /> |
| 79 | + </div> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | +</template> |
| 83 | + |
| 84 | +<style scoped> |
| 85 | +.last-filter { |
| 86 | + flex-grow: 1; |
| 87 | + place-content: flex-end; |
| 88 | +} |
| 89 | +.filters { |
| 90 | + background-color: #f3f3f3; |
| 91 | + border: #8c8c8c 1px solid; |
| 92 | + border-radius: 3px; |
| 93 | + padding: 0.3125rem; |
| 94 | + display: flex; |
| 95 | + gap: 1.1rem; |
| 96 | +} |
| 97 | +.filter { |
| 98 | + display: flex; |
| 99 | + align-items: center; |
| 100 | +} |
| 101 | +.filter-label { |
| 102 | + font-weight: bold; |
| 103 | +} |
| 104 | +
|
| 105 | +.filter-component { |
| 106 | +} |
| 107 | +.text-search-container { |
| 108 | + width: 25rem; |
| 109 | +} |
| 110 | +</style> |
0 commit comments