mirror of
https://github.com/hcengineering/platform.git
synced 2025-03-12 00:11:17 +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,
|
component: document.component.DocumentSearchIcon,
|
||||||
props: ['icon', 'color']
|
props: ['icon', 'color']
|
||||||
},
|
},
|
||||||
title: 'name'
|
title: 'title'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ async function queryDocument (
|
|||||||
search: string,
|
search: string,
|
||||||
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
||||||
): Promise<ObjectSearchResult[]> {
|
): Promise<ObjectSearchResult[]> {
|
||||||
const q: DocumentQuery<Document> = { name: { $like: `%${search}%` } }
|
const q: DocumentQuery<Document> = { title: { $like: `%${search}%` } }
|
||||||
if (filter?.in !== undefined || filter?.nin !== undefined) {
|
if (filter?.in !== undefined || filter?.nin !== undefined) {
|
||||||
q._id = {}
|
q._id = {}
|
||||||
if (filter.in !== undefined) {
|
if (filter.in !== undefined) {
|
||||||
|
@ -22,8 +22,12 @@
|
|||||||
|
|
||||||
const client = getClient()
|
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[]> {
|
async function getParents (doc: Doc | AttachedDoc): Promise<readonly Doc[]> {
|
||||||
if (!isAttachedDoc(doc)) {
|
if (!isAttachedDoc(doc) && !hasParent(doc)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,8 +35,10 @@
|
|||||||
|
|
||||||
let currentDoc: Doc | undefined = doc
|
let currentDoc: Doc | undefined = doc
|
||||||
|
|
||||||
while (currentDoc && isAttachedDoc(currentDoc)) {
|
while (currentDoc && (isAttachedDoc(currentDoc) || hasParent(currentDoc))) {
|
||||||
const parent: Doc | undefined = await client.findOne(currentDoc.attachedToClass, { _id: currentDoc.attachedTo })
|
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) {
|
if (parent) {
|
||||||
currentDoc = parent
|
currentDoc = parent
|
||||||
|
Loading…
Reference in New Issue
Block a user