Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Office.vue « view « src - github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 443975945b8c0591ec08193fd8c501d8a05c47dd (plain)
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
<!--
  - @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  -
  - @author Julius Härtl <jus@bitgrid.net>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->

<template>
	<transition name="fade" appear>
		<div v-show="loading" id="richdocuments-wrapper">
			<div class="header">
				<!-- This is obviously not the way to go since it would require absolute positioning and therefore not be compatible with viewer actions/sidebar -->
				<div class="avatars">
					<avatar v-for="view in avatarViews" :key="view.ViewId" :user="view.UserId"
						:display-name="view.UserName"
						:style="viewColor(view)" />
				</div>
			</div>
			<iframe id="collaboraframe" ref="documentFrame" :src="src" />
		</div>
	</transition>
</template>

<script>
import Avatar from '@nextcloud/vue/dist/Components/Avatar'

import { getDocumentUrlForFile } from '../helpers/url'
import PostMessageService from '../services/postMessage'
import FilesAppIntegration from './FilesAppIntegration'

const FRAME_DOCUMENT = 'FRAME_DOCUMENT'
const PostMessages = new PostMessageService({
	FRAME_DOCUMENT: () => document.getElementById('collaboraframe').contentWindow
})

export default {
	name: 'Office',
	components: {
		Avatar
	},
	props: {
		filename: {
			type: String,
			default: null
		},
		fileid: {
			type: Number,
			default: null
		},
		hasPreview: {
			type: Boolean,
			required: false,
			default: () => false
		}
	},
	data() {
		return {
			src: null,
			loading: false,
			views: []
		}
	},
	computed: {
		avatarViews() {
			return this.views
		},
		viewColor() {
			return view => ({
				'border-color': '#' + ('000000' + Number(view.Color).toString(16)).substr(-6),
				'border-width': '2px',
				'border-style': 'solid'
			})
		}
	},
	mounted() {
		PostMessages.registerPostMessageHandler(({ parsed }) => {
			console.debug('[viewer] Received post message', parsed)
			const { msgId, args, deprecated } = parsed
			if (deprecated) { return }

			switch (msgId) {
			case 'loading':
				break
			case 'close':
				this.$parent.close()
				break
			case 'Get_Views_Resp':
			case 'Views_List':
				this.views = args
				break
			case 'UI_InsertGraphic':
				FilesAppIntegration.insertGraphic((filename, url) => {
					PostMessages.sendWOPIPostMessage(FRAME_DOCUMENT, 'postAsset', { FileName: filename, Url: url })
				})
				break
			}
		})
		this.load()
	},
	methods: {
		async load() {
			let documentUrl = getDocumentUrlForFile(this.filename, this.fileid) + '&path=' + this.filename
			this.$emit('update:loaded', true)
			this.src = documentUrl
			this.loading = true
		}
	}
}
</script>
<style lang="scss">
	.header {
		position: absolute;
		right: 100px;
		top: -50px;

		.avatars {
			display: flex;
			padding: 9px;

			.avatardiv {
				margin-left: -15px;
				box-shadow: 0 0 3px var(--color-box-shadow);
			}

		}
	}

	#richdocuments-wrapper {
		width: 100vw;
		height: calc(100vh - 50px);
		top: 50px;
		left: 0;
		position: absolute;
		z-index: 100000;
		max-width: 100%;
		display: flex;
		flex-direction: column;
		background-color: var(--color-main-background);
		transition: opacity .25s;
	}
	iframe {
		width: 100%;
		flex-grow: 1;
	}
	.fade-enter-active, .fade-leave-active {
		transition: opacity .25s;
	}
	.fade-enter, .fade-leave-to {
		opacity: 0;
	}
</style>