Fix statuses (#3666)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2023-09-07 00:49:53 +06:00
committed by GitHub
parent 47e39eae75
commit f3c3541964
32 changed files with 390 additions and 125 deletions
@@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Class, Data, Ref } from '@hcengineering/core'
import { Attribute, Class, Data, Ref, Status } from '@hcengineering/core'
import presentation, { Card, createQuery, getClient } from '@hcengineering/presentation'
import { DoneState, SpaceWithStates, State, createState } from '@hcengineering/task'
import { EditBox, Label } from '@hcengineering/ui'
@@ -25,6 +25,7 @@
const hierarchy = client.getHierarchy()
export let status: State | undefined = undefined
export let _class: Ref<Class<State | DoneState>> | undefined = status?._class
export let ofAttribute: Ref<Attribute<Status>>
export let value = status?.name ?? ''
export let space: Ref<SpaceWithStates>
@@ -40,7 +41,7 @@
if (status === undefined) {
if (!hierarchy.isDerived(_class, task.class.DoneState)) {
const newDoc: Data<State> = {
ofAttribute: task.attribute.State,
ofAttribute,
name: value.trim(),
color: 9
}
@@ -48,7 +49,7 @@
await client.update(_space, { $push: { states: id } })
} else {
const newDoc: Data<DoneState> = {
ofAttribute: task.attribute.DoneState,
ofAttribute,
name: value.trim()
}
const id = await createState(client, _class, newDoc)
@@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Class, Data, Ref, SortingOrder } from '@hcengineering/core'
import { Attribute, Class, Data, Ref, SortingOrder, Status } from '@hcengineering/core'
import presentation, { Card, getClient } from '@hcengineering/presentation'
import { DoneStateTemplate, KanbanTemplate, KanbanTemplateSpace, StateTemplate, calcRank } from '@hcengineering/task'
import { EditBox, Label } from '@hcengineering/ui'
@@ -26,6 +26,7 @@
export let status: StateTemplate | undefined = undefined
export let _class: Ref<Class<StateTemplate | DoneStateTemplate>> | undefined = status?._class
export let template: KanbanTemplate
export let ofAttribute: Ref<Attribute<Status>>
export let space: KanbanTemplateSpace
export let value = status?.name ?? ''
@@ -36,14 +37,14 @@
if (_class !== undefined && status === undefined) {
const lastOne = await client.findOne(_class, attachedTo, { sort: { rank: SortingOrder.Descending } })
let newDoc: Data<StateTemplate> = {
ofAttribute: task.attribute.State,
ofAttribute,
name: value.trim(),
rank: calcRank(lastOne, undefined),
...attachedTo
}
if (!hierarchy.isDerived(_class, task.class.DoneState)) {
newDoc = {
ofAttribute: task.attribute.State,
ofAttribute,
name: value.trim(),
color: 9,
rank: calcRank(lastOne, undefined),
@@ -14,7 +14,7 @@
// limitations under the License.
-->
<script lang="ts">
import type { Doc, DocumentQuery, IdMap, Ref, Status } from '@hcengineering/core'
import type { Attribute, Doc, DocumentQuery, IdMap, Ref, Status } from '@hcengineering/core'
import { MessageBox, createQuery, getClient } from '@hcengineering/presentation'
import type { DoneState, LostState, SpaceWithStates, State, WonState } from '@hcengineering/task'
import { Icon, Label, Panel, Scroller, showPopup } from '@hcengineering/ui'
@@ -24,6 +24,8 @@
import StatesEditor from './StatesEditor.svelte'
export let _id: Ref<SpaceWithStates>
export let ofAttribute: Ref<Attribute<Status>>
export let doneOfAttribute: Ref<Attribute<Status>>
let spaceInstance: SpaceWithStates | undefined
@@ -150,13 +152,18 @@
<Scroller>
<div class="popupPanel-body__main-content py-10 clear-mins">
<StatesEditor
{states}
{wonStates}
{lostStates}
on:delete={(e) => deleteState(e.detail)}
on:move={(e) => onMove(e.detail.stateID, e.detail.position)}
/>
{#if spaceInstance}
<StatesEditor
space={_id}
{ofAttribute}
{doneOfAttribute}
{states}
{wonStates}
{lostStates}
on:delete={(e) => deleteState(e.detail)}
on:move={(e) => onMove(e.detail.stateID, e.detail.position)}
/>
{/if}
</div>
</Scroller>
</Panel>
@@ -14,12 +14,11 @@
// limitations under the License.
-->
<script lang="ts">
import { Ref } from '@hcengineering/core'
import { Attribute, Ref, Status } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import type { DoneState, KanbanTemplate, KanbanTemplateSpace, State } from '@hcengineering/task'
import type { DoneState, SpaceWithStates, State } from '@hcengineering/task'
import {
CircleButton,
Component,
IconAdd,
IconCircles,
IconMoreH,
@@ -39,8 +38,9 @@
import Won from '../icons/Won.svelte'
import StatusesPopup from './StatusesPopup.svelte'
export let template: KanbanTemplate | undefined = undefined
export let space: KanbanTemplateSpace | undefined = undefined
export let space: Ref<SpaceWithStates>
export let ofAttribute: Ref<Attribute<Status>> = task.attribute.State
export let doneOfAttribute: Ref<Attribute<Status>> = task.attribute.DoneState
export let states: State[] = []
export let wonStates: DoneState[] = []
export let lostStates: DoneState[] = []
@@ -86,12 +86,8 @@
await client.updateDoc(state._class, state.space, state._id, { color })
}
const spaceEditor = (space as KanbanTemplateSpace)?.editor
</script>
{#if spaceEditor}
<Component is={spaceEditor} props={{ template }} />
{/if}
<div class="flex-no-shrink flex-between trans-title uppercase">
<Label label={task.string.ActiveStates} />
<CircleButton
@@ -102,15 +98,15 @@
task.component.CreateStatePopup,
{
space,
template,
_class: template !== undefined ? task.class.StateTemplate : task.class.State
ofAttribute,
_class: task.class.State
},
undefined
)
}}
/>
</div>
<div class="flex-col mt-3">
<div class="flex-col flex-no-shrink mt-3">
{#each states as state, i}
{@const color = getPlatformColorDef(state.color ?? getColorNumberByText(state.name), $themeStore.dark)}
{#if state}
@@ -155,7 +151,7 @@
onDelete: () => dispatch('delete', { state }),
showDelete: states.length > 1,
onUpdate: () => {
showPopup(task.component.CreateStatePopup, { status: state, template }, undefined)
showPopup(task.component.CreateStatePopup, { status: state, space, ofAttribute }, undefined)
}
},
eventToHTMLElement(ev),
@@ -169,7 +165,7 @@
{/if}
{/each}
</div>
<div class="flex-col mt-9">
<div class="flex-col flex-no-shrink mt-9">
<div class="flex-no-shrink flex-between trans-title uppercase">
<Label label={task.string.DoneStatesWon} />
<CircleButton
@@ -180,8 +176,8 @@
task.component.CreateStatePopup,
{
space,
template,
_class: template !== undefined ? task.class.WonStateTemplate : task.class.WonState
ofAttribute: doneOfAttribute,
_class: task.class.WonState
},
undefined
)
@@ -215,7 +211,11 @@
onDelete: () => dispatch('delete', { state }),
showDelete: wonStates.length > 1,
onUpdate: () => {
showPopup(task.component.CreateStatePopup, { status: state, template }, undefined)
showPopup(
task.component.CreateStatePopup,
{ status: state, space, ofAttribute: doneOfAttribute },
undefined
)
}
},
eventToHTMLElement(ev),
@@ -230,7 +230,7 @@
{/each}
</div>
</div>
<div class="mt-9">
<div class="mt-9 flex-no-shrink">
<div class="flex-no-shrink flex-between trans-title uppercase">
<Label label={task.string.DoneStatesLost} />
<CircleButton
@@ -241,8 +241,8 @@
task.component.CreateStatePopup,
{
space,
template,
_class: template !== undefined ? task.class.LostStateTemplate : task.class.LostState
ofAttribute: doneOfAttribute,
_class: task.class.LostState
},
undefined
)
@@ -276,7 +276,11 @@
onDelete: () => dispatch('delete', { state }),
showDelete: lostStates.length > 1,
onUpdate: () => {
showPopup(task.component.CreateStatePopup, { status: state, template }, undefined)
showPopup(
task.component.CreateStatePopup,
{ status: state, space, ofAttribute: doneOfAttribute },
undefined
)
}
},
eventToHTMLElement(ev),
@@ -53,6 +53,7 @@
const dispatch = createEventDispatcher()
const client = getClient()
const hierarchy = client.getHierarchy()
const elements: HTMLElement[] = []
let selected: number | undefined
@@ -95,7 +96,11 @@
const spaceEditor = space.editor
function add (_class: Ref<Class<StateTemplate | DoneStateTemplate>>) {
const ofAttribute = hierarchy.isDerived(_class, task.class.DoneStateTemplate)
? space.doneAttribute
: space.ofAttribute
showPopup(task.component.CreateStateTemplatePopup, {
ofAttribute,
space,
template,
_class
@@ -103,7 +108,10 @@
}
function edit (status: StateTemplate) {
showPopup(task.component.CreateStateTemplatePopup, { status, template, space })
const ofAttribute = hierarchy.isDerived(status._class, task.class.DoneStateTemplate)
? space.doneAttribute
: space.ofAttribute
showPopup(task.component.CreateStateTemplatePopup, { status, template, space, ofAttribute })
}
</script>