/
SplitFlow.vue
414 lines (404 loc) · 12.2 KB
/
SplitFlow.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<template>
<el-container style="height: 100%; background: white">
<el-header
ref="header"
style="text-align: left; font-size: 14px; padding: 0"
height="32px"
class="dialog-header"
>
<DialogToolbarContent
:numberOfEntries="entries.length"
@onFullscreen="onFullscreen"
@local-search="onDisplaySearch"
@fetch-suggestions="fetchSuggestions"
ref="dialogToolbar"
/>
</el-header>
<el-main class="dialog-main">
<div
style="width: 100%; height: 100%; position: relative; overflow: hidden"
>
<SideBar
ref="sideBar"
:envVars="envVars"
:visible="sideBarVisibility"
:class="['side-bar', { 'start-up': startUp }]"
:activeId="activeDockedId"
:open-at-start="startUp"
@actionClick="actionClick"
@tabClicked="tabClicked"
@search-changed="searchChanged($event)"
@contextUpdate="contextUpdate($event)"
/>
<SplitDialog
:entries="entries"
ref="splitdialog"
@resource-selected="resourceSelected"
/>
</div>
</el-main>
</el-container>
</template>
<script>
/* eslint-disable no-alert, no-console */
import DialogToolbarContent from "./DialogToolbarContent.vue";
import EventBus from "./EventBus";
import SplitDialog from "./SplitDialog.vue";
// import contextCards from './context-cards'
import { SideBar } from "@abi-software/map-side-bar";
import { capitalise, getNewMapEntry, initialDefaultState } from "./scripts/utilities.js";
import { mapStores } from 'pinia';
import { useEntriesStore } from '../stores/entries';
import { useSettingsStore } from '../stores/settings';
import { useSplitFlowStore } from '../stores/splitFlow';
import {
ElContainer as Container,
ElHeader as Header,
ElMain as Main,
} from "element-plus";
import "@abi-software/map-side-bar/dist/style.css";
/**
* Component of the floating dialogs.
*/
export default {
name: "SplitFlow",
components: {
Container,
Header,
Main,
DialogToolbarContent,
SplitDialog,
SideBar,
},
props: {
state: {
type: Object,
default: undefined,
}
},
data: function () {
return {
sideBarVisibility: true,
startUp: true,
search: '',
activeDockedId : 1,
}
},
watch: {
state: {
handler: function (value) {
if (value) {
if (!this._externalStateSet) this.setState(value);
this._externalStateSet = true;
}
},
immediate: true,
},
},
methods: {
/**
* Callback when an action is performed (open new dialogs).
*/
actionClick: function (action) {
if (action) {
if (action.type == "Search") {
if (action.nervePath) {
this.openSearch([action.filter], action.label);
} else {
this.openSearch([], action.term);
}
} else if (action.type == "URL") {
window.open(action.resource, "_blank");
} else if (action.type == "Facet") {
if (this.$refs.sideBar) {
this.$refs.sideBar.addFilter(action);
}
} else if (action.type == "Facets") {
const facets = [];
this.settingsStore.facets.species.forEach(e => {
facets.push({
facet: capitalise(e),
term: "Species",
facetPropPath: "organisms.primary.species.name",
});
});
if (facets.length == 0)
facets.push({
facet: "Show All",
term: "Species",
facetPropPath: "organisms.primary.species.name",
});
facets.push(
...action.labels.map(val => ({
facet: capitalise(val),
term: "Anatomical structure",
facetPropPath: "anatomy.organ.category.name",
}))
);
if (this.$refs.sideBar) {
this.$refs.sideBar.openSearch(facets, "");
}
} else {
this.createNewEntry(action);
}
}
},
onDisplaySearch: function (payload) {
let searchFound = false;
//Search all active viewers when global callback is on
let splitdialog = this.$refs.splitdialog;
if (splitdialog) {
const activeContents = splitdialog.getActiveContents();
activeContents.forEach(content => {
if (content.search(payload.term)) {
searchFound = true;
}
});
}
this.$refs.dialogToolbar.setFailedSearch(searchFound ? undefined : payload.term);
},
fetchSuggestions: function(payload) {
const suggestions = [];
//Search all active viewers when global callback is on
let splitdialog = this.$refs.splitdialog;
const activeContents = splitdialog.getActiveContents();
//Push new suggestions into the pre-existing suggestions array
activeContents.forEach(content => content.searchSuggestions(payload.data.term, suggestions));
const unique = new Set(suggestions);
suggestions.length = 0;
for (const item of unique) {
suggestions.push({"value": "\"" + item +"\""});
}
payload.data.cb(suggestions);
},
searchChanged: function (data) {
if (data && data.type == "query-update") {
this.search = data.value;
}
if (data && data.type == "filter-update") {
this.settingsStore.updateFacets(data.value);
}
if (data && data.type == "available-facets") {
this.settingsStore.updateFacetLabels(data.value.labels);
this.settingsStore.updateMarkers(data.value.uberons);
EventBus.emit("markerUpdate");
}
},
getNewEntryId: function() {
if (this.entries.length) {
return (this.entries[this.entries.length - 1]).id + 1;
}
return 1;
},
/**
* Activate Synchronised workflow
*/
activateSyncMap: function (data) {
let newEntry = {};
Object.assign(newEntry, data);
newEntry.mode = "normal";
newEntry.id = this.getNewEntryId();
newEntry.state = undefined;
newEntry.type = "Scaffold";
newEntry.discoverId = data.discoverId;
newEntry.rotation = "free";
if (data.layout == "2vertpanel") newEntry.rotation = "horizontal";
else if (data.layout == "2horpanel") newEntry.rotation = "vertical";
this.entriesStore.addNewEntry(newEntry);
this.splitFlowStore.setSyncMode({
flag: true,
newId: newEntry.id,
layout: data.layout,
});
return newEntry.id;
},
/**
* Add new entry which will sequentially create a
* new dialog.
*/
createNewEntry: function (data) {
let newEntry = {};
newEntry.viewUrl = undefined;
newEntry.state = undefined;
Object.assign(newEntry, data);
newEntry.mode = "normal";
newEntry.id = this.getNewEntryId();
newEntry.discoverId = data.discoverId;
this.entriesStore.addNewEntry(newEntry);
this.splitFlowStore.setIdToPrimaryPane(newEntry.id);
if (this.splitFlowStore.syncMode) {
this.splitFlowStore.setSyncMode({ flag: false });
}
//close sidebar on entry creation to see the context card
if (this.$refs.sideBar) {
this.$refs.sideBar.setDrawerOpen(false);
}
return newEntry.id;
},
openNewMap: async function (type) {
const entry = await getNewMapEntry(type, this.settingsStore.sparcApi);
this.createNewEntry(entry);
if (entry.contextCard) {
EventBus.emit("contextUpdate", entry.contextCard);
}
},
openSearch: function (facets, query) {
// Keep the species facets currently unused
// let facets = [{facet: "All species", facetPropPath: 'organisms.primary.species.name', term:'species'}];
// this.settingsStore.facets.species.forEach(e => {
// facets.push({facet: e, facetPropPath: 'organisms.primary.species.name', term:'species'});
// });
this.search = query;
this._facets = facets;
if (this.$refs && this.$refs.sideBar) {
this.$refs.sideBar.openSearch(facets, query);
}
this.startUp = false;
},
onFullscreen: function (val) {
this.$emit("onFullscreen", val);
},
resetApp: function () {
this.setState(initialDefaultState());
},
setIdToPrimaryPane: function (id) {
this.splitFlowStore.setIdToPrimaryPane(id);
},
setState: function (state) {
this.entriesStore.setAll(state.entries);
//Support both old and new permalink.
if (state.splitFlow) this.splitFlowStore.setState(state.splitFlow);
else this.entries.forEach(entry => this.splitFlowStore.setIdToPrimaryPane(entry.id));
},
getState: function () {
let state = JSON.parse(JSON.stringify(this.entriesStore.$state));
let splitdialog = this.$refs.splitdialog;
let dialogStates = splitdialog.getContentsState();
if (state.entries.length === dialogStates.length) {
for (let i = 0; i < dialogStates.length; i++) {
const entry = state.entries[i];
entry.state = dialogStates[i];
//We do not want to serialise the following properties
if (entry.type === "Scaffold" && "viewUrl" in entry)
delete entry.viewUrl;
if (entry.type === "MultiFlatmap" && "uberonId" in entry)
delete entry.uberonId;
}
}
state.splitFlow = this.splitFlowStore.getState();
return state;
},
removeEntry: function (id) {
let index = this.entriesStore.findIndexOfId(id);
this.entriesStore.destroyEntry(index);
},
resourceSelected: function (result) {
this.$emit("resource-selected", result);
if (this.splitFlowStore.globalCallback) {
this.$refs.splitdialog.sendSynchronisedEvent(result);
}
},
tabClicked: function (id) {
this.activeDockedId = id;
},
toggleSyncMode: function (payload) {
if (payload) {
if (payload.flag) {
if (payload.action) {
this.activateSyncMap(payload.action);
}
} else {
if (this.splitFlowStore.syncMode) {
this.splitFlowStore.setSyncMode({
flag: false,
});
}
}
}
},
contextUpdate: function (payload) {
EventBus.emit("contextUpdate", payload);
}
},
created: function () {
this._facets = [];
this._externalStateSet = false;
},
mounted: function () {
EventBus.on("RemoveEntryRequest", id => {
this.removeEntry(id);
});
EventBus.on("SyncModeRequest", payload => {
this.toggleSyncMode(payload);
});
EventBus.on("PopoverActionClick", payload => {
this.actionClick(payload);
});
EventBus.on("OpenNewMap", type => {
this.openNewMap(type);
});
this.$nextTick(() => {
if (this.search === "" && this._facets.length === 0) {
if (this.$refs.sideBar) {
this.$refs.sideBar.close();
}
setTimeout(() => {
this.startUp = false;
}, 2000);
} else this.openSearch(this._facets, this.search);
});
},
computed: {
...mapStores(useEntriesStore, useSettingsStore, useSplitFlowStore),
envVars: function () {
return {
API_LOCATION: this.settingsStore.sparcApi,
ALGOLIA_INDEX: this.settingsStore.algoliaIndex,
ALGOLIA_KEY: this.settingsStore.algoliaKey,
ALGOLIA_ID: this.settingsStore.algoliaId,
PENNSIEVE_API_LOCATION: this.settingsStore.pennsieveApi,
NL_LINK_PREFIX: this.settingsStore.nlLinkPrefix,
ROOT_URL: this.settingsStore.rootUrl,
};
},
entries: function() {
return this.entriesStore.entries;
},
},
};
</script>
<style scoped lang="scss">
.dialog-header {
color: #333;
line-height: 20px;
border-bottom: solid 0.7px #dcdfe6;
background-color: #f5f7fa;
}
.dialog-main {
padding: 0px;
width: 100%;
height: 100%;
}
.start-up {
:deep(.el-drawer__open) {
.el-drawer {
&.rtl {
animation: unset;
}
}
}
:deep(.el-drawer-fade-leave-active) {
animation: unset;
}
:deep(.el-drawer) {
&.rtl {
animation: rtl-drawer-out 2s linear;
}
}
:deep(.el-drawer__wrapper) {
&.side-bar {
display: block !important;
}
}
}
</style>