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

pdf_viewer.vue « blob_viewers « components « repository « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c3df59844264d7adfffc7bbe62f18ffff16e49f9 (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
<script>
import { GlButton } from '@gitlab/ui';
import PdfViewer from '~/blob/pdf/pdf_viewer.vue';
import { __ } from '~/locale';
import { PDF_MAX_FILE_SIZE, PDF_MAX_PAGE_LIMIT } from '../../constants';

export default {
  components: { GlButton, PdfViewer },
  i18n: {
    tooLargeDescription: __('This PDF is too large to display. Please download to view.'),
    tooLargeButtonText: __('Download PDF'),
  },
  props: {
    blob: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      url: this.blob.rawPath,
      fileSize: this.blob.rawSize,
      totalPages: 0,
    };
  },
  computed: {
    tooLargeToDisplay() {
      return this.fileSize > PDF_MAX_FILE_SIZE || this.totalPages > PDF_MAX_PAGE_LIMIT;
    },
  },
  methods: {
    handleOnLoad(totalPages) {
      this.totalPages = totalPages;
    },
  },
};
</script>
<template>
  <div>
    <pdf-viewer v-if="!tooLargeToDisplay" :pdf="url" @pdflabload="handleOnLoad" />

    <div v-else class="gl-display-flex gl-flex-direction-column gl-align-items-center gl-p-5">
      <p>{{ $options.i18n.tooLargeDescription }}</p>

      <gl-button icon="download" category="secondary" variant="confirm" :href="url" download>{{
        $options.i18n.tooLargeButtonText
      }}</gl-button>
    </div>
  </div>
</template>