mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 12:35:02 +02:00
UBER-1053 (#3884)
This commit is contained in:
+31
-98
@@ -19,12 +19,12 @@ import {
|
||||
Attribute,
|
||||
Class,
|
||||
Doc,
|
||||
Interface,
|
||||
Markup,
|
||||
Mixin,
|
||||
Ref,
|
||||
Space,
|
||||
Status,
|
||||
StatusCategory,
|
||||
Timestamp
|
||||
} from '@hcengineering/core'
|
||||
import { NotificationType } from '@hcengineering/notification'
|
||||
@@ -40,45 +40,16 @@ export interface DocWithRank extends Doc {
|
||||
rank: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface SpaceWithStates extends Space {
|
||||
templateId?: Ref<KanbanTemplate>
|
||||
states: Ref<State>[]
|
||||
doneStates?: Ref<DoneState>[]
|
||||
export interface Project extends Space {
|
||||
type: Ref<ProjectType>
|
||||
}
|
||||
|
||||
// S T A T E
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface State extends Status {
|
||||
isArchived?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface DoneState extends Status {}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface WonState extends DoneState {}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface LostState extends DoneState {}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface Task extends AttachedDoc, DocWithRank {
|
||||
status: Ref<Status>
|
||||
doneState: Ref<DoneState> | null
|
||||
isDone?: boolean
|
||||
number: number
|
||||
assignee: Ref<Person> | null
|
||||
dueDate: Timestamp | null
|
||||
@@ -114,54 +85,26 @@ export interface Sequence extends Doc {
|
||||
sequence: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface StateTemplate extends Doc, State {
|
||||
attachedTo: Ref<KanbanTemplate>
|
||||
rank: string
|
||||
export interface ProjectStatus {
|
||||
_id: Ref<Status>
|
||||
// Optional color
|
||||
color?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface DoneStateTemplate extends Doc, DoneState {
|
||||
attachedTo: Ref<KanbanTemplate>
|
||||
rank: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface WonStateTemplate extends DoneStateTemplate, WonState {}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface LostStateTemplate extends DoneStateTemplate, LostState {}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface KanbanTemplate extends Doc {
|
||||
title: string
|
||||
description?: string
|
||||
export interface ProjectType extends Space {
|
||||
shortDescription?: string
|
||||
statesC: number
|
||||
doneStatesC: number
|
||||
category: Ref<ProjectTypeCategory>
|
||||
statuses: ProjectStatus[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface KanbanTemplateSpace extends Space {
|
||||
export interface ProjectTypeCategory extends Doc {
|
||||
name: IntlString
|
||||
description: IntlString
|
||||
icon: AnyComponent
|
||||
ofAttribute: Ref<Attribute<State>>
|
||||
doneAttribute?: Ref<Attribute<DoneState>>
|
||||
editor?: AnyComponent
|
||||
attachedToClass: Ref<Class<SpaceWithStates>>
|
||||
attachedToClass: Ref<Class<Project>>
|
||||
statusClass: Ref<Class<Status>>
|
||||
statusCategories: Ref<StatusCategory>[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +112,6 @@ export interface KanbanTemplateSpace extends Space {
|
||||
*/
|
||||
export enum TaskGrouping {
|
||||
State = 'state',
|
||||
DoneStatus = 'doneState',
|
||||
Assignee = 'assignee',
|
||||
NoGrouping = '#no_category'
|
||||
}
|
||||
@@ -202,12 +144,8 @@ const task = plugin(taskId, {
|
||||
mixin: {
|
||||
KanbanCard: '' as Ref<Mixin<KanbanCard>>
|
||||
},
|
||||
interface: {
|
||||
DocWithRank: '' as Ref<Interface<DocWithRank>>
|
||||
},
|
||||
attribute: {
|
||||
State: '' as Ref<Attribute<State>>,
|
||||
DoneState: '' as Ref<Attribute<DoneState>>
|
||||
State: '' as Ref<Attribute<Status>>
|
||||
},
|
||||
string: {
|
||||
StartDate: '' as IntlString,
|
||||
@@ -223,9 +161,6 @@ const task = plugin(taskId, {
|
||||
IssueName: '' as IntlString,
|
||||
TaskComments: '' as IntlString,
|
||||
TaskLabels: '' as IntlString,
|
||||
StateTemplateTitle: '' as IntlString,
|
||||
StateTemplateColor: '' as IntlString,
|
||||
KanbanTemplateTitle: '' as IntlString,
|
||||
Rank: '' as IntlString,
|
||||
EditStates: '' as IntlString,
|
||||
MarkAsDone: '' as IntlString,
|
||||
@@ -234,23 +169,17 @@ const task = plugin(taskId, {
|
||||
ApplicationLabelTask: '' as IntlString,
|
||||
TodoItems: '' as IntlString,
|
||||
AssignedToMe: '' as IntlString,
|
||||
Dashboard: '' as IntlString
|
||||
Dashboard: '' as IntlString,
|
||||
ProjectTypes: '' as IntlString,
|
||||
ProjectType: '' as IntlString
|
||||
},
|
||||
class: {
|
||||
State: '' as Ref<Class<State>>,
|
||||
DoneState: '' as Ref<Class<DoneState>>,
|
||||
WonState: '' as Ref<Class<WonState>>,
|
||||
LostState: '' as Ref<Class<LostState>>,
|
||||
SpaceWithStates: '' as Ref<Class<SpaceWithStates>>,
|
||||
Task: '' as Ref<Class<Task>>,
|
||||
Sequence: '' as Ref<Class<Sequence>>,
|
||||
StateTemplate: '' as Ref<Class<StateTemplate>>,
|
||||
DoneStateTemplate: '' as Ref<Class<DoneStateTemplate>>,
|
||||
WonStateTemplate: '' as Ref<Class<WonStateTemplate>>,
|
||||
LostStateTemplate: '' as Ref<Class<LostStateTemplate>>,
|
||||
KanbanTemplate: '' as Ref<Class<KanbanTemplate>>,
|
||||
KanbanTemplateSpace: '' as Ref<Class<KanbanTemplateSpace>>,
|
||||
TodoItem: '' as Ref<Class<TodoItem>>
|
||||
TodoItem: '' as Ref<Class<TodoItem>>,
|
||||
ProjectType: '' as Ref<Class<ProjectType>>,
|
||||
ProjectTypeCategory: '' as Ref<Class<ProjectTypeCategory>>,
|
||||
Project: '' as Ref<Class<Project>>
|
||||
},
|
||||
viewlet: {
|
||||
Kanban: '' as Ref<ViewletDescriptor>,
|
||||
@@ -274,12 +203,16 @@ const task = plugin(taskId, {
|
||||
Sequence: '' as Ref<Space>,
|
||||
Statuses: '' as Ref<Space>
|
||||
},
|
||||
statusCategory: {
|
||||
Active: '' as Ref<StatusCategory>,
|
||||
Won: '' as Ref<StatusCategory>,
|
||||
Lost: '' as Ref<StatusCategory>
|
||||
},
|
||||
component: {
|
||||
KanbanTemplateEditor: '' as AnyComponent,
|
||||
KanbanTemplateSelector: '' as AnyComponent,
|
||||
ProjectEditor: '' as AnyComponent,
|
||||
ProjectTypeSelector: '' as AnyComponent,
|
||||
TodoItemsPopup: '' as AnyComponent,
|
||||
CreateStatePopup: '' as AnyComponent,
|
||||
CreateStateTemplatePopup: '' as AnyComponent
|
||||
CreateStatePopup: '' as AnyComponent
|
||||
},
|
||||
ids: {
|
||||
AssigneedNotification: '' as Ref<NotificationType>
|
||||
|
||||
+25
-124
@@ -13,37 +13,27 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import {
|
||||
Attribute,
|
||||
Class,
|
||||
Data,
|
||||
DocumentQuery,
|
||||
IdMap,
|
||||
Ref,
|
||||
SortingOrder,
|
||||
Status,
|
||||
TxOperations
|
||||
} from '@hcengineering/core'
|
||||
import { Class, Data, DocumentQuery, IdMap, Ref, Status, TxOperations } from '@hcengineering/core'
|
||||
import { LexoDecimal, LexoNumeralSystem36, LexoRank } from 'lexorank'
|
||||
import LexoRankBucket from 'lexorank/lib/lexoRank/lexoRankBucket'
|
||||
import task, { DoneState, DoneStateTemplate, KanbanTemplate, SpaceWithStates, State } from '.'
|
||||
import task, { Project, ProjectType } from '.'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const genRanks = (count: number): Generator<string, void, unknown> =>
|
||||
(function * () {
|
||||
const sys = new LexoNumeralSystem36()
|
||||
const base = 36
|
||||
const max = base ** 6
|
||||
const gap = LexoDecimal.parse(Math.trunc(max / (count + 2)).toString(base), sys)
|
||||
let cur = LexoDecimal.parse('0', sys)
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
cur = cur.add(gap)
|
||||
yield new LexoRank(LexoRankBucket.BUCKET_0, cur).toString()
|
||||
}
|
||||
})()
|
||||
export function genRanks (count: number): string[] {
|
||||
const sys = new LexoNumeralSystem36()
|
||||
const base = 36
|
||||
const max = base ** 6
|
||||
const gap = LexoDecimal.parse(Math.trunc(max / (count + 2)).toString(base), sys)
|
||||
let cur = LexoDecimal.parse('0', sys)
|
||||
const res: string[] = []
|
||||
for (let i = 0; i < count; i++) {
|
||||
cur = cur.add(gap)
|
||||
res.push(new LexoRank(LexoRankBucket.BUCKET_0, cur).toString())
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -60,14 +50,14 @@ export const calcRank = (prev?: { rank: string }, next?: { rank: string }): stri
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function getStates (space: SpaceWithStates | undefined, statusStore: IdMap<Status>): Status[] {
|
||||
if (space === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
const states = (space.states ?? []).map((x) => statusStore.get(x) as Status).filter((p) => p !== undefined)
|
||||
|
||||
return states
|
||||
export function getStates (space: Project | undefined, types: IdMap<ProjectType>, statuses: IdMap<Status>): Status[] {
|
||||
if (space === undefined) return []
|
||||
return (
|
||||
(types
|
||||
.get(space.type)
|
||||
?.statuses?.map((p) => statuses.get(p._id))
|
||||
?.filter((p) => p !== undefined) as Status[]) ?? []
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,8 +66,7 @@ export function getStates (space: SpaceWithStates | undefined, statusStore: IdMa
|
||||
export async function createState<T extends Status> (
|
||||
client: TxOperations,
|
||||
_class: Ref<Class<T>>,
|
||||
data: Data<T>,
|
||||
_id?: Ref<T>
|
||||
data: Data<T>
|
||||
): Promise<Ref<T>> {
|
||||
const query: DocumentQuery<Status> = { name: data.name, ofAttribute: data.ofAttribute }
|
||||
if (data.category !== undefined) {
|
||||
@@ -87,94 +76,6 @@ export async function createState<T extends Status> (
|
||||
if (exists !== undefined) {
|
||||
return exists._id as Ref<T>
|
||||
}
|
||||
const res = await client.createDoc(_class, task.space.Statuses, data, _id)
|
||||
const res = await client.createDoc(_class, task.space.Statuses, data)
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function createStates (
|
||||
client: TxOperations,
|
||||
ofAttribute: Ref<Attribute<Status>>,
|
||||
doneAtrtribute?: Ref<Attribute<DoneState>>,
|
||||
templateId?: Ref<KanbanTemplate>
|
||||
): Promise<[Ref<Status>[], Ref<DoneState>[]]> {
|
||||
if (templateId === undefined) {
|
||||
const state = await createState(client, task.class.State, {
|
||||
ofAttribute,
|
||||
name: 'New State',
|
||||
color: 9
|
||||
})
|
||||
|
||||
const doneStates: Ref<DoneState>[] = []
|
||||
|
||||
doneStates.push(
|
||||
await createState(client, task.class.WonState, {
|
||||
ofAttribute: doneAtrtribute ?? ofAttribute,
|
||||
name: 'Won'
|
||||
})
|
||||
)
|
||||
doneStates.push(
|
||||
await createState(client, task.class.LostState, {
|
||||
ofAttribute: doneAtrtribute ?? ofAttribute,
|
||||
name: 'Lost'
|
||||
})
|
||||
)
|
||||
|
||||
return [[state], doneStates]
|
||||
}
|
||||
|
||||
const template = await client.findOne(task.class.KanbanTemplate, { _id: templateId })
|
||||
|
||||
if (template === undefined) {
|
||||
throw Error(`Failed to find target kanban template: ${templateId}`)
|
||||
}
|
||||
|
||||
const states: Ref<State>[] = []
|
||||
const doneStates: Ref<DoneState>[] = []
|
||||
|
||||
const tmplStates = await client.findAll(
|
||||
task.class.StateTemplate,
|
||||
{ attachedTo: template._id },
|
||||
{ sort: { rank: SortingOrder.Ascending } }
|
||||
)
|
||||
|
||||
for (const state of tmplStates) {
|
||||
states.push(
|
||||
await createState(client, task.class.State, {
|
||||
ofAttribute,
|
||||
color: state.color,
|
||||
description: state.description,
|
||||
name: state.name
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const doneClassMap = new Map<Ref<Class<DoneStateTemplate>>, Ref<Class<DoneState>>>([
|
||||
[task.class.WonStateTemplate, task.class.WonState],
|
||||
[task.class.LostStateTemplate, task.class.LostState]
|
||||
])
|
||||
const tmplDoneStates = await client.findAll(
|
||||
task.class.DoneStateTemplate,
|
||||
{ attachedTo: template._id },
|
||||
{ sort: { rank: SortingOrder.Ascending } }
|
||||
)
|
||||
for (const state of tmplDoneStates) {
|
||||
const cl = doneClassMap.get(state._class)
|
||||
|
||||
if (cl === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
doneStates.push(
|
||||
await createState(client, cl, {
|
||||
ofAttribute: doneAtrtribute ?? ofAttribute,
|
||||
description: state.description,
|
||||
name: state.name
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return [states, doneStates]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user