2020-01-31 15:08:42 +00:00
|
|
|
<script>
|
|
|
|
import BlobEmbeddable from '~/blob/components/blob_embeddable.vue';
|
|
|
|
import { SNIPPET_VISIBILITY_PUBLIC } from '../constants';
|
2020-02-11 12:08:52 +00:00
|
|
|
import BlobHeader from '~/blob/components/blob_header.vue';
|
2020-02-14 18:08:45 +00:00
|
|
|
import BlobContent from '~/blob/components/blob_content.vue';
|
2020-02-11 12:08:52 +00:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2020-01-31 15:08:42 +00:00
|
|
|
|
2020-02-14 18:08:45 +00:00
|
|
|
import GetSnippetBlobQuery from '../queries/snippet.blob.query.graphql';
|
|
|
|
import GetBlobContent from '../queries/snippet.blob.content.query.graphql';
|
|
|
|
|
|
|
|
import { SIMPLE_BLOB_VIEWER, RICH_BLOB_VIEWER } from '~/blob/components/constants';
|
|
|
|
|
2020-01-31 15:08:42 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
BlobEmbeddable,
|
2020-02-11 12:08:52 +00:00
|
|
|
BlobHeader,
|
2020-02-14 18:08:45 +00:00
|
|
|
BlobContent,
|
2020-02-11 12:08:52 +00:00
|
|
|
GlLoadingIcon,
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
blob: {
|
|
|
|
query: GetSnippetBlobQuery,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
ids: this.snippet.id,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update: data => data.snippets.edges[0].node.blob,
|
2020-02-14 18:08:45 +00:00
|
|
|
result(res) {
|
|
|
|
const viewer = res.data.snippets.edges[0].node.blob.richViewer
|
|
|
|
? RICH_BLOB_VIEWER
|
|
|
|
: SIMPLE_BLOB_VIEWER;
|
|
|
|
this.switchViewer(viewer, true);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
blobContent: {
|
|
|
|
query: GetBlobContent,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
ids: this.snippet.id,
|
|
|
|
rich: this.activeViewerType === RICH_BLOB_VIEWER,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update: data =>
|
|
|
|
data.snippets.edges[0].node.blob.richData || data.snippets.edges[0].node.blob.plainData,
|
2020-02-11 12:08:52 +00:00
|
|
|
},
|
2020-01-31 15:08:42 +00:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
snippet: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2020-02-11 12:08:52 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
blob: {},
|
2020-02-14 18:08:45 +00:00
|
|
|
blobContent: '',
|
|
|
|
activeViewerType: window.location.hash ? SIMPLE_BLOB_VIEWER : '',
|
2020-02-11 12:08:52 +00:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 15:08:42 +00:00
|
|
|
computed: {
|
|
|
|
embeddable() {
|
|
|
|
return this.snippet.visibilityLevel === SNIPPET_VISIBILITY_PUBLIC;
|
|
|
|
},
|
2020-02-11 12:08:52 +00:00
|
|
|
isBlobLoading() {
|
|
|
|
return this.$apollo.queries.blob.loading;
|
|
|
|
},
|
2020-02-14 18:08:45 +00:00
|
|
|
isContentLoading() {
|
|
|
|
return this.$apollo.queries.blobContent.loading;
|
|
|
|
},
|
|
|
|
viewer() {
|
|
|
|
const { richViewer, simpleViewer } = this.blob;
|
|
|
|
return this.activeViewerType === RICH_BLOB_VIEWER ? richViewer : simpleViewer;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
switchViewer(newViewer, respectHash = false) {
|
|
|
|
this.activeViewerType = respectHash && window.location.hash ? SIMPLE_BLOB_VIEWER : newViewer;
|
|
|
|
},
|
2020-01-31 15:08:42 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<blob-embeddable v-if="embeddable" class="mb-3" :url="snippet.webUrl" />
|
2020-02-11 12:08:52 +00:00
|
|
|
<gl-loading-icon
|
|
|
|
v-if="isBlobLoading"
|
|
|
|
:label="__('Loading blob')"
|
2020-02-14 18:08:45 +00:00
|
|
|
size="lg"
|
2020-02-11 12:08:52 +00:00
|
|
|
class="prepend-top-20 append-bottom-20"
|
|
|
|
/>
|
|
|
|
<article v-else class="file-holder snippet-file-content">
|
2020-02-14 18:08:45 +00:00
|
|
|
<blob-header :blob="blob" :active-viewer-type="viewer.type" @viewer-changed="switchViewer" />
|
|
|
|
<blob-content :loading="isContentLoading" :content="blobContent" :active-viewer="viewer" />
|
2020-02-11 12:08:52 +00:00
|
|
|
</article>
|
2020-01-31 15:08:42 +00:00
|
|
|
</div>
|
|
|
|
</template>
|