Fix collection operations

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2021-11-17 15:47:30 +07:00
parent b6fac06d2b
commit a446e3f799
No known key found for this signature in database
GPG Key ID: BD80F68D68D8F7F2
14 changed files with 969 additions and 965 deletions

View File

@ -28,6 +28,7 @@ function extractBacklinks (backlinkId: Ref<Doc>, message: string, kids: NodeList
result.push({
attachedTo: kid.getAttribute('data-id') as Ref<Doc>,
attachedToClass: kid.getAttribute('data-class') as Ref<Class<Doc>>,
collection: kid.getAttribute('data-collection') ?? '',
backlinkId,
backlinkClass: chunter.class.Message,
message

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ import type { IntlString } from '@anticrm/platform'
import { Builder, Model, Prop, UX, TypeString, Index, TypeTimestamp } 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 core, { TSpace, TDoc, TAttachedDoc } from '@anticrm/model-core'
import type { Backlink, Channel, Message, Comment, Attachment } from '@anticrm/chunter'
import type { AnyComponent } from '@anticrm/ui'
@ -42,9 +42,7 @@ export class TMessage extends TDoc implements Message {
}
@Model(chunter.class.Comment, core.class.Doc, DOMAIN_COMMENT)
export class TComment extends TDoc implements Comment {
attachedTo!: Ref<Doc>
attachedToClass!: Ref<Class<Doc>>
export class TComment extends TAttachedDoc implements Comment {
@Prop(TypeString(), 'Message' as IntlString)
@Index(IndexKind.FullText)
message!: string
@ -58,9 +56,7 @@ export class TBacklink extends TComment implements Backlink {
@Model(chunter.class.Attachment, core.class.Doc, DOMAIN_ATTACHMENT)
@UX('File' as IntlString)
export class TAttachment extends TDoc implements Attachment {
attachedTo!: Ref<Doc>
attachedToClass!: Ref<Class<Doc>>
export class TAttachment extends TAttachedDoc implements Attachment {
@Prop(TypeString(), 'Name' as IntlString)
name!: string

View File

@ -40,6 +40,7 @@ export class TDoc extends TObj implements Doc {
export class TAttachedDoc extends TDoc implements AttachedDoc {
attachedTo!: Ref<Doc>
attachedToClass!: Ref<Class<Doc>>
collection!: string
}
@Model(core.class.Class, core.class.Doc, DOMAIN_MODEL)

View File

@ -47,7 +47,7 @@ export class TState extends TDoc implements State {
color!: string
}
@Model(core.class.DocWithState, core.class.Doc)
@Model(core.class.DocWithState, core.class.AttachedDoc)
export class TDocWithState extends TDoc {
@Prop(TypeString(), 'State' as IntlString)
state!: Ref<State>

View File

@ -62,6 +62,7 @@ export class TApplicant extends TDocWithState implements Applicant {
attachedTo!: Ref<Candidate>
attachedToClass!: Ref<Class<Candidate>>
collection!: string
@Prop(TypeString(), 'Attachments' as IntlString)
attachments?: number

View File

@ -67,6 +67,7 @@ export interface UXObject extends Obj {
export interface AttachedDoc extends Doc {
attachedTo: Ref<Doc>
attachedToClass: Ref<Class<Doc>>
collection: string
}
/**

View File

@ -238,7 +238,8 @@ export abstract class TxProcessor implements WithTx {
attributes: {
...createTx.attributes,
attachedTo: tx.objectId,
attachedToClass: tx.objectClass
attachedToClass: tx.objectClass,
collection: tx.collection
}
}
return this.txCreateDoc(d)
@ -310,10 +311,10 @@ export class TxOperations implements Storage {
async updateCollection<T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
objectId: Ref<P>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: string,
objectId: Ref<P>,
operations: DocumentUpdate<P>
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCollectionCUD(

View File

@ -15,13 +15,13 @@
-->
<script lang="ts">
import type { IntlString, Asset } from '@anticrm/platform'
import type { Asset } from '@anticrm/platform'
import type { Doc } from '@anticrm/core'
import { SortingOrder } from '@anticrm/core'
import { getClient, createQuery, Backlink } from '@anticrm/presentation'
import type { AnySvelteComponent } from '@anticrm/ui'
import { ReferenceInput } from '@anticrm/text-editor'
import { IconClose, IconExpand, IconActivity, ScrollBox, Grid, Label, Icon, IconToDo } from '@anticrm/ui'
import { IconClose, IconExpand, IconActivity, ScrollBox, Grid, Icon, IconToDo } from '@anticrm/ui'
import type { Comment } from '@anticrm/chunter'
import ActivityMsg from './ActivityMsg.svelte'
@ -43,9 +43,7 @@
$: query.query(chunter.class.Comment, { attachedTo: object._id }, result => { comments = result }, { sort: { modifiedOn: SortingOrder.Descending } })
function onMessage(event: CustomEvent) {
client.createDoc(chunter.class.Comment, object.space, {
attachedTo: object._id,
attachedToClass: object._class,
client.addCollection(chunter.class.Comment, object.space, object._id, object._class, 'comments', {
message: event.detail
})
console.log(event.detail)

View File

@ -75,9 +75,7 @@
console.log('resume name', resume.name)
if (resume.uuid !== undefined) {
client.createDoc(chunter.class.Attachment, space, {
attachedTo: id,
attachedToClass: recruit.class.Candidate,
client.addCollection(chunter.class.Attachment, space, id, recruit.class.Candidate, 'attachments', {
name: resume.name,
file: resume.uuid,
size: resume.size,

View File

@ -16,7 +16,7 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte'
import type { Ref, Class, Doc, Space, SpaceWithStates, FindOptions, State, TxBulkWrite, TxCUD } from '@anticrm/core'
import type { Ref, Class, Doc, Space, SpaceWithStates, FindOptions, State, TxBulkWrite, TxCUD, AttachedDoc } from '@anticrm/core'
import { getResource } from '@anticrm/platform'
import { buildModel } from '../utils'
import { getClient } from '@anticrm/presentation'
@ -81,7 +81,13 @@
const txes: TxCUD<Doc>[] = []
if (dragCardInitialState !== state) {
client.updateDoc(_class, space, id, { state })
if (client.getHierarchy().isDerived(_class, core.class.AttachedDoc)) {
const adoc: AttachedDoc = dragCard as AttachedDoc
// We need to update using updateCollection
client.updateCollection(_class, space, id as Ref<AttachedDoc>, adoc.attachedTo, adoc.attachedToClass, adoc.collection, { state })
} else {
client.updateDoc(_class, space, id, { state })
}
// txes.push(client.txFactory.createTxUpdateDoc(_class, space, id, { state }))
}

View File

@ -29,6 +29,7 @@ function extractBacklinks (backlinkId: Ref<Doc>, message: string, kids: Node[]):
result.push({
attachedTo: (kid as HTMLElement).getAttribute('data-id') as Ref<Doc>,
attachedToClass: (kid as HTMLElement).getAttribute('data-class') as Ref<Class<Doc>>,
collection: (kid as HTMLElement).getAttribute('data-collection') ?? '',
backlinkId,
backlinkClass: chunter.class.Message,
message

File diff suppressed because it is too large Load Diff