@abi-software/map-side-bar 1.1.2 → 1.1.5-beta-1

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.
@@ -16,9 +16,10 @@
16
16
  class="filters"
17
17
  ref="filtersRef"
18
18
  :entry="filterEntry"
19
- :apiLocation="apiLocation"
19
+ :envVars="envVars"
20
20
  @filterResults="filterUpdate"
21
21
  @numberPerPage="numberPerPageUpdate"
22
+ @loading="filtersLoading"
22
23
  ></SearchFilters>
23
24
  <div class="content scrollbar" v-loading="loadingCards" ref="content">
24
25
  <div
@@ -27,7 +28,7 @@
27
28
  >No results found - Please change your search / filter criteria.</div>
28
29
  <div class="error-feedback" v-if="sciCrunchError">{{sciCrunchError}}</div>
29
30
  <div v-for="o in results" :key="o.id" class="step-item">
30
- <DatasetCard :entry="o" :apiLocation="apiLocation"></DatasetCard>
31
+ <DatasetCard :entry="o" :envVars="envVars"></DatasetCard>
31
32
  </div>
32
33
  <el-pagination
33
34
  class="pagination"
@@ -62,6 +63,9 @@ import SearchFilters from "./SearchFilters";
62
63
  import DatasetCard from "./DatasetCard";
63
64
  import ContextCard from "./ContextCard.vue";
64
65
 
66
+ import {AlgoliaClient} from "../algolia/algolia.js";
67
+ import {getFilters} from "../algolia/utils.js"
68
+
65
69
  locale.use(lang);
66
70
  Vue.use(Button);
67
71
  Vue.use(Card);
@@ -91,7 +95,6 @@ var initial_state = {
91
95
  results: [],
92
96
  numberOfHits: 0,
93
97
  filter: [],
94
- filterFacets: undefined,
95
98
  loadingCards: false,
96
99
  numberPerPage: 10,
97
100
  page: 1,
@@ -121,9 +124,9 @@ export default {
121
124
  type: Object,
122
125
  default: undefined
123
126
  },
124
- apiLocation: {
125
- type: String,
126
- default: ""
127
+ envVars: {
128
+ type: Object,
129
+ default: () => {}
127
130
  },
128
131
  firstSearch: {
129
132
  type: String,
@@ -145,59 +148,74 @@ export default {
145
148
  filterEntry: function() {
146
149
  return {
147
150
  numberOfHits: this.numberOfHits,
148
- filterFacets: this.filterFacets
151
+ filterFacets: this.filter
149
152
  };
150
153
  }
151
154
  },
152
155
  methods: {
153
- openSearch: function(search, filter = undefined,
154
- endpoint = undefined, params = undefined) {
156
+ openSearch: function(filter, search='') {
155
157
  this.searchInput = search;
156
158
  this.resetPageNavigation();
157
- this.searchSciCrunch(search, filter, endpoint, params);
159
+ this.searchAlgolia(filter, search);
160
+ if (filter) {
161
+ this.filter = [...filter];
162
+ this.$refs.filtersRef.setCascader(this.filter);
163
+ }
164
+ },
165
+ addFilter: function(filter) {
166
+ this.resetPageNavigation();
158
167
  if (filter) {
159
- this.filterFacets = [...filter];
160
- this.$refs.filtersRef.setCascader(this.filterFacets);
168
+ this.$refs.filtersRef.addFilter(filter);
169
+ this.$refs.filtersRef.initiateSearch()
161
170
  }
162
171
  },
163
172
  clearSearchClicked: function() {
164
173
  this.searchInput = "";
165
174
  this.resetPageNavigation();
166
- this.searchSciCrunch(this.searchInput);
175
+ this.searchAlgolia(this.filters, this.searchInput);
167
176
  },
168
177
  searchEvent: function(event = false) {
169
178
  if (event.keyCode === 13 || event instanceof MouseEvent) {
170
179
  this.resetPageNavigation();
171
- this.searchSciCrunch(this.searchInput);
180
+ this.searchAlgolia(this.filters, this.searchInput);
172
181
  }
173
182
  },
174
- filterUpdate: function(filter) {
175
- this.resetPageNavigation();
176
- this.searchSciCrunch(this.searchInput, filter);
177
- this.filter = [...filter];
183
+ filterUpdate: function(filters) {
184
+ this.filters = [...filters]
185
+ this.resetPageNavigation()
186
+ this.searchAlgolia(filters, this.searchInput)
178
187
  this.$emit("search-changed", {
179
188
  value: this.filter,
180
189
  type: "filter-update"
181
190
  });
182
191
  },
192
+ searchAlgolia(filters, query=''){
193
+ // Algolia search
194
+ this.algoliaClient.search(getFilters(filters), query, this.numberPerPage, this.page).then(searchData => {
195
+ this.numberOfHits = searchData.total
196
+ this.discoverIds = searchData.discoverIds
197
+ this.results = searchData.items
198
+ this.searchSciCrunch({'discoverIds':this.discoverIds})
199
+ })
200
+ },
201
+ filtersLoading: function (val) {
202
+ this.loadingCards = val;
203
+ },
183
204
  numberPerPageUpdate: function(val) {
184
205
  this.numberPerPage = val;
185
206
  this.pageChange(1);
186
207
  },
187
208
  pageChange: function(page) {
188
209
  this.start = (page - 1) * this.numberPerPage;
189
- this.searchSciCrunch(this.searchInput);
210
+ this.page = page
211
+ this.searchAlgolia(this.filters, this.searchInput, this.numberPerPage, this.page)
190
212
  },
191
- searchSciCrunch: function(search, filter = undefined,
192
- searchEndpoint = undefined, params = undefined) {
213
+ searchSciCrunch: function(params) {
193
214
  this.loadingCards = true;
194
215
  this.results = [];
195
216
  this.disableCards();
196
- if (!searchEndpoint) searchEndpoint = this.searchEndpoint;
197
- if (!params)
198
- params = this.createParams(filter, this.start, this.numberPerPage);
199
- this.$emit("search-changed", { value: search, type: "query-update" });
200
- this.callSciCrunch(this.apiLocation, searchEndpoint, search, params)
217
+ this.$emit("search-changed", { value: this.searchInput, type: "query-update" });
218
+ this.callSciCrunch(this.envVars.API_LOCATION, params)
201
219
  .then(result => {
202
220
  //Only process if the search term is the same as the last search term.
203
221
  //This avoid old search being displayed.
@@ -223,52 +241,30 @@ export default {
223
241
  this.start = 0;
224
242
  this.page = 1;
225
243
  },
226
- createParams: function(filter, start, size) {
227
- //Deconstruct list of fitlers to list of term
228
- //and facet.
229
- let params = {};
230
- let term = [];
231
- let facet = [];
232
- let f = undefined;
233
- if (filter !== undefined) {
234
- f = filter;
235
- } else {
236
- f = this.filter;
237
- }
238
- if (f)
239
- f.forEach(e => {
240
- //Do not ask for any "show all" request
241
- if (e.facet !== "show all") {
242
- term.push(e.term);
243
- facet.push(e.facet);
244
- }
245
- });
246
- params.term = term;
247
- params.facet = facet;
248
- params.start = start;
249
- params.size = size;
250
- return params;
251
- },
252
244
  resultsProcessing: function(data) {
253
245
  this.lastSearch = this.searchInput;
254
246
  this.results = [];
255
- let id = 0;
256
247
  this.numberOfHits = data.numberOfHits;
257
248
  if (data.results.length === 0) {
258
249
  return;
259
250
  }
260
251
  data.results.forEach(element => {
261
252
  // this.results.push(element) below should be once backend is ready
262
- this.results.push({
253
+ let datasetInfo = {
263
254
  name: element.name,
264
255
  description: element.description,
265
256
  contributors: element.contributors,
266
- numberSamples: Array.isArray(element.samples)
267
- ? element.samples.length
268
- : 1,
257
+ numberSamples: element.sampleSize
258
+ ? parseInt(element.sampleSize)
259
+ : 0,
260
+ numberSubjects: element.subjectSize
261
+ ? parseInt(element.subjectSize)
262
+ : 0,
269
263
  updated: element.updated[0].timestamp.split("T")[0],
270
264
  url: element.uri[0],
271
- datasetId: element.identifier,
265
+ datasetId: element.dataset_identifier,
266
+ datasetRevision: element.dataset_revision,
267
+ datasetVersion: element.dataset_version,
272
268
  organs: (element.organs && element.organs.length > 0)
273
269
  ? [...new Set(element.organs.map(v => v.name))]
274
270
  : undefined,
@@ -278,17 +274,17 @@ export default {
278
274
  : undefined
279
275
  : undefined, // This processing only includes each gender once into 'sexes'
280
276
  csvFiles: element.csvFiles,
281
- id: id,
282
277
  doi: element.doi,
283
278
  publishDate: element.publishDate,
284
279
  scaffolds: element['abi-scaffold-metadata-file'] ? element['abi-scaffold-metadata-file'] : undefined,
285
280
  additionalLinks: element.additionalLinks,
281
+ segmentation: element['mbf-segmentation'],
286
282
  simulation: element.additionalLinks
287
283
  ? element.additionalLinks[0].description == 'Repository'
288
284
  : false,
289
285
  s3uri: element.s3uri
290
- });
291
- id++;
286
+ };
287
+ this.results.push(datasetInfo);
292
288
  });
293
289
  },
294
290
  createfilterParams: function(params) {
@@ -305,47 +301,39 @@ export default {
305
301
  }
306
302
  return p.toString();
307
303
  },
308
- callSciCrunch: function(apiLocation, searchEndpoint, search, params = {}) {
304
+ callSciCrunch: function(apiLocation, params = {}) {
309
305
  return new Promise((resolve, reject) => {
310
306
  // the following controller will abort current search
311
307
  // if a new one has been started
312
308
  if (this._controller) this._controller.abort();
313
309
  this._controller = new AbortController();
314
310
  let signal = this._controller.signal;
315
- var endpoint = apiLocation + searchEndpoint;
316
311
  // Add parameters if we are sent them
317
- if (search !== "" && Object.entries(params).length !== 0) {
318
- endpoint = endpoint + search + "/?" + this.createfilterParams(params);
319
- } else {
320
- endpoint = endpoint + "?" + this.createfilterParams(params);
321
- }
322
- fetch(endpoint, { signal })
312
+ let fullEndpoint = this.envVars.API_LOCATION + this.searchEndpoint + "?" + this.createfilterParams(params);
313
+ fetch(fullEndpoint, { signal })
323
314
  .then(handleErrors)
324
315
  .then(response => response.json())
325
316
  .then(data => resolve(data))
326
317
  .catch(data => reject(data));
327
318
  });
328
- }
319
+ },
329
320
  },
330
321
  mounted: function() {
322
+ // initialise algolia
323
+ this.algoliaClient = new AlgoliaClient(this.envVars.ALGOLIA_ID, this.envVars.ALGOLIA_KEY, this.envVars.PENNSIEVE_API_LOCATION);
324
+ this.algoliaClient.initIndex(this.envVars.ALGOLIA_INDEX);
325
+ console.log('Algolia initialised in sidebar')
326
+
331
327
  // temporarily disable flatmap search since there are no datasets
332
328
  if (this.firstSearch === "Flatmap" || this.firstSearch === "flatmap") {
333
- this.openSearch('', [
334
- {facet: "show all", term:'organ'},
335
- {facet: "show all", term:'species'},
336
- {facet: "show all", term:'gender'},
337
- {facet: "show all", term:'datasets'}]);
329
+ this.openSearch(undefined, '')
338
330
  } else {
339
- this.openSearch(this.firstSearch, [
340
- {facet: "show all", term:'organ'},
341
- {facet: "show all", term:'species'},
342
- {facet: "show all", term:'gender'},
343
- {facet: "show all", term:'datasets'}]);
331
+ this.openSearch(undefined, '');
344
332
  }
345
333
  },
346
334
  created: function() {
347
335
  //Create non-reactive local variables
348
- this.searchEndpoint = "filter-search/";
336
+ this.searchEndpoint = "dataset_info/using_multiple_discoverIds/";
349
337
  }
350
338
  };
351
339
  </script>
@@ -426,6 +414,17 @@ export default {
426
414
  scrollbar-width: thin;
427
415
  }
428
416
 
417
+ .content >>> .step-item:first-child .seperator-path{
418
+ display: none;
419
+ }
420
+
421
+ .content >>> .step-item:not(:first-child) .seperator-path{
422
+ width: 486px;
423
+ height: 0px;
424
+ border: solid 1px #e4e7ed;
425
+ background-color: #e4e7ed;
426
+ }
427
+
429
428
  .scrollbar::-webkit-scrollbar-track {
430
429
  border-radius: 10px;
431
430
  background-color: #f5f5f5;