feat(dashboard): add filtering groups based on whether they have members
and vice versa
This commit is contained in:
parent
28834ba9ad
commit
f112f45e77
@ -52,7 +52,7 @@
|
|||||||
listLoading = false;
|
listLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$: processedGroups = filterList(groups, options, "group")
|
$: processedGroups = filterList(groups, groups, options, "group")
|
||||||
$: currentGroups = paginateList(processedGroups, pageOptions)
|
$: currentGroups = paginateList(processedGroups, pageOptions)
|
||||||
$: shortMembers = createShortList(members)
|
$: shortMembers = createShortList(members)
|
||||||
$: pageAmount = getPageAmount(processedGroups, pageOptions)
|
$: pageAmount = getPageAmount(processedGroups, pageOptions)
|
||||||
|
@ -403,6 +403,29 @@ function resetPage() {
|
|||||||
</Input>
|
</Input>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</Col>
|
</Col>
|
||||||
|
{#if pageOptions.type === 'member'}
|
||||||
|
<Col xs={12} md={6} lg={4} class="mb-2">
|
||||||
|
<InputGroup>
|
||||||
|
<InputGroupText>Groups</InputGroupText>
|
||||||
|
<Input type="select" bind:value={options.groups.filter} on:change={() => resetPage()}>
|
||||||
|
<option value="all">All</option>
|
||||||
|
<option value="include">With groups</option>
|
||||||
|
<option value="exclude">Without groups</option>
|
||||||
|
</Input>
|
||||||
|
</InputGroup>
|
||||||
|
</Col>
|
||||||
|
{:else}
|
||||||
|
<Col xs={12} md={6} lg={4} class="mb-2">
|
||||||
|
<InputGroup>
|
||||||
|
<InputGroupText>Members</InputGroupText>
|
||||||
|
<Input type="select" bind:value={options.groups.filter} on:change={() => resetPage()}>
|
||||||
|
<option value="all">All</option>
|
||||||
|
<option value="include">With members</option>
|
||||||
|
<option value="exclude">Without members</option>
|
||||||
|
</Input>
|
||||||
|
</InputGroup>
|
||||||
|
</Col>
|
||||||
|
{/if}
|
||||||
</Row>
|
</Row>
|
||||||
{/if}
|
{/if}
|
||||||
</CardBody>
|
</CardBody>
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
listLoading = false;
|
listLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$: processedMembers = filterList(members, options, "member")
|
$: processedMembers = filterList(members, groups, options, "member")
|
||||||
$: currentMembers = paginateList(processedMembers, pageOptions)
|
$: currentMembers = paginateList(processedMembers, pageOptions)
|
||||||
$: shortMembers = createShortList(members)
|
$: shortMembers = createShortList(members)
|
||||||
$: pageAmount = getPageAmount(processedMembers, pageOptions)
|
$: pageAmount = getPageAmount(processedMembers, pageOptions)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import type { Group, Member } from '../../api/types';
|
import type { Group, Member } from '../../api/types';
|
||||||
import type { ListOptions, PageOptions } from './types';
|
import type { ListOptions, PageOptions } from './types';
|
||||||
|
|
||||||
export function filterList<T extends Member|Group>(list: T[], options: ListOptions, type?: string): T[] {
|
export function filterList(list: Group[]|Member[], groups: Group[], options: ListOptions, type?: string): Group[]|Member[] {
|
||||||
let searchedList = search(list, options);
|
let searchedList = search(list, options);
|
||||||
let groupedList = [...searchedList];
|
let groupedList = [...searchedList];
|
||||||
if (type)
|
if (type)
|
||||||
groupedList = group(searchedList, options, type);
|
groupedList = group(searchedList, groups, options, type);
|
||||||
let filteredList = filter(groupedList, options);
|
let filteredList = filter(groupedList, options);
|
||||||
let sortedList = sort(filteredList, options);
|
let sortedList = sort(filteredList, options);
|
||||||
let orderedList = reorder(sortedList, options);
|
let orderedList = reorder(sortedList, options);
|
||||||
@ -143,8 +143,29 @@ function sort<T extends Member|Group>(list: T[], options: ListOptions): T[] {
|
|||||||
return newList;
|
return newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
function group<T extends Member|Group>(list: T[], options: ListOptions, type?: string): T[] {
|
function group<T extends Member|Group>(members: Member[], groups: Group[], options: ListOptions, type?: string): Group[]|Member[] {
|
||||||
let groupIncludedList = [...list];
|
let list = type === "member" ? [...members] : [...groups] || []
|
||||||
|
let groupFilterList = [...list]
|
||||||
|
|
||||||
|
if (options.groups.filter === "include")
|
||||||
|
if (type === "member") {
|
||||||
|
groupFilterList = [...list].filter(m =>
|
||||||
|
groups.some(g => (g as Group).members.includes(m.uuid))
|
||||||
|
);
|
||||||
|
} else if (type === "group") {
|
||||||
|
groupFilterList = [...list].filter((g: Group) => g.members && g.members.length > 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.groups.filter === "exclude")
|
||||||
|
if (type === "member") {
|
||||||
|
groupFilterList = [...list].filter(m =>
|
||||||
|
!groups.some(g => (g as Group).members.includes(m.uuid))
|
||||||
|
);
|
||||||
|
} else if (type === "group") {
|
||||||
|
groupFilterList = [...list].filter((g: Group) => !g.members || g.members.length < 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
let groupIncludedList = [...groupFilterList];
|
||||||
|
|
||||||
if (options.groups.include.list.length > 0) {
|
if (options.groups.include.list.length > 0) {
|
||||||
// include has items! check the type and whether to match exactly
|
// include has items! check the type and whether to match exactly
|
||||||
|
@ -31,7 +31,7 @@ export interface ListOptions {
|
|||||||
exact: boolean, // only exclude members who are in ALL groups
|
exact: boolean, // only exclude members who are in ALL groups
|
||||||
list: []
|
list: []
|
||||||
},
|
},
|
||||||
none: boolean
|
filter: "all"|"include"|"exclude",
|
||||||
},
|
},
|
||||||
// filter members based on whether fields have a value set or not
|
// filter members based on whether fields have a value set or not
|
||||||
// if set to true: only include items with a value
|
// if set to true: only include items with a value
|
||||||
@ -87,7 +87,7 @@ export interface List<T extends Member|Group> {
|
|||||||
export const defaultListOptions: ListOptions = {
|
export const defaultListOptions: ListOptions = {
|
||||||
search: {},
|
search: {},
|
||||||
groups: {
|
groups: {
|
||||||
none: false,
|
filter: "all",
|
||||||
include: {
|
include: {
|
||||||
exact: false,
|
exact: false,
|
||||||
list: []
|
list: []
|
||||||
|
Loading…
Reference in New Issue
Block a user