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
3 changes: 3 additions & 0 deletions models/process/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export class TProcessToDo extends TToDo implements ProcessToDo {

@Prop(TypeBoolean(), process.string.Rollback)
withRollback!: boolean

@Prop(TypeBoolean(), process.string.AskRequired)
askRequired?: boolean
}

@Model(process.class.ApproveRequest, process.class.ProcessToDo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
step.params = params
dispatch('change', step)
}
let askRequired = params.askRequired ?? false
$: askRequired = params.askRequired ?? false

function changeAskRequired (e: CustomEvent<boolean>): void {
if (e.detail !== undefined) {
params.askRequired = e.detail
step.params = params
dispatch('change', step)
}
}
</script>

<ParamsEditor _class={plugin.class.ProcessToDo} {process} {keys} {params} on:change={changeParams} />
Expand All @@ -87,6 +97,12 @@
</div>
<Toggle disabled={!userContext} on={params.field !== undefined} on:change={toggleField} />
</div>
<div class="grid">
<div>
<Label label={plugin.string.AskRequired} />
</div>
<Toggle on={askRequired} on:change={changeAskRequired} />
</div>
<div class="divider" />
<ResultsEditor {process} result={step.results} on:change={changeResults} />

Expand Down
25 changes: 23 additions & 2 deletions plugins/process-resources/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import core, {
type TxResult,
type TxUpdateDoc
} from '@hcengineering/core'
import { translate } from '@hcengineering/platform'
import { BasePresentationMiddleware, type PresentationMiddleware } from '@hcengineering/presentation'
import { type ApproveRequest, ExecutionStatus, isUpdateTx, type ProcessToDo } from '@hcengineering/process'
import { ExecutionStatus, isUpdateTx, type ApproveRequest, type ProcessToDo } from '@hcengineering/process'
import process from './plugin'
import { createExecution, getNextStateUserInput, pickTransition, requestResult } from './utils'

Expand Down Expand Up @@ -237,7 +238,27 @@ export class ProcessMiddleware extends BasePresentationMiddleware implements Pre
})
if (execution === undefined) return

const context = await requestResult(execution, todo.results, execution.context)
let results = todo.results ?? []
if (results.length > 0) {
results = await Promise.all(
results.map(async (r) => {
if (r.key !== undefined) {
const h = this.client.getHierarchy()
const _process = this.client.getModel().findObject(execution.process)
if (_process !== undefined) {
const attr = h.findAttribute(_process.masterTag, r.key)
if (attr?.label !== undefined) {
const name = await translate(attr.label, {})
return { ...r, name }
}
}
}
return r
})
)
}

const context = await requestResult(execution, results, execution.context)

const transitions = this.client.getModel().findAllSync(process.class.Transition, {
process: execution.process,
Expand Down
1 change: 1 addition & 0 deletions plugins/process/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface ProcessToDo extends ToDo {

results?: UserResult[]
field?: string
askRequired?: boolean
}

export interface ApproveRequest extends ProcessToDo {
Expand Down
27 changes: 24 additions & 3 deletions server-plugins/process-resources/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import process, {
Process,
processError,
ProcessToDo,
UserResult
UserResult,
ContextId
} from '@hcengineering/process'
import { ExecuteResult, ProcessControl, SuccessExecutionContext } from '@hcengineering/server-process'
import { isEmptyMarkup } from '@hcengineering/text-core'
Expand Down Expand Up @@ -756,6 +757,25 @@ export async function CreateToDo (
const _process = control.client.getModel().findObject(execution.process)
if (_process === undefined) return { txes: [], rollback: [], context: null }
const field = resolveAttributeId(_process, (params as any).field)
const todoResults = results ?? []
if (params.askRequired === true) {
const hierarchy = control.client.getHierarchy()
const classId = _process.masterTag
const allAttributes = Array.from(hierarchy.getAllAttributes(classId, core.class.Doc).values())

for (const attr of allAttributes) {
if (attr.hidden === true || attr.required !== true) continue
if (todoResults.some((r) => r.key === attr.name)) continue

todoResults.push({
_id: generateId() as any as ContextId,
name: attr.name,
key: attr.name,
type: attr.type
})
}
}

const tx = control.client.txFactory.createTxCreateDoc(
process.class.ProcessToDo,
time.space.ToDos,
Expand All @@ -774,8 +794,9 @@ export async function CreateToDo (
doneOn: null,
rank: '',
withRollback: params.withRollback ?? false,
results,
field
results: todoResults,
field,
askRequired: params.askRequired
},
id
)
Expand Down
Loading