-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSidePanel.vue
More file actions
318 lines (264 loc) · 9.09 KB
/
AppSidePanel.vue
File metadata and controls
318 lines (264 loc) · 9.09 KB
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
<template>
<div id="app-side" style="display:flex; height: 100%">
<!-- Tabs -->
<div class="position-relative" ref="buttonGroup" style="margin-top:50px; display:flex; flex-direction:column; height: fit-content;">
<div class="btn tab vertical-button" :class="{active: tab.isSelected}" type="button" :title="tab.name" :id="tab.id" @click="onTabClicked" :key="tab.name" v-for="tab in tabs">
<!--{{tab.name}}-->
{{ $t(tab.name)}}
</div>
</div>
<!-- Panel -->
<div class="collapse width" ref="panel" :class="{show: isPanelOpen}">
<!-- Closing button -->
<div class='row m-0' style='position: relative'>
<button type="button" class="btn-close p-0" aria-label="Close" @click='closePanel' style='position: absolute; top: 16px; right: 16px'></button>
</div>
<!-- Info container -->
<div class="side-panel-content g-0">
<!-- Haul info -->
<haul-info @selectedTrack="selectedTrack" ref="haul-info" v-show="selTab == 'tracks'">
</haul-info>
<!-- Fishing effort -->
<fishing-effort ref="fishing-effort"
@effortParamsChange='setEffortMap'
@effortLayerOpacityChange='setEffortLayerOpacity'
v-show="selTab === 'effort'">
</fishing-effort>
<!-- Layers -->
<layer-panel ref="layers"
@baseLayerChange='setBaseLayer'
@layerOpacityChange='setLayerOpacity'
@climaLayerChange='setClimaLayer'
v-show="selTab === 'layers'">
</layer-panel>
<about-panel ref="about"
v-show="selTab === 'about'">
</about-panel>
</div>
</div>
</div>
</template>
<script>
// Import components
import HaulInfo from "HaulInfo.vue"
import FishingEffortPanel from "FishingEffortPanel.vue"
import LayerPanel from "LayerPanel.vue"
import AboutPanel from "About.vue"
//import Map from "Map.vue";
//import AnimationCanvas from "AnimationCanvas.vue";
export default {
name: "app-side",
created(){
},
mounted () {
// Move tab buttons to be inside the window
// this.$refs.buttonGroup.style['margin-left'] = -this.$refs.buttonGroup.offsetHeight + 'px';
let tabButtonGroup = this.$refs.buttonGroup;
//tabButtonGroup.style['margin-left'] = - Math.max(this.$refs.buttonGroup.offsetWidth, 28) + 'px';
tabButtonGroup.style['margin-left'] = - this.$refs.buttonGroup.offsetWidth + 'px';
// When side panel is fully opened or closed, repeats the event onTabClicked
this.$refs.panel.addEventListener("webkitTransitionEnd", () => this.$emit('onPanelTransitionEnd')); // Code for Chrome, Safari and Opera
this.$refs.panel.addEventListener("transitionend", () => this.$emit('onPanelTransitionEnd')); // Standard syntax
// HACK Fix Force openlayers canvas to fill window -> In the previous coude I am modifing the position of the tab buttons and the canvas does not
// cover the whole window. Openlayers reacts to window resize events, therefore we can trigger the window event so that the
// canvas fills the whole window.
window.dispatchEvent(new Event('resize'));
},
data () {
return {
tabs: {
"tracks": {
id: "tracks",
name: "Fishing tracks",
isSelected: false
},
"effort": {
id: "effort",
name: "Fishing effort",
isSelected: false
},
"layers": {
id: "layers",
name: "Layers",
isSelected: false
},
"about": {
id: "about",
name: "About",
isSelected: false
}
},
isPanelOpen: false,
selTab: "",
}
},
methods: {
// USER HTML ACTIONS
onTabClicked: function(event){
// Use id to get tab
let id = event.target.id;
let tab = this.tabs[id];
// If tab is selected and panel is open, close panel
if (tab.isSelected){
this.closePanel();
}
// If tab is not selected, open panel
else {
// Unselect all first
Object.keys(this.tabs).forEach(kk => this.tabs[kk].isSelected = false);
// Select tab and open panel
tab.isSelected = true;
this.selTab = id;
this.openPanel();
}
// Emit that the panel open or closes, so that the month names in TimeRangeBar.vue can be updated
this.$emit('onTabClicked');
},
// INTERNAL EVENTS
openPanel: function(){
this.isPanelOpen = true;
// HACK Fix Force openlayers canvas to fill window after 0.5 s
//setTimeout(() => window.dispatchEvent(new Event('resize')), 500);
for (let i = 10; i<500; i+=10){
setTimeout(() => window.dispatchEvent(new Event('resize')), i);
}
},
closePanel: function(){
this.isPanelOpen = false;
// Deselect tabs
Object.keys(this.tabs).forEach(kk => this.tabs[kk].isSelected = false);
this.selTab = "";
// HACK Fix Force openlayers canvas to fill window after 0.5 s
for (let i = 10; i<500; i+=10){
setTimeout(() => window.dispatchEvent(new Event('resize')), i);
}
//setTimeout(() => window.dispatchEvent(new Event('resize')), 500);
},
// Event coming from HaulInfo.vue, when a track is clicked in the dropdown list.
selectedTrack: function(id){
// Change the date on the WMS Layer panel
this.$refs.layers.fishingTrackSelected(id);
// Emit
this.$emit('selectedTrack', id);
},
// Effort panel
setEffortLayerOpacity: function(opacity){
if (this.selTab == 'effort'){ // Only when the tab is open can send events
this.$emit('setEffortLayerOpacity', opacity);
// Connect with layers panel
this.$refs['layers'].setFEffortOpacity(opacity);
}
},
setEffortMap: function(inUrl){
this.$emit('setEffortMap', inUrl);
},
// Layer panel
setBaseLayer: function(baseLayerName){
this.$emit('setBaseLayer', baseLayerName);
},
setLayerOpacity: function(params){
if (this.selTab == 'layers'){ // Only when the tab is open can send events
this.$emit('setLayerOpacity', params);
// If the layer is fishing effort, connect with tab Fishing effort
if (params[0] == 'fishingEffort'){
this.$refs['fishing-effort'].setLayerOpacity(params[1]);
}
}
},
setClimaLayer: function(urlParams){
this.$emit('setClimaLayer', urlParams);
},
// PUBLIC METHODS
// Set fishing tracks once loaded
// OPTIONS-TODO:
// OPTION 1- Map is loading the tracks. When they are loaded there, an event can be passed to haul info, but the chain is
// quite long: Map.vue - AppManager.vue - AppSidePanel.vue - HaulInfo.vue
// OPTION 2- We consider FishingTracks class as singleton and we call it directly from HaulInfo.vue. We can make this call
// iteratively until fishing tracks exist. Not so clean, as the tab Fishing Tracks should only exist once the fishing tracks
// have been loaded. If there is an error with loading the fishing tracks, the tab should not exist?
// Fishing track clicked
fishingTrackClicked: function(id){
this.openFishingTab(id);
// Send event to layers panel
this.$refs.layers.fishingTrackSelected(id);
},
// Opens the fishing tracks tab with the corresponding track id selected
openFishingTab: function(id){
// Select tab
// Unselect all first
Object.keys(this.tabs).forEach(kk => this.tabs[kk].isSelected = false);
// Select tracks tab
this.tabs.tracks.isSelected = true;
this.selTab = 'tracks';
// Set track id on tracks tab
this.$refs["haul-info"].setSelectedFishingTrack(id);
// Open panel if it is not open already
this.openPanel();
},
// Set the fishing tracks once they are loaded. This event comes from Map.vue
setFishingTracks: function(geojson){
this.$refs["haul-info"].setFishingTracks(geojson);
}
},
components: {
"haul-info": HaulInfo,
"fishing-effort": FishingEffortPanel,
"layer-panel": LayerPanel,
"about-panel": AboutPanel,
//"ol-map": Map,
//"animation-canvas": AnimationCanvas,
},
computed: {
}
}
</script>
<style scoped>
.vertical-button {
-webkit-transform: scale(-1);
-moz-transform: scale(-1);
-ms-transform: scale(-1);
-o-transform: scale(-1);
transform: scale(-1);
writing-mode: vertical-lr;
text-orientation: sideways;
padding: 8px 4px 8px 4px ;
font-size: 12px;
margin-top: 2px;
border-radius: 0px 12px 12px 0px;
}
.collapse {
overflow: auto;
transition: width 0.5s, min-width 0.5s;
}
.collapse.show {
width: 40vw;
min-width: 500px;
}
.collapse:not(.show){
width: 0;
min-width: 0;
height: initial;
display: block;
}
.tab {
color: rgb(0, 0, 0);
background-color: #a0d7f2;
border-color: #72b0cf;
min-width: 18px;
max-width: 30px;
box-shadow: 1px 0px 2px #0a3142;
}
.tab.active {
color: rgb(0, 0, 0);
background-color: #7dc8e8;
border-color: #569ab8;
box-shadow: 2px 0px 5px #0a3142;
}
.side-panel-content {
display:flex;
flex-direction: column;
align-items: center;
background: #e3f4ff;;
/* height: 100%; */
}
</style>