Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions foundations/core/packages/core/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface Association extends Doc {
nameA: string
nameB: string
type: '1:1' | '1:N' | 'N:N'
automationOnly?: boolean
}

/**
Expand Down
2 changes: 2 additions & 0 deletions models/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export class TAssociation extends TDoc implements Association {
nameB!: string

type!: '1:1' | '1:N' | 'N:N'

automationOnly?: boolean
}

@Model(core.class.Relation, core.class.Doc, DOMAIN_RELATION)
Expand Down
18 changes: 15 additions & 3 deletions plugins/setting-resources/src/components/AssociationEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
DropdownLabelsIntl,
EditBox,
Label,
NestedDropdown
NestedDropdown,
Toggle
} from '@hcengineering/ui'
import view from '@hcengineering/view'
import card from '@hcengineering/card'
Expand Down Expand Up @@ -96,6 +97,7 @@
let classBRef: Ref<Class<Doc>> | undefined = undefined
let nameA = association.nameA
let nameB = association.nameB
let automationOnly = association.automationOnly ?? false

$: classA = isEmptyClass(classARef) ? undefined : hierarchy.getClass(classARef as Ref<Class<Doc>>)
$: classB = isEmptyClass(classBRef) ? undefined : hierarchy.getClass(classBRef as Ref<Class<Doc>>)
Expand All @@ -113,6 +115,7 @@
classARef = !isEmptyClass(association.classA) ? association.classA : undefined
nameA = association.nameA
nameB = association.nameB
automationOnly = association.automationOnly ?? false
}

function isAssociation (data: Data<Association> | Association): data is Association {
Expand All @@ -128,15 +131,17 @@
if (association !== undefined && isAssociation(association)) {
await client.diffUpdate(association, {
nameA,
nameB
nameB,
automationOnly
})
} else {
await client.createDoc(core.class.Association, core.space.Model, {
classA: classARef,
classB: classBRef,
type: mode,
nameA,
nameB
nameB,
automationOnly
})
dispatch('create')
dispatch('close')
Expand Down Expand Up @@ -224,6 +229,13 @@
{/if}
</div>
</div>

<div class="flex-col p-4 flex-gap-2">
<span class="label">
<Label label={view.string.AutomationOnly} />
</span>
<Toggle bind:on={automationOnly} />
</div>
</div>

<div class="flex-col-reverse">
Expand Down
13 changes: 11 additions & 2 deletions plugins/setting-resources/src/components/CreateRelation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import core, { Class, Doc, Ref } from '@hcengineering/core'
import { getEmbeddedLabel } from '@hcengineering/platform'
import presentation, { Card, getClient } from '@hcengineering/presentation'
import { DropdownIntlItem, DropdownLabelsIntl, EditBox, Label, NestedDropdown } from '@hcengineering/ui'
import { DropdownIntlItem, DropdownLabelsIntl, EditBox, Label, NestedDropdown, Toggle } from '@hcengineering/ui'
import view from '@hcengineering/view'
import { createEventDispatcher } from 'svelte'
import setting from '../plugin'
Expand Down Expand Up @@ -96,6 +96,7 @@
let classBRef: Ref<Class<Doc>> | undefined = undefined
let nameA: string = ''
let nameB: string = ''
let automationOnly = false

async function save (): Promise<void> {
if (classBRef === undefined || classARef === undefined) {
Expand All @@ -106,7 +107,8 @@
classB: classBRef,
type: mode,
nameA,
nameB
nameB,
automationOnly
})
dispatch('close', _id)
}
Expand Down Expand Up @@ -200,5 +202,12 @@
/>
</div>
</div>

<div class="flex p-4 flex-gap-2">
<span class="label">
<Label label={view.string.AutomationOnly} />
</span>
<Toggle bind:on={automationOnly} />
</div>
</div>
</Card>
12 changes: 10 additions & 2 deletions plugins/setting-resources/src/components/EditRelation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import core, { Association } from '@hcengineering/core'
import { getEmbeddedLabel, IntlString } from '@hcengineering/platform'
import presentation, { getClient, MessageBox } from '@hcengineering/presentation'
import { Button, DropdownIntlItem, EditBox, IconDelete, Label, Modal, showPopup } from '@hcengineering/ui'
import { Button, DropdownIntlItem, EditBox, IconDelete, Label, Modal, showPopup, Toggle } from '@hcengineering/ui'
import view from '@hcengineering/view'
import setting from '../plugin'
import { clearSettingsStore } from '../store'
Expand All @@ -30,11 +30,13 @@
const classB = hierarchy.getClass(association.classB)
let nameA = association.nameA
let nameB = association.nameB
let automationOnly = association.automationOnly ?? false

async function save (): Promise<void> {
await client.diffUpdate(association, {
nameA,
nameB
nameB,
automationOnly
})
clearSettingsStore()
}
Expand Down Expand Up @@ -108,5 +110,11 @@
</div>
</div>
</div>
<div class="flex-between p-4 flex-gap-2">
<span class="label">
<Label label={view.string.AutomationOnly} />
</span>
<Toggle bind:on={automationOnly} />
</div>
</div>
</Modal>
18 changes: 12 additions & 6 deletions plugins/view-resources/src/components/RelationEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,23 @@
: { docA: doc._id, docB: object._id, association: association._id }
const relation = await client.findOne(core.class.Relation, q)
const overrides = new Map()
const excludedActions: string[] = []
if (relation !== undefined) {
overrides.set(view.action.Delete, async (obj: Doc | Doc[], ev?: Event) => {
if (relation !== undefined) {
await client.remove(relation)
}
})
if (association.automationOnly) {
excludedActions.push(view.action.Delete)
} else {
overrides.set(view.action.Delete, async (obj: Doc | Doc[], ev?: Event) => {
if (relation !== undefined) {
await client.remove(relation)
}
})
}
}
showMenu(ev, { object: doc, overrides })
showMenu(ev, { object: doc, overrides, excludedActions })
}

function isAllowedToCreate (association: Association, docs: Doc[], direction: 'A' | 'B'): boolean {
if (association.automationOnly) return false
if (docs.length === 0 || association.type === 'N:N') return true
if (association.type === '1:1') return false
return direction === 'B'
Expand Down
Loading