mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 13:17:45 +02:00
Rework todo result (#9893)
This commit is contained in:
@@ -35,7 +35,8 @@ import process, {
|
||||
MethodParams,
|
||||
Process,
|
||||
processError,
|
||||
ProcessToDo
|
||||
ProcessToDo,
|
||||
UserResult
|
||||
} from '@hcengineering/process'
|
||||
import { ExecuteResult, ProcessControl, SuccessExecutionContext } from '@hcengineering/server-process'
|
||||
import time, { ToDoPriority } from '@hcengineering/time'
|
||||
@@ -282,7 +283,8 @@ export async function RunSubProcess (
|
||||
export async function CreateToDo (
|
||||
params: MethodParams<ProcessToDo>,
|
||||
execution: Execution,
|
||||
control: ProcessControl
|
||||
control: ProcessControl,
|
||||
results: UserResult[] | undefined
|
||||
): Promise<ExecuteResult> {
|
||||
for (const key in { user: params.user, title: params.title }) {
|
||||
const val = (params as any)[key]
|
||||
@@ -311,7 +313,8 @@ export async function CreateToDo (
|
||||
visibility: 'public',
|
||||
doneOn: null,
|
||||
rank: '',
|
||||
withRollback: params.withRollback ?? false
|
||||
withRollback: params.withRollback ?? false,
|
||||
results
|
||||
},
|
||||
id
|
||||
)
|
||||
|
||||
@@ -128,7 +128,6 @@ export async function OnProcessToDoClose (txes: Tx[], control: TriggerControl):
|
||||
}
|
||||
|
||||
export async function OnExecutionCreate (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
|
||||
const res: Tx[] = []
|
||||
for (const tx of txes) {
|
||||
if (tx._class !== core.class.TxCreateDoc) continue
|
||||
const createTx = tx as TxCreateDoc<Execution>
|
||||
@@ -143,11 +142,10 @@ export async function OnExecutionCreate (txes: Tx[], control: TriggerControl): P
|
||||
control
|
||||
)
|
||||
}
|
||||
return res
|
||||
return []
|
||||
}
|
||||
|
||||
export async function OnProcessToDoRemove (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
|
||||
const res: Tx[] = []
|
||||
for (const tx of txes) {
|
||||
if (tx._class !== core.class.TxRemoveDoc) continue
|
||||
const removeTx = tx as TxRemoveDoc<ProcessToDo>
|
||||
@@ -165,11 +163,10 @@ export async function OnProcessToDoRemove (txes: Tx[], control: TriggerControl):
|
||||
control
|
||||
)
|
||||
}
|
||||
return res
|
||||
return []
|
||||
}
|
||||
|
||||
export async function OnExecutionContinue (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
|
||||
const res: Tx[] = []
|
||||
for (const tx of txes) {
|
||||
if (tx._class !== core.class.TxUpdateDoc) continue
|
||||
if (tx.space !== core.space.Tx) continue
|
||||
@@ -192,7 +189,7 @@ export async function OnExecutionContinue (txes: Tx[], control: TriggerControl):
|
||||
control
|
||||
)
|
||||
}
|
||||
return res
|
||||
return []
|
||||
}
|
||||
|
||||
export async function OnProcessRemove (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
|
||||
@@ -282,30 +279,6 @@ async function syncContext (control: TriggerControl, _process: Process): Promise
|
||||
let changed = false
|
||||
let index = 1
|
||||
for (const transition of transitions) {
|
||||
if (transition.result?._id != null) {
|
||||
exists.add(transition.result._id)
|
||||
const context = _process.context[transition.result._id]
|
||||
changed = true
|
||||
const ctx: SelectedExecutionContext = {
|
||||
type: 'context',
|
||||
id: transition.result._id,
|
||||
key: ''
|
||||
}
|
||||
const parentType =
|
||||
transition.result.type._class === core.class.ArrOf
|
||||
? (transition.result.type as ArrOf<Doc>).of
|
||||
: transition.result.type
|
||||
const _class = parentType._class === core.class.RefTo ? (parentType as RefTo<Doc>).to : parentType._class
|
||||
_process.context[transition.result._id] = {
|
||||
name: context?.name ?? transition.result.name,
|
||||
isResult: true,
|
||||
type: transition.result.type,
|
||||
_class,
|
||||
index: index++,
|
||||
producer: transition._id,
|
||||
value: ctx
|
||||
}
|
||||
}
|
||||
for (const action of transition.actions) {
|
||||
if (action.context != null) {
|
||||
exists.add(action.context._id)
|
||||
@@ -328,6 +301,29 @@ async function syncContext (control: TriggerControl, _process: Process): Promise
|
||||
}
|
||||
}
|
||||
}
|
||||
if (action.results != null) {
|
||||
for (const result of action.results) {
|
||||
exists.add(result._id)
|
||||
const context = _process.context[result._id]
|
||||
changed = true
|
||||
const ctx: SelectedExecutionContext = {
|
||||
type: 'context',
|
||||
id: result._id,
|
||||
key: ''
|
||||
}
|
||||
const parentType = result.type._class === core.class.ArrOf ? (result.type as ArrOf<Doc>).of : result.type
|
||||
const _class = parentType._class === core.class.RefTo ? (parentType as RefTo<Doc>).to : parentType._class
|
||||
_process.context[result._id] = {
|
||||
name: context?.name ?? result.name,
|
||||
isResult: true,
|
||||
type: result.type,
|
||||
_class,
|
||||
index: index++,
|
||||
producer: transition._id,
|
||||
value: ctx
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const newContext: Record<ContextId, ProcessContext> = {}
|
||||
|
||||
Reference in New Issue
Block a user