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-04-08 06:27:02 +00:00
|
|
|
import contact, { Employee } from '@anticrm/contact'
|
2022-04-23 16:59:57 +00:00
|
|
|
import core, { Data, generateId, Ref, SortingOrder, WithLookup } from '@anticrm/core'
|
2022-05-16 11:41:22 +00:00
|
|
|
import presentation, { Card, createQuery, getClient, SpaceSelector, UserBox } from '@anticrm/presentation'
|
2022-04-08 06:27:02 +00:00
|
|
|
import { StyledTextBox } from '@anticrm/text-editor'
|
2022-05-16 11:41:22 +00:00
|
|
|
import { calcRank, Issue, IssuePriority, IssueStatus, Project, Team } from '@anticrm/tracker'
|
2022-04-29 05:27:17 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
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
|
|
|
showPopup,
|
|
|
|
Spinner,
|
|
|
|
IconMoreH,
|
|
|
|
ActionIcon,
|
|
|
|
DatePopup,
|
|
|
|
Menu
|
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-04-08 06:27:02 +00:00
|
|
|
import PrioritySelector from './PrioritySelector.svelte'
|
2022-05-16 10:38:51 +00:00
|
|
|
import ProjectSelector from './ProjectSelector.svelte'
|
2022-05-16 11:41:22 +00:00
|
|
|
import StatusSelector from './StatusSelector.svelte'
|
2022-03-31 08:32:42 +00:00
|
|
|
|
|
|
|
export let space: Ref<Team>
|
|
|
|
export let parent: Ref<Issue> | undefined
|
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-03-31 08:32:42 +00:00
|
|
|
|
2022-05-16 10:38:51 +00:00
|
|
|
let object: Data<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,
|
|
|
|
comments: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
const taskId: Ref<Issue> = generateId()
|
|
|
|
|
2022-04-23 16:59:57 +00:00
|
|
|
$: _space = space
|
|
|
|
$: _parent = parent
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
const team = await client.findOne(
|
|
|
|
tracker.class.Team,
|
|
|
|
{ _id: teamId },
|
|
|
|
{ lookup: { defaultIssueStatus: tracker.class.IssueStatus } }
|
|
|
|
)
|
|
|
|
const teamDefaultIssueStatusId = team?.$lookup?.defaultIssueStatus?._id
|
|
|
|
|
|
|
|
if (teamDefaultIssueStatusId) {
|
|
|
|
object.status = teamDefaultIssueStatusId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
const value: Data<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),
|
|
|
|
parentIssue: _parent,
|
|
|
|
comments: 0,
|
|
|
|
dueDate: object.dueDate
|
|
|
|
}
|
|
|
|
|
|
|
|
await client.createDoc(tracker.class.Issue, _space, value, taskId)
|
|
|
|
}
|
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,
|
|
|
|
action: async () => {
|
|
|
|
showPopup(
|
|
|
|
DatePopup,
|
|
|
|
{ mondayStart: true, withTime: false, currentDate: object.dueDate },
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
(newDueDate) => newDueDate !== undefined && (object.dueDate = newDueDate)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
showPopup(
|
|
|
|
Menu,
|
|
|
|
{
|
|
|
|
actions: [selectDueDate]
|
|
|
|
},
|
|
|
|
ev.target as HTMLElement
|
|
|
|
)
|
|
|
|
}
|
2022-04-12 17:04:29 +00:00
|
|
|
|
|
|
|
const handlePriorityChanged = (newPriority: IssuePriority | undefined) => {
|
|
|
|
if (newPriority === undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
object.priority = newPriority
|
|
|
|
}
|
2022-04-12 17:41:32 +00:00
|
|
|
|
2022-04-23 16:59:57 +00:00
|
|
|
const handleStatusChanged = (statusId: Ref<IssueStatus> | undefined) => {
|
2022-05-16 10:38:51 +00:00
|
|
|
if (statusId === undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
object.status = statusId
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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} />
|
|
|
|
</svelte:fragment>
|
2022-04-13 04:25:59 +00:00
|
|
|
<svelte:fragment slot="space">
|
2022-04-20 06:06:05 +00:00
|
|
|
<Button
|
|
|
|
icon={tracker.icon.Home}
|
|
|
|
label={presentation.string.Save}
|
|
|
|
size={'small'}
|
|
|
|
kind={'no-border'}
|
|
|
|
disabled
|
|
|
|
on:click={() => {}}
|
|
|
|
/>
|
2022-04-13 04:25:59 +00:00
|
|
|
</svelte:fragment>
|
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-04-13 04:25:59 +00:00
|
|
|
<StyledTextBox
|
|
|
|
alwaysEdit
|
|
|
|
showButtons={false}
|
|
|
|
bind:content={object.description}
|
|
|
|
placeholder={tracker.string.IssueDescriptionPlaceholder}
|
|
|
|
/>
|
|
|
|
<svelte:fragment slot="pool">
|
2022-05-19 10:37:14 +00:00
|
|
|
{#if issueStatuses}
|
|
|
|
<StatusSelector selectedStatusId={object.status} statuses={issueStatuses} onStatusChange={handleStatusChanged} />
|
|
|
|
<PrioritySelector priority={object.priority} onPriorityChange={handlePriorityChanged} />
|
|
|
|
<UserBox
|
|
|
|
_class={contact.class.Employee}
|
|
|
|
label={tracker.string.Assignee}
|
|
|
|
placeholder={tracker.string.AssignTo}
|
|
|
|
bind:value={currentAssignee}
|
|
|
|
allowDeselect
|
|
|
|
titleDeselect={tracker.string.Unassigned}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
label={tracker.string.Labels}
|
|
|
|
icon={tracker.icon.Labels}
|
|
|
|
width="min-content"
|
|
|
|
size="small"
|
|
|
|
kind="no-border"
|
|
|
|
/>
|
|
|
|
<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-04-20 06:06:05 +00:00
|
|
|
<Button icon={IconAttachment} kind={'transparent'} on:click={() => {}} />
|
2022-04-13 04:25:59 +00:00
|
|
|
</svelte:fragment>
|
2022-03-31 08:32:42 +00:00
|
|
|
</Card>
|