@abi-software/map-side-bar 1.2.0-beta.9 → 1.2.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.
@@ -1,99 +1,119 @@
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
- }
13
- initIndex(ALGOLIA_INDEX) {
14
- this.index = this.client.initIndex(ALGOLIA_INDEX);
15
- }
16
-
17
- getAlgoliaFacets (propPathMapping) {
18
- const map = new Map(Object.entries(propPathMapping));
19
- const facetPropPaths = Array.from(map.keys() );
20
- let facetData = []
21
- let facetId = 0
22
- return this.index
23
- .search('', {
24
- sortFacetValuesBy: 'alpha',
25
- facets: facetPropPaths
26
- })
27
- .then(response => {
28
- facetPropPaths.map((facetPropPath) => {
29
- var children = []
30
- const responseFacets = response.facets
31
- if (responseFacets === undefined) {return}
32
- const responseFacetChildren =
33
- responseFacets[facetPropPath] == undefined
34
- ? {}
35
- : responseFacets[facetPropPath]
36
- Object.keys(responseFacetChildren).map(facet => {
37
- children.push({
38
- label: facet,
39
- id: facetId++,
40
- facetPropPath: facetPropPath
41
- })
42
- })
43
- if (children.length > 0) {
44
- facetData.push({
45
- label: map.get(facetPropPath),
46
- id: facetId++,
47
- children: children,
48
- key: facetPropPath
49
- })
50
- }
51
- })
52
- return facetData
53
- })
54
- }
55
-
56
- // Returns all DOIs of all versions for a given discover dataset
57
- _discoverAllDois (discoverId, PENNSIEVE_API_LOCATION='https://api.pennsieve.io') {
58
- return new Promise(resolve => {
59
- fetch(`${PENNSIEVE_API_LOCATION}/discover/datasets/${discoverId}/versions`).then(r=>r.json()).then(dataset => {
60
- resolve(dataset.map(version => version.doi))
61
- })
62
- })
63
- }
64
-
65
- // Get all dois given a list of discoverIds
66
- _expandDois (discoverIds, PENNSIEVE_API_LOCATION='https://api.pennsieve.io') {
67
- return new Promise(resolve => {
68
- let promiseList = discoverIds.map(discoverId => this._discoverAllDois(discoverId, PENNSIEVE_API_LOCATION))
69
- Promise.all(promiseList).then((values) => {
70
- resolve(values.flat())
71
- });
72
- })
73
- }
74
-
75
- /**
76
- * Get Search results
77
- * This is using fetch from the Algolia API
78
- */
79
- search (filter, query='', hitsperPage=10, page=1) {
80
- return new Promise(resolve => {
81
- this.index
82
- .search(query, {
83
- facets:['*'],
84
- hitsPerPage: hitsperPage,
85
- page: page-1,
86
- filters: filter
87
- })
88
- .then(response => {
89
- let searchData = {
90
- items: response.hits,
91
- total: response.nbHits,
92
- discoverIds: response.hits.map(r=>r.pennsieve.identifier),
93
- dois: response.hits.map(r=>r.item.curie.split(':')[1])
94
- }
95
- resolve(searchData)
96
- })
97
- })
98
- }
99
- }
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
+ }
13
+ initIndex(ALGOLIA_INDEX) {
14
+ this.index = this.client.initIndex(ALGOLIA_INDEX);
15
+ }
16
+
17
+ getAlgoliaFacets (propPathMapping) {
18
+ const map = new Map(Object.entries(propPathMapping));
19
+ const facetPropPaths = Array.from(map.keys() );
20
+ let facetData = []
21
+ let facetId = 0
22
+ return this.index
23
+ .search('', {
24
+ sortFacetValuesBy: 'alpha',
25
+ facets: facetPropPaths
26
+ })
27
+ .then(response => {
28
+ facetPropPaths.map((facetPropPath) => {
29
+ var children = []
30
+ const responseFacets = response.facets
31
+ if (responseFacets === undefined) {return}
32
+ const responseFacetChildren =
33
+ responseFacets[facetPropPath] == undefined
34
+ ? {}
35
+ : responseFacets[facetPropPath]
36
+ Object.keys(responseFacetChildren).map(facet => {
37
+ children.push({
38
+ label: facet,
39
+ id: facetId++,
40
+ facetPropPath: facetPropPath
41
+ })
42
+ })
43
+ if (children.length > 0) {
44
+ facetData.push({
45
+ label: map.get(facetPropPath),
46
+ id: facetId++,
47
+ children: children,
48
+ key: facetPropPath
49
+ })
50
+ }
51
+ })
52
+ return facetData
53
+ })
54
+ }
55
+
56
+ // Returns all DOIs of all versions for a given discover dataset
57
+ _discoverAllDois (discoverId, PENNSIEVE_API_LOCATION='https://api.pennsieve.io') {
58
+ return new Promise(resolve => {
59
+ fetch(`${PENNSIEVE_API_LOCATION}/discover/datasets/${discoverId}/versions`).then(r=>r.json()).then(dataset => {
60
+ resolve(dataset.map(version => version.doi))
61
+ })
62
+ })
63
+ }
64
+
65
+ // Get all dois given a list of discoverIds
66
+ _expandDois (discoverIds, PENNSIEVE_API_LOCATION='https://api.pennsieve.io') {
67
+ return new Promise(resolve => {
68
+ let promiseList = discoverIds.map(discoverId => this._discoverAllDois(discoverId, PENNSIEVE_API_LOCATION))
69
+ Promise.all(promiseList).then((values) => {
70
+ resolve(values.flat())
71
+ });
72
+ })
73
+ }
74
+
75
+ _processResultsForCards(results) {
76
+ let newResults = []
77
+ let newResult = {}
78
+ let id = 0
79
+ for (let res of results) {
80
+ newResult = {...res}
81
+ newResult = {
82
+ doi: res.item.curie.split(':')[1],
83
+ name: res.item.name,
84
+ description: res.item.description,
85
+ updated: res.pennsieve.updatedAt,
86
+ publishDate: res.pennsieve.publishDate,
87
+ id: id
88
+ }
89
+ id++
90
+ newResults.push(newResult)
91
+ }
92
+ return newResults
93
+ }
94
+
95
+ /**
96
+ * Get Search results
97
+ * This is using fetch from the Algolia API
98
+ */
99
+ search (filter, query='', hitsperPage=10, page=1) {
100
+ return new Promise(resolve => {
101
+ this.index
102
+ .search(query, {
103
+ facets:['*'],
104
+ hitsPerPage: hitsperPage,
105
+ page: page-1,
106
+ filters: filter
107
+ })
108
+ .then(response => {
109
+ let searchData = {
110
+ items: this._processResultsForCards(response.hits),
111
+ total: response.nbHits,
112
+ discoverIds: response.hits.map(r=>r.pennsieve.identifier),
113
+ dois: response.hits.map(r=>r.item.curie.split(':')[1])
114
+ }
115
+ resolve(searchData)
116
+ })
117
+ })
118
+ }
119
+ }
@@ -1,52 +1,52 @@
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
- 'anatomy.organ.name' : 'Anatomical Structure',
7
- 'organisms.primary.species.name' : 'Species',
8
- 'item.modalities.keyword' : 'Experimental Approach',
9
- 'attributes.subject.sex.value' : 'Sex',
10
- 'attributes.subject.ageCategory.value' : 'Age Categories',
11
- }
12
-
13
- /* Returns filter for searching algolia. All facets of the same category are joined with OR,
14
- * and each of those results is then joined with an AND.
15
- * i.e. (color:blue OR color:red) AND (shape:circle OR shape:red) */
16
- export function getFilters(selectedFacetArray=undefined) {
17
-
18
- // return all datasets if no filter
19
- if (selectedFacetArray === undefined) {
20
- return 'NOT item.published.status:embargo'
21
- }
22
-
23
- // Switch the 'term' attribute to 'label' if 'label' does not exist
24
- selectedFacetArray.forEach(f=>f.label=f.facet)
25
-
26
-
27
- let facets = removeShowAllFacets(selectedFacetArray)
28
-
29
- let filters = "NOT item.published.status:embargo";
30
- filters = `(${filters}) AND `;
31
-
32
- const facetPropPaths = Object.keys(facetPropPathMapping);
33
- facetPropPaths.map((facetPropPath) => {
34
- const facetsToOr = facets.filter(
35
- (facet) => facet.facetPropPath == facetPropPath
36
- );
37
- var filter = "";
38
- facetsToOr.map((facet) => {
39
- filter += `"${facetPropPath}":"${facet.label}" OR `;
40
- });
41
- if (filter == "") {
42
- return;
43
- }
44
- filter = `(${filter.substring(0, filter.lastIndexOf(" OR "))})`;
45
- filters += `${filter} AND `;
46
- });
47
- return filters.substring(0, filters.lastIndexOf(" AND "));
48
- }
49
-
50
- function removeShowAllFacets(facetArray){
51
- 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
+ 'anatomy.organ.name' : 'Anatomical Structure',
7
+ 'organisms.primary.species.name' : 'Species',
8
+ 'item.modalities.keyword' : 'Experimental Approach',
9
+ 'attributes.subject.sex.value' : 'Sex',
10
+ 'attributes.subject.ageCategory.value' : 'Age Categories',
11
+ }
12
+
13
+ /* Returns filter for searching algolia. All facets of the same category are joined with OR,
14
+ * and each of those results is then joined with an AND.
15
+ * i.e. (color:blue OR color:red) AND (shape:circle OR shape:red) */
16
+ export function getFilters(selectedFacetArray=undefined) {
17
+
18
+ // return all datasets if no filter
19
+ if (selectedFacetArray === undefined) {
20
+ return 'NOT item.published.status:embargo'
21
+ }
22
+
23
+ // Switch the 'term' attribute to 'label' if 'label' does not exist
24
+ selectedFacetArray.forEach(f=>f.label=f.facet)
25
+
26
+
27
+ let facets = removeShowAllFacets(selectedFacetArray)
28
+
29
+ let filters = "NOT item.published.status:embargo";
30
+ filters = `(${filters}) AND `;
31
+
32
+ const facetPropPaths = Object.keys(facetPropPathMapping);
33
+ facetPropPaths.map((facetPropPath) => {
34
+ const facetsToOr = facets.filter(
35
+ (facet) => facet.facetPropPath == facetPropPath
36
+ );
37
+ var filter = "";
38
+ facetsToOr.map((facet) => {
39
+ filter += `"${facetPropPath}":"${facet.label}" OR `;
40
+ });
41
+ if (filter == "") {
42
+ return;
43
+ }
44
+ filter = `(${filter.substring(0, filter.lastIndexOf(" OR "))})`;
45
+ filters += `${filter} AND `;
46
+ });
47
+ return filters.substring(0, filters.lastIndexOf(" AND "));
48
+ }
49
+
50
+ function removeShowAllFacets(facetArray){
51
+ return facetArray.filter( f => f.label !== 'Show all')
52
52
  }
@@ -1,49 +1,49 @@
1
- <script>
2
- /* eslint-disable no-alert, no-console */
3
- import { Cascader } from "element-ui";
4
-
5
- export default {
6
- name: 'CustomCascader',
7
- extends: Cascader,
8
- methods:{
9
- //Modify this internal function to disable Show all tags
10
- computePresentTags() {
11
- const { isDisabled, leafOnly, showAllLevels, separator, collapseTags } = this;
12
- const checkedNodes = this.getCheckedNodes(leafOnly);
13
- const tags = [];
14
- const genTag = node => ({
15
- node,
16
- key: node.uid,
17
- text: node.getText(showAllLevels, separator),
18
- hitState: false,
19
- closable: !isDisabled && !node.isDisabled
20
- });
21
- let customNodes = checkedNodes.filter(node =>
22
- {
23
- return !(node.getText(showAllLevels, separator).includes("Show all"));
24
- }
25
- );
26
- if (customNodes.length) {
27
- const [first, ...rest] = customNodes;
28
- const restCount = rest.length;
29
- tags.push(genTag(first));
30
- if (restCount) {
31
- if (collapseTags) {
32
- tags.push({
33
- key: -1,
34
- text: `+ ${restCount}`,
35
- closable: false
36
- });
37
- } else {
38
- rest.forEach(node => tags.push(genTag(node)));
39
- }
40
- }
41
- }
42
- this.checkedNodes = checkedNodes;
43
- this.presentTags = tags;
44
- this.$emit("tags-changed", this.presentTags);
45
- }
46
- }
47
- }
48
-
49
- </script>
1
+ <script>
2
+ /* eslint-disable no-alert, no-console */
3
+ import { Cascader } from "element-ui";
4
+
5
+ export default {
6
+ name: 'CustomCascader',
7
+ extends: Cascader,
8
+ methods:{
9
+ //Modify this internal function to disable Show all tags
10
+ computePresentTags() {
11
+ const { isDisabled, leafOnly, showAllLevels, separator, collapseTags } = this;
12
+ const checkedNodes = this.getCheckedNodes(leafOnly);
13
+ const tags = [];
14
+ const genTag = node => ({
15
+ node,
16
+ key: node.uid,
17
+ text: node.getText(showAllLevels, separator),
18
+ hitState: false,
19
+ closable: !isDisabled && !node.isDisabled
20
+ });
21
+ let customNodes = checkedNodes.filter(node =>
22
+ {
23
+ return !(node.getText(showAllLevels, separator).includes("Show all"));
24
+ }
25
+ );
26
+ if (customNodes.length) {
27
+ const [first, ...rest] = customNodes;
28
+ const restCount = rest.length;
29
+ tags.push(genTag(first));
30
+ if (restCount) {
31
+ if (collapseTags) {
32
+ tags.push({
33
+ key: -1,
34
+ text: `+ ${restCount}`,
35
+ closable: false
36
+ });
37
+ } else {
38
+ rest.forEach(node => tags.push(genTag(node)));
39
+ }
40
+ }
41
+ }
42
+ this.checkedNodes = checkedNodes;
43
+ this.presentTags = tags;
44
+ this.$emit("tags-changed", this.presentTags);
45
+ }
46
+ }
47
+ }
48
+
49
+ </script>