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:
parent
94cc769d4b
commit
96b9d6a5d2
@ -50,9 +50,11 @@ func NewSQLStore(dbType, connectionString string) (*SQLStore, error) {
|
|||||||
type Block struct {
|
type Block struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ParentID string `json:"parentId"`
|
ParentID string `json:"parentId"`
|
||||||
|
Schema int64 `json:"schema"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Properties map[string]interface{} `json:"properties"`
|
Properties map[string]interface{} `json:"properties"`
|
||||||
|
Fields map[string]interface{} `json:"fields"`
|
||||||
CreateAt int64 `json:"createAt"`
|
CreateAt int64 `json:"createAt"`
|
||||||
UpdateAt int64 `json:"updateAt"`
|
UpdateAt int64 `json:"updateAt"`
|
||||||
DeleteAt int64 `json:"deleteAt"`
|
DeleteAt int64 `json:"deleteAt"`
|
||||||
@ -68,8 +70,7 @@ func (s *SQLStore) createTablesIfNotExists() error {
|
|||||||
insert_at DATETIME NOT NULL DEFAULT current_timestamp,
|
insert_at DATETIME NOT NULL DEFAULT current_timestamp,
|
||||||
parent_id VARCHAR(36),
|
parent_id VARCHAR(36),
|
||||||
type TEXT,
|
type TEXT,
|
||||||
title TEXT,
|
json TEXT,
|
||||||
properties TEXT,
|
|
||||||
create_at BIGINT,
|
create_at BIGINT,
|
||||||
update_at BIGINT,
|
update_at BIGINT,
|
||||||
delete_at BIGINT,
|
delete_at BIGINT,
|
||||||
@ -81,8 +82,7 @@ func (s *SQLStore) createTablesIfNotExists() error {
|
|||||||
insert_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
insert_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
parent_id VARCHAR(36),
|
parent_id VARCHAR(36),
|
||||||
type TEXT,
|
type TEXT,
|
||||||
title TEXT,
|
json TEXT,
|
||||||
properties TEXT,
|
|
||||||
create_at BIGINT,
|
create_at BIGINT,
|
||||||
update_at BIGINT,
|
update_at BIGINT,
|
||||||
delete_at BIGINT,
|
delete_at BIGINT,
|
||||||
|
@ -3,6 +3,7 @@ import { Utils } from "./utils"
|
|||||||
|
|
||||||
class Block implements IBlock {
|
class Block implements IBlock {
|
||||||
id: string = Utils.createGuid()
|
id: string = Utils.createGuid()
|
||||||
|
schema: number
|
||||||
parentId: string
|
parentId: string
|
||||||
type: string
|
type: string
|
||||||
title: string
|
title: string
|
||||||
@ -10,6 +11,7 @@ class Block implements IBlock {
|
|||||||
url?: string
|
url?: string
|
||||||
order: number
|
order: number
|
||||||
properties: Record<string, string> = {}
|
properties: Record<string, string> = {}
|
||||||
|
fields: Record<string, any> = {}
|
||||||
createAt: number = Date.now()
|
createAt: number = Date.now()
|
||||||
updateAt: number = 0
|
updateAt: number = 0
|
||||||
deleteAt: number = 0
|
deleteAt: number = 0
|
||||||
@ -31,26 +33,35 @@ class Block implements IBlock {
|
|||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
|
|
||||||
this.id = block.id || Utils.createGuid()
|
this.id = block.id || Utils.createGuid()
|
||||||
|
this.schema = 1
|
||||||
this.parentId = block.parentId
|
this.parentId = block.parentId
|
||||||
this.type = block.type
|
this.type = block.type
|
||||||
|
|
||||||
|
this.fields = block.fields ? { ...block.fields } : {}
|
||||||
|
|
||||||
this.title = block.title
|
this.title = block.title
|
||||||
this.icon = block.icon
|
this.icon = block.icon
|
||||||
this.url = block.url
|
this.url = block.url
|
||||||
this.order = block.order
|
this.order = block.order
|
||||||
|
|
||||||
this.createAt = block.createAt || now
|
this.createAt = block.createAt || now
|
||||||
this.updateAt = block.updateAt || now
|
this.updateAt = block.updateAt || now
|
||||||
this.deleteAt = block.deleteAt || 0
|
this.deleteAt = block.deleteAt || 0
|
||||||
|
|
||||||
if (Array.isArray(block.properties)) {
|
if (block.schema !== 1) {
|
||||||
// HACKHACK: Port from old schema
|
if (Array.isArray(block.properties)) {
|
||||||
this.properties = {}
|
// HACKHACK: Port from old schema
|
||||||
for (const property of block.properties) {
|
this.properties = {}
|
||||||
if (property.id) {
|
for (const property of block.properties) {
|
||||||
this.properties[property.id] = property.value
|
if (property.id) {
|
||||||
|
this.properties[property.id] = property.value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.properties = { ...block.properties || {} }
|
||||||
}
|
}
|
||||||
} else {
|
} 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.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,24 +16,37 @@ interface IPropertyTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Board extends Block {
|
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 = {}) {
|
constructor(block: any = {}) {
|
||||||
super(block)
|
super(block)
|
||||||
this.type = "board"
|
this.type = "board"
|
||||||
if (block.cardProperties) {
|
|
||||||
// Deep clone of properties and their options
|
if (block.fields?.cardProperties) {
|
||||||
this.cardProperties = block.cardProperties.map((o: IPropertyTemplate) => {
|
// Deep clone of card properties and their options
|
||||||
|
this.cardProperties = block.fields?.cardProperties.map((o: IPropertyTemplate) => {
|
||||||
return {
|
return {
|
||||||
id: o.id,
|
id: o.id,
|
||||||
name: o.name,
|
name: o.name,
|
||||||
type: o.type,
|
type: o.type,
|
||||||
options: o.options ? o.options.map(option => ({...option})): []
|
options: o.options ? o.options.map(option => ({ ...option })) : []
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.cardProperties = []
|
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 })) : []
|
||||||
|
}
|
||||||
|
}) || []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,21 +5,40 @@ type IViewType = "board" | "table" | "calendar" | "list" | "gallery"
|
|||||||
type ISortOption = { propertyId: "__name" | string, reversed: boolean }
|
type ISortOption = { propertyId: "__name" | string, reversed: boolean }
|
||||||
|
|
||||||
class BoardView extends Block {
|
class BoardView extends Block {
|
||||||
viewType: IViewType
|
get viewType(): IViewType { return this.fields.viewType }
|
||||||
groupById?: string
|
set viewType(value: IViewType) { this.fields.viewType = value }
|
||||||
sortOptions: ISortOption[]
|
|
||||||
visiblePropertyIds: string[]
|
get groupById(): string | undefined { return this.fields.groupById }
|
||||||
filter?: FilterGroup
|
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 = {}) {
|
constructor(block: any = {}) {
|
||||||
super(block)
|
super(block)
|
||||||
|
|
||||||
this.type = "view"
|
this.type = "view"
|
||||||
this.viewType = block.viewType || "board"
|
|
||||||
this.groupById = block.groupById
|
this.sortOptions = block.properties?.sortOptions?.map((o: ISortOption) => ({ ...o })) || [] // Deep clone
|
||||||
this.sortOptions = block.sortOptions ? block.sortOptions.map((o: ISortOption) => ({...o})) : [] // Deep clone
|
this.visiblePropertyIds = block.properties?.visiblePropertyIds?.slice() || []
|
||||||
this.visiblePropertyIds = block.visiblePropertyIds ? block.visiblePropertyIds.slice() : []
|
this.filter = new FilterGroup(block.properties?.filter)
|
||||||
this.filter = new FilterGroup(block.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" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,14 @@ interface IBlock {
|
|||||||
id: string
|
id: string
|
||||||
parentId: string
|
parentId: string
|
||||||
|
|
||||||
|
schema: number
|
||||||
type: string
|
type: string
|
||||||
title?: string
|
title?: string
|
||||||
url?: string // TODO: Move to properties (_url)
|
url?: string // TODO: Move to properties (_url)
|
||||||
icon?: string
|
icon?: string
|
||||||
order: number
|
order: number
|
||||||
properties: Record<string, string>
|
properties: Record<string, string>
|
||||||
|
fields: Record<string, any>
|
||||||
|
|
||||||
createAt: number
|
createAt: number
|
||||||
updateAt: number
|
updateAt: number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user