1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-23 18:34:02 +02:00

Add generic fields to IBlock

This commit is contained in:
Chen-I Lim 2020-10-14 13:44:35 -07:00
parent 94cc769d4b
commit 96b9d6a5d2
5 changed files with 71 additions and 26 deletions

View File

@ -50,9 +50,11 @@ func NewSQLStore(dbType, connectionString string) (*SQLStore, error) {
type Block struct {
ID string `json:"id"`
ParentID string `json:"parentId"`
Schema int64 `json:"schema"`
Type string `json:"type"`
Title string `json:"title"`
Properties map[string]interface{} `json:"properties"`
Fields map[string]interface{} `json:"fields"`
CreateAt int64 `json:"createAt"`
UpdateAt int64 `json:"updateAt"`
DeleteAt int64 `json:"deleteAt"`
@ -68,8 +70,7 @@ func (s *SQLStore) createTablesIfNotExists() error {
insert_at DATETIME NOT NULL DEFAULT current_timestamp,
parent_id VARCHAR(36),
type TEXT,
title TEXT,
properties TEXT,
json TEXT,
create_at BIGINT,
update_at BIGINT,
delete_at BIGINT,
@ -81,8 +82,7 @@ func (s *SQLStore) createTablesIfNotExists() error {
insert_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
parent_id VARCHAR(36),
type TEXT,
title TEXT,
properties TEXT,
json TEXT,
create_at BIGINT,
update_at BIGINT,
delete_at BIGINT,

View File

@ -3,6 +3,7 @@ import { Utils } from "./utils"
class Block implements IBlock {
id: string = Utils.createGuid()
schema: number
parentId: string
type: string
title: string
@ -10,6 +11,7 @@ class Block implements IBlock {
url?: string
order: number
properties: Record<string, string> = {}
fields: Record<string, any> = {}
createAt: number = Date.now()
updateAt: number = 0
deleteAt: number = 0
@ -31,26 +33,35 @@ class Block implements IBlock {
const now = Date.now()
this.id = block.id || Utils.createGuid()
this.schema = 1
this.parentId = block.parentId
this.type = block.type
this.fields = block.fields ? { ...block.fields } : {}
this.title = block.title
this.icon = block.icon
this.url = block.url
this.order = block.order
this.createAt = block.createAt || now
this.updateAt = block.updateAt || now
this.deleteAt = block.deleteAt || 0
if (Array.isArray(block.properties)) {
// HACKHACK: Port from old schema
this.properties = {}
for (const property of block.properties) {
if (property.id) {
this.properties[property.id] = property.value
if (block.schema !== 1) {
if (Array.isArray(block.properties)) {
// HACKHACK: Port from old schema
this.properties = {}
for (const property of block.properties) {
if (property.id) {
this.properties[property.id] = property.value
}
}
} else {
this.properties = { ...block.properties || {} }
}
} else {
this.properties = { ...block.properties || {} }
this.properties = { ...block.properties } // Shallow copy here. Derived classes must make deep copies of their known properties in their constructors.
}
}
}

View File

@ -16,24 +16,37 @@ interface IPropertyTemplate {
}
class Board extends Block {
cardProperties: IPropertyTemplate[] = []
get cardProperties(): IPropertyTemplate[] { return this.fields.cardProperties as IPropertyTemplate[] }
set cardProperties(value: IPropertyTemplate[]) { this.fields.cardProperties = value }
constructor(block: any = {}) {
super(block)
this.type = "board"
if (block.cardProperties) {
// Deep clone of properties and their options
this.cardProperties = block.cardProperties.map((o: IPropertyTemplate) => {
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})): []
options: o.options ? o.options.map(option => ({ ...option })) : []
}
})
} else {
this.cardProperties = []
}
if (block.schema !== 1) {
this.cardProperties = block.cardProperties?.map((o: IPropertyTemplate) => {
return {
id: o.id,
name: o.name,
type: o.type,
options: o.options ? o.options.map(option => ({ ...option })) : []
}
}) || []
}
}
}

View File

@ -5,21 +5,40 @@ type IViewType = "board" | "table" | "calendar" | "list" | "gallery"
type ISortOption = { propertyId: "__name" | string, reversed: boolean }
class BoardView extends Block {
viewType: IViewType
groupById?: string
sortOptions: ISortOption[]
visiblePropertyIds: string[]
filter?: FilterGroup
get viewType(): IViewType { return this.fields.viewType }
set viewType(value: IViewType) { this.fields.viewType = value }
get groupById(): string | undefined { return this.fields.groupById }
set groupById(value: string | undefined) { this.fields.groupById = value }
get sortOptions(): ISortOption[] { return this.fields.sortOptions }
set sortOptions(value: ISortOption[]) { this.fields.sortOptions = value }
get visiblePropertyIds(): string[] { return this.fields.visiblePropertyIds }
set visiblePropertyIds(value: string[]) { this.fields.visiblePropertyIds = value }
get filter(): FilterGroup | undefined { return this.fields.filter }
set filter(value: FilterGroup | undefined) { this.fields.filter = value }
constructor(block: any = {}) {
super(block)
this.type = "view"
this.viewType = block.viewType || "board"
this.groupById = block.groupById
this.sortOptions = block.sortOptions ? block.sortOptions.map((o: ISortOption) => ({...o})) : [] // Deep clone
this.visiblePropertyIds = block.visiblePropertyIds ? block.visiblePropertyIds.slice() : []
this.filter = new FilterGroup(block.filter)
this.sortOptions = block.properties?.sortOptions?.map((o: ISortOption) => ({ ...o })) || [] // Deep clone
this.visiblePropertyIds = block.properties?.visiblePropertyIds?.slice() || []
this.filter = new FilterGroup(block.properties?.filter)
// TODO: Remove this fixup code
if (block.schema !== 1) {
this.viewType = block.viewType || "board"
this.groupById = block.groupById
this.sortOptions = block.sortOptions ? block.sortOptions.map((o: ISortOption) => ({ ...o })) : [] // Deep clone
this.visiblePropertyIds = block.visiblePropertyIds ? block.visiblePropertyIds.slice() : []
this.filter = new FilterGroup(block.filter)
}
if (!this.viewType) { this.viewType = "board" }
}
}

View File

@ -3,12 +3,14 @@ interface IBlock {
id: string
parentId: string
schema: number
type: string
title?: string
url?: string // TODO: Move to properties (_url)
icon?: string
order: number
properties: Record<string, string>
fields: Record<string, any>
createAt: number
updateAt: number