Skip to content

Commit

Permalink
Merge pull request #131 from SpeciesFileGroup/development
Browse files Browse the repository at this point in the history
Add ProjectStats component
  • Loading branch information
José Luis Pereira authored and GitHub committed Aug 30, 2023
2 parents 9c83db3 + 761ea13 commit bf26acb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ TaxonPages provides a set of global components that could be used to create your
| `<Dropdown/>` | Dropdown menu | |
| `<GalleryImage/>` | | [Link](https://github.com/SpeciesFileGroup/taxonpages/blob/main/src/components/Gallery/GalleryImage.global.vue#L40) |
| `<ImageViewer/>` | | |
| `<ProjectStats/>` | TaxonWorks Project Statistics | |
| `<TabMenu/>` | | |
| `<TabItem/>` | | |
| `<VMap/>` | Interactive map that use Leaflet library | |
Expand Down
66 changes: 66 additions & 0 deletions src/components/ProjectStats.global.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<component :is="tag">
<slot
v-for="([type, value], index) in list"
:type="type"
:value="value"
>
<span>
{{ type }}: {{ value }}{{ index < list.length - 1 ? '; ' : '' }}
</span>
</slot>
</component>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { makeAPIRequest } from '@/utils'
const props = defineProps({
data: {
type: Array,
default: () => []
},
tag: {
type: String,
default: 'span'
}
})
const stats = ref({ data: [] })
const selectedData = computed(() =>
props.data.map((item) => item.toLowerCase())
)
const list = computed(() => {
const currentStats = stats.value.data
return currentStats.length
? filterStats(currentStats)
: selectedData.value.map((item) => [item, '??'])
})
function filterStats(currentStats) {
const list = props.data.length
? currentStats.filter(([key]) => selectedData.value.includes(key))
: currentStats
list.sort(
([a], [b]) => selectedData.value.indexOf(a) - selectedData.value.indexOf(b)
)
return list
}
onMounted(() => {
makeAPIRequest.get('/stats').then((response) => {
const data = Object.entries(response.data.data).map(([key, value]) => [
key.toLowerCase(),
value.toLocaleString()
])
stats.value.data = data
})
})
</script>
1 change: 0 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './color'
export * from './getMeta'
export * from './request'
export * from './strings'

0 comments on commit bf26acb

Please sign in to comment.