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;
|
||||
}
|
||||
|
||||
$: processedGroups = filterList(groups, options, "group")
|
||||
$: processedGroups = filterList(groups, groups, options, "group")
|
||||
$: currentGroups = paginateList(processedGroups, pageOptions)
|
||||
$: shortMembers = createShortList(members)
|
||||
$: pageAmount = getPageAmount(processedGroups, pageOptions)
|
||||
|
@ -403,6 +403,29 @@ function resetPage() {
|
||||
</Input>
|
||||
</InputGroup>
|
||||
</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>
|
||||
{/if}
|
||||
</CardBody>
|
||||
|
@ -52,7 +52,7 @@
|
||||
listLoading = false;
|
||||
}
|
||||
|
||||
$: processedMembers = filterList(members, options, "member")
|
||||
$: processedMembers = filterList(members, groups, options, "member")
|
||||
$: currentMembers = paginateList(processedMembers, pageOptions)
|
||||
$: shortMembers = createShortList(members)
|
||||
$: pageAmount = getPageAmount(processedMembers, pageOptions)
|
||||
|
@ -1,11 +1,11 @@
|
||||
import type { Group, Member } from '../../api/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 groupedList = [...searchedList];
|
||||
if (type)
|
||||
groupedList = group(searchedList, options, type);
|
||||
groupedList = group(searchedList, groups, options, type);
|
||||
let filteredList = filter(groupedList, options);
|
||||
let sortedList = sort(filteredList, options);
|
||||
let orderedList = reorder(sortedList, options);
|
||||
@ -143,8 +143,29 @@ function sort<T extends Member|Group>(list: T[], options: ListOptions): T[] {
|
||||
return newList;
|
||||
}
|
||||
|
||||
function group<T extends Member|Group>(list: T[], options: ListOptions, type?: string): T[] {
|
||||
let groupIncludedList = [...list];
|
||||
function group<T extends Member|Group>(members: Member[], groups: Group[], options: ListOptions, type?: string): Group[]|Member[] {
|
||||
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) {
|
||||
// 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
|
||||
list: []
|
||||
},
|
||||
none: boolean
|
||||
filter: "all"|"include"|"exclude",
|
||||
},
|
||||
// filter members based on whether fields have a value set or not
|
||||
// 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 = {
|
||||
search: {},
|
||||
groups: {
|
||||
none: false,
|
||||
filter: "all",
|
||||
include: {
|
||||
exact: false,
|
||||
list: []
|
||||
|
Loading…
Reference in New Issue
Block a user