Add sorting parameters and refactor server part to use enums for sorting.
This commit is contained in:
parent
f95829adc6
commit
a3dce0b8a2
9 changed files with 174 additions and 100 deletions
frontend/src
|
@ -1,5 +1,5 @@
|
|||
import {defineStore} from "pinia";
|
||||
import {type EnhancedNode, isEnhancedNode, type NodesFilter} from "@/types";
|
||||
import {type EnhancedNode, isEnhancedNode, type NodesFilter, NodeSortField, SortDirection} from "@/types";
|
||||
import {internalApi} from "@/utils/Api";
|
||||
|
||||
interface NodesStoreState {
|
||||
|
@ -7,6 +7,8 @@ interface NodesStoreState {
|
|||
page: number;
|
||||
nodesPerPage: number;
|
||||
totalNodes: number;
|
||||
sortDirection: SortDirection;
|
||||
sortField: NodeSortField;
|
||||
}
|
||||
|
||||
export const useNodesStore = defineStore({
|
||||
|
@ -17,6 +19,8 @@ export const useNodesStore = defineStore({
|
|||
page: 1,
|
||||
nodesPerPage: 20,
|
||||
totalNodes: 0,
|
||||
sortDirection: SortDirection.ASCENDING,
|
||||
sortField: NodeSortField.HOSTNAME,
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
|
@ -37,18 +41,27 @@ export const useNodesStore = defineStore({
|
|||
},
|
||||
},
|
||||
actions: {
|
||||
async refresh(page: number, nodesPerPage: number, filter: NodesFilter, searchTerm?: string): Promise<void> {
|
||||
async refresh(
|
||||
page: number,
|
||||
nodesPerPage: number,
|
||||
sortDirection: SortDirection,
|
||||
sortField: NodeSortField,
|
||||
filter: NodesFilter,
|
||||
searchTerm?: string
|
||||
): Promise<void> {
|
||||
const query: Record<string, any> = {
|
||||
...filter,
|
||||
};
|
||||
if (searchTerm) {
|
||||
query.q = searchTerm;
|
||||
}
|
||||
const result = await internalApi.getPagedList<EnhancedNode>(
|
||||
const result = await internalApi.getPagedList<EnhancedNode, NodeSortField>(
|
||||
"nodes",
|
||||
isEnhancedNode,
|
||||
page,
|
||||
nodesPerPage,
|
||||
sortDirection,
|
||||
sortField,
|
||||
query,
|
||||
);
|
||||
this.nodes = result.entries;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {toIsArray, type TypeGuard} from "@/types";
|
||||
import {SortDirection, toIsArray, type TypeGuard} from "@/types";
|
||||
import type {Headers} from "request";
|
||||
import {parseInteger} from "@/utils/Numbers";
|
||||
|
||||
|
@ -57,16 +57,20 @@ class Api {
|
|||
return response.result;
|
||||
}
|
||||
|
||||
async getPagedList<T>(
|
||||
async getPagedList<Element, SortField>(
|
||||
path: string,
|
||||
isT: TypeGuard<T>,
|
||||
isElement: TypeGuard<Element>,
|
||||
page: number,
|
||||
itemsPerPage: number,
|
||||
sortDirection?: SortDirection,
|
||||
sortField?: SortField,
|
||||
filter?: object,
|
||||
): Promise<PagedListResult<T>> {
|
||||
const response = await this.doGet(path, toIsArray(isT), {
|
||||
): Promise<PagedListResult<Element>> {
|
||||
const response = await this.doGet(path, toIsArray(isElement), {
|
||||
_page: page,
|
||||
_perPage: itemsPerPage,
|
||||
_sortDir: sortDirection,
|
||||
_sortField: sortField,
|
||||
...filter,
|
||||
});
|
||||
const totalStr = response.headers.get("x-total-count");
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import {useNodesStore} from "@/stores/nodes";
|
||||
import {onMounted, ref, watch} from "vue";
|
||||
import type {EnhancedNode, MAC, NodesFilter} from "@/types";
|
||||
import {NodeSortField, SortDirection} from "@/types";
|
||||
import Pager from "@/components/Pager.vue";
|
||||
import LoadingContainer from "@/components/LoadingContainer.vue";
|
||||
import NodesFilterPanel from "@/components/nodes/NodesFilterPanel.vue";
|
||||
|
@ -32,7 +33,14 @@ async function refresh(page: number): Promise<void> {
|
|||
loading.value = true;
|
||||
redactAllFields(true);
|
||||
try {
|
||||
await nodes.refresh(page, NODE_PER_PAGE, currentFilter.value, currentSearchTerm.value);
|
||||
await nodes.refresh(
|
||||
page,
|
||||
NODE_PER_PAGE,
|
||||
SortDirection.ASCENDING,
|
||||
NodeSortField.HOSTNAME,
|
||||
currentFilter.value,
|
||||
currentSearchTerm.value,
|
||||
);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue