2022-05-04 13:46:34 +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-06-06 15:52:30 +00:00
|
|
|
import { createEventDispatcher } from 'svelte'
|
2022-06-08 14:03:26 +00:00
|
|
|
import { AttachedData, Ref, SortingOrder, WithLookup } from '@anticrm/core'
|
2022-05-16 10:38:51 +00:00
|
|
|
import { Issue, IssueStatus } from '@anticrm/tracker'
|
2022-06-16 10:33:52 +00:00
|
|
|
import { createQuery, getClient } from '@anticrm/presentation'
|
2022-07-05 05:00:54 +00:00
|
|
|
import { Button, showPopup, SelectPopup, TooltipAlignment, eventToHTMLElement, getPlatformColor } from '@anticrm/ui'
|
2022-05-09 11:37:34 +00:00
|
|
|
import type { ButtonKind, ButtonSize } from '@anticrm/ui'
|
2022-05-04 13:46:34 +00:00
|
|
|
import tracker from '../../plugin'
|
2022-07-05 05:00:54 +00:00
|
|
|
import IssueStatusIcon from './IssueStatusIcon.svelte'
|
2022-05-04 13:46:34 +00:00
|
|
|
|
2022-06-06 15:52:30 +00:00
|
|
|
export let value: Issue | AttachedData<Issue>
|
2022-06-17 08:28:31 +00:00
|
|
|
export let statuses: WithLookup<IssueStatus>[] | undefined = undefined
|
2022-05-04 13:46:34 +00:00
|
|
|
export let isEditable: boolean = true
|
|
|
|
export let shouldShowLabel: boolean = false
|
2022-06-02 16:57:07 +00:00
|
|
|
export let tooltipAlignment: TooltipAlignment | undefined = undefined
|
2022-05-04 13:46:34 +00:00
|
|
|
|
2022-05-09 11:37:34 +00:00
|
|
|
export let kind: ButtonKind = 'link'
|
|
|
|
export let size: ButtonSize = 'large'
|
|
|
|
export let justify: 'left' | 'center' = 'left'
|
2022-06-17 08:28:31 +00:00
|
|
|
export let width: string | undefined = undefined
|
2022-05-09 11:37:34 +00:00
|
|
|
|
2022-05-04 13:46:34 +00:00
|
|
|
const client = getClient()
|
2022-06-16 10:33:52 +00:00
|
|
|
const statusesQuery = createQuery()
|
2022-06-06 15:52:30 +00:00
|
|
|
const dispatch = createEventDispatcher()
|
2022-05-04 13:46:34 +00:00
|
|
|
|
2022-06-17 08:28:31 +00:00
|
|
|
const changeStatus = async (newStatus: Ref<IssueStatus> | undefined) => {
|
2022-05-16 10:38:51 +00:00
|
|
|
if (!isEditable || newStatus === undefined || value.status === newStatus) {
|
2022-05-04 13:46:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:52:30 +00:00
|
|
|
dispatch('change', newStatus)
|
|
|
|
|
|
|
|
if ('_id' in value) {
|
|
|
|
await client.update(value, { status: newStatus })
|
|
|
|
}
|
2022-05-04 13:46:34 +00:00
|
|
|
}
|
2022-06-17 08:28:31 +00:00
|
|
|
|
|
|
|
const handleStatusEditorOpened = (event: MouseEvent) => {
|
|
|
|
if (!isEditable) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
showPopup(
|
|
|
|
SelectPopup,
|
|
|
|
{ value: statusesInfo, placeholder: tracker.string.SetStatus, searchable: true },
|
|
|
|
eventToHTMLElement(event),
|
|
|
|
changeStatus
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
$: selectedStatus = statuses?.find((status) => status._id === value.status) ?? statuses?.[0]
|
|
|
|
$: selectedStatusLabel = shouldShowLabel ? selectedStatus?.name : undefined
|
2022-07-05 05:00:54 +00:00
|
|
|
$: statusesInfo = statuses?.map((s) => {
|
|
|
|
const color = s.color ?? s.$lookup?.category?.color
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: s._id,
|
|
|
|
text: s.name,
|
|
|
|
icon: s.$lookup?.category?.icon,
|
|
|
|
...(color !== undefined ? { iconColor: getPlatformColor(color) } : undefined)
|
|
|
|
}
|
|
|
|
})
|
2022-06-08 15:49:38 +00:00
|
|
|
$: if (!statuses) {
|
|
|
|
const query = '_id' in value ? { attachedTo: value.space } : {}
|
2022-06-16 10:33:52 +00:00
|
|
|
statusesQuery.query(
|
|
|
|
tracker.class.IssueStatus,
|
|
|
|
query,
|
|
|
|
(result) => {
|
|
|
|
statuses = result
|
|
|
|
},
|
|
|
|
{
|
2022-06-08 15:49:38 +00:00
|
|
|
lookup: { category: tracker.class.IssueStatusCategory },
|
|
|
|
sort: { rank: SortingOrder.Ascending }
|
2022-06-16 10:33:52 +00:00
|
|
|
}
|
|
|
|
)
|
2022-06-08 15:49:38 +00:00
|
|
|
}
|
2022-05-04 13:46:34 +00:00
|
|
|
</script>
|
|
|
|
|
2022-06-08 14:03:26 +00:00
|
|
|
{#if value && statuses}
|
2022-06-20 14:11:14 +00:00
|
|
|
{#if kind === 'list'}
|
|
|
|
<div class="flex-row-center flex-no-shrink" class:cursor-pointer={isEditable} on:click={handleStatusEditorOpened}>
|
|
|
|
<div class="flex-center flex-no-shrink square-4">
|
2022-07-05 05:00:54 +00:00
|
|
|
{#if selectedStatus}<IssueStatusIcon value={selectedStatus} size="inline" />{/if}
|
2022-06-20 14:11:14 +00:00
|
|
|
</div>
|
|
|
|
{#if selectedStatusLabel}
|
|
|
|
<span class="ml-2 overflow-label disabled text-md fs-bold content-accent-color">
|
|
|
|
{selectedStatusLabel}
|
|
|
|
</span>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2022-07-05 05:00:54 +00:00
|
|
|
{:else}
|
2022-06-17 08:28:31 +00:00
|
|
|
<Button
|
|
|
|
showTooltip={isEditable ? { label: tracker.string.SetStatus, direction: tooltipAlignment } : undefined}
|
|
|
|
disabled={!isEditable}
|
|
|
|
{justify}
|
2022-05-09 11:37:34 +00:00
|
|
|
{size}
|
2022-06-17 08:28:31 +00:00
|
|
|
{kind}
|
2022-05-09 11:37:34 +00:00
|
|
|
{width}
|
2022-06-17 08:28:31 +00:00
|
|
|
on:click={handleStatusEditorOpened}
|
|
|
|
>
|
2022-07-05 05:00:54 +00:00
|
|
|
<span slot="content" class="inline-flex">
|
|
|
|
{#if selectedStatus}
|
|
|
|
<IssueStatusIcon value={selectedStatus} size="inline" />
|
|
|
|
{/if}
|
|
|
|
{#if selectedStatusLabel}
|
|
|
|
<span class="overflow-label disabled" class:ml-1={selectedStatus}>{selectedStatusLabel}</span>
|
|
|
|
{/if}
|
|
|
|
</span>
|
2022-06-17 08:28:31 +00:00
|
|
|
</Button>
|
|
|
|
{/if}
|
2022-05-04 13:46:34 +00:00
|
|
|
{/if}
|