debian-mirror-gitlab/app/assets/javascripts/issue_show/components/description.vue

137 lines
2.9 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2018-12-13 13:39:08 +05:30
import $ from 'jquery';
import animateMixin from '../mixins/animate';
import TaskList from '../../task_list';
import recaptchaModalImplementor from '../../vue_shared/mixins/recaptcha_modal_implementor';
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
export default {
mixins: [animateMixin, recaptchaModalImplementor],
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
props: {
canUpdate: {
type: Boolean,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
descriptionHtml: {
type: String,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
descriptionText: {
type: String,
required: true,
},
taskStatus: {
type: String,
required: false,
default: '',
},
issuableType: {
type: String,
required: false,
default: 'issue',
},
updateUrl: {
type: String,
required: false,
default: null,
},
},
data() {
return {
preAnimation: false,
pulseAnimation: false,
};
},
watch: {
descriptionHtml() {
this.animateChange();
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
this.$nextTick(() => {
this.renderGFM();
});
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
taskStatus() {
2018-03-17 18:26:18 +05:30
this.updateTaskStatusText();
},
2018-12-13 13:39:08 +05:30
},
mounted() {
this.renderGFM();
this.updateTaskStatusText();
},
methods: {
renderGFM() {
$(this.$refs['gfm-content']).renderGFM();
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
if (this.canUpdate) {
// eslint-disable-next-line no-new
new TaskList({
dataType: this.issuableType,
fieldName: 'description',
selector: '.detail-page-description',
onSuccess: this.taskListUpdateSuccess.bind(this),
});
}
},
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
taskListUpdateSuccess(data) {
try {
this.checkForSpam(data);
this.closeRecaptcha();
} catch (error) {
if (error && error.name === 'SpamError') this.openRecaptcha();
}
},
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
updateTaskStatusText() {
const taskRegexMatches = this.taskStatus.match(/(\d+) of ((?!0)\d+)/);
const $issuableHeader = $('.issuable-meta');
const $tasks = $('#task_status', $issuableHeader);
const $tasksShort = $('#task_status_short', $issuableHeader);
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
if (taskRegexMatches) {
$tasks.text(this.taskStatus);
$tasksShort.text(
`${taskRegexMatches[1]}/${taskRegexMatches[2]} task${taskRegexMatches[2] > 1 ? 's' : ''}`,
);
} else {
$tasks.text('');
$tasksShort.text('');
}
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
},
};
2017-09-10 17:25:29 +05:30
</script>
<template>
<div
v-if="descriptionHtml"
:class="{
2019-01-03 12:48:30 +05:30
'js-task-list-container': canUpdate
2018-03-17 18:26:18 +05:30
}"
2018-11-08 19:23:39 +05:30
class="description"
2018-03-17 18:26:18 +05:30
>
2017-09-10 17:25:29 +05:30
<div
2018-11-08 19:23:39 +05:30
ref="gfm-content"
2017-09-10 17:25:29 +05:30
:class="{
'issue-realtime-pre-pulse': preAnimation,
2019-01-03 12:48:30 +05:30
'issue-realtime-trigger-pulse': pulseAnimation
2017-09-10 17:25:29 +05:30
}"
2018-11-08 19:23:39 +05:30
class="wiki"
2019-01-03 12:48:30 +05:30
v-html="descriptionHtml">
</div>
2017-09-10 17:25:29 +05:30
<textarea
v-if="descriptionText"
2018-03-17 18:26:18 +05:30
v-model="descriptionText"
:data-update-url="updateUrl"
2018-11-08 19:23:39 +05:30
class="hidden js-task-list-field"
2018-03-17 18:26:18 +05:30
>
2017-09-10 17:25:29 +05:30
</textarea>
2018-03-17 18:26:18 +05:30
2019-01-03 12:48:30 +05:30
<recaptcha-modal
v-show="showRecaptcha"
:html="recaptchaHTML"
@close="closeRecaptcha"
/>
2017-09-10 17:25:29 +05:30
</div>
</template>