Skip to content
Snippets Groups Projects
Commit 12de073e authored by Mathieu Massaviol's avatar Mathieu Massaviol
Browse files

Refactor searchResult and text truncate #29

parent 3c896f9b
No related branches found
No related tags found
1 merge request!75Resolve "Permettre la recherche d'un jeu de données"
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
<h1>{{ index }}</h1> <h1>{{ index }}</h1>
<OcLink v-if="!!item.to" :to="item.to"> <OcLink v-if="!!item.to" :to="item.to">
<span v-if="item.icon" :class="item.icon" class="text-gray-400 text-xs mr-1" /> <span v-if="item.icon" :class="item.icon" class="text-gray-400 text-xs mr-1" />
<span class="text-gray-400 text-xs" :title="item.label">{{ truncateLabel(item.label) }}</span> <span class="text-gray-400 text-xs" :title="item.label">{{ truncateText(item.label) }}</span>
</OcLink> </OcLink>
<span v-else> <span v-else>
<span v-if="item.icon" :class="item.icon" class="text-gray-400 text-xs mr-1" /> <span v-if="item.icon" :class="item.icon" class="text-gray-400 text-xs mr-1" />
<span class="text-gray-400 text-xs" :title="item.label">{{ truncateLabel(item.label) }}</span> <span class="text-gray-400 text-xs" :title="item.label">{{ truncateText(item.label) }}</span>
</span> </span>
</template> </template>
</Breadcrumb> </Breadcrumb>
...@@ -21,7 +21,8 @@ import type { MenuItem } from 'primevue/menuitem' ...@@ -21,7 +21,8 @@ import type { MenuItem } from 'primevue/menuitem'
import type { OcBreadcrumbItem } from '@/declarations' import type { OcBreadcrumbItem } from '@/declarations'
import { iconsDict } from '@/helpers/icons' import { iconsDict } from '@/helpers/icons'
import { computed } from 'vue' import { computed } from 'vue'
import OcLink from '../OcLink.vue' import OcLink from '@/components/OcLink.vue'
import { truncateText } from '@/helpers/text'
const props = defineProps<{ const props = defineProps<{
items: OcBreadcrumbItem[] items: OcBreadcrumbItem[]
...@@ -43,14 +44,6 @@ function ocBreadcrumbItem2menuItem(item: OcBreadcrumbItem): MenuItem { ...@@ -43,14 +44,6 @@ function ocBreadcrumbItem2menuItem(item: OcBreadcrumbItem): MenuItem {
} }
} }
function truncateLabel(label:string, maxSize: number=40){
if (label.length > maxSize){
return label.substring(0,maxSize) + '...'
} else {
return label
}
}
const formattedItems = computed(() => { const formattedItems = computed(() => {
if (props.items.length > 4){ if (props.items.length > 4){
return [ return [
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<div <div
class="rounded-md shadow-md border bg-gray-100" class="rounded-md shadow-md border bg-gray-100"
> >
<div class="px-4 pt-4"> <div class="p-4">
<div id="title" class="font-semibold text-2xl mb-2"> <div id="title" class="font-semibold text-xl mb-3">
<i :class="iconsDict[dcatType] ?? ''" :title="t('resourceType.'+dcatType)" class="fa-lg fa-fw"></i> <i :class="iconsDict[dcatType] ?? ''" :title="t('resourceType.'+dcatType)" class="fa-lg fa-fw"></i>
<OcVisibilityIcon <OcVisibilityIcon
v-if="visibility !== 'public'" v-if="visibility !== 'public'"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
:color="props.community.color" :color="props.community.color"
/> />
<OcLink <OcLink
class="ml-1" class="ml-2"
:to="{ :to="{
name: 'community.resource', name: 'community.resource',
params: { params: {
...@@ -22,26 +22,17 @@ ...@@ -22,26 +22,17 @@
} }
}" }"
> >
{{ title }} {{ translateValue(props.searchResult.title) }}
</OcLink> </OcLink>
</div> </div>
<div id="subtitle" class="text-sm text-gray-600"> <div id="subtitle" class="text-sm text-gray-600 mb-4">
<span>{{ t('search.searchResult.id') + ': ' + props.searchResult.identifier }}</span> <span>{{ t('search.searchResult.id') + ': ' + props.searchResult.identifier }}</span>
<span v-if="props.searchResult.version"> | {{ t('search.searchResult.version') + ': ' + props.searchResult.version }}</span> <span v-if="props.searchResult.version"> | {{ t('search.searchResult.version') + ': ' + props.searchResult.version }}</span>
</div> </div>
<div v-if="creators" id="creators" class="mt-1 mb-1">{{ creators }}</div> <div v-if="creators" id="creators" class="mb-4">{{ creators }}</div>
<div v-if="description" id="description"> <div v-if="props.searchResult.description" id="description">
<p class="font-medium">{{ t('search.searchResult.description') }}</p> <p class="font-medium mb-1">{{ t('search.searchResult.description') }}</p>
<ScrollPanel <p class="text-justify text-sm">{{ truncateText(translateValue(props.searchResult.description), 500) }}</p>
style="width: 100%; max-height: 150px;"
:dt="{
bar: {
background: `black`
}
}"
>
<p class="text-justify text-sm">{{ description }}</p>
</ScrollPanel>
</div> </div>
</div> </div>
<div id="footer" class="pl-4 pr-4 pt-2 pb-2 bg-gray-200 rounded-b-md text-sm flex flex-row gap-2 justify-between"> <div id="footer" class="pl-4 pr-4 pt-2 pb-2 bg-gray-200 rounded-b-md text-sm flex flex-row gap-2 justify-between">
...@@ -104,8 +95,8 @@ import { computed, ref, type PropType } from 'vue' ...@@ -104,8 +95,8 @@ import { computed, ref, type PropType } from 'vue'
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import OcLink from '@/components/OcLink.vue'; import OcLink from '@/components/OcLink.vue';
import { getResourceVisibility } from '@/helpers/resourceVisibility'; import { getResourceVisibility } from '@/helpers/resourceVisibility';
import { truncateText } from '@/helpers/text'
import OcVisibilityIcon from '@/components/OcVisibilityIcon/OcVisibilityIcon.vue'; import OcVisibilityIcon from '@/components/OcVisibilityIcon/OcVisibilityIcon.vue';
import ScrollPanel from 'primevue/scrollpanel';
import Popover from 'primevue/popover'; import Popover from 'primevue/popover';
import Button from 'primevue/button'; import Button from 'primevue/button';
...@@ -127,7 +118,6 @@ const props = defineProps({ ...@@ -127,7 +118,6 @@ const props = defineProps({
} }
}) })
const title = computed(() => translateValue(props.searchResult.title))
const dcatType = getResourceTypeFromAtType(props.searchResult['@type']) const dcatType = getResourceTypeFromAtType(props.searchResult['@type'])
const visibility = getResourceVisibility(props.community, props.searchResult, props.userPrivateGraph) const visibility = getResourceVisibility(props.community, props.searchResult, props.userPrivateGraph)
...@@ -147,14 +137,13 @@ const creatorName = (creator: OcPerson | OcOrganization) => { ...@@ -147,14 +137,13 @@ const creatorName = (creator: OcPerson | OcOrganization) => {
else if (Object.keys(creator).length === 1){ return creator['@id'] } else if (Object.keys(creator).length === 1){ return creator['@id'] }
else if (creator.name){ else if (creator.name){
return translateValue(creator.name) if (typeof creator.name === 'string'){ return creator.name }
else { return translateValue(creator.name) }
} else { } else {
return creator.familyName + ' ' + (creator.firstName ?? creator.givenName ?? '') return creator.familyName + ' ' + (creator.firstName ?? creator.givenName ?? '')
} }
} }
const description = computed(() => translateValue(props.searchResult.description))
const catalogues = props.searchResult.catalog?.length ?? 0 const catalogues = props.searchResult.catalog?.length ?? 0
const datasets = props.searchResult.dataset?.length ?? 0 const datasets = props.searchResult.dataset?.length ?? 0
const distributions = props.searchResult.distribution?.length ?? 0 const distributions = props.searchResult.distribution?.length ?? 0
......
export function truncateText(text: string, maxSize: number = 40) {
if (text.length > maxSize) {
return text.substring(0, maxSize) + ' ...'
} else {
return text
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment