mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-23 03:49:49 +00:00
Fix documents search (#6818)
This commit is contained in:
parent
a78ec1bc19
commit
c9a032eb0b
@ -33,7 +33,7 @@ export function createModel (builder: Builder): void {
|
||||
component: document.component.DocumentSearchIcon,
|
||||
props: ['icon', 'color']
|
||||
},
|
||||
title: 'name'
|
||||
title: 'title'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ async function queryDocument (
|
||||
search: string,
|
||||
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
||||
): Promise<ObjectSearchResult[]> {
|
||||
const q: DocumentQuery<Document> = { name: { $like: `%${search}%` } }
|
||||
const q: DocumentQuery<Document> = { title: { $like: `%${search}%` } }
|
||||
if (filter?.in !== undefined || filter?.nin !== undefined) {
|
||||
q._id = {}
|
||||
if (filter.in !== undefined) {
|
||||
|
@ -22,8 +22,12 @@
|
||||
|
||||
const client = getClient()
|
||||
|
||||
function hasParent (doc: Doc | AttachedDoc): boolean {
|
||||
return 'parent' in doc && doc.parent != null
|
||||
}
|
||||
|
||||
async function getParents (doc: Doc | AttachedDoc): Promise<readonly Doc[]> {
|
||||
if (!isAttachedDoc(doc)) {
|
||||
if (!isAttachedDoc(doc) && !hasParent(doc)) {
|
||||
return []
|
||||
}
|
||||
|
||||
@ -31,8 +35,10 @@
|
||||
|
||||
let currentDoc: Doc | undefined = doc
|
||||
|
||||
while (currentDoc && isAttachedDoc(currentDoc)) {
|
||||
const parent: Doc | undefined = await client.findOne(currentDoc.attachedToClass, { _id: currentDoc.attachedTo })
|
||||
while (currentDoc && (isAttachedDoc(currentDoc) || hasParent(currentDoc))) {
|
||||
const parent: Doc | undefined = isAttachedDoc(currentDoc)
|
||||
? await client.findOne(currentDoc.attachedToClass, { _id: currentDoc.attachedTo })
|
||||
: await client.findOne(currentDoc._class, { _id: (currentDoc as any).parent })
|
||||
|
||||
if (parent) {
|
||||
currentDoc = parent
|
||||
|
Loading…
Reference in New Issue
Block a user