Add ordering selector in list view
This commit is contained in:
parent
4c4f06f733
commit
35c4188096
|
@ -1347,8 +1347,8 @@ class UserPublicKeyViewSet(UserSubresourceViewSetMixin, mixins.ListModelMixin, m
|
|||
# * [x] prop with ordering options
|
||||
# * [x] dropdown menu to select ordering
|
||||
# * [x] v-model:ordering prop
|
||||
# * [ ] configure ordering options:
|
||||
# * [x] configure ordering options:
|
||||
# * [x] project list (open, finished)
|
||||
# * [ ] project type list (global, private)
|
||||
# * [x] project type list (global, private)
|
||||
# * [x] template list
|
||||
# * [ ] user list
|
||||
# * [x] user list
|
||||
|
|
|
@ -11,17 +11,24 @@
|
|||
</div>
|
||||
</h1>
|
||||
|
||||
<slot name="searchbar" :items="items">
|
||||
<v-text-field
|
||||
:model-value="items.search.value"
|
||||
@update:model-value="updateSearch"
|
||||
label="Search"
|
||||
variant="underlined"
|
||||
spellcheck="false"
|
||||
hide-details="auto"
|
||||
autofocus
|
||||
class="mt-0 mb-2"
|
||||
/>
|
||||
<slot name="searchbar" :items="items" :ordering="ordering" :ordering-options="orderingOptions">
|
||||
<div class="d-flex flex-row">
|
||||
<v-text-field
|
||||
:model-value="items.search.value"
|
||||
@update:model-value="updateSearch"
|
||||
label="Search"
|
||||
variant="underlined"
|
||||
spellcheck="false"
|
||||
hide-details="auto"
|
||||
autofocus
|
||||
class="mt-0 mb-2"
|
||||
/>
|
||||
<s-select-ordering
|
||||
:model-value="ordering"
|
||||
@update:model-value="updateOrdering"
|
||||
:ordering-options="props.orderingOptions"
|
||||
/>
|
||||
</div>
|
||||
</slot>
|
||||
<v-tabs v-if="$slots.tabs" height="30" selected-class="text-primary" class="list-header-tabs">
|
||||
<slot name="tabs" />
|
||||
|
@ -48,15 +55,28 @@
|
|||
<script setup lang="ts" generic="T = any">
|
||||
import { useSearchableCursorPaginationFetcher } from "~/composables/api";
|
||||
|
||||
const orderingModel = defineModel<string|null>('ordering');
|
||||
const props = defineProps<{
|
||||
url: string|null;
|
||||
orderingOptions?: OrderingOption[];
|
||||
}>();
|
||||
|
||||
const ordering = computed(() => {
|
||||
if (route.query.ordering) {
|
||||
return props.orderingOptions?.find(o => o.value === route.query.ordering) || null;
|
||||
} else {
|
||||
return props.orderingOptions?.find(o => o.id === orderingModel.value) || props.orderingOptions?.[0] || null
|
||||
}
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const items = useSearchableCursorPaginationFetcher<T>({
|
||||
baseURL: props.url,
|
||||
query: { ...route.query },
|
||||
query: {
|
||||
ordering: ordering.value?.value,
|
||||
...route.query
|
||||
},
|
||||
});
|
||||
useLazyAsyncData(async () => {
|
||||
await items.fetchNextPage()
|
||||
|
@ -75,9 +95,19 @@ function updateSearch(search: string) {
|
|||
router.replace({ query: { ...route.query, search } });
|
||||
}
|
||||
|
||||
function updateOrdering(ordering?: OrderingOption|null) {
|
||||
orderingModel.value = ordering?.id || null;
|
||||
if (!ordering) {
|
||||
ordering = props.orderingOptions![0];
|
||||
}
|
||||
router.replace({ query: { ...route.query, ordering: ordering.value } });
|
||||
items.applyFilters({ ...route.query });
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
items,
|
||||
updateSearch,
|
||||
updateOrdering,
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<template>
|
||||
<s-btn-icon v-if="(props.orderingOptions?.length || 0) > 0">
|
||||
<v-icon icon="mdi-sort" />
|
||||
|
||||
<v-menu activator="parent" location="bottom">
|
||||
<v-list
|
||||
:selected="[modelValue]"
|
||||
@update:selected="modelValue = $event[0] || null"
|
||||
>
|
||||
<v-list-item
|
||||
v-for="option in props.orderingOptions" :key="option.id"
|
||||
prepend-icon="mdi-sort"
|
||||
:title="option.title"
|
||||
:value="option"
|
||||
/>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
</s-btn-icon>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const modelValue = defineModel<OrderingOption|null>();
|
||||
const props = defineProps<{
|
||||
orderingOptions?: OrderingOption[];
|
||||
}>();
|
||||
</script>
|
|
@ -1,6 +1,14 @@
|
|||
<template>
|
||||
<file-drop-area @drop="importBtnRef.performImport($event)" class="h-100">
|
||||
<list-view url="/api/v1/projecttypes/?scope=global&ordering=name">
|
||||
<list-view
|
||||
url="/api/v1/projecttypes/?scope=global"
|
||||
v-model:ordering="localSettings.designListOrdering"
|
||||
:ordering-options="[
|
||||
{id: 'name', title: 'Name', value: 'name'},
|
||||
{id: 'created', title: 'Created', value: '-created'},
|
||||
{id: 'updated', title: 'Updated', value: '-updated'},
|
||||
]"
|
||||
>
|
||||
<template #title>Designs</template>
|
||||
<template #actions>
|
||||
<design-create-design-dialog :project-type-scope="ProjectTypeScope.GLOBAL" />
|
||||
|
@ -27,6 +35,7 @@ useHeadExtended({
|
|||
});
|
||||
|
||||
const route = useRoute();
|
||||
const localSettings = useLocalSettings();
|
||||
const apiSettings = useApiSettings();
|
||||
|
||||
const importBtnRef = ref();
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
<template>
|
||||
<file-drop-area @drop="importBtnRef.performImport($event)" class="h-100">
|
||||
<list-view url="/api/v1/projecttypes/?scope=private&ordering=name">
|
||||
<list-view
|
||||
url="/api/v1/projecttypes/?scope=private"
|
||||
v-model:ordering="localSettings.designListOrdering"
|
||||
:ordering-options="[
|
||||
{id: 'name', title: 'Name', value: 'name'},
|
||||
{id: 'created', title: 'Created', value: '-created'},
|
||||
{id: 'updated', title: 'Updated', value: '-updated'},
|
||||
]"
|
||||
>
|
||||
<template #title>Designs</template>
|
||||
<template #actions>
|
||||
<design-create-design-dialog :project-type-scope="ProjectTypeScope.PRIVATE" />
|
||||
|
@ -27,6 +35,7 @@ useHeadExtended({
|
|||
});
|
||||
|
||||
const route = useRoute();
|
||||
const localSettings = useLocalSettings();
|
||||
const apiSettings = useApiSettings();
|
||||
|
||||
const importBtnRef = ref();
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<template>
|
||||
<list-view url="/api/v1/pentestprojects/?readonly=true">
|
||||
<list-view
|
||||
url="/api/v1/pentestprojects/?readonly=true"
|
||||
v-model:ordering="localSettings.projectListOrdering"
|
||||
:ordering-options="[
|
||||
{id: 'created', title: 'Created', value: '-created'},
|
||||
{id: 'updated', title: 'Updated', value: '-updated'},
|
||||
{id: 'name', title: 'Name', value: 'name'},
|
||||
]"
|
||||
>
|
||||
<template #title>Projects</template>
|
||||
<template #tabs>
|
||||
<v-tab :to="{path: '/projects/', query: route.query}" exact prepend-icon="mdi-file-document" text="Active" />
|
||||
|
@ -24,5 +32,6 @@ useHeadExtended({
|
|||
});
|
||||
|
||||
const route = useRoute();
|
||||
const localSettings = useLocalSettings();
|
||||
const apiSettings = useApiSettings();
|
||||
</script>
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
<template>
|
||||
<file-drop-area @drop="importBtn.performImport($event)" class="h-100">
|
||||
<list-view url="/api/v1/pentestprojects/?readonly=false">
|
||||
<list-view
|
||||
url="/api/v1/pentestprojects/?readonly=false"
|
||||
v-model:ordering="localSettings.projectListOrdering"
|
||||
:ordering-options="[
|
||||
{id: 'created', title: 'Created', value: '-created'},
|
||||
{id: 'updated', title: 'Updated', value: '-updated'},
|
||||
{id: 'name', title: 'Name', value: 'name'},
|
||||
]"
|
||||
>
|
||||
<template #title>Projects</template>
|
||||
<template #actions>
|
||||
<btn-create to="/projects/new/" :disabled="!auth.permissions.value.create_projects" />
|
||||
|
@ -31,6 +39,7 @@ useHeadExtended({
|
|||
|
||||
const auth = useAuth();
|
||||
const route = useRoute();
|
||||
const localSettings = useLocalSettings();
|
||||
const apiSettings = useApiSettings();
|
||||
|
||||
const importBtn = ref();
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
<template>
|
||||
<file-drop-area @drop="importBtnRef?.performImport($event)" class="h-100">
|
||||
<list-view ref="listViewRef" url="/api/v1/findingtemplates/">
|
||||
<list-view
|
||||
ref="listViewRef"
|
||||
url="/api/v1/findingtemplates/"
|
||||
v-model:ordering="localSettings.templateListOrdering"
|
||||
:ordering-options="[
|
||||
{id: 'risk', title: 'Severity', value: '-risk'},
|
||||
{id: 'created', title: 'Created', value: '-created'},
|
||||
]"
|
||||
>
|
||||
<template #title>Templates</template>
|
||||
<template #searchbar="{items}">
|
||||
<template #searchbar="{ items, ordering, orderingOptions }">
|
||||
<v-row dense class="mb-2 w-100">
|
||||
<v-col cols="12" md="10">
|
||||
<v-col cols="12" md="auto" class="flex-grow-1">
|
||||
<v-text-field
|
||||
:model-value="items.search.value"
|
||||
@update:model-value="listViewRef?.updateSearch"
|
||||
|
@ -24,6 +32,13 @@
|
|||
class="ma-0"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="auto">
|
||||
<s-select-ordering
|
||||
:model-value="ordering"
|
||||
@update:model-value="listViewRef?.updateOrdering"
|
||||
:ordering-options="orderingOptions"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</template>
|
||||
<template #actions>
|
||||
|
@ -60,6 +75,7 @@ useHeadExtended({
|
|||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const localSettings = useLocalSettings();
|
||||
const apiSettings = useApiSettings();
|
||||
const auth = useAuth();
|
||||
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<template>
|
||||
<list-view url="/api/v1/pentestusers/">
|
||||
<list-view
|
||||
url="/api/v1/pentestusers/"
|
||||
:ordering-options="[
|
||||
{id: 'created', title: 'Created', value: '-created'},
|
||||
{id: 'username', title: 'Username', value: 'username'},
|
||||
]"
|
||||
>
|
||||
<template #title>Users</template>
|
||||
<template #actions>
|
||||
<btn-create
|
||||
|
|
|
@ -20,6 +20,9 @@ export const useLocalSettings = defineStore('settings', {
|
|||
reportFieldDefinitionMenuSize: 15,
|
||||
findingFieldDefinitionMenuSize: 15,
|
||||
defaultNotesDefinitionMenuSize: 15,
|
||||
projectListOrdering: null as string|null,
|
||||
designListOrdering: null as string|null,
|
||||
templateListOrdering: null as string|null,
|
||||
templateFieldFilterDesign: 'all',
|
||||
templateFieldFilterHiddenFields: [] as string[],
|
||||
noteExpandStates: {} as {[noteId: string]: boolean},
|
||||
|
|
|
@ -544,3 +544,9 @@ export type CWE = {
|
|||
description: string;
|
||||
parent: number|null;
|
||||
};
|
||||
|
||||
export type OrderingOption = {
|
||||
id: string;
|
||||
title: string;
|
||||
value: string;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue