tweak(dashboard): make excluding fields take priority over including
This commit is contained in:
parent
a189d740ab
commit
2a5cadff13
@ -117,6 +117,7 @@ function resetPage() {
|
||||
<option value="id">ID</option>
|
||||
{#if pageOptions.type === 'member'}
|
||||
<option value="pronouns">Pronouns</option>
|
||||
<option value="birthday">Birthday</option>
|
||||
{/if}
|
||||
<option value="none">API response order</option>
|
||||
</Input>
|
||||
@ -253,7 +254,7 @@ function resetPage() {
|
||||
<div class="icon d-inline-block" id={`${pageOptions.type}-groups-help`}>
|
||||
<FaQuestionCircle />
|
||||
</div>
|
||||
<Tooltip target={`${pageOptions.type}-groups-help`} placement="left" >Augh</Tooltip>
|
||||
<Tooltip target={`${pageOptions.type}-groups-help`} placement="left" >You can select what groups/members to <b>include and exclude</b> here. Exact? means only items with <b>all</b> selected members/groups will be included. Excluded items take priority over included</Tooltip>
|
||||
</CardTitle>
|
||||
<Row>
|
||||
<p><b>Include</b> {pageOptions.type === 'group' ? "groups with the following members" : "members in the following groups"}</p>
|
||||
@ -299,7 +300,7 @@ function resetPage() {
|
||||
<div class="icon d-inline-block" id={`${pageOptions.type}-filters-help`}>
|
||||
<FaQuestionCircle />
|
||||
</div>
|
||||
<Tooltip target={`${pageOptions.type}-filters-help`} placement="left" >I am so tired</Tooltip>
|
||||
<Tooltip target={`${pageOptions.type}-filters-help`} placement="left" >You can filter out items based on whether a certain field has been filled out or not here.</Tooltip>
|
||||
</CardTitle>
|
||||
<Row class="mt-3">
|
||||
<Col xs={12} md={6} lg={4} class="mb-2">
|
||||
|
@ -1,5 +1,6 @@
|
||||
import type { Group, Member } from '../../api/types';
|
||||
import type { ListOptions, PageOptions } from './types';
|
||||
import moment from 'moment';
|
||||
|
||||
export function filterList<T extends Member|Group>(list: T[], options: ListOptions, type?: string): T[] {
|
||||
let searchedList = search(list, options);
|
||||
@ -52,17 +53,23 @@ function filter<T extends Member|Group>(list: T[], options: ListOptions): T[] {
|
||||
Object.keys(options.filter).forEach(x => {
|
||||
if (options.filter[x] === 'include') {
|
||||
newList = [...list].filter(item => item[x] && true);
|
||||
} else if (options.filter[x] === 'exclude') {
|
||||
newList = [...list].filter(item => !item[x] && true)
|
||||
}
|
||||
});
|
||||
|
||||
let anotherList = [...newList];
|
||||
let newList2 = [...newList]
|
||||
|
||||
Object.keys(options.filter).forEach(x => {
|
||||
if (options.filter[x] === 'exclude') {
|
||||
newList2 = [...newList].filter(item => !item[x] && true)
|
||||
}
|
||||
});
|
||||
|
||||
let anotherList = [...newList2];
|
||||
|
||||
if (options.show === 'private') {
|
||||
anotherList = [...newList].filter(item => item.privacy && item.privacy.visibility === 'private');
|
||||
anotherList = [...newList2].filter(item => item.privacy && item.privacy.visibility === 'private');
|
||||
} else if (options.show === 'public') {
|
||||
anotherList = [...newList].filter(item => item.privacy && item.privacy.visibility === 'public');
|
||||
anotherList = [...newList2].filter(item => item.privacy && item.privacy.visibility === 'public');
|
||||
}
|
||||
|
||||
return anotherList;
|
||||
@ -88,6 +95,30 @@ function sort<T extends Member|Group>(list: T[], options: ListOptions): T[] {
|
||||
if (bb === null) return -1;
|
||||
return aa.localeCompare(bb);
|
||||
});
|
||||
} else if (options.sort === 'birthday') {
|
||||
newList = [...list].sort((a, b) => {
|
||||
let aa = (a as Member).birthday;
|
||||
let bb = (b as Member).birthday;
|
||||
|
||||
if (aa === null) {
|
||||
return 1;
|
||||
}
|
||||
if (bb === null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
let aBirthday = moment(aa.slice(5, aa.length), "MM-DD", true);
|
||||
let bBirthday = moment(bb.slice(5, bb.length), "MM-DD", true);
|
||||
if (aBirthday.isBefore(bBirthday)) {
|
||||
return -1;
|
||||
}
|
||||
if (aBirthday.isAfter(bBirthday)) {
|
||||
return 1;
|
||||
}
|
||||
if (aBirthday === bBirthday) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user