2022-05-23 07:24:15 +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-10 15:51:31 +00:00
|
|
|
import { AttachedData, FindOptions, SortingOrder } from '@anticrm/core'
|
2022-06-24 12:36:08 +00:00
|
|
|
import { getClient, ObjectPopup } from '@anticrm/presentation'
|
|
|
|
import { calcRank, Issue, IssueStatusCategory } from '@anticrm/tracker'
|
2022-05-23 07:24:15 +00:00
|
|
|
import { Icon } from '@anticrm/ui'
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
|
|
|
import tracker from '../plugin'
|
2022-06-09 14:49:57 +00:00
|
|
|
import { getIssueId } from '../utils'
|
2022-05-23 07:24:15 +00:00
|
|
|
|
2022-06-24 12:36:08 +00:00
|
|
|
export let value: Issue | AttachedData<Issue> | Issue[]
|
|
|
|
export let width: 'medium' | 'large' | 'full' = 'large'
|
2022-05-23 07:24:15 +00:00
|
|
|
|
|
|
|
const client = getClient()
|
2022-06-24 12:36:08 +00:00
|
|
|
|
2022-05-23 07:24:15 +00:00
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const options: FindOptions<Issue> = {
|
2022-06-24 12:36:08 +00:00
|
|
|
lookup: { status: tracker.class.IssueStatus, space: tracker.class.Team },
|
2022-05-23 07:24:15 +00:00
|
|
|
sort: { modifiedOn: SortingOrder.Descending }
|
|
|
|
}
|
|
|
|
|
|
|
|
let statusCategoryById: Map<string, IssueStatusCategory> | undefined
|
|
|
|
|
|
|
|
async function updateIssueStatusCategories () {
|
|
|
|
const categories = await client.findAll(tracker.class.IssueStatusCategory, {})
|
|
|
|
|
|
|
|
statusCategoryById = new Map(categories.map((c) => [c._id, c]))
|
|
|
|
}
|
|
|
|
|
|
|
|
async function onClose ({ detail: parentIssue }: CustomEvent<Issue | undefined | null>) {
|
2022-06-24 12:36:08 +00:00
|
|
|
const vv = Array.isArray(value) ? value : [value]
|
|
|
|
for (const docValue of vv) {
|
|
|
|
if ('_id' in docValue && parentIssue !== undefined && parentIssue?._id !== docValue.attachedTo) {
|
|
|
|
let rank: string | null = null
|
2022-06-10 15:51:31 +00:00
|
|
|
|
2022-06-24 12:36:08 +00:00
|
|
|
if (parentIssue) {
|
|
|
|
const lastAttachedIssue = await client.findOne<Issue>(
|
|
|
|
tracker.class.Issue,
|
|
|
|
{ attachedTo: parentIssue._id },
|
|
|
|
{ sort: { rank: SortingOrder.Descending } }
|
|
|
|
)
|
2022-06-10 15:51:31 +00:00
|
|
|
|
2022-06-24 12:36:08 +00:00
|
|
|
rank = calcRank(lastAttachedIssue, undefined)
|
|
|
|
}
|
2022-06-10 15:51:31 +00:00
|
|
|
|
2022-06-24 12:36:08 +00:00
|
|
|
await client.update(docValue, {
|
|
|
|
attachedTo: parentIssue === null ? tracker.ids.NoParent : parentIssue._id,
|
|
|
|
...(rank ? { rank } : {})
|
|
|
|
})
|
|
|
|
}
|
2022-05-23 07:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dispatch('close', parentIssue)
|
|
|
|
}
|
|
|
|
|
2022-06-24 12:36:08 +00:00
|
|
|
$: selected = !Array.isArray(value) ? ('attachedTo' in value ? value.attachedTo : undefined) : undefined
|
|
|
|
$: ignoreObjects = !Array.isArray(value) ? ('_id' in value ? [value._id] : []) : undefined
|
2022-05-23 07:24:15 +00:00
|
|
|
$: updateIssueStatusCategories()
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<ObjectPopup
|
|
|
|
_class={tracker.class.Issue}
|
|
|
|
{options}
|
2022-06-10 15:51:31 +00:00
|
|
|
{selected}
|
2022-05-23 07:24:15 +00:00
|
|
|
multiSelect={false}
|
|
|
|
allowDeselect={true}
|
|
|
|
placeholder={tracker.string.SetParent}
|
|
|
|
create={undefined}
|
|
|
|
{ignoreObjects}
|
|
|
|
shadows={true}
|
2022-06-24 12:36:08 +00:00
|
|
|
{width}
|
2022-05-23 07:24:15 +00:00
|
|
|
searchField="title"
|
|
|
|
on:update
|
|
|
|
on:close={onClose}
|
|
|
|
>
|
|
|
|
<svelte:fragment slot="item" let:item={issue}>
|
|
|
|
{@const { icon } = statusCategoryById?.get(issue.$lookup?.status.category) ?? {}}
|
2022-06-24 12:36:08 +00:00
|
|
|
{@const issueId = getIssueId(issue.$lookup.space, issue)}
|
2022-05-23 07:24:15 +00:00
|
|
|
{#if issueId && icon}
|
|
|
|
<div class="flex-center clear-mins w-full h-9">
|
|
|
|
<div class="icon mr-4 h-8">
|
|
|
|
<Icon {icon} size="small" />
|
|
|
|
</div>
|
|
|
|
<span class="overflow-label flex-no-shrink mr-3">{issueId}</span>
|
|
|
|
<span class="overflow-label w-full issue-title">{issue.title}</span>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</svelte:fragment>
|
|
|
|
</ObjectPopup>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.issue-title {
|
|
|
|
color: var(--theme-content-color);
|
|
|
|
}
|
|
|
|
</style>
|