112 lines
3.0 KiB
TypeScript
Raw Normal View History

2020-10-20 12:50:53 -07:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
2020-11-17 14:11:04 -08:00
import {Utils} from '../utils'
import {IBlock} from '../blocks/block'
2020-10-20 18:28:55 -07:00
import {MutableBlock} from './block'
2020-10-08 09:21:27 -07:00
2020-10-20 12:50:53 -07:00
type PropertyType = 'text' | 'number' | 'select' | 'multiSelect' | 'date' | 'person' | 'file' | 'checkbox' | 'url' | 'email' | 'phone' | 'createdTime' | 'createdBy' | 'updatedTime' | 'updatedBy'
2020-10-08 09:21:27 -07:00
interface IPropertyOption {
2020-10-23 12:59:09 -07:00
readonly id: string
readonly value: string
2020-10-20 18:28:55 -07:00
readonly color: string
}
interface IMutablePropertyOption {
2020-10-23 12:59:09 -07:00
id: string
value: string
2020-10-20 12:50:53 -07:00
color: string
2020-10-08 09:21:27 -07:00
}
// A template for card properties attached to a board
interface IPropertyTemplate {
2020-10-20 18:28:55 -07:00
readonly id: string
readonly name: string
readonly type: PropertyType
readonly options: IPropertyOption[]
}
interface IMutablePropertyTemplate extends IPropertyTemplate {
2020-10-20 12:50:53 -07:00
id: string
name: string
type: PropertyType
2020-10-20 18:28:55 -07:00
options: IMutablePropertyOption[]
}
interface Board extends IBlock {
readonly icon: string
2020-11-18 11:11:51 -08:00
readonly description: string
readonly showDescription: boolean
2020-11-17 14:11:04 -08:00
readonly isTemplate: boolean
2020-10-20 18:28:55 -07:00
readonly cardProperties: readonly IPropertyTemplate[]
2020-11-17 14:11:04 -08:00
duplicate(): MutableBoard
2020-10-08 09:21:27 -07:00
}
2020-10-20 18:28:55 -07:00
class MutableBoard extends MutableBlock {
2020-10-20 12:50:53 -07:00
get icon(): string {
return this.fields.icon as string
}
set icon(value: string) {
this.fields.icon = value
}
2020-11-18 11:11:51 -08:00
get description(): string {
return this.fields.description as string
}
set description(value: string) {
this.fields.description = value
}
get showDescription(): boolean {
return Boolean(this.fields.showDescription)
}
set showDescription(value: boolean) {
this.fields.showDescription = value
}
2020-11-17 14:11:04 -08:00
get isTemplate(): boolean {
return Boolean(this.fields.isTemplate)
}
set isTemplate(value: boolean) {
this.fields.isTemplate = value
}
2020-10-20 18:28:55 -07:00
get cardProperties(): IMutablePropertyTemplate[] {
2020-10-20 12:50:53 -07:00
return this.fields.cardProperties as IPropertyTemplate[]
}
2020-10-20 18:28:55 -07:00
set cardProperties(value: IMutablePropertyTemplate[]) {
2020-10-20 12:50:53 -07:00
this.fields.cardProperties = value
}
constructor(block: any = {}) {
super(block)
2020-10-20 12:52:56 -07:00
this.type = 'board'
2020-10-20 12:50:53 -07:00
2020-11-12 17:24:24 -08:00
this.icon = block.fields?.icon || ''
2020-11-18 11:11:51 -08:00
this.description = block.fields?.description || ''
2020-10-20 12:50:53 -07:00
if (block.fields?.cardProperties) {
// Deep clone of card properties and their options
this.cardProperties = block.fields.cardProperties.map((o: IPropertyTemplate) => {
return {
id: o.id,
name: o.name,
type: o.type,
options: o.options ? o.options.map((option) => ({...option})) : [],
}
2020-10-20 12:52:56 -07:00
})
2020-10-20 12:50:53 -07:00
} else {
this.cardProperties = []
}
}
2020-11-17 14:11:04 -08:00
duplicate(): MutableBoard {
const card = new MutableBoard(this)
card.id = Utils.createGuid()
return card
}
2020-10-08 09:21:27 -07:00
}
2020-10-20 18:28:55 -07:00
export {Board, MutableBoard, PropertyType, IPropertyOption, IPropertyTemplate}