2021-12-14 09:24:14 +00:00
|
|
|
import core, { DoneState, Ref, SpaceWithStates, State, TxOperations } from '@anticrm/core'
|
2021-12-10 09:47:54 +00:00
|
|
|
import { findOrUpdate } from './utils'
|
|
|
|
import view, { Kanban } from '@anticrm/view'
|
|
|
|
|
|
|
|
export async function createUpdateSpaceKanban (spaceId: Ref<SpaceWithStates>, client: TxOperations): Promise<Ref<State>[]> {
|
2021-12-14 09:24:14 +00:00
|
|
|
const rawStates = [
|
2021-12-10 09:47:54 +00:00
|
|
|
{ color: '#7C6FCD', name: 'Initial' },
|
|
|
|
{ color: '#6F7BC5', name: 'Intermidiate' },
|
|
|
|
{ color: '#77C07B', name: 'OverIntermidiate' },
|
|
|
|
{ color: '#A5D179', name: 'Done' },
|
|
|
|
{ color: '#F28469', name: 'Invalid' }
|
|
|
|
]
|
2021-12-14 09:24:14 +00:00
|
|
|
const states: Array<Ref<State>> = []
|
|
|
|
for (const st of rawStates) {
|
2021-12-10 09:47:54 +00:00
|
|
|
const sid = ('generated-' + spaceId + '.state.' + st.name.toLowerCase().replace(' ', '_')) as Ref<State>
|
|
|
|
await findOrUpdate(client, spaceId, core.class.State,
|
|
|
|
sid,
|
|
|
|
{
|
|
|
|
title: st.name,
|
|
|
|
color: st.color
|
|
|
|
}
|
|
|
|
)
|
2021-12-14 09:24:14 +00:00
|
|
|
states.push(sid)
|
|
|
|
}
|
|
|
|
|
|
|
|
const rawDoneStates = [
|
|
|
|
{ class: core.class.WonState, title: 'Won' },
|
|
|
|
{ class: core.class.LostState, title: 'Lost' }
|
|
|
|
]
|
|
|
|
const doneStates: Array<Ref<DoneState>> = []
|
|
|
|
for (const st of rawDoneStates) {
|
|
|
|
const sid = ('generated-' + spaceId + '.done-state.' + st.title.toLowerCase().replace(' ', '_')) as Ref<DoneState>
|
|
|
|
await findOrUpdate(client, spaceId, st.class,
|
|
|
|
sid,
|
|
|
|
{
|
|
|
|
title: st.title
|
|
|
|
}
|
|
|
|
)
|
|
|
|
doneStates.push(sid)
|
2021-12-10 09:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await findOrUpdate(client, spaceId,
|
|
|
|
view.class.Kanban,
|
|
|
|
('generated-' + spaceId + '.kanban') as Ref<Kanban>,
|
|
|
|
{
|
|
|
|
attachedTo: spaceId,
|
2021-12-14 09:24:14 +00:00
|
|
|
states,
|
|
|
|
doneStates,
|
2021-12-10 09:47:54 +00:00
|
|
|
order: []
|
|
|
|
}
|
|
|
|
)
|
2021-12-14 09:24:14 +00:00
|
|
|
return states
|
2021-12-10 09:47:54 +00:00
|
|
|
}
|