2021-01-03 14:25:43 +05:30
|
|
|
<script>
|
|
|
|
import { GlModal } from '@gitlab/ui';
|
2021-01-29 00:20:46 +05:30
|
|
|
import Api from '~/api';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { __, s__, sprintf } from '~/locale';
|
2021-01-29 00:20:46 +05:30
|
|
|
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
import { ISSUABLE_TYPE, MR_META_LOCAL_STORAGE_KEY } from '../constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import EditMetaControls from './edit_meta_controls.vue';
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlModal,
|
|
|
|
EditMetaControls,
|
2021-01-29 00:20:46 +05:30
|
|
|
LocalStorageSync,
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
sourcePath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
namespace: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
project: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-01-29 00:20:46 +05:30
|
|
|
clearStorage: false,
|
|
|
|
currentTemplate: null,
|
|
|
|
mergeRequestTemplates: null,
|
2021-01-03 14:25:43 +05:30
|
|
|
mergeRequestMeta: {
|
|
|
|
title: sprintf(s__(`StaticSiteEditor|Update %{sourcePath} file`), {
|
|
|
|
sourcePath: this.sourcePath,
|
|
|
|
}),
|
|
|
|
description: s__('StaticSiteEditor|Copy update'),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
disabled() {
|
|
|
|
return this.mergeRequestMeta.title === '';
|
|
|
|
},
|
|
|
|
primaryProps() {
|
|
|
|
return {
|
|
|
|
text: __('Submit changes'),
|
|
|
|
attributes: [{ variant: 'success' }, { disabled: this.disabled }],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
secondaryProps() {
|
|
|
|
return {
|
|
|
|
text: __('Keep editing'),
|
|
|
|
attributes: [{ variant: 'default' }],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
mounted() {
|
|
|
|
this.initTemplates();
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
methods: {
|
|
|
|
hide() {
|
|
|
|
this.$refs.modal.hide();
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
initTemplates() {
|
|
|
|
const { namespace, project } = this;
|
|
|
|
Api.issueTemplates(namespace, project, ISSUABLE_TYPE, (err, templates) => {
|
|
|
|
if (err) return; // Error handled by global AJAX error handler
|
|
|
|
this.mergeRequestTemplates = templates;
|
|
|
|
});
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
show() {
|
|
|
|
this.$refs.modal.show();
|
|
|
|
},
|
|
|
|
onPrimary() {
|
|
|
|
this.$emit('primary', this.mergeRequestMeta);
|
2021-01-29 00:20:46 +05:30
|
|
|
this.clearStorage = true;
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
onSecondary() {
|
|
|
|
this.hide();
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
onChangeTemplate(template) {
|
|
|
|
this.currentTemplate = template;
|
|
|
|
|
|
|
|
const description = this.currentTemplate ? this.currentTemplate.content : '';
|
|
|
|
const mergeRequestMeta = { ...this.mergeRequestMeta, description };
|
|
|
|
this.onUpdateSettings(mergeRequestMeta);
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
onUpdateSettings(mergeRequestMeta) {
|
|
|
|
this.mergeRequestMeta = { ...mergeRequestMeta };
|
|
|
|
},
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
storageKey: MR_META_LOCAL_STORAGE_KEY,
|
2021-01-03 14:25:43 +05:30
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<gl-modal
|
|
|
|
ref="modal"
|
|
|
|
modal-id="edit-meta-modal"
|
|
|
|
:title="__('Submit your changes')"
|
|
|
|
:action-primary="primaryProps"
|
|
|
|
:action-secondary="secondaryProps"
|
|
|
|
size="sm"
|
|
|
|
@primary="onPrimary"
|
|
|
|
@secondary="onSecondary"
|
|
|
|
@hide="() => $emit('hide')"
|
|
|
|
>
|
2021-01-29 00:20:46 +05:30
|
|
|
<local-storage-sync
|
|
|
|
v-model="mergeRequestMeta"
|
|
|
|
:storage-key="$options.storageKey"
|
|
|
|
:clear="clearStorage"
|
|
|
|
as-json
|
|
|
|
/>
|
2021-01-03 14:25:43 +05:30
|
|
|
<edit-meta-controls
|
|
|
|
ref="editMetaControls"
|
|
|
|
:title="mergeRequestMeta.title"
|
|
|
|
:description="mergeRequestMeta.description"
|
2021-01-29 00:20:46 +05:30
|
|
|
:templates="mergeRequestTemplates"
|
|
|
|
:current-template="currentTemplate"
|
2021-01-03 14:25:43 +05:30
|
|
|
@updateSettings="onUpdateSettings"
|
2021-01-29 00:20:46 +05:30
|
|
|
@changeTemplate="onChangeTemplate"
|
2021-01-03 14:25:43 +05:30
|
|
|
/>
|
|
|
|
</gl-modal>
|
|
|
|
</template>
|