2017-05-10 07:29:33 -04:00
|
|
|
<script>
|
2017-05-12 06:23:30 -04:00
|
|
|
/* global Flash */
|
2017-05-10 07:29:33 -04:00
|
|
|
import Visibility from 'visibilityjs';
|
|
|
|
import Poll from '../../lib/utils/poll';
|
2017-05-12 06:23:30 -04:00
|
|
|
import eventHub from '../event_hub';
|
2017-05-10 07:29:33 -04:00
|
|
|
import Service from '../services/index';
|
|
|
|
import Store from '../stores';
|
|
|
|
import titleComponent from './title.vue';
|
|
|
|
import descriptionComponent from './description.vue';
|
2017-05-16 04:43:33 -04:00
|
|
|
import formComponent from './form.vue';
|
2017-05-10 07:29:33 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
endpoint: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
canUpdate: {
|
|
|
|
required: true,
|
|
|
|
type: Boolean,
|
|
|
|
},
|
2017-05-12 06:58:48 -04:00
|
|
|
canDestroy: {
|
|
|
|
required: true,
|
|
|
|
type: Boolean,
|
|
|
|
},
|
2017-05-10 07:29:33 -04:00
|
|
|
issuableRef: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
initialTitle: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
initialDescriptionHtml: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
initialDescriptionText: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2017-05-15 12:00:16 -04:00
|
|
|
isConfidential: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2017-05-12 10:52:45 -04:00
|
|
|
markdownPreviewUrl: {
|
|
|
|
type: String,
|
2017-05-12 06:23:30 -04:00
|
|
|
required: true,
|
|
|
|
},
|
2017-05-15 07:28:42 -04:00
|
|
|
markdownDocs: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2017-05-10 07:29:33 -04:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
const store = new Store({
|
2017-05-10 12:28:36 -04:00
|
|
|
titleHtml: this.initialTitle,
|
2017-05-10 07:29:33 -04:00
|
|
|
descriptionHtml: this.initialDescriptionHtml,
|
|
|
|
descriptionText: this.initialDescriptionText,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
store,
|
|
|
|
state: store.state,
|
2017-05-12 07:54:10 -04:00
|
|
|
showForm: false,
|
2017-05-10 07:29:33 -04:00
|
|
|
};
|
|
|
|
},
|
2017-05-12 07:54:10 -04:00
|
|
|
computed: {
|
2017-05-15 10:34:01 -04:00
|
|
|
formState() {
|
|
|
|
return this.store.formState;
|
|
|
|
},
|
2017-05-12 07:54:10 -04:00
|
|
|
},
|
2017-05-10 07:29:33 -04:00
|
|
|
components: {
|
|
|
|
descriptionComponent,
|
|
|
|
titleComponent,
|
2017-05-16 04:43:33 -04:00
|
|
|
formComponent,
|
2017-05-12 06:23:30 -04:00
|
|
|
},
|
|
|
|
methods: {
|
2017-05-12 07:54:10 -04:00
|
|
|
openForm() {
|
|
|
|
this.showForm = true;
|
|
|
|
this.store.formState = {
|
|
|
|
title: this.state.titleText,
|
2017-05-15 12:00:16 -04:00
|
|
|
confidential: this.isConfidential,
|
2017-05-12 10:52:45 -04:00
|
|
|
description: this.state.descriptionText,
|
2017-05-12 07:54:10 -04:00
|
|
|
};
|
|
|
|
},
|
2017-05-15 06:09:13 -04:00
|
|
|
closeForm() {
|
|
|
|
this.showForm = false;
|
|
|
|
},
|
2017-05-12 06:23:30 -04:00
|
|
|
updateIssuable() {
|
2017-05-15 06:09:13 -04:00
|
|
|
this.service.updateIssuable(this.store.formState)
|
2017-05-15 12:00:16 -04:00
|
|
|
.then((res) => {
|
|
|
|
const data = res.json();
|
|
|
|
|
|
|
|
if (data.confidential !== this.isConfidential) {
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
2017-05-12 06:23:30 -04:00
|
|
|
eventHub.$emit('close.form');
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
eventHub.$emit('close.form');
|
|
|
|
return new Flash('Error updating issue');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
deleteIssuable() {
|
|
|
|
this.service.deleteIssuable()
|
2017-05-12 08:04:36 -04:00
|
|
|
.then(res => res.json())
|
2017-05-12 06:23:30 -04:00
|
|
|
.then((data) => {
|
|
|
|
// Stop the poll so we don't get 404's with the issue not existing
|
|
|
|
this.poll.stop();
|
2017-05-12 07:57:52 -04:00
|
|
|
|
|
|
|
gl.utils.visitUrl(data.path);
|
2017-05-12 06:23:30 -04:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
eventHub.$emit('close.form');
|
|
|
|
return new Flash('Error deleting issue');
|
|
|
|
});
|
|
|
|
},
|
2017-05-10 07:29:33 -04:00
|
|
|
},
|
|
|
|
created() {
|
2017-05-12 06:23:30 -04:00
|
|
|
this.service = new Service(this.endpoint);
|
|
|
|
this.poll = new Poll({
|
|
|
|
resource: this.service,
|
2017-05-10 07:29:33 -04:00
|
|
|
method: 'getData',
|
|
|
|
successCallback: (res) => {
|
|
|
|
this.store.updateState(res.json());
|
|
|
|
},
|
|
|
|
errorCallback(err) {
|
|
|
|
throw new Error(err);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!Visibility.hidden()) {
|
2017-05-12 06:23:30 -04:00
|
|
|
this.poll.makeRequest();
|
2017-05-10 07:29:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Visibility.change(() => {
|
|
|
|
if (!Visibility.hidden()) {
|
2017-05-12 06:23:30 -04:00
|
|
|
this.poll.restart();
|
2017-05-10 07:29:33 -04:00
|
|
|
} else {
|
2017-05-12 06:23:30 -04:00
|
|
|
this.poll.stop();
|
2017-05-10 07:29:33 -04:00
|
|
|
}
|
|
|
|
});
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
eventHub.$on('delete.issuable', this.deleteIssuable);
|
|
|
|
eventHub.$on('update.issuable', this.updateIssuable);
|
2017-05-15 06:09:13 -04:00
|
|
|
eventHub.$on('close.form', this.closeForm);
|
2017-05-12 07:54:10 -04:00
|
|
|
eventHub.$on('open.form', this.openForm);
|
2017-05-12 06:23:30 -04:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('delete.issuable', this.deleteIssuable);
|
|
|
|
eventHub.$off('update.issuable', this.updateIssuable);
|
2017-05-15 06:09:13 -04:00
|
|
|
eventHub.$off('close.form', this.closeForm);
|
2017-05-15 06:38:26 -04:00
|
|
|
eventHub.$off('open.form', this.openForm);
|
2017-05-10 07:29:33 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2017-05-16 04:43:33 -04:00
|
|
|
<div>
|
|
|
|
<form-component
|
2017-05-12 06:58:48 -04:00
|
|
|
v-if="canUpdate && showForm"
|
2017-05-16 04:43:33 -04:00
|
|
|
:form-state="formState"
|
2017-05-16 05:37:05 -04:00
|
|
|
:can-destroy="canDestroy"
|
|
|
|
:markdown-docs="markdownDocs"
|
|
|
|
:markdown-preview-url="markdownPreviewUrl" />
|
2017-05-16 04:43:33 -04:00
|
|
|
<div v-else>
|
|
|
|
<title-component
|
|
|
|
:issuable-ref="issuableRef"
|
|
|
|
:title-html="state.titleHtml"
|
|
|
|
:title-text="state.titleText" />
|
|
|
|
<description-component
|
|
|
|
v-if="state.descriptionHtml"
|
|
|
|
:can-update="canUpdate"
|
|
|
|
:description-html="state.descriptionHtml"
|
|
|
|
:description-text="state.descriptionText"
|
|
|
|
:updated-at="state.updatedAt"
|
|
|
|
:task-status="state.taskStatus" />
|
|
|
|
</div>
|
2017-05-10 07:29:33 -04:00
|
|
|
</div>
|
|
|
|
</template>
|