mirror of
https://github.com/hcengineering/platform.git
synced 2026-10-01 22:15:04 +02:00
Copy ids and attributes to markdown card title (#10467)
Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
@@ -15,10 +15,11 @@
|
||||
|
||||
import { type Class, type Doc, type Hierarchy, type Ref } from '@hcengineering/core'
|
||||
import { translate, type IntlString } from '@hcengineering/platform'
|
||||
import cardPlugin, { type CardSpace } from '@hcengineering/card'
|
||||
import cardPlugin, { type Card, type CardSpace } from '@hcengineering/card'
|
||||
import { type AttributeModel } from '@hcengineering/view'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { isIntlString } from '@hcengineering/converter-resources'
|
||||
import { getCardIds, getCardVersion } from './cardUtils'
|
||||
|
||||
/**
|
||||
* Cache for MasterTag ID -> label mappings to reduce database calls
|
||||
@@ -110,6 +111,18 @@ export async function formatCardValue (
|
||||
|
||||
const cardDoc = card as unknown as Record<string, unknown>
|
||||
|
||||
if (attr.key === '') {
|
||||
const labelStr = typeof attr.label === 'string' ? attr.label : ''
|
||||
if (labelStr.startsWith('custom') || attr.isLookup) {
|
||||
return undefined
|
||||
}
|
||||
const cardObj = card as unknown as Card
|
||||
const ids = getCardIds(cardObj, hierarchy)
|
||||
const version = getCardVersion(cardObj, hierarchy)
|
||||
const parts = [ids, cardObj.title, version].filter(Boolean)
|
||||
return parts.join(' ')
|
||||
}
|
||||
|
||||
// Handle _class field (MasterTag/Type) - format MasterTag ID to label
|
||||
if (attr.key === '_class') {
|
||||
const classValue: unknown = cardDoc._class
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// Copyright © 2026 Hardcore Engineering Inc.
|
||||
//
|
||||
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License. You may
|
||||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
//
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import core, { type Hierarchy, toRank } from '@hcengineering/core'
|
||||
import { type Card } from '@hcengineering/card'
|
||||
|
||||
/**
|
||||
* Get the IDs string for a card (attributes with showInPresenter, sorted by rank).
|
||||
* Same logic as CardPresenter title line prefix.
|
||||
*/
|
||||
export function getCardIds (object: Card | undefined, hierarchy: Hierarchy): string {
|
||||
if (object === undefined) return ''
|
||||
const attrs = [...hierarchy.getAllAttributes(object._class, core.class.Doc).values()].sort((a, b) => {
|
||||
const rankA = a.rank ?? toRank(a._id) ?? ''
|
||||
const rankB = b.rank ?? toRank(b._id) ?? ''
|
||||
return rankA.localeCompare(rankB)
|
||||
})
|
||||
const res: string[] = []
|
||||
for (const attr of attrs) {
|
||||
const val = (object as any)[attr.name]
|
||||
if ((attr as { showInPresenter?: boolean }).showInPresenter === true && val !== undefined) {
|
||||
if (typeof val === 'string' || typeof val === 'number') {
|
||||
res.push(val.toString())
|
||||
} else if (typeof val === 'boolean') {
|
||||
res.push(val ? '✅' : '❌️')
|
||||
}
|
||||
}
|
||||
}
|
||||
return res.join(' ')
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version string for a card (e.g. "v1") when VersionableClass is enabled.
|
||||
* Same logic as CardPresenter title line suffix.
|
||||
*/
|
||||
export function getCardVersion (val: Card | undefined, hierarchy: Hierarchy): string {
|
||||
if (val === undefined) return ''
|
||||
const mixin = hierarchy.classHierarchyMixin(val._class, core.mixin.VersionableClass)
|
||||
if (mixin != null && mixin.enabled) {
|
||||
return 'v' + (val.version ?? 1)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { Card, MasterTag } from '@hcengineering/card'
|
||||
import core, { Ref, toRank } from '@hcengineering/core'
|
||||
import { Ref } from '@hcengineering/core'
|
||||
import { Asset, getEmbeddedLabel } from '@hcengineering/platform'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { AnySvelteComponent, tooltip } from '@hcengineering/ui'
|
||||
@@ -22,6 +22,7 @@
|
||||
import { DocNavLink, ObjectMention } from '@hcengineering/view-resources'
|
||||
|
||||
import card from '../plugin'
|
||||
import { getCardIds, getCardVersion } from '../cardUtils'
|
||||
import CardIcon from './CardIcon.svelte'
|
||||
import ParentNamesPresenter from './ParentNamesPresenter.svelte'
|
||||
|
||||
@@ -56,41 +57,8 @@
|
||||
$: _class = cardObj && (client.getHierarchy().getClass(cardObj?._class) as MasterTag)
|
||||
$: icon = _class && _class.icon
|
||||
|
||||
$: ids = getIds(cardObj)
|
||||
|
||||
function getIds (object: Card | undefined): string {
|
||||
if (object === undefined) return ''
|
||||
const h = client.getHierarchy()
|
||||
const attrs = [...h.getAllAttributes(object._class, core.class.Doc).values()].sort((a, b) => {
|
||||
const rankA = a.rank ?? toRank(a._id) ?? ''
|
||||
const rankB = b.rank ?? toRank(b._id) ?? ''
|
||||
return rankA.localeCompare(rankB)
|
||||
})
|
||||
const res: string[] = []
|
||||
for (const attr of attrs) {
|
||||
const val = (object as any)[attr.name]
|
||||
if (attr.showInPresenter === true && val !== undefined) {
|
||||
if (typeof val === 'string' || typeof val === 'number') {
|
||||
res.push(val.toString())
|
||||
} else if (typeof val === 'boolean') {
|
||||
res.push(val ? '✅' : '❌️')
|
||||
}
|
||||
}
|
||||
}
|
||||
return res.join(' ')
|
||||
}
|
||||
|
||||
$: version = getVersion(cardObj)
|
||||
|
||||
function getVersion (val: Card | undefined): string {
|
||||
if (val === undefined) return ''
|
||||
const h = client.getHierarchy()
|
||||
const mixin = h.classHierarchyMixin(val._class, core.mixin.VersionableClass)
|
||||
if (mixin?.enabled) {
|
||||
return 'v' + (val.version ?? 1)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
$: ids = getCardIds(cardObj, client.getHierarchy())
|
||||
$: version = getCardVersion(cardObj, client.getHierarchy())
|
||||
</script>
|
||||
|
||||
{#if inline && cardObj}
|
||||
|
||||
Reference in New Issue
Block a user