2017-09-10 17:25:29 +05:30
|
|
|
<script>
|
2022-04-04 11:22:00 +05:30
|
|
|
import {
|
|
|
|
GlSafeHtmlDirective as SafeHtml,
|
|
|
|
GlModal,
|
|
|
|
GlModalDirective,
|
|
|
|
GlPopover,
|
|
|
|
GlButton,
|
|
|
|
} from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import $ from 'jquery';
|
2021-09-04 01:27:46 +05:30
|
|
|
import createFlash from '~/flash';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { __, sprintf } from '~/locale';
|
2022-01-26 12:08:38 +05:30
|
|
|
import TaskList from '~/task_list';
|
2022-05-07 20:08:51 +05:30
|
|
|
import Tracking from '~/tracking';
|
2022-04-04 11:22:00 +05:30
|
|
|
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
|
2022-05-07 20:08:51 +05:30
|
|
|
import WorkItemDetailModal from '~/work_items/components/work_item_detail_modal.vue';
|
2022-04-04 11:22:00 +05:30
|
|
|
import CreateWorkItem from '~/work_items/pages/create_work_item.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import animateMixin from '../mixins/animate';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
export default {
|
2020-11-24 15:15:51 +05:30
|
|
|
directives: {
|
|
|
|
SafeHtml,
|
2022-04-04 11:22:00 +05:30
|
|
|
GlModal: GlModalDirective,
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
components: {
|
|
|
|
GlModal,
|
|
|
|
GlPopover,
|
|
|
|
CreateWorkItem,
|
|
|
|
GlButton,
|
2022-05-07 20:08:51 +05:30
|
|
|
WorkItemDetailModal,
|
2022-04-04 11:22:00 +05:30
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
mixins: [animateMixin, glFeatureFlagMixin(), Tracking.mixin()],
|
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,
|
2020-11-24 15:15:51 +05:30
|
|
|
required: false,
|
|
|
|
default: '',
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
taskStatus: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
issuableType: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'issue',
|
|
|
|
},
|
|
|
|
updateUrl: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
lockVersion: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 0,
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
preAnimation: false,
|
|
|
|
pulseAnimation: false,
|
2020-11-24 15:15:51 +05:30
|
|
|
initialUpdate: true,
|
2022-04-04 11:22:00 +05:30
|
|
|
taskButtons: [],
|
|
|
|
activeTask: {},
|
2022-05-07 20:08:51 +05:30
|
|
|
workItemId: null,
|
2018-12-13 13:39:08 +05:30
|
|
|
};
|
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
computed: {
|
2022-05-07 20:08:51 +05:30
|
|
|
showWorkItemDetailModal() {
|
|
|
|
return Boolean(this.workItemId);
|
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
workItemsEnabled() {
|
|
|
|
return this.glFeatures.workItems;
|
|
|
|
},
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
watch: {
|
2020-11-24 15:15:51 +05:30
|
|
|
descriptionHtml(newDescription, oldDescription) {
|
|
|
|
if (!this.initialUpdate && newDescription !== oldDescription) {
|
|
|
|
this.animateChange();
|
|
|
|
} else {
|
|
|
|
this.initialUpdate = false;
|
|
|
|
}
|
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();
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
if (this.workItemsEnabled) {
|
|
|
|
this.renderTaskActions();
|
|
|
|
}
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
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',
|
2019-03-02 22:35:43 +05:30
|
|
|
lockVersion: this.lockVersion,
|
2018-12-13 13:39:08 +05:30
|
|
|
selector: '.detail-page-description',
|
2021-12-11 22:18:48 +05:30
|
|
|
onUpdate: this.taskListUpdateStarted.bind(this),
|
|
|
|
onSuccess: this.taskListUpdateSuccess.bind(this),
|
2019-03-02 22:35:43 +05:30
|
|
|
onError: this.taskListUpdateError.bind(this),
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
taskListUpdateStarted() {
|
|
|
|
this.$emit('taskListUpdateStarted');
|
|
|
|
},
|
|
|
|
|
|
|
|
taskListUpdateSuccess() {
|
|
|
|
this.$emit('taskListUpdateSucceeded');
|
|
|
|
},
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
taskListUpdateError() {
|
2021-09-04 01:27:46 +05:30
|
|
|
createFlash({
|
|
|
|
message: sprintf(
|
2021-12-11 22:18:48 +05:30
|
|
|
__(
|
2019-03-02 22:35:43 +05:30
|
|
|
'Someone edited this %{issueType} at the same time you did. The description has been updated and you will need to make your changes again.',
|
|
|
|
),
|
|
|
|
{
|
|
|
|
issueType: this.issuableType,
|
|
|
|
},
|
|
|
|
),
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
this.$emit('taskListUpdateFailed');
|
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
renderTaskActions() {
|
|
|
|
if (!this.$el?.querySelectorAll) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const taskListFields = this.$el.querySelectorAll('.task-list-item');
|
|
|
|
|
|
|
|
taskListFields.forEach((item, index) => {
|
|
|
|
const button = document.createElement('button');
|
|
|
|
button.classList.add(
|
|
|
|
'btn',
|
|
|
|
'btn-default',
|
|
|
|
'btn-md',
|
|
|
|
'gl-button',
|
|
|
|
'btn-default-tertiary',
|
|
|
|
'gl-left-0',
|
|
|
|
'gl-p-0!',
|
|
|
|
'gl-top-2',
|
|
|
|
'gl-absolute',
|
|
|
|
'js-add-task',
|
|
|
|
);
|
|
|
|
button.id = `js-task-button-${index}`;
|
|
|
|
this.taskButtons.push(button.id);
|
|
|
|
button.innerHTML = `
|
|
|
|
<svg data-testid="ellipsis_v-icon" role="img" aria-hidden="true" class="dropdown-icon gl-icon s14">
|
|
|
|
<use href="${gon.sprite_icons}#ellipsis_v"></use>
|
|
|
|
</svg>
|
|
|
|
`;
|
|
|
|
item.prepend(button);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
openCreateTaskModal(id) {
|
|
|
|
this.activeTask = { id, title: this.$el.querySelector(`#${id}`).parentElement.innerText };
|
|
|
|
this.$refs.modal.show();
|
|
|
|
},
|
|
|
|
closeCreateTaskModal() {
|
|
|
|
this.$refs.modal.hide();
|
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
closeWorkItemDetailModal() {
|
|
|
|
this.workItemId = null;
|
|
|
|
},
|
|
|
|
handleWorkItemDetailModalError(message) {
|
|
|
|
createFlash({ message });
|
|
|
|
},
|
|
|
|
handleCreateTask({ id, title, type }) {
|
2022-04-04 11:22:00 +05:30
|
|
|
const listItem = this.$el.querySelector(`#${this.activeTask.id}`).parentElement;
|
|
|
|
const taskBadge = document.createElement('span');
|
|
|
|
taskBadge.innerHTML = `
|
|
|
|
<svg data-testid="issue-open-m-icon" role="img" aria-hidden="true" class="gl-icon gl-fill-green-500 s12">
|
|
|
|
<use href="${gon.sprite_icons}#issue-open-m"></use>
|
|
|
|
</svg>
|
|
|
|
<span class="badge badge-info badge-pill gl-badge sm gl-mr-1">
|
|
|
|
${__('Task')}
|
|
|
|
</span>
|
|
|
|
`;
|
2022-05-07 20:08:51 +05:30
|
|
|
const button = this.createWorkItemDetailButton(id, title, type);
|
|
|
|
taskBadge.append(button);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
listItem.insertBefore(taskBadge, listItem.lastChild);
|
|
|
|
listItem.removeChild(listItem.lastChild);
|
|
|
|
this.closeCreateTaskModal();
|
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
createWorkItemDetailButton(id, title, type) {
|
|
|
|
const button = document.createElement('button');
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
this.workItemId = id;
|
|
|
|
this.track('viewed_work_item_from_modal', {
|
|
|
|
category: 'workItems:show',
|
|
|
|
label: 'work_item_view',
|
|
|
|
property: `type_${type}`,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
button.classList.add('btn-link');
|
|
|
|
button.innerText = title;
|
|
|
|
return button;
|
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
focusButton() {
|
|
|
|
this.$refs.convertButton[0].$el.focus();
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
safeHtmlConfig: { ADD_TAGS: ['gl-emoji', 'copy-code'] },
|
2018-12-13 13:39:08 +05:30
|
|
|
};
|
2017-09-10 17:25:29 +05:30
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
v-if="descriptionHtml"
|
|
|
|
:class="{
|
2019-02-15 15:39:39 +05:30
|
|
|
'js-task-list-container': canUpdate,
|
2022-04-04 11:22:00 +05:30
|
|
|
'work-items-enabled': workItemsEnabled,
|
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"
|
2021-11-11 11:23:49 +05:30
|
|
|
v-safe-html:[$options.safeHtmlConfig]="descriptionHtml"
|
2022-04-04 11:22:00 +05:30
|
|
|
data-testid="gfm-content"
|
2017-09-10 17:25:29 +05:30
|
|
|
:class="{
|
|
|
|
'issue-realtime-pre-pulse': preAnimation,
|
2019-02-15 15:39:39 +05:30
|
|
|
'issue-realtime-trigger-pulse': pulseAnimation,
|
2017-09-10 17:25:29 +05:30
|
|
|
}"
|
2019-07-07 11:18:12 +05:30
|
|
|
class="md"
|
2019-02-15 15:39:39 +05:30
|
|
|
></div>
|
2021-03-11 19:13:27 +05:30
|
|
|
<!-- eslint-disable vue/no-mutating-props -->
|
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"
|
2019-07-31 22:56:46 +05:30
|
|
|
dir="auto"
|
2022-04-04 11:22:00 +05:30
|
|
|
data-testid="textarea"
|
2018-03-17 18:26:18 +05:30
|
|
|
>
|
2017-09-10 17:25:29 +05:30
|
|
|
</textarea>
|
2021-03-11 19:13:27 +05:30
|
|
|
<!-- eslint-enable vue/no-mutating-props -->
|
2022-04-04 11:22:00 +05:30
|
|
|
<gl-modal
|
|
|
|
ref="modal"
|
|
|
|
modal-id="create-task-modal"
|
|
|
|
:title="s__('WorkItem|New Task')"
|
|
|
|
hide-footer
|
|
|
|
body-class="gl-p-0!"
|
|
|
|
>
|
|
|
|
<create-work-item
|
|
|
|
:is-modal="true"
|
|
|
|
:initial-title="activeTask.title"
|
|
|
|
@closeModal="closeCreateTaskModal"
|
|
|
|
@onCreate="handleCreateTask"
|
|
|
|
/>
|
|
|
|
</gl-modal>
|
2022-05-07 20:08:51 +05:30
|
|
|
<work-item-detail-modal
|
|
|
|
:visible="showWorkItemDetailModal"
|
|
|
|
:work-item-id="workItemId"
|
|
|
|
@close="closeWorkItemDetailModal"
|
|
|
|
@error="handleWorkItemDetailModalError"
|
|
|
|
/>
|
2022-04-04 11:22:00 +05:30
|
|
|
<template v-if="workItemsEnabled">
|
|
|
|
<gl-popover
|
|
|
|
v-for="item in taskButtons"
|
|
|
|
:key="item"
|
|
|
|
:target="item"
|
|
|
|
placement="top"
|
|
|
|
triggers="focus"
|
|
|
|
@shown="focusButton"
|
|
|
|
>
|
|
|
|
<gl-button
|
|
|
|
ref="convertButton"
|
|
|
|
variant="link"
|
|
|
|
data-testid="convert-to-task"
|
|
|
|
class="gl-text-gray-900! gl-text-decoration-none! gl-outline-0!"
|
|
|
|
@click="openCreateTaskModal(item)"
|
|
|
|
>{{ s__('WorkItem|Convert to work item') }}</gl-button
|
|
|
|
>
|
|
|
|
</gl-popover>
|
|
|
|
</template>
|
2017-09-10 17:25:29 +05:30
|
|
|
</div>
|
|
|
|
</template>
|