Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search result details component #11

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion afrc/src/afrc/Search/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import arches from "arches";

import SimpleSearchFilter from "@/afrc/Search/components/SimpleSearchFilter.vue";
import SearchResultItem from "@/afrc/Search/components/SearchResultItem.vue";
import SearchItemDetails from "@/afrc/Search/components/SearchItemDetails.vue";
import InteractiveMap from "@/afrc/Search/components/InteractiveMap/InteractiveMap.vue";
import { fetchMapData } from "@/afrc/Search/api.ts";
import type { GenericObject } from "@/afrc/Search/types";
Expand All @@ -21,6 +22,7 @@ let query = getQueryObject(null);
let queryString = ref(JSON.stringify(query));
let searchResults = ref([]);
let resultsCount = ref("calculating...");
let resultSelected = ref("");
const showMap = ref(false);
const basemaps: Ref<Basemap[]> = ref([]);
const overlays: Ref<MapLayer[]> = ref([]);
Expand All @@ -31,6 +33,7 @@ const toast = useToast();
const { $gettext } = useGettext();

provide("resultsSelected", resultsSelected);
provide("resultSelected", resultSelected);

watch(queryString, () => {
doQuery();
Expand Down Expand Up @@ -181,7 +184,11 @@ onMounted(async () => {
/>
</div>
</section>

<section
v-if="dataLoaded && resultSelected"
>
<SearchItemDetails :instanceId="resultSelected"/>
</section>
<div
v-if="showMap && dataLoaded"
style="width: 100%; height: 100%"
Expand All @@ -191,6 +198,7 @@ onMounted(async () => {
:overlays="overlays"
:sources="sources"
:include-drawer="false"
:popup-enabled="false"
/>
</div>

Expand Down Expand Up @@ -260,6 +268,7 @@ section.afrc-search-results-panel {
flex-grow: 1;
margin: 15px;
overflow-y: auto;
min-width: 350px;
}
.search-result-list {
display: flex;
Expand Down
5 changes: 5 additions & 0 deletions afrc/src/afrc/Search/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ export const createRequest = (url: string) => {
};
};

export const fetchResourceData = (resourceId: string) => {
const url = `${arches.urls["api_resources"](resourceId)}?format=json&v=beta`
return createRequest(url)();
};

export const fetchSettings = createRequest(arches.urls["api-settings"]);
export const fetchMapData = createRequest(arches.urls["api-map-data"]);
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const props = defineProps<{
basemaps: Basemap[];
sources: MapSource[];
includeDrawer: boolean;
popupEnabled: boolean;
}>();

const map: Ref<Map | null> = ref(null);
Expand Down Expand Up @@ -116,6 +117,7 @@ function updateSelectedDrawnFeature(feature: Feature) {
:overlays="overlays"
:sources="sources"
:is-drawing-enabled="true"
:is-popup-enabled="popupEnabled"
@map-initialized="
(mapInstance) => {
map = mapInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface Props {
isDrawingEnabled?: boolean;
drawnFeatures?: Feature[];
drawnFeaturesBuffer?: Buffer;
isPopupEnabled?: boolean;
}

const props = withDefaults(defineProps<Props>(), {
Expand All @@ -76,6 +77,7 @@ const props = withDefaults(defineProps<Props>(), {
isDrawingEnabled: false,
drawnFeatures: () => [],
drawnFeaturesBuffer: undefined,
isPopupEnabled: false,
});

const {
Expand All @@ -86,9 +88,11 @@ const {
isDrawingEnabled,
drawnFeatures,
drawnFeaturesBuffer,
isPopupEnabled,
} = props;

let resultsSelected = inject("resultsSelected") as Ref<string[]>;
let resultSelected = inject("resultSelected") as Ref<string>;

const emits = defineEmits([
"mapInitialized",
Expand Down Expand Up @@ -143,15 +147,17 @@ watch(
},
);

watch(clickedFeatures, () => {
if (popupInstance.value) {
popupInstance.value.remove();
}
popupInstance.value = new maplibregl.Popup()
.setLngLat(clickedCoordinates.value)
.setDOMContent(popupContainer.value!.$el)
.addTo(map.value!);
});
if (isPopupEnabled) {
watch(clickedFeatures, () => {
if (popupInstance.value) {
popupInstance.value.remove();
}
popupInstance.value = new maplibregl.Popup()
.setLngLat(clickedCoordinates.value)
.setDOMContent(popupContainer.value!.$el)
.addTo(map.value!);
});
}

onMounted(() => {
createMap();
Expand Down Expand Up @@ -386,15 +392,18 @@ function addOverlayToMap(overlay: MapLayer) {
clickedCoordinates.value = [e.lngLat.lng, e.lngLat.lat];
clickedFeatures.value = features;
resultsSelected.value = [];
resultSelected.value = "";
const uniqueResourceIds = new Set(
features.map(
(feature) =>
feature.properties?.resourceinstanceid as string,
),
);
resultsSelected.value = Array.from(uniqueResourceIds);
resultSelected.value = resultsSelected.value[0];
} else {
resultsSelected.value = [];
resultSelected.value = "";
}
};

Expand Down
19 changes: 0 additions & 19 deletions afrc/src/afrc/Search/components/MapView.vue

This file was deleted.

144 changes: 144 additions & 0 deletions afrc/src/afrc/Search/components/SearchItemDetails.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<script setup lang="ts">
import { onMounted, inject, ref, watch } from "vue";
import { fetchResourceData } from "@/afrc/Search/api.ts";
import type { Ref } from "vue";
import Button from "primevue/button";
import Carousel from 'primevue/carousel';

const resultSelected = inject("resultSelected") as Ref<string>;
const resultsSelected = inject("resultsSelected") as Ref<string[]>;

let displayname = ref("")
let displaydescription = ref("")
let images = ref([])



onMounted(async () => {
getData();
});

watch(resultSelected, () => {
getData()
});

async function getData() {
const resp = await fetchResourceData(resultSelected.value);
displayname.value = resp.displayname;
displaydescription.value = resp.displaydescription;
images.value = [
'http://www.minisimmonssurfboards.com/wp-content/uploads/2012/07/mini_simmons_round_tail.jpg',
'https://www.minisimmonssurfboards.com/wp-content/uploads/2013/08/DOC-Mini-Simmons-1.jpg',
'https://www.minisimmonssurfboards.com/wp-content/uploads/2013/06/20130606-222901.jpg',
'https://www.surfboardsbygrantnewby.com/wp-content/uploads/2020/12/Traditional-Mini-Simmons.jpg',
'https://i0.wp.com/www.minisimmonssurfboards.com/wp-content/uploads/2015/11/5_mandala_doubleRainbow_PinotNoir_1024x1024.jpg?resize=600%2C800',
'https://3.bp.blogspot.com/-O0s9gHdDs-c/TW0i1DgLfBI/AAAAAAAAEMc/p3gwEQ9fziE/s1600/mini-simmons.jpg',
];
}

function clearResult() {
resultSelected.value = "";
resultsSelected.value = [];
}

</script>

<template>
<div class="search-item-details">
<div class="title">
<div style='display:flex; flex-direction: column; padding: 3px'>
<div>
{{ displayname || "No name provided" }}
</div>
<div style="font-size: 0.7em; color: steelblue; font-style: italic; font-weight: 400;">
(Room 32, Row 2, Shelf 3)
</div>
</div>
<div>
<Button
label="Close"
severity="secondary"
icon="pi pi-times-circle"
icon-pos="top"
text
size="large"
@click="clearResult()"
/>
</div>
</div>
<div class="description">
{{ displaydescription || "No description provided" }} <span>Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit</span>
</div>
<div class="images">
<Carousel :value="images" :numVisible="2" :numScroll="1" containerClass="flex items-center">
<template #item="image">
<div class="border border-surface-200 dark:border-surface-700 rounded m-2 p-4">
<div class="mb-4">
<div class="relative mx-auto">
<div style="padding: 3px">
<img :src="image.data" height="120px" width="120px" class="w-full rounded" />
</div>
</div>
</div>
</div>
</template>
</Carousel>
</div>
<div class="resource-details">
<div class="value-header">Chemical Information</div>
<div class="value-entry">Chemical (CAS) Number:<span class="resource-details-value">1309-36-0</span></div>
<div class="value-entry">Chemical Formula:<span class="resource-details-value">FeS2</span></div>
<div class="value-entry">Chemical Name:<span class="resource-details-value">Iron Disulfide</span></div>
<div class="value-entry">Common Name:<span class="resource-details-value">Pyrite, Fool's Gold</span></div>
</div>
<div class="resource-details">
<div class="value-header">Aquisition Information</div>
<div class="value-entry">Acquired by:<span class="resource-details-value">Art Kaplan</span></div>
<div class="value-entry">Acquired from:<span class="resource-details-value">Minerals-R-Us</span></div>
<div class="value-entry">Acquired on:<span class="resource-details-value">Feb 18, 2001</span></div>
</div>

</div>
</template>

<style scoped>
.search-item-details {
display: flex;
flex-direction: column;
padding: 5px;
border-right: #ddd solid 1px;
border-left: solid #ddd 1px;
width: 375px;
height: 100%;
background-color: #fff;
}
.title {
display: flex;
font-size: 1.2em;
font-weight: bold;
margin-bottom: 5px;
justify-content: space-between;
border-bottom: #ddd solid 1px;
}
.description {
font-size: 1em;
margin-bottom: 15px;
padding: 10px;
}
.resource-details {
padding: 10px;
}
.value-header {
color: steelblue;
font-size: 1.1em;
font-weight: bold;
}
.value-entry {
font-size: 1.0em;
padding: 0px 3px;
}
.resource-details-value {
color: steelblue;
padding: 0px 3px;
}
</style>
17 changes: 12 additions & 5 deletions afrc/src/afrc/Search/components/SearchResultItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Button from "primevue/button";
import arches from "arches";

const resultsSelected = inject("resultsSelected") as Ref<string[]>;
const resultSelected = inject("resultSelected") as Ref<string>;

const props = defineProps({
searchResult: {
Expand All @@ -15,13 +16,19 @@ const props = defineProps({
},
});

function highlightResult(resourceid: string) {
if (!resultSelected.value) {
resultsSelected.value = [];
resultsSelected.value = [resourceid];
}
}

function selectResult(resourceid: string) {
resultSelected.value = "";
resultSelected.value = resourceid;
resultsSelected.value = [resourceid];
}

function clearResult() {
resultsSelected.value = [];
}
</script>

<template>
Expand All @@ -32,8 +39,7 @@ function clearResult() {
searchResult._source.resourceinstanceid,
),
}"
@mouseenter="selectResult(searchResult._source.resourceinstanceid)"
@mouseleave="clearResult"
@mouseenter="highlightResult(searchResult._source.resourceinstanceid)"
>
<div class="image-placeholder">
<img src="https://picsum.photos/160" />
Expand All @@ -55,6 +61,7 @@ function clearResult() {
severity="secondary"
text
size="large"
@click="selectResult(searchResult._source.resourceinstanceid)"
/>
<Button
label="edit"
Expand Down
Loading