From 6057ad5a2a76f554308536233272e37824f83080 Mon Sep 17 00:00:00 2001 From: baldo Date: Mon, 27 Jun 2022 13:51:01 +0200 Subject: [PATCH] Add sorting by column and fix page reload issue. --- .../src/components/nodes/NodesFilterPanel.vue | 14 +- frontend/src/components/table/SortTH.vue | 67 ++++++ frontend/src/router/index.ts | 6 +- frontend/src/views/AdminNodesView.vue | 191 ++++++++++++++---- server/types/shared.ts | 3 + 5 files changed, 228 insertions(+), 53 deletions(-) create mode 100644 frontend/src/components/table/SortTH.vue diff --git a/frontend/src/components/nodes/NodesFilterPanel.vue b/frontend/src/components/nodes/NodesFilterPanel.vue index f22d986..3b360a1 100644 --- a/frontend/src/components/nodes/NodesFilterPanel.vue +++ b/frontend/src/components/nodes/NodesFilterPanel.vue @@ -7,12 +7,14 @@ import { NODES_FILTER_FIELDS, type NodesFilter, OnlineState, + type SearchTerm, type UnixTimestampMilliseconds, } from "@/types"; import {computed, nextTick, onMounted, ref, watch} from "vue"; import {useConfigStore} from "@/stores/config"; interface Props { + searchTerm: SearchTerm; filter: NodesFilter; } @@ -41,7 +43,7 @@ const FILTER_LABELS: Record> = { } const emit = defineEmits<{ - (e: "updateFilter", filter: NodesFilter, searchTerm?: string): void, + (e: "updateFilter", filter: NodesFilter, searchTerm: SearchTerm): void, }>(); const props = defineProps(); @@ -204,15 +206,12 @@ function buildNodesFilter(): NodesFilter { let lastSearchTimestamp: UnixTimestampMilliseconds = 0 as UnixTimestampMilliseconds; let searchTimeout: NodeJS.Timeout | undefined = undefined; -let lastSearchTerm = ""; +let lastSearchTerm: SearchTerm = "" as SearchTerm; function doSearch(): void { const nodesFilter = buildNodesFilter(); - lastSearchTerm = input.value.value; - let searchTerm: string | undefined = lastSearchTerm.trim(); - if (!searchTerm) { - searchTerm = undefined; - } + lastSearchTerm = input.value.value as SearchTerm; + const searchTerm: SearchTerm = lastSearchTerm.trim() as SearchTerm; emit("updateFilter", nodesFilter, searchTerm); } @@ -258,6 +257,7 @@ function doThrottledSearch(): void { @keyup="doThrottledSearch()" maxlength="64" type="search" + :value="searchTerm" placeholder="Knoten durchsuchen..."/> diff --git a/frontend/src/components/table/SortTH.vue b/frontend/src/components/table/SortTH.vue new file mode 100644 index 0000000..c3be3ad --- /dev/null +++ b/frontend/src/components/table/SortTH.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 5d4520a..bf5a0fb 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -2,7 +2,7 @@ import {createRouter, createWebHistory} from "vue-router"; import AdminDashboardView from "@/views/AdminDashboardView.vue"; import AdminNodesView from "@/views/AdminNodesView.vue"; import HomeView from "@/views/HomeView.vue"; -import {isNodesFilter} from "@/types"; +import {isNodesFilter, isNodeSortField, isSortDirection, type SearchTerm} from "@/types"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -34,10 +34,12 @@ const router = createRouter({ filter = {}; } - const searchTerm = route.query.q ? route.query.q as string : undefined; + const searchTerm = route.query.q ? route.query.q as SearchTerm : undefined; return { filter: isNodesFilter(filter) ? filter : {}, searchTerm, + sortDirection: isSortDirection(route.query.sortDir) ? route.query.sortDir : undefined, + sortField: isNodeSortField(route.query.sortField) ? route.query.sortField : undefined, } } }, diff --git a/frontend/src/views/AdminNodesView.vue b/frontend/src/views/AdminNodesView.vue index 53ffe64..e603b80 100644 --- a/frontend/src/views/AdminNodesView.vue +++ b/frontend/src/views/AdminNodesView.vue @@ -1,23 +1,53 @@