Browse Source

Merge pull request #269 from CatalystCode/enhancement/render-source-document

Enhancement/Add viewer pane for source document
pull/311/head
Hiroki Nakayama 5 years ago
committed by GitHub
parent
commit
e4458133f4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 2 deletions
  1. 7
      app/server/static/components/annotation.pug
  2. 3
      app/server/static/components/annotationMixin.js
  3. 51
      app/server/static/components/preview.vue

7
app/server/static/components/annotation.pug

@ -133,7 +133,12 @@ div.columns(v-cloak="")
span.icon
i.fas.fa-box
block annotation-area
div.columns
div.column
block annotation-area
div.column(v-if="documentMetadata != null && documentMetadata.documentSourceUrl != null")
preview(v-bind:url="documentMetadata.documentSourceUrl")
div.level.mt30
a.button.level-left(

3
app/server/static/components/annotationMixin.js

@ -2,6 +2,7 @@ import * as marked from 'marked';
import VueJsonPretty from 'vue-json-pretty';
import isEmpty from 'lodash.isempty';
import HTTP, { defaultHttpClient } from './http';
import Preview from './preview.vue';
const getOffsetFromUrl = (url) => {
const offsetMatch = url.match(/[?#].*offset=(\d+)/);
@ -36,7 +37,7 @@ const storeOffsetInUrl = (offset) => {
};
export default {
components: { VueJsonPretty },
components: { VueJsonPretty, Preview },
data() {
return {

51
app/server/static/components/preview.vue

@ -0,0 +1,51 @@
<template lang="pug">
div.preview
object(v-if="isPDF", v-bind:data="url", type="application/pdf")
embed(v-bind:src="url", type="application/pdf")
iframe(v-else-if="isWord", v-bind:src="officeViewer")
iframe(v-else, v-bind:src="url")
</template>
<style scoped>
.preview, object, iframe {
width: 100%;
height: 100%;
}
</style>
<script>
export default {
props: {
url: {
type: String,
default: '',
},
},
computed: {
fileExtension() {
const filename = this.url.split('/').pop();
const extension = filename.match(/[^#?]+/)[0].split('.').pop();
return extension.toLowerCase();
},
isPDF() {
return this.fileExtension === 'pdf';
},
isWord() {
return [
'doc',
'dot',
'docx',
'docm',
'dotm',
].indexOf(this.fileExtension) !== -1;
},
officeViewer() {
return `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(this.url)}`;
},
},
};
</script>
Loading…
Cancel
Save