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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@
<script lang="ts"> <script lang="ts">
import { createEventDispatcher } from 'svelte' 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 { getResource } from '@anticrm/platform'
import { buildModel } from '../utils' import { buildModel } from '../utils'
import { getClient } from '@anticrm/presentation' import { getClient } from '@anticrm/presentation'
@ -81,7 +81,13 @@
const txes: TxCUD<Doc>[] = [] const txes: TxCUD<Doc>[] = []
if (dragCardInitialState !== state) { 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 })) // 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({ result.push({
attachedTo: (kid as HTMLElement).getAttribute('data-id') as Ref<Doc>, attachedTo: (kid as HTMLElement).getAttribute('data-id') as Ref<Doc>,
attachedToClass: (kid as HTMLElement).getAttribute('data-class') as Ref<Class<Doc>>, attachedToClass: (kid as HTMLElement).getAttribute('data-class') as Ref<Class<Doc>>,
collection: (kid as HTMLElement).getAttribute('data-collection') ?? '',
backlinkId, backlinkId,
backlinkClass: chunter.class.Message, backlinkClass: chunter.class.Message,
message message

File diff suppressed because it is too large Load Diff