|
| 1 | +<template> |
| 2 | + <div ref="resizeTarget" class="ff--immersive-editor-wrapper" :class="{resizing: isEditorResizing}"> |
| 3 | + <EditorWrapper |
| 4 | + :url="device?.editor?.url" |
| 5 | + :device="device" |
| 6 | + /> |
| 7 | + |
| 8 | + <section |
| 9 | + class="tabs-wrapper drawer" |
| 10 | + :class="{'open': drawer.open, resizing: isEditorResizing}" |
| 11 | + :style="{ width: editorWidthStyle }" |
| 12 | + data-el="tabs-drawer" |
| 13 | + @mouseenter="handleDrawerMouseEnter" |
| 14 | + @mouseleave="handleDrawerMouseLeave" |
| 15 | + > |
| 16 | + <resize-bar |
| 17 | + @mousedown="startEditorResize" |
| 18 | + /> |
| 19 | + </section> |
| 20 | + </div> |
| 21 | +</template> |
| 22 | + |
| 23 | +<script> |
| 24 | +
|
| 25 | +import semver from 'semver' |
| 26 | +import { mapActions } from 'vuex' |
| 27 | +
|
| 28 | +import deviceApi from '../../../api/devices.js' |
| 29 | +import ResizeBar from '../../../components/ResizeBar.vue' |
| 30 | +import EditorWrapper from '../../../components/immersive-editor/RemoteInstanceEditorWrapper.vue' |
| 31 | +import { useDrawerHelper } from '../../../composables/DrawerHelper.js' |
| 32 | +import { useResizingHelper } from '../../../composables/ResizingHelper.js' |
| 33 | +import Alerts from '../../../services/alerts.js' |
| 34 | +
|
| 35 | +export default { |
| 36 | + name: 'DeviceEditor', |
| 37 | + components: { |
| 38 | + ResizeBar, |
| 39 | + EditorWrapper |
| 40 | + }, |
| 41 | + setup () { |
| 42 | + const { |
| 43 | + drawer, |
| 44 | + toggleDrawer, |
| 45 | + notifyDrawerState, |
| 46 | + handleDrawerMouseEnter, |
| 47 | + handleDrawerMouseLeave, |
| 48 | + runInitialTease, |
| 49 | + bindDrawer, |
| 50 | + cleanup: cleanupDrawer |
| 51 | + } = useDrawerHelper() |
| 52 | +
|
| 53 | + const { |
| 54 | + startResize: startEditorResize, |
| 55 | + widthStyle: editorWidthStyle, |
| 56 | + bindResizer: bindDrawerResizer, |
| 57 | + isResizing: isEditorResizing |
| 58 | + } = useResizingHelper() |
| 59 | +
|
| 60 | + return { |
| 61 | + startEditorResize, |
| 62 | + bindDrawerResizer, |
| 63 | + editorWidthStyle, |
| 64 | + drawer, |
| 65 | + isEditorResizing, |
| 66 | + toggleDrawer, |
| 67 | + notifyDrawerState, |
| 68 | + handleDrawerMouseEnter, |
| 69 | + handleDrawerMouseLeave, |
| 70 | + runInitialTease, |
| 71 | + bindDrawer, |
| 72 | + cleanupDrawer |
| 73 | + } |
| 74 | + }, |
| 75 | + data () { |
| 76 | + return { |
| 77 | + agentSupportsDeviceAccess: null, |
| 78 | + agentSupportsActions: null, |
| 79 | + device: null, |
| 80 | + openingTunnel: false, |
| 81 | + openTunnelTimeout: null |
| 82 | + } |
| 83 | + }, |
| 84 | + computed: { |
| 85 | +
|
| 86 | + }, |
| 87 | + watch: { |
| 88 | + device (device) { |
| 89 | + if (device && Object.prototype.hasOwnProperty.call(device, 'editor')) { |
| 90 | + this.setContextDevice(device) |
| 91 | + } else { |
| 92 | + Alerts.emit('Unable to connect to the Remote Instance', 'warning') |
| 93 | +
|
| 94 | + setTimeout(() => this.$router.push({ name: 'device-overview' }), 2000) |
| 95 | + } |
| 96 | + } |
| 97 | + }, |
| 98 | + mounted () { |
| 99 | + this.loadDevice().catch(err => err) |
| 100 | + }, |
| 101 | + methods: { |
| 102 | + ...mapActions('context', { setContextDevice: 'setDevice' }), |
| 103 | + loadDevice: async function () { |
| 104 | + try { |
| 105 | + this.device = await deviceApi.getDevice(this.$route.params.id) |
| 106 | + } catch (err) { |
| 107 | + if (err.status === 403) { |
| 108 | + clearTimeout(this.openTunnelTimeout) |
| 109 | + return this.$router.push({ name: 'Home' }) |
| 110 | + } |
| 111 | + } finally { |
| 112 | + this.loading = false |
| 113 | + } |
| 114 | +
|
| 115 | + this.agentSupportsDeviceAccess = this.device.agentVersion && semver.gte(this.device.agentVersion, '0.8.0') |
| 116 | + this.agentSupportsActions = this.device.agentVersion && semver.gte(this.device.agentVersion, '2.3.0') |
| 117 | +
|
| 118 | + // todo we first need to get the device and set the team afterwards |
| 119 | + await this.$store.dispatch('account/setTeam', this.device.team.slug) |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | +</script> |
| 124 | + |
| 125 | +<style scoped lang="scss"> |
| 126 | +
|
| 127 | +</style> |
0 commit comments