Files
huly-platform/plugins/card-resources/src/components/CreateCardButton.svelte
T
2026-03-02 19:18:11 +07:00

55 lines
1.8 KiB
Svelte

<!--
// Copyright © 2025 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<script lang="ts">
import { Analytics } from '@hcengineering/analytics'
import { Card, CardEvents } from '@hcengineering/card'
import core, { Class, Data, Doc, fillDefaults, MarkupBlobRef, Ref } from '@hcengineering/core'
import { translate } from '@hcengineering/platform'
import { ButtonIcon, getCurrentLocation, IconAdd, navigate } from '@hcengineering/ui'
import { getClient } from '@hcengineering/presentation'
import card from '../plugin'
export let _class: Ref<Class<Doc>> | undefined
const client = getClient()
const hierarchy = client.getHierarchy()
async function createCard (): Promise<void> {
if (_class === undefined) return
const title = await translate(card.string.Card, {})
const data: Data<Card> = {
title,
rank: '',
content: '' as MarkupBlobRef,
parentInfo: [],
blobs: {}
}
const filledData = fillDefaults(hierarchy, data, _class)
const _id = await client.createDoc(_class, core.space.Workspace, filledData)
Analytics.handleEvent(CardEvents.CardCreated)
const loc = getCurrentLocation()
loc.path[3] = _id
loc.path.length = 4
navigate(loc)
}
</script>
<ButtonIcon kind="primary" icon={IconAdd} size="small" dataId={'btnCreateCard'} on:click={createCard} />