Add hide-archived default filter based on app toggle

This commit is contained in:
rijkvanzanten
2020-09-02 13:27:34 -04:00
parent 0e886f4db0
commit 1b71dd294e
4 changed files with 29 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import { usePresetsStore, useUserStore } from '@/stores';
import { ref, Ref, computed, watch } from '@vue/composition-api';
import { debounce } from 'lodash';
import { useCollection } from '@/composables/use-collection';
import { Filter, Preset } from '@/types/';
@@ -8,6 +9,8 @@ export function usePreset(collection: Ref<string>, bookmark: Ref<number | null>
const presetsStore = usePresetsStore();
const userStore = useUserStore();
const { info: collectionInfo } = useCollection(collection);
const bookmarkExists = computed(() => {
if (!bookmark.value) return false;
@@ -156,11 +159,28 @@ export function usePreset(collection: Ref<string>, bookmark: Ref<number | null>
};
}
if (!localPreset.value.view_type)
if (!localPreset.value.view_type) {
localPreset.value = {
...localPreset.value,
view_type: 'tabular',
};
}
if (collectionInfo.value?.meta?.archive_field && collectionInfo.value?.meta?.archive_app_filter === true) {
localPreset.value = {
...localPreset.value,
filters: [
...(localPreset.value.filters || []),
{
key: 'hide-archived',
field: collectionInfo.value.meta.archive_field,
operator: 'neq',
value: collectionInfo.value.meta.archive_value!,
locked: true,
},
],
};
}
}
/**

View File

@@ -24,10 +24,6 @@ function unbind(element: HTMLElement) {
delete handlers[element.dataset.tooltip as string];
}
function update(element: HTMLElement, binding: DirectiveBinding) {
console.log(element);
}
const Tooltip: DirectiveOptions = {
bind,
unbind,

View File

@@ -18,6 +18,7 @@ export interface CollectionRaw {
archive_field: string | null;
archive_value: string | null;
unarchive_value: string | null;
archive_app_filter: boolean;
} | null;
schema: Record<string, any>;
}

View File

@@ -34,9 +34,11 @@
</v-list>
</v-menu>
<v-divider />
<template v-if="showArchiveToggle">
<v-divider />
<v-checkbox v-model="archived" :label="$t('show_archived_items')" />
<v-checkbox v-model="archived" :label="$t('show_archived_items')" />
</template>
</drawer-detail>
</template>
@@ -147,7 +149,9 @@ export default defineComponent({
},
});
const showArchiveToggle = computed(() => !!collectionInfo.value?.meta?.archive_field);
const showArchiveToggle = computed(
() => !!collectionInfo.value?.meta?.archive_field && !!collectionInfo.value?.meta?.archive_app_filter
);
const archived = computed({
get() {