Fix processes triggers (On card update, on subprocesses done) (#9841)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-09-12 15:12:05 +07:00
committed by GitHub
parent 6fcf58574e
commit fb95ad6ce7
12 changed files with 91 additions and 44 deletions
@@ -78,6 +78,10 @@
items={triggersItems}
bind:selected={selectedTrigger}
label={plugin.string.Trigger}
on:change={() => {
params = {}
result = null
}}
justify={'left'}
width={'100%'}
kind={'no-border'}
+3 -1
View File
@@ -80,7 +80,8 @@ import {
showDoneQuery,
timeTransitionCheck,
todoTranstionCheck,
updateCardTranstionCheck
updateCardTranstionCheck,
subProcessesDoneCheck
} from './utils'
export * from './query'
@@ -160,6 +161,7 @@ export default async (): Promise<Resources> => ({
},
triggerCheck: {
UpdateCheck: updateCardTranstionCheck,
SubProcessesDoneCheck: subProcessesDoneCheck,
ToDo: todoTranstionCheck,
Time: timeTransitionCheck
},
+2 -14
View File
@@ -88,13 +88,7 @@ export class ProcessMiddleware extends BasePresentationMiddleware implements Pre
from: execution.currentState,
trigger: process.trigger.OnCardUpdate
})
const transition = await pickTransition(
this.client.getModel(),
this.client.getHierarchy(),
execution,
transitions,
updated
)
const transition = await pickTransition(this.client, execution, transitions, updated)
if (transition === undefined) return
const context = await getNextStateUserInput(execution, transition, execution.context)
const txop = new TxOperations(this.client, getCurrentAccount().primarySocialId)
@@ -158,13 +152,7 @@ export class ProcessMiddleware extends BasePresentationMiddleware implements Pre
from: execution.currentState,
trigger: process.trigger.OnToDoClose
})
const transition = await pickTransition(
this.client.getModel(),
this.client.getHierarchy(),
execution,
transitions,
todo
)
const transition = await pickTransition(this.client, execution, transitions, todo)
if (transition === undefined) return
const context = await getNextStateUserInput(execution, transition, execution.context)
const txop = new TxOperations(this.client, getCurrentAccount().primarySocialId)
+3 -3
View File
@@ -149,7 +149,7 @@ export function parseValue (modes: Mode[], value: any): [any, Mode] {
if (mode.parse !== undefined) {
return [mode.parse(obj2[key2]), mode]
}
return [obj2[key2], mode]
return [mode.withoutEditor === true ? undefined : obj2[key2], mode]
}
obj1 = obj1[key1]
obj2 = obj2[key2]
@@ -168,10 +168,10 @@ export function buildResult (mode: Mode, value: any): any {
const key = Object.keys(q)[0]
const v: any = (q as any)[key]
if (typeof v !== 'object') {
if (typeof value === 'string') {
if (typeof value === 'string' && typeof v === 'string') {
res[key] = v.replace('$val', value)
} else {
res[key] = value
res[key] = mode.withoutEditor === true ? v : value ?? v
}
return result
}
+35 -10
View File
@@ -21,9 +21,7 @@ import core, {
type Doc,
type DocumentQuery,
generateId,
type Hierarchy,
matchQuery,
type ModelDb,
type Ref,
type RefTo,
type Space,
@@ -110,20 +108,19 @@ export function getContextMasterTag (
}
export async function pickTransition (
model: ModelDb,
hierarchy: Hierarchy,
client: Client,
execution: Execution,
transitions: Transition[],
doc: Doc
): Promise<Transition | undefined> {
for (const tr of transitions) {
const trigger = model.findObject(tr.trigger)
const trigger = client.getModel().findObject(tr.trigger)
if (trigger === undefined) continue
if (trigger.checkFunction === undefined) return tr
const filled = fillParams(tr.triggerParams, execution)
const checkFunc = await getResource(trigger.checkFunction)
if (checkFunc === undefined) continue
const res = await checkFunc(filled, doc, hierarchy)
const res = await checkFunc(client, execution, filled, doc)
if (res) return tr
}
}
@@ -596,21 +593,49 @@ export async function requestResult (
})
}
export function todoTranstionCheck (params: Record<string, any>, doc: Doc): boolean {
export function todoTranstionCheck (
client: Client,
execution: Execution,
params: Record<string, any>,
doc: Doc
): boolean {
if (params._id === undefined) return false
return doc._id === params._id
}
export function timeTransitionCheck (params: Record<string, any>): boolean {
export function timeTransitionCheck (
client: Client,
execution: Execution,
params: Record<string, any>,
context: Record<string, any>
): boolean {
if (params.value === undefined) return false
return params.value <= Date.now()
}
export function updateCardTranstionCheck (params: Record<string, any>, doc: Doc, hierarchy: Hierarchy): boolean {
const res = matchQuery([doc], params, doc._class, hierarchy, true)
export function updateCardTranstionCheck (
client: Client,
execution: Execution,
params: Record<string, any>,
doc: Doc
): boolean {
const res = matchQuery([doc], params, doc._class, client.getHierarchy(), true)
return res.length > 0
}
export async function subProcessesDoneCheck (
client: Client,
execution: Execution,
params: Record<string, any>,
context: Record<string, any>
): Promise<boolean> {
const res = client.findOne(process.class.Execution, {
parentId: execution._id,
status: ExecutionStatus.Active
})
return res === undefined
}
export function getCirteriaEditor (of: Ref<Class<Doc>>, category: AttributeCategory): AnyComponent | undefined {
const client = getClient()
if (category !== 'attribute') {