mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 05:07:43 +02:00
Introduce createDeps (#702)
Signed-off-by: Ilya Sumbatyants <ilya.sumb@gmail.com>
This commit is contained in:
@@ -15,10 +15,10 @@
|
||||
//
|
||||
|
||||
import type { Contact } from '@anticrm/contact'
|
||||
import { Class, Data, Doc, Ref, Space } from '@anticrm/core'
|
||||
import type { Class, Ref } from '@anticrm/core'
|
||||
import type { Asset, Plugin } from '@anticrm/platform'
|
||||
import { plugin } from '@anticrm/platform'
|
||||
import task, { CreateFn, genRanks, createKanbanTemplate, DoneState, Kanban, KanbanTemplate, KanbanTemplateSpace, SpaceWithStates, State, Task } from '@anticrm/task'
|
||||
import type { KanbanTemplateSpace, SpaceWithStates, Task } from '@anticrm/task'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -53,97 +53,7 @@ const lead = plugin(leadId, {
|
||||
},
|
||||
space: {
|
||||
FunnelTemplates: '' as Ref<KanbanTemplateSpace>
|
||||
},
|
||||
template: {
|
||||
DefaultFunnel: '' as Ref<KanbanTemplate>
|
||||
}
|
||||
})
|
||||
|
||||
export default lead
|
||||
|
||||
const defaultKanban = {
|
||||
states: [
|
||||
{ color: '#7C6FCD', title: 'Incoming' },
|
||||
{ color: '#6F7BC5', title: 'Negotation' },
|
||||
{ color: '#77C07B', title: 'Offer preparing' },
|
||||
{ color: '#A5D179', title: 'Make a decision' },
|
||||
{ color: '#F28469', title: 'Contract conclusion' },
|
||||
{ color: '#7C6FCD', title: 'Done' }
|
||||
],
|
||||
doneStates: [
|
||||
{ isWon: true, title: 'Won' },
|
||||
{ isWon: false, title: 'Lost' }
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function createKanban (
|
||||
funnelId: Ref<Funnel>,
|
||||
factory: <T extends Doc>(_class: Ref<Class<T>>, space: Ref<Space>, data: Data<T>, id: Ref<T>) => Promise<void>
|
||||
): Promise<void> {
|
||||
const { states, doneStates } = defaultKanban
|
||||
const stateRank = genRanks(states.length)
|
||||
for (const st of states) {
|
||||
const sid = (funnelId + '.state.' + st.title.toLowerCase().replace(' ', '_')) as Ref<State>
|
||||
const rank = stateRank.next().value
|
||||
|
||||
if (rank === undefined) {
|
||||
throw Error('Failed to generate rank')
|
||||
}
|
||||
|
||||
await factory(
|
||||
task.class.State,
|
||||
funnelId,
|
||||
{
|
||||
title: st.title,
|
||||
color: st.color,
|
||||
rank
|
||||
},
|
||||
sid
|
||||
)
|
||||
}
|
||||
|
||||
const doneStateRank = genRanks(doneStates.length)
|
||||
for (const st of doneStates) {
|
||||
const rank = doneStateRank.next().value
|
||||
|
||||
if (rank === undefined) {
|
||||
throw Error('Failed to generate rank')
|
||||
}
|
||||
|
||||
const sid = (funnelId + '.done-state.' + st.title.toLowerCase().replace(' ', '_')) as Ref<DoneState>
|
||||
await factory(
|
||||
st.isWon ? task.class.WonState : task.class.LostState,
|
||||
funnelId,
|
||||
{
|
||||
title: st.title,
|
||||
rank
|
||||
},
|
||||
sid
|
||||
)
|
||||
}
|
||||
|
||||
await factory(
|
||||
task.class.Kanban,
|
||||
funnelId,
|
||||
{
|
||||
attachedTo: funnelId
|
||||
},
|
||||
(funnelId + '.kanban') as Ref<Kanban>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const createDefaultKanbanTemplate = async (create: CreateFn): Promise<void> => {
|
||||
await createKanbanTemplate(create)({
|
||||
kanbanId: lead.template.DefaultFunnel,
|
||||
space: lead.space.FunnelTemplates,
|
||||
title: 'Default funnel',
|
||||
states: defaultKanban.states,
|
||||
doneStates: defaultKanban.doneStates
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import type { Person } from '@anticrm/contact'
|
||||
import type { Class, Ref, Space, Timestamp } from '@anticrm/core'
|
||||
import type { Asset, Plugin } from '@anticrm/platform'
|
||||
import { plugin } from '@anticrm/platform'
|
||||
import { CreateFn, createKanbanTemplate, KanbanTemplate, KanbanTemplateSpace, SpaceWithStates, Task } from '@anticrm/task'
|
||||
import type { KanbanTemplateSpace, SpaceWithStates, Task } from '@anticrm/task'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -79,36 +79,7 @@ const recruit = plugin(recruitId, {
|
||||
},
|
||||
space: {
|
||||
VacancyTemplates: '' as Ref<KanbanTemplateSpace>
|
||||
},
|
||||
template: {
|
||||
DefaultVacancy: '' as Ref<KanbanTemplate>
|
||||
}
|
||||
})
|
||||
|
||||
export default recruit
|
||||
|
||||
const defaultKanban = {
|
||||
states: [
|
||||
{ color: '#7C6FCD', title: 'HR Interview' },
|
||||
{ color: '#6F7BC5', title: 'Technical Interview' },
|
||||
{ color: '#77C07B', title: 'Test task' },
|
||||
{ color: '#A5D179', title: 'Offer' }
|
||||
],
|
||||
doneStates: [
|
||||
{ isWon: true, title: 'Won' },
|
||||
{ isWon: false, title: 'Lost' }
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const createDefaultKanbanTemplate = async (create: CreateFn): Promise<void> => {
|
||||
await createKanbanTemplate(create)({
|
||||
kanbanId: recruit.template.DefaultVacancy,
|
||||
space: recruit.space.VacancyTemplates,
|
||||
title: 'Default vacancy',
|
||||
states: defaultKanban.states,
|
||||
doneStates: defaultKanban.doneStates
|
||||
})
|
||||
}
|
||||
|
||||
+3
-161
@@ -17,8 +17,6 @@ import type { Employee } from '@anticrm/contact'
|
||||
import {
|
||||
AttachedDoc,
|
||||
Class,
|
||||
Client,
|
||||
Data,
|
||||
Doc,
|
||||
Interface,
|
||||
Mixin,
|
||||
@@ -223,91 +221,17 @@ const task = plugin(taskId, {
|
||||
space: {
|
||||
ProjectTemplates: '' as Ref<KanbanTemplateSpace>,
|
||||
Sequence: '' as Ref<Space>
|
||||
},
|
||||
template: {
|
||||
DefaultProject: '' as Ref<KanbanTemplate>
|
||||
}
|
||||
})
|
||||
|
||||
export default task
|
||||
|
||||
const defaultKanban = {
|
||||
states: [
|
||||
{ color: '#7C6FCD', title: 'Open' },
|
||||
{ color: '#6F7BC5', title: 'In Progress' },
|
||||
{ color: '#77C07B', title: 'Under review' },
|
||||
{ color: '#A5D179', title: 'Done' },
|
||||
{ color: '#F28469', title: 'Invalid' }
|
||||
],
|
||||
doneStates: [
|
||||
{ isWon: true, title: 'Won' },
|
||||
{ isWon: false, title: 'Lost' }
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function createProjectKanban (
|
||||
projectId: Ref<Project>,
|
||||
factory: <T extends Doc>(_class: Ref<Class<T>>, space: Ref<Space>, data: Data<T>, id: Ref<T>) => Promise<void>
|
||||
): Promise<void> {
|
||||
const { states, doneStates } = defaultKanban
|
||||
const stateRank = genRanks(states.length)
|
||||
for (const st of states) {
|
||||
const rank = stateRank.next().value
|
||||
|
||||
if (rank === undefined) {
|
||||
throw Error('Failed to generate rank')
|
||||
}
|
||||
|
||||
const sid = (projectId + '.state.' + st.title.toLowerCase().replace(' ', '_')) as Ref<State>
|
||||
await factory(
|
||||
task.class.State,
|
||||
projectId,
|
||||
{
|
||||
title: st.title,
|
||||
color: st.color,
|
||||
rank
|
||||
},
|
||||
sid
|
||||
)
|
||||
}
|
||||
|
||||
const doneStateRank = genRanks(doneStates.length)
|
||||
for (const st of doneStates) {
|
||||
const rank = doneStateRank.next().value
|
||||
|
||||
if (rank === undefined) {
|
||||
throw Error('Failed to generate rank')
|
||||
}
|
||||
|
||||
const sid = (projectId + '.done-state.' + st.title.toLowerCase().replace(' ', '_')) as Ref<DoneState>
|
||||
await factory(
|
||||
st.isWon ? task.class.WonState : task.class.LostState,
|
||||
projectId,
|
||||
{
|
||||
title: st.title,
|
||||
rank
|
||||
},
|
||||
sid
|
||||
)
|
||||
}
|
||||
|
||||
await factory(
|
||||
task.class.Kanban,
|
||||
projectId,
|
||||
{
|
||||
attachedTo: projectId
|
||||
},
|
||||
(projectId + '.kanban') as Ref<Kanban>
|
||||
)
|
||||
}
|
||||
export * from './utils'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function createKanban (
|
||||
client: Client & TxOperations,
|
||||
client: TxOperations,
|
||||
attachedTo: Ref<Space>,
|
||||
templateId?: Ref<KanbanTemplate>
|
||||
): Promise<Ref<Kanban>> {
|
||||
@@ -367,85 +291,3 @@ export async function createKanban (
|
||||
attachedTo
|
||||
})
|
||||
}
|
||||
|
||||
export * from './utils'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type CreateFn = <T extends Doc>(
|
||||
props: {
|
||||
id?: Ref<T>
|
||||
space: Ref<Space>
|
||||
class: Ref<Class<T>>
|
||||
},
|
||||
attrs: Data<T>
|
||||
) => Promise<void>
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface KanbanTemplateData {
|
||||
kanbanId: Ref<KanbanTemplate>
|
||||
space: Ref<Space>
|
||||
title: KanbanTemplate['title']
|
||||
states: Pick<StateTemplate, 'title' | 'color'>[]
|
||||
doneStates: (Pick<DoneStateTemplate, 'title'> & { isWon: boolean })[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const createKanbanTemplate = (create: CreateFn) =>
|
||||
async (data: KanbanTemplateData) => {
|
||||
await create(
|
||||
{
|
||||
id: data.kanbanId,
|
||||
space: data.space,
|
||||
class: task.class.KanbanTemplate
|
||||
},
|
||||
{
|
||||
doneStatesC: data.doneStates.length,
|
||||
statesC: data.states.length,
|
||||
title: data.title
|
||||
}
|
||||
)
|
||||
|
||||
const doneStateRanks = [...genRanks(data.doneStates.length)]
|
||||
await Promise.all(data.doneStates.map((st, i) => create({
|
||||
space: data.space,
|
||||
class: st.isWon ? task.class.WonStateTemplate : task.class.LostStateTemplate
|
||||
}, {
|
||||
attachedTo: data.kanbanId,
|
||||
attachedToClass: task.class.KanbanTemplate,
|
||||
collection: 'doneStatesC',
|
||||
rank: doneStateRanks[i],
|
||||
title: st.title
|
||||
})))
|
||||
|
||||
const stateRanks = [...genRanks(data.states.length)]
|
||||
await Promise.all(data.states.map((st, i) => create({
|
||||
space: data.space,
|
||||
class: task.class.StateTemplate
|
||||
}, {
|
||||
attachedTo: data.kanbanId,
|
||||
attachedToClass: task.class.KanbanTemplate,
|
||||
collection: 'statesC',
|
||||
rank: stateRanks[i],
|
||||
title: st.title,
|
||||
color: st.color
|
||||
})))
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const createDefaultKanbanTemplate = async (create: CreateFn): Promise<void> => {
|
||||
await createKanbanTemplate(create)({
|
||||
kanbanId: task.template.DefaultProject,
|
||||
space: task.space.ProjectTemplates,
|
||||
title: 'Default project',
|
||||
states: defaultKanban.states,
|
||||
doneStates: defaultKanban.doneStates
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user