debian-mirror-gitlab/app/assets/javascripts/snippets/components/snippet_blob_edit.vue

94 lines
2.2 KiB
Vue
Raw Normal View History

2020-04-08 14:13:33 +05:30
<script>
2020-10-24 23:57:45 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2020-04-08 14:13:33 +05:30
import BlobHeaderEdit from '~/blob/components/blob_edit_header.vue';
import BlobContentEdit from '~/blob/components/blob_edit_content.vue';
2020-07-28 23:09:34 +05:30
import { getBaseURL, joinPaths } from '~/lib/utils/url_utility';
import axios from '~/lib/utils/axios_utils';
import { SNIPPET_BLOB_CONTENT_FETCH_ERROR } from '~/snippets/constants';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as Flash } from '~/flash';
2020-07-28 23:09:34 +05:30
import { sprintf } from '~/locale';
2020-04-08 14:13:33 +05:30
export default {
components: {
BlobHeaderEdit,
BlobContentEdit,
2020-04-22 19:07:51 +05:30
GlLoadingIcon,
2020-04-08 14:13:33 +05:30
},
2020-04-22 19:07:51 +05:30
inheritAttrs: false,
2020-04-08 14:13:33 +05:30
props: {
2020-07-28 23:09:34 +05:30
blob: {
type: Object,
2020-10-24 23:57:45 +05:30
required: true,
},
canDelete: {
type: Boolean,
2020-04-22 19:07:51 +05:30
required: false,
2020-10-24 23:57:45 +05:30
default: true,
2020-04-08 14:13:33 +05:30
},
2020-10-24 23:57:45 +05:30
showDelete: {
type: Boolean,
required: false,
default: false,
2020-04-22 19:07:51 +05:30
},
2020-10-24 23:57:45 +05:30
},
computed: {
inputId() {
return `${this.blob.id}_file_path`;
2020-07-28 23:09:34 +05:30
},
},
mounted() {
2020-10-24 23:57:45 +05:30
if (!this.blob.isLoaded) {
2020-07-28 23:09:34 +05:30
this.fetchBlobContent();
}
},
methods: {
2020-10-24 23:57:45 +05:30
onDelete() {
this.$emit('delete');
},
2020-07-28 23:09:34 +05:30
notifyAboutUpdates(args = {}) {
2020-10-24 23:57:45 +05:30
this.$emit('blob-updated', args);
2020-07-28 23:09:34 +05:30
},
fetchBlobContent() {
const baseUrl = getBaseURL();
const url = joinPaths(baseUrl, this.blob.rawPath);
axios
.get(url)
.then(res => {
2020-10-24 23:57:45 +05:30
this.notifyAboutUpdates({ content: res.data });
2020-07-28 23:09:34 +05:30
})
2020-10-24 23:57:45 +05:30
.catch(e => this.flashAPIFailure(e));
2020-07-28 23:09:34 +05:30
},
flashAPIFailure(err) {
Flash(sprintf(SNIPPET_BLOB_CONTENT_FETCH_ERROR, { err }));
2020-04-08 14:13:33 +05:30
},
},
};
</script>
<template>
2020-10-24 23:57:45 +05:30
<div class="file-holder snippet">
<blob-header-edit
:id="inputId"
:value="blob.path"
data-qa-selector="file_name_field"
:can-delete="canDelete"
:show-delete="showDelete"
@input="notifyAboutUpdates({ path: $event })"
@delete="onDelete"
/>
<gl-loading-icon
v-if="!blob.isLoaded"
:label="__('Loading snippet')"
size="lg"
class="loading-animation prepend-top-20 append-bottom-20"
/>
<blob-content-edit
v-else
:value="blob.content"
:file-global-id="blob.id"
:file-name="blob.path"
@input="notifyAboutUpdates({ content: $event })"
/>
2020-04-08 14:13:33 +05:30
</div>
</template>