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
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

const client = getClient()

const origin = client.getHierarchy().clone(viewlet)

async function save (): Promise<void> {
await client.diffUpdate(viewlet, {
await client.diffUpdate(origin, {
title,
descriptor: type,
config: viewlet.config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte'

import core, { AnyAttribute, Association, AssociationQuery, Class, Doc, Ref, Type } from '@hcengineering/core'
import core, { AnyAttribute, Association, AssociationQuery, Class, Client, Doc, Ref, Type } from '@hcengineering/core'
import { Asset, getEmbeddedLabel, IntlString } from '@hcengineering/platform'
import { getAttributePresenterClass, getClient, hasResource } from '@hcengineering/presentation'
import { resizeObserver } from '@hcengineering/ui'
Expand Down Expand Up @@ -57,6 +57,22 @@
}
}

function getAssoctiationLabel (client: Client, param: string): IntlString {
const model = client.getModel()
const associations = param.split('$associations.')
const resultLabels = associations
.map((r) => {
const parts = r.split('_')
if (parts.length !== 2) return ''
const assoc = model.findObject(parts[0] as Ref<Association>)
if (assoc === undefined) return ''
return parts[1] === '1' ? assoc.nameA : assoc.nameB
})
.filter((it) => it.length > 0)

return getEmbeddedLabel(resultLabels.join(' › '))
}

function getBaseConfig (viewlet: Viewlet): Config[] {
const lookup = buildConfigLookup(hierarchy, viewlet.attachTo, viewlet.config, viewlet.options?.lookup)
const result: Config[] = []
Expand All @@ -67,6 +83,16 @@
if (viewlet.configOptions?.hiddenKeys?.includes(param)) continue
if (param.length === 0) {
result.push(getObjectConfig(viewlet.attachTo, param))
} else if (param.startsWith('$associations.')) {
const assocConfig: AttributeConfig = {
type: 'attribute',
value: param,
enabled: true,
label: getAssoctiationLabel(client, param),
_class: viewlet.attachTo,
icon: clazz.icon
}
result.push(assocConfig)
} else {
const attrCfg: AttributeConfig = {
type: 'attribute',
Expand Down
28 changes: 27 additions & 1 deletion plugins/view-resources/src/components/ViewletSetting.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import core, { AnyAttribute, Association, AssociationQuery, Class, Doc, Ref, Type } from '@hcengineering/core'
import core, { AnyAttribute, Association, AssociationQuery, Class, Client, Doc, Ref, Type } from '@hcengineering/core'
import { Asset, getEmbeddedLabel, IntlString } from '@hcengineering/platform'
import { createQuery, getAttributePresenterClass, getClient, hasResource } from '@hcengineering/presentation'
import { DropdownLabelsIntl, Loading, resizeObserver } from '@hcengineering/ui'
Expand Down Expand Up @@ -97,6 +97,22 @@
}
}

function getAssoctiationLabel (client: Client, param: string): IntlString {
const model = client.getModel()
const associations = param.split('$associations.')
const resultLabels = associations
.map((r) => {
const parts = r.split('_')
if (parts.length !== 2) return ''
const assoc = model.findObject(parts[0] as Ref<Association>)
if (assoc === undefined) return ''
return parts[1] === '1' ? assoc.nameA : assoc.nameB
})
.filter((it) => it.length > 0)

return getEmbeddedLabel(resultLabels.join(' › '))
}

function getBaseConfig (viewlet: Viewlet): Config[] {
const config = defaultConfig ?? viewlet.config
const lookup = buildConfigLookup(hierarchy, viewlet.attachTo, config, viewlet.options?.lookup)
Expand All @@ -109,6 +125,16 @@
if (viewlet.configOptions?.hiddenKeys?.includes(param)) continue
if (param.length === 0) {
result.push(getObjectConfig(viewlet.attachTo, param))
} else if (param.startsWith('$associations.')) {
const assocConfig: AttributeConfig = {
type: 'attribute',
value: param,
enabled: true,
label: getAssoctiationLabel(client, param),
_class: viewlet.attachTo,
icon: clazz.icon
}
result.push(assocConfig)
} else {
const paramValue = param.startsWith('custom') ? { key: param, displayProps: { optional: true } } : param
const attrCfg: AttributeConfig = {
Expand Down
Loading