@abi-software/map-side-bar 2.2.0 → 2.2.1-alpha-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +12 -12
- package/.postcssrc.json +5 -5
- package/LICENSE +201 -201
- package/README.md +168 -168
- package/dist/map-side-bar.js +6982 -7170
- package/dist/map-side-bar.umd.cjs +50 -103
- package/dist/style.css +1 -1
- package/package.json +72 -72
- package/src/App.vue +233 -233
- package/src/algolia/algolia.js +242 -211
- package/src/algolia/utils.js +101 -101
- package/src/assets/_variables.scss +43 -43
- package/src/assets/styles.scss +6 -6
- package/src/components/BadgesGroup.vue +124 -124
- package/src/components/DatasetCard.vue +356 -356
- package/src/components/EventBus.js +3 -3
- package/src/components/ImageGallery.vue +542 -542
- package/src/components/SearchFilters.vue +1000 -1000
- package/src/components/SearchHistory.vue +175 -175
- package/src/components/SideBar.vue +347 -338
- package/src/components/SidebarContent.vue +576 -576
- package/src/components/Tabs.vue +78 -78
- package/src/components/index.js +8 -8
- package/src/components/species-map.js +8 -8
- package/src/main.js +9 -9
- package/src/mixins/S3Bucket.vue +37 -37
- package/static.json +6 -6
- package/vite.config.js +55 -55
- package/vuese-generator.js +65 -65
package/src/algolia/algolia.js
CHANGED
|
@@ -1,211 +1,242 @@
|
|
|
1
|
-
/* eslint-disable no-alert, no-console */
|
|
2
|
-
import algoliasearch from 'algoliasearch'
|
|
3
|
-
|
|
4
|
-
// export `createAlgoliaClient` to use it in page components
|
|
5
|
-
export class AlgoliaClient {
|
|
6
|
-
constructor(algoliaId, algoliaKey, PENNSIEVE_API_LOCATION = 'https://api.pennsieve.io') {
|
|
7
|
-
this.client = algoliasearch(
|
|
8
|
-
algoliaId,
|
|
9
|
-
algoliaKey
|
|
10
|
-
)
|
|
11
|
-
this.PENNSIEVE_API_LOCATION = PENNSIEVE_API_LOCATION
|
|
12
|
-
this.anatomyFacetLabels = []
|
|
13
|
-
}
|
|
14
|
-
initIndex(ALGOLIA_INDEX) {
|
|
15
|
-
this.index = this.client.initIndex(ALGOLIA_INDEX);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
getAlgoliaFacets(propPathMapping) {
|
|
19
|
-
const facetPropPaths = propPathMapping.map(facet => facet.facetPropPath)
|
|
20
|
-
const facetSubpropPaths = propPathMapping.map(item => item.facetSubpropPath)
|
|
21
|
-
let facetData = []
|
|
22
|
-
let facetId = 0
|
|
23
|
-
return this.index
|
|
24
|
-
.search('', {
|
|
25
|
-
sortFacetValuesBy: 'alpha',
|
|
26
|
-
facets: facetPropPaths.concat(facetSubpropPaths),
|
|
27
|
-
})
|
|
28
|
-
.then(response => {
|
|
29
|
-
facetPropPaths.map((facetPropPath) => {
|
|
30
|
-
const parentFacet = propPathMapping.find(item => item.facetPropPath == facetPropPath)
|
|
31
|
-
var children = []
|
|
32
|
-
const responseFacets = response.facets
|
|
33
|
-
if (responseFacets === undefined) {return}
|
|
34
|
-
const responseFacetChildren =
|
|
35
|
-
responseFacets[facetPropPath] == undefined // if no facets, return empty object
|
|
36
|
-
? {}
|
|
37
|
-
: responseFacets[facetPropPath]
|
|
38
|
-
const allPossibleChildrenSubfacets = parentFacet && responseFacets[parentFacet.facetSubpropPath] ? Object.keys(responseFacets[parentFacet.facetSubpropPath]) : []
|
|
39
|
-
// Loop through all subfacets and find the ones that are children of the current facet
|
|
40
|
-
Object.keys(responseFacetChildren).map(facet => {
|
|
41
|
-
const childrenSubfacets = allPossibleChildrenSubfacets.reduce((filtered, childFacetInfo) => {
|
|
42
|
-
const info = childFacetInfo.split('.');
|
|
43
|
-
if (info.length !== 2) {
|
|
44
|
-
return filtered;
|
|
45
|
-
}
|
|
46
|
-
if (facet === info[0]) {
|
|
47
|
-
filtered.push({
|
|
48
|
-
label: info[1],
|
|
49
|
-
id: facetId++,
|
|
50
|
-
facetPropPath: `${parentFacet ? parentFacet.facetSubpropPath : undefined}`
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return filtered;
|
|
54
|
-
}, []); // Provide an empty array as the initial value
|
|
55
|
-
let newChild = {
|
|
56
|
-
label: facet,
|
|
57
|
-
id: facetId++,
|
|
58
|
-
facetPropPath: facetPropPath
|
|
59
|
-
}
|
|
60
|
-
if (childrenSubfacets.length > 0) {
|
|
61
|
-
newChild.children = childrenSubfacets
|
|
62
|
-
}
|
|
63
|
-
children.push(newChild)
|
|
64
|
-
})
|
|
65
|
-
if (children.length > 0) {
|
|
66
|
-
facetData.push({
|
|
67
|
-
label: parentFacet ? parentFacet.label : '',
|
|
68
|
-
id: facetId++,
|
|
69
|
-
children: children,
|
|
70
|
-
key: facetPropPath
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
return facetData
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Returns all DOIs of all versions for a given discover dataset
|
|
79
|
-
_discoverAllDois(discoverId, PENNSIEVE_API_LOCATION = 'https://api.pennsieve.io') {
|
|
80
|
-
return new Promise(resolve => {
|
|
81
|
-
fetch(`${PENNSIEVE_API_LOCATION}/discover/datasets/${discoverId}/versions`).then(r => r.json()).then(dataset => {
|
|
82
|
-
resolve(dataset.map(version => version.doi))
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Get all dois given a list of discoverIds
|
|
88
|
-
_expandDois(discoverIds, PENNSIEVE_API_LOCATION = 'https://api.pennsieve.io') {
|
|
89
|
-
return new Promise(resolve => {
|
|
90
|
-
let promiseList = discoverIds.map(discoverId => this._discoverAllDois(discoverId, PENNSIEVE_API_LOCATION))
|
|
91
|
-
Promise.all(promiseList).then((values) => {
|
|
92
|
-
resolve(values.flat())
|
|
93
|
-
});
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_processResultsForCards(results) {
|
|
98
|
-
let newResults = []
|
|
99
|
-
let newResult = {}
|
|
100
|
-
for (let res of results) {
|
|
101
|
-
newResult = { ...res }
|
|
102
|
-
newResult = {
|
|
103
|
-
anatomy: res.anatomy ? res.anatomy.organ.map((organ => organ.curie)) : undefined,
|
|
104
|
-
doi: res.item.curie.split(':')[1],
|
|
105
|
-
name: res.item.name,
|
|
106
|
-
description: res.item.description,
|
|
107
|
-
updated: res.pennsieve ? res.pennsieve.updatedAt : undefined,
|
|
108
|
-
publishDate: res.pennsieve ? res.pennsieve.publishDate : undefined,
|
|
109
|
-
datasetId: res.objectID,
|
|
110
|
-
detailsReady: false
|
|
111
|
-
}
|
|
112
|
-
newResults.push(newResult)
|
|
113
|
-
}
|
|
114
|
-
return newResults
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
_processAnatomy(hits) {
|
|
118
|
-
let foundKeyWords = []
|
|
119
|
-
let foundLabels = []
|
|
120
|
-
let uniqueLabels = []
|
|
121
|
-
let uniqueKeywords = []
|
|
122
|
-
hits.forEach(hit => {
|
|
123
|
-
if (hit.item && hit.item.keywords) {
|
|
124
|
-
hit.item.keywords.forEach(keywordObj => {
|
|
125
|
-
let keyword = keywordObj.keyword.toUpperCase()
|
|
126
|
-
if (keyword.includes('UBERON') || keyword.includes('ILX')) {
|
|
127
|
-
foundKeyWords.push(this._processUberonURL(keyword))
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
if (hit.anatomy && hit.anatomy.organ ) {
|
|
132
|
-
hit.anatomy.organ.forEach(anatomy => {
|
|
133
|
-
if (anatomy.curie) {
|
|
134
|
-
foundKeyWords.push(anatomy.curie)
|
|
135
|
-
foundLabels.push(anatomy.name)
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
uniqueKeywords = [...new Set(foundKeyWords) ]
|
|
141
|
-
uniqueLabels = [...new Set(foundLabels) ]
|
|
142
|
-
this.anatomyFacetLabels = uniqueLabels
|
|
143
|
-
return uniqueKeywords
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
_processUberonURL(url) {
|
|
147
|
-
let ub = url.split('/').pop()
|
|
148
|
-
return ub.replace('_', ':')
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Get Search results
|
|
153
|
-
* This is using fetch from the Algolia API
|
|
154
|
-
*/
|
|
155
|
-
search(filter, query = '', hitsperPage = 10, page = 1) {
|
|
156
|
-
return new Promise(resolve => {
|
|
157
|
-
this.index
|
|
158
|
-
.search(query, {
|
|
159
|
-
facets: ['*'],
|
|
160
|
-
hitsPerPage: hitsperPage,
|
|
161
|
-
page: page - 1,
|
|
162
|
-
filters: filter,
|
|
163
|
-
attributesToHighlight: [],
|
|
164
|
-
attributesToRetrieve: [
|
|
165
|
-
'pennsieve.publishDate',
|
|
166
|
-
'pennsieve.updatedAt',
|
|
167
|
-
'item.curie',
|
|
168
|
-
'item.name',
|
|
169
|
-
'item.description',
|
|
170
|
-
'objectID',
|
|
171
|
-
'anatomy.organ.curie'
|
|
172
|
-
],
|
|
173
|
-
})
|
|
174
|
-
.then(response => {
|
|
175
|
-
let searchData = {
|
|
176
|
-
items: this._processResultsForCards(response.hits),
|
|
177
|
-
total: response.nbHits,
|
|
178
|
-
discoverIds: response.hits.map(r => r.pennsieve ? r.pennsieve.identifier : r.objectID),
|
|
179
|
-
dois: response.hits.map(r => r.item.curie.split(':')[1])
|
|
180
|
-
}
|
|
181
|
-
resolve(searchData)
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get key words
|
|
188
|
-
* This is used to return all keywords for a given search. Note that you often want the hits per page to be maxed out
|
|
189
|
-
*/
|
|
190
|
-
anatomyInSearch(filter, query = '', hitsperPage = 999999, page = 1) {
|
|
191
|
-
return new Promise(resolve => {
|
|
192
|
-
this.index
|
|
193
|
-
.search(query, {
|
|
194
|
-
facets: ['*'],
|
|
195
|
-
hitsPerPage: hitsperPage,
|
|
196
|
-
page: page - 1,
|
|
197
|
-
filters: filter,
|
|
198
|
-
attributesToHighlight: [],
|
|
199
|
-
attributesToRetrieve: [
|
|
200
|
-
'
|
|
201
|
-
'
|
|
202
|
-
'anatomy.organ.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
import algoliasearch from 'algoliasearch'
|
|
3
|
+
|
|
4
|
+
// export `createAlgoliaClient` to use it in page components
|
|
5
|
+
export class AlgoliaClient {
|
|
6
|
+
constructor(algoliaId, algoliaKey, PENNSIEVE_API_LOCATION = 'https://api.pennsieve.io') {
|
|
7
|
+
this.client = algoliasearch(
|
|
8
|
+
algoliaId,
|
|
9
|
+
algoliaKey
|
|
10
|
+
)
|
|
11
|
+
this.PENNSIEVE_API_LOCATION = PENNSIEVE_API_LOCATION
|
|
12
|
+
this.anatomyFacetLabels = []
|
|
13
|
+
}
|
|
14
|
+
initIndex(ALGOLIA_INDEX) {
|
|
15
|
+
this.index = this.client.initIndex(ALGOLIA_INDEX);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getAlgoliaFacets(propPathMapping) {
|
|
19
|
+
const facetPropPaths = propPathMapping.map(facet => facet.facetPropPath)
|
|
20
|
+
const facetSubpropPaths = propPathMapping.map(item => item.facetSubpropPath)
|
|
21
|
+
let facetData = []
|
|
22
|
+
let facetId = 0
|
|
23
|
+
return this.index
|
|
24
|
+
.search('', {
|
|
25
|
+
sortFacetValuesBy: 'alpha',
|
|
26
|
+
facets: facetPropPaths.concat(facetSubpropPaths),
|
|
27
|
+
})
|
|
28
|
+
.then(response => {
|
|
29
|
+
facetPropPaths.map((facetPropPath) => {
|
|
30
|
+
const parentFacet = propPathMapping.find(item => item.facetPropPath == facetPropPath)
|
|
31
|
+
var children = []
|
|
32
|
+
const responseFacets = response.facets
|
|
33
|
+
if (responseFacets === undefined) {return}
|
|
34
|
+
const responseFacetChildren =
|
|
35
|
+
responseFacets[facetPropPath] == undefined // if no facets, return empty object
|
|
36
|
+
? {}
|
|
37
|
+
: responseFacets[facetPropPath]
|
|
38
|
+
const allPossibleChildrenSubfacets = parentFacet && responseFacets[parentFacet.facetSubpropPath] ? Object.keys(responseFacets[parentFacet.facetSubpropPath]) : []
|
|
39
|
+
// Loop through all subfacets and find the ones that are children of the current facet
|
|
40
|
+
Object.keys(responseFacetChildren).map(facet => {
|
|
41
|
+
const childrenSubfacets = allPossibleChildrenSubfacets.reduce((filtered, childFacetInfo) => {
|
|
42
|
+
const info = childFacetInfo.split('.');
|
|
43
|
+
if (info.length !== 2) {
|
|
44
|
+
return filtered;
|
|
45
|
+
}
|
|
46
|
+
if (facet === info[0]) {
|
|
47
|
+
filtered.push({
|
|
48
|
+
label: info[1],
|
|
49
|
+
id: facetId++,
|
|
50
|
+
facetPropPath: `${parentFacet ? parentFacet.facetSubpropPath : undefined}`
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return filtered;
|
|
54
|
+
}, []); // Provide an empty array as the initial value
|
|
55
|
+
let newChild = {
|
|
56
|
+
label: facet,
|
|
57
|
+
id: facetId++,
|
|
58
|
+
facetPropPath: facetPropPath
|
|
59
|
+
}
|
|
60
|
+
if (childrenSubfacets.length > 0) {
|
|
61
|
+
newChild.children = childrenSubfacets
|
|
62
|
+
}
|
|
63
|
+
children.push(newChild)
|
|
64
|
+
})
|
|
65
|
+
if (children.length > 0) {
|
|
66
|
+
facetData.push({
|
|
67
|
+
label: parentFacet ? parentFacet.label : '',
|
|
68
|
+
id: facetId++,
|
|
69
|
+
children: children,
|
|
70
|
+
key: facetPropPath
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
return facetData
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Returns all DOIs of all versions for a given discover dataset
|
|
79
|
+
_discoverAllDois(discoverId, PENNSIEVE_API_LOCATION = 'https://api.pennsieve.io') {
|
|
80
|
+
return new Promise(resolve => {
|
|
81
|
+
fetch(`${PENNSIEVE_API_LOCATION}/discover/datasets/${discoverId}/versions`).then(r => r.json()).then(dataset => {
|
|
82
|
+
resolve(dataset.map(version => version.doi))
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Get all dois given a list of discoverIds
|
|
88
|
+
_expandDois(discoverIds, PENNSIEVE_API_LOCATION = 'https://api.pennsieve.io') {
|
|
89
|
+
return new Promise(resolve => {
|
|
90
|
+
let promiseList = discoverIds.map(discoverId => this._discoverAllDois(discoverId, PENNSIEVE_API_LOCATION))
|
|
91
|
+
Promise.all(promiseList).then((values) => {
|
|
92
|
+
resolve(values.flat())
|
|
93
|
+
});
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_processResultsForCards(results) {
|
|
98
|
+
let newResults = []
|
|
99
|
+
let newResult = {}
|
|
100
|
+
for (let res of results) {
|
|
101
|
+
newResult = { ...res }
|
|
102
|
+
newResult = {
|
|
103
|
+
anatomy: res.anatomy ? res.anatomy.organ.map((organ => organ.curie)) : undefined,
|
|
104
|
+
doi: res.item.curie.split(':')[1],
|
|
105
|
+
name: res.item.name,
|
|
106
|
+
description: res.item.description,
|
|
107
|
+
updated: res.pennsieve ? res.pennsieve.updatedAt : undefined,
|
|
108
|
+
publishDate: res.pennsieve ? res.pennsieve.publishDate : undefined,
|
|
109
|
+
datasetId: res.objectID,
|
|
110
|
+
detailsReady: false
|
|
111
|
+
}
|
|
112
|
+
newResults.push(newResult)
|
|
113
|
+
}
|
|
114
|
+
return newResults
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_processAnatomy(hits) {
|
|
118
|
+
let foundKeyWords = []
|
|
119
|
+
let foundLabels = []
|
|
120
|
+
let uniqueLabels = []
|
|
121
|
+
let uniqueKeywords = []
|
|
122
|
+
hits.forEach(hit => {
|
|
123
|
+
if (hit.item && hit.item.keywords) {
|
|
124
|
+
hit.item.keywords.forEach(keywordObj => {
|
|
125
|
+
let keyword = keywordObj.keyword.toUpperCase()
|
|
126
|
+
if (keyword.includes('UBERON') || keyword.includes('ILX')) {
|
|
127
|
+
foundKeyWords.push(this._processUberonURL(keyword))
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
if (hit.anatomy && hit.anatomy.organ ) {
|
|
132
|
+
hit.anatomy.organ.forEach(anatomy => {
|
|
133
|
+
if (anatomy.curie) {
|
|
134
|
+
foundKeyWords.push(anatomy.curie)
|
|
135
|
+
foundLabels.push(anatomy.name)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
uniqueKeywords = [...new Set(foundKeyWords) ]
|
|
141
|
+
uniqueLabels = [...new Set(foundLabels) ]
|
|
142
|
+
this.anatomyFacetLabels = uniqueLabels
|
|
143
|
+
return uniqueKeywords
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_processUberonURL(url) {
|
|
147
|
+
let ub = url.split('/').pop()
|
|
148
|
+
return ub.replace('_', ':')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get Search results
|
|
153
|
+
* This is using fetch from the Algolia API
|
|
154
|
+
*/
|
|
155
|
+
search(filter, query = '', hitsperPage = 10, page = 1) {
|
|
156
|
+
return new Promise(resolve => {
|
|
157
|
+
this.index
|
|
158
|
+
.search(query, {
|
|
159
|
+
facets: ['*'],
|
|
160
|
+
hitsPerPage: hitsperPage,
|
|
161
|
+
page: page - 1,
|
|
162
|
+
filters: filter,
|
|
163
|
+
attributesToHighlight: [],
|
|
164
|
+
attributesToRetrieve: [
|
|
165
|
+
'pennsieve.publishDate',
|
|
166
|
+
'pennsieve.updatedAt',
|
|
167
|
+
'item.curie',
|
|
168
|
+
'item.name',
|
|
169
|
+
'item.description',
|
|
170
|
+
'objectID',
|
|
171
|
+
'anatomy.organ.curie'
|
|
172
|
+
],
|
|
173
|
+
})
|
|
174
|
+
.then(response => {
|
|
175
|
+
let searchData = {
|
|
176
|
+
items: this._processResultsForCards(response.hits),
|
|
177
|
+
total: response.nbHits,
|
|
178
|
+
discoverIds: response.hits.map(r => r.pennsieve ? r.pennsieve.identifier : r.objectID),
|
|
179
|
+
dois: response.hits.map(r => r.item.curie.split(':')[1])
|
|
180
|
+
}
|
|
181
|
+
resolve(searchData)
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get key words
|
|
188
|
+
* This is used to return all keywords for a given search. Note that you often want the hits per page to be maxed out
|
|
189
|
+
*/
|
|
190
|
+
anatomyInSearch(filter, query = '', hitsperPage = 999999, page = 1) {
|
|
191
|
+
return new Promise(resolve => {
|
|
192
|
+
this.index
|
|
193
|
+
.search(query, {
|
|
194
|
+
facets: ['*'],
|
|
195
|
+
hitsPerPage: hitsperPage,
|
|
196
|
+
page: page - 1,
|
|
197
|
+
filters: filter,
|
|
198
|
+
attributesToHighlight: [],
|
|
199
|
+
attributesToRetrieve: [
|
|
200
|
+
'objectID',
|
|
201
|
+
'item.keywords.keyword',
|
|
202
|
+
'anatomy.organ.name',
|
|
203
|
+
'anatomy.organ.curie'
|
|
204
|
+
],
|
|
205
|
+
})
|
|
206
|
+
.then(response => {
|
|
207
|
+
// Saving the line below incase we want to starty using keywords again
|
|
208
|
+
// let anatomyAsUberons = this._processAnatomy(response.hits)
|
|
209
|
+
|
|
210
|
+
resolve({
|
|
211
|
+
forFlamap: this.processResultsForFlatmap(response.hits),
|
|
212
|
+
forScaffold: this.processResultsForScaffold(response.hits)
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
processResultsForFlatmap(hits) {
|
|
218
|
+
let curieForDatsets = hits.map(h=>({
|
|
219
|
+
id: h.objectID,
|
|
220
|
+
terms: h.anatomy? h.anatomy.organ.map(o=>o.curie) : []
|
|
221
|
+
}))
|
|
222
|
+
return curieForDatsets
|
|
223
|
+
}
|
|
224
|
+
processResultsForScaffold(hits) {
|
|
225
|
+
let numberOfDatasetsForAnatomy = {}
|
|
226
|
+
hits.forEach(hit => {
|
|
227
|
+
if (hit.anatomy && hit.anatomy.organ ) {
|
|
228
|
+
hit.anatomy.organ.forEach(anatomy => {
|
|
229
|
+
if (anatomy.name) {
|
|
230
|
+
if (numberOfDatasetsForAnatomy[anatomy.name]) {
|
|
231
|
+
numberOfDatasetsForAnatomy[anatomy.name]++
|
|
232
|
+
} else {
|
|
233
|
+
numberOfDatasetsForAnatomy[anatomy.name] = 1
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
return numberOfDatasetsForAnatomy
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
}
|
package/src/algolia/utils.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
/* eslint-disable no-alert, no-console */
|
|
2
|
-
|
|
3
|
-
// Mapping between display categories and their Algolia index property path
|
|
4
|
-
// Used for populating the Dataset Search Results facet menu dynamically
|
|
5
|
-
export const facetPropPathMapping = [
|
|
6
|
-
{
|
|
7
|
-
label: 'Data Type',
|
|
8
|
-
id: 'item.types',
|
|
9
|
-
facetPropPath: 'item.types.name',
|
|
10
|
-
facetSubpropPath: 'item.types.subcategory.name'
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
label: 'Anatomical Structure',
|
|
14
|
-
id: 'anatomy.organ.category',
|
|
15
|
-
facetPropPath: 'anatomy.organ.category.name',
|
|
16
|
-
facetSubpropPath: 'anatomy.organ.subcategory.name',
|
|
17
|
-
facetFilterPath: 'anatomy.organ.name'
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
label: 'Species',
|
|
21
|
-
id: 'organisms.primary.species',
|
|
22
|
-
facetPropPath: 'organisms.primary.species.name',
|
|
23
|
-
facetSubpropPath: 'organisms.primary.species.subcategory.name'
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
label: 'Experimental Approach',
|
|
27
|
-
id: 'item.modalities',
|
|
28
|
-
facetPropPath: 'item.modalities.keyword',
|
|
29
|
-
facetSubpropPath: 'item.modalities.subcategory.name'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
label: 'Sex',
|
|
33
|
-
id: 'attributes.subject.sex',
|
|
34
|
-
facetPropPath: 'attributes.subject.sex.value',
|
|
35
|
-
facetSubpropPath: 'attributes.subject.sex.subcategory.name'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
label: 'Age Categories',
|
|
39
|
-
id: 'attributes.subject.ageCategory',
|
|
40
|
-
facetPropPath: 'attributes.subject.ageCategory.value',
|
|
41
|
-
facetSubpropPath: 'attributes.subject.ageCategory.subcategory.name'
|
|
42
|
-
},
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
// Same as above, but these show on the sidebar filters
|
|
46
|
-
export const shownFilters = {
|
|
47
|
-
'anatomy.organ.name' : 'Anatomical Structure',
|
|
48
|
-
'organisms.primary.species.name' : 'Species',
|
|
49
|
-
'attributes.subject.sex.value' : 'Sex',
|
|
50
|
-
'attributes.subject.ageCategory.value' : 'Age Categories',
|
|
51
|
-
'item.types.name' : 'Data type',
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/* Returns filter for searching algolia. All facets of the same category are joined with OR,
|
|
55
|
-
* and each of those results is then joined with an AND.
|
|
56
|
-
* i.e. (color:blue OR color:red) AND (shape:circle OR shape:red) */
|
|
57
|
-
export function getFilters(selectedFacetArray=undefined) {
|
|
58
|
-
// return all datasets if no filter
|
|
59
|
-
if (selectedFacetArray === undefined) {
|
|
60
|
-
return 'NOT item.published.status:embargo'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Switch the 'term' attribute to 'label' if 'label' does not exist
|
|
64
|
-
selectedFacetArray.forEach(f=>f.label=f.facet)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let facets = removeShowAllFacets(selectedFacetArray)
|
|
68
|
-
|
|
69
|
-
let filters = "NOT item.published.status:embargo";
|
|
70
|
-
filters = `(${filters}) AND `;
|
|
71
|
-
const facetPropPaths = facetPropPathMapping.map((f) => f.facetPropPath);
|
|
72
|
-
facetPropPaths.map((facetPropPath) => {
|
|
73
|
-
let facetsToBool = facets.filter(
|
|
74
|
-
(facet) => facet.facetPropPath == facetPropPath
|
|
75
|
-
);
|
|
76
|
-
let orFilters = "";
|
|
77
|
-
let andFilters = "";
|
|
78
|
-
facetsToBool.map((facet) => {
|
|
79
|
-
let facetPropPathToUse = facet.facetSubPropPath ? facet.facetSubPropPath : facetPropPath // Check if we have a subpath
|
|
80
|
-
if (facet.AND){
|
|
81
|
-
andFilters += `AND "${facetPropPathToUse}":"${facet.label}"`;
|
|
82
|
-
} else {
|
|
83
|
-
orFilters += `"${facetPropPathToUse}":"${facet.label}" OR `;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
if (orFilters == "" && andFilters =="") {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
orFilters = `(${orFilters.substring(0, orFilters.lastIndexOf(" OR "))})` // remove last OR
|
|
90
|
-
|
|
91
|
-
filters += `${orFilters + andFilters} AND `; // Put them together
|
|
92
|
-
// (Note that we add an extra AND in case there are facets at a higher level)
|
|
93
|
-
|
|
94
|
-
filters = filters.split('()AND ').join(''); // Handle case where there where no OR facets
|
|
95
|
-
});
|
|
96
|
-
console.log('filters about to be applied:', filters)
|
|
97
|
-
return filters.substring(0, filters.lastIndexOf(" AND "));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function removeShowAllFacets(facetArray){
|
|
101
|
-
return facetArray.filter( f => f.label !== 'Show all')
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
|
|
3
|
+
// Mapping between display categories and their Algolia index property path
|
|
4
|
+
// Used for populating the Dataset Search Results facet menu dynamically
|
|
5
|
+
export const facetPropPathMapping = [
|
|
6
|
+
{
|
|
7
|
+
label: 'Data Type',
|
|
8
|
+
id: 'item.types',
|
|
9
|
+
facetPropPath: 'item.types.name',
|
|
10
|
+
facetSubpropPath: 'item.types.subcategory.name'
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
label: 'Anatomical Structure',
|
|
14
|
+
id: 'anatomy.organ.category',
|
|
15
|
+
facetPropPath: 'anatomy.organ.category.name',
|
|
16
|
+
facetSubpropPath: 'anatomy.organ.subcategory.name',
|
|
17
|
+
facetFilterPath: 'anatomy.organ.name'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: 'Species',
|
|
21
|
+
id: 'organisms.primary.species',
|
|
22
|
+
facetPropPath: 'organisms.primary.species.name',
|
|
23
|
+
facetSubpropPath: 'organisms.primary.species.subcategory.name'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: 'Experimental Approach',
|
|
27
|
+
id: 'item.modalities',
|
|
28
|
+
facetPropPath: 'item.modalities.keyword',
|
|
29
|
+
facetSubpropPath: 'item.modalities.subcategory.name'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: 'Sex',
|
|
33
|
+
id: 'attributes.subject.sex',
|
|
34
|
+
facetPropPath: 'attributes.subject.sex.value',
|
|
35
|
+
facetSubpropPath: 'attributes.subject.sex.subcategory.name'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'Age Categories',
|
|
39
|
+
id: 'attributes.subject.ageCategory',
|
|
40
|
+
facetPropPath: 'attributes.subject.ageCategory.value',
|
|
41
|
+
facetSubpropPath: 'attributes.subject.ageCategory.subcategory.name'
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
// Same as above, but these show on the sidebar filters
|
|
46
|
+
export const shownFilters = {
|
|
47
|
+
'anatomy.organ.name' : 'Anatomical Structure',
|
|
48
|
+
'organisms.primary.species.name' : 'Species',
|
|
49
|
+
'attributes.subject.sex.value' : 'Sex',
|
|
50
|
+
'attributes.subject.ageCategory.value' : 'Age Categories',
|
|
51
|
+
'item.types.name' : 'Data type',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Returns filter for searching algolia. All facets of the same category are joined with OR,
|
|
55
|
+
* and each of those results is then joined with an AND.
|
|
56
|
+
* i.e. (color:blue OR color:red) AND (shape:circle OR shape:red) */
|
|
57
|
+
export function getFilters(selectedFacetArray=undefined) {
|
|
58
|
+
// return all datasets if no filter
|
|
59
|
+
if (selectedFacetArray === undefined) {
|
|
60
|
+
return 'NOT item.published.status:embargo'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Switch the 'term' attribute to 'label' if 'label' does not exist
|
|
64
|
+
selectedFacetArray.forEach(f=>f.label=f.facet)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
let facets = removeShowAllFacets(selectedFacetArray)
|
|
68
|
+
|
|
69
|
+
let filters = "NOT item.published.status:embargo";
|
|
70
|
+
filters = `(${filters}) AND `;
|
|
71
|
+
const facetPropPaths = facetPropPathMapping.map((f) => f.facetPropPath);
|
|
72
|
+
facetPropPaths.map((facetPropPath) => {
|
|
73
|
+
let facetsToBool = facets.filter(
|
|
74
|
+
(facet) => facet.facetPropPath == facetPropPath
|
|
75
|
+
);
|
|
76
|
+
let orFilters = "";
|
|
77
|
+
let andFilters = "";
|
|
78
|
+
facetsToBool.map((facet) => {
|
|
79
|
+
let facetPropPathToUse = facet.facetSubPropPath ? facet.facetSubPropPath : facetPropPath // Check if we have a subpath
|
|
80
|
+
if (facet.AND){
|
|
81
|
+
andFilters += `AND "${facetPropPathToUse}":"${facet.label}"`;
|
|
82
|
+
} else {
|
|
83
|
+
orFilters += `"${facetPropPathToUse}":"${facet.label}" OR `;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (orFilters == "" && andFilters =="") {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
orFilters = `(${orFilters.substring(0, orFilters.lastIndexOf(" OR "))})` // remove last OR
|
|
90
|
+
|
|
91
|
+
filters += `${orFilters + andFilters} AND `; // Put them together
|
|
92
|
+
// (Note that we add an extra AND in case there are facets at a higher level)
|
|
93
|
+
|
|
94
|
+
filters = filters.split('()AND ').join(''); // Handle case where there where no OR facets
|
|
95
|
+
});
|
|
96
|
+
console.log('filters about to be applied:', filters)
|
|
97
|
+
return filters.substring(0, filters.lastIndexOf(" AND "));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function removeShowAllFacets(facetArray){
|
|
101
|
+
return facetArray.filter( f => f.label !== 'Show all')
|
|
102
102
|
}
|