/
MapContent.vue
280 lines (268 loc) · 8.79 KB
/
MapContent.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<template>
<div
ref="MapApp"
v-loading="!isReady"
class="mapcontent"
element-loading-text="Loading..."
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(0, 0, 0, 0.3)"
>
<map-svg-sprite-color/>
<SplitFlow
v-if="isReady"
@onFullscreen="onFullscreen"
:state="stateToSet"
ref="flow"
@hook:mounted="flowMounted"
/>
</div>
</template>
<script>
/* eslint-disable no-alert, no-console */
import Vue from "vue";
import SplitFlow from './SplitFlow';
import EventBus from './EventBus';
import store from '../store';
import { findSpeciesKey } from './scripts/utilities.js';
import {MapSvgSpriteColor} from '@abi-software/svg-sprite';
import { initialState } from "./scripts/utilities.js";
import { Loading } from "element-ui";
import lang from "element-ui/lib/locale/lang/en";
import locale from "element-ui/lib/locale";
locale.use(lang);
Vue.use(Loading.directive);
/**
* Content of the app. More work flows will be added here.
*/
export default {
name: "MapContent",
components: {
SplitFlow,
MapSvgSpriteColor,
},
props: {
shareLink: {
type: String,
default: undefined
},
state: {
type: Object,
default: undefined
},
options: {
type: Object,
default: () => {}
},
//New option to start the map in AC, FC or WholeBody
startingMap: {
type: String,
default: "AC"
}
},
data: function () {
return {
isReady: false,
initialState: undefined,
}
},
methods: {
isFullscreen: function(){
return (document.fullscreenElement || document.webkitFullscreenElement ||
document.mozFullScreenElement || document.msFullscreenElement )
},
onFullscreen: function(fullscreenReq) {
//If a request is sent, try it
if (fullscreenReq !== undefined){
if (fullscreenReq && !this.isFullscreen()){
this.goFullscreen()
}
if(!fullscreenReq && this.isFullscreen()){
this.leaveFullscreen()
}
}
// Else we toggle fullscreen
else{
if(this.isFullscreen()){
this.leaveFullscreen()
} else {
this.goFullscreen()
}
}
},
leaveFullscreen: function(){
if (this.isFullscreen()) {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
}
},
goFullscreen: function(){
let mapApp = this.$refs.MapApp;
if (mapApp.requestFullscreen) {
mapApp.requestFullscreen();
} else if (mapApp.mozRequestFullScreen) { /* Firefox */
mapApp.mozRequestFullScreen();
} else if (mapApp.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
mapApp.webkitRequestFullscreen();
} else if (parent.msRequestFullscreen) { /* IE/Edge */
mapApp.msRequestFullscreen();
}
},
setState: function(state){
return this.$refs.flow.setState(state);
},
getState: function(){
return this.$refs.flow.getState();
},
/**
* Provide a way to set the current view, this is currently limited
* to setting view for flatmapm, multiflatmap or scaffold.
* In the case of the multiflatmap, it will not create a new entry and
* instead change the current entry by setting the state.
*
*/
setCurrentEntry: function(state) {
if (state && state.type) {
if (state.type === "Scaffold" && state.url) {
//State for scaffold containing the following items:
// label - Setting the name of the dialog
// region - Which region/group currently focusing on
// resource - the url to metadata
// state - state to restore (viewport)
// viewUrl - relative path of the view file to metadata
const newView = {
type: state.type,
label: state.label,
region: state.region,
resource: state.url,
state: state.state,
viewUrl: state.viewUrl
};
this.$refs.flow.createNewEntry(newView);
} else if (state.type === "MultiFlatmap") {
//State for scaffold containing the following items:
// label - Setting the name of the dialog
// taxo - taxo of species to set
// biologicalSex - biological sex to be displayed (PATO)
// organ - Target organ, flatmap will conduct a local search
// using this
//Look for the key in the available species array,
//it will use the taxo and biologicalSex as hints.
const key = findSpeciesKey(state);
if (key) {
const currentState = this.getState();
if (currentState && currentState.entries) {
for (let i = 0; i < currentState.entries.length; i++) {
const entry = currentState.entries[i];
if (entry.type === "MultiFlatmap") {
entry.resource = key;
entry.state = {species: key};
if (state.organ || state.uuid) {
entry.state.state = { searchTerm: state.organ, uuid: state.uuid };
//if it contains an uuid, use the taxo to help identify if the uuid
//is current
if (state.uuid) entry.state.state.entry = state.taxo;
}
this.$refs.flow.setState(currentState);
//Do not create a new entry, instead set the multiflatmap viewer
//to the primary slot
this.$refs.flow.setIdToPrimaryPane(entry.id);
break;
}
}
}
}
}
else if (state.type === "Flatmap") {
//State for scaffold containing the following items:
// label - Setting the name of the dialog
// region - Which region/group currently focusing on
// resource - the url to metadata
// state - state to restore (viewport)
// viewUrl - relative path of the view file to metadata
const newView = {
type: state.type,
resource: state.resource,
state: state.state,
label: state.label
};
this.$refs.flow.createNewEntry(newView);
}
}
},
/**
* Open the sidebar with the specified facets and query.
*/
openSearch: function(facets, query) {
return this.$refs.flow.openSearch(facets, query);
},
flowMounted: function () {
this._flowMounted = true;
this.$emit("isReady");
},
},
computed: {
stateToSet() {
return this.state ? this.state : this.initialState;
},
},
watch: {
"shareLink" : {
handler: function (newLink) {
store.commit("settings/updateShareLink", newLink);
},
immediate: true,
},
},
beforeMount: function() {
if (this.options) {
// Split options prop up to commit to the store
this.options.sparcApi ? store.commit("settings/updateSparcAPI", this.options.sparcApi) : null
this.options.algoliaIndex ? store.commit("settings/updateAlgoliaIndex", this.options.algoliaIndex) : null
this.options.algoliaKey ? store.commit("settings/updateAlgoliaKey", this.options.algoliaKey) : null
this.options.algoliaId ? store.commit("settings/updateAlgoliaId", this.options.algoliaId) : null
this.options.pennsieveApi ? store.commit("settings/updatePennsieveApi", this.options.pennsieveApi) : null
this.options.flatmapAPI ? store.commit("settings/updateFlatmapAPI", this.options.flatmapAPI) : null,
this.options.nlLinkPrefix ? store.commit("settings/updateNLLinkPrefix", this.options.nlLinkPrefix) : null
this.options.rootUrl ? store.commit("settings/updateRootUrl", this.options.rootUrl) : null
}
},
mounted: async function() {
EventBus.$on("updateShareLinkRequested", () => {
this.$emit("updateShareLinkRequested");
});
if (!this.state) {
this.initialState = await initialState(this.startingMap, this.options.sparcApi);
}
this.isReady = true;
}
}
</script>
<style scoped lang="scss">
@import "@/assets/styles";
@import "~element-ui/packages/theme-chalk/src/loading";
::v-deep .el-loading-spinner {
i, .el-loading-text {
color: $app-primary-color;
}
}
.map-help-dialog {
position: fixed;
z-index: 20;
bottom: 30px;
right: 30px;
}
.mapcontent {
height: 100%;
width:100%;
z-index:1;
}
</style>
<style src="@/../assets/styleguide.css">
</style>