debian-mirror-gitlab/app/assets/javascripts/blob/pdf/index.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
import pdfLab from '../../pdf/index.vue';
2020-03-13 15:44:24 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2017-08-17 22:00:37 +05:30
export default () => {
const el = document.getElementById('js-pdf-viewer');
return new Vue({
el,
2018-03-17 18:26:18 +05:30
components: {
pdfLab,
2020-03-13 15:44:24 +05:30
GlLoadingIcon,
2018-03-17 18:26:18 +05:30
},
2017-08-17 22:00:37 +05:30
data() {
return {
error: false,
loadError: false,
loading: true,
pdf: el.dataset.endpoint,
};
},
methods: {
onLoad() {
this.loading = false;
},
onError(error) {
this.loading = false;
this.loadError = true;
this.error = error;
},
},
template: `
<div class="js-pdf-viewer container-fluid md prepend-top-default append-bottom-default">
<div
class="text-center loading"
v-if="loading && !error">
2020-03-13 15:44:24 +05:30
<gl-loading-icon class="mt-5" size="lg"/>
2017-08-17 22:00:37 +05:30
</div>
<pdf-lab
v-if="!loadError"
:pdf="pdf"
@pdflabload="onLoad"
@pdflaberror="onError" />
<p
class="text-center"
v-if="error">
<span v-if="loadError">
2020-03-13 15:44:24 +05:30
An error occurred while loading the file. Please try again later.
2017-08-17 22:00:37 +05:30
</span>
<span v-else>
2020-03-13 15:44:24 +05:30
An error occurred while decoding the file.
2017-08-17 22:00:37 +05:30
</span>
</p>
</div>
`,
});
};