Skip to content

Commit 3a45f31

Browse files
authored
Multiple user request input (#10367)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
1 parent 214f61f commit 3a45f31

5 files changed

Lines changed: 227 additions & 101 deletions

File tree

plugins/contact-resources/src/components/EmployeeAttributePresenter.svelte

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts">
22
import { Employee } from '@hcengineering/contact'
3-
import { Ref } from '@hcengineering/core'
3+
import core, { AccountUuid, AnyAttribute, DocumentQuery, notEmpty, Ref, Space } from '@hcengineering/core'
44
import { ButtonKind, IconSize } from '@hcengineering/ui'
5-
import { PersonLabelTooltip } from '..'
5+
import { employeeRefByAccountUuidStore, PersonLabelTooltip } from '..'
66
import contact from '../plugin'
77
import { employeeByIdStore } from '../utils'
88
import AssigneeBox from './AssigneeBox.svelte'
99
import EmployeePresenter from './EmployeePresenter.svelte'
10+
import { getClient } from '@hcengineering/presentation'
1011
1112
export let value: Ref<Employee> | null | undefined
1213
export let kind: ButtonKind = 'link'
@@ -18,6 +19,8 @@
1819
export let shouldShowName: boolean = true
1920
export let avatarSize: IconSize = kind === 'list-header' ? 'smaller' : 'x-small'
2021
export let readonly = false
22+
export let attribute: AnyAttribute | undefined = undefined
23+
export let space: Ref<Space> | undefined = undefined
2124
2225
$: employee = value ? $employeeByIdStore.get(value) : undefined
2326
@@ -30,6 +33,51 @@
3033
}
3134
return employee
3235
}
36+
37+
let query: DocumentQuery<Employee> = {
38+
active: true
39+
}
40+
41+
const client = getClient()
42+
43+
$: buildQuery(attribute, space)
44+
45+
async function buildQuery (attribute: AnyAttribute | undefined, space: Ref<Space> | undefined): Promise<void> {
46+
const baseQuery = {
47+
active: true
48+
}
49+
if (attribute === undefined || space === undefined) {
50+
query = baseQuery
51+
return
52+
}
53+
if (attribute.spaceMembersOnly === true || attribute.byRole !== undefined) {
54+
const _space = await client.findOne(core.class.Space, {
55+
_id: space
56+
})
57+
if (_space === undefined) {
58+
query = baseQuery
59+
return
60+
}
61+
62+
if (attribute.byRole === undefined) {
63+
const allMembers = _space.members ?? []
64+
const allPersonsSet = new Set(allMembers.map((p) => $employeeRefByAccountUuidStore.get(p)).filter(notEmpty))
65+
66+
query = {
67+
...baseQuery,
68+
_id: { $in: Array.from(allPersonsSet) }
69+
}
70+
} else {
71+
const asMixin = client.getHierarchy().as(_space, core.mixin.SpacesTypeData)
72+
const roleMembers = ((asMixin as any)[attribute.byRole] ?? []) as AccountUuid[]
73+
const rolePersons = new Set(roleMembers.map((p) => $employeeRefByAccountUuidStore.get(p)).filter(notEmpty))
74+
query = {
75+
...baseQuery,
76+
_id: { $in: Array.from(rolePersons) }
77+
}
78+
}
79+
}
80+
}
3381
</script>
3482

3583
{#if onChange !== undefined}
@@ -39,6 +87,7 @@
3987
{value}
4088
size={'medium'}
4189
kind={'link'}
90+
docQuery={query}
4291
showNavigate={false}
4392
justify={'left'}
4493
{shouldShowName}

plugins/contact-resources/src/components/EmployeeRefPresenter.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { Employee } from '@hcengineering/contact'
3-
import { Ref } from '@hcengineering/core'
3+
import { AnyAttribute, Ref, Space } from '@hcengineering/core'
44
import { ButtonKind, IconSize } from '@hcengineering/ui'
55
import { PersonLabelTooltip } from '..'
66
import EmployeeAttributePresenter from './EmployeeAttributePresenter.svelte'
@@ -15,6 +15,8 @@
1515
export let shouldShowName: boolean = true
1616
export let avatarSize: IconSize = kind === 'regular' ? 'small' : 'card'
1717
export let readonly = false
18+
export let attribute: AnyAttribute | undefined = undefined
19+
export let space: Ref<Space> | undefined = undefined
1820
</script>
1921

2022
{#if Array.isArray(value)}
@@ -31,6 +33,8 @@
3133
{shouldShowName}
3234
{avatarSize}
3335
{readonly}
36+
{attribute}
37+
{space}
3438
on:accent-color
3539
/>
3640
{/each}
@@ -47,6 +51,8 @@
4751
{shouldShowName}
4852
{avatarSize}
4953
{readonly}
54+
{attribute}
55+
{space}
5056
on:accent-color
5157
/>
5258
{/if}

plugins/process-resources/src/components/contextEditors/RequestUserInput.svelte

Lines changed: 34 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,27 @@
1313
// limitations under the License.
1414
-->
1515
<script lang="ts">
16-
import core, { AnyAttribute, Class, Doc, generateId, Ref, RefTo } from '@hcengineering/core'
17-
import presentation, { Card, findAttributeEditor, getClient } from '@hcengineering/presentation'
18-
import { Process, Transition } from '@hcengineering/process'
19-
import { AnyComponent, Component, Label } from '@hcengineering/ui'
20-
import view from '@hcengineering/view'
16+
import { Ref, Space } from '@hcengineering/core'
17+
import presentation, { Card, getClient } from '@hcengineering/presentation'
18+
import { ExecutionContext, Process, SelectedUserRequest, Transition } from '@hcengineering/process'
19+
import { Label } from '@hcengineering/ui'
2120
import { createEventDispatcher } from 'svelte'
2221
import plugin from '../../plugin'
2322
import TransitionPresenter from '../settings/TransitionPresenter.svelte'
23+
import RequestUserInputAttribute from './RequestUserInputAttribute.svelte'
2424
2525
export let processId: Ref<Process>
26+
export let space: Ref<Space>
2627
export let transition: Ref<Transition>
27-
export let key: string
28-
export let _class: Ref<Class<Doc>>
29-
export let value: any | undefined = undefined
28+
export let inputs: SelectedUserRequest[]
29+
export let values: ExecutionContext
3030
3131
const dispatch = createEventDispatcher()
3232
const client = getClient()
33-
const hierarchy = client.getHierarchy()
3433
const model = client.getModel()
35-
const attribute = hierarchy.findAttribute(_class, key) ?? (key === '' ? mockAttribute(_class) : undefined)
36-
37-
function mockAttribute (_class: Ref<Class<Doc>>): AnyAttribute {
38-
const type: RefTo<Doc> = {
39-
label: core.string.Ref,
40-
_class: core.class.RefTo,
41-
to: _class
42-
}
43-
return {
44-
attributeOf: _class,
45-
name: '',
46-
type,
47-
_id: generateId(),
48-
space: core.space.Model,
49-
modifiedOn: 0,
50-
modifiedBy: core.account.System,
51-
_class: core.class.Attribute,
52-
label: core.string.Object
53-
}
54-
}
5534
5635
function save (): void {
57-
dispatch('close', { value })
58-
}
59-
60-
let editor: AnyComponent | undefined
61-
62-
function getEditor (_class: Ref<Class<Doc>>, key: string): void {
63-
if (key === '' || key === '_id') {
64-
const mixin = hierarchy.classHierarchyMixin(_class, view.mixin.AttributeEditor)
65-
if (mixin?.inlineEditor !== undefined) {
66-
editor = mixin.inlineEditor
67-
return
68-
}
69-
}
70-
editor = findAttributeEditor(client, _class, key)
71-
}
72-
73-
function onChange (val: any | undefined): void {
74-
value = val
36+
dispatch('close', { value: values })
7537
}
7638
7739
export function canClose (): boolean {
@@ -80,13 +42,11 @@
8042
8143
const transitionVal = model.findObject(transition)
8244
const processVal = model.findObject(processId)
83-
84-
$: getEditor(_class, key)
8545
</script>
8646

8747
<Card
8848
on:close
89-
width={'menu'}
49+
width={'small'}
9050
label={plugin.string.EnterValue}
9151
canSave
9252
okAction={save}
@@ -101,27 +61,30 @@
10161
{#if transitionVal}
10262
<TransitionPresenter transition={transitionVal} />
10363
{/if}
104-
{#if attribute}
105-
<Label label={attribute.label} />:
106-
{/if}
107-
{#if editor}
108-
<div class="w-full mt-2">
109-
<Component
110-
is={editor}
111-
props={{
112-
label: attribute?.label,
113-
placeholder: attribute?.label,
114-
kind: 'ghost',
115-
size: 'large',
116-
width: '100%',
117-
justify: 'left',
118-
type: attribute?.type,
119-
showNavigate: false,
120-
value,
121-
onChange,
122-
focus
64+
<div class="grid">
65+
{#each inputs as input}
66+
<RequestUserInputAttribute
67+
key={input.key}
68+
_class={input._class}
69+
{space}
70+
on:change={(e) => {
71+
values[input.id] = e.detail
12372
}}
12473
/>
125-
</div>
126-
{/if}
74+
{/each}
75+
</div>
12776
</Card>
77+
78+
<style lang="scss">
79+
.grid {
80+
display: grid;
81+
grid-template-columns: 1fr 1.5fr;
82+
grid-auto-rows: minmax(2rem, max-content);
83+
justify-content: start;
84+
align-items: center;
85+
row-gap: 0.5rem;
86+
column-gap: 1rem;
87+
width: calc(100% - 4rem);
88+
height: min-content;
89+
}
90+
</style>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!--
2+
// Copyright © 2025 Hardcore Engineering Inc.
3+
//
4+
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License. You may
6+
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
//
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
-->
15+
<script lang="ts">
16+
import core, { AnyAttribute, Class, Doc, generateId, Ref, RefTo, Space } from '@hcengineering/core'
17+
import { findAttributeEditor, getClient } from '@hcengineering/presentation'
18+
import { AnyComponent, Component, Label } from '@hcengineering/ui'
19+
import view from '@hcengineering/view'
20+
import { createEventDispatcher } from 'svelte'
21+
22+
export let key: string
23+
export let _class: Ref<Class<Doc>>
24+
export let value: any | undefined = undefined
25+
export let space: Ref<Space>
26+
27+
const client = getClient()
28+
const hierarchy = client.getHierarchy()
29+
const attribute = hierarchy.findAttribute(_class, key) ?? (key === '' ? mockAttribute(_class) : undefined)
30+
31+
function mockAttribute (_class: Ref<Class<Doc>>): AnyAttribute {
32+
const type: RefTo<Doc> = {
33+
label: core.string.Ref,
34+
_class: core.class.RefTo,
35+
to: _class
36+
}
37+
return {
38+
attributeOf: _class,
39+
name: '',
40+
type,
41+
_id: generateId(),
42+
space: core.space.Model,
43+
modifiedOn: 0,
44+
modifiedBy: core.account.System,
45+
_class: core.class.Attribute,
46+
label: core.string.Object
47+
}
48+
}
49+
50+
let editor: AnyComponent | undefined
51+
52+
function getEditor (_class: Ref<Class<Doc>>, key: string): void {
53+
if (key === '' || key === '_id') {
54+
const mixin = hierarchy.classHierarchyMixin(_class, view.mixin.AttributeEditor)
55+
if (mixin?.inlineEditor !== undefined) {
56+
editor = mixin.inlineEditor
57+
return
58+
}
59+
}
60+
editor = findAttributeEditor(client, _class, key)
61+
}
62+
63+
const dispatch = createEventDispatcher()
64+
function onChange (val: any | undefined): void {
65+
value = val
66+
dispatch('change', val)
67+
}
68+
69+
$: getEditor(_class, key)
70+
</script>
71+
72+
{#if attribute}
73+
<div>
74+
<Label label={attribute.label} />:
75+
</div>
76+
{/if}
77+
{#if editor}
78+
<div class="w-full">
79+
<Component
80+
is={editor}
81+
props={{
82+
label: attribute?.label,
83+
placeholder: attribute?.label,
84+
kind: 'ghost',
85+
size: 'large',
86+
width: '100%',
87+
justify: 'left',
88+
type: attribute?.type,
89+
showNavigate: false,
90+
value,
91+
attribute,
92+
space,
93+
onChange,
94+
focus
95+
}}
96+
/>
97+
</div>
98+
{/if}

0 commit comments

Comments
 (0)