From e99562b8fd87f97835c48b20cc185458470ae7fb Mon Sep 17 00:00:00 2001 From: Jesse Khorasanee Date: Tue, 4 Jun 2024 14:53:14 +1200 Subject: [PATCH 1/7] Add aloglia call to return anatomy curations for each dataset --- src/algolia/algolia.js | 23 +++++++++++++++++++++++ src/components/SidebarContent.vue | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/src/algolia/algolia.js b/src/algolia/algolia.js index c50c4157..6de54e6f 100644 --- a/src/algolia/algolia.js +++ b/src/algolia/algolia.js @@ -148,6 +148,29 @@ export class AlgoliaClient { return ub.replace('_', ':') } + getAnatomyForDatasets(filter, query = '',){ + return new Promise(resolve => { + this.index + .search(query, { + facets: ['*'], + filters: filter, + attributesToRetrieve: [ + 'objectID', + 'anatomy.organ.curie', + ], + hitsPerPage: 999999, + }) + .then(response => { + // The line below restructures the response to be an array of objects with the dataset id and the curie + let curieForDatsets = response.hits.map(h=>({ + id: h.objectID, + curie: h.anatomy? h.anatomy.organ.map(o=>o.curie) : [] + })) + resolve(curieForDatsets) + }) + }) + } + /** * Get Search results * This is using fetch from the Algolia API diff --git a/src/components/SidebarContent.vue b/src/components/SidebarContent.vue index 455b7fba..8507f71c 100644 --- a/src/components/SidebarContent.vue +++ b/src/components/SidebarContent.vue @@ -248,7 +248,12 @@ export default { }, searchAlgolia(filters, query = '') { // Algolia search + this.loadingCards = true + this.algoliaClient.getAnatomyForDatasets(getFilters(filters), query) + .then((datasets) => { + EventBus.emit('organs-in-datasets', datasets) + }) this.algoliaClient .anatomyInSearch(getFilters(filters), query) .then((anatomy) => { From 6fe3474f6e9fd7f1d880bb31573c1bec3fa7af78 Mon Sep 17 00:00:00 2001 From: Jesse Khorasanee Date: Tue, 4 Jun 2024 14:59:58 +1200 Subject: [PATCH 2/7] Add missing emit for the eventbus --- package.json | 2 +- src/components/SideBar.vue | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bc8305c7..801bda7f 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", "files": [ "dist/*", "src/*", diff --git a/src/components/SideBar.vue b/src/components/SideBar.vue index 87f223db..ffe1e366 100644 --- a/src/components/SideBar.vue +++ b/src/components/SideBar.vue @@ -211,12 +211,21 @@ export default { value: payLoad, }) }) - EventBus.on('contextUpdate', (payLoad) => { - /** + EventBus.on('organs-in-datasets', (payLoad) => { + /** * This event is emitted when the context is updated. * Example, context update on first load. * @arg payload */ + this.$emit('organs-in-datasets', payLoad) + }) + + EventBus.on('contextUpdate', (payLoad) => { + /** + * This event is emitted when the context card is updated. + * Example, context card update on first load. + * @arg payload + */ this.$emit('contextUpdate', payLoad) }) EventBus.on('datalink-clicked', (payLoad) => { From 59284d88c2b9ffd5d9e432d8cac7a0f89c78287c Mon Sep 17 00:00:00 2001 From: Jesse Khorasanee Date: Tue, 4 Jun 2024 16:35:16 +1200 Subject: [PATCH 3/7] switch version to alpha --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 801bda7f..f5594743 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@abi-software/map-side-bar", - "version": "2.2.1", + "version": "2.2.1.alpha.1", "files": [ "dist/*", "src/*", From 2faedc53efa1a86dbe7747e69a395f0a1c14ffde Mon Sep 17 00:00:00 2001 From: Jesse Khorasanee Date: Tue, 4 Jun 2024 16:51:43 +1200 Subject: [PATCH 4/7] Fix dict key --- src/algolia/algolia.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algolia/algolia.js b/src/algolia/algolia.js index 6de54e6f..c889be0b 100644 --- a/src/algolia/algolia.js +++ b/src/algolia/algolia.js @@ -164,7 +164,7 @@ export class AlgoliaClient { // The line below restructures the response to be an array of objects with the dataset id and the curie let curieForDatsets = response.hits.map(h=>({ id: h.objectID, - curie: h.anatomy? h.anatomy.organ.map(o=>o.curie) : [] + terms: h.anatomy? h.anatomy.organ.map(o=>o.curie) : [] })) resolve(curieForDatsets) }) From 9a9b9d97115e76211ea11dbd6c1f70ef4ec06138 Mon Sep 17 00:00:00 2001 From: Jesse Khorasanee Date: Thu, 6 Jun 2024 14:24:34 +1200 Subject: [PATCH 5/7] rename emit --- src/components/SideBar.vue | 4 ++-- src/components/SidebarContent.vue | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/SideBar.vue b/src/components/SideBar.vue index ffe1e366..90ec8e7e 100644 --- a/src/components/SideBar.vue +++ b/src/components/SideBar.vue @@ -211,13 +211,13 @@ export default { value: payLoad, }) }) - EventBus.on('organs-in-datasets', (payLoad) => { + EventBus.on('anatomy-in-datasets', (payLoad) => { /** * This event is emitted when the context is updated. * Example, context update on first load. * @arg payload */ - this.$emit('organs-in-datasets', payLoad) + this.$emit('anatomy-in-datasets', payLoad) }) EventBus.on('contextUpdate', (payLoad) => { diff --git a/src/components/SidebarContent.vue b/src/components/SidebarContent.vue index 8507f71c..8b49b953 100644 --- a/src/components/SidebarContent.vue +++ b/src/components/SidebarContent.vue @@ -252,7 +252,7 @@ export default { this.loadingCards = true this.algoliaClient.getAnatomyForDatasets(getFilters(filters), query) .then((datasets) => { - EventBus.emit('organs-in-datasets', datasets) + EventBus.emit('anatomy-in-datasets', datasets) }) this.algoliaClient .anatomyInSearch(getFilters(filters), query) From 648d149e8487a7bc93a67daedd3c490df919d1d9 Mon Sep 17 00:00:00 2001 From: Jesse Khorasanee Date: Tue, 11 Jun 2024 16:03:22 +1200 Subject: [PATCH 6/7] Add new processing to anatomy to scaffold like we do to flatmap --- package.json | 2 +- src/algolia/algolia.js | 58 ++++++++++++++++++------------- src/components/SideBar.vue | 14 ++++---- src/components/SidebarContent.vue | 13 +++---- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index f5594743..5873329c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@abi-software/map-side-bar", - "version": "2.2.1.alpha.1", + "version": "2.2.1-alpha-2", "files": [ "dist/*", "src/*", diff --git a/src/algolia/algolia.js b/src/algolia/algolia.js index c889be0b..3293f2d5 100644 --- a/src/algolia/algolia.js +++ b/src/algolia/algolia.js @@ -148,29 +148,6 @@ export class AlgoliaClient { return ub.replace('_', ':') } - getAnatomyForDatasets(filter, query = '',){ - return new Promise(resolve => { - this.index - .search(query, { - facets: ['*'], - filters: filter, - attributesToRetrieve: [ - 'objectID', - 'anatomy.organ.curie', - ], - hitsPerPage: 999999, - }) - .then(response => { - // The line below restructures the response to be an array of objects with the dataset id and the curie - let curieForDatsets = response.hits.map(h=>({ - id: h.objectID, - terms: h.anatomy? h.anatomy.organ.map(o=>o.curie) : [] - })) - resolve(curieForDatsets) - }) - }) - } - /** * Get Search results * This is using fetch from the Algolia API @@ -220,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({ + forFlamap: 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 90ec8e7e..e889b51c 100644 --- a/src/components/SideBar.vue +++ b/src/components/SideBar.vue @@ -205,16 +205,16 @@ 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 event is emitted when the context is updated. - * Example, context update on first load. + * 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) diff --git a/src/components/SidebarContent.vue b/src/components/SidebarContent.vue index 8b49b953..b5ec479f 100644 --- a/src/components/SidebarContent.vue +++ b/src/components/SidebarContent.vue @@ -250,17 +250,12 @@ export default { // Algolia search this.loadingCards = true - this.algoliaClient.getAnatomyForDatasets(getFilters(filters), query) - .then((datasets) => { - EventBus.emit('anatomy-in-datasets', datasets) - }) 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) From f070712901646b02c9b240811f2c5b17ec3765f4 Mon Sep 17 00:00:00 2001 From: Jesse Khorasanee Date: Tue, 11 Jun 2024 16:49:46 +1200 Subject: [PATCH 7/7] fix typo --- package.json | 2 +- src/algolia/algolia.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5873329c..1e426882 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@abi-software/map-side-bar", - "version": "2.2.1-alpha-2", + "version": "2.2.1-alpha-3", "files": [ "dist/*", "src/*", diff --git a/src/algolia/algolia.js b/src/algolia/algolia.js index 3293f2d5..7fa6e5b3 100644 --- a/src/algolia/algolia.js +++ b/src/algolia/algolia.js @@ -208,7 +208,7 @@ export class AlgoliaClient { // let anatomyAsUberons = this._processAnatomy(response.hits) resolve({ - forFlamap: this.processResultsForFlatmap(response.hits), + forFlatmap: this.processResultsForFlatmap(response.hits), forScaffold: this.processResultsForScaffold(response.hits) }) })