@abi-software/map-side-bar 1.2.3 → 1.3.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.
@@ -0,0 +1,505 @@
1
+ <template>
2
+ <div class="full-size">
3
+ <gallery
4
+ :bottomSpacer="bottomSpacer"
5
+ :cardWidth="10"
6
+ :items="galleryItems"
7
+ :max-width="maxWidth"
8
+ :show-indicator-bar="false"
9
+ :show-card-details="true"
10
+ :highlight-active="false"
11
+ :image-style="imageStyle"
12
+ :image-container-style="imageContainerStyle"
13
+ :body-style="bodyStyle"
14
+ :shadow="shadow"
15
+ @card-clicked="cardClicked"
16
+ ref="gallery"
17
+ />
18
+ </div>
19
+ </template>
20
+
21
+ <script>
22
+ /* eslint-disable no-alert, no-console */
23
+ const baseName = (str) => {
24
+ return str.split("\\").pop().split("/").pop();
25
+ };
26
+
27
+ const capitalise = function (string) {
28
+ return string.replace(/\b\w/g, (v) => v.toUpperCase());
29
+ };
30
+
31
+ import GalleryHelper from "@abi-software/gallery/src/mixins/GalleryHelpers";
32
+ import Gallery from "@abi-software/gallery";
33
+ import "@abi-software/gallery/dist/gallery.css";
34
+
35
+ export default {
36
+ name: "ImageGallery",
37
+ components: { Gallery },
38
+ mixins: [GalleryHelper],
39
+ props: {
40
+ datasetBiolucida: {
41
+ type: Object,
42
+ default: () => {
43
+ return {};
44
+ },
45
+ },
46
+ envVars: {
47
+ type: Object,
48
+ default: () => {},
49
+ },
50
+ label: {
51
+ type: String,
52
+ default: "",
53
+ },
54
+ plots: {
55
+ type: Array,
56
+ default: () => {
57
+ return [];
58
+ },
59
+ },
60
+ datasetId: {
61
+ type: Number,
62
+ default: -1,
63
+ },
64
+ datasetVersion: {
65
+ type: Number,
66
+ default: -1,
67
+ },
68
+ datasetThumbnail: {
69
+ type: String,
70
+ default: "",
71
+ },
72
+ category: {
73
+ type: String,
74
+ default: "All",
75
+ },
76
+ entry: {
77
+ type: Object,
78
+ default: () => {
79
+ return {};
80
+ },
81
+ },
82
+ },
83
+ data() {
84
+ return {
85
+ currentIndex: 0,
86
+ ro: null,
87
+ maxWidth: 3,
88
+ items: {
89
+ "Biolucida Images": [],
90
+ 'Dataset': [],
91
+ 'Images': [],
92
+ 'Scaffolds': [],
93
+ 'Segmentations': [],
94
+ 'Simulations': [],
95
+ 'Videos': [],
96
+ 'Plots': [],
97
+ },
98
+ bodyStyle: { padding: '0px', background: '#ffffff' },
99
+ imageContainerStyle: {
100
+ width: '160px',
101
+ height: '160px',
102
+ display: 'flex',
103
+ alignItems: 'center',
104
+ justifyContent: 'center',
105
+ },
106
+ imageStyle: { maxWidth: '160px', maxHeight: '160px'},
107
+ shadow: "never",
108
+ bottomSpacer: { minHeight: '0rem' },
109
+ resetIndex: false
110
+ };
111
+ },
112
+ methods: {
113
+ cardClicked: function(payload) {
114
+ this.$emit('card-clicked', payload);
115
+ },
116
+ createSciCurnchItems: function () {
117
+ this.createDatasetItem();
118
+ this.createScaffoldItems();
119
+ this.createSimulationItems();
120
+ this.createPlotItems();
121
+ this.createSegmentationItems();
122
+ /* Disable these two
123
+ this.createImageItems();
124
+ this.createVideoItems();
125
+ */
126
+ },
127
+ createDatasetItem: function () {
128
+ const link = `${this.envVars.ROOT_URL}/datasets/${this.datasetId}?type=dataset`
129
+ if (this.datasetThumbnail) {
130
+ this.items['Dataset'].push({
131
+ id: -1,
132
+ //Work around gallery requires a truthy string
133
+ title: " ",
134
+ type: `Dataset ${this.datasetId}`,
135
+ thumbnail: this.datasetThumbnail,
136
+ link,
137
+ hideType: true,
138
+ hideTitle: true,
139
+ });
140
+ }
141
+ },
142
+ createImageItems: function () {
143
+ if (this.entry.images) {
144
+ this.entry.images.forEach((image) => {
145
+ const filePath = image.dataset.path;
146
+ const id = image.identifier;
147
+ const linkUrl = `${this.envVars.ROOT_URL}/datasets/imageviewer?dataset_id=${this.datasetId}&dataset_version=${this.datasetVersion}&file_path=${filePath}&mimetype=${image.mimetype.name}`;
148
+ this.items['Images'].push({
149
+ id,
150
+ title: baseName(filePath),
151
+ type: "Image",
152
+ link: linkUrl,
153
+ hideType: true,
154
+ });
155
+ });
156
+ }
157
+ },
158
+ createPlotItems: function () {
159
+ if (this.entry.plots) {
160
+ this.entry.plots.forEach((plot) => {
161
+ const filePath = plot.dataset.path;
162
+ const id = plot.identifier;
163
+ const thumbnail = this.getThumbnailForPlot(plot, this.entry.thumbnails);
164
+ let thumbnailURL = undefined;
165
+ let mimetype = '';
166
+ if (thumbnail) {
167
+ thumbnailURL = this.getImageURLFromS3(this.envVars.API_LOCATION, {
168
+ id,
169
+ datasetId: this.datasetId,
170
+ datasetVersion: this.datasetVersion,
171
+ file_path: thumbnail.dataset.path,
172
+ });
173
+ mimetype = thumbnail.mimetype.name;
174
+ }
175
+ const plotAnnotation = plot.datacite;
176
+ const filePathPrefix = `${this.envVars.API_LOCATION}/s3-resource/${this.datasetId}/${this.datasetVersion}/files/`;
177
+ const sourceUrl = filePathPrefix + plot.dataset.path;
178
+
179
+ const metadata = JSON.parse(
180
+ plotAnnotation.supplemental_json_metadata.description
181
+ );
182
+
183
+ let supplementalData = [];
184
+ if (plotAnnotation.isDescribedBy) {
185
+ supplementalData.push({
186
+ url: filePathPrefix + plotAnnotation.isDescribedBy.path
187
+ });
188
+ }
189
+
190
+ const resource = {
191
+ dataSource: {url: sourceUrl},
192
+ metadata,
193
+ supplementalData
194
+ }
195
+
196
+ let action = {
197
+ label: capitalise(this.label),
198
+ resource: resource,
199
+ title: "View plot",
200
+ type: "Plot",
201
+ discoverId: this.discoverId,
202
+ version: this.datasetVersion,
203
+ };
204
+ this.items['Plots'].push({
205
+ id,
206
+ title: baseName(filePath),
207
+ type: "Plot",
208
+ thumbnail: thumbnailURL,
209
+ userData: action,
210
+ hideType: true,
211
+ mimetype
212
+ });
213
+ });
214
+ }
215
+ },
216
+ createScaffoldItems: function () {
217
+ if (this.entry.scaffolds) {
218
+ let index = 0;
219
+ this.entry.scaffolds.forEach((scaffold) => {
220
+ const filePath = scaffold.dataset.path;
221
+ const id = scaffold.identifier;
222
+ const thumbnail = this.getThumbnailForScaffold(
223
+ scaffold,
224
+ this.entry.scaffoldViews,
225
+ this.entry.thumbnails,
226
+ index
227
+ );
228
+ let mimetype = '';
229
+ let thumbnailURL = undefined;
230
+ if (thumbnail) {
231
+ thumbnailURL = this.getImageURLFromS3(this.envVars.API_LOCATION, {
232
+ id,
233
+ datasetId: this.datasetId,
234
+ datasetVersion: this.datasetVersion,
235
+ file_path: thumbnail.dataset.path,
236
+ });
237
+ mimetype = thumbnail.mimetype.name;
238
+ }
239
+ let action = {
240
+ label: capitalise(this.label),
241
+ resource: `${this.envVars.API_LOCATION}s3-resource/${this.datasetId}/${this.datasetVersion}/files/${filePath}`,
242
+ title: "View 3D scaffold",
243
+ type: "Scaffold",
244
+ discoverId: this.datasetId,
245
+ apiLocation: this.envVars.API_LOCATION,
246
+ version: this.datasetVersion,
247
+ banner: this.datasetThumbnail,
248
+ contextCardUrl: this.entry.contextualInformation ? `${this.envVars.API_LOCATION}s3-resource/${this.datasetId}/${this.datasetVersion}/files/${this.entry.contextualInformation}` : undefined,
249
+ };
250
+ this.items['Scaffolds'].push({
251
+ id,
252
+ title: baseName(filePath),
253
+ type: "Scaffold",
254
+ thumbnail: thumbnailURL,
255
+ userData: action,
256
+ hideType: true,
257
+ mimetype
258
+ });
259
+ });
260
+ }
261
+ },
262
+ createSegmentationItems: function () {
263
+ if (this.entry.segmentation) {
264
+ this.entry.segmentation.forEach((segmentation) => {
265
+ const id = segmentation.id;
266
+ let filePath = segmentation.dataset.path;
267
+ filePath = filePath.replaceAll(" ", "_");
268
+ filePath = filePath.replaceAll(",", "_");
269
+ const prefix = this.envVars.NL_LINK_PREFIX;
270
+ const resource = {
271
+ share_link: `${prefix}/dataviewer?datasetId=${this.datasetId}&version=${this.datasetVersion}&path=files/${filePath}`,
272
+ };
273
+ let action = {
274
+ label: capitalise(this.label),
275
+ resource: resource,
276
+ datasetId: this.datasetId,
277
+ title: "View segmentation",
278
+ type: "Segmentation",
279
+ };
280
+ const thumbnailURL = this.getSegmentationThumbnailURL(
281
+ this.envVars.API_LOCATION,
282
+ {
283
+ id,
284
+ datasetId: this.datasetId,
285
+ datasetVersion: this.datasetVersion,
286
+ segmentationFilePath: filePath,
287
+ }
288
+ );
289
+ this.items['Segmentations'].push({
290
+ id,
291
+ title: baseName(filePath),
292
+ type: "Segmentation",
293
+ thumbnail: thumbnailURL,
294
+ userData: action,
295
+ hideType: true,
296
+ mimetype: 'image/png',
297
+ });
298
+ });
299
+ }
300
+ },
301
+ createSimulationItems: function () {
302
+ if (this.entry.simulation && this.entry.simulation.length > 0) {
303
+ let action = {
304
+ label: undefined,
305
+ apiLocation: this.envVars.API_LOCATION,
306
+ version: this.datasetVersion,
307
+ title: "View simulation",
308
+ type: "Simulation",
309
+ name: this.entry.name,
310
+ description: this.entry.description,
311
+ discoverId: this.datasetId,
312
+ dataset: `${this.envVars.ROOT_URL}/datasets/${this.datasetId}?type=dataset`
313
+ };
314
+ this.items['Simulations'].push({
315
+ id: "simulation",
316
+ title: " ",
317
+ type: "Simulation",
318
+ hideType: true,
319
+ hideTitle: true,
320
+ userData: action,
321
+ });
322
+ }
323
+ },
324
+ createVideoItems: function () {
325
+ if (this.entry.videos) {
326
+ this.entry.videos.forEach((video) => {
327
+ const filePath = this.getS3FilePath(
328
+ this.datasetId,
329
+ this.datasetVersion,
330
+ video.dataset.path
331
+ );
332
+ const linkUrl = `${this.envVars.ROOT_URL}/datasets/videoviewer?dataset_version=${this.datasetVersion}&dataset_id=${this.datasetId}&file_path=${filePath}&mimetype=${video.mimetype.name}`;
333
+ this.items['Videos'].push({
334
+ title: video.name,
335
+ type: "Video",
336
+ thumbnail: this.defaultVideoImg,
337
+ hideType: true,
338
+ link: linkUrl,
339
+ });
340
+ });
341
+ }
342
+ },
343
+ onResize: function () {
344
+ this.maxWidth = this.$el.clientWidth;
345
+ // this.$emit('resize', this.$el.clientWidth)
346
+ },
347
+ },
348
+ computed: {
349
+ galleryItems() {
350
+ if (this.resetIndex) {
351
+ this.$refs.gallery.indicatorClicked(0);
352
+ }
353
+ let items = [...this.items["Dataset"]];
354
+ if (this.category === "All") {
355
+ for (const [key, value] of Object.entries(this.items)) {
356
+ if (key !== "Dataset")
357
+ items = items.concat(value);
358
+ }
359
+ return items;
360
+ }
361
+ else
362
+ return this.items[this.category];
363
+ },
364
+ },
365
+ created: function () {
366
+ this.createSciCurnchItems();
367
+ },
368
+ watch: {
369
+ category: function() {
370
+ this.resetIndex = true;
371
+ },
372
+ galleryItems: function() {
373
+ this.resetIndex = false;
374
+ },
375
+ datasetBiolucida: {
376
+ deep: true,
377
+ immediate: true,
378
+ handler: function (biolucidaData) {
379
+ let items = [];
380
+ if ("dataset_images" in biolucidaData) {
381
+ items.push(
382
+ ...Array.from(biolucidaData.dataset_images, (dataset_image) => {
383
+ const thumbnailURL = this.getThumbnailURLFromBiolucida(
384
+ this.envVars.API_LOCATION,
385
+ {
386
+ id: dataset_image.image_id,
387
+ }
388
+ );
389
+ const resource = {
390
+ share_link: dataset_image.share_link,
391
+ id: dataset_image.image_id,
392
+ itemId: dataset_image.sourcepkg_id,
393
+ };
394
+ let action = {
395
+ label: capitalise(this.label),
396
+ resource: resource,
397
+ datasetId: this.datasetId,
398
+ title: "View image",
399
+ name: capitalise(this.label),
400
+ type: "Biolucida",
401
+ };
402
+ return {
403
+ id: dataset_image.image_id,
404
+ title: `Biolucida Image`,
405
+ type: "Image",
406
+ thumbnail: thumbnailURL,
407
+ userData: action,
408
+ mimetype: 'image/png',
409
+ hideType: true,
410
+ };
411
+ })
412
+ );
413
+ }
414
+ this.items['Biolucida Images'] = items;
415
+ },
416
+ },
417
+ },
418
+ mounted() {
419
+ this.ro = new ResizeObserver(this.onResize).observe(this.$el);
420
+ },
421
+ destroyed() {
422
+ delete this.ro;
423
+ },
424
+ };
425
+ </script>
426
+
427
+ <style scoped>
428
+ .full-size {
429
+ height: 100%;
430
+ width: 244px;
431
+ }
432
+
433
+ .key-image-span.active {
434
+ transform: scale(1.16);
435
+ border: 4px #8300bf solid;
436
+ }
437
+
438
+ .key-image-span {
439
+ display: flex;
440
+ position: relative;
441
+ }
442
+
443
+ .overlay {
444
+ position: absolute;
445
+ right: 5px;
446
+ top: 5px;
447
+ width: 1.61em;
448
+ height: 1em;
449
+ border-radius: 3px;
450
+ opacity: 0.8;
451
+ }
452
+
453
+ img {
454
+ vertical-align: bottom;
455
+ }
456
+
457
+ a.prev,
458
+ a.next {
459
+ display: flex;
460
+ font-size: 3em;
461
+ }
462
+
463
+ a.prev:not(.underline),
464
+ a.next:not(.underline) {
465
+ text-decoration: none;
466
+ }
467
+
468
+ a.prev {
469
+ justify-content: flex-start;
470
+ }
471
+
472
+ a.next {
473
+ justify-content: flex-end;
474
+ }
475
+
476
+ .standard-gallery {
477
+ display: flex;
478
+ flex-wrap: nowrap;
479
+ justify-content: space-around;
480
+ align-items: center;
481
+ }
482
+
483
+ .image-line {
484
+ display: flex;
485
+ margin-top: 1%;
486
+ margin-bottom: 1%;
487
+ flex-grow: 1;
488
+ justify-content: space-between;
489
+ }
490
+ .disabled {
491
+ opacity: 0.2;
492
+ cursor: default;
493
+ }
494
+
495
+ .rectangle {
496
+ height: 1em;
497
+ width: 2em;
498
+ border-radius: 3px;
499
+ background-color: #555;
500
+ }
501
+
502
+ .full-size >>> .el-card {
503
+ border: 0px;
504
+ }
505
+ </style>