Board: Create board labels (#1426)

Signed-off-by: Anna No <anna.no@xored.com>
This commit is contained in:
Anna No 2022-04-18 14:56:21 +07:00 committed by GitHub
parent ae51623556
commit b462a9d680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 98 additions and 30 deletions

View File

@ -1,17 +1,31 @@
export const FeijoaColor = '#A5D179'
export const DeYorkColor = '#77C07B'
export const FernColor = '#60B96E' // green
export const PuertoRicoColor = '#45AEA3'
export const MediumTurquoiseColor = '#46CBDE'
export const SummerSkyColor = '#47BDF6'
export const MalibuColor = '#5AADF6'
export const SeagullColor = '#73A6CD'
export const EastSideColor = '#B977CB' // purple
export const MoodyBlueColor = '#7C6FCD' // violet
export const ChetwodeBlueColor = '#6F7BC5' // dark blue
export const SalmonColor = '#F28469' // salmon
export const SeaBuckthornColor = '#F2994A' // orange (warning)
export const FlamingoColor = '#EB5757' // red (error)
const blackColors = Object.freeze([ const blackColors = Object.freeze([
'#A5D179', FeijoaColor,
'#77C07B', DeYorkColor,
'#60B96E', FernColor,
'#45AEA3', PuertoRicoColor,
'#46CBDE', MediumTurquoiseColor,
'#47BDF6', SummerSkyColor,
'#5AADF6', MalibuColor,
'#73A6CD', SeagullColor,
'#B977CB', EastSideColor,
'#7C6FCD', MoodyBlueColor,
'#6F7BC5', ChetwodeBlueColor,
'#F28469' SalmonColor
]) ])
/** /**
@ -46,3 +60,17 @@ function hashCode (str: string): number {
export function getColorNumberByText (str: string): number { export function getColorNumberByText (str: string): number {
return hashCode(str) return hashCode(str)
} }
/**
* @public
*/
export function hexColorToNumber (hexColor: string): number {
return parseInt(hexColor.replace('#', ''), 16)
}
/**
* @public
*/
export function numberToHexColor (color: number): string {
return `#${color.toString(16)}`
}

View File

@ -14,12 +14,13 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import core, { Ref } from '@anticrm/core' import { Ref } from '@anticrm/core'
import { getClient, SpaceCreateCard } from '@anticrm/presentation' import { getClient, SpaceCreateCard } from '@anticrm/presentation'
import task, { createKanban, KanbanTemplate } from '@anticrm/task' import task, { KanbanTemplate } from '@anticrm/task'
import { Component, EditBox, Grid, IconFolder } from '@anticrm/ui' import { Component, EditBox, Grid, IconFolder } from '@anticrm/ui'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import board from '../plugin' import board from '../plugin'
import { createBoard } from '../utils/BoardUtils'
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -33,7 +34,7 @@
const client = getClient() const client = getClient()
async function createBoard (): Promise<void> { async function onCreateBoard (): Promise<void> {
if ( if (
templateId !== undefined && templateId !== undefined &&
(await client.findOne(task.class.KanbanTemplate, { _id: templateId })) === undefined (await client.findOne(task.class.KanbanTemplate, { _id: templateId })) === undefined
@ -41,21 +42,13 @@
throw Error(`Failed to find target kanban template: ${templateId}`) throw Error(`Failed to find target kanban template: ${templateId}`)
} }
const id = await client.createDoc(board.class.Board, core.space.Space, { await createBoard(client, name, description, templateId)
name,
description,
private: false,
archived: false,
members: []
})
await createKanban(client, id, templateId)
} }
</script> </script>
<SpaceCreateCard <SpaceCreateCard
label={board.string.CreateBoard} label={board.string.CreateBoard}
okAction={createBoard} okAction={onCreateBoard}
canSave={name.length > 0} canSave={name.length > 0}
on:close={() => { on:close={() => {
dispatch('close') dispatch('close')

View File

@ -29,7 +29,7 @@
let actionGroups: { label: IntlString; actions: CardAction[] }[] = [] let actionGroups: { label: IntlString; actions: CardAction[] }[] = []
async function fetch() { async function fetch () {
const suggestedActions: CardAction[] = [] const suggestedActions: CardAction[] = []
const addToCardActions: CardAction[] = [] const addToCardActions: CardAction[] = []
const automationActions: CardAction[] = [] const automationActions: CardAction[] = []
@ -80,7 +80,6 @@
$: value.members && fetch() $: value.members && fetch()
$: value.isArchived && fetch() $: value.isArchived && fetch()
$: !value.isArchived && fetch() $: !value.isArchived && fetch()
</script> </script>
{#if value} {#if value}
@ -105,7 +104,8 @@
const handler = await getResource(action.handler) const handler = await getResource(action.handler)
handler(value, client) handler(value, client)
} }
}} /> }}
/>
{/if} {/if}
{/each} {/each}
</div> </div>

View File

@ -1,11 +1,11 @@
<script lang="ts"> <script lang="ts">
import { Button, getPlatformColor } from '@anticrm/ui' import { Button, numberToHexColor } from '@anticrm/ui'
import type { CardLabel } from '@anticrm/board' import type { CardLabel } from '@anticrm/board'
export let value: CardLabel export let value: CardLabel
export let size: 'large' | 'medium' export let size: 'large' | 'medium'
const background = getPlatformColor(value.color) const background = numberToHexColor(value.color)
</script> </script>

View File

@ -0,0 +1,47 @@
import core, { Ref, TxOperations } from '@anticrm/core'
import board, { Board, CardLabel } from '@anticrm/board'
import type { KanbanTemplate } from '@anticrm/task'
import { createKanban } from '@anticrm/task'
import { hexColorToNumber, FernColor, FlamingoColor, MalibuColor, MoodyBlueColor, SeaBuckthornColor } from '@anticrm/ui'
export async function createBoard (
client: TxOperations,
name: string,
description: string,
templateId?: Ref<KanbanTemplate>
): Promise<Ref<Board>> {
const boardRef = await client.createDoc(board.class.Board, core.space.Space, {
name,
description,
private: false,
archived: false,
members: []
})
await Promise.all([createBoardLabels(client, boardRef), createKanban(client, boardRef, templateId)])
return boardRef
}
export async function getBoardLabels (client: TxOperations, boardRef: Ref<Board>): Promise<CardLabel[]> {
return await client.findAll(board.class.CardLabel, { attachedTo: boardRef })
}
export async function createBoardLabels (client: TxOperations, boardRef: Ref<Board>): Promise<void> {
await Promise.all([
createCardLabel(client, boardRef, FernColor),
createCardLabel(client, boardRef, SeaBuckthornColor),
createCardLabel(client, boardRef, FlamingoColor),
createCardLabel(client, boardRef, MalibuColor),
createCardLabel(client, boardRef, MoodyBlueColor)
])
}
export async function createCardLabel (client: TxOperations, boardRef: Ref<Board>, color: string, title?: string): Promise<void> {
await client.createDoc(board.class.CardLabel, core.space.Model, {
attachedTo: boardRef,
attachedToClass: board.class.Board,
collection: '',
color: hexColorToNumber(color),
title: title ?? ''
})
}