debian-mirror-gitlab/app/assets/javascripts/blob/components/blob_content.vue

94 lines
2.2 KiB
Vue
Raw Normal View History

2020-03-13 15:44:24 +05:30
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { RichViewer, SimpleViewer } from '~/vue_shared/components/blob_viewers';
import BlobContentError from './blob_content_error.vue';
2020-05-24 23:13:21 +05:30
import { BLOB_RENDER_EVENT_LOAD, BLOB_RENDER_EVENT_SHOW_SOURCE } from './constants';
2020-03-13 15:44:24 +05:30
export default {
2021-06-08 01:23:25 +05:30
name: 'BlobContent',
2020-03-13 15:44:24 +05:30
components: {
GlLoadingIcon,
BlobContentError,
},
props: {
2020-05-24 23:13:21 +05:30
blob: {
type: Object,
required: false,
default: () => ({}),
},
2020-03-13 15:44:24 +05:30
content: {
type: String,
default: '',
required: false,
},
2021-04-29 21:17:54 +05:30
isRawContent: {
type: Boolean,
default: false,
required: false,
},
2021-09-30 23:02:18 +05:30
richViewer: {
type: String,
default: '',
required: false,
},
2020-03-13 15:44:24 +05:30
loading: {
type: Boolean,
default: true,
required: false,
},
activeViewer: {
type: Object,
required: true,
},
2021-11-18 22:05:49 +05:30
hideLineNumbers: {
type: Boolean,
required: false,
default: false,
},
2020-03-13 15:44:24 +05:30
},
computed: {
viewer() {
switch (this.activeViewer.type) {
case 'rich':
return RichViewer;
default:
return SimpleViewer;
}
},
viewerError() {
return this.activeViewer.renderError;
},
},
2020-05-24 23:13:21 +05:30
BLOB_RENDER_EVENT_LOAD,
BLOB_RENDER_EVENT_SHOW_SOURCE,
2020-03-13 15:44:24 +05:30
};
</script>
<template>
2021-12-11 22:18:48 +05:30
<div class="blob-viewer" :data-type="activeViewer.type" :data-loaded="!loading">
2020-03-13 15:44:24 +05:30
<gl-loading-icon v-if="loading" size="md" color="dark" class="my-4 mx-auto" />
<template v-else>
2020-05-24 23:13:21 +05:30
<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)"
/>
2020-04-08 14:13:33 +05:30
<component
:is="viewer"
v-else
ref="contentViewer"
:content="content"
2021-09-30 23:02:18 +05:30
:rich-viewer="richViewer"
2021-04-29 21:17:54 +05:30
:is-raw-content="isRawContent"
:file-name="blob.name"
2020-04-08 14:13:33 +05:30
:type="activeViewer.fileType"
2021-11-18 22:05:49 +05:30
:hide-line-numbers="hideLineNumbers"
2020-06-23 00:09:42 +05:30
data-qa-selector="file_content"
2020-04-08 14:13:33 +05:30
/>
2020-03-13 15:44:24 +05:30
</template>
</div>
</template>