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
2 changes: 1 addition & 1 deletion models/process/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export function createModel (builder: Builder): void {
},
label: process.string.RunProcess,
icon: process.icon.Process,
input: 'focus',
input: 'any',
category: view.category.General,
target: card.class.Card,
context: {
Expand Down
45 changes: 39 additions & 6 deletions plugins/process-resources/src/components/RunProcessPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,56 @@
-->
<script lang="ts">
import { Card } from '@hcengineering/card'
import { Ref } from '@hcengineering/core'
import { Class, Doc, Ref } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import { Process } from '@hcengineering/process'
import { Label } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte'
import process from '../plugin'
import { createExecution } from '../utils'

export let value: Card
export let value: Card | Card[] | undefined

const values = Array.isArray(value) ? value : value ? [value] : []

Check warning on line 27 in plugins/process-resources/src/components/RunProcessPopup.svelte

View workflow job for this annotation

GitHub Actions / formatting

Unexpected nullable object value in conditional. An explicit null check is required

const client = getClient()
const h = client.getHierarchy()

const asc = h.getAncestors(value._class)
const mixins = h.getDescendants(value._class).filter((p) => h.hasMixin(value, p))
const resClasses = [...asc, ...mixins]
const resClasses = getPossibleClasses()

const res = client.getModel().findAllSync(process.class.Process, {})
const processes = res.filter((it) => resClasses.includes(it.masterTag))

function getCardPossibleClasses (card: Card): Ref<Class<Doc>>[] {
const asc = h.getAncestors(card._class)
const mixins = h.getDescendants(card._class).filter((p) => h.hasMixin(card, p))
return [...asc, ...mixins]
}

function getPossibleClasses (): Ref<Class<Doc>>[] {
if (!value) {

Check warning on line 44 in plugins/process-resources/src/components/RunProcessPopup.svelte

View workflow job for this annotation

GitHub Actions / formatting

Unexpected nullable object value in conditional. An explicit null check is required
return []
}
const res = new Set<Ref<Class<Doc>>>()
for (const val of values) {
const resClasses = getCardPossibleClasses(val)
if (res.size === 0) {
for (const cls of resClasses) {
res.add(cls)
}
} else {
for (const cls of Array.from(res)) {
if (!resClasses.includes(cls)) {
res.delete(cls)
}
}
}
}
return [...res]
}

async function filterProcesses (processes: Process[]): Promise<Process[]> {
if (value === undefined) return []
const res: Process[] = []
const shouldCheck: Process[] = []
for (const val of processes) {
Expand All @@ -48,6 +77,7 @@

const executions = await client.findAll(process.class.Execution, {
process: { $in: shouldCheck.map((it) => it._id) },
card: { $in: values.map((it) => it._id) },
done: false
})
const notAllowed = new Set(executions.map((it) => it.process))
Expand All @@ -62,7 +92,10 @@
const dispatch = createEventDispatcher()

async function runProcess (_id: Ref<Process>): Promise<void> {
await createExecution(value._id, _id, value.space)
if (!value) return

Check warning on line 95 in plugins/process-resources/src/components/RunProcessPopup.svelte

View workflow job for this annotation

GitHub Actions / formatting

Unexpected nullable object value in conditional. An explicit null check is required
for (const element of values) {
await createExecution(element._id, _id, element.space)
}
dispatch('close')
}
</script>
Expand Down
Loading