debian-mirror-gitlab/app/assets/javascripts/boards/components/issue_due_date.vue

100 lines
2.5 KiB
Vue
Raw Normal View History

2018-12-13 13:39:08 +05:30
<script>
import dateFormat from 'dateformat';
2019-02-15 15:39:39 +05:30
import { GlTooltip } from '@gitlab/ui';
2018-12-13 13:39:08 +05:30
import Icon from '~/vue_shared/components/icon.vue';
import { __ } from '~/locale';
2019-02-15 15:39:39 +05:30
import {
getDayDifference,
getTimeago,
dateInWords,
parsePikadayDate,
} from '~/lib/utils/datetime_utility';
2018-12-13 13:39:08 +05:30
export default {
components: {
Icon,
GlTooltip,
},
props: {
date: {
type: String,
required: true,
},
2019-02-15 15:39:39 +05:30
cssClass: {
type: String,
required: false,
default: '',
},
tooltipPlacement: {
type: String,
required: false,
default: 'bottom',
},
2018-12-13 13:39:08 +05:30
},
computed: {
title() {
const timeago = getTimeago();
const { timeDifference, standardDateFormat } = this;
const formatedDate = standardDateFormat;
if (timeDifference >= -1 && timeDifference < 7) {
return `${timeago.format(this.issueDueDate)} (${formatedDate})`;
}
return timeago.format(this.issueDueDate);
},
body() {
const { timeDifference, issueDueDate, standardDateFormat } = this;
if (timeDifference === 0) {
return __('Today');
} else if (timeDifference === 1) {
return __('Tomorrow');
} else if (timeDifference === -1) {
return __('Yesterday');
} else if (timeDifference > 0 && timeDifference < 7) {
2019-07-07 11:18:12 +05:30
return dateFormat(issueDueDate, 'dddd');
2018-12-13 13:39:08 +05:30
}
return standardDateFormat;
},
issueDueDate() {
2019-02-15 15:39:39 +05:30
return parsePikadayDate(this.date);
2018-12-13 13:39:08 +05:30
},
timeDifference() {
const today = new Date();
return getDayDifference(today, this.issueDueDate);
},
isPastDue() {
if (this.timeDifference >= 0) return false;
return true;
},
standardDateFormat() {
const today = new Date();
const isDueInCurrentYear = today.getFullYear() === this.issueDueDate.getFullYear();
return dateInWords(this.issueDueDate, true, isDueInCurrentYear);
},
},
};
</script>
<template>
<span>
2019-02-15 15:39:39 +05:30
<span ref="issueDueDate" :class="cssClass" class="board-card-info card-number">
2019-07-31 22:56:46 +05:30
<icon
:class="{ 'text-danger': isPastDue }"
class="board-card-info-icon align-top"
name="calendar"
/>
2019-02-15 15:39:39 +05:30
<time :class="{ 'text-danger': isPastDue }" datetime="date" class="board-card-info-text">{{
body
}}</time>
2018-12-13 13:39:08 +05:30
</span>
2019-02-15 15:39:39 +05:30
<gl-tooltip :target="() => $refs.issueDueDate" :placement="tooltipPlacement">
<span class="bold">{{ __('Due date') }}</span> <br />
<span :class="{ 'text-danger-muted': isPastDue }">{{ title }}</span>
2018-12-13 13:39:08 +05:30
</gl-tooltip>
</span>
</template>