diff --git a/package.json b/package.json index bc8305c7..1e426882 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@abi-software/map-side-bar", - "version": "2.2.0", + "version": "2.2.1-alpha-3", "files": [ "dist/*", "src/*", diff --git a/src/algolia/algolia.js b/src/algolia/algolia.js index c50c4157..7fa6e5b3 100644 --- a/src/algolia/algolia.js +++ b/src/algolia/algolia.js @@ -197,15 +197,46 @@ export class AlgoliaClient { filters: filter, attributesToHighlight: [], attributesToRetrieve: [ + 'objectID', 'item.keywords.keyword', 'anatomy.organ.name', 'anatomy.organ.curie' ], }) .then(response => { - let anatomyAsUberons = this._processAnatomy(response.hits) - resolve(anatomyAsUberons) + // Saving the line below incase we want to starty using keywords again + // let anatomyAsUberons = this._processAnatomy(response.hits) + + resolve({ + forFlatmap: this.processResultsForFlatmap(response.hits), + forScaffold: this.processResultsForScaffold(response.hits) + }) + }) + }) + } + processResultsForFlatmap(hits) { + let curieForDatsets = hits.map(h=>({ + id: h.objectID, + terms: h.anatomy? h.anatomy.organ.map(o=>o.curie) : [] + })) + return curieForDatsets + } + processResultsForScaffold(hits) { + let numberOfDatasetsForAnatomy = {} + hits.forEach(hit => { + if (hit.anatomy && hit.anatomy.organ ) { + hit.anatomy.organ.forEach(anatomy => { + if (anatomy.name) { + if (numberOfDatasetsForAnatomy[anatomy.name]) { + numberOfDatasetsForAnatomy[anatomy.name]++ + } else { + numberOfDatasetsForAnatomy[anatomy.name] = 1 + } + } }) + } }) + return numberOfDatasetsForAnatomy } + } diff --git a/src/components/SideBar.vue b/src/components/SideBar.vue index 87f223db..e889b51c 100644 --- a/src/components/SideBar.vue +++ b/src/components/SideBar.vue @@ -205,16 +205,25 @@ export default { */ this.$emit('actionClick', payLoad) }) - EventBus.on('available-facets', (payLoad) => { - this.$emit('search-changed', { - type: 'available-facets', - value: payLoad, - }) + EventBus.on('number-of-datasets-for-anatomies', (payLoad) => { + /** + * This emits a object with keys as anatomy and values as number of datasets for that anatomy. + * @arg payload + */ + this.$emit('number-of-datasets-for-anatomies', payLoad) + }) + EventBus.on('anatomy-in-datasets', (payLoad) => { + /** + * This emits a lis of datasets, with the anatomy for each one. Used by flatmap for markers + * @arg payload + */ + this.$emit('anatomy-in-datasets', payLoad) }) + EventBus.on('contextUpdate', (payLoad) => { /** - * This event is emitted when the context is updated. - * Example, context update on first load. + * This event is emitted when the context card is updated. + * Example, context card update on first load. * @arg payload */ this.$emit('contextUpdate', payLoad) diff --git a/src/components/SidebarContent.vue b/src/components/SidebarContent.vue index 455b7fba..b5ec479f 100644 --- a/src/components/SidebarContent.vue +++ b/src/components/SidebarContent.vue @@ -248,14 +248,14 @@ export default { }, searchAlgolia(filters, query = '') { // Algolia search + this.loadingCards = true this.algoliaClient .anatomyInSearch(getFilters(filters), query) - .then((anatomy) => { - EventBus.emit('available-facets', { - uberons: anatomy, - labels: this.algoliaClient.anatomyFacetLabels, - }) + .then((r) => { + // Send result anatomy to the scaffold and flatmap + EventBus.emit('anatomy-in-datasets', r.forFlatmap) + EventBus.emit('number-of-datasets-for-anatomies', r.forScaffold) }) this.algoliaClient .search(getFilters(filters), query, this.numberPerPage, this.page)