Skip to content

Commit d5e69ed

Browse files
authored
RunProcess action for multiple cards (#10125)
1 parent 47e3f2b commit d5e69ed

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

models/process/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export function createModel (builder: Builder): void {
315315
},
316316
label: process.string.RunProcess,
317317
icon: process.icon.Process,
318-
input: 'focus',
318+
input: 'any',
319319
category: view.category.General,
320320
target: card.class.Card,
321321
context: {

plugins/process-resources/src/components/RunProcessPopup.svelte

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,56 @@
1414
-->
1515
<script lang="ts">
1616
import { Card } from '@hcengineering/card'
17-
import { Ref } from '@hcengineering/core'
17+
import { Class, Doc, Ref } from '@hcengineering/core'
1818
import { getClient } from '@hcengineering/presentation'
1919
import { Process } from '@hcengineering/process'
2020
import { Label } from '@hcengineering/ui'
2121
import { createEventDispatcher } from 'svelte'
2222
import process from '../plugin'
2323
import { createExecution } from '../utils'
2424
25-
export let value: Card
25+
export let value: Card | Card[] | undefined
26+
27+
const values = Array.isArray(value) ? value : value ? [value] : []
2628
2729
const client = getClient()
2830
const h = client.getHierarchy()
2931
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()
3333
3434
const res = client.getModel().findAllSync(process.class.Process, {})
3535
const processes = res.filter((it) => resClasses.includes(it.masterTag))
3636
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+
3765
async function filterProcesses (processes: Process[]): Promise<Process[]> {
66+
if (value === undefined) return []
3867
const res: Process[] = []
3968
const shouldCheck: Process[] = []
4069
for (const val of processes) {
@@ -48,6 +77,7 @@
4877
4978
const executions = await client.findAll(process.class.Execution, {
5079
process: { $in: shouldCheck.map((it) => it._id) },
80+
card: { $in: values.map((it) => it._id) },
5181
done: false
5282
})
5383
const notAllowed = new Set(executions.map((it) => it.process))
@@ -62,7 +92,10 @@
6292
const dispatch = createEventDispatcher()
6393
6494
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+
}
6699
dispatch('close')
67100
}
68101
</script>

0 commit comments

Comments
 (0)