@abi-software/map-side-bar 1.3.32 → 1.3.34
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/LICENSE +201 -201
- package/README.md +146 -146
- package/babel.config.js +14 -14
- package/dist/map-side-bar.common.js +226 -242
- package/dist/map-side-bar.common.js.map +1 -1
- package/dist/map-side-bar.css +1 -1
- package/dist/map-side-bar.umd.js +226 -242
- package/dist/map-side-bar.umd.js.map +1 -1
- package/dist/map-side-bar.umd.min.js +1 -1
- package/dist/map-side-bar.umd.min.js.map +1 -1
- package/package-lock.json +13716 -13716
- package/package.json +67 -67
- package/public/index.html +17 -17
- package/src/App.vue +152 -149
- package/src/algolia/algolia.js +182 -182
- package/src/algolia/utils.js +69 -69
- package/src/components/BadgesGroup.vue +142 -141
- package/src/components/Cascader.vue +49 -49
- package/src/components/ContextCard.vue +381 -381
- package/src/components/DatasetCard.vue +325 -325
- package/src/components/EventBus.js +3 -3
- package/src/components/ImageGallery.vue +515 -515
- package/src/components/SearchFilters.vue +609 -609
- package/src/components/SideBar.vue +224 -245
- package/src/components/SidebarContent.vue +508 -508
- package/src/components/Tabs.vue +78 -78
- package/src/components/hardcoded-context-info.js +79 -79
- package/src/components/index.js +8 -8
- package/src/components/species-map.js +8 -8
- package/src/main.js +8 -8
- package/static.json +6 -6
- package/vue.config.js +11 -11
- package/del.json +0 -27
- package/delte.json +0 -30
- package/scaffold_context_info.json +0 -31
- package/src/components/processFilters.js +0 -22
|
@@ -1,381 +1,381 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="context-card-container" ref="container">
|
|
3
|
-
<div v-show="showContextCard">
|
|
4
|
-
<div v-show="showDetails" class="hide" @click="showDetails = !showDetails">Hide information<i class="el-icon-arrow-up"></i></div>
|
|
5
|
-
<div v-show="!showDetails" class="hide" @click="showDetails = !showDetails">Show information<i class="el-icon-arrow-down"></i></div>
|
|
6
|
-
<el-card v-if="showDetails && Object.keys(contextData).length !== 0" v-loading="loading" class="context-card" >
|
|
7
|
-
<div class="card-left">
|
|
8
|
-
<img :src="banner" class="context-image">
|
|
9
|
-
</div>
|
|
10
|
-
<div class="card-right scrollbar">
|
|
11
|
-
<div class="title">{{contextData.heading}}</div>
|
|
12
|
-
<div v-html="parseMarkdown(contextData.description)"/>
|
|
13
|
-
<br/>
|
|
14
|
-
|
|
15
|
-
<!-- Show sampeles and views seperately if they do not match -->
|
|
16
|
-
<template v-if="!samplesUnderViews">
|
|
17
|
-
<div v-if="contextData.views && contextData.views.length > 0" class="subtitle">Scaffold Views</div>
|
|
18
|
-
<template v-for="(view, i) in contextData.views">
|
|
19
|
-
<div v-bind:key="i+'_1'" @click="openViewFile(view)" class="context-card-view">
|
|
20
|
-
<img class="view-image" :src="getFileFromPath(view.thumbnail)">
|
|
21
|
-
<div class="view-description">{{view.description}}</div>
|
|
22
|
-
</div>
|
|
23
|
-
<div v-bind:key="i" class="padding"/>
|
|
24
|
-
</template>
|
|
25
|
-
<div style="margin-bottom: 16px;"/>
|
|
26
|
-
<div v-if="contextData.samples && contextData.samples.length > 0" class="subtitle">Samples on Scaffold</div>
|
|
27
|
-
<template v-for="(sample, i) in contextData.samples">
|
|
28
|
-
<span v-bind:key="i+'_3'" class="context-card-item cursor-pointer" @click="toggleSampleDetails(i)">
|
|
29
|
-
<div v-bind:key="i+'_6'" style="display: flex">
|
|
30
|
-
<div v-if="sample.color" class="color-box" :style="'background-color:'+ sample.color"></div>
|
|
31
|
-
<img class="key-image" v-else-if="sample.thumbnail" :src="getFileFromPath(sample.thumbnail)">
|
|
32
|
-
{{sample.heading}}
|
|
33
|
-
<i class="el-icon-warning-outline info"></i>
|
|
34
|
-
</div>
|
|
35
|
-
</span>
|
|
36
|
-
<div v-bind:key="i+'_4'" v-if="sampleDetails[i]" v-html="sample.description"/>
|
|
37
|
-
<a v-bind:key="i+'_5'" v-if="sampleDetails[i] && sample.path" :href="generateFileLink(sample)" target="_blank">View Source</a>
|
|
38
|
-
<div v-bind:key="i+'_2'" class="padding"/>
|
|
39
|
-
</template>
|
|
40
|
-
</template>
|
|
41
|
-
|
|
42
|
-
<!-- Show samples under views if the ids match -->
|
|
43
|
-
<template v-else>
|
|
44
|
-
<div v-if="contextData.views && contextData.views.length > 0" class="subtitle">Scaffold Views</div>
|
|
45
|
-
<template v-for="(view, i) in contextData.views">
|
|
46
|
-
<span :key="i+'_1'" @click="viewClicked(view, i)" class="context-card-view">
|
|
47
|
-
<img class="view-image" :src="getFileFromPath(view.thumbnail)"/>
|
|
48
|
-
<div class="view-description">{{view.description}}<i class="el-icon-warning-outline info"></i> </div>
|
|
49
|
-
</span>
|
|
50
|
-
<div v-if="sampleDetails[i]" v-html="samplesMatching(view.id).description" :key="i+'_2'"/>
|
|
51
|
-
<a v-bind:key="i+'_5'" v-if="sampleDetails[i] && samplesMatching(view.id).path" :href="generateFileLink(samplesMatching(view.id))" target="_blank">View Source</a>
|
|
52
|
-
<div :key="i" class="padding"/>
|
|
53
|
-
|
|
54
|
-
<!-- Extra padding if sample details is open -->
|
|
55
|
-
<div :key="i+'_6'" v-if="sampleDetails[i]" class="padding"/>
|
|
56
|
-
</template>
|
|
57
|
-
</template>
|
|
58
|
-
</div>
|
|
59
|
-
</el-card>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
</template>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
<script>
|
|
66
|
-
/* eslint-disable no-alert, no-console */
|
|
67
|
-
import Vue from "vue";
|
|
68
|
-
import { Link, Icon, Card, Button, Select, Input } from "element-ui";
|
|
69
|
-
import lang from "element-ui/lib/locale/lang/en";
|
|
70
|
-
import locale from "element-ui/lib/locale";
|
|
71
|
-
import EventBus from "./EventBus"
|
|
72
|
-
import hardcoded_info from './hardcoded-context-info'
|
|
73
|
-
|
|
74
|
-
import { marked } from 'marked'
|
|
75
|
-
import xss from 'xss'
|
|
76
|
-
|
|
77
|
-
locale.use(lang);
|
|
78
|
-
Vue.use(Link);
|
|
79
|
-
Vue.use(Icon);
|
|
80
|
-
Vue.use(Card);
|
|
81
|
-
Vue.use(Button);
|
|
82
|
-
Vue.use(Select);
|
|
83
|
-
Vue.use(Input);
|
|
84
|
-
|
|
85
|
-
const addFilesToPathIfMissing = function(path){
|
|
86
|
-
if (!path.includes('files')){
|
|
87
|
-
return 'files/' + path
|
|
88
|
-
} else {
|
|
89
|
-
return path
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const convertBackslashToForwardSlash = function(path){
|
|
94
|
-
path = path.replaceAll('\\','/')
|
|
95
|
-
path = path.replaceAll('\\\\', '/')
|
|
96
|
-
return path
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// const switchPathToDirectory = function(path){
|
|
100
|
-
// let newPath = path.split('/')
|
|
101
|
-
// newPath.pop()
|
|
102
|
-
// return newPath.join('/')
|
|
103
|
-
// }
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
export default {
|
|
107
|
-
name: "contextCard",
|
|
108
|
-
props: {
|
|
109
|
-
/**
|
|
110
|
-
* Object containing information for
|
|
111
|
-
* the required viewing.
|
|
112
|
-
*/
|
|
113
|
-
entry: Object,
|
|
114
|
-
envVars: Object,
|
|
115
|
-
},
|
|
116
|
-
data: function () {
|
|
117
|
-
return {
|
|
118
|
-
contextData: {},
|
|
119
|
-
showDetails: true,
|
|
120
|
-
showContextCard: true,
|
|
121
|
-
sampleDetails: {},
|
|
122
|
-
loading: false
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
watch: {
|
|
126
|
-
'entry.contextCardUrl': {
|
|
127
|
-
handler(val){
|
|
128
|
-
if (val) {
|
|
129
|
-
// used for hardcoding data
|
|
130
|
-
if (val === true){
|
|
131
|
-
this.contextData = hardcoded_info[this.entry.discoverId]
|
|
132
|
-
} else {
|
|
133
|
-
this.getContextFile(val)
|
|
134
|
-
this.showContextCard = true
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
this.showContextCard = false
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
immediate: true
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
computed: {
|
|
144
|
-
samplesUnderViews: function(){
|
|
145
|
-
if (this.contextData){
|
|
146
|
-
if (this.contextData.samplesUnderViews){
|
|
147
|
-
return true
|
|
148
|
-
} else {
|
|
149
|
-
let viewId = this.contextData.views.map(v=>v.id)
|
|
150
|
-
let samplesView = this.contextData.samples.map(s=>s.view)
|
|
151
|
-
|
|
152
|
-
// get matching values
|
|
153
|
-
let matching = viewId.filter(v=>samplesView.includes(v))
|
|
154
|
-
|
|
155
|
-
// check all arrays have the same length (which means all values are in all three)
|
|
156
|
-
if ( viewId.length === matching.length && matching.length === samplesView.length){
|
|
157
|
-
return true
|
|
158
|
-
}
|
|
159
|
-
return false
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else return false
|
|
163
|
-
},
|
|
164
|
-
banner: function(){
|
|
165
|
-
if (this.contextData.banner){
|
|
166
|
-
return this.getFileFromPath(this.contextData.banner)
|
|
167
|
-
} else if (this.contextData && this.contextData.views && this.contextData.views.length > 0) {
|
|
168
|
-
if(this.contextData.views[0].thumbnail){
|
|
169
|
-
return this.getFileFromPath(this.contextData.views[0].thumbnail)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return this.entry.banner
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
methods: {
|
|
176
|
-
samplesMatching: function(viewId){
|
|
177
|
-
if (this.contextData && this.contextData.samples){
|
|
178
|
-
return this.contextData.samples.filter(s=>s.view == viewId)[0]
|
|
179
|
-
}
|
|
180
|
-
else return []
|
|
181
|
-
},
|
|
182
|
-
viewClicked: function(view, i){
|
|
183
|
-
this.openViewFile(view)
|
|
184
|
-
this.toggleSampleDetails(i)
|
|
185
|
-
},
|
|
186
|
-
getContextFile: function (contextFileUrl) {
|
|
187
|
-
this.loading = true
|
|
188
|
-
fetch(contextFileUrl)
|
|
189
|
-
.then((response) =>{
|
|
190
|
-
if (!response.ok){
|
|
191
|
-
throw Error(response.statusText)
|
|
192
|
-
} else {
|
|
193
|
-
return response.json()
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
.then((data) => {
|
|
197
|
-
this.contextData = data
|
|
198
|
-
this.loading = false
|
|
199
|
-
this.addDiscoverIdsToContextData()
|
|
200
|
-
})
|
|
201
|
-
.catch((err) => {
|
|
202
|
-
//set defaults if we hit an error
|
|
203
|
-
console.error('caught error!', err)
|
|
204
|
-
this.thumbnail = require('@/../assets/missing-image.svg')
|
|
205
|
-
this.discoverId = undefined
|
|
206
|
-
this.loading = false
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
removeDoubleFilesPath: function(path){
|
|
210
|
-
if (path.includes('files/')){
|
|
211
|
-
return path.replace('files/', '')
|
|
212
|
-
} else if (path.includes('files\\')) {
|
|
213
|
-
return path.replace('files\\', '')
|
|
214
|
-
} else {
|
|
215
|
-
return path
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
toggleSampleDetails: function(i){
|
|
219
|
-
if (this.sampleDetails[i] === undefined){
|
|
220
|
-
Vue.set(this.sampleDetails, i, true)
|
|
221
|
-
} else {
|
|
222
|
-
Vue.set(this.sampleDetails, i, !this.sampleDetails[i])
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
getFileFromPath: function(path){
|
|
226
|
-
// for hardcoded data
|
|
227
|
-
if(this.entry.contextCardUrl === true){
|
|
228
|
-
return path
|
|
229
|
-
}
|
|
230
|
-
path = this.removeDoubleFilesPath(path)
|
|
231
|
-
return `${this.envVars.API_LOCATION}s3-resource/${this.entry.discoverId}/${this.entry.version}/files/${path}`
|
|
232
|
-
},
|
|
233
|
-
// This is used later when generateing links to the resource on sparc.science (see generateFileLink)
|
|
234
|
-
addDiscoverIdsToContextData(){
|
|
235
|
-
this.contextData.samples.forEach((sample, i)=>{
|
|
236
|
-
if (sample && sample.doi && sample.doi !== ""){
|
|
237
|
-
fetch(`${this.envVars.PENNSIEVE_API_LOCATION}/discover/datasets/doi/${this.splitDoiFromUrl(sample.doi)}`)
|
|
238
|
-
.then((response) => response.json())
|
|
239
|
-
.then((data) => {
|
|
240
|
-
this.contextData.samples[i].discoverId = data.id
|
|
241
|
-
this.contextData.samples[i].version = data.version
|
|
242
|
-
})
|
|
243
|
-
} else {
|
|
244
|
-
this.contextData.samples[i].discoverId = this.entry.discoverId
|
|
245
|
-
this.contextData.samples[i].version = this.entry.version
|
|
246
|
-
}
|
|
247
|
-
})
|
|
248
|
-
},
|
|
249
|
-
processPathForUrl(path){
|
|
250
|
-
path = convertBackslashToForwardSlash(path)
|
|
251
|
-
path = addFilesToPathIfMissing(path)
|
|
252
|
-
return encodeURI(path)
|
|
253
|
-
},
|
|
254
|
-
splitDoiFromUrl(url){
|
|
255
|
-
return url.split('https://doi.org/').pop()
|
|
256
|
-
},
|
|
257
|
-
generateFileLink(sample){
|
|
258
|
-
return `${this.envVars.ROOT_URL}/file/${sample.discoverId}/${sample.version}?path=${this.processPathForUrl(sample.path)}`
|
|
259
|
-
|
|
260
|
-
},
|
|
261
|
-
parseMarkdown(markdown){
|
|
262
|
-
return xss(marked.parse(markdown))
|
|
263
|
-
},
|
|
264
|
-
openViewFile: function(view){
|
|
265
|
-
// note that we assume that the view file is in the same directory as the scaffold (viewUrls take relative paths)
|
|
266
|
-
this.entry.viewUrl = `${this.envVars.API_LOCATION}s3-resource/${this.entry.discoverId}/${this.entry.version}/${view.path}`
|
|
267
|
-
this.entry.type = 'Scaffold View'
|
|
268
|
-
EventBus.$emit("PopoverActionClick", this.entry)
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
</script>
|
|
273
|
-
|
|
274
|
-
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
275
|
-
<style scoped>
|
|
276
|
-
|
|
277
|
-
.hide{
|
|
278
|
-
color: #e4e7ed;
|
|
279
|
-
cursor: pointer;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
.context-card{
|
|
283
|
-
background-color: white;
|
|
284
|
-
max-height: 10 50px;
|
|
285
|
-
padding: 8px;
|
|
286
|
-
font-size: 14px;
|
|
287
|
-
margin-bottom: 18px;
|
|
288
|
-
position: relative;
|
|
289
|
-
border: solid 1px #e4e7ed;
|
|
290
|
-
display: flex;
|
|
291
|
-
width: 500px;
|
|
292
|
-
max-height: 258px;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
.context-card-view{
|
|
296
|
-
cursor: pointer;
|
|
297
|
-
padding-bottom: 8px;
|
|
298
|
-
display: flex;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
.view-image {
|
|
302
|
-
width: 34px;
|
|
303
|
-
height: 34px;
|
|
304
|
-
flex: 1;
|
|
305
|
-
margin-right: 4px;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
.view-descriptions {
|
|
309
|
-
flex: 8;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
.context-card >>> .el-card__body {
|
|
313
|
-
padding: 0px;
|
|
314
|
-
display: flex;
|
|
315
|
-
width: 516px;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
.context-image{
|
|
319
|
-
width: 250px;
|
|
320
|
-
height: auto;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
.color-box {
|
|
324
|
-
width: 16px;
|
|
325
|
-
height: 16px;
|
|
326
|
-
border: solid 1px #8300bf;
|
|
327
|
-
border-radius: 2px;
|
|
328
|
-
margin-right: 8px;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
.card-left{
|
|
332
|
-
flex: 1
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
.card-right {
|
|
336
|
-
flex: 1.3;
|
|
337
|
-
padding-left: 6px;
|
|
338
|
-
overflow-y: scroll;
|
|
339
|
-
scrollbar-width: thin;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
.cursor-pointer {
|
|
343
|
-
cursor: pointer;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
.info{
|
|
347
|
-
transform: rotate(180deg);
|
|
348
|
-
color: #8300bf;
|
|
349
|
-
margin-left: 8px;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
.padding {
|
|
353
|
-
padding-bottom: 8px;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
.title{
|
|
357
|
-
font-weight: bold;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
.subtitle{
|
|
361
|
-
font-weight: bold;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
.scrollbar::-webkit-scrollbar-track {
|
|
365
|
-
border-radius: 10px;
|
|
366
|
-
background-color: #f5f5f5;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
.scrollbar::-webkit-scrollbar {
|
|
370
|
-
width: 12px;
|
|
371
|
-
right: -12px;
|
|
372
|
-
background-color: #f5f5f5;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
.scrollbar::-webkit-scrollbar-thumb {
|
|
376
|
-
border-radius: 4px;
|
|
377
|
-
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.06);
|
|
378
|
-
background-color: #979797;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="context-card-container" ref="container">
|
|
3
|
+
<div v-show="showContextCard">
|
|
4
|
+
<div v-show="showDetails" class="hide" @click="showDetails = !showDetails">Hide information<i class="el-icon-arrow-up"></i></div>
|
|
5
|
+
<div v-show="!showDetails" class="hide" @click="showDetails = !showDetails">Show information<i class="el-icon-arrow-down"></i></div>
|
|
6
|
+
<el-card v-if="showDetails && Object.keys(contextData).length !== 0" v-loading="loading" class="context-card" >
|
|
7
|
+
<div class="card-left">
|
|
8
|
+
<img :src="banner" class="context-image">
|
|
9
|
+
</div>
|
|
10
|
+
<div class="card-right scrollbar">
|
|
11
|
+
<div class="title">{{contextData.heading}}</div>
|
|
12
|
+
<div v-html="parseMarkdown(contextData.description)"/>
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<!-- Show sampeles and views seperately if they do not match -->
|
|
16
|
+
<template v-if="!samplesUnderViews">
|
|
17
|
+
<div v-if="contextData.views && contextData.views.length > 0" class="subtitle">Scaffold Views</div>
|
|
18
|
+
<template v-for="(view, i) in contextData.views">
|
|
19
|
+
<div v-bind:key="i+'_1'" @click="openViewFile(view)" class="context-card-view">
|
|
20
|
+
<img class="view-image" :src="getFileFromPath(view.thumbnail)">
|
|
21
|
+
<div class="view-description">{{view.description}}</div>
|
|
22
|
+
</div>
|
|
23
|
+
<div v-bind:key="i" class="padding"/>
|
|
24
|
+
</template>
|
|
25
|
+
<div style="margin-bottom: 16px;"/>
|
|
26
|
+
<div v-if="contextData.samples && contextData.samples.length > 0" class="subtitle">Samples on Scaffold</div>
|
|
27
|
+
<template v-for="(sample, i) in contextData.samples">
|
|
28
|
+
<span v-bind:key="i+'_3'" class="context-card-item cursor-pointer" @click="toggleSampleDetails(i)">
|
|
29
|
+
<div v-bind:key="i+'_6'" style="display: flex">
|
|
30
|
+
<div v-if="sample.color" class="color-box" :style="'background-color:'+ sample.color"></div>
|
|
31
|
+
<img class="key-image" v-else-if="sample.thumbnail" :src="getFileFromPath(sample.thumbnail)">
|
|
32
|
+
{{sample.heading}}
|
|
33
|
+
<i class="el-icon-warning-outline info"></i>
|
|
34
|
+
</div>
|
|
35
|
+
</span>
|
|
36
|
+
<div v-bind:key="i+'_4'" v-if="sampleDetails[i]" v-html="sample.description"/>
|
|
37
|
+
<a v-bind:key="i+'_5'" v-if="sampleDetails[i] && sample.path" :href="generateFileLink(sample)" target="_blank">View Source</a>
|
|
38
|
+
<div v-bind:key="i+'_2'" class="padding"/>
|
|
39
|
+
</template>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<!-- Show samples under views if the ids match -->
|
|
43
|
+
<template v-else>
|
|
44
|
+
<div v-if="contextData.views && contextData.views.length > 0" class="subtitle">Scaffold Views</div>
|
|
45
|
+
<template v-for="(view, i) in contextData.views">
|
|
46
|
+
<span :key="i+'_1'" @click="viewClicked(view, i)" class="context-card-view">
|
|
47
|
+
<img class="view-image" :src="getFileFromPath(view.thumbnail)"/>
|
|
48
|
+
<div class="view-description">{{view.description}}<i class="el-icon-warning-outline info"></i> </div>
|
|
49
|
+
</span>
|
|
50
|
+
<div v-if="sampleDetails[i]" v-html="samplesMatching(view.id).description" :key="i+'_2'"/>
|
|
51
|
+
<a v-bind:key="i+'_5'" v-if="sampleDetails[i] && samplesMatching(view.id).path" :href="generateFileLink(samplesMatching(view.id))" target="_blank">View Source</a>
|
|
52
|
+
<div :key="i" class="padding"/>
|
|
53
|
+
|
|
54
|
+
<!-- Extra padding if sample details is open -->
|
|
55
|
+
<div :key="i+'_6'" v-if="sampleDetails[i]" class="padding"/>
|
|
56
|
+
</template>
|
|
57
|
+
</template>
|
|
58
|
+
</div>
|
|
59
|
+
</el-card>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
<script>
|
|
66
|
+
/* eslint-disable no-alert, no-console */
|
|
67
|
+
import Vue from "vue";
|
|
68
|
+
import { Link, Icon, Card, Button, Select, Input } from "element-ui";
|
|
69
|
+
import lang from "element-ui/lib/locale/lang/en";
|
|
70
|
+
import locale from "element-ui/lib/locale";
|
|
71
|
+
import EventBus from "./EventBus"
|
|
72
|
+
import hardcoded_info from './hardcoded-context-info'
|
|
73
|
+
|
|
74
|
+
import { marked } from 'marked'
|
|
75
|
+
import xss from 'xss'
|
|
76
|
+
|
|
77
|
+
locale.use(lang);
|
|
78
|
+
Vue.use(Link);
|
|
79
|
+
Vue.use(Icon);
|
|
80
|
+
Vue.use(Card);
|
|
81
|
+
Vue.use(Button);
|
|
82
|
+
Vue.use(Select);
|
|
83
|
+
Vue.use(Input);
|
|
84
|
+
|
|
85
|
+
const addFilesToPathIfMissing = function(path){
|
|
86
|
+
if (!path.includes('files')){
|
|
87
|
+
return 'files/' + path
|
|
88
|
+
} else {
|
|
89
|
+
return path
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const convertBackslashToForwardSlash = function(path){
|
|
94
|
+
path = path.replaceAll('\\','/')
|
|
95
|
+
path = path.replaceAll('\\\\', '/')
|
|
96
|
+
return path
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// const switchPathToDirectory = function(path){
|
|
100
|
+
// let newPath = path.split('/')
|
|
101
|
+
// newPath.pop()
|
|
102
|
+
// return newPath.join('/')
|
|
103
|
+
// }
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export default {
|
|
107
|
+
name: "contextCard",
|
|
108
|
+
props: {
|
|
109
|
+
/**
|
|
110
|
+
* Object containing information for
|
|
111
|
+
* the required viewing.
|
|
112
|
+
*/
|
|
113
|
+
entry: Object,
|
|
114
|
+
envVars: Object,
|
|
115
|
+
},
|
|
116
|
+
data: function () {
|
|
117
|
+
return {
|
|
118
|
+
contextData: {},
|
|
119
|
+
showDetails: true,
|
|
120
|
+
showContextCard: true,
|
|
121
|
+
sampleDetails: {},
|
|
122
|
+
loading: false
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
watch: {
|
|
126
|
+
'entry.contextCardUrl': {
|
|
127
|
+
handler(val){
|
|
128
|
+
if (val) {
|
|
129
|
+
// used for hardcoding data
|
|
130
|
+
if (val === true){
|
|
131
|
+
this.contextData = hardcoded_info[this.entry.discoverId]
|
|
132
|
+
} else {
|
|
133
|
+
this.getContextFile(val)
|
|
134
|
+
this.showContextCard = true
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
this.showContextCard = false
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
immediate: true
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
computed: {
|
|
144
|
+
samplesUnderViews: function(){
|
|
145
|
+
if (this.contextData){
|
|
146
|
+
if (this.contextData.samplesUnderViews){
|
|
147
|
+
return true
|
|
148
|
+
} else {
|
|
149
|
+
let viewId = this.contextData.views.map(v=>v.id)
|
|
150
|
+
let samplesView = this.contextData.samples.map(s=>s.view)
|
|
151
|
+
|
|
152
|
+
// get matching values
|
|
153
|
+
let matching = viewId.filter(v=>samplesView.includes(v))
|
|
154
|
+
|
|
155
|
+
// check all arrays have the same length (which means all values are in all three)
|
|
156
|
+
if ( viewId.length === matching.length && matching.length === samplesView.length){
|
|
157
|
+
return true
|
|
158
|
+
}
|
|
159
|
+
return false
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else return false
|
|
163
|
+
},
|
|
164
|
+
banner: function(){
|
|
165
|
+
if (this.contextData.banner){
|
|
166
|
+
return this.getFileFromPath(this.contextData.banner)
|
|
167
|
+
} else if (this.contextData && this.contextData.views && this.contextData.views.length > 0) {
|
|
168
|
+
if(this.contextData.views[0].thumbnail){
|
|
169
|
+
return this.getFileFromPath(this.contextData.views[0].thumbnail)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return this.entry.banner
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
methods: {
|
|
176
|
+
samplesMatching: function(viewId){
|
|
177
|
+
if (this.contextData && this.contextData.samples){
|
|
178
|
+
return this.contextData.samples.filter(s=>s.view == viewId)[0]
|
|
179
|
+
}
|
|
180
|
+
else return []
|
|
181
|
+
},
|
|
182
|
+
viewClicked: function(view, i){
|
|
183
|
+
this.openViewFile(view)
|
|
184
|
+
this.toggleSampleDetails(i)
|
|
185
|
+
},
|
|
186
|
+
getContextFile: function (contextFileUrl) {
|
|
187
|
+
this.loading = true
|
|
188
|
+
fetch(contextFileUrl)
|
|
189
|
+
.then((response) =>{
|
|
190
|
+
if (!response.ok){
|
|
191
|
+
throw Error(response.statusText)
|
|
192
|
+
} else {
|
|
193
|
+
return response.json()
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
.then((data) => {
|
|
197
|
+
this.contextData = data
|
|
198
|
+
this.loading = false
|
|
199
|
+
this.addDiscoverIdsToContextData()
|
|
200
|
+
})
|
|
201
|
+
.catch((err) => {
|
|
202
|
+
//set defaults if we hit an error
|
|
203
|
+
console.error('caught error!', err)
|
|
204
|
+
this.thumbnail = require('@/../assets/missing-image.svg')
|
|
205
|
+
this.discoverId = undefined
|
|
206
|
+
this.loading = false
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
removeDoubleFilesPath: function(path){
|
|
210
|
+
if (path.includes('files/')){
|
|
211
|
+
return path.replace('files/', '')
|
|
212
|
+
} else if (path.includes('files\\')) {
|
|
213
|
+
return path.replace('files\\', '')
|
|
214
|
+
} else {
|
|
215
|
+
return path
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
toggleSampleDetails: function(i){
|
|
219
|
+
if (this.sampleDetails[i] === undefined){
|
|
220
|
+
Vue.set(this.sampleDetails, i, true)
|
|
221
|
+
} else {
|
|
222
|
+
Vue.set(this.sampleDetails, i, !this.sampleDetails[i])
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
getFileFromPath: function(path){
|
|
226
|
+
// for hardcoded data
|
|
227
|
+
if(this.entry.contextCardUrl === true){
|
|
228
|
+
return path
|
|
229
|
+
}
|
|
230
|
+
path = this.removeDoubleFilesPath(path)
|
|
231
|
+
return `${this.envVars.API_LOCATION}s3-resource/${this.entry.discoverId}/${this.entry.version}/files/${path}`
|
|
232
|
+
},
|
|
233
|
+
// This is used later when generateing links to the resource on sparc.science (see generateFileLink)
|
|
234
|
+
addDiscoverIdsToContextData(){
|
|
235
|
+
this.contextData.samples.forEach((sample, i)=>{
|
|
236
|
+
if (sample && sample.doi && sample.doi !== ""){
|
|
237
|
+
fetch(`${this.envVars.PENNSIEVE_API_LOCATION}/discover/datasets/doi/${this.splitDoiFromUrl(sample.doi)}`)
|
|
238
|
+
.then((response) => response.json())
|
|
239
|
+
.then((data) => {
|
|
240
|
+
this.contextData.samples[i].discoverId = data.id
|
|
241
|
+
this.contextData.samples[i].version = data.version
|
|
242
|
+
})
|
|
243
|
+
} else {
|
|
244
|
+
this.contextData.samples[i].discoverId = this.entry.discoverId
|
|
245
|
+
this.contextData.samples[i].version = this.entry.version
|
|
246
|
+
}
|
|
247
|
+
})
|
|
248
|
+
},
|
|
249
|
+
processPathForUrl(path){
|
|
250
|
+
path = convertBackslashToForwardSlash(path)
|
|
251
|
+
path = addFilesToPathIfMissing(path)
|
|
252
|
+
return encodeURI(path)
|
|
253
|
+
},
|
|
254
|
+
splitDoiFromUrl(url){
|
|
255
|
+
return url.split('https://doi.org/').pop()
|
|
256
|
+
},
|
|
257
|
+
generateFileLink(sample){
|
|
258
|
+
return `${this.envVars.ROOT_URL}/file/${sample.discoverId}/${sample.version}?path=${this.processPathForUrl(sample.path)}`
|
|
259
|
+
|
|
260
|
+
},
|
|
261
|
+
parseMarkdown(markdown){
|
|
262
|
+
return xss(marked.parse(markdown))
|
|
263
|
+
},
|
|
264
|
+
openViewFile: function(view){
|
|
265
|
+
// note that we assume that the view file is in the same directory as the scaffold (viewUrls take relative paths)
|
|
266
|
+
this.entry.viewUrl = `${this.envVars.API_LOCATION}s3-resource/${this.entry.discoverId}/${this.entry.version}/${view.path}`
|
|
267
|
+
this.entry.type = 'Scaffold View'
|
|
268
|
+
EventBus.$emit("PopoverActionClick", this.entry)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
</script>
|
|
273
|
+
|
|
274
|
+
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
275
|
+
<style scoped>
|
|
276
|
+
|
|
277
|
+
.hide{
|
|
278
|
+
color: #e4e7ed;
|
|
279
|
+
cursor: pointer;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.context-card{
|
|
283
|
+
background-color: white;
|
|
284
|
+
max-height: 10 50px;
|
|
285
|
+
padding: 8px;
|
|
286
|
+
font-size: 14px;
|
|
287
|
+
margin-bottom: 18px;
|
|
288
|
+
position: relative;
|
|
289
|
+
border: solid 1px #e4e7ed;
|
|
290
|
+
display: flex;
|
|
291
|
+
width: 500px;
|
|
292
|
+
max-height: 258px;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.context-card-view{
|
|
296
|
+
cursor: pointer;
|
|
297
|
+
padding-bottom: 8px;
|
|
298
|
+
display: flex;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.view-image {
|
|
302
|
+
width: 34px;
|
|
303
|
+
height: 34px;
|
|
304
|
+
flex: 1;
|
|
305
|
+
margin-right: 4px;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.view-descriptions {
|
|
309
|
+
flex: 8;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.context-card >>> .el-card__body {
|
|
313
|
+
padding: 0px;
|
|
314
|
+
display: flex;
|
|
315
|
+
width: 516px;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.context-image{
|
|
319
|
+
width: 250px;
|
|
320
|
+
height: auto;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.color-box {
|
|
324
|
+
width: 16px;
|
|
325
|
+
height: 16px;
|
|
326
|
+
border: solid 1px #8300bf;
|
|
327
|
+
border-radius: 2px;
|
|
328
|
+
margin-right: 8px;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.card-left{
|
|
332
|
+
flex: 1
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.card-right {
|
|
336
|
+
flex: 1.3;
|
|
337
|
+
padding-left: 6px;
|
|
338
|
+
overflow-y: scroll;
|
|
339
|
+
scrollbar-width: thin;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.cursor-pointer {
|
|
343
|
+
cursor: pointer;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
.info{
|
|
347
|
+
transform: rotate(180deg);
|
|
348
|
+
color: #8300bf;
|
|
349
|
+
margin-left: 8px;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.padding {
|
|
353
|
+
padding-bottom: 8px;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.title{
|
|
357
|
+
font-weight: bold;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.subtitle{
|
|
361
|
+
font-weight: bold;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.scrollbar::-webkit-scrollbar-track {
|
|
365
|
+
border-radius: 10px;
|
|
366
|
+
background-color: #f5f5f5;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.scrollbar::-webkit-scrollbar {
|
|
370
|
+
width: 12px;
|
|
371
|
+
right: -12px;
|
|
372
|
+
background-color: #f5f5f5;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
.scrollbar::-webkit-scrollbar-thumb {
|
|
376
|
+
border-radius: 4px;
|
|
377
|
+
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.06);
|
|
378
|
+
background-color: #979797;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
</style>
|