From 8b69ab5ddd15b12d62847a1c1ac9a9111b5d6154 Mon Sep 17 00:00:00 2001 From: Remi PLANEL <rplanel@pasteur.fr> Date: Mon, 18 Sep 2023 18:26:42 +0200 Subject: [PATCH] WIP: automatic list --- components/content/ListSystems.vue | 21 +++++++------- content/2.defense-systems/abi2.md | 2 ++ pages/defense-systems.vue | 44 ++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/components/content/ListSystems.vue b/components/content/ListSystems.vue index 6c5efb7a..94628e9d 100644 --- a/components/content/ListSystems.vue +++ b/components/content/ListSystems.vue @@ -1,16 +1,17 @@ <script setup lang="ts"> - const props = defineProps<{ - systems: any; + headers: Array<Object> + systems: Array<Object> + }>(); const itemsPerParge = ref(25) const search = ref('') const sortBy = ref([{ key: 'system', order: 'asc' }]) -const headers = ref([{ - title: "Systems", - key: "system" -}, { title: "Articles", key: "dois" } -]) +// const headers = ref([{ +// title: "Systems", +// key: "system" +// }, { title: "Articles", key: "doi" } +// ]) </script> <template> @@ -21,14 +22,14 @@ const headers = ref([{ <v-text-field v-model="search" density="compact" variant="underlined" append-inner-icon="mdi-magnify" label="Search" single-line hide-details class="mx-2"></v-text-field> </v-toolbar> - <v-data-table :items-per-page="itemsPerParge" v-model:sort-by="sortBy" :headers="headers" :items="props.systems" + <v-data-table :items-per-page="itemsPerParge" v-model:sort-by="sortBy" :headers="props.headers" :items="props.systems" :search="search"> <template #[`item.system`]="{ item }"> <v-chip variant="text" link :to="`/defense-systems/${item.columns.system.toLowerCase()}`">{{ item.columns.system }}</v-chip> </template> - <template #[`item.dois`]="{ item }"> - <ArticleDoiList :items="item.columns.dois" :divider="false" /> + <template #[`item.doi`]="{ item }"> + <ArticleDoiList v-if="item.columns?.doi" :items="[item.columns.doi]" :divider="false" /> </template> </v-data-table> </v-card> diff --git a/content/2.defense-systems/abi2.md b/content/2.defense-systems/abi2.md index ca92286d..7bd6e7b4 100644 --- a/content/2.defense-systems/abi2.md +++ b/content/2.defense-systems/abi2.md @@ -1,5 +1,7 @@ --- title: Abi2 +tableDescription: + doi: 10.1016/j.mib.2005.06.006 --- The Abi2 system is composed of one protein: Abi_2. diff --git a/pages/defense-systems.vue b/pages/defense-systems.vue index 81535462..b744ef92 100644 --- a/pages/defense-systems.vue +++ b/pages/defense-systems.vue @@ -1,18 +1,44 @@ <script setup lang="ts"> const { data, error, pending } = await useAsyncData('list-defense-systems', () => queryContent('/defense-systems').find()) -const defaultHeaders = ref([{ title: 'System', key: "title" }]) -console.log(data.value) +const defaultHeaders = ref([{ title: 'System', key: "system" }]) const tableDescriptionKey = ref("tableDescription") -const headers = data.value ? ref(Array.from(data.value.reduce((headerSet, df) => { - if (df?.[tableDescriptionKey.value]) { - return new Set([...headerSet, ...Object.keys(df[tableDescriptionKey.value])]) +const headers = computed(() => { + if (data?.value && data.value?.length > 0) { + const uniqHeaders = Array.from(data.value.reduce((headerSet, df) => { + if (df?.[tableDescriptionKey.value]) { + return new Set([...headerSet, ...Object.keys(df[tableDescriptionKey.value])]) + } + else { return headerSet } + }, new Set())) + return [...defaultHeaders.value, ...uniqHeaders.map(value => { return { title: value, key: value } })] } - else { return headerSet } -}, new Set())).map(value => { return { title: value, key: value } }) + else { + return [] + } +}) +const systems = computed(() => { + if (data?.value && data.value?.length > 0) { + return data.value.map(({ title, tableDescription }) => { + return { + system: title, + ...tableDescription + } + }) + } else { + return [] + } + +}) + -) : defaultHeaders console.log(headers.value) +console.log(systems.value) </script> <template> - <v-card :loading="pending"></v-card> + <v-card> + <v-card-title>List systems</v-card-title> + <v-card-text> + <ListSystems :headers=headers :systems="systems"></ListSystems> + </v-card-text> + </v-card> </template> \ No newline at end of file -- GitLab