2020-10-20 21:50:53 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2020-11-10 20:23:08 +01:00
|
|
|
import {Utils} from '../utils'
|
2020-10-15 02:35:15 +02:00
|
|
|
|
2021-02-16 19:31:00 +01:00
|
|
|
import {IBlock, MutableBlock} from './block'
|
2020-10-21 03:28:55 +02:00
|
|
|
|
|
|
|
interface Card extends IBlock {
|
|
|
|
readonly icon: string
|
2020-11-10 20:23:08 +01:00
|
|
|
readonly isTemplate: boolean
|
2021-06-03 22:48:16 +02:00
|
|
|
readonly properties: Readonly<Record<string, string | string[]>>
|
2021-07-15 16:38:12 +02:00
|
|
|
readonly contentOrder: Readonly<Array<string | string[]>>
|
2020-12-18 21:52:45 +01:00
|
|
|
|
2020-11-11 18:21:16 +01:00
|
|
|
duplicate(): MutableCard
|
2020-10-21 03:28:55 +02:00
|
|
|
}
|
|
|
|
|
2021-01-19 23:48:20 +01:00
|
|
|
class MutableCard extends MutableBlock implements Card {
|
2020-10-20 21:50:53 +02:00
|
|
|
get icon(): string {
|
|
|
|
return this.fields.icon as string
|
|
|
|
}
|
|
|
|
set icon(value: string) {
|
|
|
|
this.fields.icon = value
|
|
|
|
}
|
2020-10-15 02:35:15 +02:00
|
|
|
|
2020-11-10 20:23:08 +01:00
|
|
|
get isTemplate(): boolean {
|
2020-11-17 23:11:04 +01:00
|
|
|
return Boolean(this.fields.isTemplate)
|
2020-11-10 20:23:08 +01:00
|
|
|
}
|
|
|
|
set isTemplate(value: boolean) {
|
|
|
|
this.fields.isTemplate = value
|
|
|
|
}
|
|
|
|
|
2021-06-03 22:48:16 +02:00
|
|
|
get properties(): Record<string, string | string[]> {
|
|
|
|
return this.fields.properties as Record<string, string | string[]>
|
2020-10-20 21:50:53 +02:00
|
|
|
}
|
2021-06-03 22:48:16 +02:00
|
|
|
set properties(value: Record<string, string | string[]>) {
|
2020-10-20 21:50:53 +02:00
|
|
|
this.fields.properties = value
|
|
|
|
}
|
2020-10-15 02:35:15 +02:00
|
|
|
|
2021-07-15 16:38:12 +02:00
|
|
|
get contentOrder(): Array<string | string[]> {
|
2020-12-18 21:52:45 +01:00
|
|
|
return this.fields.contentOrder
|
|
|
|
}
|
2021-07-15 16:38:12 +02:00
|
|
|
set contentOrder(value: Array<string | string[]>) {
|
2020-12-18 21:52:45 +01:00
|
|
|
this.fields.contentOrder = value
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
constructor(block: any = {}) {
|
|
|
|
super(block)
|
2020-10-20 21:52:56 +02:00
|
|
|
this.type = 'card'
|
2020-10-15 02:35:15 +02:00
|
|
|
|
2020-11-13 02:24:24 +01:00
|
|
|
this.icon = block.fields?.icon || ''
|
2020-10-20 21:50:53 +02:00
|
|
|
this.properties = {...(block.fields?.properties || {})}
|
2020-12-18 21:52:45 +01:00
|
|
|
this.contentOrder = block.fields?.contentOrder?.slice() || []
|
2020-10-20 21:50:53 +02:00
|
|
|
}
|
2020-11-10 20:23:08 +01:00
|
|
|
|
2020-11-11 18:21:16 +01:00
|
|
|
duplicate(): MutableCard {
|
2020-11-10 20:23:08 +01:00
|
|
|
const card = new MutableCard(this)
|
|
|
|
card.id = Utils.createGuid()
|
|
|
|
return card
|
|
|
|
}
|
2020-10-15 02:35:15 +02:00
|
|
|
}
|
|
|
|
|
2020-10-21 03:28:55 +02:00
|
|
|
export {MutableCard, Card}
|