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

82 lines
1.9 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,
},
2020-03-13 15:44:24 +05:30
loading: {
type: Boolean,
default: true,
required: false,
},
activeViewer: {
type: Object,
required: true,
},
},
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>
<div class="blob-viewer" :data-type="activeViewer.type">
<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-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"
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>