2022-03-31 08:32:42 +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-14 06:40:35 +00:00
|
|
|
import { AttachmentStyledBox } from '@anticrm/attachment-resources'
|
2022-06-06 15:52:30 +00:00
|
|
|
import { Employee } from '@anticrm/contact'
|
2022-06-19 16:27:47 +00:00
|
|
|
import core, { Account, AttachedData, Doc, generateId, Ref, SortingOrder, WithLookup } from '@anticrm/core'
|
|
|
|
import { Card, createQuery, getClient, KeyedAttribute, SpaceSelector } from '@anticrm/presentation'
|
2022-05-16 11:41:22 +00:00
|
|
|
import { calcRank, Issue, IssuePriority, IssueStatus, Project, Team } from '@anticrm/tracker'
|
2022-06-19 16:27:47 +00:00
|
|
|
import tags, { TagElement, TagReference } from '@anticrm/tags'
|
2022-04-29 05:27:17 +00:00
|
|
|
import {
|
2022-06-14 06:40:35 +00:00
|
|
|
ActionIcon,
|
2022-04-29 05:27:17 +00:00
|
|
|
Button,
|
2022-06-19 16:27:47 +00:00
|
|
|
Component,
|
2022-04-29 05:27:17 +00:00
|
|
|
DatePresenter,
|
2022-05-16 11:41:22 +00:00
|
|
|
EditBox,
|
2022-04-29 05:27:17 +00:00
|
|
|
IconAttachment,
|
2022-05-19 10:37:14 +00:00
|
|
|
IconMoreH,
|
2022-06-14 06:40:35 +00:00
|
|
|
Menu,
|
|
|
|
showPopup,
|
|
|
|
Spinner
|
2022-04-29 05:27:17 +00:00
|
|
|
} from '@anticrm/ui'
|
2022-03-31 08:32:42 +00:00
|
|
|
import { createEventDispatcher } from 'svelte'
|
|
|
|
import tracker from '../plugin'
|
2022-06-14 06:40:35 +00:00
|
|
|
import AssigneeEditor from './issues/AssigneeEditor.svelte'
|
2022-05-23 07:24:15 +00:00
|
|
|
import ParentIssue from './issues/ParentIssue.svelte'
|
2022-06-16 14:30:26 +00:00
|
|
|
import PriorityEditor from './issues/PriorityEditor.svelte'
|
|
|
|
import StatusEditor from './issues/StatusEditor.svelte'
|
2022-05-16 10:38:51 +00:00
|
|
|
import ProjectSelector from './ProjectSelector.svelte'
|
2022-05-23 07:24:15 +00:00
|
|
|
import SetDueDateActionPopup from './SetDueDateActionPopup.svelte'
|
2022-06-16 14:30:26 +00:00
|
|
|
import SetParentIssueActionPopup from './SetParentIssueActionPopup.svelte'
|
2022-03-31 08:32:42 +00:00
|
|
|
|
|
|
|
export let space: Ref<Team>
|
2022-04-28 12:01:11 +00:00
|
|
|
export let status: Ref<IssueStatus> | undefined = undefined
|
2022-04-20 06:06:05 +00:00
|
|
|
export let priority: IssuePriority = IssuePriority.NoPriority
|
|
|
|
export let assignee: Ref<Employee> | null = null
|
2022-05-16 10:38:51 +00:00
|
|
|
export let project: Ref<Project> | null = null
|
2022-04-20 06:06:05 +00:00
|
|
|
|
|
|
|
let currentAssignee: Ref<Employee> | null = assignee
|
2022-05-19 10:37:14 +00:00
|
|
|
let issueStatuses: WithLookup<IssueStatus>[] | undefined
|
2022-05-23 07:24:15 +00:00
|
|
|
let parentIssue: Issue | undefined
|
2022-06-19 16:27:47 +00:00
|
|
|
let labels: TagReference[] = []
|
2022-03-31 08:32:42 +00:00
|
|
|
|
2022-06-14 06:40:35 +00:00
|
|
|
let objectId: Ref<Issue> = generateId()
|
2022-06-02 02:42:44 +00:00
|
|
|
let object: AttachedData<Issue> = {
|
2022-03-31 08:32:42 +00:00
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
assignee: null,
|
2022-05-16 10:38:51 +00:00
|
|
|
project: project,
|
2022-03-31 08:32:42 +00:00
|
|
|
number: 0,
|
|
|
|
rank: '',
|
2022-04-23 16:59:57 +00:00
|
|
|
status: '' as Ref<IssueStatus>,
|
2022-04-20 06:06:05 +00:00
|
|
|
priority: priority,
|
2022-03-31 08:32:42 +00:00
|
|
|
dueDate: null,
|
2022-06-02 02:42:44 +00:00
|
|
|
comments: 0,
|
|
|
|
subIssues: 0
|
2022-03-31 08:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const client = getClient()
|
2022-04-23 16:59:57 +00:00
|
|
|
const statusesQuery = createQuery()
|
2022-03-31 08:32:42 +00:00
|
|
|
|
2022-06-14 06:40:35 +00:00
|
|
|
let descriptionBox: AttachmentStyledBox
|
|
|
|
|
2022-06-19 16:27:47 +00:00
|
|
|
const key: KeyedAttribute = {
|
|
|
|
key: 'labels',
|
|
|
|
attr: client.getHierarchy().getAttribute(tracker.class.Issue, 'labels')
|
|
|
|
}
|
|
|
|
|
2022-04-23 16:59:57 +00:00
|
|
|
$: _space = space
|
2022-04-28 12:01:11 +00:00
|
|
|
$: updateIssueStatusId(space, status)
|
2022-05-11 05:36:35 +00:00
|
|
|
$: canSave = getTitle(object.title ?? '').length > 0
|
2022-04-23 16:59:57 +00:00
|
|
|
|
2022-05-19 10:37:14 +00:00
|
|
|
$: statusesQuery.query(tracker.class.IssueStatus, { attachedTo: space }, (statuses) => (issueStatuses = statuses), {
|
|
|
|
lookup: { category: tracker.class.IssueStatusCategory },
|
|
|
|
sort: { rank: SortingOrder.Ascending }
|
|
|
|
})
|
|
|
|
|
2022-04-28 12:01:11 +00:00
|
|
|
async function updateIssueStatusId (teamId: Ref<Team>, issueStatusId?: Ref<IssueStatus>) {
|
|
|
|
if (issueStatusId !== undefined) {
|
|
|
|
object.status = issueStatusId
|
2022-04-23 16:59:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:52:30 +00:00
|
|
|
const team = await client.findOne(tracker.class.Team, { _id: teamId })
|
2022-04-23 16:59:57 +00:00
|
|
|
|
2022-06-06 15:52:30 +00:00
|
|
|
if (team?.defaultIssueStatus) {
|
|
|
|
object.status = team.defaultIssueStatus
|
2022-04-23 16:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-23 07:24:15 +00:00
|
|
|
function clearParentIssue () {
|
|
|
|
parentIssue = undefined
|
|
|
|
}
|
|
|
|
|
2022-05-11 05:36:35 +00:00
|
|
|
function getTitle (value: string) {
|
|
|
|
return value.trim()
|
2022-05-06 08:00:45 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 08:32:42 +00:00
|
|
|
export function canClose (): boolean {
|
2022-05-11 05:36:35 +00:00
|
|
|
return !canSave
|
2022-03-31 08:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function createIssue () {
|
2022-05-06 08:00:45 +00:00
|
|
|
if (!canSave) {
|
2022-04-23 16:59:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-31 08:32:42 +00:00
|
|
|
const lastOne = await client.findOne<Issue>(
|
|
|
|
tracker.class.Issue,
|
|
|
|
{ status: object.status },
|
|
|
|
{ sort: { rank: SortingOrder.Descending } }
|
|
|
|
)
|
|
|
|
const incResult = await client.updateDoc(
|
|
|
|
tracker.class.Team,
|
|
|
|
core.space.Space,
|
|
|
|
_space,
|
|
|
|
{
|
|
|
|
$inc: { sequence: 1 }
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
2022-06-02 02:42:44 +00:00
|
|
|
const value: AttachedData<Issue> = {
|
2022-05-11 05:36:35 +00:00
|
|
|
title: getTitle(object.title),
|
2022-03-31 08:32:42 +00:00
|
|
|
description: object.description,
|
2022-04-20 06:06:05 +00:00
|
|
|
assignee: currentAssignee,
|
2022-05-16 10:38:51 +00:00
|
|
|
project: object.project,
|
2022-03-31 08:32:42 +00:00
|
|
|
number: (incResult as any).object.sequence,
|
|
|
|
status: object.status,
|
|
|
|
priority: object.priority,
|
|
|
|
rank: calcRank(lastOne, undefined),
|
|
|
|
comments: 0,
|
2022-06-02 02:42:44 +00:00
|
|
|
subIssues: 0,
|
2022-03-31 08:32:42 +00:00
|
|
|
dueDate: object.dueDate
|
|
|
|
}
|
|
|
|
|
2022-06-02 02:42:44 +00:00
|
|
|
await client.addCollection(
|
|
|
|
tracker.class.Issue,
|
|
|
|
_space,
|
|
|
|
parentIssue?._id ?? tracker.ids.NoParent,
|
|
|
|
parentIssue?._class ?? tracker.class.Issue,
|
|
|
|
'subIssues',
|
2022-06-14 06:40:35 +00:00
|
|
|
value,
|
|
|
|
objectId
|
2022-06-02 02:42:44 +00:00
|
|
|
)
|
2022-06-19 16:27:47 +00:00
|
|
|
for (const label of labels) {
|
|
|
|
await client.addCollection(label._class, label.space, objectId, tracker.class.Issue, 'labels', {
|
|
|
|
title: label.title,
|
|
|
|
color: label.color,
|
|
|
|
tag: label.tag
|
|
|
|
})
|
|
|
|
}
|
2022-06-14 06:40:35 +00:00
|
|
|
await descriptionBox.createAttachments()
|
|
|
|
objectId = generateId()
|
2022-03-31 08:32:42 +00:00
|
|
|
}
|
2022-04-02 04:06:48 +00:00
|
|
|
|
2022-05-19 10:37:14 +00:00
|
|
|
async function showMoreActions (ev: Event) {
|
|
|
|
ev.preventDefault()
|
|
|
|
|
|
|
|
const selectDueDate = {
|
|
|
|
label: object.dueDate === null ? tracker.string.SetDueDate : tracker.string.ChangeDueDate,
|
|
|
|
icon: tracker.icon.DueDate,
|
2022-05-23 07:24:15 +00:00
|
|
|
action: async () =>
|
2022-05-19 10:37:14 +00:00
|
|
|
showPopup(
|
2022-05-23 07:24:15 +00:00
|
|
|
SetDueDateActionPopup,
|
2022-06-10 15:51:31 +00:00
|
|
|
{ value: object },
|
2022-05-25 05:56:06 +00:00
|
|
|
'top',
|
2022-05-19 10:37:14 +00:00
|
|
|
undefined,
|
|
|
|
(newDueDate) => newDueDate !== undefined && (object.dueDate = newDueDate)
|
|
|
|
)
|
2022-05-23 07:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const setParentIssue = {
|
2022-06-02 02:42:44 +00:00
|
|
|
label: parentIssue ? tracker.string.ChangeParent : tracker.string.SetParent,
|
2022-05-23 07:24:15 +00:00
|
|
|
icon: tracker.icon.Parent,
|
|
|
|
action: async () =>
|
|
|
|
showPopup(
|
|
|
|
SetParentIssueActionPopup,
|
2022-06-10 15:51:31 +00:00
|
|
|
{ value: { ...object, space, attachedTo: parentIssue?._id } },
|
2022-05-25 05:56:06 +00:00
|
|
|
'top',
|
2022-06-02 02:42:44 +00:00
|
|
|
(selectedIssue) => selectedIssue !== undefined && (parentIssue = selectedIssue)
|
2022-05-23 07:24:15 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-02 02:42:44 +00:00
|
|
|
const removeParentIssue = parentIssue && {
|
2022-05-23 07:24:15 +00:00
|
|
|
label: tracker.string.RemoveParent,
|
|
|
|
icon: tracker.icon.Parent,
|
|
|
|
action: clearParentIssue
|
2022-05-19 10:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showPopup(
|
|
|
|
Menu,
|
|
|
|
{
|
2022-05-23 07:24:15 +00:00
|
|
|
actions: [selectDueDate, setParentIssue, ...(removeParentIssue ? [removeParentIssue] : [])]
|
2022-05-19 10:37:14 +00:00
|
|
|
},
|
|
|
|
ev.target as HTMLElement
|
|
|
|
)
|
|
|
|
}
|
2022-04-12 17:04:29 +00:00
|
|
|
|
2022-05-16 10:38:51 +00:00
|
|
|
const handleProjectIdChanged = (projectId: Ref<Project> | null | undefined) => {
|
|
|
|
if (projectId === undefined) {
|
|
|
|
return
|
2022-04-12 17:41:32 +00:00
|
|
|
}
|
2022-05-16 10:38:51 +00:00
|
|
|
|
|
|
|
object = { ...object, project: projectId }
|
2022-04-12 17:41:32 +00:00
|
|
|
}
|
2022-06-19 16:27:47 +00:00
|
|
|
|
|
|
|
function addTagRef (tag: TagElement): void {
|
|
|
|
labels = [
|
|
|
|
...labels,
|
|
|
|
{
|
|
|
|
_class: tags.class.TagReference,
|
|
|
|
_id: generateId() as Ref<TagReference>,
|
|
|
|
attachedTo: '' as Ref<Doc>,
|
|
|
|
attachedToClass: tracker.class.Issue,
|
|
|
|
collection: 'labels',
|
|
|
|
space: tags.space.Tags,
|
|
|
|
modifiedOn: 0,
|
|
|
|
modifiedBy: '' as Ref<Account>,
|
|
|
|
title: tag.title,
|
|
|
|
tag: tag._id,
|
|
|
|
color: tag.color
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-03-31 08:32:42 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<Card
|
|
|
|
label={tracker.string.NewIssue}
|
|
|
|
okAction={createIssue}
|
2022-05-06 08:00:45 +00:00
|
|
|
{canSave}
|
2022-04-02 04:06:48 +00:00
|
|
|
okLabel={tracker.string.SaveIssue}
|
2022-03-31 08:32:42 +00:00
|
|
|
on:close={() => {
|
|
|
|
dispatch('close')
|
|
|
|
}}
|
2022-05-16 11:41:22 +00:00
|
|
|
createMore={false}
|
2022-03-31 08:32:42 +00:00
|
|
|
>
|
2022-05-16 11:41:22 +00:00
|
|
|
<svelte:fragment slot="header">
|
|
|
|
<SpaceSelector _class={tracker.class.Team} label={tracker.string.Team} bind:space={_space} />
|
2022-06-16 14:30:26 +00:00
|
|
|
<!-- <Button
|
2022-04-20 06:06:05 +00:00
|
|
|
icon={tracker.icon.Home}
|
|
|
|
label={presentation.string.Save}
|
|
|
|
size={'small'}
|
|
|
|
kind={'no-border'}
|
|
|
|
disabled
|
|
|
|
on:click={() => {}}
|
2022-06-16 14:30:26 +00:00
|
|
|
/> -->
|
2022-04-13 04:25:59 +00:00
|
|
|
</svelte:fragment>
|
2022-05-23 07:24:15 +00:00
|
|
|
{#if parentIssue}
|
|
|
|
<ParentIssue issue={parentIssue} on:close={clearParentIssue} />
|
|
|
|
{/if}
|
2022-04-02 04:06:48 +00:00
|
|
|
<EditBox
|
|
|
|
bind:value={object.title}
|
|
|
|
placeholder={tracker.string.IssueTitlePlaceholder}
|
|
|
|
maxWidth={'37.5rem'}
|
|
|
|
kind={'large-style'}
|
|
|
|
focus
|
|
|
|
/>
|
2022-06-14 06:40:35 +00:00
|
|
|
<AttachmentStyledBox
|
|
|
|
bind:this={descriptionBox}
|
|
|
|
{objectId}
|
|
|
|
_class={tracker.class.Issue}
|
|
|
|
space={_space}
|
2022-04-13 04:25:59 +00:00
|
|
|
alwaysEdit
|
|
|
|
showButtons={false}
|
2022-06-22 06:48:39 +00:00
|
|
|
maxHeight={'card'}
|
2022-04-13 04:25:59 +00:00
|
|
|
bind:content={object.description}
|
|
|
|
placeholder={tracker.string.IssueDescriptionPlaceholder}
|
|
|
|
/>
|
|
|
|
<svelte:fragment slot="pool">
|
2022-05-19 10:37:14 +00:00
|
|
|
{#if issueStatuses}
|
2022-06-19 16:27:47 +00:00
|
|
|
<div id="status-editor">
|
|
|
|
<StatusEditor
|
|
|
|
value={object}
|
|
|
|
statuses={issueStatuses}
|
|
|
|
kind="no-border"
|
|
|
|
size="small"
|
|
|
|
shouldShowLabel={true}
|
|
|
|
on:change={({ detail }) => (object.status = detail)}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-06-15 03:01:21 +00:00
|
|
|
<PriorityEditor
|
|
|
|
value={object}
|
|
|
|
shouldShowLabel
|
|
|
|
isEditable
|
|
|
|
kind="no-border"
|
|
|
|
size="small"
|
|
|
|
justify="center"
|
|
|
|
on:change={({ detail }) => (object.priority = detail)}
|
|
|
|
/>
|
2022-06-06 15:52:30 +00:00
|
|
|
<AssigneeEditor
|
|
|
|
value={object}
|
|
|
|
size="small"
|
|
|
|
kind="no-border"
|
2022-06-21 08:53:19 +00:00
|
|
|
width={'min-content'}
|
2022-06-06 15:52:30 +00:00
|
|
|
on:change={({ detail }) => (currentAssignee = detail)}
|
2022-05-19 10:37:14 +00:00
|
|
|
/>
|
2022-06-19 16:27:47 +00:00
|
|
|
<Component
|
|
|
|
is={tags.component.TagsDropdownEditor}
|
|
|
|
props={{
|
|
|
|
items: labels,
|
|
|
|
key,
|
|
|
|
targetClass: tracker.class.Issue,
|
|
|
|
countLabel: tracker.string.NumberLabels
|
|
|
|
}}
|
|
|
|
on:open={(evt) => {
|
|
|
|
addTagRef(evt.detail)
|
|
|
|
}}
|
|
|
|
on:delete={(evt) => {
|
|
|
|
labels = labels.filter((it) => it._id !== evt.detail)
|
|
|
|
}}
|
|
|
|
/>
|
2022-05-19 10:37:14 +00:00
|
|
|
<ProjectSelector value={object.project} onProjectIdChange={handleProjectIdChanged} />
|
|
|
|
{#if object.dueDate !== null}
|
|
|
|
<DatePresenter bind:value={object.dueDate} editable />
|
|
|
|
{/if}
|
|
|
|
<ActionIcon icon={IconMoreH} size={'medium'} action={showMoreActions} />
|
|
|
|
{:else}
|
|
|
|
<Spinner size="small" />
|
|
|
|
{/if}
|
2022-04-13 04:25:59 +00:00
|
|
|
</svelte:fragment>
|
|
|
|
<svelte:fragment slot="footer">
|
2022-06-14 06:40:35 +00:00
|
|
|
<Button
|
|
|
|
icon={IconAttachment}
|
|
|
|
kind={'transparent'}
|
|
|
|
on:click={() => {
|
|
|
|
descriptionBox.attach()
|
|
|
|
}}
|
|
|
|
/>
|
2022-04-13 04:25:59 +00:00
|
|
|
</svelte:fragment>
|
2022-03-31 08:32:42 +00:00
|
|
|
</Card>
|