@abi-software/map-side-bar 2.4.0-isan-1 → 2.4.0
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/dist/map-side-bar.js +19548 -9719
- package/dist/map-side-bar.umd.cjs +500 -62
- package/dist/style.css +1 -1
- package/package.json +2 -1
- package/src/App.vue +11 -14
- package/src/algolia/algolia.js +28 -42
- package/src/algolia/utils.js +2 -7
- package/src/components/ConnectivityInfo.vue +137 -3
- package/src/components/DatasetCard.vue +87 -11
- package/src/components/SearchFilters.vue +5 -21
- package/src/components/SideBar.vue +0 -4
- package/src/components/SidebarContent.vue +34 -135
- package/src/components.d.ts +0 -1
- package/src/components/PMRDatasetCard.vue +0 -317
- package/src/flatmapQueries/flatmapQueries.js +0 -221
- package/src/mixins/mixedPageCalculation.vue +0 -102
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
function transformKeyValueArrayToObject(data) {
|
|
2
|
-
try {
|
|
3
|
-
let result = data.values.map(valueArray =>
|
|
4
|
-
data.keys.reduce((acc, key, index) => {
|
|
5
|
-
acc[key] = valueArray[index];
|
|
6
|
-
return acc;
|
|
7
|
-
}, {})
|
|
8
|
-
)
|
|
9
|
-
return result
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.error(`Error occured during conversion of Key Value Array to Object: ${error}`)
|
|
12
|
-
return {}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// remove duplicates by stringifying the objects
|
|
18
|
-
const removeDuplicates = function (arrayOfAnything) {
|
|
19
|
-
if (!arrayOfAnything) return []
|
|
20
|
-
return [...new Set(arrayOfAnything.map((e) => JSON.stringify(e)))].map((e) =>
|
|
21
|
-
JSON.parse(e)
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let FlatmapQueries = function () {
|
|
27
|
-
this.initialise = function (flatmapApi) {
|
|
28
|
-
this.flatmapApi = flatmapApi
|
|
29
|
-
this.features = []
|
|
30
|
-
this.limit = 10
|
|
31
|
-
this.offset = 0
|
|
32
|
-
this.numberOfHits = 0
|
|
33
|
-
this.sqlPreOffset = ''
|
|
34
|
-
this.lookup = {}
|
|
35
|
-
this.createLookup()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.updateOffset = function (offset) {
|
|
39
|
-
this.offset = offset
|
|
40
|
-
}
|
|
41
|
-
this.updateLimit = function (limit) {
|
|
42
|
-
this.limit = limit
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this.offsetText = function () {
|
|
46
|
-
return 'limit ' + this.limit + ' offset ' + this.offset
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.createTermSQL = function (terms) {
|
|
50
|
-
let sql = ''
|
|
51
|
-
let validFilter = false
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (terms && terms.length > 0) {
|
|
55
|
-
sql += 'and '
|
|
56
|
-
terms.forEach((t, i) => {
|
|
57
|
-
if (i == 0) {
|
|
58
|
-
sql += '('
|
|
59
|
-
}
|
|
60
|
-
if (t !== '') {
|
|
61
|
-
sql += `m.term='${t}'`
|
|
62
|
-
validFilter = true
|
|
63
|
-
if (i < terms.length - 1) {
|
|
64
|
-
sql += ' or '
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (i == terms.length - 1) {
|
|
68
|
-
sql += ') '
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
if (!validFilter) {
|
|
73
|
-
sql = ''
|
|
74
|
-
}
|
|
75
|
-
return sql
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.pmrSQL = function (terms=[], search='') {
|
|
80
|
-
let sql = 'select distinct m.term, m.exposure, m.score, m.workspace, d.metadata from pmr_text '
|
|
81
|
-
sql += 'as t left join pmr_metadata as d on t.entity=d.entity left join pmr_models as m on m.exposure=t.entity '
|
|
82
|
-
sql += 'where d.metadata is not null '
|
|
83
|
-
|
|
84
|
-
// add filters for the terms
|
|
85
|
-
const termsSql = this.createTermSQL(terms)
|
|
86
|
-
sql += termsSql
|
|
87
|
-
|
|
88
|
-
// Add the text search
|
|
89
|
-
if (search && search !== '') {
|
|
90
|
-
sql += `and (t.pmr_text match '${search}')`
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Add exposure and score filters if we aren't text searching
|
|
94
|
-
if (!search || search === '') {
|
|
95
|
-
sql += 'and m.exposure is not null and score > 0.69'
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// group by exposure
|
|
99
|
-
sql += ' group by m.exposure'
|
|
100
|
-
|
|
101
|
-
this.sqlPreOffset = sql
|
|
102
|
-
|
|
103
|
-
// add the limit and offset for pagination
|
|
104
|
-
sql += ' ' + this.offsetText() + ';'
|
|
105
|
-
|
|
106
|
-
console.log(sql)
|
|
107
|
-
return sql
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.convertTermsToIds = function (terms) {
|
|
111
|
-
return terms.map(t => this.lookUpId(t))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.labelSQL = function (){
|
|
115
|
-
return "select entity, label from labels"
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
this.countSQL = function (sql) {
|
|
119
|
-
sql = `select count(*) from (${sql})`
|
|
120
|
-
return sql
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.flatmapQuery = function (sql) {
|
|
125
|
-
const data = { sql: sql }
|
|
126
|
-
return fetch(`${this.flatmapApi}knowledge/query/`, {
|
|
127
|
-
method: 'POST',
|
|
128
|
-
headers: {
|
|
129
|
-
'Content-Type': 'application/json',
|
|
130
|
-
},
|
|
131
|
-
body: JSON.stringify(data),
|
|
132
|
-
})
|
|
133
|
-
.then((response) => response.json())
|
|
134
|
-
.catch((error) => {
|
|
135
|
-
console.error('Error:', error)
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
this.processFilters = function (filters) {
|
|
140
|
-
let featureLabels = []
|
|
141
|
-
filters.forEach((f) => {
|
|
142
|
-
if (f.label !== 'Show all' && f.label !== 'PMR')
|
|
143
|
-
featureLabels.push(f.facet)
|
|
144
|
-
})
|
|
145
|
-
return featureLabels
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.pmrSearch = function (filters=[], search='') {
|
|
151
|
-
let features = this.processFilters(filters)
|
|
152
|
-
let featureIds = this.convertTermsToIds(features)
|
|
153
|
-
return new Promise((resolve, reject) => {
|
|
154
|
-
this.flatmapQuery(this.pmrSQL(featureIds, search))
|
|
155
|
-
.then(data => {
|
|
156
|
-
const pd = this.processPMRData(data, featureIds)
|
|
157
|
-
this.setAvailableFeatures(pd)
|
|
158
|
-
|
|
159
|
-
// get the number of hits for pagination
|
|
160
|
-
this.flatmapQuery(this.countSQL(this.sqlPreOffset)).then(data => {
|
|
161
|
-
this.numberOfHits = data.values[0][0]
|
|
162
|
-
resolve(pd);
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
.catch(reject);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// setAvailableFeatures returns the available features in the flatmap for filtering
|
|
170
|
-
// pd is the processed data from the flatmap
|
|
171
|
-
this.setAvailableFeatures = function (pd) {
|
|
172
|
-
pd.forEach((d) => {
|
|
173
|
-
Object.keys(d).forEach((key) => {
|
|
174
|
-
if (!this.features.includes(key)) {
|
|
175
|
-
this.features.push(key)
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.processPMRData = function (data, featureIds=[]) {
|
|
183
|
-
// Convert the flatmap data into an array of objects
|
|
184
|
-
let dataObj = transformKeyValueArrayToObject(data)
|
|
185
|
-
|
|
186
|
-
// Only use the results with metadata
|
|
187
|
-
let metadataResults = dataObj.filter(d => d.metadata)
|
|
188
|
-
let metadataOnly = metadataResults.map(d => {
|
|
189
|
-
let md = JSON.parse(d.metadata)
|
|
190
|
-
md.dataSource = 'PMR'
|
|
191
|
-
return md
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
// If there are featureIds, filter the results
|
|
195
|
-
if (featureIds.length > 0) {
|
|
196
|
-
metadataOnly = metadataOnly.filter(d => featureIds.includes(d.term))
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Remove duplicates
|
|
200
|
-
let uniqueResults = removeDuplicates(metadataOnly)
|
|
201
|
-
return uniqueResults
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
this.createLookup = function () {
|
|
205
|
-
this.flatmapQuery(this.labelSQL())
|
|
206
|
-
.then(data => {
|
|
207
|
-
data.values.forEach(d => {
|
|
208
|
-
if (d[1] && (typeof d[1] === 'string' || d[1] instanceof String)) {
|
|
209
|
-
this.lookup[d[1].toLowerCase()] = d[0]
|
|
210
|
-
}
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
this.lookUpId = function (label) {
|
|
216
|
-
return this.lookup[label.toLowerCase()]
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export default FlatmapQueries
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
// The functions below are needed because the number of results shown on the page is dependent what is available from each index.
|
|
3
|
-
// We fix this by calcuting how many results we have shown before the requested page and then calculating the offset based on that.
|
|
4
|
-
|
|
5
|
-
// Note that this.RatioOfPMRResults is a number that determines how many PMR results are shown compared to SPARC results. It is grabbed from a constant in
|
|
6
|
-
// SidebarContent.vue.
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
methods: {
|
|
10
|
-
|
|
11
|
-
// Calculate Variable Ratio is used as a number to determine how the ratio of PMR results to SPARC results
|
|
12
|
-
// will be shown on the page. 1 means only PMR results, 0 means only SPARC results.
|
|
13
|
-
calculateVariableRatio: function () {
|
|
14
|
-
if (this.page === 1) {
|
|
15
|
-
this.variableRatio = this.RatioOfPMRResults
|
|
16
|
-
|
|
17
|
-
// Check if we have run out of Sparc results
|
|
18
|
-
} else if( this.npp_SPARC * (this.page -1) >= this.sparcNumberOfHits) {
|
|
19
|
-
this.variableRatio = 1
|
|
20
|
-
|
|
21
|
-
// Check if we have run out of PMR results
|
|
22
|
-
} else if(this.npp_PMR * (this.page - 1) >= this.pmrNumberOfHits) {
|
|
23
|
-
this.variableRatio = 0
|
|
24
|
-
} else {
|
|
25
|
-
|
|
26
|
-
// Set the ratio to the same as the previous page if both indeces have results
|
|
27
|
-
this.variableRatio = this.RatioOfPMRResults
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
// calculatePMROffest is used to calculate how many PMR results we have shown before the requested page
|
|
32
|
-
calculatePMROffest: function() {
|
|
33
|
-
|
|
34
|
-
// If variable ratio has not changed, we have not run out of results.
|
|
35
|
-
// we can use the the number per page PMR to calculate the offset
|
|
36
|
-
if (this.variableRatio === this.RatioOfPMRResults) {
|
|
37
|
-
return (this.page-1)*this.npp_PMR
|
|
38
|
-
|
|
39
|
-
// If we have run out of SPARC results, we need to calculate how many PMR results we have shown before the requested page
|
|
40
|
-
} else if (this.variableRatio === 1) {
|
|
41
|
-
|
|
42
|
-
// calculate how many results we showed before the requested page
|
|
43
|
-
// We want our offset to be the number of PMR results shown before the requested page
|
|
44
|
-
// This can be though of as numberOfPMRResultsShownInMixed + numberOfPMRResultsShownInPMROnly = offset
|
|
45
|
-
let pageWhereSPARCResultsRanOut = Math.ceil(this.sparcNumberOfHits / this.npp_SPARC)
|
|
46
|
-
let numberOfPMRResultsShownInMixed = this.npp_PMR * pageWhereSPARCResultsRanOut
|
|
47
|
-
let numberOfPMRResultsShownInPMROnly = (this.page - 1 - pageWhereSPARCResultsRanOut) * this.numberPerPage
|
|
48
|
-
return numberOfPMRResultsShownInMixed + numberOfPMRResultsShownInPMROnly
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
// calculateSPARCOffest is used to calculate how many SPARC results we have shown before the requested page. See above for details
|
|
53
|
-
calculateSPARCOffest: function() {
|
|
54
|
-
if(this.variableRatio === this.RatioOfPMRResults) {
|
|
55
|
-
return (this.page-1)*this.npp_SPARC
|
|
56
|
-
} else if (this.variableRatio === 0) {
|
|
57
|
-
|
|
58
|
-
// calculate how many results we showed before the requested page
|
|
59
|
-
let pageWherePMRResultsRanOut = Math.ceil(this.pmrNumberOfHits / this.npp_PMR)
|
|
60
|
-
let numberOfSPARCResultsShownInMixed = this.npp_SPARC * pageWherePMRResultsRanOut
|
|
61
|
-
let numberOfSPARCResultsShownInSPARCOnly = (this.page - 1 - pageWherePMRResultsRanOut) * this.numberPerPage
|
|
62
|
-
let offset = numberOfSPARCResultsShownInMixed + numberOfSPARCResultsShownInSPARCOnly
|
|
63
|
-
return offset
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
// PMRLimit is used to calculate how many PMR results we can show on the page.
|
|
68
|
-
PMRLimit: function(pmrResultsOnlyFlag=false) {
|
|
69
|
-
// If we only want PMR results, return the number per page
|
|
70
|
-
if (pmrResultsOnlyFlag) {
|
|
71
|
-
return this.numberPerPage
|
|
72
|
-
}
|
|
73
|
-
// If the variable ratio is the same as the ratio of PMR results, return the number per page set for PMR
|
|
74
|
-
if (this.variableRatio === this.RatioOfPMRResults) {
|
|
75
|
-
return this.npp_PMR
|
|
76
|
-
|
|
77
|
-
// if we have run out of sparc results, we want to show pmr results equal to the total number of results per page
|
|
78
|
-
} else if (this.variableRatio === 1) {
|
|
79
|
-
return this.numberPerPage
|
|
80
|
-
|
|
81
|
-
// if we have run out of pmr results, we want to show 0 pmr results
|
|
82
|
-
} else if (this.variableRatio === 0) {
|
|
83
|
-
return 0
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
SPARCLimit: function(pmrResultsOnlyFlag=false) {
|
|
87
|
-
if(pmrResultsOnlyFlag) {
|
|
88
|
-
return 0
|
|
89
|
-
}
|
|
90
|
-
if (this.variableRatio === this.RatioOfPMRResults) {
|
|
91
|
-
return this.npp_SPARC
|
|
92
|
-
} else if (this.variableRatio === 0) {
|
|
93
|
-
return this.numberPerPage
|
|
94
|
-
} else if (this.variableRatio === 1) {
|
|
95
|
-
return 0
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
</script>
|
|
101
|
-
|
|
102
|
-
|