feat(dashboard): add filtering by proxy tags

This commit is contained in:
Jake Fulmine 2023-08-17 12:18:22 +02:00
parent 7c7108bd30
commit 2082f76b87
3 changed files with 35 additions and 9 deletions

View file

@ -349,6 +349,16 @@ function resetPage() {
</InputGroup>
</Col>
{#if pageOptions.type === 'member'}
<Col xs={12} md={6} lg={4} class="mb-2">
<InputGroup>
<InputGroupText>Proxy tags</InputGroupText>
<Input type="select" bind:value={options.filterArray.proxy_tags} on:change={() => resetPage()}>
<option value="all">All</option>
<option value="include">With proxy tags</option>
<option value="exclude">Without proxy tags</option>
</Input>
</InputGroup>
</Col>
<Col xs={12} md={6} lg={4} class="mb-2">
<InputGroup>
<InputGroupText>Avatar</InputGroupText>

View file

@ -50,29 +50,38 @@ function search<T extends Member|Group>(list: T[], options: ListOptions): T[] {
function filter<T extends Member|Group>(list: T[], options: ListOptions): T[] {
let newList = [...list];
Object.keys(options.filter).forEach(x => {
if (options.filter[x] === 'include') {
newList = [...list].filter(item => item[x] && true);
newList = [...newList].filter(item => item[x] && true);
}
});
let newList2 = [...newList]
Object.keys(options.filter).forEach(x => {
if (options.filter[x] === 'exclude') {
newList2 = [...newList].filter(item => !item[x] && true)
newList = [...newList].filter(item => !item[x] && true)
}
});
let anotherList = [...newList2];
Object.keys(options.filterArray).forEach(x => {
if (options.filterArray[x] === 'include') {
newList = [...newList].filter(i => i[x] && i[x].length > 0 ? true : false)
}
})
Object.keys(options.filterArray).forEach(x => {
if (options.filterArray[x] === 'exclude') {
newList = [...newList].filter(i => !i[x] || i[x].length === 0 ? true : false)
}
})
if (options.show === 'private') {
anotherList = [...newList2].filter(item => item.privacy && item.privacy.visibility === 'private');
newList = [...newList].filter(item => item.privacy && item.privacy.visibility === 'private');
} else if (options.show === 'public') {
anotherList = [...newList2].filter(item => item.privacy && item.privacy.visibility === 'public');
newList = [...newList].filter(item => item.privacy && item.privacy.visibility === 'public');
}
return anotherList;
return newList;
}
function sort<T extends Member|Group>(list: T[], options: ListOptions): T[] {

View file

@ -48,6 +48,11 @@ export interface ListOptions {
banner: "all"|"include"|"exclude",
}
// filter members based on whether an array field has any items or not
// used for proxy tags right now
filterArray: {
proxy_tags: "all"|"include"|"exclude",
}
// what it says on the tin
sort: 'name'|'description'|'birthday'|'pronouns'|'display_name'|'id'|'none'|'created' | 'color',
order: "ascending"|"descending",
@ -114,7 +119,9 @@ export const defaultListOptions: ListOptions = {
icon: 'all',
color: 'all',
banner: 'all'
},
filterArray: {
proxy_tags: 'all',
},
sort: 'name',
order: 'ascending',