Skip to content

Commit

Permalink
default search queries and programmatic search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaomiDEV committed Aug 11, 2024
1 parent 8a936ef commit a9fc658
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/lib/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const defaultAppConfig: AppConfig = {
twelveHourClock: false,
},
view: "members",
defaultFilterQueries: {}
defaultFilterQueries: {
members: "@archived:no"
}
};

const defaultAccessibilityConfig: AccessibilityConfig = {
Expand Down
43 changes: 36 additions & 7 deletions src/lib/db/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FrontingEntry, FrontingEntryComplete, toFrontingEntryComplete } from ".
import { parseBoardMessageFilterQuery, parseFrontingHistoryFilterQuery, parseMemberFilterQuery } from "../util/filterQuery";
import dayjs from "dayjs";
import { BoardMessage, BoardMessageComplete, toBoardMessageComplete } from "./entities/boardMessages";
import { appConfig } from "../config";

export function getFilteredMembers(search: Ref<string>, members: ShallowRef<Member[]>){
const _members = shallowRef<Member[]>([]);
Expand All @@ -14,7 +15,13 @@ export function getFilteredMembers(search: Ref<string>, members: ShallowRef<Memb
search,
members,
], async () => {
const parsed = await parseMemberFilterQuery(search.value);
let query: string;
if(!search.value.length)
query = appConfig.defaultFilterQueries.members || "";
else
query = search.value;

const parsed = await parseMemberFilterQuery(query);

_members.value = members.value.filter(x => {

Expand Down Expand Up @@ -63,10 +70,18 @@ export function getFilteredTags(search: Ref<string>, type: Ref<string>, tags: Sh
type,
tags
], async () => {
if(!search.value.length)
let query: string;

if (!search.value.length)
query = appConfig.defaultFilterQueries.tags || "";
else
query = search.value;


if(!query.length)
_tags.value = tags.value.filter(x => x.type === type.value);
else
_tags.value = tags.value.filter(x => x.name.toLowerCase().startsWith(search.value.toLowerCase()) && x.type === type.value);
_tags.value = tags.value.filter(x => x.name.toLowerCase().startsWith(query.toLowerCase()) && x.type === type.value);
}, { immediate: true });

return _tags;
Expand All @@ -80,12 +95,18 @@ export function getFilteredFrontingEntries(search: Ref<string>, frontingEntries:
frontingEntries
], async () => {
const filtered: FrontingEntryComplete[] = [];
let query: string;

if(!search.value.length){
if(!search.value.length)
query = appConfig.defaultFilterQueries.frontingHistory || "";
else
query = search.value;

if(!query.length){
for (const x of frontingEntries.value)
filtered.push(await toFrontingEntryComplete(x))
} else {
const parsed = parseFrontingHistoryFilterQuery(search.value);
const parsed = parseFrontingHistoryFilterQuery(query);

for (const x of frontingEntries.value) {
const complete = await toFrontingEntryComplete(x);
Expand Down Expand Up @@ -164,11 +185,19 @@ export function getFilteredBoardMessages(search: Ref<string>, boardMessages: Sha
], async () => {
const filtered: BoardMessageComplete[] = [];

if (!search.value.length) {
let query: string;

if (!search.value.length)
query = appConfig.defaultFilterQueries.messageBoard || "";
else
query = search.value;


if (!query.length) {
for (const x of boardMessages.value)
filtered.push(await toBoardMessageComplete(x))
} else {
const parsed = parseBoardMessageFilterQuery(search.value);
const parsed = parseBoardMessageFilterQuery(query);

for (const x of boardMessages.value) {
const complete = await toBoardMessageComplete(x);
Expand Down
8 changes: 7 additions & 1 deletion src/modals/MemberEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
</div>

<IonList class="member-actions" v-if="!isEditing">
<IonItem button detail>
<IonItem button detail :router-link="`/options/messageBoard?q=@member:${member.uuid}`" @click="modalController.dismiss()">
<IonIcon :ios="newspaperIOS" :md="newspaperMD" slot="start" aria-hidden="true" />
<IonLabel>{{ $t("members:edit.showBoardEntries") }}</IonLabel>
</IonItem>
Expand Down Expand Up @@ -243,6 +243,12 @@
<p>{{ $t("members:edit.delete.desc") }}</p>
</IonLabel>
</IonItem>

<IonItem v-if="member.uuid">
<IonLabel>
<p>{{ $t("members:edit.memberID", { memberID: member.uuid }) }}</p>
</IonLabel>
</IonItem>
</IonList>

<IonFab slot="fixed" vertical="bottom" horizontal="end">
Expand Down
3 changes: 3 additions & 0 deletions src/router/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ const settings: Array<RouteRecordRaw> = [
path: '/options/frontHistory',
name: 'Front History',
component: () => import("../views/options/FrontHistory.vue"),
props: route => ({ q: route.query.q })
},
{
path: '/options/messageBoard',
name: 'Message Board',
component: () => import("../views/options/MessageBoard.vue"),
props: route => ({ q: route.query.q })
},
{
path: '/options/tagManagement',
name: 'Tag Management',
component: () => import("../views/options/TagManagement.vue"),
props: route => ({ q: route.query.q })
},
{
path: '/options/reminders',
Expand Down
1 change: 1 addition & 0 deletions src/router/tabbedRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const tabbedRoutes: Array<RouteRecordRaw> = [
path: '/members',
name: 'Members',
component: () => import("../views/tabbed/Members.vue"),
props: route => ({ q: route.query.q })
},
{
path: '/journal',
Expand Down
28 changes: 27 additions & 1 deletion src/views/options/AppSettings.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { IonContent, IonHeader, IonList, IonPage, IonLabel, IonListHeader, IonTitle, IonToolbar, IonBackButton, IonItem, IonToggle, IonSegment, IonSelect, IonSelectOption } from '@ionic/vue';
import { IonContent, IonHeader, IonList, IonPage, IonLabel, IonListHeader, IonTitle, IonToolbar, IonBackButton, IonItem, IonToggle, IonSegment, IonSelect, IonSelectOption, IonInput } from '@ionic/vue';
import { inject, ref, watch } from 'vue';
import NotDoneYet from "../../components/NotDoneYet.vue";
Expand Down Expand Up @@ -91,8 +91,34 @@
</IonSelectOption>
</IonSelect>
</IonItem>

<IonItem>
<IonInput fill="outline" labelPlacement="floating" :label="$t('options:appSettings.defaultFilterQueries.members')" v-model="appConfig.defaultFilterQueries.members" />
</IonItem>

<IonItem>
<IonInput fill="outline" labelPlacement="floating" :label="$t('options:appSettings.defaultFilterQueries.journal')" v-model="appConfig.defaultFilterQueries.journal" />
</IonItem>

<IonItem>
<IonInput fill="outline" labelPlacement="floating" :label="$t('options:appSettings.defaultFilterQueries.tags')" v-model="appConfig.defaultFilterQueries.tags" />
</IonItem>

<IonItem>
<IonInput fill="outline" labelPlacement="floating" :label="$t('options:appSettings.defaultFilterQueries.frontingHistory')" v-model="appConfig.defaultFilterQueries.frontingHistory" />
</IonItem>

<IonItem>
<IonInput fill="outline" labelPlacement="floating" :label="$t('options:appSettings.defaultFilterQueries.messageBoard')" v-model="appConfig.defaultFilterQueries.messageBoard" />
</IonItem>
</IonList>

</IonContent>
</IonPage>
</template>

<style scoped>
ion-input {
margin: 16px 0;
}
</style>
7 changes: 6 additions & 1 deletion src/views/options/FrontHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
import { getMembersTable } from '../../lib/db/entities/members';
import { PartialBy } from '../../lib/db/types';
const props = defineProps<{
q?: string
}>();
const isIOS = inject<boolean>("isIOS");
const frontingEntryModal = ref();
const emptyFrontingEntry: PartialBy<FrontingEntryComplete, "uuid" | "member"> = {
isMainFronter: false,
Expand All @@ -41,7 +46,7 @@
const isCalendarView = ref(false);
const date = ref(dayjs().toISOString());
const search = ref("");
const search = ref(props.q || "");
const frontingEntries: ShallowRef<FrontingEntry[]> = shallowRef([]);
const filteredFrontingEntries = getFilteredFrontingEntries(search, frontingEntries);
Expand Down
6 changes: 5 additions & 1 deletion src/views/options/MessageBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import { getMembersTable } from '../../lib/db/entities/members';
import { getFilteredBoardMessages } from '../../lib/db/search';
const props = defineProps<{
q?: string
}>();
const isIOS = inject<boolean>("isIOS");
const twelveHour = appConfig.locale.twelveHourClock;
Expand All @@ -36,7 +40,7 @@
const boardMessageEditModal = ref();
const boardMessages = shallowRef<BoardMessage[]>([]);
const search = ref("");
const search = ref(props.q || "");
const filteredBoardMessages = getFilteredBoardMessages(search, boardMessages);
let handle: WatchStopHandle;
Expand Down
14 changes: 11 additions & 3 deletions src/views/tabbed/Members.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
IonItemSliding,
IonItemOptions,
IonItemOption,
onIonViewWillEnter,
onIonViewWillLeave,
} from '@ionic/vue';
import { inject, onMounted, onUnmounted, Ref, ref, shallowReactive, shallowRef, watch, WatchStopHandle } from 'vue';
import { getFilteredMembers } from '../../lib/db/search';
Expand Down Expand Up @@ -48,9 +50,13 @@
import { from, useObservable } from '@vueuse/rxjs';
import { liveQuery } from 'dexie';
const props = defineProps<{
q?: string
}>();
const isIOS = inject<boolean>("isIOS");
const search = ref("");
const search = ref(props.q || "");
const members = shallowRef<Member[]>([]);
const filteredMembers = getFilteredMembers(search, members);
Expand All @@ -70,7 +76,9 @@
const watchStopHandlers: WatchStopHandle[] = [];
onMounted(() => {
onIonViewWillEnter(() => {
search.value = props.q || "";
watchStopHandlers.push(
watch(
useObservable(from(liveQuery(() => getMembersTable().toArray()))),
Expand All @@ -91,7 +99,7 @@
);
});
onUnmounted(() => {
onIonViewWillLeave(() => {
watchStopHandlers.forEach(x => x());
watchStopHandlers.length = 0;
});
Expand Down
3 changes: 2 additions & 1 deletion translations/en/members.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"delete": {
"title": "Delete member",
"desc": "You won't be able to undo this action!"
}
},
"memberID": "Member ID: {{memberID}}"
}
}
7 changes: 7 additions & 0 deletions translations/en/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
"journal": "Journal",
"dashboard": "Dashboard",
"chat": "Chats"
},
"defaultFilterQueries": {
"members": "Default search query for members",
"journal": "Default search query for journal",
"tags": "Default search query for tags",
"frontingHistory": "Default search query for the fronting history",
"messageBoard": "Default search query for the message board"
}
},
"security": {
Expand Down

0 comments on commit a9fc658

Please sign in to comment.