|
1 | 1 | <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" /> |
15 | 3 | </template> |
| 4 | +<script type="module"></script> |
16 | 5 | <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' |
18 | 9 |
|
19 | 10 | export default defineComponent({ |
20 | 11 | name: 'ROOTJSViewer', |
21 | 12 | props: { |
22 | | - url: { |
23 | | - type: String, |
| 13 | + space: { |
| 14 | + type: SpaceResource, |
| 15 | + required: true |
| 16 | + }, |
| 17 | + resource: { |
| 18 | + type: Resource, |
24 | 19 | required: true |
25 | 20 | } |
26 | 21 | }, |
27 | 22 | 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)) |
30 | 41 | }) |
31 | 42 |
|
32 | 43 | return { |
33 | | - davURL |
| 44 | + iframeSource |
34 | 45 | } |
35 | 46 | }, |
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 | | - }, |
55 | 47 | 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 | | - }, |
82 | 48 | showError: function () { |
83 | | - // FIXME waiting for owncloud to implement a way to show error |
84 | 49 | console.error('showError') |
85 | 50 | } |
86 | 51 | } |
87 | 52 | }) |
88 | 53 | </script> |
89 | 54 |
|
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