delete status

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-10-26 12:15:04 +02:00
parent 33356bfc61
commit 9ef7399bd6
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
3 changed files with 39 additions and 5 deletions

View File

@ -15,7 +15,7 @@
--> -->
<script lang="ts"> <script lang="ts">
import type { Ref, SpaceWithStates, State } from '@anticrm/core' import type { Ref, SpaceWithStates, State, Class, Obj } from '@anticrm/core'
import { CircleButton, IconAdd, Label, IconMoreH, ActionIcon, showPopup, ScrollBox } from '@anticrm/ui' import { CircleButton, IconAdd, Label, IconMoreH, ActionIcon, showPopup, ScrollBox } from '@anticrm/ui'
import { createQuery, getClient, AttributeEditor } from '@anticrm/presentation' import { createQuery, getClient, AttributeEditor } from '@anticrm/presentation'
import type { Kanban } from '@anticrm/view' import type { Kanban } from '@anticrm/view'
@ -30,6 +30,7 @@
import view from '@anticrm/view' import view from '@anticrm/view'
export let _id: Ref<SpaceWithStates> export let _id: Ref<SpaceWithStates>
export let spaceClass: Ref<Class<Obj>>
let kanban: Kanban | undefined let kanban: Kanban | undefined
@ -147,7 +148,7 @@
<div class="flex-grow caption-color"><AttributeEditor maxWidth="20rem" _class={core.class.State} object={state} key="title"/></div> <div class="flex-grow caption-color"><AttributeEditor maxWidth="20rem" _class={core.class.State} object={state} key="title"/></div>
<div class="tool hover-trans" <div class="tool hover-trans"
on:click={(ev) => { on:click={(ev) => {
showPopup(StatusesPopup, {}, ev.target, (result) => { if (result) console.log('StatusesPopup:', result) }) showPopup(StatusesPopup, { state, spaceClass }, ev.target, (result) => { if (result) console.log('StatusesPopup:', result) })
}} }}
> >
<IconMoreH size={'medium'} /> <IconMoreH size={'medium'} />

View File

@ -15,15 +15,48 @@
<script lang="ts"> <script lang="ts">
// import type { IntlString, Asset, Resource } from '@anticrm/platform' // import type { IntlString, Asset, Resource } from '@anticrm/platform'
import type { Ref, State, Class, Obj } from '@anticrm/core'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import { Label } from '@anticrm/ui' import { Label, showPopup } from '@anticrm/ui'
import { getClient, MessageBox } from '@anticrm/presentation'
import Delete from './icons/Delete.svelte' import Delete from './icons/Delete.svelte'
import workbench from '@anticrm/workbench'
export let state: State
export let spaceClass: Ref<Class<Obj>>
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const client = getClient()
async function deleteState() {
const spaceClassInstance = client.getHierarchy().getClass(spaceClass)
const view = client.getHierarchy().as(spaceClassInstance, workbench.mixin.SpaceView)
const containingClass = view.view.class
const objectsInThisState = await client.findAll(containingClass, { state: state._id })
if (objectsInThisState.length > 0) {
showPopup(MessageBox, {
label: 'Can\'t delete status',
message: `There are ${objectsInThisState.length} objects in the given state. Move or delete them first.`
})
} else {
showPopup(MessageBox, {
label: 'Delete status',
message: 'Do you want to delete this status?'
}, undefined, (result) => {
if (result) {
client.removeDoc(state._class, state.space, state._id)
}
})
}
}
</script> </script>
<div class="flex-col popup"> <div class="flex-col popup">
<div class="flex-row-center red-color menu-item" on:click={() => { dispatch('close', 'delete') }}> <div class="flex-row-center red-color menu-item" on:click={() => { dispatch('close'); deleteState() }}>
<div class="icon"> <div class="icon">
<Delete size={'medium'} /> <Delete size={'medium'} />
</div> </div>

View File

@ -52,7 +52,7 @@
label: 'Edit Statuses' as IntlString, label: 'Edit Statuses' as IntlString,
icon: IconAdd, icon: IconAdd,
action: async (_id: Ref<Doc>): Promise<void> => { action: async (_id: Ref<Doc>): Promise<void> => {
showPopup(EditStatuses, { _id }, 'right') showPopup(EditStatuses, { _id, spaceClass: model.spaceClass }, 'right')
} }
} }