2022-04-14 06:07:07 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2022-05-16 10:38:51 +00:00
|
|
|
import { Timestamp, WithLookup } from '@anticrm/core'
|
|
|
|
import { Issue } from '@anticrm/tracker'
|
2022-04-14 06:07:07 +00:00
|
|
|
import { DatePresenter, Tooltip, getDaysDifference } from '@anticrm/ui'
|
|
|
|
import { getClient } from '@anticrm/presentation'
|
|
|
|
import DueDatePopup from './DueDatePopup.svelte'
|
|
|
|
import tracker from '../../plugin'
|
2022-05-18 04:04:54 +00:00
|
|
|
import { getDueDateIconModifier } from '../../utils'
|
2022-04-14 06:07:07 +00:00
|
|
|
|
2022-04-23 16:59:57 +00:00
|
|
|
export let value: WithLookup<Issue>
|
2022-04-14 06:07:07 +00:00
|
|
|
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
$: today = new Date(new Date(Date.now()).setHours(0, 0, 0, 0))
|
|
|
|
$: dueDateMs = value.dueDate
|
|
|
|
$: isOverdue = dueDateMs !== null && dueDateMs < today.getTime()
|
|
|
|
$: dueDate = dueDateMs === null ? null : new Date(dueDateMs)
|
|
|
|
$: daysDifference = dueDate === null ? null : getDaysDifference(today, dueDate)
|
2022-05-18 04:04:54 +00:00
|
|
|
$: iconModifier = getDueDateIconModifier(isOverdue, daysDifference)
|
2022-04-14 06:07:07 +00:00
|
|
|
$: formattedDate = !dueDateMs ? '' : new Date(dueDateMs).toLocaleString('default', { month: 'short', day: 'numeric' })
|
|
|
|
|
|
|
|
const handleDueDateChanged = async (event: CustomEvent<Timestamp>) => {
|
|
|
|
const newDate = event.detail
|
|
|
|
|
2022-05-16 10:38:51 +00:00
|
|
|
if (newDate === undefined || value.dueDate === newDate) {
|
2022-04-14 06:07:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:38:51 +00:00
|
|
|
await client.update(value, { dueDate: newDate })
|
2022-04-14 06:07:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-23 16:59:57 +00:00
|
|
|
$: shouldRenderPresenter =
|
|
|
|
dueDateMs &&
|
|
|
|
value.$lookup?.status?.category !== tracker.issueStatusCategory.Completed &&
|
|
|
|
value.$lookup?.status?.category !== tracker.issueStatusCategory.Canceled
|
2022-04-14 06:07:07 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if shouldRenderPresenter}
|
|
|
|
<Tooltip
|
|
|
|
direction={'top'}
|
|
|
|
component={DueDatePopup}
|
|
|
|
props={{
|
|
|
|
formattedDate: formattedDate,
|
|
|
|
daysDifference: daysDifference,
|
|
|
|
isOverdue: isOverdue,
|
|
|
|
iconModifier: iconModifier
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<DatePresenter
|
|
|
|
value={dueDateMs}
|
|
|
|
editable={true}
|
|
|
|
shouldShowLabel={false}
|
|
|
|
icon={iconModifier}
|
|
|
|
on:change={handleDueDateChanged}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
{/if}
|