Skip to content

Commit a6d6328

Browse files
committed
rootjs: migrate viewer to iframe
Migrate viewer for .root files to a iframe from root.cern
1 parent 17a07e0 commit a6d6328

File tree

1 file changed

+31
-80
lines changed

1 file changed

+31
-80
lines changed

rootjs/src/App.vue

Lines changed: 31 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,55 @@
11
<template>
2-
<main id="rootjs-main" class="oc-height-1-1">
3-
<div class="oc-flex root-viewer oc-height-1-1">
4-
<div id="web-nav-sidebar" class="root-sidebar app-navigation oc-app-navigation-expanded">
5-
<select id="mode-select" v-model="viewMode" @change="renderViewer">
6-
<option v-for="item in items" :key="item" :value="item">
7-
{{ item }}
8-
</option>
9-
</select>
10-
<div id="treeViewer"></div>
11-
</div>
12-
<div id="mainViewer" class="oc-flex oc-height-1-1 app-content oc-width-1-1"></div>
13-
</div>
14-
</main>
2+
<iframe id="rootjs-viewer" ref="rootJsViewer" :src="iframeSource" title="ROOTJS Viewer" />
153
</template>
4+
<script type="module"></script>
165
<script lang="ts">
17-
import { computed, defineComponent } from 'vue'
6+
import { defineComponent, unref, ref, onMounted } from 'vue'
7+
import { Resource, SpaceResource } from '@ownclouders/web-client'
8+
import { useClientService, useAuthStore, useUserStore } from '@ownclouders/web-pkg'
189
1910
export default defineComponent({
2011
name: 'ROOTJSViewer',
2112
props: {
22-
url: {
23-
type: String,
13+
space: {
14+
type: SpaceResource,
15+
required: true
16+
},
17+
resource: {
18+
type: Resource,
2419
required: true
2520
}
2621
},
2722
setup(props) {
28-
const davURL = computed(() => {
29-
return props.url
23+
const clientService = useClientService()
24+
const { user } = useUserStore()
25+
const authStore = useAuthStore()
26+
27+
const rootUrl = 'https://root.cern/js/latest'
28+
const iframeSource = ref('')
29+
30+
onMounted(async () => {
31+
// get direct url to file and clean query parameters
32+
const signedUrl = await clientService.webdav.getFileUrl(props.space, props.resource, {
33+
isUrlSigningEnabled: true,
34+
username: user.id
35+
})
36+
const fileUrl = new URL(signedUrl)
37+
fileUrl.search = ''
38+
iframeSource.value = `${rootUrl}?file=${fileUrl.href}?access_token=${authStore.accessToken}`
39+
const frame = document.getElementById('rootjs-viewer')
40+
frame.contentWindow.postMessage({}, unref(iframeSource))
3041
})
3142
3243
return {
33-
davURL
44+
iframeSource
3445
}
3546
},
36-
data: () => ({
37-
loading: true,
38-
error: false,
39-
items: ['simple', 'tabs', 'collapsible', 'grid 2x2', 'grid 3x3', 'grid 4x4'],
40-
viewMode: null,
41-
painter: null,
42-
isPublic: false
43-
}),
44-
created() {
45-
this.viewMode = this.items[0]
46-
},
47-
mounted: function () {
48-
require.config({
49-
onNodeCreated: function(node){
50-
node.setAttribute('crossorigin', 'anonymous')
51-
}
52-
})
53-
require(['//root.cern/js/7.8.2/scripts/JSRoot.core.min.js'], this.renderViewer, this.showError)
54-
},
5547
methods: {
56-
rootFile() {
57-
return fetch(this.davURL).then((resp) => {
58-
if (resp.ok) {
59-
return resp.arrayBuffer()
60-
} else {
61-
return Promise.reject('error code: ' + resp.status)
62-
}
63-
})
64-
},
65-
renderViewer: function () {
66-
if (this.painter !== null) {
67-
this.painter.cleanup()
68-
}
69-
this.rootFile()
70-
.then((file) => {
71-
JSROOT.require('hierarchy').then(() => {
72-
this.painter = new JSROOT.HierarchyPainter('treeViewer', 'treeViewer')
73-
this.painter.setDisplay(this.viewMode, 'mainViewer')
74-
this.painter.openRootFile(file).then(() => (this.loading = false))
75-
})
76-
})
77-
.catch((error) => {
78-
this.showError()
79-
console.log(error)
80-
})
81-
},
8248
showError: function () {
83-
// FIXME waiting for owncloud to implement a way to show error
8449
console.error('showError')
8550
}
8651
}
8752
})
8853
</script>
8954

90-
<style>
91-
#rootjs-main {
92-
/* FIXME make app compatible with dark mode */
93-
background-color: white !important;
94-
}
95-
.root-sidebar {
96-
display: block !important;
97-
padding: 10px;
98-
overflow: auto !important;
99-
box-sizing: border-box;
100-
}
101-
#mainViewer {
102-
padding: 10px;
103-
}
104-
</style>
55+
<style></style>

0 commit comments

Comments
 (0)