@abi-software/map-utilities 1.3.3-beta.0 → 1.3.3-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/map-utilities",
3
- "version": "1.3.3-beta.0",
3
+ "version": "1.3.3-beta.2",
4
4
  "files": [
5
5
  "dist/*",
6
6
  "src/*",
@@ -117,12 +117,15 @@
117
117
  {{ connectivityError.errorMessage }}
118
118
  </div>
119
119
 
120
+ <div v-if="loadingError" class="loading-error">
121
+ {{ loadingError }}
122
+ </div>
123
+
120
124
  </div>
121
125
  </template>
122
126
 
123
127
  <script>
124
128
  import { ConnectivityGraph } from './graph';
125
- import { capitalise } from '../utilities';
126
129
 
127
130
  const MIN_SCHEMA_VERSION = 1.3;
128
131
  const CACHE_LIFETIME = 24 * 60 * 60 * 1000; // One day
@@ -149,6 +152,10 @@ export default {
149
152
  type: String,
150
153
  default: '',
151
154
  },
155
+ sckanVersion: {
156
+ type: String,
157
+ default: '',
158
+ },
152
159
  selectedConnectivityData: {
153
160
  type: Array,
154
161
  default: [],
@@ -157,8 +164,10 @@ export default {
157
164
  data: function () {
158
165
  return {
159
166
  loading: true,
167
+ loadingError: '',
160
168
  connectivityGraph: null,
161
169
  selectedSource: '',
170
+ availableSources: [],
162
171
  pathList: [],
163
172
  schemaVersion: '',
164
173
  knowledgeByPath: new Map(),
@@ -176,41 +185,73 @@ export default {
176
185
  };
177
186
  },
178
187
  mounted() {
188
+ this.showSpinner();
179
189
  this.updateTooltipContainer();
180
190
  this.refreshCache();
181
191
  this.loadCacheData();
182
- this.run().then((res) => {
183
- this.showGraph(this.entry);
184
- });
192
+ this.run()
193
+ .then((res) => {
194
+ if (res?.success) {
195
+ this.showGraph(this.entry);
196
+ } else if (res?.error) {
197
+ this.loadingError = res.error;
198
+ } else {
199
+ this.loadingError = 'Loading error!';
200
+ }
201
+ this.hideSpinner();
202
+ })
203
+ .catch((error) => {
204
+ this.loadingError = 'Loading error!';
205
+ this.hideSpinner();
206
+ });
185
207
  },
186
208
  methods: {
187
209
  updateTooltipContainer: function () {
188
210
  this.connectivityGraphContainer = this.$refs.connectivityGraphRef;
189
211
  },
190
212
  loadCacheData: function () {
191
- const selectedSource = sessionStorage.getItem('connectivity-graph-source');
213
+ const availableSources = sessionStorage.getItem('connectivity-graph-sources');
192
214
  const labelCache = sessionStorage.getItem('connectivity-graph-labels');
193
215
  const pathList = sessionStorage.getItem('connectivity-graph-pathlist');
194
216
  const schemaVersion = sessionStorage.getItem('connectivity-graph-schema-version');
195
217
 
196
- if (selectedSource) {
197
- this.selectedSource = selectedSource;
218
+ // Use provided SCKAN version for the knowledge source
219
+ if (this.sckanVersion) {
220
+ this.selectedSource = this.sckanVersion;
198
221
  }
222
+ sessionStorage.setItem('connectivity-graph-selected-source', this.selectedSource);
223
+ this.updateCacheExpiry();
224
+
225
+ if (availableSources) {
226
+ this.availableSources = JSON.parse(availableSources);
227
+ }
228
+
199
229
  if (pathList) {
200
230
  this.pathList = JSON.parse(pathList);
201
231
  }
232
+
202
233
  if (labelCache) {
203
234
  const labelCacheObj = JSON.parse(labelCache);
204
235
  this.labelCache = new Map(Object.entries(labelCacheObj));
205
236
  }
237
+
206
238
  if (schemaVersion) {
207
239
  this.schemaVersion = schemaVersion;
208
240
  }
209
241
  },
242
+ isValidKnowledgeSource: function () {
243
+ const selectedSource = sessionStorage.getItem('connectivity-graph-selected-source');
244
+ if (this.sckanVersion && (this.sckanVersion !== selectedSource)) {
245
+ return false;
246
+ }
247
+ return true;
248
+ },
210
249
  removeAllCacheData: function () {
211
250
  const keys = [
212
251
  'connectivity-graph-expiry',
213
- 'connectivity-graph-source',
252
+ 'connectivity-graph-selected-source',
253
+ 'connectivity-graph-source', // to clear old data
254
+ 'connectivity-graph-sources',
214
255
  'connectivity-graph-labels',
215
256
  'connectivity-graph-pathlist',
216
257
  'connectivity-graph-schema-version',
@@ -222,8 +263,9 @@ export default {
222
263
  refreshCache: function () {
223
264
  const expiry = sessionStorage.getItem('connectivity-graph-expiry');
224
265
  const now = new Date();
266
+ const validKnowledgeSource = this.isValidKnowledgeSource();
225
267
 
226
- if (now.getTime() > expiry) {
268
+ if (now.getTime() > expiry || !validKnowledgeSource) {
227
269
  this.removeAllCacheData();
228
270
  }
229
271
  },
@@ -240,28 +282,32 @@ export default {
240
282
  this.updateCacheExpiry();
241
283
  }
242
284
  if (this.schemaVersion < MIN_SCHEMA_VERSION) {
243
- console.warn('No Server!');
244
- return;
285
+ return {
286
+ error: `No server available for schema-version ${this.schemaVersion}.`,
287
+ };
245
288
  }
246
- this.showSpinner();
247
- if (!this.selectedSource) {
248
- this.selectedSource = await this.setSourceList();
249
- sessionStorage.setItem('connectivity-graph-source', this.selectedSource);
250
- this.updateCacheExpiry();
289
+
290
+ if (!this.availableSources.length) {
291
+ this.availableSources = await this.loadAvailableSources();
292
+ }
293
+
294
+ if (!this.isSCKANVersionAvailable()) {
295
+ return {
296
+ error: `No data available for SCKAN version ${this.selectedSource}.`,
297
+ };
251
298
  }
299
+
252
300
  await this.setPathList(this.selectedSource);
253
- this.hideSpinner();
301
+ return {
302
+ success: true,
303
+ };
254
304
  },
255
305
  showGraph: async function (neuronPath) {
256
306
  const graphCanvas = this.$refs.graphCanvas;
257
307
 
258
- this.showSpinner();
259
-
260
308
  this.connectivityGraph = new ConnectivityGraph(this.labelCache, graphCanvas);
261
309
  await this.connectivityGraph.addConnectivity(this.knowledgeByPath.get(neuronPath));
262
310
 
263
- this.hideSpinner();
264
-
265
311
  this.connectivityGraph.showConnectivity(graphCanvas);
266
312
 
267
313
  // saved state from list view
@@ -303,25 +349,16 @@ export default {
303
349
  };
304
350
  }
305
351
  },
306
- setSourceList: async function () {
352
+ isSCKANVersionAvailable: function () {
353
+ return this.availableSources.includes(this.selectedSource);
354
+ },
355
+ loadAvailableSources: async function () {
307
356
  const data = await this.getJsonData(`${this.mapServer}knowledge/sources`);
308
357
  const sources = data ? (data.sources || []) : [];
309
-
310
- // Order with most recent first...
311
- let firstSource = '';
312
- const sourceList = [];
313
-
314
- for (const source of sources) {
315
- if (source) {
316
- sourceList.push(source);
317
-
318
- if (firstSource === '') {
319
- firstSource = source;
320
- }
321
- }
322
- }
323
-
324
- return firstSource;
358
+ const filteredSources = sources.filter((source) => source); // filter null values
359
+ sessionStorage.setItem('connectivity-graph-sources', JSON.stringify(filteredSources));
360
+ this.updateCacheExpiry();
361
+ return filteredSources;
325
362
  },
326
363
  loadPathData: async function (source) {
327
364
  const data = await this.query(
@@ -641,6 +678,15 @@ export default {
641
678
  white-space: nowrap;
642
679
  width: 1px;
643
680
  }
681
+
682
+ .loading-error {
683
+ position: absolute;
684
+ inset: 0;
685
+ display: flex;
686
+ align-items: center;
687
+ justify-content: center;
688
+ background-color: var(--el-mask-color);
689
+ }
644
690
  </style>
645
691
 
646
692
  <style lang="scss">
@@ -14,7 +14,6 @@ declare module 'vue' {
14
14
  CreateTooltipContent: typeof import('./components/Tooltip/CreateTooltipContent.vue')['default']
15
15
  DrawToolbar: typeof import('./components/DrawToolbar/DrawToolbar.vue')['default']
16
16
  ElButton: typeof import('element-plus/es')['ElButton']
17
- ElCard: typeof import('element-plus/es')['ElCard']
18
17
  ElCol: typeof import('element-plus/es')['ElCol']
19
18
  ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
20
19
  ElContainer: typeof import('element-plus/es')['ElContainer']