From 2a5cadff1346d6b6e8df79c951acf4362421bd85 Mon Sep 17 00:00:00 2001 From: Jake Fulmine Date: Sun, 27 Nov 2022 20:50:31 +0100 Subject: [PATCH] tweak(dashboard): make excluding fields take priority over including --- .../src/components/list/ListControl.svelte | 5 ++- dashboard/src/components/list/functions.ts | 41 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/dashboard/src/components/list/ListControl.svelte b/dashboard/src/components/list/ListControl.svelte index bb1f7780..d1577e19 100644 --- a/dashboard/src/components/list/ListControl.svelte +++ b/dashboard/src/components/list/ListControl.svelte @@ -117,6 +117,7 @@ function resetPage() { {#if pageOptions.type === 'member'} + {/if} @@ -253,7 +254,7 @@ function resetPage() {
- Augh + You can select what groups/members to include and exclude here. Exact? means only items with all selected members/groups will be included. Excluded items take priority over included

Include {pageOptions.type === 'group' ? "groups with the following members" : "members in the following groups"}

@@ -299,7 +300,7 @@ function resetPage() {
- I am so tired + You can filter out items based on whether a certain field has been filled out or not here. diff --git a/dashboard/src/components/list/functions.ts b/dashboard/src/components/list/functions.ts index db14a2e4..bdc01559 100644 --- a/dashboard/src/components/list/functions.ts +++ b/dashboard/src/components/list/functions.ts @@ -1,5 +1,6 @@ import type { Group, Member } from '../../api/types'; import type { ListOptions, PageOptions } from './types'; +import moment from 'moment'; export function filterList(list: T[], options: ListOptions, type?: string): T[] { let searchedList = search(list, options); @@ -52,17 +53,23 @@ function filter(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(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; }