mirror of
https://github.com/hcengineering/platform.git
synced 2025-03-15 02:23:12 +00:00
more card fixes (#8077)
This commit is contained in:
parent
ce10156fe4
commit
355025d56a
models/server-card/src
packages/query/src
plugins
server-plugins
server/middleware/src
@ -32,6 +32,15 @@ export function createModel (builder: Builder): void {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||||
|
trigger: serverCard.trigger.OnAttributeRemove,
|
||||||
|
isAsync: true,
|
||||||
|
txMatch: {
|
||||||
|
_class: core.class.TxRemoveDoc,
|
||||||
|
objectClass: core.class.Attribute
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||||
trigger: serverCard.trigger.OnMasterTagRemove,
|
trigger: serverCard.trigger.OnMasterTagRemove,
|
||||||
isAsync: true,
|
isAsync: true,
|
||||||
|
@ -760,7 +760,7 @@ export class LiveQuery implements WithTx, Client {
|
|||||||
}
|
}
|
||||||
const docs = q.result.getDocs()
|
const docs = q.result.getDocs()
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
const docToUpdate = doc.$associations?.[association._id].find((it) => it._id === tx.objectId)
|
const docToUpdate = doc.$associations?.[association._id]?.find((it) => it._id === tx.objectId)
|
||||||
if (docToUpdate !== undefined) {
|
if (docToUpdate !== undefined) {
|
||||||
if (tx._class === core.class.TxMixin) {
|
if (tx._class === core.class.TxMixin) {
|
||||||
TxProcessor.updateMixin4Doc(docToUpdate, tx as TxMixin<Doc, Doc>)
|
TxProcessor.updateMixin4Doc(docToUpdate, tx as TxMixin<Doc, Doc>)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { MasterTag } from '@hcengineering/card'
|
import { MasterTag } from '@hcengineering/card'
|
||||||
import { Ref } from '@hcengineering/core'
|
import core, { Ref } from '@hcengineering/core'
|
||||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||||
import {
|
import {
|
||||||
BreadcrumbItem,
|
BreadcrumbItem,
|
||||||
@ -46,7 +46,7 @@
|
|||||||
const hierarchy = client.getHierarchy()
|
const hierarchy = client.getHierarchy()
|
||||||
|
|
||||||
const query = createQuery()
|
const query = createQuery()
|
||||||
$: query.query(card.class.MasterTag, { _id: selectedTagId }, (res) => {
|
$: query.query(core.class.Class, { _id: selectedTagId }, (res) => {
|
||||||
masterTag = res[0]
|
masterTag = res[0]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ export * from './analytics'
|
|||||||
|
|
||||||
export interface MasterTag extends Class<Card> {}
|
export interface MasterTag extends Class<Card> {}
|
||||||
|
|
||||||
export interface Tag extends Mixin<Card> {}
|
export interface Tag extends MasterTag, Mixin<Card> {}
|
||||||
|
|
||||||
export interface Card extends Doc {
|
export interface Card extends Doc {
|
||||||
attachments?: number
|
attachments?: number
|
||||||
|
@ -34,9 +34,41 @@ async function OnAttribute (ctx: TxCreateDoc<AnyAttribute>[], control: TriggerCo
|
|||||||
)
|
)
|
||||||
const prefs = await control.findAll(control.ctx, view.class.ViewletPreference, { attachedTo: viewlet._id })
|
const prefs = await control.findAll(control.ctx, view.class.ViewletPreference, { attachedTo: viewlet._id })
|
||||||
for (const pref of prefs) {
|
for (const pref of prefs) {
|
||||||
|
pref.config.push(attr.name)
|
||||||
res.push(
|
res.push(
|
||||||
control.txFactory.createTxUpdateDoc(pref._class, pref.space, pref._id, {
|
control.txFactory.createTxUpdateDoc(pref._class, pref.space, pref._id, {
|
||||||
config: viewlet.config
|
config: pref.config
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
async function OnAttributeRemove (ctx: TxRemoveDoc<AnyAttribute>[], control: TriggerControl): Promise<Tx[]> {
|
||||||
|
const attr = control.removedMap.get(ctx[0].objectId) as AnyAttribute
|
||||||
|
if (attr === undefined) return []
|
||||||
|
if (control.hierarchy.isDerived(attr.attributeOf, card.class.Card)) {
|
||||||
|
const desc = control.hierarchy.getDescendants(attr.attributeOf)
|
||||||
|
const res: Tx[] = []
|
||||||
|
for (const des of desc) {
|
||||||
|
const viewlets = control.modelDb.findAllSync(view.class.Viewlet, { attachTo: des })
|
||||||
|
for (const viewlet of viewlets) {
|
||||||
|
viewlet.config = viewlet.config.filter((p) => p !== attr.name)
|
||||||
|
res.push(
|
||||||
|
control.txFactory.createTxUpdateDoc(viewlet._class, viewlet.space, viewlet._id, {
|
||||||
|
config: viewlet.config
|
||||||
|
})
|
||||||
|
)
|
||||||
|
const prefs = await control.findAll(control.ctx, view.class.ViewletPreference, { attachedTo: viewlet._id })
|
||||||
|
for (const pref of prefs) {
|
||||||
|
pref.config = pref.config.filter((p) => p !== attr.name)
|
||||||
|
res.push(
|
||||||
|
control.txFactory.createTxUpdateDoc(pref._class, pref.space, pref._id, {
|
||||||
|
config: pref.config
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -72,6 +104,7 @@ async function OnMasterTagRemove (ctx: TxRemoveDoc<MasterTag>[], control: Trigge
|
|||||||
export default async () => ({
|
export default async () => ({
|
||||||
trigger: {
|
trigger: {
|
||||||
OnAttribute,
|
OnAttribute,
|
||||||
|
OnAttributeRemove,
|
||||||
OnMasterTagRemove
|
OnMasterTagRemove
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -28,6 +28,7 @@ export const serverCardId = 'server-card' as Plugin
|
|||||||
export default plugin(serverCardId, {
|
export default plugin(serverCardId, {
|
||||||
trigger: {
|
trigger: {
|
||||||
OnAttribute: '' as Resource<TriggerFunc>,
|
OnAttribute: '' as Resource<TriggerFunc>,
|
||||||
|
OnAttributeRemove: '' as Resource<TriggerFunc>,
|
||||||
OnMasterTagRemove: '' as Resource<TriggerFunc>
|
OnMasterTagRemove: '' as Resource<TriggerFunc>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import core, {
|
import core, {
|
||||||
Domain,
|
Domain,
|
||||||
|
DOMAIN_MODEL,
|
||||||
groupByArray,
|
groupByArray,
|
||||||
TxProcessor,
|
TxProcessor,
|
||||||
withContext,
|
withContext,
|
||||||
@ -86,20 +87,29 @@ export class DomainTxMiddleware extends BaseMiddleware implements Middleware {
|
|||||||
const deleteByDomain = groupByArray(toDelete, (it) => this.context.hierarchy.getDomain(it.objectClass))
|
const deleteByDomain = groupByArray(toDelete, (it) => this.context.hierarchy.getDomain(it.objectClass))
|
||||||
|
|
||||||
for (const [domain, domainTxes] of deleteByDomain.entries()) {
|
for (const [domain, domainTxes] of deleteByDomain.entries()) {
|
||||||
const todel = await ctx.with(
|
if (domain === DOMAIN_MODEL) {
|
||||||
'adapter-load',
|
for (const tx of domainTxes) {
|
||||||
{},
|
const ddoc = this.context.modelDb.findObject(tx.objectId)
|
||||||
() =>
|
if (ddoc !== undefined) {
|
||||||
adapter.load(
|
ctx.contextData.removedMap.set(ddoc._id, ddoc)
|
||||||
ctx,
|
}
|
||||||
domain,
|
}
|
||||||
domainTxes.map((it) => it.objectId)
|
} else {
|
||||||
),
|
const todel = await ctx.with(
|
||||||
{ count: toDelete.length }
|
'adapter-load',
|
||||||
)
|
{},
|
||||||
|
() =>
|
||||||
|
adapter.load(
|
||||||
|
ctx,
|
||||||
|
domain,
|
||||||
|
domainTxes.map((it) => it.objectId)
|
||||||
|
),
|
||||||
|
{ count: toDelete.length }
|
||||||
|
)
|
||||||
|
|
||||||
for (const ddoc of todel) {
|
for (const ddoc of todel) {
|
||||||
ctx.contextData.removedMap.set(ddoc._id, ddoc)
|
ctx.contextData.removedMap.set(ddoc._id, ddoc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user