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-12 06:23:30 -04:00
|
|
|
import editActions from './edit_actions.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-12 06:23:30 -04:00
|
|
|
showForm: {
|
|
|
|
type: Boolean,
|
|
|
|
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 06:23:30 -04:00
|
|
|
formState: store.formState,
|
2017-05-10 07:29:33 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
descriptionComponent,
|
|
|
|
titleComponent,
|
2017-05-12 06:23:30 -04:00
|
|
|
editActions,
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateIssuable() {
|
|
|
|
this.service.updateIssuable(this.formState)
|
|
|
|
.then(() => {
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('delete.issuable', this.deleteIssuable);
|
|
|
|
eventHub.$off('update.issuable', this.updateIssuable);
|
2017-05-10 07:29:33 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<title-component
|
|
|
|
:issuable-ref="issuableRef"
|
|
|
|
:title-html="state.titleHtml"
|
|
|
|
:title-text="state.titleText" />
|
|
|
|
<description-component
|
2017-05-10 12:28:36 -04:00
|
|
|
v-if="state.descriptionHtml"
|
2017-05-10 07:29:33 -04:00
|
|
|
:can-update="canUpdate"
|
|
|
|
:description-html="state.descriptionHtml"
|
|
|
|
:description-text="state.descriptionText"
|
|
|
|
:updated-at="state.updatedAt"
|
|
|
|
:task-status="state.taskStatus" />
|
2017-05-12 06:23:30 -04:00
|
|
|
<edit-actions
|
2017-05-12 06:58:48 -04:00
|
|
|
v-if="canUpdate && showForm"
|
|
|
|
:can-destroy="canDestroy" />
|
2017-05-10 07:29:33 -04:00
|
|
|
</div>
|
|
|
|
</template>
|