mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-22 01:25:00 +02:00
Rollback and custom events preparation (#10298)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
import { getCurrentEmployee } from '@hcengineering/contact'
|
||||
import { getEmbeddedLabel } from '@hcengineering/platform'
|
||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||
import { Execution, ExecutionStatus, ProcessToDo } from '@hcengineering/process'
|
||||
import { EventButton, Execution, ExecutionStatus, ProcessToDo } from '@hcengineering/process'
|
||||
import { Button } from '@hcengineering/ui'
|
||||
import process from '../plugin'
|
||||
|
||||
@@ -25,6 +25,18 @@
|
||||
|
||||
let docs: Execution[] = []
|
||||
let todos: ProcessToDo[] = []
|
||||
let actions: EventButton[] = []
|
||||
|
||||
const buttonsQuery = createQuery()
|
||||
$: buttonsQuery.query(
|
||||
process.class.EventButton,
|
||||
{
|
||||
card: card._id
|
||||
},
|
||||
(res) => {
|
||||
actions = res
|
||||
}
|
||||
)
|
||||
|
||||
const executionQuery = createQuery()
|
||||
$: executionQuery.query(
|
||||
@@ -60,8 +72,41 @@
|
||||
doneOn: new Date().getTime()
|
||||
})
|
||||
}
|
||||
|
||||
async function performAction (action: EventButton) {
|
||||
await client.createDoc(process.class.ProcessCustomEvent, action.space, {
|
||||
execution: action.execution,
|
||||
eventType: action.eventType,
|
||||
card: card._id
|
||||
})
|
||||
}
|
||||
|
||||
async function performRollback (execution: Execution) {
|
||||
await client.createDoc(process.class.ProcessCustomEvent, execution.space, {
|
||||
execution: execution._id,
|
||||
eventType: 'rollback',
|
||||
card: card._id
|
||||
})
|
||||
}
|
||||
|
||||
function getExecutionLabel (execution: Execution): string {
|
||||
const pr = client.getModel().findObject(execution.process)
|
||||
if (pr !== undefined) {
|
||||
return `${pr.name}: `
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
$: rollbacks = docs.filter((d) => d.rollback.length > 0)
|
||||
</script>
|
||||
|
||||
{#each todos as todo (todo._id)}
|
||||
<Button kind={'primary'} label={getEmbeddedLabel(todo.title)} on:click={() => checkTodo(todo)} />
|
||||
{/each}
|
||||
{#each actions as action (action._id)}
|
||||
<Button kind={'primary'} label={getEmbeddedLabel(action.title)} on:click={() => performAction(action)} />
|
||||
{/each}
|
||||
{#each rollbacks as rollback}
|
||||
{getExecutionLabel(rollback)}
|
||||
<Button kind={'dangerous'} label={process.string.Rollback} on:click={() => performRollback(rollback)} />
|
||||
{/each}
|
||||
|
||||
@@ -85,7 +85,8 @@ import {
|
||||
matchCardCheck,
|
||||
subProcessesDoneCheck,
|
||||
fieldChangesCheck,
|
||||
subProcessMatchCheck
|
||||
subProcessMatchCheck,
|
||||
eventCheck
|
||||
} from './utils'
|
||||
import FieldChangesEditor from './components/settings/FieldChangesEditor.svelte'
|
||||
|
||||
@@ -173,7 +174,8 @@ export default async (): Promise<Resources> => ({
|
||||
SubProcessesDoneCheck: subProcessesDoneCheck,
|
||||
SubProcessMatchCheck: subProcessMatchCheck,
|
||||
ToDo: todoTranstionCheck,
|
||||
Time: timeTransitionCheck
|
||||
Time: timeTransitionCheck,
|
||||
OnEventCheck: eventCheck
|
||||
},
|
||||
function: {
|
||||
ShowDoneQuery: showDoneQuery,
|
||||
|
||||
@@ -68,6 +68,8 @@ export default mergeIds(processId, process, {
|
||||
CardUpdateEditor: '' as AnyComponent,
|
||||
CardUpdatePresenter: '' as AnyComponent,
|
||||
FieldChangesEditor: '' as AnyComponent,
|
||||
OnEventEditor: '' as AnyComponent,
|
||||
OnEventPresenter: '' as AnyComponent,
|
||||
ToDoSettingPresenter: '' as AnyComponent,
|
||||
TimeEditor: '' as AnyComponent,
|
||||
TimePresenter: '' as AnyComponent,
|
||||
@@ -174,6 +176,7 @@ export default mergeIds(processId, process, {
|
||||
WaitUntil: '' as IntlString,
|
||||
WhenCardMatches: '' as IntlString,
|
||||
WhenFieldChanges: '' as IntlString,
|
||||
OnEvent: '' as IntlString,
|
||||
Result: '' as IntlString,
|
||||
RequestResult: '' as IntlString,
|
||||
NoResultRequired: '' as IntlString,
|
||||
|
||||
@@ -617,6 +617,16 @@ export function timeTransitionCheck (
|
||||
return params.value <= Date.now()
|
||||
}
|
||||
|
||||
export function eventCheck (
|
||||
client: Client,
|
||||
execution: Execution,
|
||||
params: Record<string, any>,
|
||||
context: Record<string, any>
|
||||
): boolean {
|
||||
if (params.eventType === undefined) return false
|
||||
return context.eventType === params.eventType
|
||||
}
|
||||
|
||||
export function matchCardCheck (
|
||||
client: Client,
|
||||
execution: Execution,
|
||||
|
||||
Reference in New Issue
Block a user