2022-03-31 08:32:42 +00:00
|
|
|
//
|
2022-04-23 16:59:57 +00:00
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
2022-03-31 08:32:42 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
2022-05-11 17:15:29 +00:00
|
|
|
import { DocumentQuery, Ref, SortingOrder } from '@anticrm/core'
|
2022-03-31 08:32:42 +00:00
|
|
|
import type { Asset, IntlString } from '@anticrm/platform'
|
2022-04-23 16:59:57 +00:00
|
|
|
import {
|
|
|
|
IssuePriority,
|
|
|
|
Team,
|
|
|
|
IssuesGrouping,
|
|
|
|
IssuesOrdering,
|
|
|
|
Issue,
|
2022-04-27 08:18:59 +00:00
|
|
|
IssuesDateModificationPeriod,
|
|
|
|
ProjectStatus
|
2022-04-23 16:59:57 +00:00
|
|
|
} from '@anticrm/tracker'
|
2022-05-05 06:35:26 +00:00
|
|
|
import { AnyComponent, AnySvelteComponent, getMillisecondsInMonth, MILLISECONDS_IN_WEEK } from '@anticrm/ui'
|
2022-04-08 06:27:02 +00:00
|
|
|
import tracker from './plugin'
|
2022-03-31 08:32:42 +00:00
|
|
|
|
|
|
|
export interface NavigationItem {
|
|
|
|
id: string
|
|
|
|
label: IntlString
|
|
|
|
icon: Asset
|
|
|
|
component: AnyComponent
|
|
|
|
componentProps?: Record<string, string>
|
|
|
|
top: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Selection {
|
|
|
|
currentTeam?: Ref<Team>
|
|
|
|
currentSpecial?: string
|
|
|
|
}
|
|
|
|
|
2022-04-08 06:27:02 +00:00
|
|
|
export const issuePriorities: Record<IssuePriority, { icon: Asset, label: IntlString }> = {
|
|
|
|
[IssuePriority.NoPriority]: { icon: tracker.icon.PriorityNoPriority, label: tracker.string.NoPriority },
|
|
|
|
[IssuePriority.Urgent]: { icon: tracker.icon.PriorityUrgent, label: tracker.string.Urgent },
|
|
|
|
[IssuePriority.High]: { icon: tracker.icon.PriorityHigh, label: tracker.string.High },
|
|
|
|
[IssuePriority.Medium]: { icon: tracker.icon.PriorityMedium, label: tracker.string.Medium },
|
|
|
|
[IssuePriority.Low]: { icon: tracker.icon.PriorityLow, label: tracker.string.Low }
|
|
|
|
}
|
2022-04-20 06:06:05 +00:00
|
|
|
|
|
|
|
export const issuesGroupByOptions: Record<IssuesGrouping, IntlString> = {
|
|
|
|
[IssuesGrouping.Status]: tracker.string.Status,
|
|
|
|
[IssuesGrouping.Assignee]: tracker.string.Assignee,
|
|
|
|
[IssuesGrouping.Priority]: tracker.string.Priority,
|
2022-06-01 16:08:22 +00:00
|
|
|
[IssuesGrouping.Project]: tracker.string.Project,
|
2022-04-20 06:06:05 +00:00
|
|
|
[IssuesGrouping.NoGrouping]: tracker.string.NoGrouping
|
|
|
|
}
|
|
|
|
|
|
|
|
export const issuesOrderByOptions: Record<IssuesOrdering, IntlString> = {
|
|
|
|
[IssuesOrdering.Status]: tracker.string.Status,
|
|
|
|
[IssuesOrdering.Priority]: tracker.string.Priority,
|
|
|
|
[IssuesOrdering.LastUpdated]: tracker.string.LastUpdated,
|
|
|
|
[IssuesOrdering.DueDate]: tracker.string.DueDate
|
|
|
|
}
|
|
|
|
|
2022-04-22 06:13:57 +00:00
|
|
|
export const issuesDateModificationPeriodOptions: Record<IssuesDateModificationPeriod, IntlString> = {
|
|
|
|
[IssuesDateModificationPeriod.All]: tracker.string.All,
|
|
|
|
[IssuesDateModificationPeriod.PastWeek]: tracker.string.PastWeek,
|
|
|
|
[IssuesDateModificationPeriod.PastMonth]: tracker.string.PastMonth
|
|
|
|
}
|
|
|
|
|
2022-06-01 16:08:22 +00:00
|
|
|
export type IssuesGroupByKeys = keyof Pick<Issue, 'status' | 'priority' | 'assignee' | 'project'>
|
2022-04-20 06:06:05 +00:00
|
|
|
export type IssuesOrderByKeys = keyof Pick<Issue, 'status' | 'priority' | 'modifiedOn' | 'dueDate'>
|
|
|
|
|
|
|
|
export const issuesGroupKeyMap: Record<IssuesGrouping, IssuesGroupByKeys | undefined> = {
|
|
|
|
[IssuesGrouping.Status]: 'status',
|
|
|
|
[IssuesGrouping.Priority]: 'priority',
|
|
|
|
[IssuesGrouping.Assignee]: 'assignee',
|
2022-06-01 16:08:22 +00:00
|
|
|
[IssuesGrouping.Project]: 'project',
|
2022-04-20 06:06:05 +00:00
|
|
|
[IssuesGrouping.NoGrouping]: undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
export const issuesOrderKeyMap: Record<IssuesOrdering, IssuesOrderByKeys> = {
|
|
|
|
[IssuesOrdering.Status]: 'status',
|
|
|
|
[IssuesOrdering.Priority]: 'priority',
|
|
|
|
[IssuesOrdering.LastUpdated]: 'modifiedOn',
|
|
|
|
[IssuesOrdering.DueDate]: 'dueDate'
|
|
|
|
}
|
|
|
|
|
|
|
|
export const issuesSortOrderMap: Record<IssuesOrderByKeys, SortingOrder> = {
|
|
|
|
status: SortingOrder.Ascending,
|
|
|
|
priority: SortingOrder.Ascending,
|
|
|
|
modifiedOn: SortingOrder.Descending,
|
|
|
|
dueDate: SortingOrder.Descending
|
|
|
|
}
|
|
|
|
|
2022-06-01 16:08:22 +00:00
|
|
|
export const issuesGroupEditorMap: Record<'status' | 'priority' | 'project', AnyComponent | undefined> = {
|
2022-05-04 13:46:34 +00:00
|
|
|
status: tracker.component.StatusEditor,
|
2022-06-01 16:08:22 +00:00
|
|
|
priority: tracker.component.PriorityEditor,
|
|
|
|
project: tracker.component.ProjectEditor
|
2022-04-20 06:06:05 +00:00
|
|
|
}
|
2022-04-22 06:13:57 +00:00
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
export const getIssuesModificationDatePeriodTime = (period: IssuesDateModificationPeriod | null): number => {
|
2022-04-22 06:13:57 +00:00
|
|
|
const today = new Date(Date.now())
|
|
|
|
|
|
|
|
switch (period) {
|
|
|
|
case IssuesDateModificationPeriod.PastWeek: {
|
|
|
|
return today.getTime() - MILLISECONDS_IN_WEEK
|
|
|
|
}
|
|
|
|
case IssuesDateModificationPeriod.PastMonth: {
|
|
|
|
return today.getTime() - getMillisecondsInMonth(today)
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-26 08:46:35 +00:00
|
|
|
|
2022-05-18 05:35:34 +00:00
|
|
|
export const defaultProjectStatuses = [
|
2022-05-18 15:57:11 +00:00
|
|
|
ProjectStatus.Backlog,
|
2022-05-18 05:35:34 +00:00
|
|
|
ProjectStatus.Planned,
|
|
|
|
ProjectStatus.InProgress,
|
|
|
|
ProjectStatus.Paused,
|
|
|
|
ProjectStatus.Completed,
|
|
|
|
ProjectStatus.Canceled
|
|
|
|
]
|
|
|
|
|
|
|
|
export const projectStatusAssets: Record<ProjectStatus, { icon: Asset, label: IntlString }> = {
|
2022-05-18 15:57:11 +00:00
|
|
|
[ProjectStatus.Backlog]: { icon: tracker.icon.ProjectStatusBacklog, label: tracker.string.Backlog },
|
|
|
|
[ProjectStatus.Planned]: { icon: tracker.icon.ProjectStatusPlanned, label: tracker.string.Planned },
|
|
|
|
[ProjectStatus.InProgress]: { icon: tracker.icon.ProjectStatusInProgress, label: tracker.string.InProgress },
|
|
|
|
[ProjectStatus.Paused]: { icon: tracker.icon.ProjectStatusPaused, label: tracker.string.Paused },
|
|
|
|
[ProjectStatus.Completed]: { icon: tracker.icon.ProjectStatusCompleted, label: tracker.string.Completed },
|
|
|
|
[ProjectStatus.Canceled]: { icon: tracker.icon.ProjectStatusCanceled, label: tracker.string.Canceled }
|
2022-04-27 08:18:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 08:46:35 +00:00
|
|
|
export const groupBy = (data: any, key: any): { [key: string]: any[] } => {
|
|
|
|
return data.reduce((storage: { [key: string]: any[] }, item: any) => {
|
|
|
|
const group = item[key]
|
|
|
|
|
|
|
|
storage[group] = storage[group] ?? []
|
|
|
|
|
|
|
|
storage[group].push(item)
|
|
|
|
|
|
|
|
return storage
|
|
|
|
}, {})
|
|
|
|
}
|
2022-05-05 06:35:26 +00:00
|
|
|
|
|
|
|
export interface FilterAction {
|
|
|
|
icon?: Asset | AnySvelteComponent
|
|
|
|
label?: IntlString
|
|
|
|
onSelect: (event: MouseEvent | KeyboardEvent) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface FilterSectionElement extends Omit<FilterAction, 'label'> {
|
|
|
|
title?: string
|
|
|
|
count?: number
|
|
|
|
isSelected?: boolean
|
|
|
|
}
|
|
|
|
|
2022-05-11 17:15:29 +00:00
|
|
|
export interface IssueFilter {
|
|
|
|
mode: '$in' | '$nin'
|
|
|
|
query: DocumentQuery<Issue>
|
|
|
|
}
|
|
|
|
|
2022-05-05 06:35:26 +00:00
|
|
|
export const getGroupedIssues = (
|
|
|
|
key: IssuesGroupByKeys | undefined,
|
|
|
|
elements: Issue[],
|
|
|
|
orderedCategories?: any[]
|
|
|
|
): { [p: string]: Issue[] } => {
|
|
|
|
if (key === undefined) {
|
|
|
|
return { [undefined as any]: elements }
|
|
|
|
}
|
|
|
|
|
|
|
|
const unorderedIssues = groupBy(elements, key)
|
|
|
|
|
|
|
|
if (orderedCategories === undefined || orderedCategories.length === 0) {
|
|
|
|
return unorderedIssues
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.keys(unorderedIssues)
|
|
|
|
.sort((o1, o2) => {
|
|
|
|
const key1 = o1 === 'null' ? null : o1
|
|
|
|
const key2 = o2 === 'null' ? null : o2
|
|
|
|
|
|
|
|
const i1 = orderedCategories.findIndex((x) => x === key1)
|
|
|
|
const i2 = orderedCategories.findIndex((x) => x === key2)
|
|
|
|
|
|
|
|
return i1 - i2
|
|
|
|
})
|
|
|
|
.reduce((obj: { [p: string]: any[] }, objKey) => {
|
|
|
|
obj[objKey] = unorderedIssues[objKey]
|
|
|
|
return obj
|
|
|
|
}, {})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getIssueFilterAssetsByType = (type: string): { icon: Asset, label: IntlString } | undefined => {
|
|
|
|
switch (type) {
|
|
|
|
case 'status': {
|
|
|
|
return {
|
|
|
|
icon: tracker.icon.CategoryBacklog,
|
|
|
|
label: tracker.string.Status
|
|
|
|
}
|
|
|
|
}
|
2022-05-11 17:15:29 +00:00
|
|
|
case 'priority': {
|
|
|
|
return {
|
|
|
|
icon: tracker.icon.PriorityHigh,
|
|
|
|
label: tracker.string.Priority
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 16:08:22 +00:00
|
|
|
case 'project': {
|
|
|
|
return {
|
|
|
|
icon: tracker.icon.Project,
|
|
|
|
label: tracker.string.Project
|
|
|
|
}
|
|
|
|
}
|
2022-05-05 06:35:26 +00:00
|
|
|
default: {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-11 17:15:29 +00:00
|
|
|
|
|
|
|
export const defaultPriorities = [
|
|
|
|
IssuePriority.NoPriority,
|
|
|
|
IssuePriority.Urgent,
|
|
|
|
IssuePriority.High,
|
|
|
|
IssuePriority.Medium,
|
|
|
|
IssuePriority.Low
|
|
|
|
]
|
|
|
|
|
|
|
|
export const getArraysIntersection = (a: any[], b: any[]): any[] => {
|
|
|
|
const setB = new Set(b)
|
|
|
|
const intersection = new Set(a.filter((x) => setB.has(x)))
|
|
|
|
|
|
|
|
return Array.from(intersection)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getArraysUnion = (a: any[], b: any[]): any[] => {
|
|
|
|
const setB = new Set(b)
|
|
|
|
const union = new Set(a)
|
|
|
|
|
|
|
|
for (const element of setB) {
|
|
|
|
union.add(element)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Array.from(union)
|
|
|
|
}
|
2022-05-18 04:04:54 +00:00
|
|
|
|
|
|
|
const WARNING_DAYS = 7
|
|
|
|
|
|
|
|
export const getDueDateIconModifier = (
|
|
|
|
isOverdue: boolean,
|
|
|
|
daysDifference: number | null
|
|
|
|
): 'overdue' | 'critical' | 'warning' | undefined => {
|
|
|
|
if (isOverdue) {
|
|
|
|
return 'overdue'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (daysDifference === 0) {
|
|
|
|
return 'critical'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (daysDifference !== null && daysDifference <= WARNING_DAYS) {
|
|
|
|
return 'warning'
|
|
|
|
}
|
|
|
|
}
|
2022-05-18 15:57:11 +00:00
|
|
|
|
|
|
|
export type ProjectsViewMode = 'all' | 'backlog' | 'active' | 'closed'
|
|
|
|
|
|
|
|
export const getIncludedProjectStatuses = (mode: ProjectsViewMode): ProjectStatus[] => {
|
|
|
|
switch (mode) {
|
|
|
|
case 'all': {
|
|
|
|
return defaultProjectStatuses
|
|
|
|
}
|
|
|
|
case 'active': {
|
|
|
|
return [ProjectStatus.Planned, ProjectStatus.InProgress, ProjectStatus.Paused]
|
|
|
|
}
|
|
|
|
case 'backlog': {
|
|
|
|
return [ProjectStatus.Backlog]
|
|
|
|
}
|
|
|
|
case 'closed': {
|
|
|
|
return [ProjectStatus.Completed, ProjectStatus.Canceled]
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-19 10:37:41 +00:00
|
|
|
|
|
|
|
export const projectsTitleMap: Record<ProjectsViewMode, IntlString> = Object.freeze({
|
|
|
|
all: tracker.string.AllProjects,
|
|
|
|
backlog: tracker.string.BacklogProjects,
|
|
|
|
active: tracker.string.ActiveProjects,
|
|
|
|
closed: tracker.string.ClosedProjects
|
|
|
|
})
|