@abi-software/map-side-bar 1.1.1-beta.5 → 1.1.3-fix-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/src/App.vue CHANGED
@@ -4,6 +4,7 @@
4
4
  href="https://fonts.googleapis.com/css?family=Asap:400,400i,500,600,700&display=swap">
5
5
  Click arrow to open sidebar
6
6
  <el-button @click="openSearch">search 'heart' from refs</el-button>
7
+ <el-button @click="singleFacets">single facets</el-button>
7
8
  <el-button @click="multiFacets">multiple facets</el-button>
8
9
  <el-button @click="neuronSearch">open neuron search</el-button>
9
10
  <SideBar class="side-bar" ref="sideBar" :apiLocation="apiLocation" :visible="sideBarVisibility"
@@ -77,7 +78,13 @@ export default {
77
78
  console.log("action fired: ", val)
78
79
  },
79
80
  openSearch: function(){
80
- this.$refs.sideBar.openSearch('heart', [{facet: 'Show all', term:'species'}] )
81
+ this.$refs.sideBar.openSearch('heart', [{facet: "show all", term:'organ'},
82
+ {facet: "show all", term:'species'},
83
+ {facet: "show all", term:'gender'},
84
+ {facet: "show all", term:'datasets'}] )
85
+ },
86
+ singleFacets: function(){
87
+ this.$refs.sideBar.openSearch('', [{facet: 'Heart', term:'organ'}])
81
88
  },
82
89
  multiFacets: function(){
83
90
  this.$refs.sideBar.openSearch('', [{facet: 'Rat', term:'species'}, {facet: 'Heart', term:'organ'}])
@@ -43,19 +43,16 @@ import lang from "element-ui/lib/locale/lang/en";
43
43
  import locale from "element-ui/lib/locale";
44
44
  import EventBus from "./EventBus"
45
45
  import scaffoldMetaMap from './scaffold-meta-map';
46
- import speciesMap from "./species-map"
46
+ import speciesMap from "./species-map";
47
47
 
48
48
  locale.use(lang);
49
49
  Vue.use(Button);
50
50
  Vue.use(Icon);
51
51
 
52
52
  const capitalise = function(string){
53
- return string.replace(/\b\w/g, v => v.toUpperCase())
53
+ return string.replace(/\b\w/g, v => v.toUpperCase());
54
54
  }
55
55
 
56
- const swapped = (obj)=>Object.fromEntries(Object.entries(obj).map(a => a.reverse()))
57
- const swappedSpeciesMap = swapped(speciesMap)
58
-
59
56
  export default {
60
57
  name: "DatasetCard",
61
58
  props: {
@@ -103,8 +100,8 @@ export default {
103
100
  text = this.entry.numberSamples + " samples";
104
101
  }
105
102
  if (this.entry.species) {
106
- if (swappedSpeciesMap[this.entry.species[0].toLowerCase()]){
107
- text += ` (${swappedSpeciesMap[this.entry.species[0].toLowerCase()]})`
103
+ if (speciesMap[this.entry.species[0].toLowerCase()]){
104
+ text += ` (${speciesMap[this.entry.species[0].toLowerCase()]})`
108
105
  } else {
109
106
  text += ` (${this.entry.species})`
110
107
  }
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="filters">
3
- <SvgSpriteColor />
3
+ <map-svg-sprite-color />
4
4
  <transition name="el-zoom-in-top">
5
5
  <span v-show="showFilters" class="search-filters transition-box">
6
6
  <custom-cascader
@@ -18,7 +18,7 @@
18
18
  @tags-changed="tagsChangedCallback"
19
19
  ></custom-cascader>
20
20
  <div v-if="showFiltersText" class="filter-default-value">
21
- <svg-icon icon="noun-filter" class="filter-icon-inside" />Apply Filters
21
+ <map-svg-icon icon="noun-filter" class="filter-icon-inside" />Apply Filters
22
22
  </div>
23
23
  </span>
24
24
  </transition>
@@ -43,22 +43,32 @@ import { Option, Select } from "element-ui";
43
43
  import CustomCascader from "./Cascader";
44
44
  import lang from "element-ui/lib/locale/lang/en";
45
45
  import locale from "element-ui/lib/locale";
46
- import { SvgIcon, SvgSpriteColor } from "@abi-software/svg-sprite";
47
- Vue.component("svg-icon", SvgIcon);
46
+ import speciesMap from "./species-map";
47
+ import { MapSvgIcon, MapSvgSpriteColor } from "@abi-software/svg-sprite";
48
48
 
49
49
  locale.use(lang);
50
50
  Vue.use(Option);
51
51
  Vue.use(Select);
52
52
 
53
- var capitalise = function(txt) {
53
+ const capitalise = function(txt) {
54
54
  return txt.charAt(0).toUpperCase() + txt.slice(1);
55
55
  };
56
56
 
57
+ const convertReadableLabel = function(original) {
58
+ const name = original.toLowerCase();
59
+ if (speciesMap[name]){
60
+ return capitalise(speciesMap[name]);
61
+ } else {
62
+ return capitalise(name);
63
+ }
64
+ }
65
+
57
66
  export default {
58
67
  name: "SearchFilters",
59
68
  components: {
60
69
  CustomCascader,
61
- SvgSpriteColor
70
+ MapSvgIcon,
71
+ MapSvgSpriteColor
62
72
  },
63
73
  props: {
64
74
  /**
@@ -117,7 +127,7 @@ export default {
117
127
  this.facets[i].toLowerCase(),
118
128
  undefined
119
129
  ),
120
- label: capitalise(this.facets[i]),
130
+ label: convertReadableLabel(this.facets[i]),
121
131
  children: []
122
132
  });
123
133
  promiseList.push(
@@ -127,9 +137,8 @@ export default {
127
137
  this.options[i].children.push({
128
138
  value: this.createCascaderItemValue(
129
139
  this.facets[i].toLowerCase(),
130
- labels[j].toLowerCase()
131
- ),
132
- label: capitalise(labels[j]) // Capitalisation is to match design specs
140
+ labels[j].toLowerCase()),
141
+ label: convertReadableLabel(labels[j]) // Capitalisation is to match design specs
133
142
  });
134
143
  }
135
144
  })
@@ -165,32 +174,6 @@ export default {
165
174
  switchTermToRequest: function(term) {
166
175
  return term.split(" ")[0].toLowerCase();
167
176
  },
168
- // updateLabels is used to show user how many are at each nested level.
169
- // i.e.: if 3 species are selected it will show 'Species (3)' in the cascader
170
- updateLabels: function(counts) {
171
- for (let i in counts) {
172
- switch (i) {
173
- case "species":
174
- this.options[0].label = this.options[0].label.split(" ")[0];
175
- if (counts[i] > 0) this.options[0].label += ` (${counts[i]})`;
176
- break;
177
- case "gender":
178
- this.options[1].label = this.options[1].label.split(" ")[0];
179
- if (counts[i] > 0) this.options[1].label += ` (${counts[i]})`;
180
- break;
181
- case "organ":
182
- this.options[2].label = this.options[2].label.split(" ")[0];
183
- if (counts[i] > 0) this.options[2].label += ` (${counts[i]})`;
184
- break;
185
- case "datasets":
186
- this.options[3].label = this.options[3].label.split(" ")[0];
187
- if (counts[i] > 0) this.options[3].label += ` (${counts[i]})`;
188
- break;
189
- default:
190
- break;
191
- }
192
- }
193
- },
194
177
  tagsChangedCallback: function(presentTags) {
195
178
  if (presentTags.length > 0) {
196
179
  this.showFiltersText = false;
@@ -232,7 +215,6 @@ export default {
232
215
  if (facetMaps[event[i][0]] === undefined) facetMaps[event[i][0]] = [];
233
216
  facetMaps[event[i][0]].push(event[i]);
234
217
  }
235
-
236
218
  // go through each facets
237
219
  for (const facet in facetMaps) {
238
220
  let showAll = undefined;
@@ -259,11 +241,33 @@ export default {
259
241
  modifiedEvent.push(...facetMaps[facet]);
260
242
  }
261
243
  }
262
- return modifiedEvent;
244
+ //Make sure the expanded item are sorted first.
245
+ return modifiedEvent.sort((a, b) => {
246
+ if (this.__expandItem__) {
247
+ if (a[0] == this.__expandItem__) {
248
+ if (b[0] == this.__expandItem__) {
249
+ return 0;
250
+ } else {
251
+ return -1;
252
+ }
253
+ } else if (b[0] == this.__expandItem__) {
254
+ if (a[0] == this.__expandItem__) {
255
+ return 0;
256
+ } else {
257
+ return 1;
258
+ }
259
+ } else {
260
+ return 0;
261
+ }
262
+ } else
263
+ return 0;
264
+ });
263
265
  }
264
266
  return event;
265
267
  },
266
- cascadeExpandChange: function() {
268
+ cascadeExpandChange: function(event) {
269
+ //work around as the expand item may change on modifying the cascade props
270
+ this.__expandItem__ = event;
267
271
  this.makeCascadeLabelsClickable();
268
272
  },
269
273
  numberShownChanged: function(event) {
@@ -291,7 +295,6 @@ export default {
291
295
  setCascader: function(filterFacets) {
292
296
  //Do not set the value unless it is ready
293
297
  if (this.cascaderIsReady) {
294
- let labelCounts = { species: 0, gender: 0, organ: 0, datasets: 0 };
295
298
  this.cascadeSelected = [];
296
299
  filterFacets.forEach(e => {
297
300
  this.cascadeSelected.push([
@@ -301,10 +304,8 @@ export default {
301
304
  e.facet.toLowerCase()
302
305
  )
303
306
  ]);
304
- labelCounts[e.term.toLowerCase()] += 1;
305
307
  });
306
308
  this.updatePreviousShowAllChecked(this.cascadeSelected);
307
- this.updateLabels(labelCounts);
308
309
  }
309
310
  },
310
311
  makeCascadeLabelsClickable: function() {
@@ -91,7 +91,6 @@ var initial_state = {
91
91
  results: [],
92
92
  numberOfHits: 0,
93
93
  filter: [],
94
- filterFacets: undefined,
95
94
  loadingCards: false,
96
95
  numberPerPage: 10,
97
96
  page: 1,
@@ -145,7 +144,7 @@ export default {
145
144
  filterEntry: function() {
146
145
  return {
147
146
  numberOfHits: this.numberOfHits,
148
- filterFacets: this.filterFacets
147
+ filterFacets: this.filter
149
148
  };
150
149
  }
151
150
  },
@@ -156,8 +155,8 @@ export default {
156
155
  this.resetPageNavigation();
157
156
  this.searchSciCrunch(search, filter, endpoint, params);
158
157
  if (filter) {
159
- this.filterFacets = [...filter];
160
- this.$refs.filtersRef.setCascader(this.filterFacets);
158
+ this.filter = [...filter];
159
+ this.$refs.filtersRef.setCascader(this.filter);
161
160
  }
162
161
  },
163
162
  clearSearchClicked: function() {
@@ -237,8 +236,11 @@ export default {
237
236
  }
238
237
  if (f)
239
238
  f.forEach(e => {
240
- term.push(e.term);
241
- facet.push(e.facet);
239
+ //Do not ask for any "show all" request
240
+ if (e.facet !== "show all") {
241
+ term.push(e.term);
242
+ facet.push(e.facet);
243
+ }
242
244
  });
243
245
  params.term = term;
244
246
  params.facet = facet;
@@ -327,9 +329,17 @@ export default {
327
329
  mounted: function() {
328
330
  // temporarily disable flatmap search since there are no datasets
329
331
  if (this.firstSearch === "Flatmap" || this.firstSearch === "flatmap") {
330
- this.openSearch("", []);
332
+ this.openSearch('', [
333
+ {facet: "show all", term:'species'},
334
+ {facet: "show all", term:'gender'},
335
+ {facet: "show all", term:'organ'},
336
+ {facet: "show all", term:'datasets'}]);
331
337
  } else {
332
- this.openSearch(this.firstSearch, []);
338
+ this.openSearch(this.firstSearch, [
339
+ {facet: "show all", term:'species'},
340
+ {facet: "show all", term:'gender'},
341
+ {facet: "show all", term:'organ'},
342
+ {facet: "show all", term:'datasets'}]);
333
343
  }
334
344
  },
335
345
  created: function() {
@@ -1,8 +1,8 @@
1
1
  export default {
2
- 'Human': 'homo sapiens',
3
- 'Rat': 'rattus norvegicus',
4
- 'Mouse': 'mus musculus',
5
- 'Pig': 'sus scrofa domesticus',
6
- 'Boar': 'sus scrofa',
7
- 'Cat': 'felis catus'
2
+ 'homo sapiens': 'Human',
3
+ 'rattus norvegicus': 'Rat',
4
+ 'mus musculus': 'Mouse',
5
+ 'sus scrofa domesticus': 'Pig',
6
+ 'sus scrofa': 'Boar',
7
+ 'felis catus': 'Cat'
8
8
  }