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

blob_content.vue « components « blob « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5592a75a4d2d373c2e9c4238b6abe761f9149237 (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
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { RichViewer, SimpleViewer } from '~/vue_shared/components/blob_viewers';
import BlobContentError from './blob_content_error.vue';

import {
  BLOB_RENDER_EVENT_LOAD,
  BLOB_RENDER_EVENT_SHOW_SOURCE,
  RICH_BLOB_VIEWER,
} from './constants';

export default {
  name: 'BlobContent',
  components: {
    GlLoadingIcon,
    BlobContentError,
  },
  props: {
    blob: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    content: {
      type: String,
      default: '',
      required: false,
    },
    isRawContent: {
      type: Boolean,
      default: false,
      required: false,
    },
    richViewer: {
      type: String,
      default: '',
      required: false,
    },
    loading: {
      type: Boolean,
      default: true,
      required: false,
    },
    activeViewer: {
      type: Object,
      required: true,
    },
    hideLineNumbers: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return { richContentLoaded: false };
  },
  computed: {
    viewer() {
      switch (this.activeViewer.type) {
        case 'rich':
          return RichViewer;
        default:
          return SimpleViewer;
      }
    },
    viewerError() {
      return this.activeViewer.renderError;
    },
    isContentLoaded() {
      return this.activeViewer.type === RICH_BLOB_VIEWER
        ? !this.loading && this.richContentLoaded
        : !this.loading;
    },
  },
  BLOB_RENDER_EVENT_LOAD,
  BLOB_RENDER_EVENT_SHOW_SOURCE,
};
</script>
<template>
  <div class="blob-viewer" :data-type="activeViewer.type" :data-loaded="isContentLoaded">
    <gl-loading-icon v-if="loading" size="lg" color="dark" class="my-4 mx-auto" />

    <template v-else>
      <blob-content-error
        v-if="viewerError"
        :viewer-error="viewerError"
        :blob="blob"
        @[$options.BLOB_RENDER_EVENT_LOAD]="$emit($options.BLOB_RENDER_EVENT_LOAD)"
        @[$options.BLOB_RENDER_EVENT_SHOW_SOURCE]="$emit($options.BLOB_RENDER_EVENT_SHOW_SOURCE)"
      />
      <component
        :is="viewer"
        v-else
        ref="contentViewer"
        :content="content"
        :rich-viewer="richViewer"
        :is-raw-content="isRawContent"
        :file-name="blob.name"
        :type="activeViewer.fileType"
        :hide-line-numbers="hideLineNumbers"
        data-testid="blob-viewer-file-content"
        @richContentLoaded="richContentLoaded = true"
      />
    </template>
  </div>
</template>