All files / app/assets/javascripts/blob/pdf pdf_viewer.vue

100% Statements 6/6
100% Branches 0/0
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    2x                           5x               2x     2x 2x 2x                                                    
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import PdfLab from '~/pdf/index.vue';
 
export default {
  components: {
    PdfLab,
    GlLoadingIcon,
  },
  props: {
    pdf: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      error: false,
      loadError: false,
      loading: true,
    };
  },
  methods: {
    onLoad() {
      this.loading = false;
    },
    onError(error) {
      this.loading = false;
      this.loadError = true;
      this.error = error;
    },
  },
};
</script>
 
<template>
  <div class="js-pdf-viewer container-fluid md gl-mt-3 gl-mb-3">
    <div v-if="loading && !error" class="text-center loading">
      <gl-loading-icon class="mt-5" size="lg" />
    </div>
    <pdf-lab
      v-if="!loadError"
      :pdf="pdf"
      @pdflabload="onLoad"
      @pdflaberror="onError"
      v-on="$listeners"
    />
    <p v-if="error" class="text-center">
      <span v-if="loadError" ref="loadError">
        {{ __('An error occurred while loading the file. Please try again later.') }}
      </span>
      <span v-else>{{ __('An error occurred while decoding the file.') }}</span>
    </p>
  </div>
</template>