mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
add index to model
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
64e88b01ec
commit
753e5e4690
File diff suppressed because it is too large
Load Diff
@ -14,8 +14,9 @@
|
||||
//
|
||||
|
||||
import type { IntlString } from '@anticrm/platform'
|
||||
import { Builder, Model, UX } from '@anticrm/model'
|
||||
import { Builder, Model, Prop, UX, TypeString, Index } from '@anticrm/model'
|
||||
import type { Ref, Doc, Class, Domain } from '@anticrm/core'
|
||||
import { IndexKind } from '@anticrm/core'
|
||||
import core, { TSpace, TDoc } from '@anticrm/model-core'
|
||||
import type { Backlink, Channel, Message, Comment } from '@anticrm/chunter'
|
||||
import type { AnyComponent } from '@anticrm/ui'
|
||||
@ -34,6 +35,8 @@ export class TChannel extends TSpace implements Channel {}
|
||||
|
||||
@Model(chunter.class.Message, core.class.Doc, DOMAIN_CHUNTER)
|
||||
export class TMessage extends TDoc implements Message {
|
||||
@Prop(TypeString(), 'Content' as IntlString)
|
||||
@Index(IndexKind.FullText)
|
||||
content!: string
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,13 @@ export interface UXObject extends Obj {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export interface Type<T extends PropertyType> extends UXObject {}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export enum IndexKind {
|
||||
FullText
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
@ -74,6 +81,7 @@ export interface Attribute<T extends PropertyType> extends Doc, UXObject {
|
||||
attributeOf: Ref<Class<Obj>>
|
||||
name: string
|
||||
type: Type<T>
|
||||
index?: IndexKind
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,6 +169,14 @@ export class Hierarchy {
|
||||
attributes.set(attribute.name, attribute)
|
||||
}
|
||||
|
||||
getAttributes (clazz: Ref<Class<Obj>>): Map<string, AnyAttribute> {
|
||||
const attributes = this.attributes.get(clazz)
|
||||
if (attributes === undefined) {
|
||||
throw new Error('attributes not found for class ' + clazz)
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
getAttribute (_class: Ref<Class<Obj>>, name: string): AnyAttribute {
|
||||
const attribute = this.attributes.get(_class)?.get(name)
|
||||
if (attribute === undefined) {
|
||||
|
@ -29,7 +29,7 @@ import type {
|
||||
Space,
|
||||
ExtendedAttributes
|
||||
} from '@anticrm/core'
|
||||
import { ClassifierKind, generateId, TxFactory } from '@anticrm/core'
|
||||
import { ClassifierKind, IndexKind, generateId, TxFactory } from '@anticrm/core'
|
||||
import type { IntlString, Asset } from '@anticrm/platform'
|
||||
import toposort from 'toposort'
|
||||
|
||||
@ -37,6 +37,21 @@ import core from './component'
|
||||
|
||||
type NoIDs<T extends Tx> = Omit<T, '_id' | 'objectId'>
|
||||
|
||||
const targets = new Map<any, Map<string, IndexKind>>()
|
||||
|
||||
function setIndex (target: any, property: string, index: IndexKind): void {
|
||||
let indexes = targets.get(target)
|
||||
if (indexes === undefined) {
|
||||
indexes = new Map<string, IndexKind>()
|
||||
targets.set(target, indexes)
|
||||
}
|
||||
indexes.set(property, index)
|
||||
}
|
||||
|
||||
function getIndex (target: any, property: string): IndexKind | undefined {
|
||||
return targets.get(target)?.get(property)
|
||||
}
|
||||
|
||||
interface ClassTxes {
|
||||
_id: Ref<Class<Obj>>
|
||||
extends?: Ref<Class<Obj>>
|
||||
@ -77,8 +92,9 @@ export function Prop (type: Type<PropertyType>, label?: IntlString, icon?: Asset
|
||||
objectSpace: core.space.Model,
|
||||
objectClass: core.class.Attribute,
|
||||
attributes: {
|
||||
type,
|
||||
name: propertyKey,
|
||||
index: getIndex(target, propertyKey),
|
||||
type,
|
||||
label,
|
||||
icon,
|
||||
attributeOf: txes._id // undefined, need to fix later
|
||||
@ -88,6 +104,15 @@ export function Prop (type: Type<PropertyType>, label?: IntlString, icon?: Asset
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function Index (kind: IndexKind) {
|
||||
return function (target: any, propertyKey: string): void {
|
||||
setIndex(target, propertyKey, kind)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user