platform/plugins/contact-resources/src/components/CreateContact.svelte

43 lines
1.2 KiB
Svelte
Raw Normal View History

2022-04-29 05:27:17 +00:00
<script lang="ts">
import { Asset, getResource } from '@hcengineering/platform'
import { getClient } from '@hcengineering/presentation'
import { Menu, Action, showPopup, closePopup } from '@hcengineering/ui'
import view from '@hcengineering/view'
import contact from '../plugin'
const client = getClient()
const actions: Action[] = []
const hierarchy = client.getHierarchy()
2022-04-29 05:27:17 +00:00
client
.getHierarchy()
.getDescendants(contact.class.Contact)
.forEach(async (v) => {
2022-04-29 05:27:17 +00:00
const cl = hierarchy.getClass(v)
if (hierarchy.hasMixin(cl, view.mixin.ObjectFactory)) {
const { component, create } = hierarchy.as(cl, view.mixin.ObjectFactory)
let action: (() => Promise<void>) | undefined
if (component) {
action = async () => {
2022-04-29 05:27:17 +00:00
closePopup()
showPopup(component, { shouldSaveDraft: true }, 'top')
2022-04-29 05:27:17 +00:00
}
} else if (create) {
action = await getResource(create)
}
if (action) {
actions.push({
icon: cl.icon as Asset,
label: cl.label,
action
})
}
2022-04-29 05:27:17 +00:00
}
})
</script>
<Menu {actions} on:changeContent />