Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script lang="ts">
import { Ref } from '@hcengineering/core'
import presentation, { getClient } from '@hcengineering/presentation'
import { Process, Transition, Trigger } from '@hcengineering/process'
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
import { Process, State, Transition, Trigger } from '@hcengineering/process'
import { clearSettingsStore } from '@hcengineering/setting-resources'
import {
ButtonIcon,
Component,
Dropdown,
DropdownIntlItem,
DropdownLabelsIntl,
IconDelete,
Label,
ListItem,
Modal
} from '@hcengineering/ui'
import plugin from '../../plugin'
Expand All @@ -23,6 +25,14 @@

const client = getClient()

let states: State[] = []
const statesQuery = createQuery()

$: process &&
statesQuery.query(plugin.class.State, { process: process?._id }, (res) => {
states = res
})

async function save (): Promise<void> {
await client.update(transition, { triggerParams: params, trigger: selectedTrigger })
clearSettingsStore()
Expand All @@ -45,6 +55,32 @@
const triggers = client.getModel().findAllSync(plugin.class.Trigger, { init: transition.from === null })

const triggersItems: DropdownIntlItem[] = triggers.map((p) => ({ label: p.label, id: p._id, icon: p.icon }))

let statesItems: ListItem[] = []
$: statesItems = states.map((s) => ({ label: s.title, _id: s._id }))

let fromState: ListItem | undefined
$: fromState = statesItems.find((s) => s._id === (transition?.from as string))

let toState: ListItem | undefined
$: toState = statesItems.find((s) => s._id === (transition?.to as string))

$: withoutFrom =
process &&
client.getModel().findAllSync(plugin.class.Transition, { from: null, process: process._id })[0] === undefined

async function updateFrom (e: CustomEvent<ListItem>): Promise<void> {
if (transition === undefined) return
const from = (e.detail?._id as Ref<State>) ?? null
await client.update(transition, { from })
}

async function updateTo (e: CustomEvent<ListItem>): Promise<void> {
if (transition === undefined) return
const to = e.detail?._id as Ref<State>
if (to === undefined) return
await client.update(transition, { to })
}
</script>

<Modal
Expand All @@ -69,6 +105,30 @@
</div>
{#if trigger !== undefined}
<div class="editor-grid">
<Label label={plugin.string.From} />
{#if !withoutFrom || transition.from === null}
<Dropdown
items={statesItems}
selected={fromState}
placeholder={plugin.string.From}
justify={'left'}
width={'100%'}
kind={'no-border'}
on:selected={updateFrom}
/>
{:else}
<div>⦳</div>
{/if}
<Label label={plugin.string.To} />
<Dropdown
items={statesItems}
selected={toState}
placeholder={plugin.string.To}
justify={'left'}
width={'100%'}
kind={'no-border'}
on:selected={updateTo}
/>
<Label label={plugin.string.Trigger} />
<DropdownLabelsIntl
items={triggersItems}
Expand Down
15 changes: 12 additions & 3 deletions server-plugins/process-resources/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,20 @@ export async function AddTag (
res.push(tx)
const card = control.cache.get(execution.card)
if (card === undefined) throw processError(process.error.ObjectNotFound, { _id: execution.card })
if (control.client.getHierarchy().hasMixin(card, tagId)) {
return { txes: res, rollback: [], context: null }
}
const cardWithMixin =
card !== undefined ? TxProcessor.updateMixin4Doc(control.client.getHierarchy().clone(card), tx) : undefined
if (control.client.getHierarchy().hasMixin(card, tagId)) {
return {
txes: res,
rollback: [],
context: [
{
_id: execution.card,
value: cardWithMixin
}
]
}
}

const rollback: Tx[] = [
control.client.txFactory.createTxUpdateDoc(_process.masterTag, execution.space, execution.card, {
Expand Down
Loading