|
14 | 14 | --> |
15 | 15 | <script lang="ts"> |
16 | 16 | import { Card } from '@hcengineering/card' |
17 | | - import { Ref } from '@hcengineering/core' |
| 17 | + import { Class, Doc, Ref } from '@hcengineering/core' |
18 | 18 | import { getClient } from '@hcengineering/presentation' |
19 | 19 | import { Process } from '@hcengineering/process' |
20 | 20 | import { Label } from '@hcengineering/ui' |
21 | 21 | import { createEventDispatcher } from 'svelte' |
22 | 22 | import process from '../plugin' |
23 | 23 | import { createExecution } from '../utils' |
24 | 24 |
|
25 | | - export let value: Card |
| 25 | + export let value: Card | Card[] | undefined |
| 26 | +
|
| 27 | + const values = Array.isArray(value) ? value : value ? [value] : [] |
26 | 28 |
|
27 | 29 | const client = getClient() |
28 | 30 | const h = client.getHierarchy() |
29 | 31 |
|
30 | | - const asc = h.getAncestors(value._class) |
31 | | - const mixins = h.getDescendants(value._class).filter((p) => h.hasMixin(value, p)) |
32 | | - const resClasses = [...asc, ...mixins] |
| 32 | + const resClasses = getPossibleClasses() |
33 | 33 |
|
34 | 34 | const res = client.getModel().findAllSync(process.class.Process, {}) |
35 | 35 | const processes = res.filter((it) => resClasses.includes(it.masterTag)) |
36 | 36 |
|
| 37 | + function getCardPossibleClasses (card: Card): Ref<Class<Doc>>[] { |
| 38 | + const asc = h.getAncestors(card._class) |
| 39 | + const mixins = h.getDescendants(card._class).filter((p) => h.hasMixin(card, p)) |
| 40 | + return [...asc, ...mixins] |
| 41 | + } |
| 42 | +
|
| 43 | + function getPossibleClasses (): Ref<Class<Doc>>[] { |
| 44 | + if (!value) { |
| 45 | + return [] |
| 46 | + } |
| 47 | + const res = new Set<Ref<Class<Doc>>>() |
| 48 | + for (const val of values) { |
| 49 | + const resClasses = getCardPossibleClasses(val) |
| 50 | + if (res.size === 0) { |
| 51 | + for (const cls of resClasses) { |
| 52 | + res.add(cls) |
| 53 | + } |
| 54 | + } else { |
| 55 | + for (const cls of Array.from(res)) { |
| 56 | + if (!resClasses.includes(cls)) { |
| 57 | + res.delete(cls) |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + return [...res] |
| 63 | + } |
| 64 | +
|
37 | 65 | async function filterProcesses (processes: Process[]): Promise<Process[]> { |
| 66 | + if (value === undefined) return [] |
38 | 67 | const res: Process[] = [] |
39 | 68 | const shouldCheck: Process[] = [] |
40 | 69 | for (const val of processes) { |
|
48 | 77 |
|
49 | 78 | const executions = await client.findAll(process.class.Execution, { |
50 | 79 | process: { $in: shouldCheck.map((it) => it._id) }, |
| 80 | + card: { $in: values.map((it) => it._id) }, |
51 | 81 | done: false |
52 | 82 | }) |
53 | 83 | const notAllowed = new Set(executions.map((it) => it.process)) |
|
62 | 92 | const dispatch = createEventDispatcher() |
63 | 93 |
|
64 | 94 | async function runProcess (_id: Ref<Process>): Promise<void> { |
65 | | - await createExecution(value._id, _id, value.space) |
| 95 | + if (!value) return |
| 96 | + for (const element of values) { |
| 97 | + await createExecution(element._id, _id, element.space) |
| 98 | + } |
66 | 99 | dispatch('close') |
67 | 100 | } |
68 | 101 | </script> |
|
0 commit comments