debian-mirror-gitlab/app/assets/javascripts/issuable/mixins/related_issuable_mixin.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

216 lines
4.9 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import { isEmpty } from 'lodash';
2023-06-20 00:43:36 +05:30
import { STATUS_CLOSED, STATUS_MERGED, STATUS_OPEN, STATUS_REOPENED } from '~/issues/constants';
2019-07-07 11:18:12 +05:30
import { formatDate } from '~/lib/utils/datetime_utility';
2021-03-11 19:13:27 +05:30
import { sprintf, __ } from '~/locale';
2019-07-07 11:18:12 +05:30
import timeagoMixin from '~/vue_shared/mixins/timeago';
const mixins = {
data() {
return {
removeDisabled: false,
};
},
props: {
idKey: {
type: Number,
required: true,
},
displayReference: {
type: String,
required: true,
},
pathIdSeparator: {
type: String,
required: true,
},
eventNamespace: {
type: String,
required: false,
default: '',
},
confidential: {
type: Boolean,
required: false,
default: false,
},
title: {
type: String,
required: false,
default: '',
},
path: {
type: String,
required: false,
default: '',
},
state: {
type: String,
required: false,
default: '',
},
createdAt: {
type: String,
required: false,
default: '',
},
closedAt: {
type: String,
required: false,
default: '',
},
mergedAt: {
type: String,
required: false,
default: '',
},
milestone: {
type: Object,
required: false,
default: () => ({}),
},
dueDate: {
type: String,
required: false,
default: '',
},
assignees: {
type: Array,
required: false,
default: () => [],
},
weight: {
type: Number,
required: false,
default: 0,
},
canRemove: {
type: Boolean,
required: false,
default: false,
},
isMergeRequest: {
type: Boolean,
required: false,
default: false,
},
pipelineStatus: {
type: Object,
required: false,
default: () => ({}),
},
},
mixins: [timeagoMixin],
computed: {
hasState() {
return this.state && this.state.length > 0;
},
hasPipeline() {
return this.isMergeRequest && this.pipelineStatus && Object.keys(this.pipelineStatus).length;
},
isOpen() {
2023-06-20 00:43:36 +05:30
return this.state === STATUS_OPEN || this.state === STATUS_REOPENED;
2019-07-07 11:18:12 +05:30
},
isClosed() {
2023-06-20 00:43:36 +05:30
return this.state === STATUS_CLOSED;
2019-07-07 11:18:12 +05:30
},
isMerged() {
2023-06-20 00:43:36 +05:30
return this.state === STATUS_MERGED;
2019-07-07 11:18:12 +05:30
},
hasTitle() {
return this.title.length > 0;
},
2019-09-30 21:07:59 +05:30
hasAssignees() {
return this.assignees.length > 0;
},
2019-07-07 11:18:12 +05:30
hasMilestone() {
2020-04-22 19:07:51 +05:30
return !isEmpty(this.milestone);
2019-07-07 11:18:12 +05:30
},
iconName() {
if (this.isMergeRequest && this.isMerged) {
return 'merge';
}
return this.isOpen ? 'issue-open-m' : 'issue-close';
},
iconClass() {
if (this.isMergeRequest && this.isClosed) {
return 'merge-request-status closed issue-token-state-icon-closed';
}
2020-06-23 00:09:42 +05:30
return this.isOpen
? 'issue-token-state-icon-open gl-text-green-500'
: 'issue-token-state-icon-closed gl-text-blue-500';
2019-07-07 11:18:12 +05:30
},
computedLinkElementType() {
return this.path.length > 0 ? 'a' : 'span';
},
computedPath() {
return this.path.length ? this.path : null;
},
itemPath() {
return this.displayReference.split(this.pathIdSeparator)[0];
},
itemId() {
return this.displayReference.split(this.pathIdSeparator).pop();
},
createdAtInWords() {
2020-01-01 13:55:28 +05:30
return this.createdAt ? this.timeFormatted(this.createdAt) : '';
2019-07-07 11:18:12 +05:30
},
createdAtTimestamp() {
return this.createdAt ? formatDate(new Date(this.createdAt)) : '';
},
mergedAtTimestamp() {
return this.mergedAt ? formatDate(new Date(this.mergedAt)) : '';
},
mergedAtInWords() {
2020-01-01 13:55:28 +05:30
return this.mergedAt ? this.timeFormatted(this.mergedAt) : '';
2019-07-07 11:18:12 +05:30
},
closedAtInWords() {
2020-01-01 13:55:28 +05:30
return this.closedAt ? this.timeFormatted(this.closedAt) : '';
2019-07-07 11:18:12 +05:30
},
closedAtTimestamp() {
return this.closedAt ? formatDate(new Date(this.closedAt)) : '';
},
stateText() {
if (this.isMerged) {
return __('Merged');
}
2021-04-17 20:07:23 +05:30
return this.isOpen ? __('Created') : __('Closed');
2019-07-07 11:18:12 +05:30
},
stateTimeInWords() {
if (this.isMerged) {
return this.mergedAtInWords;
}
return this.isOpen ? this.createdAtInWords : this.closedAtInWords;
},
stateTimestamp() {
if (this.isMerged) {
return this.mergedAtTimestamp;
}
return this.isOpen ? this.createdAtTimestamp : this.closedAtTimestamp;
},
pipelineStatusTooltip() {
return this.hasPipeline
? sprintf(__('Pipeline: %{status}'), { status: this.pipelineStatus.label })
: '';
},
},
methods: {
onRemoveRequest() {
let namespacePrefix = '';
if (this.eventNamespace && this.eventNamespace.length > 0) {
namespacePrefix = `${this.eventNamespace}`;
}
this.$emit(`${namespacePrefix}RemoveRequest`, this.idKey);
this.removeDisabled = true;
},
},
};
export default mixins;