|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ChevronLeftIcon, ChevronRightIcon } from "lucide-vue-next"; |
| 3 | +
|
| 4 | +const t = useTranslations(); |
| 5 | +
|
| 6 | +const { getUnprefixedId } = useIdPrefix(); |
| 7 | +
|
| 8 | +const props = defineProps<{ entity: EntityFeature }>(); |
| 9 | +const route = useRoute(); |
| 10 | +
|
| 11 | +const multipleMovements = useGetLinkedEntitiesRecursive( |
| 12 | + computed(() => { |
| 13 | + return { entityId: Number.parseInt(getUnprefixedId(props.entity["@id"])) }; |
| 14 | + }), |
| 15 | +); |
| 16 | +
|
| 17 | +const movementDetails = computed(() => { |
| 18 | + if (multipleMovements.data.value) { |
| 19 | + return multipleMovements.data.value; |
| 20 | + } else return null; |
| 21 | +}); |
| 22 | +
|
| 23 | +const linkedMovements = computed(() => { |
| 24 | + if (movementDetails.value === null) { |
| 25 | + return null; |
| 26 | + } |
| 27 | +
|
| 28 | + const features = Object.values(movementDetails.value).flatMap((entity) => { |
| 29 | + if (entity && typeof entity === "object" && Array.isArray(entity.features)) { |
| 30 | + return entity.features as Array<EntityFeature>; |
| 31 | + } |
| 32 | + return []; |
| 33 | + }); |
| 34 | +
|
| 35 | + // Now map through the features to get the IDs |
| 36 | + return features.map((movement) => { |
| 37 | + return { |
| 38 | + id: getUnprefixedId(movement["@id"]), |
| 39 | + "@id": movement["@id"], |
| 40 | + title: movement.properties.title, |
| 41 | + systemClass: movement.systemClass, |
| 42 | + }; |
| 43 | + }); |
| 44 | +}); |
| 45 | +
|
| 46 | +const currentFeatureIndex = computed(() => { |
| 47 | + if (linkedMovements.value == null) { |
| 48 | + return -1; |
| 49 | + } |
| 50 | + return linkedMovements.value.findIndex((feature) => { |
| 51 | + return feature["@id"] === props.entity["@id"]; |
| 52 | + }); |
| 53 | +}); |
| 54 | +
|
| 55 | +const previousFeature = computed(() => { |
| 56 | + if (currentFeatureIndex.value <= 0 || linkedMovements.value == null) { |
| 57 | + return null; |
| 58 | + } |
| 59 | + return linkedMovements.value[currentFeatureIndex.value - 1]; |
| 60 | +}); |
| 61 | +
|
| 62 | +const nextFeature = computed(() => { |
| 63 | + if ( |
| 64 | + linkedMovements.value == null || |
| 65 | + currentFeatureIndex.value === linkedMovements.value.length - 1 |
| 66 | + ) { |
| 67 | + return null; |
| 68 | + } |
| 69 | + return linkedMovements.value[currentFeatureIndex.value + 1]; |
| 70 | +}); |
| 71 | +
|
| 72 | +const collapsibleRelations: Array<{ |
| 73 | + relationType: RelationType; |
| 74 | + systemClass?: string; |
| 75 | + title: string; |
| 76 | +}> = [ |
| 77 | + { |
| 78 | + relationType: { |
| 79 | + crmCode: "P46", |
| 80 | + }, |
| 81 | + systemClass: "artifact", |
| 82 | + title: t("Relations.Artifacts"), |
| 83 | + }, |
| 84 | + { |
| 85 | + relationType: { |
| 86 | + crmCode: "P46", |
| 87 | + }, |
| 88 | + systemClass: "human_remains", |
| 89 | + title: t("Relations.HumanRemains"), |
| 90 | + }, |
| 91 | +]; |
| 92 | +
|
| 93 | +const emit = defineEmits({ |
| 94 | + handledRelations(payload: Array<RelationType>) { |
| 95 | + return payload; |
| 96 | + }, |
| 97 | +}); |
| 98 | +
|
| 99 | +const handledRelations: Array<RelationType> = [ |
| 100 | + { |
| 101 | + crmCode: "P46", |
| 102 | + }, |
| 103 | +]; |
| 104 | +
|
| 105 | +onMounted(() => { |
| 106 | + emit("handledRelations", handledRelations); |
| 107 | +}); |
| 108 | +
|
| 109 | +function getPath() { |
| 110 | + if (route.path.includes("visualization")) { |
| 111 | + return "visualization"; |
| 112 | + } |
| 113 | + return ""; |
| 114 | +} |
| 115 | +
|
| 116 | +const currentMode = computed(() => { |
| 117 | + return route.query.mode; |
| 118 | +}); |
| 119 | +</script> |
| 120 | + |
| 121 | +<template> |
| 122 | + <div class="flex justify-between"> |
| 123 | + <NavLink |
| 124 | + v-if="previousFeature" |
| 125 | + :href="{ |
| 126 | + path: `/${getPath()}`, |
| 127 | + query: { mode: currentMode, selection: getUnprefixedId(previousFeature['@id']) }, |
| 128 | + }" |
| 129 | + class="flex items-center underline decoration-dotted transition hover:no-underline focus-visible:no-underline" |
| 130 | + > |
| 131 | + <ChevronLeftIcon class="size-4" /> |
| 132 | + <span>{{ previousFeature.title }}</span> |
| 133 | + <span class="sr-only">{{ t("EntitySidebar.PreviousFeature") }}</span> |
| 134 | + </NavLink> |
| 135 | + <NavLink |
| 136 | + v-if="nextFeature" |
| 137 | + :href="{ |
| 138 | + path: `/${getPath()}`, |
| 139 | + query: { mode: currentMode, selection: getUnprefixedId(nextFeature['@id']) }, |
| 140 | + }" |
| 141 | + class="flex items-center underline decoration-dotted transition hover:no-underline focus-visible:no-underline" |
| 142 | + > |
| 143 | + <span>{{ nextFeature.title }}</span> |
| 144 | + <span class="sr-only">{{ t("EntitySidebar.NextFeature") }}</span> |
| 145 | + <ChevronRightIcon class="size-4" /> |
| 146 | + </NavLink> |
| 147 | + </div> |
| 148 | + <GroupedRelationCollapsible |
| 149 | + v-for="rel in collapsibleRelations" |
| 150 | + :key="rel.relationType.crmCode + rel.relationType.inverse" |
| 151 | + :title="rel.title" |
| 152 | + :relations="entity.relations" |
| 153 | + :system-class="rel.systemClass" |
| 154 | + :relation-type="rel.relationType" |
| 155 | + /> |
| 156 | +</template> |
0 commit comments